Components system

This commit is contained in:
Mo Bitar
2017-06-15 11:44:20 -05:00
parent b759b2b770
commit de21d110d9
19 changed files with 1071 additions and 39 deletions

View File

@@ -0,0 +1,59 @@
class Component extends Item {
constructor(json_obj) {
super(json_obj);
if(!this.componentData) {
this.componentData = {};
}
if(!this.disassociatedItemIds) {
this.disassociatedItemIds = [];
}
}
mapContentToLocalProperties(contentObject) {
super.mapContentToLocalProperties(contentObject)
this.url = contentObject.url;
this.name = contentObject.name;
// the location in the view this component is located in. Valid values are currently tags-list, note-tags, and editor-stack`
this.area = contentObject.area;
this.permissions = contentObject.permissions;
this.active = contentObject.active;
// custom data that a component can store in itself
this.componentData = contentObject.componentData || {};
// items that have requested a component to be disabled in its context
this.disassociatedItemIds = contentObject.disassociatedItemIds || [];
}
structureParams() {
var params = {
url: this.url,
name: this.name,
area: this.area,
permissions: this.permissions,
active: this.active,
componentData: this.componentData,
disassociatedItemIds: this.disassociatedItemIds
};
_.merge(params, super.structureParams());
return params;
}
toJSON() {
return {uuid: this.uuid}
}
get content_type() {
return "SN|Component";
}
isActiveForItem(item) {
return this.disassociatedItemIds.indexOf(item.uuid) === -1;
}
}

View File

@@ -22,30 +22,26 @@ class ItemParams {
}
paramsForSync() {
return this.__params(null, false);
return this.__params();
}
__params() {
let encryptionVersion = "001";
var itemCopy = _.cloneDeep(this.item);
console.assert(!this.item.dummy, "Item is dummy, should not have gotten here.", this.item.dummy)
var params = {uuid: this.item.uuid, content_type: this.item.content_type, deleted: this.item.deleted, created_at: this.item.created_at};
if(this.keys && !this.item.doNotEncrypt()) {
EncryptionHelper.encryptItem(itemCopy, this.keys, encryptionVersion);
params.content = itemCopy.content;
params.enc_item_key = itemCopy.enc_item_key;
if(encryptionVersion === "001") {
params.auth_hash = itemCopy.auth_hash;
} else {
var encryptedParams = EncryptionHelper.encryptItem(this.item, this.keys, encryptionVersion);
_.merge(params, encryptedParams);
if(encryptionVersion !== "001") {
params.auth_hash = null;
}
}
else {
params.content = this.forExportFile ? itemCopy.createContentJSONFromProperties() : "000" + Neeto.crypto.base64(JSON.stringify(itemCopy.createContentJSONFromProperties()));
params.content = this.forExportFile ? this.item.createContentJSONFromProperties() : "000" + Neeto.crypto.base64(JSON.stringify(this.item.createContentJSONFromProperties()));
if(!this.forExportFile) {
params.enc_item_key = null;
params.auth_hash = null;