no extensions box

This commit is contained in:
Mo Bitar
2017-05-16 11:55:52 -05:00
parent b65ed8c90c
commit 5ec4797d85
13 changed files with 315 additions and 156 deletions

View File

@@ -8,4 +8,14 @@ class BaseCtrl {
}
}
function getParameterByName(name, url) {
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);

View File

@@ -55,6 +55,11 @@ angular.module('app.frontend')
this.showExtensionsMenu = !this.showExtensionsMenu;
}
$timeout(function(){
// testing
this.toggleExtensions();
}.bind(this))
this.toggleIO = function() {
this.showIOMenu = !this.showIOMenu;
this.showExtensionsMenu = false;

View File

@@ -26,7 +26,7 @@ class ContextualExtensionsMenu {
})
}
$scope.executeAction = function(action, extension) {
$scope.executeAction = function(action, extension, parentAction) {
if(!$scope.isActionEnabled(action, extension)) {
alert("This action requires " + action.access_type + " access to this note. You can change this setting in the Extensions menu on the bottom of the app.");
return;
@@ -41,7 +41,13 @@ class ContextualExtensionsMenu {
$scope.handleActionResponse(action, response);
// reload extension actions
extensionManager.loadExtensionInContextOfItem(extension, $scope.item, null);
extensionManager.loadExtensionInContextOfItem(extension, $scope.item, function(ext){
// keep nested state
if(parentAction) {
var matchingAction = _.find(ext.actions, {label: parentAction.label});
matchingAction.showNestedActions = true;
}
});
})
}

View File

@@ -20,25 +20,6 @@ class EditorMenu {
$scope.callback()(editor);
}
$scope.deleteEditor = function(editor) {
if(confirm("Are you sure you want to delete this editor?")) {
editorManager.deleteEditor(editor);
}
}
$scope.setDefaultEditor = function(editor) {
editorManager.setDefaultEditor(editor);
}
$scope.removeDefaultEditor = function(editor) {
editorManager.removeDefaultEditor(editor);
}
$scope.submitNewEditorRequest = function() {
editorManager.addNewEditorFromURL($scope.formData.url);
$scope.formData = {};
}
}
}

View File

@@ -7,37 +7,14 @@ class GlobalExtensionsMenu {
};
}
controller($scope, extensionManager, syncManager, modelManager, themeManager) {
controller($scope, extensionManager, syncManager, modelManager, themeManager, editorManager) {
'ngInject';
$scope.formData = {};
$scope.extensionManager = extensionManager;
$scope.themeManager = themeManager;
$scope.state = {showDataExts: true, showThemes: true};
$scope.toggleExtensionForm = function() {
$scope.newExtensionData = {};
$scope.showNewExtensionForm = !$scope.showNewExtensionForm;
}
$scope.submitNewExtensionForm = function() {
if($scope.newExtensionData.url) {
extensionManager.addExtension($scope.newExtensionData.url, function(response){
if(!response) {
if($scope.newExtensionData.url.indexOf("type=sf") != -1) {
alert("Unable to register this extension. You are attempting to register a Standard File extension in Standard Notes. You should instead open your Standard File Dashboard and register this extension there.");
} else if($scope.newExtensionData.url.indexOf("name=") != -1) {
// user is mistakenly trying to register editor extension, most likely
alert("Unable to register this extension. It looks like you may be trying to install an editor extension. To do that, click 'Editor' under the current note's title.");
} else {
alert("Unable to register this extension. Make sure the link is valid and try again.");
}
} else {
$scope.newExtensionData.url = "";
$scope.showNewExtensionForm = false;
}
})
}
}
$scope.editorManager = editorManager;
$scope.selectedAction = function(action, extension) {
extensionManager.executeAction(action, extension, null, function(response){
@@ -55,7 +32,7 @@ class GlobalExtensionsMenu {
extensionManager.changeExtensionEncryptionFormat(encrypted, extension);
}
$scope.deleteExtension = function(extension) {
$scope.deleteActionExtension = function(extension) {
if(confirm("Are you sure you want to delete this extension?")) {
extensionManager.deleteExtension(extension);
}
@@ -67,11 +44,6 @@ class GlobalExtensionsMenu {
}
}
$scope.submitTheme = function() {
themeManager.submitTheme($scope.state.themeUrl);
$scope.state.themeUrl = "";
}
$scope.deleteTheme = function(theme) {
if(confirm("Are you sure you want to delete this theme?")) {
themeManager.deactivateTheme(theme);
@@ -80,6 +52,75 @@ class GlobalExtensionsMenu {
}
}
// Editors
$scope.deleteEditor = function(editor) {
if(confirm("Are you sure you want to delete this editor?")) {
editorManager.deleteEditor(editor);
}
}
$scope.setDefaultEditor = function(editor) {
editorManager.setDefaultEditor(editor);
}
$scope.removeDefaultEditor = function(editor) {
editorManager.removeDefaultEditor(editor);
}
// Installation
$scope.submitInstallLink = function() {
var link = $scope.formData.installLink;
if(!link) {
return;
}
var completion = function() {
$scope.formData.installLink = "";
}
var type = getParameterByName("type", link);
if(type == "sf" || type == "sync") {
$scope.handleSyncAdapterLink(link, completion);
} else if(type == "editor") {
$scope.handleEditorLink(link, completion);
} else if(link.indexOf(".css") != -1 || type == "theme") {
$scope.handleThemeLink(link, completion);
} else {
$scope.handleActionLink(link, completion);
}
}
$scope.handleSyncAdapterLink = function(link, completion) {
completion();
}
$scope.handleThemeLink = function(link, completion) {
themeManager.submitTheme(link);
completion();
}
$scope.handleActionLink = function(link, completion) {
if(link) {
extensionManager.addExtension(link, function(response){
if(!response) {
alert("Unable to register this extension. Make sure the link is valid and try again.");
} else {
completion();
}
})
}
}
$scope.handleEditorLink = function(link, completion) {
editorManager.addNewEditorFromURL(link);
completion();
}
}
}

View File

@@ -1,6 +1,5 @@
class EditorManager {
constructor($rootScope, modelManager, syncManager) {
this.syncManager = syncManager;
this.modelManager = modelManager;
@@ -79,7 +78,7 @@ class EditorManager {
}
addNewEditorFromURL(url) {
var name = this.getParameterByName("name", url);
var name = getParameterByName("name", url);
var editor = this.modelManager.createItem({
content_type: this.editorType,
url: url,
@@ -96,15 +95,6 @@ class EditorManager {
this.syncManager.sync();
}
getParameterByName(name, url) {
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
}
angular.module('app.frontend').service('editorManager', EditorManager);

View File

@@ -84,6 +84,10 @@ class ThemeManager {
}
displayNameForThemeFile(fileName) {
let fromParam = getParameterByName("name", fileName);
if(fromParam) {
return fromParam;
}
let name = fileName.split(".")[0];
let cleaned = name.split("-").join(" ");
return this.capitalizeString(cleaned);