Wip
This commit is contained in:
@@ -30,7 +30,9 @@ class Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return JSON.parse(this.content);
|
// console.log("Parsing json", this.content);
|
||||||
|
this.content = JSON.parse(this.content);
|
||||||
|
return this.content;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Error parsing json", e, this);
|
console.log("Error parsing json", e, this);
|
||||||
return {};
|
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() {
|
refreshContentObject() {
|
||||||
// Before an item can be duplicated or cloned, we must update this.content (if it is an object) with the object's
|
// 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,
|
// 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) {
|
addItemAsRelationship(item) {
|
||||||
// must override
|
// must override
|
||||||
}
|
}
|
||||||
@@ -172,6 +175,11 @@ class Item {
|
|||||||
|
|
||||||
potentialItemOfInterestHasChangedItsUUID(newItem, oldUUID, newUUID) {
|
potentialItemOfInterestHasChangedItsUUID(newItem, oldUUID, newUUID) {
|
||||||
// optional override
|
// optional override
|
||||||
|
for(var reference of this.content.references) {
|
||||||
|
if(reference.uuid == oldUUID) {
|
||||||
|
reference.uuid = newUUID;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allReferencedObjects() {
|
allReferencedObjects() {
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ class Mfa extends Item {
|
|||||||
super(json_obj);
|
super(json_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
mapContentToLocalProperties(content) {
|
// mapContentToLocalProperties(content) {
|
||||||
super.mapContentToLocalProperties(content)
|
// super.mapContentToLocalProperties(content)
|
||||||
this.serverContent = content;
|
// this.serverContent = content;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
structureParams() {
|
// structureParams() {
|
||||||
return _.merge(this.serverContent, super.structureParams());
|
// return _.merge(this.serverContent, super.structureParams());
|
||||||
}
|
// }
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {uuid: this.uuid}
|
return {uuid: this.uuid}
|
||||||
|
|||||||
@@ -9,20 +9,20 @@ class ServerExtension extends Item {
|
|||||||
this.url = content.url;
|
this.url = content.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
structureParams() {
|
// structureParams() {
|
||||||
// There was a bug with the way Base64 content was parsed in previous releases related to this item.
|
// // 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.
|
// // 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
|
// // 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
|
// // We'll remedy this for affected users by trying to parse the content string
|
||||||
if(typeof this.content !== 'object') {
|
// if(typeof this.content !== 'object') {
|
||||||
try {
|
// try {
|
||||||
this.content = JSON.parse(this.content);
|
// this.content = JSON.parse(this.content);
|
||||||
} catch (e) {}
|
// } catch (e) {}
|
||||||
}
|
// }
|
||||||
var params = this.content || {};
|
// var params = this.content || {};
|
||||||
_.merge(params, super.structureParams());
|
// _.merge(params, super.structureParams());
|
||||||
return params;
|
// return params;
|
||||||
}
|
// }
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {uuid: this.uuid}
|
return {uuid: this.uuid}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class Component extends Item {
|
|||||||
super.mapContentToLocalProperties(content)
|
super.mapContentToLocalProperties(content)
|
||||||
/* Legacy */
|
/* Legacy */
|
||||||
this.url = content.url || content.hosted_url;
|
this.url = content.url || content.hosted_url;
|
||||||
|
|
||||||
/* New */
|
/* New */
|
||||||
this.local_url = content.local_url;
|
this.local_url = content.local_url;
|
||||||
this.hosted_url = content.hosted_url || content.url;
|
this.hosted_url = content.hosted_url || content.url;
|
||||||
@@ -82,8 +83,9 @@ class Component extends Item {
|
|||||||
associatedItemIds: this.associatedItemIds,
|
associatedItemIds: this.associatedItemIds,
|
||||||
};
|
};
|
||||||
|
|
||||||
_.merge(params, super.structureParams());
|
var superParams = super.structureParams();
|
||||||
return params;
|
Object.assign(superParams, params);
|
||||||
|
return superParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ class Editor extends Item {
|
|||||||
systemEditor: this.systemEditor
|
systemEditor: this.systemEditor
|
||||||
};
|
};
|
||||||
|
|
||||||
_.merge(params, super.structureParams());
|
var superParams = super.structureParams();
|
||||||
return params;
|
Object.assign(superParams, params);
|
||||||
|
return superParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
referenceParams() {
|
referenceParams() {
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ class Extension extends Component {
|
|||||||
supported_types: this.supported_types
|
supported_types: this.supported_types
|
||||||
};
|
};
|
||||||
|
|
||||||
_.merge(params, super.structureParams());
|
var superParams = super.structureParams();
|
||||||
return params;
|
Object.assign(superParams, params);
|
||||||
|
return superParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,9 @@ class Note extends Item {
|
|||||||
text: this.text
|
text: this.text
|
||||||
};
|
};
|
||||||
|
|
||||||
_.merge(params, super.structureParams());
|
var superParams = super.structureParams();
|
||||||
return params;
|
Object.assign(superParams, params);
|
||||||
|
return superParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
addItemAsRelationship(item) {
|
addItemAsRelationship(item) {
|
||||||
@@ -71,7 +72,7 @@ class Note extends Item {
|
|||||||
|
|
||||||
removeReferencesNotPresentIn(references) {
|
removeReferencesNotPresentIn(references) {
|
||||||
this.savedTagsString = null;
|
this.savedTagsString = null;
|
||||||
|
|
||||||
super.removeReferencesNotPresentIn(references);
|
super.removeReferencesNotPresentIn(references);
|
||||||
|
|
||||||
var uuids = references.map(function(ref){return ref.uuid});
|
var uuids = references.map(function(ref){return ref.uuid});
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ class Tag extends Item {
|
|||||||
title: this.title
|
title: this.title
|
||||||
};
|
};
|
||||||
|
|
||||||
_.merge(params, super.structureParams());
|
var superParams = super.structureParams();
|
||||||
return params;
|
Object.assign(superParams, params);
|
||||||
|
return superParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
addItemAsRelationship(item) {
|
addItemAsRelationship(item) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ class Theme extends Component {
|
|||||||
|
|
||||||
constructor(json_obj) {
|
constructor(json_obj) {
|
||||||
super(json_obj);
|
super(json_obj);
|
||||||
|
|
||||||
this.area = "themes";
|
this.area = "themes";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,6 @@ class ModelManager {
|
|||||||
this.itemsPendingRemoval = [];
|
this.itemsPendingRemoval = [];
|
||||||
this.items = [];
|
this.items = [];
|
||||||
this._extensions = [];
|
this._extensions = [];
|
||||||
this.acceptableContentTypes = [
|
|
||||||
"Note", "Tag", "Extension", "SN|Editor", "SN|Theme",
|
|
||||||
"SN|Component", "SF|Extension", "SN|UserPreferences", "SF|MFA"
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resetLocalMemory() {
|
resetLocalMemory() {
|
||||||
@@ -66,7 +62,6 @@ class ModelManager {
|
|||||||
|
|
||||||
this.informModelsOfUUIDChangeForItem(newItem, item.uuid, newItem.uuid);
|
this.informModelsOfUUIDChangeForItem(newItem, item.uuid, newItem.uuid);
|
||||||
|
|
||||||
|
|
||||||
console.log(item.uuid, "-->", newItem.uuid);
|
console.log(item.uuid, "-->", newItem.uuid);
|
||||||
|
|
||||||
var block = () => {
|
var block = () => {
|
||||||
@@ -162,16 +157,15 @@ class ModelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let contentType = json_obj["content_type"] || (item && item.content_type);
|
let contentType = json_obj["content_type"] || (item && item.content_type);
|
||||||
var unknownContentType = !_.includes(this.acceptableContentTypes, contentType);
|
|
||||||
var isDirtyItemPendingDelete = false;
|
var isDirtyItemPendingDelete = false;
|
||||||
if(json_obj.deleted == true || unknownContentType) {
|
if(json_obj.deleted == true) {
|
||||||
if(json_obj.deleted && json_obj.dirty) {
|
if(json_obj.deleted && json_obj.dirty) {
|
||||||
// Item was marked as deleted but not yet synced
|
// 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
|
// 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)
|
// i.e add to this.items but not this.notes (so that it can be retrieved with getDirtyItems)
|
||||||
isDirtyItemPendingDelete = true;
|
isDirtyItemPendingDelete = true;
|
||||||
} else {
|
} else {
|
||||||
if(item && !unknownContentType) {
|
if(item) {
|
||||||
modelsToNotifyObserversOf.push(item);
|
modelsToNotifyObserversOf.push(item);
|
||||||
this.removeItemLocally(item);
|
this.removeItemLocally(item);
|
||||||
}
|
}
|
||||||
@@ -418,9 +412,7 @@ class ModelManager {
|
|||||||
|
|
||||||
/* Used when changing encryption key */
|
/* Used when changing encryption key */
|
||||||
setAllItemsDirty(dontUpdateClientDates = true) {
|
setAllItemsDirty(dontUpdateClientDates = true) {
|
||||||
var relevantItems = this.allItems.filter(function(item){
|
var relevantItems = this.allItems;
|
||||||
return _.includes(this.acceptableContentTypes, item.content_type);
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
for(var item of relevantItems) {
|
for(var item of relevantItems) {
|
||||||
item.setDirty(true, dontUpdateClientDates);
|
item.setDirty(true, dontUpdateClientDates);
|
||||||
|
|||||||
Reference in New Issue
Block a user