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());

View File

@@ -12,6 +12,7 @@
padding-top: 12px;
padding-left: 10px;
padding-bottom: 10px;
position: relative;
> .name {
font-size: 14px;
@@ -23,6 +24,14 @@
font-weight: normal;
margin-top: 2px;
}
> .loading {
position: absolute;
height: 15px;
width: 15px;
right: 10px;
top: 20px;
}
}
ul {

View File

@@ -5,6 +5,7 @@
.access
Can access your data
%strong {{accessTypeForExtension(extension)}}
.spinner.loading{"ng-if" => "extension.loading"}
%ul
%li.action{"ng-repeat" => "action in extension.actionsWithContextForItem(item)", "ng-click" => "executeAction(action, extension)"}
.name {{action.label}}