Skip to content

Commit 3a47d38

Browse files
committed
Added workspace new/load/save
+update SchemaClassMenu immediately
1 parent 2baead7 commit 3a47d38

4 files changed

Lines changed: 102 additions & 19 deletions

File tree

lib/SchemaEditor.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,32 @@ export class SchemaEditor {
156156
// FUTURE: Extend above types with menu of user-defined types.
157157
break;
158158

159-
case 'SchemaClassMenu':
160-
// Get the classes from the Classes tab, filtered for schema_name
161-
// selected in Schema tab.
162-
163-
this.getDynamicMenu(schema, schema.classes, 'Class', user_schema_name, permissible_values);
164-
console.log("REGENERATING CLASS MENU", )
159+
case 'SchemaClassMenu': {
160+
// Read directly from the live Class DH so edits on the Table tab
161+
// are reflected immediately — same pattern as SchemaMenu.
162+
// "All records" display → include all uniquely-named classes across schemas.
163+
// "Records by selected key" display → restrict to the user-selected schema (if any).
164+
const class_dh = this.context.dhs['Class'];
165+
if (class_dh) {
166+
const show_all = ($('input[name="display-main-type"]:checked').val() ?? '') === 'all';
167+
const name_col = class_dh.slot_name_to_column['name'];
168+
const desc_col = class_dh.slot_name_to_column['description'];
169+
const schema_col = class_dh.slot_name_to_column['schema_id'];
170+
for (let row = 0; row < class_dh.hot.countSourceRows(); row++) {
171+
const row_schema = class_dh.hot.getSourceDataAtCell(row, schema_col);
172+
if (!show_all && row_schema !== user_schema_name) continue;
173+
const class_name = class_dh.hot.getSourceDataAtCell(row, name_col);
174+
if (class_name && !(class_name in permissible_values)) {
175+
permissible_values[class_name] = {
176+
text: class_name,
177+
title: row_schema ? `${row_schema} - ${class_name}` : class_name,
178+
description: class_dh.hot.getSourceDataAtCell(row, desc_col) || ''
179+
};
180+
}
181+
}
182+
}
165183
break;
184+
}
166185

167186
case 'SchemaEnumMenu':
168187
// Get the enums from the Enums tab, filtered for schema
@@ -1931,6 +1950,14 @@ export class SchemaEditor {
19311950
* a summary of what will be copied before the user confirms.
19321951
*/
19331952
openCopyToSchemaModal(sourceDh) {
1953+
if (sourceDh.template_name === 'Schema') {
1954+
dhAlert(
1955+
'Copying whole schemas is not supported here. Only parts of a schema (tables, fields, enumerations, etc.) can be copied to another schema.\n\n' +
1956+
'To make a visible copy of an entire schema, load it a second time from its source file — it will appear as a separate row.'
1957+
);
1958+
return;
1959+
}
1960+
19341961
// Collect unique non-empty physical rows from all selection ranges.
19351962
const selection = sourceDh.hot.getSelected() || [];
19361963
const physRowSet = new Set();

lib/Toolbar.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,14 @@ class Toolbar {
290290
});
291291

292292
// DATA FILE
293-
$('#new-dropdown-item').on('click', this.createNewFile.bind(this));
293+
$('#new-dropdown-item, #clear-dropdown-workspace').on('click', this.createNewFile.bind(this));
294294
$('#open-file-input').on('change', this.openDataFile.bind(this));
295-
$('#save-as-dropdown-item').on('click', () => this.showSaveAsModal());
295+
$('#save-as-dropdown-item').on('click', () => { this._saveAsJsonOnly = false; this.showSaveAsModal(); });
296+
$('#save-as-dropdown-workspace').on('click', () => { this._saveAsJsonOnly = true; this.showSaveAsModal(); });
296297
$('#save-as-json-use-index').on('change', this.toggleJsonIndexKey);
297298
$('#save-as-confirm-btn').on('click', this.saveDataFile.bind(this));
298299
$('#save-as-modal').on('hidden.bs.modal', this.resetSaveAsModal);
300+
$('#save-as-modal').on('hidden.bs.modal', () => { $('#file-ext-save-as-select option').show(); });
299301
$('#save-as-modal').on('show.bs.modal', () => this._updateSaveOptions());
300302
$('#file-ext-save-as-select').on('change', () => this._updateSaveOptions());
301303
$('#export-to-confirm-btn').on('click', this.exportFile.bind(this));
@@ -867,6 +869,11 @@ class Toolbar {
867869
* non-JSON defaults depend on the active locale.
868870
*/
869871
_updateSaveOptions() {
872+
// In Schema Editor workspace context only JSON export is supported.
873+
if (this._saveAsJsonOnly) {
874+
$('#file-ext-save-as-select option:not([value="json"])').hide();
875+
$('#file-ext-save-as-select').val('json');
876+
}
870877
const ext = $('#file-ext-save-as-select').val();
871878
const isJson = ext === 'json';
872879
const $localeSelect = $('#select-translation-localization');

lib/toolbar.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
id="load-template-url-button"
8282
data-toggle="modal"
8383
data-target="#load-template-url-modal"
84+
data-i18n="load-template-url-button"
8485
>... from URL</span
8586
>
8687

@@ -116,6 +117,7 @@
116117
id="load-schema-url-button"
117118
data-toggle="modal"
118119
data-target="#load-schema-url-modal"
120+
data-i18n="load-schema-url-button"
119121
>Load schema from URL (yaml format)</span
120122
>
121123
<span
@@ -144,6 +146,7 @@
144146
data-i18n="translation-form-button"
145147
>Translation form (for chosen rows)</span
146148
>
149+
147150
<label
148151
for="schema_expert"
149152
class="dropdown-item mb-0"
@@ -157,11 +160,35 @@
157160
/>
158161
</label>
159162

163+
<span data-i18n="workspace">Workspace</span>
164+
165+
<span
166+
class="dropdown-item"
167+
id="clear-dropdown-workspace"
168+
data-i18n="clear-dropdown-workspace"
169+
>Clear</span
170+
>
171+
<!-- reusing open-file-input -->
172+
<label
173+
for="open-file-input"
174+
class="dropdown-item mb-0"
175+
id="open-dropdown-workspace"
176+
data-i18n="open-dropdown-workspace"
177+
>Open</label
178+
>
179+
<span
180+
class="dropdown-item"
181+
data-toggle="modal"
182+
id="save-as-dropdown-workspace"
183+
data-i18n="save-as-dropdown-workspace"
184+
>Save as</span
185+
>
186+
160187
<span
161188
class="dropdown-item" style="padding-left:0"
162189
id="load-data-manager-button"
163190
data-i18n="load-data-manager"
164-
>Run data manager
191+
>Run DataHarmonizer
165192
</span>
166193

167194
</div>

web/translations/translations.json

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
"en": "Schema editor",
2222
"fr": "L'éditeur de schéma"
2323
},
24+
"load-data-manager": {
25+
"en": "Run DataHarmonizer",
26+
"fr": "Exécuter DataHarmonizer"
27+
},
2428
"load-schema-editor": {
25-
"en": "Run schema editor",
26-
"fr": "Exécuter l'éditeur"
29+
"en": "Run Schema Editor",
30+
"fr": "Exécuter l'éditeur de schéma"
2731
},
2832
"schema-editor-menu": {
2933
"en": "Schema editor options",
@@ -34,17 +38,35 @@
3438
"fr": "Activer/désactiver le mode utilisateur expert"
3539
},
3640
"upload-template-yaml-dropdown-item": {
37-
"en": "Load schema from file (yaml format)",
38-
"fr": "Charger le schéma à partir du fichier (format yaml)"
41+
"en": "Load schema from file (yaml)",
42+
"fr": "Charger le schéma à partir du fichier (yaml)"
3943
},
40-
"upload-template-uri": {
41-
"en": "Load schema from URL (yaml format)",
42-
"fr": "Charger le schéma à partir de l'URL (format yaml)"
44+
"load-schema-url-button": {
45+
"en": "Load schema from URL (yaml)",
46+
"fr": "Charger le schéma à partir de l'URL (yaml)"
4347
},
44-
48+
49+
"workspace": {
50+
"en": "Workspace",
51+
"fr": "Espace de travail"
52+
},
53+
54+
"clear-dropdown-workspace": {
55+
"en": "Clear",
56+
"fr": "Vider"
57+
},
58+
"open-dropdown-workspace": {
59+
"en": "Open",
60+
"fr": "Ouvrir"
61+
},
62+
"save-as-dropdown-workspace": {
63+
"en": "Save as",
64+
"fr": "Enregistrer sous"
65+
},
66+
4567
"save-template-button": {
46-
"en": "Save selected schema (yaml format)",
47-
"fr": "Enregistrer le schéma sélectionné (format yaml)"
68+
"en": "Save selected schema (yaml)",
69+
"fr": "Enregistrer le schéma sélectionné (yaml)"
4870
},
4971
"preview-schema-button": {
5072
"en": "Preview selected schema",

0 commit comments

Comments
 (0)