Merge pull request #46 from standardnotes/context-ext

Context ext
This commit is contained in:
Mo Bitar
2017-01-21 16:44:15 -06:00
committed by GitHub
6 changed files with 46 additions and 2 deletions

View File

@@ -83,6 +83,8 @@ angular.module('app.frontend')
this.setNote = function(note, oldNote) {
this.editorMode = 'edit';
this.showExtensions = false;
this.showMenu = false;
if(note.safeText().length == 0 && note.dummy) {
this.focusTitle(100);

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(let 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,24 @@ 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());
callback(scopedExtension);
}.bind(this))
.catch(function(response){
console.log("Error loading 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}}

View File

@@ -139,7 +139,7 @@
Last run {{action.lastExecuted | appDateTime}}
.error{"ng-if" => "action.error"}
Error performing action.
%a{"ng-click" => "ctrl.deleteExtension(extension)", "style" => "margin-top: 22px; display: block;"} Remove extension
%a{"ng-click" => "ctrl.deleteExtension(extension)", "style" => "margin-top: 22px; display: block; text-align: center;"} Remove extension
.extension-link
%a{"ng-click" => "ctrl.toggleExtensionForm()"} Add new extension