load ext in context of item

This commit is contained in:
Mo Bitar
2017-01-21 10:23:13 -06:00
parent f904c84827
commit 6f0eb66c33
4 changed files with 44 additions and 1 deletions

View File

@@ -10,7 +10,21 @@ class ContextualExtensionsMenu {
controller($scope, modelManager, extensionManager) {
'ngInject';
$scope.extensions = extensionManager.extensionsInContextOfItem($scope.item);
$scope.extensions = _.map(extensionManager.extensionsInContextOfItem($scope.item), function(ext){
return _.cloneDeep(ext);
});
for(var ext of $scope.extensions) {
ext.loading = true;
extensionManager.loadExtensionInContextOfItem(ext, $scope.item, function(scopedExtension) {
ext.loading = false;
if(scopedExtension) {
_.merge(ext, scopedExtension);
ext.actions = scopedExtension.actions;
}
})
}
$scope.executeAction = function(action, extension) {
action.running = true;

View File

@@ -71,6 +71,25 @@ class ExtensionManager {
this.apiController.sync(null);
}
/*
Loads an extension in the context of a certain item. The server then has the chance to respond with actions that are
relevant just to this item. The response extension is not saved, just displayed as a one-time thing.
*/
loadExtensionInContextOfItem(extension, item, callback) {
this.Restangular.oneUrl(extension.url, extension.url).customGET("", {content_type: item.content_type, item_uuid: item.uuid}).then(function(response){
var scopedExtension = new Extension(response.plain());
scopedExtension.url = extension.url;
callback(scopedExtension);
}.bind(this))
.catch(function(response){
console.log("Error reloading extension", response);
callback(null);
})
}
/*
Registers new extension and saves it to user's account
*/
retrieveExtensionFromServer(url, callback) {
this.Restangular.oneUrl(url, url).get().then(function(response){
var ext = this.handleExtensionLoadExternalResponseItem(url, response.plain());