contextual extension menu
This commit is contained in:
@@ -18,7 +18,6 @@ class Item {
|
||||
}
|
||||
|
||||
get contentObject() {
|
||||
// console.log("getting content object from content", this.content);
|
||||
if(!this.content) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -56,6 +56,12 @@ class Extension extends Item {
|
||||
})
|
||||
}
|
||||
|
||||
actionsWithContextForItem(item) {
|
||||
return this.actions.filter(function(action){
|
||||
return action.context == item.content_type || action.context == "Item";
|
||||
})
|
||||
}
|
||||
|
||||
mapContentToLocalProperties(contentObject) {
|
||||
super.mapContentToLocalProperties(contentObject)
|
||||
this.name = contentObject.name;
|
||||
|
||||
@@ -234,7 +234,7 @@ angular.module('app.frontend')
|
||||
return this.createRequestParamsForItem(item, options.additionalFields);
|
||||
}.bind(this));
|
||||
|
||||
console.log("syncing items", request.items);
|
||||
// console.log("syncing items", request.items);
|
||||
|
||||
if(this.syncToken) {
|
||||
request.sync_token = this.syncToken;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
class ContextualExtensionsMenu {
|
||||
|
||||
constructor() {
|
||||
this.restrict = "E";
|
||||
this.templateUrl = "frontend/directives/contextual-menu.html";
|
||||
this.scope = {
|
||||
item: "="
|
||||
};
|
||||
}
|
||||
|
||||
controller($scope, modelManager, extensionManager) {
|
||||
$scope.extensions = extensionManager.extensionsInContextOfItem($scope.item);
|
||||
|
||||
$scope.executeAction = function(action, extension) {
|
||||
action.running = true;
|
||||
extensionManager.executeAction(action, extension, $scope.item, function(response){
|
||||
action.running = false;
|
||||
})
|
||||
}
|
||||
|
||||
$scope.accessTypeForExtension = function(extension) {
|
||||
return extensionManager.extensionUsesEncryptedData(extension) ? "encrypted" : "decrypted";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
angular.module('app.frontend').directive('contextualExtensionsMenu', () => new ContextualExtensionsMenu);
|
||||
@@ -25,6 +25,12 @@ class ExtensionManager {
|
||||
return this.modelManager.extensions;
|
||||
}
|
||||
|
||||
extensionsInContextOfItem(item) {
|
||||
return this.extensions.filter(function(ext){
|
||||
return ext.actionsWithContextForItem(item).length > 0;
|
||||
})
|
||||
}
|
||||
|
||||
actionWithURL(url) {
|
||||
for (var extension of this.extensions) {
|
||||
return _.find(extension.actions, {url: url})
|
||||
@@ -115,14 +121,20 @@ class ExtensionManager {
|
||||
}
|
||||
|
||||
case "post": {
|
||||
var items;
|
||||
var params = {};
|
||||
|
||||
if(action.all) {
|
||||
items = this.modelManager.allItemsMatchingTypes(action.content_types);
|
||||
var items = this.modelManager.allItemsMatchingTypes(action.content_types);
|
||||
params.items = items.map(function(item){
|
||||
var params = this.outgoingParamsForItem(item, extension);
|
||||
return params;
|
||||
}.bind(this))
|
||||
|
||||
} else {
|
||||
items = [item];
|
||||
params.item = this.outgoingParamsForItem(item, extension);
|
||||
}
|
||||
|
||||
this.performPost(action, extension, items, function(items){
|
||||
this.performPost(action, extension, params, function(items){
|
||||
callback(items);
|
||||
});
|
||||
}
|
||||
@@ -149,7 +161,7 @@ class ExtensionManager {
|
||||
}
|
||||
|
||||
enableRepeatAction(action, extension) {
|
||||
console.log("Enabling repeat action", action);
|
||||
// console.log("Enabling repeat action", action);
|
||||
|
||||
if(!_.find(this.enabledRepeatActionUrls, action.url)) {
|
||||
this.enabledRepeatActionUrls.push(action.url);
|
||||
@@ -205,7 +217,12 @@ class ExtensionManager {
|
||||
action.lastExecuted = new Date();
|
||||
|
||||
if(action.verb == "post") {
|
||||
this.performPost(action, extension, changedItems, null);
|
||||
var params = {};
|
||||
params.items = changedItems.map(function(item){
|
||||
var params = this.outgoingParamsForItem(item, extension);
|
||||
return params;
|
||||
}.bind(this))
|
||||
this.performPost(action, extension, params, null);
|
||||
} else {
|
||||
// todo
|
||||
}
|
||||
@@ -215,12 +232,9 @@ class ExtensionManager {
|
||||
return this.apiController.paramsForExtension(item, this.extensionUsesEncryptedData(extension));
|
||||
}
|
||||
|
||||
performPost(action, extension, items, callback) {
|
||||
performPost(action, extension, params, callback) {
|
||||
var request = this.Restangular.oneUrl(action.url, action.url);
|
||||
request.items = items.map(function(item){
|
||||
var params = this.outgoingParamsForItem(item, extension);
|
||||
return params;
|
||||
}.bind(this))
|
||||
_.merge(request, params);
|
||||
|
||||
request.post().then(function(response){
|
||||
// console.log("watch action response", response);
|
||||
|
||||
@@ -140,7 +140,7 @@ class ModelManager {
|
||||
item.addItemAsRelationship(referencedItem);
|
||||
referencedItem.addItemAsRelationship(item);
|
||||
} else {
|
||||
console.log("Unable to find item:", reference.uuid);
|
||||
// console.log("Unable to find item:", reference.uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,9 @@ class ModelManager {
|
||||
|
||||
setItemToBeDeleted(item) {
|
||||
item.deleted = true;
|
||||
item.setDirty(true);
|
||||
if(!item.dummy) {
|
||||
item.setDirty(true);
|
||||
}
|
||||
item.removeAllRelationships();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user