From 43bbeed141abc1d4b3c0097df7335edb4f06589c Mon Sep 17 00:00:00 2001 From: Zhang Hao Date: Wed, 20 Jul 2022 08:39:44 +0800 Subject: [PATCH] refactor(docker/switch/component): implement new design [EE-3688] (#7239) * refactor(docker/switch/component): implement new design [EE=3688] * revert create volume * revert por-switch on exec.html * refactor(container): switch fields on container creation page and edition page * refactor(container): switch fields on networking/secret/servicewebhook/swarmvisual * bug fixed * code review issues * merge code * fix teaser for container edition * fix encode secret toggle bug on adding secret page * fixed a bug for service webhook toggle --- .../container-capabilities.controller.js | 23 ++++++ .../container-capabilities.js | 3 + .../containerCapabilities.html | 23 +++--- .../create/createContainerController.js | 36 ++++++++++ .../containers/create/createcontainer.html | 71 ++++++++++--------- .../views/containers/edit/container.html | 23 +++--- .../containers/edit/containerController.js | 2 + .../secrets/create/createSecretController.js | 8 +++ .../views/secrets/create/createsecret.html | 12 ++-- .../create/createServiceController.js | 8 +++ .../views/services/create/createservice.html | 15 ++-- app/docker/views/services/edit/service.html | 15 ++-- .../views/services/edit/serviceController.js | 7 ++ .../visualizer/swarmVisualizerController.js | 14 ++++ .../swarm/visualizer/swarmvisualizer.html | 20 ++++-- 15 files changed, 194 insertions(+), 86 deletions(-) create mode 100644 app/docker/components/container-capabilities/container-capabilities.controller.js diff --git a/app/docker/components/container-capabilities/container-capabilities.controller.js b/app/docker/components/container-capabilities/container-capabilities.controller.js new file mode 100644 index 000000000..a743f5a50 --- /dev/null +++ b/app/docker/components/container-capabilities/container-capabilities.controller.js @@ -0,0 +1,23 @@ +export default class ContainerCapabilitiesController { + /* @ngInject */ + constructor($scope) { + this.$scope = $scope; + + this.oldCapabilities = []; + } + + createOnChangeHandler(capability) { + return (checked) => { + this.$scope.$evalAsync(() => { + capability.allowed = checked; + }); + }; + } + + $doCheck() { + if (this.oldCapabilities.length !== this.capabilities.length) { + this.oldCapabilities = this.capabilities; + this.capabilitiesOnChange = Object.fromEntries(this.capabilities.map((cap) => [cap.capability, this.createOnChangeHandler(cap)])); + } + } +} diff --git a/app/docker/components/container-capabilities/container-capabilities.js b/app/docker/components/container-capabilities/container-capabilities.js index bd8aa6463..aa13b5ac8 100644 --- a/app/docker/components/container-capabilities/container-capabilities.js +++ b/app/docker/components/container-capabilities/container-capabilities.js @@ -1,6 +1,9 @@ +import controller from './container-capabilities.controller'; + angular.module('portainer.docker').component('containerCapabilities', { templateUrl: './containerCapabilities.html', bindings: { capabilities: '=', }, + controller, }); diff --git a/app/docker/components/container-capabilities/containerCapabilities.html b/app/docker/components/container-capabilities/containerCapabilities.html index fdfd25a83..d2e0e47b2 100644 --- a/app/docker/components/container-capabilities/containerCapabilities.html +++ b/app/docker/components/container-capabilities/containerCapabilities.html @@ -1,18 +1,15 @@
Container capabilities
-
-
-
-
- -
-
- -
-
+
+
+
diff --git a/app/docker/views/containers/create/createContainerController.js b/app/docker/views/containers/create/createContainerController.js index d68252695..40f26b8db 100644 --- a/app/docker/views/containers/create/createContainerController.js +++ b/app/docker/views/containers/create/createContainerController.js @@ -110,6 +110,42 @@ angular.module('portainer.docker').controller('CreateContainerController', [ settingUnlimitedResources: false, }; + $scope.onAlwaysPullChange = onAlwaysPullChange; + $scope.handlePublishAllPortsChange = handlePublishAllPortsChange; + $scope.handleAutoRemoveChange = handleAutoRemoveChange; + $scope.handlePrivilegedChange = handlePrivilegedChange; + $scope.handleInitChange = handleInitChange; + + function onAlwaysPullChange(checked) { + return $scope.$evalAsync(() => { + $scope.formValues.alwaysPull = checked; + }); + } + + function handlePublishAllPortsChange(checked) { + return $scope.$evalAsync(() => { + $scope.config.HostConfig.PublishAllPorts = checked; + }); + } + + function handleAutoRemoveChange(checked) { + return $scope.$evalAsync(() => { + $scope.config.HostConfig.AutoRemove = checked; + }); + } + + function handlePrivilegedChange(checked) { + return $scope.$evalAsync(() => { + $scope.config.HostConfig.Privileged = checked; + }); + } + + function handleInitChange(checked) { + return $scope.$evalAsync(() => { + $scope.config.HostConfig.Init = checked; + }); + } + $scope.handleEnvVarChange = handleEnvVarChange; function handleEnvVarChange(value) { $scope.formValues.Env = value; diff --git a/app/docker/views/containers/create/createcontainer.html b/app/docker/views/containers/create/createcontainer.html index a1e022279..ab78248dd 100644 --- a/app/docker/views/containers/create/createcontainer.html +++ b/app/docker/views/containers/create/createcontainer.html @@ -48,11 +48,15 @@
- - +
@@ -64,18 +68,12 @@
Webhooks
- - - +
@@ -85,13 +83,13 @@
- - +
@@ -156,13 +154,13 @@
- - +
@@ -614,16 +612,19 @@
- - +
- - +
diff --git a/app/docker/views/containers/edit/container.html b/app/docker/views/containers/edit/container.html index 1f20c2b64..fc4f4cbac 100644 --- a/app/docker/views/containers/edit/container.html +++ b/app/docker/views/containers/edit/container.html @@ -107,17 +107,18 @@ Finished {{ container.State.FinishedAt | getisodate }} - - - Container webhook - - - + + +
+
+ +
+
diff --git a/app/docker/views/containers/edit/containerController.js b/app/docker/views/containers/edit/containerController.js index 0320d1ff2..7f84a784f 100644 --- a/app/docker/views/containers/edit/containerController.js +++ b/app/docker/views/containers/edit/containerController.js @@ -52,6 +52,7 @@ angular.module('portainer.docker').controller('ContainerController', [ $scope.activityTime = 0; $scope.portBindings = []; $scope.displayRecreateButton = false; + $scope.displayCreateWebhookButton = false; $scope.containerWebhookFeature = FeatureId.CONTAINER_WEBHOOK; $scope.config = { @@ -150,6 +151,7 @@ angular.module('portainer.docker').controller('ContainerController', [ !allowPrivilegedModeForRegularUsers; $scope.displayRecreateButton = !inSwarm && !autoRemove && (admin || !settingRestrictsRegularUsers); + $scope.displayCreateWebhookButton = $scope.displayRecreateButton; }) .catch(function error(err) { Notifications.error('Failure', err, 'Unable to retrieve container info'); diff --git a/app/docker/views/secrets/create/createSecretController.js b/app/docker/views/secrets/create/createSecretController.js index cbd654c77..98341e338 100644 --- a/app/docker/views/secrets/create/createSecretController.js +++ b/app/docker/views/secrets/create/createSecretController.js @@ -23,6 +23,14 @@ angular.module('portainer.docker').controller('CreateSecretController', [ actionInProgress: false, }; + $scope.handleEncodeSecretChange = handleEncodeSecretChange; + + function handleEncodeSecretChange(checked) { + return $scope.$evalAsync(() => { + $scope.formValues.encodeSecret = checked; + }); + } + $scope.addLabel = function () { $scope.formValues.Labels.push({ key: '', value: '' }); }; diff --git a/app/docker/views/secrets/create/createsecret.html b/app/docker/views/secrets/create/createsecret.html index 6aba6518c..b01219066 100644 --- a/app/docker/views/secrets/create/createsecret.html +++ b/app/docker/views/secrets/create/createsecret.html @@ -24,11 +24,13 @@
- - +
diff --git a/app/docker/views/services/create/createServiceController.js b/app/docker/views/services/create/createServiceController.js index 2602d407d..80ebe6ac4 100644 --- a/app/docker/views/services/create/createServiceController.js +++ b/app/docker/views/services/create/createServiceController.js @@ -111,6 +111,14 @@ angular.module('portainer.docker').controller('CreateServiceController', [ $scope.allowBindMounts = false; + $scope.handleWebHookChange = handleWebHookChange; + + function handleWebHookChange(checked) { + return $scope.$evalAsync(() => { + $scope.formValues.Webhook = checked; + }); + } + $scope.handleEnvVarChange = handleEnvVarChange; function handleEnvVarChange(value) { $scope.formValues.Env = value; diff --git a/app/docker/views/services/create/createservice.html b/app/docker/views/services/create/createservice.html index f6217dc79..8a4836b00 100644 --- a/app/docker/views/services/create/createservice.html +++ b/app/docker/views/services/create/createservice.html @@ -96,14 +96,13 @@
Webhooks
- - +
diff --git a/app/docker/views/services/edit/service.html b/app/docker/views/services/edit/service.html index 636759b7d..e3ed5ca3a 100644 --- a/app/docker/views/services/edit/service.html +++ b/app/docker/views/services/edit/service.html @@ -67,14 +67,13 @@ - Service webhook - - + {{ webhookURL | truncatelr }} diff --git a/app/docker/views/services/edit/serviceController.js b/app/docker/views/services/edit/serviceController.js index b32f62a66..8f2f00c1c 100644 --- a/app/docker/views/services/edit/serviceController.js +++ b/app/docker/views/services/edit/serviceController.js @@ -331,6 +331,13 @@ angular.module('portainer.docker').controller('ServiceController', [ updateServiceArray(service, 'Hosts', service.Hosts); }; + $scope.onWebhookChange = function (enabled) { + $scope.$evalAsync(() => { + $scope.updateWebhook($scope.service); + $scope.WebhookExists = enabled; + }); + }; + $scope.updateWebhook = function updateWebhook(service) { if ($scope.WebhookExists) { WebhookService.deleteWebhook($scope.webhookID) diff --git a/app/docker/views/swarm/visualizer/swarmVisualizerController.js b/app/docker/views/swarm/visualizer/swarmVisualizerController.js index 0c842a07c..ccae8da77 100644 --- a/app/docker/views/swarm/visualizer/swarmVisualizerController.js +++ b/app/docker/views/swarm/visualizer/swarmVisualizerController.js @@ -16,6 +16,20 @@ angular.module('portainer.docker').controller('SwarmVisualizerController', [ refreshRate: '5', }; + $scope.handleChangeDisplayOnlyRunningTasks = function handleChangeDisplayOnlyRunningTasks(enabled) { + $scope.$evalAsync(() => { + $scope.state.DisplayOnlyRunningTasks = enabled; + $scope.changeDisplayOnlyRunningTasks(); + }); + }; + + $scope.handleChangeDisplayNodeLabels = function handleChangeDisplayNodeLabels(enabled) { + $scope.$evalAsync(() => { + $scope.state.DisplayNodeLabels = enabled; + $scope.changeDisplayNodeLabels(); + }); + }; + $scope.$on('$destroy', function () { stopRepeater(); }); diff --git a/app/docker/views/swarm/visualizer/swarmvisualizer.html b/app/docker/views/swarm/visualizer/swarmvisualizer.html index b4a377f69..0d1f0e456 100644 --- a/app/docker/views/swarm/visualizer/swarmvisualizer.html +++ b/app/docker/views/swarm/visualizer/swarmvisualizer.html @@ -31,14 +31,22 @@
Options
- - +
+
+
- - +