Skip to content

Commit

Permalink
Add caption for add buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevhen Zavhorodnii committed Nov 21, 2024
1 parent 8bd0aa4 commit 00b0236
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
26 changes: 23 additions & 3 deletions server/static/js/edit-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,41 @@ $(document).ready(function() {
schema.properties.data_assets.additionalProperties.properties :
schema.properties.technical_assets.additionalProperties.properties;
const assetEditor = new EditorGenerator(nodeData, editorSchema, $('#itemPropertyEditor'), title, generateEnumFields());
assetEditor.generateEditor([], ['communication_links'], () => {
const hiddenProperties = [];
const extendableProperties = {
'communication_links': {
addCaption: 'Add communication link'
}
};
assetEditor.generateEditor(hiddenProperties, extendableProperties, () => {
updateDiagramModel(diagramYaml);
});
}

function showProjectFields(nodeData) {
const projectEditor = new EditorGenerator(nodeData, schema.properties, $('#projectInfo'), undefined, generateEnumFields());
const hiddenProperties = ['data_assets', 'technical_assets', 'trust_boundaries', 'shared_runtimes', 'risk_tracking'];
const extendableProperties = ['questions', 'abuse_cases', 'security_requirements', 'individual_risk_categories'];
const extendableProperties = {
'questions': {
addCaption: 'Add question'
},
'abuse_cases': {
addCaption: 'Add abuse case'

},
'security_requirements': {
addCaption: 'Add security requirement'
},
'individual_risk_categories': {
addCaption: 'Add individual risk category'
}
};
projectEditor.generateEditor(hiddenProperties, extendableProperties);
}

function showTechnicalAssets(data) {
const editor = new EditorGenerator(data, schema.properties, $('#technicalAssets'), undefined, generateEnumFields());
editor.generateEditorForKeys('technical_assets', (key, value) => {
editor.generateEditorForKeys('technical_assets', 'Add technical asset', (key, value) => {
updateDiagramModel(diagramYaml);
});
}
Expand Down
13 changes: 7 additions & 6 deletions server/static/js/property-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EditorGenerator {
this.customEnumFields = customEnumFields;
}

generateEditor(ignoreFields = [], extendableProperties = [], callback = (key, value) => {}) {
generateEditor(ignoreFields = [], extendableProperties = {}, callback = (key, value) => {}) {
this.formContainer.empty();
if (this.title) {
const title = $('<label>')
Expand Down Expand Up @@ -121,10 +121,11 @@ class EditorGenerator {
const subObject = this.object[key] || {};
const subSchema = property.properties || {};

if (extendableProperties.includes(key)) {
if (extendableProperties[key]) {
const extendableContainer = $('<div>').addClass('property-editor-extendable');
const addEntryCaption = extendableProperties[key].addCaption ? extendableProperties[key].addCaption : 'Add entry'
const addButton = $('<button>')
.text('Add Entry')
.text(addEntryCaption)
.on('click', () => {
const newKey = prompt('Enter key for the new entry:');
if (!newKey) return;
Expand Down Expand Up @@ -353,7 +354,7 @@ class EditorGenerator {
}
}

generateEditorForKeys(objectKey, callback = (key, value) => {}) {
generateEditorForKeys(objectKey, addCaption, callback = (key, value) => {}) {
this.formContainer.empty();
if (this.title) {
const title = $('<label>')
Expand All @@ -370,7 +371,7 @@ class EditorGenerator {
const subObject = this.object[key] || {};
const extendableContainer = $('<div>').addClass('property-editor-extendable');
const addButton = $('<button>')
.text('Add Entry')
.text(addCaption)
.on('click', () => {
const newKey = prompt('Enter key for the new entry:');
if (!newKey) {
Expand Down Expand Up @@ -501,7 +502,7 @@ class EditorGenerator {
'',
customEnumFields
);
entrySubEditor.generateEditor([], [], callback);
entrySubEditor.generateEditor([], {}, callback);
valueEditor = entrySubEditor.formContainer;
} else {
valueEditor = $('<input type="text">')
Expand Down

0 comments on commit 00b0236

Please sign in to comment.