extension css and logic updates

This commit is contained in:
Mo Bitar
2017-01-07 13:15:30 -06:00
parent ad678a5d21
commit a4f05b8c31
11 changed files with 225 additions and 70 deletions

View File

@@ -210,7 +210,7 @@ angular.module('app.frontend')
this.note.setDirty(true); this.note.setDirty(true);
apiController.sync(function(response){ apiController.sync(function(response){
if(!response) { if(response && response.error) {
this.note.presentation_name = original; this.note.presentation_name = original;
this.url.token = original; this.url.token = original;
alert("This URL is not available."); alert("This URL is not available.");

View File

@@ -32,9 +32,11 @@ angular.module('app.frontend')
this.showAccountMenu = !this.showAccountMenu; this.showAccountMenu = !this.showAccountMenu;
this.showFaq = false; this.showFaq = false;
this.showNewPasswordForm = false; this.showNewPasswordForm = false;
this.showExtensionsMenu = false;
} }
this.toggleExtensions = function() { this.toggleExtensions = function() {
this.showAccountMenu = false;
this.showExtensionsMenu = !this.showExtensionsMenu; this.showExtensionsMenu = !this.showExtensionsMenu;
} }
@@ -57,7 +59,13 @@ angular.module('app.frontend')
action.running = true; action.running = true;
extensionManager.executeAction(action, extension, null, function(response){ extensionManager.executeAction(action, extension, null, function(response){
action.running = false; action.running = false;
apiController.sync(null); if(response && response.error) {
action.error = true;
alert("There was an error performing this action. Please try again.");
} else {
action.error = false;
apiController.sync(null);
}
}) })
} }
@@ -118,7 +126,7 @@ angular.module('app.frontend')
$timeout(function(){ $timeout(function(){
this.isRefreshing = false; this.isRefreshing = false;
}.bind(this), 200) }.bind(this), 200)
if(!response) { if(response && response.error) {
alert("There was an error syncing. Please try again. If all else fails, log out and log back in."); alert("There was an error syncing. Please try again. If all else fails, log out and log back in.");
} else { } else {
this.syncUpdated(); this.syncUpdated();

View File

@@ -113,11 +113,15 @@ angular.module('app.frontend')
$scope.saveNote = function(note, callback) { $scope.saveNote = function(note, callback) {
note.setDirty(true); note.setDirty(true);
apiController.sync(function(){ apiController.sync(function(response){
note.hasChanges = false; if(response && response.error) {
alert("There was an error saving your note. Please try again.");
if(callback) { callback(false);
callback(true); } else {
note.hasChanges = false;
if(callback) {
callback(true);
}
} }
}) })
} }

View File

@@ -2,6 +2,11 @@ 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.running = false; // in case running=true was synced with server since model is uploaded nondiscriminatory
this.error = false;
if(this.lastExecuted) {
// is string
this.lastExecuted = new Date(this.lastExecuted);
}
} }
get permissionsString() { get permissionsString() {
@@ -47,6 +52,7 @@ class Extension extends Item {
super(json); super(json);
_.merge(this, json); _.merge(this, json);
this.encrypted = true;
this.content_type = "Extension"; this.content_type = "Extension";
} }

View File

@@ -57,6 +57,10 @@ angular.module('app.frontend')
Auth Auth
*/ */
this.isUserSignedIn = function() {
return this.user.email && this.retrieveMk();
}
this.getAuthParamsForEmail = function(email, callback) { this.getAuthParamsForEmail = function(email, callback) {
var request = Restangular.one("auth", "params"); var request = Restangular.one("auth", "params");
request.get({email: email}).then(function(response){ request.get({email: email}).then(function(response){
@@ -219,7 +223,6 @@ angular.module('app.frontend')
this.syncWithOptions = function(callback, options = {}) { this.syncWithOptions = function(callback, options = {}) {
if(!this.user.uuid) { if(!this.user.uuid) {
this.writeItemsToLocalStorage(function(responseItems){ this.writeItemsToLocalStorage(function(responseItems){
this.handleItemsResponse(responseItems);
modelManager.clearDirtyItems(); modelManager.clearDirtyItems();
if(callback) { if(callback) {
callback(); callback();
@@ -256,7 +259,7 @@ angular.module('app.frontend')
}.bind(this)) }.bind(this))
.catch(function(response){ .catch(function(response){
console.log("Sync error: ", response); console.log("Sync error: ", response);
callback(null); callback({error: "Sync error"});
}) })
} }
@@ -361,7 +364,7 @@ angular.module('app.frontend')
console.log("importing data", data); console.log("importing data", data);
this.decryptItems(data.items); this.decryptItems(data.items);
modelManager.mapResponseItemsToLocalModels(data.items); modelManager.mapResponseItemsToLocalModels(data.items);
modelManager.items.forEach(function(item){ modelManager.allItems.forEach(function(item){
item.setDirty(true); item.setDirty(true);
}) })
this.syncWithOptions(callback, {additionalFields: ["created_at", "updated_at"]}); this.syncWithOptions(callback, {additionalFields: ["created_at", "updated_at"]});
@@ -430,10 +433,10 @@ angular.module('app.frontend')
} }
this.writeItemsToLocalStorage = function(callback) { this.writeItemsToLocalStorage = function(callback) {
var items = _.map(modelManager.items, function(item){ var items = _.map(modelManager.allItems, function(item){
return this.paramsForItem(item, false, ["created_at", "updated_at"], false) return this.paramsForItem(item, false, ["created_at", "updated_at"], false)
}.bind(this)); }.bind(this));
console.log("writing items to local", items); console.log("Writing items to local", items);
this.writeToLocalStorage('items', items); this.writeToLocalStorage('items', items);
callback(items); callback(items);
} }
@@ -445,7 +448,7 @@ angular.module('app.frontend')
this.loadLocalItemsAndUser = function() { this.loadLocalItemsAndUser = function() {
var user = {}; var user = {};
var items = JSON.parse(localStorage.getItem('items')) || []; var items = JSON.parse(localStorage.getItem('items')) || [];
items = this.handleItemsResponse(items); items = this.handleItemsResponse(items, null);
Item.sortItemsByDate(items); Item.sortItemsByDate(items);
user.items = items; user.items = items;
user.shouldMerge = true; user.shouldMerge = true;

View File

@@ -62,7 +62,7 @@ class ExtensionManager {
deleteExtension(extension) { deleteExtension(extension) {
for(var action of extension.actions) { for(var action of extension.actions) {
_.pull(this.decryptedExtensions, extension); _.pull(this.decryptedExtensions, extension);
if(action.repeat_type) { if(action.repeat_mode) {
if(this.isRepeatActionEnabled(action)) { if(this.isRepeatActionEnabled(action)) {
this.disableRepeatAction(action); this.disableRepeatAction(action);
} }
@@ -105,7 +105,9 @@ class ExtensionManager {
refreshExtensionsFromServer() { refreshExtensionsFromServer() {
for (var url of this.enabledRepeatActionUrls) { for (var url of this.enabledRepeatActionUrls) {
var action = this.actionWithURL(url); var action = this.actionWithURL(url);
this.disableRepeatAction(action); if(action) {
this.disableRepeatAction(action);
}
} }
for(var ext of this.extensions) { for(var ext of this.extensions) {
@@ -117,14 +119,24 @@ class ExtensionManager {
executeAction(action, extension, item, callback) { executeAction(action, extension, item, callback) {
if(this.extensionUsesEncryptedData(extension) && !this.apiController.isUserSignedIn()) {
alert("To send data encrypted, you must have an encryption key, and must therefore be signed in.");
callback(null);
return;
}
switch (action.verb) { switch (action.verb) {
case "get": { case "get": {
this.Restangular.oneUrl(action.url, action.url).get().then(function(response){ this.Restangular.oneUrl(action.url, action.url).get().then(function(response){
console.log("Execute action response", response); console.log("Execute action response", response);
action.error = false;
var items = response.items; var items = response.items;
this.modelManager.mapResponseItemsToLocalModels(items); this.modelManager.mapResponseItemsToLocalModels(items);
callback(items); callback(items);
}.bind(this)) }.bind(this))
.catch(function(response){
action.error = true;
})
break; break;
} }
@@ -133,6 +145,7 @@ class ExtensionManager {
var win = window.open(action.url, '_blank'); var win = window.open(action.url, '_blank');
win.focus(); win.focus();
callback(); callback();
break;
} }
case "post": { case "post": {
@@ -149,9 +162,11 @@ class ExtensionManager {
params.item = this.outgoingParamsForItem(item, extension); params.item = this.outgoingParamsForItem(item, extension);
} }
this.performPost(action, extension, params, function(items){ this.performPost(action, extension, params, function(response){
callback(items); callback(response);
}); });
break;
} }
default: { default: {
@@ -170,6 +185,7 @@ class ExtensionManager {
console.log("Disabling action", action); console.log("Disabling action", action);
_.pull(this.enabledRepeatActionUrls, action.url); _.pull(this.enabledRepeatActionUrls, action.url);
localStorage.setItem("enabledRepeatActionUrls", JSON.stringify(this.enabledRepeatActionUrls));
this.modelManager.removeItemChangeObserver(action.url); this.modelManager.removeItemChangeObserver(action.url);
console.assert(this.isRepeatActionEnabled(action) == false); console.assert(this.isRepeatActionEnabled(action) == false);
@@ -220,16 +236,15 @@ class ExtensionManager {
var diffInSeconds = (new Date() - lastExecuted)/1000; var diffInSeconds = (new Date() - lastExecuted)/1000;
if(diffInSeconds < action.repeat_timeout) { if(diffInSeconds < action.repeat_timeout) {
var delay = action.repeat_timeout - diffInSeconds; var delay = action.repeat_timeout - diffInSeconds;
console.log("Delaying action by", delay);
this.queueAction(action, extension, delay, changedItems); this.queueAction(action, extension, delay, changedItems);
return; return;
} }
} }
console.log("Performing action immediately", action);
action.lastExecuted = new Date(); action.lastExecuted = new Date();
console.log("Performing action immediately", action);
if(action.verb == "post") { if(action.verb == "post") {
var params = {}; var params = {};
params.items = changedItems.map(function(item){ params.items = changedItems.map(function(item){
@@ -251,11 +266,18 @@ class ExtensionManager {
_.merge(request, params); _.merge(request, params);
request.post().then(function(response){ request.post().then(function(response){
// console.log("watch action response", response); action.error = false;
if(callback) { if(callback) {
callback(response.plain()); callback(response.plain());
} }
}) })
.catch(function(response){
action.error = true;
console.log("Action error response:", response);
if(callback) {
callback({error: "Request error"});
}
})
} }
} }

View File

@@ -6,7 +6,19 @@ class ModelManager {
this.itemSyncObservers = []; this.itemSyncObservers = [];
this.itemChangeObservers = []; this.itemChangeObservers = [];
this.items = []; this.items = [];
this.extensions = []; this._extensions = [];
}
get allItems() {
return this.items.filter(function(item){
return !item.dummy;
})
}
get extensions() {
return this._extensions.filter(function(ext){
return !ext.deleted;
})
} }
allItemsMatchingTypes(contentTypes) { allItemsMatchingTypes(contentTypes) {
@@ -111,8 +123,8 @@ class ModelManager {
this.notes.unshift(item); this.notes.unshift(item);
} }
} else if(item.content_type == "Extension") { } else if(item.content_type == "Extension") {
if(!_.find(this.extensions, {uuid: item.uuid})) { if(!_.find(this._extensions, {uuid: item.uuid})) {
this.extensions.unshift(item); this._extensions.unshift(item);
} }
} }
}.bind(this)) }.bind(this))
@@ -199,7 +211,7 @@ class ModelManager {
} else if(item.content_type == "Note") { } else if(item.content_type == "Note") {
_.pull(this.notes, item); _.pull(this.notes, item);
} else if(item.content_type == "Extension") { } else if(item.content_type == "Extension") {
_.pull(this.extensions, item); _.pull(this._extensions, item);
} }
} }

View File

@@ -114,6 +114,10 @@
.email { .email {
font-size: 18px; font-size: 18px;
font-weight: bold; font-weight: bold;
margin-bottom: 2px;
}
.server {
margin-bottom: 10px; margin-bottom: 10px;
} }
@@ -286,8 +290,10 @@ Extensions
.extension { .extension {
margin-bottom: 18px; margin-bottom: 18px;
background-color: #ededed; background-color: #f6f6f6;
padding: 10px; border: 1px solid #f2f2f2;
padding: 14px 6px;
padding-bottom: 8px;
color: black; color: black;
a { a {
@@ -299,16 +305,18 @@ Extensions
> .name { > .name {
font-weight: bold; font-weight: bold;
font-size: 16px; font-size: 16px;
margin-bottom: 2px; margin-bottom: 6px;
text-align: center;
} }
.encryption-format { .encryption-format {
margin-top: 4px; margin-top: 4px;
font-size: 12px; font-size: 12px;
text-align: center;
> .title { > .title {
font-size: 13px; font-size: 13px;
font-weight: bold; // font-weight: bold;
margin-bottom: 2px; margin-bottom: 2px;
} }
} }
@@ -323,16 +331,44 @@ Extensions
font-size: 12px; font-size: 12px;
.action { .action {
padding: 13px;
margin-bottom: 10px; margin-bottom: 10px;
background-color: rgba(white, 0.9);
border: 1px solid rgba(gray, 0.15);
> .name { > .name {
font-weight: bold; font-weight: bold;
} }
> .permissions {
margin-top: 2px;
a {
font-weight: normal !important;
}
}
> .execute { > .execute {
font-weight: bold; font-weight: bold;
margin-bottom: 0px; margin-bottom: 0px;
font-size: 12px; font-size: 12px;
height: 30px;
padding-top: 7px;
text-align: center;
margin-top: 6px;
border: 1px solid rgba(gray, 0.15);
cursor: pointer;
color: $blue-color;
&:hover {
background-color: rgba(gray, 0.10);
}
.execution-spinner {
margin-left: auto;
margin-right: auto;
text-align: center;
margin-top: 3px;
}
} }
> .execute-type { > .execute-type {
@@ -340,9 +376,15 @@ Extensions
margin-bottom: 1px; margin-bottom: 1px;
} }
> .error {
color: red;
margin-top: 6px;
}
> .last-run { > .last-run {
opacity: 0.5; opacity: 0.5;
font-size: 12px; font-size: 11px;
margin-top: 6px;
} }
} }

View File

@@ -49,6 +49,7 @@
.account-item{"ng-if" => "ctrl.user.email"} .account-item{"ng-if" => "ctrl.user.email"}
.email {{ctrl.user.email}} .email {{ctrl.user.email}}
.server {{ctrl.serverData.url}}
.links{"ng-if" => "ctrl.user.email"} .links{"ng-if" => "ctrl.user.email"}
.link-item .link-item
%a{"ng-click" => "ctrl.changePasswordPressed()"} Change Password %a{"ng-click" => "ctrl.changePasswordPressed()"} Change Password
@@ -98,7 +99,7 @@
.extension{"ng-repeat" => "extension in ctrl.extensionManager.extensions"} .extension{"ng-repeat" => "extension in ctrl.extensionManager.extensions"}
.name {{extension.name}} .name {{extension.name}}
.encryption-format .encryption-format
.title Send data .title Send data:
%label %label
%input{"type" => "radio", "ng-model" => "extension.encrypted", "ng-value" => "true", "ng-change" => "ctrl.extensionManager.changeExtensionEncryptionFormat(true, extension)"} %input{"type" => "radio", "ng-model" => "extension.encrypted", "ng-value" => "true", "ng-change" => "ctrl.extensionManager.changeExtensionEncryptionFormat(true, extension)"}
Encrypted Encrypted
@@ -120,16 +121,18 @@
.encryption-type .encryption-type
%span {{action.encryptionModeString}} %span {{action.encryptionModeString}}
.execute .execute
%a{"ng-if" => "action.repeat_mode"} %div{"ng-if" => "action.repeat_mode"}
%span{"ng-if" => "ctrl.extensionManager.isRepeatActionEnabled(action)", "ng-click" => "ctrl.extensionManager.disableRepeatAction(action, extension)"} Disable %div{"ng-if" => "ctrl.extensionManager.isRepeatActionEnabled(action)", "ng-click" => "ctrl.extensionManager.disableRepeatAction(action, extension)"} Disable
%span{"ng-if" => "!ctrl.extensionManager.isRepeatActionEnabled(action)", "ng-click" => "ctrl.extensionManager.enableRepeatAction(action, extension)"} Enable %div{"ng-if" => "!ctrl.extensionManager.isRepeatActionEnabled(action)", "ng-click" => "ctrl.extensionManager.enableRepeatAction(action, extension)"} Enable
%a{"ng-if" => "!action.repeat_mode", "ng-click" => "ctrl.selectedAction(action, extension)"} %div{"ng-if" => "!action.repeat_mode", "ng-click" => "ctrl.selectedAction(action, extension)"}
%span{"ng-if" => "!action.running"} %div{"ng-if" => "!action.running"}
Run Perform Action
%span{"ng-if" => "action.running"} %div{"ng-if" => "action.running"}
.spinner{"style" => "margin-top: 3px;"} .spinner.execution-spinner
.last-run{"ng-if" => "action.lastExecuted && !action.running"} .last-run{"ng-if" => "!action.error && action.lastExecuted && !action.running"}
Last executed {{action.lastExecuted | appDateTime}} Last run {{action.lastExecuted | appDateTime}}
.error{"ng-if" => "action.error"}
Error performing action.
%a{"ng-click" => "ctrl.deleteExtension(extension)", "style" => "margin-top: 22px; display: block;"} Remove extension %a{"ng-click" => "ctrl.deleteExtension(extension)", "style" => "margin-top: 22px; display: block;"} Remove extension
.extension-link .extension-link

View File

@@ -659,7 +659,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
this.note.setDirty(true); this.note.setDirty(true);
apiController.sync(function (response) { apiController.sync(function (response) {
if (!response) { if (response && response.error) {
this.note.presentation_name = original; this.note.presentation_name = original;
this.url.token = original; this.url.token = original;
alert("This URL is not available."); alert("This URL is not available.");
@@ -744,9 +744,11 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
this.showAccountMenu = !this.showAccountMenu; this.showAccountMenu = !this.showAccountMenu;
this.showFaq = false; this.showFaq = false;
this.showNewPasswordForm = false; this.showNewPasswordForm = false;
this.showExtensionsMenu = false;
}; };
this.toggleExtensions = function () { this.toggleExtensions = function () {
this.showAccountMenu = false;
this.showExtensionsMenu = !this.showExtensionsMenu; this.showExtensionsMenu = !this.showExtensionsMenu;
}; };
@@ -769,7 +771,13 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
action.running = true; action.running = true;
extensionManager.executeAction(action, extension, null, function (response) { extensionManager.executeAction(action, extension, null, function (response) {
action.running = false; action.running = false;
apiController.sync(null); if (response && response.error) {
action.error = true;
alert("There was an error performing this action. Please try again.");
} else {
action.error = false;
apiController.sync(null);
}
}); });
}; };
@@ -827,7 +835,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
$timeout(function () { $timeout(function () {
this.isRefreshing = false; this.isRefreshing = false;
}.bind(this), 200); }.bind(this), 200);
if (!response) { if (response && response.error) {
alert("There was an error syncing. Please try again. If all else fails, log out and log back in."); alert("There was an error syncing. Please try again. If all else fails, log out and log back in.");
} else { } else {
this.syncUpdated(); this.syncUpdated();
@@ -1036,11 +1044,15 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
$scope.saveNote = function (note, callback) { $scope.saveNote = function (note, callback) {
note.setDirty(true); note.setDirty(true);
apiController.sync(function () { apiController.sync(function (response) {
note.hasChanges = false; if (response && response.error) {
alert("There was an error saving your note. Please try again.");
if (callback) { callback(false);
callback(true); } else {
note.hasChanges = false;
if (callback) {
callback(true);
}
} }
}); });
}; };
@@ -1498,6 +1510,11 @@ var Action = function () {
_.merge(this, json); _.merge(this, json);
this.running = false; // in case running=true was synced with server since model is uploaded nondiscriminatory this.running = false; // in case running=true was synced with server since model is uploaded nondiscriminatory
this.error = false;
if (this.lastExecuted) {
// is string
this.lastExecuted = new Date(this.lastExecuted);
}
} }
_createClass(Action, [{ _createClass(Action, [{
@@ -1574,6 +1591,7 @@ var Extension = function (_Item) {
_.merge(_this3, json); _.merge(_this3, json);
_this3.encrypted = true;
_this3.content_type = "Extension"; _this3.content_type = "Extension";
return _this3; return _this3;
} }
@@ -1927,6 +1945,10 @@ var User = function User(json_obj) {
Auth Auth
*/ */
this.isUserSignedIn = function () {
return this.user.email && this.retrieveMk();
};
this.getAuthParamsForEmail = function (email, callback) { this.getAuthParamsForEmail = function (email, callback) {
var request = Restangular.one("auth", "params"); var request = Restangular.one("auth", "params");
request.get({ email: email }).then(function (response) { request.get({ email: email }).then(function (response) {
@@ -2084,7 +2106,6 @@ var User = function User(json_obj) {
if (!this.user.uuid) { if (!this.user.uuid) {
this.writeItemsToLocalStorage(function (responseItems) { this.writeItemsToLocalStorage(function (responseItems) {
this.handleItemsResponse(responseItems);
modelManager.clearDirtyItems(); modelManager.clearDirtyItems();
if (callback) { if (callback) {
callback(); callback();
@@ -2120,7 +2141,7 @@ var User = function User(json_obj) {
} }
}.bind(this)).catch(function (response) { }.bind(this)).catch(function (response) {
console.log("Sync error: ", response); console.log("Sync error: ", response);
callback(null); callback({ error: "Sync error" });
}); });
}; };
@@ -2226,7 +2247,7 @@ var User = function User(json_obj) {
console.log("importing data", data); console.log("importing data", data);
this.decryptItems(data.items); this.decryptItems(data.items);
modelManager.mapResponseItemsToLocalModels(data.items); modelManager.mapResponseItemsToLocalModels(data.items);
modelManager.items.forEach(function (item) { modelManager.allItems.forEach(function (item) {
item.setDirty(true); item.setDirty(true);
}); });
this.syncWithOptions(callback, { additionalFields: ["created_at", "updated_at"] }); this.syncWithOptions(callback, { additionalFields: ["created_at", "updated_at"] });
@@ -2290,10 +2311,10 @@ var User = function User(json_obj) {
}; };
this.writeItemsToLocalStorage = function (callback) { this.writeItemsToLocalStorage = function (callback) {
var items = _.map(modelManager.items, function (item) { var items = _.map(modelManager.allItems, function (item) {
return this.paramsForItem(item, false, ["created_at", "updated_at"], false); return this.paramsForItem(item, false, ["created_at", "updated_at"], false);
}.bind(this)); }.bind(this));
console.log("writing items to local", items); console.log("Writing items to local", items);
this.writeToLocalStorage('items', items); this.writeToLocalStorage('items', items);
callback(items); callback(items);
}; };
@@ -2305,7 +2326,7 @@ var User = function User(json_obj) {
this.loadLocalItemsAndUser = function () { this.loadLocalItemsAndUser = function () {
var user = {}; var user = {};
var items = JSON.parse(localStorage.getItem('items')) || []; var items = JSON.parse(localStorage.getItem('items')) || [];
items = this.handleItemsResponse(items); items = this.handleItemsResponse(items, null);
Item.sortItemsByDate(items); Item.sortItemsByDate(items);
user.items = items; user.items = items;
user.shouldMerge = true; user.shouldMerge = true;
@@ -2960,7 +2981,7 @@ var ExtensionManager = function () {
var action = _step8.value; var action = _step8.value;
_.pull(this.decryptedExtensions, extension); _.pull(this.decryptedExtensions, extension);
if (action.repeat_type) { if (action.repeat_mode) {
if (this.isRepeatActionEnabled(action)) { if (this.isRepeatActionEnabled(action)) {
this.disableRepeatAction(action); this.disableRepeatAction(action);
} }
@@ -3026,7 +3047,9 @@ var ExtensionManager = function () {
var url = _step9.value; var url = _step9.value;
var action = this.actionWithURL(url); var action = this.actionWithURL(url);
this.disableRepeatAction(action); if (action) {
this.disableRepeatAction(action);
}
} }
} catch (err) { } catch (err) {
_didIteratorError9 = true; _didIteratorError9 = true;
@@ -3074,15 +3097,24 @@ var ExtensionManager = function () {
key: 'executeAction', key: 'executeAction',
value: function executeAction(action, extension, item, callback) { value: function executeAction(action, extension, item, callback) {
if (this.extensionUsesEncryptedData(extension) && !this.apiController.isUserSignedIn()) {
alert("To send data encrypted, you must have an encryption key, and must therefore be signed in.");
callback(null);
return;
}
switch (action.verb) { switch (action.verb) {
case "get": case "get":
{ {
this.Restangular.oneUrl(action.url, action.url).get().then(function (response) { this.Restangular.oneUrl(action.url, action.url).get().then(function (response) {
console.log("Execute action response", response); console.log("Execute action response", response);
action.error = false;
var items = response.items; var items = response.items;
this.modelManager.mapResponseItemsToLocalModels(items); this.modelManager.mapResponseItemsToLocalModels(items);
callback(items); callback(items);
}.bind(this)); }.bind(this)).catch(function (response) {
action.error = true;
});
break; break;
} }
@@ -3092,6 +3124,7 @@ var ExtensionManager = function () {
var win = window.open(action.url, '_blank'); var win = window.open(action.url, '_blank');
win.focus(); win.focus();
callback(); callback();
break;
} }
case "post": case "post":
@@ -3108,9 +3141,11 @@ var ExtensionManager = function () {
params.item = this.outgoingParamsForItem(item, extension); params.item = this.outgoingParamsForItem(item, extension);
} }
this.performPost(action, extension, params, function (items) { this.performPost(action, extension, params, function (response) {
callback(items); callback(response);
}); });
break;
} }
default: default:
@@ -3130,6 +3165,7 @@ var ExtensionManager = function () {
console.log("Disabling action", action); console.log("Disabling action", action);
_.pull(this.enabledRepeatActionUrls, action.url); _.pull(this.enabledRepeatActionUrls, action.url);
localStorage.setItem("enabledRepeatActionUrls", JSON.stringify(this.enabledRepeatActionUrls));
this.modelManager.removeItemChangeObserver(action.url); this.modelManager.removeItemChangeObserver(action.url);
console.assert(this.isRepeatActionEnabled(action) == false); console.assert(this.isRepeatActionEnabled(action) == false);
@@ -3182,16 +3218,15 @@ var ExtensionManager = function () {
var diffInSeconds = (new Date() - lastExecuted) / 1000; var diffInSeconds = (new Date() - lastExecuted) / 1000;
if (diffInSeconds < action.repeat_timeout) { if (diffInSeconds < action.repeat_timeout) {
var delay = action.repeat_timeout - diffInSeconds; var delay = action.repeat_timeout - diffInSeconds;
console.log("Delaying action by", delay);
this.queueAction(action, extension, delay, changedItems); this.queueAction(action, extension, delay, changedItems);
return; return;
} }
} }
console.log("Performing action immediately", action);
action.lastExecuted = new Date(); action.lastExecuted = new Date();
console.log("Performing action immediately", action);
if (action.verb == "post") { if (action.verb == "post") {
var params = {}; var params = {};
params.items = changedItems.map(function (item) { params.items = changedItems.map(function (item) {
@@ -3215,10 +3250,16 @@ var ExtensionManager = function () {
_.merge(request, params); _.merge(request, params);
request.post().then(function (response) { request.post().then(function (response) {
// console.log("watch action response", response); action.error = false;
if (callback) { if (callback) {
callback(response.plain()); callback(response.plain());
} }
}).catch(function (response) {
action.error = true;
console.log("Action error response:", response);
if (callback) {
callback({ error: "Request error" });
}
}); });
} }
}, { }, {
@@ -3269,7 +3310,7 @@ var ModelManager = function () {
this.itemSyncObservers = []; this.itemSyncObservers = [];
this.itemChangeObservers = []; this.itemChangeObservers = [];
this.items = []; this.items = [];
this.extensions = []; this._extensions = [];
} }
_createClass(ModelManager, [{ _createClass(ModelManager, [{
@@ -3448,8 +3489,8 @@ var ModelManager = function () {
this.notes.unshift(item); this.notes.unshift(item);
} }
} else if (item.content_type == "Extension") { } else if (item.content_type == "Extension") {
if (!_.find(this.extensions, { uuid: item.uuid })) { if (!_.find(this._extensions, { uuid: item.uuid })) {
this.extensions.unshift(item); this._extensions.unshift(item);
} }
} }
}.bind(this)); }.bind(this));
@@ -3567,7 +3608,7 @@ var ModelManager = function () {
} else if (item.content_type == "Note") { } else if (item.content_type == "Note") {
_.pull(this.notes, item); _.pull(this.notes, item);
} else if (item.content_type == "Extension") { } else if (item.content_type == "Extension") {
_.pull(this.extensions, item); _.pull(this._extensions, item);
} }
} }
@@ -3593,6 +3634,20 @@ var ModelManager = function () {
itemOne.setDirty(true); itemOne.setDirty(true);
itemTwo.setDirty(true); itemTwo.setDirty(true);
} }
}, {
key: 'allItems',
get: function get() {
return this.items.filter(function (item) {
return !item.dummy;
});
}
}, {
key: 'extensions',
get: function get() {
return this._extensions.filter(function (ext) {
return !ext.deleted;
});
}
}, { }, {
key: 'filteredNotes', key: 'filteredNotes',
get: function get() { get: function get() {

File diff suppressed because one or more lines are too long