Skip to content

Commit 98eeafa

Browse files
committed
SchemaEditor Fields tab work
1 parent f9538f3 commit 98eeafa

7 files changed

Lines changed: 114 additions & 63 deletions

File tree

lib/AppContext.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default class AppContext {
7575
let class_name = dh.template_name;
7676
let report_type = $('#report_select_type').val();
7777

78-
console.log("refreshTabDisplay()", class_name, this.schemaEditor, report_type)
78+
//console.log("REFRESHTABDISPLAY", class_name, this.schemaEditor, report_type)
7979

8080
// Display Focus path only if there is some path > 1 element.
8181
$("#record-hierarchy-div").toggle(Object.keys(this.dhs).length > 1);
@@ -98,12 +98,8 @@ export default class AppContext {
9898
let cursor = dh.hot.getSelected();
9999
dh.hot.deselectCell();
100100

101-
//columnsorting cannot be disabled. If it is, below code will error.
102-
const columnSorting = dh.hot.getPlugin('multiColumnSorting');
103-
columnSorting.clearSort(); // Reset sort so filter matches raw fields
104-
105101
// Schema editor SCHEMA tab should never be filtered.
106-
// NO TAB THAT ISN'T A DEPENDENT SHOULD BE FILTERED.
102+
// ONLY DEPENDENT TABS/TABLES SHOULD BE FILTERED.
107103
// OR MORE SIMPLY WHEN FILTERING WE ALWAYS PRESERVE FOCUSED NODE
108104
// - BUT WE DON'T WANT EVENT TRIGGERED
109105
switch (report_type) {
@@ -113,7 +109,8 @@ export default class AppContext {
113109
break;
114110

115111
case 'slot':
116-
this.slotTypeFilter(dh, ['slot']);
112+
//this.slotTypeFilter(dh, ['slot']);
113+
//dh.hot.getPlugin('multiColumnSorting').sort() ; //{ column: 3, sortOrder: 'asc' }
117114
break;
118115

119116
case 'attribute':
@@ -122,7 +119,7 @@ export default class AppContext {
122119

123120
case 'slot_usage':
124121
this.slotTypeFilter(dh, ['slot','slot_usage']);
125-
122+
// UNFINISHED CODE
126123
columnSorting.sort({
127124
column: dh.slot_name_column,
128125
sortOrder: 'asc'
@@ -142,26 +139,35 @@ export default class AppContext {
142139
this.tabFilter(dh, dependent_report.fkey_vals); // filter by selected keys.
143140
}
144141

145-
dh.render(); // Otherwise cells() implements meta and class stuff that isn't reflected
146-
147142
// DON'T RESTORE CURSOR UNTIL WE KNOW THAT IT IS POINTING TO SAME KEY AS BEFORE FILTER?
148143
// Refreshes dependent record list.
149144
if (cursor) {
150145
// Adding custom event type to selectCell() call, but so far not using this.
151-
cursor[0].push('afterFilteriing');
146+
cursor[0].push('afterFiltering');
152147
// Now this may not select row related to original selection after filter?
153148
// Suggests converting cursor into unique_key fields, for reselection.
154149
dh.hot.selectCell(...cursor[0], '');
155150
// Note this will cause a "double event" of selecting same cell twice.
156151

157152
}
153+
154+
//columnsorting cannot be disabled. If it is, below code will error.
155+
const columnSorting = dh.hot.getPlugin('multiColumnSorting');
156+
// Unable to get original multiColumnSorting.initConfig via
157+
// columnSorting.getSortConfig() ?!!!!
158+
// WARNING - this clears out initialConfig TOO?!?!
159+
//columnSorting.clearSort(); // Reset sort so filter matches raw fields
160+
columnSorting.sort(dh.defaultMultiColumnSortConfig); // possibly null
161+
162+
dh.render(); // Otherwise cells() implements meta and class stuff that isn't reflected
163+
158164
}
159165

160166
/** filterByKeys() SHOULD NOT BE APPLIED TO A schema's ROOT (top level) tab.
161167
* E.g. for SCHEMA EDITOR, on "Schema" TAB - we never want to filter selection
162168
* there unless there's a way of releasing that filter.
163169
*/
164-
async filterByKeys(dh, key_vals = {}) {
170+
async filterByKeys_UNUSED_UNUSED(dh, key_vals = {}) {
165171

166172
/* For Slot tab query, only foreign key at moment is schema_id.
167173
* However, if user has selected a table in Table/Class tab, we want
@@ -202,8 +208,8 @@ export default class AppContext {
202208
// also bring in slots not associated with a class. (no class_name).
203209

204210
// let multiColumnSorting = dh.hot.getPlugin('multiColumnSorting');
205-
const columnSorting = dh.hot.getPlugin('columnSorting');
206-
columnSorting.clearSort(); // Reset sort so filter matches raw fields
211+
//const columnSorting = dh.hot.getPlugin('columnSorting');
212+
//columnSorting.clearSort(); // Reset sort so filter matches raw fields
207213

208214
const mode = $('#report_select_type').val();
209215

@@ -500,7 +506,7 @@ export default class AppContext {
500506
// based on LinkML class
501507
this.useTemplate(handsOnDH, class_name);
502508

503-
handsOnDH.createHot();
509+
handsOnDH.createHot(); // Instance without data.
504510

505511
// FUTURE: try reorganization to separate dh from all .context
506512
// schema/template data/functions
@@ -513,7 +519,7 @@ export default class AppContext {
513519
if (found_name)
514520
handsOnDH.container_name = found_name;
515521
}
516-
console.log("container lookup", handsOnDH.container_name);
522+
//console.log("CONTAINER LOOKUP", handsOnDH.container_name);
517523

518524
if (is_child) {
519525
/* Initialization of each child table is to hide all rows until

lib/DataHarmonizer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,21 +748,22 @@ class DataHarmonizer {
748748
}
749749
}
750750
},
751-
...this.hot_override_settings,
751+
...this.hot_override_settings, // custom overrides from DH setup.
752752
};
753753

754-
//columnSorting: true,
754+
// DEFAULT multiColumnSorting settings which are overriden in initTab()
755755
hot_settings.multiColumnSorting = {
756756
sortEmptyCells: true, // false = empty rows at end of table regardless of sort
757757
indicator: true, // true = header indicator
758758
headerAction: true, // true = header double click sort
759759
}
760760

761-
// Here is place to add settings based on particular tabs, e.g. Slot Editor "Slot"
761+
// Within the SchemaEditor template context, this adds settings based on
762+
// particular tabs, e.g. Slot Editor "Slot". It modifies hot_settings above;
762763
this.context.schemaEditor?.initTab(this, this.template_name, hot_settings);
763-
// Other tabs
764764

765765
this.hot.updateSettings(hot_settings);
766+
766767
this.enableMultiSelection();
767768
} else {
768769
console.warn(

lib/HelpSidebar.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
background-color: white;
66
transition-property: right;
77
transition-timing-function: ease;
8-
border-left: 1px solid #ddd;
8+
border:0;
9+
/*border-left: 1px solid #ddd;*/
910
}
1011

1112
.help-sidebar__toggler {
1213
position: absolute;
1314
top: 0;
1415
transform: translateX(-100%);
1516
z-index: 200;
16-
border: 1px solid #ddd;
17+
border: 0px;
18+
border-radius:5px;
1719
border-right-width: 0;
18-
background-color: white;
20+
background-color: #007bff;
21+
color: white;
1922
}
2023

2124
.help-sidebar__content {

lib/SchemaEditor.js

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class SchemaEditor {
152152
// ONLY reprogrammable for multiselects.
153153
// Reset menu's permissible_values to latest.
154154
if (! (enum_name in schema.enums)) {
155-
console.log("Adding enumeration", enum_name);
155+
//console.log("Adding enumeration", enum_name);
156156
schema.enums[enum_name] = {name: enum_name};
157157

158158
}
@@ -392,20 +392,21 @@ export class SchemaEditor {
392392
return true;
393393
};
394394

395+
/* Empty table render will still trigger .cells () for all row 0 columns
396+
*/
395397
initTab (dh, class_name, hot_settings) {
396398

397399
if (class_name === 'Slot') {
398-
const slot_table_attribute_column = ['rank','inlined','inlined_as_list'].map((x) => dh.slot_name_to_column[x]);
400+
const slot_table_attribute_column = ['rank','slot_group','inlined','inlined_as_list'].map((x) => dh.slot_name_to_column[x]);
399401

400402
// See https://forum.handsontable.com/t/how-to-unhide-columns-after-hiding-them/5086/6
401403
hot_settings.contextMenu.items['hidden_columns_hide'] = {};
402404
hot_settings.contextMenu.items['hidden_columns_show'] = {};
403-
404405
// Could be turning off/on based on expert user
405406
hot_settings.hiddenColumns = {
406407
// set columns that are hidden by default
407408
columns: slot_table_attribute_column,
408-
indicators: true
409+
indicators: false
409410
}
410411

411412
hot_settings.fixedColumnsLeft = 4; // Freeze both schema and slot name.
@@ -417,21 +418,51 @@ export class SchemaEditor {
417418
// We can't lookup existing .getCellMeta() without causing stack overflow.
418419
// ISSUE: We have to disable sorting for 'Slot' table because
419420
// separate reporting controls are at work.
421+
422+
// ASSUMES alphabetical order with schema fields at top
423+
424+
// ISSUE: user clicking on "toggle expert user mode" doesn't visually
425+
// take effect until after dh.render(), so cellProp.readOnly doesn't
426+
// work right away.
420427
hot_settings.cells = function(row, col) {
421428
let cellProp = {};
429+
let read_only = !(dh.context.expert_user === true);
430+
//console.log("EXPERT", row, col, class_name, dh.context.expert_user);
431+
432+
// slot, slot_usage, attribute
422433
let slot_type = dh.hot.getSourceDataAtCell(row, dh.slot_type_column);
423-
let slot_report = $('#report_select_type').val() === 'slot';
424-
let read_only = !slot_report || col == dh.slot_class_name_column;
425-
if (slot_type === 'slot') {
426-
cellProp.className = 'schemaSlot' + (read_only ? ' hatched' : '');
427-
// block changing slot class name when working on Schema classes.
428-
cellProp.readOnly = read_only;
434+
cellProp.className = 'tabFieldTd_' + slot_type;
435+
436+
if (read_only) {
437+
// Here we tweak the read-only nature of this field.
438+
if (slot_type === 'slot') {
439+
}
440+
else { // slot_usage or attribute here
441+
read_only = false;
442+
if (col in [dh.schema_name_column]) //dh.slot_class_name_column);
443+
read_only = true;
444+
// ADD LOGIC TO copy display and read only of slot values.
445+
if (slot_type === 'slot_usage') {
446+
447+
}
448+
}
449+
429450
}
451+
452+
/* Handsontable assigns .htDimmed to any cell with .readOnly = true
453+
* see https://handsontable.com/docs/javascript-data-grid/disabled-cells/
454+
*/
455+
cellProp.readOnly = read_only;
456+
//if (row==2 && col == dh.slot_class_name_column) {
457+
// console.log("READONLY", cellProp, dh.slot_class_name_column)
458+
//}
459+
430460
return cellProp;
431461
}
432-
433-
/*
434-
hot_settings.columnSorting = {
462+
//hot_settings.multiColumnSorting = false;
463+
//hot_settings.columnSorting = false; // NOT USING single column sorting.
464+
465+
hot_settings.multiColumnSorting = {
435466
// let the end user sort data by clicking on the column name (set by default)
436467
headerAction: false,
437468
// don't sort empty cells – move rows that contain empty cells to the bottom (set by default)
@@ -440,28 +471,29 @@ export class SchemaEditor {
440471
indicator: false,
441472

442473
// at initialization, sort data by the first column, in descending order
443-
//initialConfig: {
444-
// column: 1, // slot name
445-
// sortOrder: 'asc',
446-
//},
447-
448-
// implement your own comparator
449-
compareFunctionFactory(sortOrder, columnMeta) {
450-
return function (value, nextValue) {
451-
// here, add a compare function
452-
// that returns `-1`, or `0`, or `1`
453-
// ADD OTHER COLUMN VALUES...
454-
if (value < nextValue) {
455-
return -1
456-
}
457-
if (value > nextValue) {
458-
return 1
459-
}
460-
return 0
461-
};
462-
},
474+
// FOR MULTICOLUMN SORTING PROVIDE AN ARRAY, essentially REVERSE ORDER
475+
//initialConfig: [],
476+
463477
}
464-
*/
478+
479+
// Somehow putting this above doesn't enable memory of it, as though initial
480+
// condition is being wiped out.
481+
dh.defaultMultiColumnSortConfig = [
482+
{
483+
column: 3, // slot.name
484+
sortOrder: 'asc'
485+
},
486+
/*
487+
{
488+
column: 1, // slot type
489+
sortOrder: 'asc'
490+
},
491+
{
492+
column: 3, // schema
493+
sortOrder: 'asc'
494+
}
495+
*/
496+
];
465497
}
466498
else {}
467499
}

lib/Toolbar.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ class Toolbar {
270270
// Load a DH schema.yaml file into this slot.
271271
// Prompt user for schema file name.
272272
$('#schema_expert').on('click', (event) => {
273-
let expert_visibility = $('#schema_expert').is(':checked');
274-
$(SCHEMA_EDITOR_EXPERT_TABS).toggle(expert_visibility);
273+
let expert_user = $('#schema_expert').is(':checked');
274+
this.context.expert_user = expert_user;
275+
$(SCHEMA_EDITOR_EXPERT_TABS).toggle(expert_user);
275276
});
276277

277278
$('#schema_upload').on('change', (event) => {
@@ -1393,9 +1394,9 @@ export function titleOverText(enm) {
13931394
}
13941395

13951396
let schema_editor = this.context.getCurrentDataHarmonizer().schema.name === 'DH_LinkML';
1396-
let expert_visibility = $('#schema_expert').is(':checked');
1397+
let expert_user = $('#schema_expert').is(':checked');
13971398
$('#schema-editor-menu').toggle(schema_editor);
1398-
$(SCHEMA_EDITOR_EXPERT_TABS).toggle(expert_visibility);
1399+
$(SCHEMA_EDITOR_EXPERT_TABS).toggle(expert_user);
13991400
$('#slot_report_control').hide();
14001401

14011402
this.setupJumpToModal(dh);

lib/data-harmonizer.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,16 @@ tr.translate_key td {
249249
font-weight:bold;
250250
}
251251

252-
td.schemaSlot {
252+
/* Handsontable assigns .htDimmed to any cell with .readOnly = true */
253+
td.tabFieldTd_slot {
253254
border-top:2px solid green;
254255
background-color: #EFE;
255256
}
256257

258+
td.tabFieldTd_attribute {
259+
border-top:2px solid green;
260+
background-color: lightyellow;
261+
}
257262
/* Not sure how to display frozen column right side in header area
258263
.data-harmonizer-grid th.overlayEdge {
259264
border-right: 2px solid black !important;
@@ -273,7 +278,7 @@ td.schemaSlot {
273278

274279
.coding_name {font-size: .8rem} /* Used where slot.name is shown */
275280

276-
/* Handsontable class for readOnly fields */
281+
/* Handsontable class for readOnly fields
277282
.handsontable td.hatched {
278283
background: repeating-linear-gradient(
279284
-45deg,
@@ -282,6 +287,7 @@ td.schemaSlot {
282287
lightsilver 1px,
283288
lightsilver 8px);
284289
}
290+
*/
285291

286292
td.hide {
287293
display:none;

lib/toolbar.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,13 @@
378378
<select id="report_select_type" class="btn btn-primary">
379379
<option value="all" data-i18n="all-records">All records</option>
380380
<option value="" selected="selected" data-i18n="records-by-selected-key">Record(s) by selected key</option>
381+
<!-- Only a single report for Field / Slot tab for now
381382
<optgroup id="slot_report_type" label="By field report:">
382383
<option value="slot" data-i18n="schema-field">Schema field</option>
383384
<option value="slot_usage" data-i18n="table-field-from-schema">Table field from schema</option>
384385
<option value="attribute" data-i18n="table-field-stand-alone">Table field (stand-alone)</option>
385386
</optgroup>
387+
-->
386388
</select>
387389
<span class="input-group-text" style="background-color:#fdfdfd" id="record-hierarchy"></span>
388390
</div>

0 commit comments

Comments
 (0)