Action menu updates, ionicons minimal

This commit is contained in:
Mo Bitar
2018-01-19 12:22:17 -06:00
parent 59fb649bd4
commit 5be2402f65
25 changed files with 185 additions and 5642 deletions

View File

@@ -8,55 +8,12 @@ class Action {
this.lastExecuted = new Date(this.lastExecuted);
}
}
permissionsString() {
if(!this.permissions) {
return "";
}
var permission = this.permissions.charAt(0).toUpperCase() + this.permissions.slice(1); // capitalize first letter
permission += ": ";
for(var contentType of this.content_types) {
if(contentType == "*") {
permission += "All items";
} else {
permission += contentType;
}
permission += " ";
}
return permission;
}
encryptionModeString() {
if(this.verb != "post") {
return null;
}
var encryptionMode = "This action accepts data ";
if(this.accepts_encrypted && this.accepts_decrypted) {
encryptionMode += "encrypted or decrypted.";
} else {
if(this.accepts_encrypted) {
encryptionMode += "encrypted.";
} else {
encryptionMode += "decrypted.";
}
}
return encryptionMode;
}
}
class Extension extends Item {
constructor(json) {
super(json);
if(this.encrypted === null || this.encrypted === undefined) {
// Default to encrypted on creation.
this.encrypted = true;
}
if(json.actions) {
this.actions = json.actions.map(function(action){
return new Action(action);
@@ -68,12 +25,6 @@ class Extension extends Item {
}
}
actionsInGlobalContext() {
return this.actions.filter(function(action){
return action.context == "global";
})
}
actionsWithContextForItem(item) {
return this.actions.filter(function(action){
return action.context == item.content_type || action.context == "Item";
@@ -86,12 +37,6 @@ class Extension extends Item {
this.description = content.description;
this.url = content.url;
if(content.encrypted !== null && content.encrypted !== undefined) {
this.encrypted = content.encrypted;
} else {
this.encrypted = true;
}
this.supported_types = content.supported_types;
if(content.actions) {
this.actions = content.actions.map(function(action){
@@ -114,8 +59,7 @@ class Extension extends Item {
url: this.url,
description: this.description,
actions: this.actions,
supported_types: this.supported_types,
encrypted: this.encrypted
supported_types: this.supported_types
};
_.merge(params, super.structureParams());

View File

@@ -7,16 +7,6 @@ class ActionsManager {
this.enabledRepeatActionUrls = JSON.parse(storageManager.getItem("enabledRepeatActionUrls")) || [];
this.syncManager = syncManager;
this.storageManager = storageManager;
modelManager.addItemSyncObserver("actionsManager", "Extension", function(allItems, validItems, deletedItems){
for (var ext of validItems) {
for (var action of ext.actions) {
if(_.includes(this.enabledRepeatActionUrls, action.url)) {
this.enableRepeatAction(action, ext);
}
}
}
}.bind(this))
}
get extensions() {
@@ -40,14 +30,6 @@ class ActionsManager {
}
deleteExtension(extension) {
for(var action of extension.actions) {
if(action.repeat_mode) {
if(this.isRepeatActionEnabled(action)) {
this.disableRepeatAction(action);
}
}
}
this.modelManager.setItemToBeDeleted(extension);
this.syncManager.sync(null);
}
@@ -90,7 +72,6 @@ class ActionsManager {
handleExtensionLoadExternalResponseItem(url, externalResponseItem) {
// Don't allow remote response to set these flags
delete externalResponseItem.encrypted;
delete externalResponseItem.uuid;
var extension = _.find(this.extensions, {url: url});
@@ -125,13 +106,6 @@ class ActionsManager {
}
refreshExtensionsFromServer() {
for (var url of this.enabledRepeatActionUrls) {
var action = this.actionWithURL(url);
if(action) {
this.disableRepeatAction(action);
}
}
for(var ext of this.extensions) {
this.retrieveExtensionFromServer(ext.url, function(extension){
extension.setDirty(true);
@@ -141,12 +115,6 @@ class ActionsManager {
executeAction(action, extension, item, callback) {
if(extension.encrypted && this.authManager.offline()) {
alert("To send data encrypted, you must have an encryption key, and must therefore be signed in.");
callback(null);
return;
}
var customCallback = function(response) {
action.running = false;
callback(response);
@@ -154,6 +122,8 @@ class ActionsManager {
action.running = true;
let decrypted = action.access_type == "decrypted";
switch (action.verb) {
case "get": {
@@ -204,12 +174,12 @@ class ActionsManager {
if(action.all) {
var items = this.modelManager.allItemsMatchingTypes(action.content_types);
params.items = items.map(function(item){
var params = this.outgoingParamsForItem(item, extension);
var params = this.outgoingParamsForItem(item, extension, decrypted);
return params;
}.bind(this))
} else {
params.items = [this.outgoingParamsForItem(item, extension)];
params.items = [this.outgoingParamsForItem(item, extension, decrypted)];
}
this.performPost(action, extension, params, function(response){
@@ -231,35 +201,6 @@ class ActionsManager {
return _.includes(this.enabledRepeatActionUrls, action.url);
}
disableRepeatAction(action, extension) {
_.pull(this.enabledRepeatActionUrls, action.url);
this.storageManager.setItem("enabledRepeatActionUrls", JSON.stringify(this.enabledRepeatActionUrls));
this.modelManager.removeItemChangeObserver(action.url);
console.assert(this.isRepeatActionEnabled(action) == false);
}
enableRepeatAction(action, extension) {
if(!_.find(this.enabledRepeatActionUrls, action.url)) {
this.enabledRepeatActionUrls.push(action.url);
this.storageManager.setItem("enabledRepeatActionUrls", JSON.stringify(this.enabledRepeatActionUrls));
}
if(action.repeat_mode) {
if(action.repeat_mode == "watch") {
this.modelManager.addItemChangeObserver(action.url, action.content_types, function(changedItems){
this.triggerWatchAction(action, extension, changedItems);
}.bind(this))
}
if(action.repeat_mode == "loop") {
// todo
}
}
}
queueAction(action, extension, delay, changedItems) {
this.actionQueue = this.actionQueue || [];
if(_.find(this.actionQueue, {url: action.url})) {
@@ -274,38 +215,9 @@ class ActionsManager {
}.bind(this), delay * 1000);
}
triggerWatchAction(action, extension, changedItems) {
if(action.repeat_timeout > 0) {
var lastExecuted = action.lastExecuted;
var diffInSeconds = (new Date() - lastExecuted)/1000;
if(diffInSeconds < action.repeat_timeout) {
var delay = action.repeat_timeout - diffInSeconds;
this.queueAction(action, extension, delay, changedItems);
return;
}
}
action.lastExecuted = new Date();
if(action.verb == "post") {
var params = {};
params.items = changedItems.map(function(item){
var params = this.outgoingParamsForItem(item, extension);
return params;
}.bind(this))
action.running = true;
this.performPost(action, extension, params, function(){
action.running = false;
});
} else {
// todo
}
}
outgoingParamsForItem(item, extension) {
outgoingParamsForItem(item, extension, decrypted = false) {
var keys = this.authManager.keys();
if(!extension.encrypted) {
if(decrypted) {
keys = null;
}
var itemParams = new ItemParams(item, keys, this.authManager.protocolVersion());
@@ -313,11 +225,6 @@ class ActionsManager {
}
performPost(action, extension, params, callback) {
if(extension.encrypted) {
params.auth_params = this.authManager.getAuthParams();
}
this.httpManager.postAbsolute(action.url, params, function(response){
action.error = false;
if(callback) {

View File

@@ -23,12 +23,12 @@ class ActionsMenu {
}
$scope.executeAction = function(action, extension, parentAction) {
if(!$scope.isActionEnabled(action, extension)) {
alert("This action requires " + action.access_type + " access to this note. You can change this setting in the Extensions menu on the bottom of the app.");
return;
}
if(action.verb == "nested") {
action.showNestedActions = !action.showNestedActions;
if(!action.subrows) {
action.subrows = $scope.subRowsForAction(action, extension);
} else {
action.subrows = null;
}
return;
}
action.running = true;
@@ -41,7 +41,7 @@ class ActionsMenu {
// keep nested state
if(parentAction) {
var matchingAction = _.find(ext.actions, {label: parentAction.label});
matchingAction.showNestedActions = true;
matchingAction.subrows = $scope.subRowsForAction(parentAction, extension);
}
});
})
@@ -60,21 +60,25 @@ class ActionsMenu {
}
}
$scope.isActionEnabled = function(action, extension) {
if(action.access_type) {
var extEncryptedAccess = extension.encrypted;
if(action.access_type == "decrypted" && extEncryptedAccess) {
return false;
} else if(action.access_type == "encrypted" && !extEncryptedAccess) {
return false;
}
$scope.subRowsForAction = function(parentAction, extension) {
if(!parentAction.subactions) {
return null;
}
return true;
return parentAction.subactions.map((subaction) => {
return {
onClick: ($event) => {
this.executeAction(subaction, extension, parentAction);
$event.stopPropagation();
},
title: subaction.label,
subtitle: subaction.desc,
spinnerClass: subaction.running ? 'info' : null
}
})
}
$scope.accessTypeForExtension = function(extension) {
return extension.encrypted ? "encrypted" : "decrypted";
}
}
}

View File

@@ -11,7 +11,9 @@ class MenuRow {
hasButton: "=",
buttonText: "=",
buttonClass: "=",
buttonAction: "&"
buttonAction: "&",
spinnerClass: "=",
subRows: "="
};
}