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);
apiController.sync(function(response){
if(!response) {
if(response && response.error) {
this.note.presentation_name = original;
this.url.token = original;
alert("This URL is not available.");

View File

@@ -32,9 +32,11 @@ angular.module('app.frontend')
this.showAccountMenu = !this.showAccountMenu;
this.showFaq = false;
this.showNewPasswordForm = false;
this.showExtensionsMenu = false;
}
this.toggleExtensions = function() {
this.showAccountMenu = false;
this.showExtensionsMenu = !this.showExtensionsMenu;
}
@@ -57,7 +59,13 @@ angular.module('app.frontend')
action.running = true;
extensionManager.executeAction(action, extension, null, function(response){
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(){
this.isRefreshing = false;
}.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.");
} else {
this.syncUpdated();

View File

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

View File

@@ -2,6 +2,11 @@ class Action {
constructor(json) {
_.merge(this, json);
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() {
@@ -47,6 +52,7 @@ class Extension extends Item {
super(json);
_.merge(this, json);
this.encrypted = true;
this.content_type = "Extension";
}

View File

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

View File

@@ -62,7 +62,7 @@ class ExtensionManager {
deleteExtension(extension) {
for(var action of extension.actions) {
_.pull(this.decryptedExtensions, extension);
if(action.repeat_type) {
if(action.repeat_mode) {
if(this.isRepeatActionEnabled(action)) {
this.disableRepeatAction(action);
}
@@ -105,7 +105,9 @@ class ExtensionManager {
refreshExtensionsFromServer() {
for (var url of this.enabledRepeatActionUrls) {
var action = this.actionWithURL(url);
this.disableRepeatAction(action);
if(action) {
this.disableRepeatAction(action);
}
}
for(var ext of this.extensions) {
@@ -117,14 +119,24 @@ class ExtensionManager {
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) {
case "get": {
this.Restangular.oneUrl(action.url, action.url).get().then(function(response){
console.log("Execute action response", response);
action.error = false;
var items = response.items;
this.modelManager.mapResponseItemsToLocalModels(items);
callback(items);
}.bind(this))
.catch(function(response){
action.error = true;
})
break;
}
@@ -133,6 +145,7 @@ class ExtensionManager {
var win = window.open(action.url, '_blank');
win.focus();
callback();
break;
}
case "post": {
@@ -149,9 +162,11 @@ class ExtensionManager {
params.item = this.outgoingParamsForItem(item, extension);
}
this.performPost(action, extension, params, function(items){
callback(items);
this.performPost(action, extension, params, function(response){
callback(response);
});
break;
}
default: {
@@ -170,6 +185,7 @@ class ExtensionManager {
console.log("Disabling action", action);
_.pull(this.enabledRepeatActionUrls, action.url);
localStorage.setItem("enabledRepeatActionUrls", JSON.stringify(this.enabledRepeatActionUrls));
this.modelManager.removeItemChangeObserver(action.url);
console.assert(this.isRepeatActionEnabled(action) == false);
@@ -220,16 +236,15 @@ class ExtensionManager {
var diffInSeconds = (new Date() - lastExecuted)/1000;
if(diffInSeconds < action.repeat_timeout) {
var delay = action.repeat_timeout - diffInSeconds;
console.log("Delaying action by", delay);
this.queueAction(action, extension, delay, changedItems);
return;
}
}
console.log("Performing action immediately", action);
action.lastExecuted = new Date();
console.log("Performing action immediately", action);
if(action.verb == "post") {
var params = {};
params.items = changedItems.map(function(item){
@@ -251,11 +266,18 @@ class ExtensionManager {
_.merge(request, params);
request.post().then(function(response){
// console.log("watch action response", response);
action.error = false;
if(callback) {
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.itemChangeObservers = [];
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) {
@@ -111,8 +123,8 @@ class ModelManager {
this.notes.unshift(item);
}
} else if(item.content_type == "Extension") {
if(!_.find(this.extensions, {uuid: item.uuid})) {
this.extensions.unshift(item);
if(!_.find(this._extensions, {uuid: item.uuid})) {
this._extensions.unshift(item);
}
}
}.bind(this))
@@ -199,7 +211,7 @@ class ModelManager {
} else if(item.content_type == "Note") {
_.pull(this.notes, item);
} else if(item.content_type == "Extension") {
_.pull(this.extensions, item);
_.pull(this._extensions, item);
}
}