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