diff --git a/app/docker/views/configs/create/createConfigController.js b/app/docker/views/configs/create/createConfigController.js index 19a698b0b..07868dd3c 100644 --- a/app/docker/views/configs/create/createConfigController.js +++ b/app/docker/views/configs/create/createConfigController.js @@ -1,11 +1,12 @@ angular.module('portainer.docker') -.controller('CreateConfigController', ['$scope', '$state', '$document', 'Notifications', 'ConfigService', 'Authentication', 'FormValidator', 'ResourceControlService', 'CodeMirrorService', -function ($scope, $state, $document, Notifications, ConfigService, Authentication, FormValidator, ResourceControlService, CodeMirrorService) { +.controller('CreateConfigController', ['$scope', '$state', 'Notifications', 'ConfigService', 'Authentication', 'FormValidator', 'ResourceControlService', +function ($scope, $state, Notifications, ConfigService, Authentication, FormValidator, ResourceControlService) { $scope.formValues = { Name: '', Labels: [], - AccessControlData: new AccessControlFormData() + AccessControlData: new AccessControlFormData(), + ConfigContent: '' }; $scope.state = { @@ -31,9 +32,7 @@ function ($scope, $state, $document, Notifications, ConfigService, Authenticatio } function prepareConfigData(config) { - // The codemirror editor does not work with ng-model so we need to retrieve - // the value directly from the editor. - var configData = $scope.editor.getValue(); + var configData = $scope.formValues.ConfigContent; config.Data = btoa(unescape(encodeURIComponent(configData))); } @@ -62,6 +61,11 @@ function ($scope, $state, $document, Notifications, ConfigService, Authenticatio var userDetails = Authentication.getUserDetails(); var isAdmin = userDetails.role === 1; + if ($scope.formValues.ConfigContent === '') { + $scope.state.formValidationError = 'Config content must not be empty'; + return; + } + if (!validateForm(accessControlData, isAdmin)) { return; } @@ -83,14 +87,7 @@ function ($scope, $state, $document, Notifications, ConfigService, Authenticatio }); }; - function initView() { - $document.ready(function() { - var webEditorElement = $document[0].getElementById('config-editor', false); - if (webEditorElement) { - $scope.editor = CodeMirrorService.applyCodeMirrorOnElement(webEditorElement, false, false); - } - }); - } - - initView(); + $scope.editorUpdate = function(cm) { + $scope.formValues.ConfigContent = cm.getValue(); + }; }]); diff --git a/app/docker/views/configs/create/createconfig.html b/app/docker/views/configs/create/createconfig.html index 0f7972ad0..d55343dcb 100644 --- a/app/docker/views/configs/create/createconfig.html +++ b/app/docker/views/configs/create/createconfig.html @@ -21,7 +21,12 @@
- +
@@ -62,6 +67,7 @@
+ {{ state.formValidationError }}
diff --git a/app/docker/views/configs/edit/config.html b/app/docker/views/configs/edit/config.html index 2b84b6d54..32475db4f 100644 --- a/app/docker/views/configs/edit/config.html +++ b/app/docker/views/configs/edit/config.html @@ -70,7 +70,12 @@
- +
diff --git a/app/docker/views/configs/edit/configController.js b/app/docker/views/configs/edit/configController.js index 72c1ea86b..3e0ad0178 100644 --- a/app/docker/views/configs/edit/configController.js +++ b/app/docker/views/configs/edit/configController.js @@ -1,6 +1,6 @@ angular.module('portainer.docker') -.controller('ConfigController', ['$scope', '$transition$', '$state', '$document', 'ConfigService', 'Notifications', 'CodeMirrorService', -function ($scope, $transition$, $state, $document, ConfigService, Notifications, CodeMirrorService) { +.controller('ConfigController', ['$scope', '$transition$', '$state', 'ConfigService', 'Notifications', +function ($scope, $transition$, $state, ConfigService, Notifications) { $scope.removeConfig = function removeConfig(configId) { ConfigService.remove(configId) @@ -13,20 +13,10 @@ function ($scope, $transition$, $state, $document, ConfigService, Notifications, }); }; - function initEditor() { - $document.ready(function() { - var webEditorElement = $document[0].getElementById('config-editor'); - if (webEditorElement) { - $scope.editor = CodeMirrorService.applyCodeMirrorOnElement(webEditorElement, false, true); - } - }); - } - function initView() { ConfigService.config($transition$.params().id) .then(function success(data) { $scope.config = data; - initEditor(); }) .catch(function error(err) { Notifications.error('Failure', err, 'Unable to retrieve config details'); diff --git a/app/docker/views/stacks/create/createStackController.js b/app/docker/views/stacks/create/createStackController.js index f569dc9e3..cc11a680b 100644 --- a/app/docker/views/stacks/create/createStackController.js +++ b/app/docker/views/stacks/create/createStackController.js @@ -1,14 +1,10 @@ angular.module('portainer.docker') -.controller('CreateStackController', ['$scope', '$state', '$document', 'StackService', 'CodeMirrorService', 'Authentication', 'Notifications', 'FormValidator', 'ResourceControlService', 'FormHelper', -function ($scope, $state, $document, StackService, CodeMirrorService, Authentication, Notifications, FormValidator, ResourceControlService, FormHelper) { - - // Store the editor content when switching builder methods - var editorContent = ''; - var editorEnabled = true; +.controller('CreateStackController', ['$scope', '$state', 'StackService', 'Authentication', 'Notifications', 'FormValidator', 'ResourceControlService', 'FormHelper', +function ($scope, $state, StackService, Authentication, Notifications, FormValidator, ResourceControlService, FormHelper) { $scope.formValues = { Name: '', - StackFileContent: '# Define or paste the content of your docker-compose file here', + StackFileContent: '', StackFile: null, RepositoryURL: '', Env: [], @@ -42,15 +38,11 @@ function ($scope, $state, $document, StackService, CodeMirrorService, Authentica return true; } - function createStack(name) { - var method = $scope.state.Method; + function createStack(name, method) { var env = FormHelper.removeInvalidEnvVars($scope.formValues.Env); if (method === 'editor') { - // The codemirror editor does not work with ng-model so we need to retrieve - // the value directly from the editor. - var stackFileContent = $scope.editor.getValue(); - + var stackFileContent = $scope.formValues.StackFileContent; return StackService.createStackFromFileContent(name, stackFileContent, env); } else if (method === 'upload') { var stackFile = $scope.formValues.StackFile; @@ -64,18 +56,24 @@ function ($scope, $state, $document, StackService, CodeMirrorService, Authentica $scope.deployStack = function () { var name = $scope.formValues.Name; + var method = $scope.state.Method; var accessControlData = $scope.formValues.AccessControlData; var userDetails = Authentication.getUserDetails(); var isAdmin = userDetails.role === 1; var userId = userDetails.ID; + if (method === 'editor' && $scope.formValues.StackFileContent === '') { + $scope.state.formValidationError = 'Stack file content must not be empty'; + return; + } + if (!validateForm(accessControlData, isAdmin)) { return; } $scope.state.actionInProgress = true; - createStack(name) + createStack(name, method) .then(function success(data) { Notifications.success('Stack successfully deployed'); }) @@ -96,33 +94,7 @@ function ($scope, $state, $document, StackService, CodeMirrorService, Authentica }); }; - function enableEditor(value) { - $document.ready(function() { - var webEditorElement = $document[0].getElementById('web-editor'); - if (webEditorElement) { - $scope.editor = CodeMirrorService.applyCodeMirrorOnElement(webEditorElement, true, false); - if (value) { - $scope.editor.setValue(value); - } - } - }); - } - - $scope.toggleEditor = function() { - if (!editorEnabled) { - enableEditor(editorContent); - editorEnabled = true; - } + $scope.editorUpdate = function(cm) { + $scope.formValues.StackFileContent = cm.getValue(); }; - - $scope.saveEditorContent = function() { - editorContent = $scope.editor.getValue(); - editorEnabled = false; - }; - - function initView() { - enableEditor(); - } - - initView(); }]); diff --git a/app/docker/views/stacks/create/createstack.html b/app/docker/views/stacks/create/createstack.html index af80be3e2..927255b23 100644 --- a/app/docker/views/stacks/create/createstack.html +++ b/app/docker/views/stacks/create/createstack.html @@ -31,7 +31,7 @@
- +