From 9d61096c2c4f845fd30f3cf660f7529e981ff533 Mon Sep 17 00:00:00 2001 From: Shu Muto Date: Tue, 11 Apr 2017 12:42:38 +0900 Subject: [PATCH] Add dialogs for stop/reboot actions This patch adds dialogs for stop and reboot actions to specify timeout attribute. Change-Id: I4d7e92441dd976d6974c7b8ad84a5338b420c9d6 --- zun_ui/api/rest_api.py | 4 +- .../containers/operations/reboot.service.js | 71 +++++++++++++++++-- .../containers/operations/stop.service.js | 71 +++++++++++++++++-- .../static/dashboard/container/zun.service.js | 8 +-- 4 files changed, 134 insertions(+), 20 deletions(-) diff --git a/zun_ui/api/rest_api.py b/zun_ui/api/rest_api.py index 1e7a35b..0fb1dca 100644 --- a/zun_ui/api/rest_api.py +++ b/zun_ui/api/rest_api.py @@ -64,10 +64,10 @@ class ContainerActions(generic.View): if action == 'start': return client.container_start(request, id) elif action == 'stop': - timeout = 10 + timeout = request.DATA.get("timeout") or 10 return client.container_stop(request, id, timeout) elif action == 'reboot': - timeout = 10 + timeout = request.DATA.get("timeout") or 10 return client.container_reboot(request, id, timeout) elif action == 'pause': return client.container_pause(request, id) diff --git a/zun_ui/static/dashboard/container/containers/operations/reboot.service.js b/zun_ui/static/dashboard/container/containers/operations/reboot.service.js index 9cd0c20..59d8a1d 100644 --- a/zun_ui/static/dashboard/container/containers/operations/reboot.service.js +++ b/zun_ui/static/dashboard/container/containers/operations/reboot.service.js @@ -27,15 +27,52 @@ rebootService.$inject = [ 'horizon.app.core.openstack-service-api.zun', + 'horizon.dashboard.container.containers.basePath', 'horizon.dashboard.container.containers.resourceType', 'horizon.framework.util.actions.action-result.service', + 'horizon.framework.util.i18n.gettext', 'horizon.framework.util.q.extensions', + 'horizon.framework.widgets.form.ModalFormService', 'horizon.framework.widgets.toast.service' ]; function rebootService( - zun, resourceType, actionResult, $qExtensions, toast + zun, basePath, resourceType, actionResult, gettext, $qExtensions, modal, toast ) { + // schema + var schema = { + type: "object", + properties: { + timeout: { + title: gettext("Reboot Container"), + type: "number", + minimum: 1 + } + } + }; + + // form + var form = [ + { + type: 'section', + htmlClass: 'row', + items: [ + { + type: 'section', + htmlClass: 'col-sm-12', + items: [ + { + "key": "timeout", + "placeholder": gettext("Specify a shutdown timeout in seconds. (default: 10)") + } + ] + } + ] + } + ]; + + // model + var model; var message = { success: gettext('Container %s was successfully rebooted.') @@ -61,12 +98,32 @@ } function perform(selected) { - // reboot selected container - return zun.rebootContainer(selected.id).then(function() { - toast.add('success', interpolate(message.success, [selected.name])); - var result = actionResult.getActionResult().updated(resourceType, selected.id); - return result.result; - }); + model = { + id: selected.id, + name: selected.name, + timeout: null + }; + // modal config + var config = { + "title": gettext('Reboot Container'), + "submitText": gettext('Reboot'), + "schema": schema, + "form": form, + "model": model + }; + return modal.open(config).then(submit); + + function submit(context) { + var id = context.model.id; + var name = context.model.name; + delete context.model.id; + delete context.model.name; + return zun.rebootContainer(id, context.model).then(function() { + toast.add('success', interpolate(message.success, [name])); + var result = actionResult.getActionResult().updated(resourceType, id); + return result.result; + }); + } } } })(); diff --git a/zun_ui/static/dashboard/container/containers/operations/stop.service.js b/zun_ui/static/dashboard/container/containers/operations/stop.service.js index 9dbe154..3025e4f 100644 --- a/zun_ui/static/dashboard/container/containers/operations/stop.service.js +++ b/zun_ui/static/dashboard/container/containers/operations/stop.service.js @@ -27,15 +27,52 @@ stopService.$inject = [ 'horizon.app.core.openstack-service-api.zun', + 'horizon.dashboard.container.containers.basePath', 'horizon.dashboard.container.containers.resourceType', 'horizon.framework.util.actions.action-result.service', + 'horizon.framework.util.i18n.gettext', 'horizon.framework.util.q.extensions', + 'horizon.framework.widgets.form.ModalFormService', 'horizon.framework.widgets.toast.service' ]; function stopService( - zun, resourceType, actionResult, $qExtensions, toast + zun, basePath, resourceType, actionResult, gettext, $qExtensions, modal, toast ) { + // schema + var schema = { + type: "object", + properties: { + timeout: { + title: gettext("Stop Container"), + type: "number", + minimum: 1 + } + } + }; + + // form + var form = [ + { + type: 'section', + htmlClass: 'row', + items: [ + { + type: 'section', + htmlClass: 'col-sm-12', + items: [ + { + "key": "timeout", + "placeholder": gettext("Specify a shutdown timeout in seconds. (default: 10)") + } + ] + } + ] + } + ]; + + // model + var model; var message = { success: gettext('Container %s was successfully stoped.') @@ -61,12 +98,32 @@ } function perform(selected) { - // start selected container - return zun.stopContainer(selected.id).then(function() { - toast.add('success', interpolate(message.success, [selected.name])); - var result = actionResult.getActionResult().updated(resourceType, selected.id); - return result.result; - }); + model = { + id: selected.id, + name: selected.name, + timeout: null + }; + // modal config + var config = { + "title": gettext('Stop Container'), + "submitText": gettext('Stop'), + "schema": schema, + "form": form, + "model": model + }; + return modal.open(config).then(submit); + + function submit(context) { + var id = context.model.id; + var name = context.model.name; + delete context.model.id; + delete context.model.name; + return zun.stopContainer(id, context.model).then(function() { + toast.add('success', interpolate(message.success, [name])); + var result = actionResult.getActionResult().updated(resourceType, id); + return result.result; + }); + } } } })(); diff --git a/zun_ui/static/dashboard/container/zun.service.js b/zun_ui/static/dashboard/container/zun.service.js index fa8871b..0560587 100644 --- a/zun_ui/static/dashboard/container/zun.service.js +++ b/zun_ui/static/dashboard/container/zun.service.js @@ -91,9 +91,9 @@ return apiService.post(containersPath + id + '/start').error(error(msg)); } - function stopContainer(id) { + function stopContainer(id, params) { var msg = gettext('Unable to stop Container.'); - return apiService.post(containersPath + id + '/stop').error(error(msg)); + return apiService.post(containersPath + id + '/stop', params).error(error(msg)); } function logsContainer(id) { @@ -101,9 +101,9 @@ return apiService.get(containersPath + id + '/logs').error(error(msg)); } - function rebootContainer(id) { + function rebootContainer(id, params) { var msg = gettext('Unable to reboot Container.'); - return apiService.post(containersPath + id + '/reboot').error(error(msg)); + return apiService.post(containersPath + id + '/reboot', params).error(error(msg)); } function pauseContainer(id) {