adjustments

This commit is contained in:
Mo Bitar
2017-01-05 19:40:58 -06:00
parent 6306f2a316
commit d99d3919de
6 changed files with 56 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ class Action {
constructor(json) { constructor(json) {
_.merge(this, json); _.merge(this, json);
this.running = false; // in case running=true was synced with server since model is uploaded nondiscriminatory
this.actionVerb = this.type; this.actionVerb = this.type;
var comps = this.type.split(":"); var comps = this.type.split(":");
@@ -9,12 +10,16 @@ class Action {
this.actionType = comps[0]; // 'watch', 'poll', or 'all' this.actionType = comps[0]; // 'watch', 'poll', or 'all'
this.repeatable = this.actionType == "watch" || this.actionType == "poll"; this.repeatable = this.actionType == "watch" || this.actionType == "poll";
this.actionVerb = comps[1]; // http verb : "get", "post", "show" this.actionVerb = comps[1]; // http verb : "get", "post", "show"
this.repeatFrequency = comps[2]; this.repeatFrequency = comps[2];
} }
} }
structureContentTypes() {
return this.structures.map(function(structure){
return structure.type;
})
}
} }
class Extension extends Item { class Extension extends Item {

View File

@@ -234,8 +234,6 @@ angular.module('app.frontend')
return this.createRequestParamsForItem(item, options.additionalFields); return this.createRequestParamsForItem(item, options.additionalFields);
}.bind(this)); }.bind(this));
// console.log("syncing items", request.items);
if(this.syncToken) { if(this.syncToken) {
request.sync_token = this.syncToken; request.sync_token = this.syncToken;
} }
@@ -273,6 +271,10 @@ angular.module('app.frontend')
return this.paramsForItem(item, !item.isPublic(), additionalFields, false); return this.paramsForItem(item, !item.isPublic(), additionalFields, false);
} }
this.paramsForExternalUse = function(item) {
return _.omit(this.paramsForItem(item, false, ["created_at", "updated_at"], true), ["deleted"]);
}
this.paramsForItem = function(item, encrypted, additionalFields, forExportFile) { this.paramsForItem = function(item, encrypted, additionalFields, forExportFile) {
var itemCopy = _.cloneDeep(item); var itemCopy = _.cloneDeep(item);
@@ -288,7 +290,7 @@ angular.module('app.frontend')
params.auth_hash = itemCopy.auth_hash; params.auth_hash = itemCopy.auth_hash;
} }
else { else {
params.content = forExportFile ? itemCopy.content : "000" + Neeto.crypto.base64(JSON.stringify(itemCopy.createContentJSONFromProperties())); params.content = forExportFile ? itemCopy.createContentJSONFromProperties() : "000" + Neeto.crypto.base64(JSON.stringify(itemCopy.createContentJSONFromProperties()));
if(!forExportFile) { if(!forExportFile) {
params.enc_item_key = null; params.enc_item_key = null;
params.auth_hash = null; params.auth_hash = null;
@@ -378,8 +380,8 @@ angular.module('app.frontend')
return textFile; return textFile;
}.bind(this); }.bind(this);
var items = _.map(modelManager.items, function(item){ var items = _.map(modelManager.allItemsMatchingTypes(["Tag", "Note"]), function(item){
return _.omit(this.paramsForItem(item, false, ["created_at", "updated_at"], true), ["deleted"]); return this.paramsForExternalUse(item);
}.bind(this)); }.bind(this));
var data = { var data = {

View File

@@ -90,7 +90,7 @@ class ExtensionManager {
} }
else if(action.actionType == "all") { else if(action.actionType == "all") {
var allItems = this.modelManager.allItems(); var allItems = this.modelManager.allItemsMatchingTypes(action.structureContentTypes());
this.performPost(action, allItems, function(items){ this.performPost(action, allItems, function(items){
callback(items); callback(items);
}); });
@@ -143,7 +143,7 @@ class ExtensionManager {
} }
outgoingParamsForItem(item) { outgoingParamsForItem(item) {
return this.apiController.paramsForItem(item, false, null, true); return this.apiController.paramsForExternalUse(item);
} }
triggerWatchAction(action, changedItems) { triggerWatchAction(action, changedItems) {

View File

@@ -9,8 +9,8 @@ class ModelManager {
this.extensions = []; this.extensions = [];
} }
allItems() { allItemsMatchingTypes(contentTypes) {
return this.items.filter(function(item){return !item.dummy}) return this.items.filter(function(item){return contentTypes.includes(item.content_type) && !item.dummy})
} }
findItem(itemId) { findItem(itemId) {

View File

@@ -1491,24 +1491,36 @@ var Item = function () {
}(); }();
; ;
var Action = function Action(json) { var Action = function () {
_classCallCheck(this, Action); function Action(json) {
_classCallCheck(this, Action);
_.merge(this, json); _.merge(this, json);
this.actionVerb = this.type; this.running = false; // in case running=true was synced with server since model is uploaded nondiscriminatory
this.actionVerb = this.type;
var comps = this.type.split(":"); var comps = this.type.split(":");
if (comps.length > 1) { if (comps.length > 1) {
this.actionType = comps[0]; // 'watch', 'poll', or 'all' this.actionType = comps[0]; // 'watch', 'poll', or 'all'
this.repeatable = this.actionType == "watch" || this.actionType == "poll"; this.repeatable = this.actionType == "watch" || this.actionType == "poll";
this.actionVerb = comps[1]; // http verb : "get", "post", "show"
this.actionVerb = comps[1]; // http verb : "get", "post", "show" this.repeatFrequency = comps[2];
}
this.repeatFrequency = comps[2];
} }
};
_createClass(Action, [{
key: 'structureContentTypes',
value: function structureContentTypes() {
return this.structures.map(function (structure) {
return structure.type;
});
}
}]);
return Action;
}();
var Extension = function (_Item) { var Extension = function (_Item) {
_inherits(Extension, _Item); _inherits(Extension, _Item);
@@ -2031,8 +2043,6 @@ var User = function User(json_obj) {
return this.createRequestParamsForItem(item, options.additionalFields); return this.createRequestParamsForItem(item, options.additionalFields);
}.bind(this)); }.bind(this));
// console.log("syncing items", request.items);
if (this.syncToken) { if (this.syncToken) {
request.sync_token = this.syncToken; request.sync_token = this.syncToken;
} }
@@ -2069,6 +2079,10 @@ var User = function User(json_obj) {
return this.paramsForItem(item, !item.isPublic(), additionalFields, false); return this.paramsForItem(item, !item.isPublic(), additionalFields, false);
}; };
this.paramsForExternalUse = function (item) {
return _.omit(this.paramsForItem(item, false, ["created_at", "updated_at"], true), ["deleted"]);
};
this.paramsForItem = function (item, encrypted, additionalFields, forExportFile) { this.paramsForItem = function (item, encrypted, additionalFields, forExportFile) {
var itemCopy = _.cloneDeep(item); var itemCopy = _.cloneDeep(item);
@@ -2083,7 +2097,7 @@ var User = function User(json_obj) {
params.enc_item_key = itemCopy.enc_item_key; params.enc_item_key = itemCopy.enc_item_key;
params.auth_hash = itemCopy.auth_hash; params.auth_hash = itemCopy.auth_hash;
} else { } else {
params.content = forExportFile ? itemCopy.content : "000" + Neeto.crypto.base64(JSON.stringify(itemCopy.createContentJSONFromProperties())); params.content = forExportFile ? itemCopy.createContentJSONFromProperties() : "000" + Neeto.crypto.base64(JSON.stringify(itemCopy.createContentJSONFromProperties()));
if (!forExportFile) { if (!forExportFile) {
params.enc_item_key = null; params.enc_item_key = null;
params.auth_hash = null; params.auth_hash = null;
@@ -2175,8 +2189,8 @@ var User = function User(json_obj) {
return textFile; return textFile;
}.bind(this); }.bind(this);
var items = _.map(modelManager.items, function (item) { var items = _.map(modelManager.allItemsMatchingTypes(["Tag", "Note"]), function (item) {
return _.omit(this.paramsForItem(item, false, ["created_at", "updated_at"], true), ["deleted"]); return this.paramsForExternalUse(item);
}.bind(this)); }.bind(this));
var data = { var data = {
@@ -2901,7 +2915,7 @@ var ExtensionManager = function () {
win.focus(); win.focus();
callback(); callback();
} else if (action.actionType == "all") { } else if (action.actionType == "all") {
var allItems = this.modelManager.allItems(); var allItems = this.modelManager.allItemsMatchingTypes(action.structureContentTypes());
this.performPost(action, allItems, function (items) { this.performPost(action, allItems, function (items) {
callback(items); callback(items);
}); });
@@ -2980,7 +2994,7 @@ var ExtensionManager = function () {
}, { }, {
key: 'outgoingParamsForItem', key: 'outgoingParamsForItem',
value: function outgoingParamsForItem(item) { value: function outgoingParamsForItem(item) {
return this.apiController.paramsForItem(item, false, null, true); return this.apiController.paramsForExternalUse(item);
} }
}, { }, {
key: 'triggerWatchAction', key: 'triggerWatchAction',
@@ -3074,10 +3088,10 @@ var ModelManager = function () {
} }
_createClass(ModelManager, [{ _createClass(ModelManager, [{
key: 'allItems', key: 'allItemsMatchingTypes',
value: function allItems() { value: function allItemsMatchingTypes(contentTypes) {
return this.items.filter(function (item) { return this.items.filter(function (item) {
return !item.dummy; return contentTypes.includes(item.content_type) && !item.dummy;
}); });
} }
}, { }, {

File diff suppressed because one or more lines are too long