This commit is contained in:
Mo Bitar
2018-06-19 18:34:22 -05:00
parent 38956471b1
commit e71a4b6589
10 changed files with 73 additions and 68 deletions

View File

@@ -30,7 +30,9 @@ class Item {
}
try {
return JSON.parse(this.content);
// console.log("Parsing json", this.content);
this.content = JSON.parse(this.content);
return this.content;
} catch (e) {
console.log("Error parsing json", e, this);
return {};
@@ -58,6 +60,29 @@ class Item {
}
}
mapContentToLocalProperties(contentObj) {
if(contentObj.appData) {
this.appData = contentObj.appData;
}
if(!this.appData) { this.appData = {}; }
}
createContentJSONFromProperties() {
return this.structureParams();
}
referenceParams() {
// subclasses can override
return this.contentObject.references || [];
}
structureParams() {
var params = this.contentObject;
params.appData = this.appData;
params.references = this.referenceParams();
return params;
}
refreshContentObject() {
// Before an item can be duplicated or cloned, we must update this.content (if it is an object) with the object's
// current physical properties, because updateFromJSON, which is what all new items must go through,
@@ -119,28 +144,6 @@ class Item {
}
}
mapContentToLocalProperties(contentObj) {
if(contentObj.appData) {
this.appData = contentObj.appData;
}
if(!this.appData) { this.appData = {}; }
}
createContentJSONFromProperties() {
return this.structureParams();
}
referenceParams() {
// must override
}
structureParams() {
return {
references: this.referenceParams(),
appData: this.appData
}
}
addItemAsRelationship(item) {
// must override
}
@@ -172,6 +175,11 @@ class Item {
potentialItemOfInterestHasChangedItsUUID(newItem, oldUUID, newUUID) {
// optional override
for(var reference of this.content.references) {
if(reference.uuid == oldUUID) {
reference.uuid = newUUID;
}
}
}
allReferencedObjects() {

View File

@@ -4,14 +4,14 @@ class Mfa extends Item {
super(json_obj);
}
mapContentToLocalProperties(content) {
super.mapContentToLocalProperties(content)
this.serverContent = content;
}
structureParams() {
return _.merge(this.serverContent, super.structureParams());
}
// mapContentToLocalProperties(content) {
// super.mapContentToLocalProperties(content)
// this.serverContent = content;
// }
//
// structureParams() {
// return _.merge(this.serverContent, super.structureParams());
// }
toJSON() {
return {uuid: this.uuid}

View File

@@ -9,20 +9,20 @@ class ServerExtension extends Item {
this.url = content.url;
}
structureParams() {
// There was a bug with the way Base64 content was parsed in previous releases related to this item.
// The bug would not parse the JSON behind the base64 string and thus saved data in an invalid format.
// This is the line: https://github.com/standardnotes/web/commit/1ad0bf73d8e995b7588854f1b1e4e4a02303a42f#diff-15753bac364782a3a5876032bcdbf99aR76
// We'll remedy this for affected users by trying to parse the content string
if(typeof this.content !== 'object') {
try {
this.content = JSON.parse(this.content);
} catch (e) {}
}
var params = this.content || {};
_.merge(params, super.structureParams());
return params;
}
// structureParams() {
// // There was a bug with the way Base64 content was parsed in previous releases related to this item.
// // The bug would not parse the JSON behind the base64 string and thus saved data in an invalid format.
// // This is the line: https://github.com/standardnotes/web/commit/1ad0bf73d8e995b7588854f1b1e4e4a02303a42f#diff-15753bac364782a3a5876032bcdbf99aR76
// // We'll remedy this for affected users by trying to parse the content string
// if(typeof this.content !== 'object') {
// try {
// this.content = JSON.parse(this.content);
// } catch (e) {}
// }
// var params = this.content || {};
// _.merge(params, super.structureParams());
// return params;
// }
toJSON() {
return {uuid: this.uuid}

View File

@@ -24,6 +24,7 @@ class Component extends Item {
super.mapContentToLocalProperties(content)
/* Legacy */
this.url = content.url || content.hosted_url;
/* New */
this.local_url = content.local_url;
this.hosted_url = content.hosted_url || content.url;
@@ -82,8 +83,9 @@ class Component extends Item {
associatedItemIds: this.associatedItemIds,
};
_.merge(params, super.structureParams());
return params;
var superParams = super.structureParams();
Object.assign(superParams, params);
return superParams;
}
toJSON() {

View File

@@ -28,8 +28,9 @@ class Editor extends Item {
systemEditor: this.systemEditor
};
_.merge(params, super.structureParams());
return params;
var superParams = super.structureParams();
Object.assign(superParams, params);
return superParams;
}
referenceParams() {

View File

@@ -54,8 +54,9 @@ class Extension extends Component {
supported_types: this.supported_types
};
_.merge(params, super.structureParams());
return params;
var superParams = super.structureParams();
Object.assign(superParams, params);
return superParams;
}
}

View File

@@ -35,8 +35,9 @@ class Note extends Item {
text: this.text
};
_.merge(params, super.structureParams());
return params;
var superParams = super.structureParams();
Object.assign(superParams, params);
return superParams;
}
addItemAsRelationship(item) {
@@ -71,7 +72,7 @@ class Note extends Item {
removeReferencesNotPresentIn(references) {
this.savedTagsString = null;
super.removeReferencesNotPresentIn(references);
var uuids = references.map(function(ref){return ref.uuid});

View File

@@ -26,8 +26,9 @@ class Tag extends Item {
title: this.title
};
_.merge(params, super.structureParams());
return params;
var superParams = super.structureParams();
Object.assign(superParams, params);
return superParams;
}
addItemAsRelationship(item) {

View File

@@ -2,7 +2,6 @@ class Theme extends Component {
constructor(json_obj) {
super(json_obj);
this.area = "themes";
}

View File

@@ -26,10 +26,6 @@ class ModelManager {
this.itemsPendingRemoval = [];
this.items = [];
this._extensions = [];
this.acceptableContentTypes = [
"Note", "Tag", "Extension", "SN|Editor", "SN|Theme",
"SN|Component", "SF|Extension", "SN|UserPreferences", "SF|MFA"
];
}
resetLocalMemory() {
@@ -66,7 +62,6 @@ class ModelManager {
this.informModelsOfUUIDChangeForItem(newItem, item.uuid, newItem.uuid);
console.log(item.uuid, "-->", newItem.uuid);
var block = () => {
@@ -162,16 +157,15 @@ class ModelManager {
}
let contentType = json_obj["content_type"] || (item && item.content_type);
var unknownContentType = !_.includes(this.acceptableContentTypes, contentType);
var isDirtyItemPendingDelete = false;
if(json_obj.deleted == true || unknownContentType) {
if(json_obj.deleted == true) {
if(json_obj.deleted && json_obj.dirty) {
// Item was marked as deleted but not yet synced
// We need to create this item as usual, but just not add it to individual arrays
// i.e add to this.items but not this.notes (so that it can be retrieved with getDirtyItems)
isDirtyItemPendingDelete = true;
} else {
if(item && !unknownContentType) {
if(item) {
modelsToNotifyObserversOf.push(item);
this.removeItemLocally(item);
}
@@ -418,9 +412,7 @@ class ModelManager {
/* Used when changing encryption key */
setAllItemsDirty(dontUpdateClientDates = true) {
var relevantItems = this.allItems.filter(function(item){
return _.includes(this.acceptableContentTypes, item.content_type);
}.bind(this));
var relevantItems = this.allItems;
for(var item of relevantItems) {
item.setDirty(true, dontUpdateClientDates);