Skip to content

Commit

Permalink
WEBUI-1385: Fix update of Template properties
Browse files Browse the repository at this point in the history
  • Loading branch information
alokhyland committed Mar 5, 2024
1 parent f2a850f commit 44d6007
Showing 1 changed file with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Polymer({
type: String,
value: 'view',
},
originalDocument: Object,
},

_getProcessorLabel(processor) {
Expand All @@ -191,7 +192,8 @@ Polymer({
_documentChanged() {
if (this.document) {
this.set('document.properties.tmpl:templateType', this.document.properties['tmpl:templateType'] || 'auto');
this.set('editedDocument', JSON.parse(JSON.stringify(this.document)));
this.set('editedDocument', this._parseJSON(this.document));
if (this.originalDocument === undefined) this.originalDocument = this._parseJSON(this.document);
}
},

Expand All @@ -216,12 +218,33 @@ Polymer({
},

_resetConfig() {
this.set('editedDocument', JSON.parse(JSON.stringify(this.document)));
this.set('editedDocument', this._parseJSON(this.document));
},

_findChangedValues(originalDocument, modifiedDocument) {
return Object.fromEntries(
Object.entries(modifiedDocument).filter(([key, val]) => {
if (typeof originalDocument[key] === 'object') {
return key in originalDocument && JSON.stringify(originalDocument[key]) !== JSON.stringify(val);
}
return key in originalDocument && originalDocument[key] !== val;
}),
);
},

_parseJSON(obj) {
return JSON.parse(JSON.stringify(obj));
},

_save() {
delete this.editedDocument.properties['dc:contributors'];
return this.$.doc.put();
const modified = this._parseJSON(this.editedDocument.properties);
const originalDocument = this._parseJSON(this.originalDocument.properties);
const changedvalue = this._findChangedValues(originalDocument, modified);

this.editedDocument.properties = changedvalue;
return this.$.doc.put().then(() => {
this.originalDocument = this._parseJSON(this.editedDocument);
});
},

_editConfig() {
Expand Down

0 comments on commit 44d6007

Please sign in to comment.