From ca26b867eb5db605a1641b11985c5afdd17c1156 Mon Sep 17 00:00:00 2001 From: Feilong Wang Date: Fri, 21 Jul 2017 14:03:09 +1200 Subject: [PATCH] Fix view messages dialog The 'View Messages' action shows the dialog to list messages. The dialog controller retrieves messages when called. To refresh the messages using 'List Messages' button in the dialog, 'List Messages' button calls dialog re-creation process. Closes-Bug: #1705598 Change-Id: I884a4b98599889cc3b66474be0e13221c1177d8e --- .../openstack-service-api/zaqar.service.js | 3 +- .../queues/actions/list-message.controller.js | 2 + .../queues/actions/list-message.service.js | 48 ++++++++----------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/zaqar_ui/static/app/core/openstack-service-api/zaqar.service.js b/zaqar_ui/static/app/core/openstack-service-api/zaqar.service.js index 19c45c2..f853e10 100644 --- a/zaqar_ui/static/app/core/openstack-service-api/zaqar.service.js +++ b/zaqar_ui/static/app/core/openstack-service-api/zaqar.service.js @@ -97,8 +97,9 @@ } function getMessages(queueName) { + var msg = gettext('Unable to get messages.'); var url = interpolate(msgPath, [queueName]); - return apiService.get(url); + return apiService.get(url).error(error(msg)); } function postMessages(queueName, msgs) { diff --git a/zaqar_ui/static/dashboard/project/queues/actions/list-message.controller.js b/zaqar_ui/static/dashboard/project/queues/actions/list-message.controller.js index aa2d37c..17e1489 100644 --- a/zaqar_ui/static/dashboard/project/queues/actions/list-message.controller.js +++ b/zaqar_ui/static/dashboard/project/queues/actions/list-message.controller.js @@ -40,8 +40,10 @@ var ctrl = this; ctrl.queue = $scope.model.id; ctrl.messages = []; + /* TODO: actions will be implemented later. ctrl.claimMessage = claimMessage; ctrl.deleteMessage = deleteMessage; + */ zaqar.getMessages(ctrl.queue).success(function (response) { ctrl.messages = response; diff --git a/zaqar_ui/static/dashboard/project/queues/actions/list-message.service.js b/zaqar_ui/static/dashboard/project/queues/actions/list-message.service.js index 81096eb..779d93a 100644 --- a/zaqar_ui/static/dashboard/project/queues/actions/list-message.service.js +++ b/zaqar_ui/static/dashboard/project/queues/actions/list-message.service.js @@ -23,13 +23,9 @@ listMessageService.$inject = [ '$q', 'horizon.dashboard.project.queues.basePath', - 'horizon.app.core.openstack-service-api.policy', - 'horizon.app.core.openstack-service-api.zaqar', - 'horizon.dashboard.project.queues.events', 'horizon.framework.util.i18n.gettext', 'horizon.framework.util.q.extensions', - 'horizon.framework.widgets.form.ModalFormService', - 'horizon.framework.widgets.toast.service' + 'horizon.framework.widgets.form.ModalFormService' ]; /** @@ -37,26 +33,22 @@ * @name horizon.dashboard.project.queues.actions.listMessageService * @param {Object} $q * @param {String} basePath - * @param {Object} policy - * @param {Object} zaqar - * @param {Object} events * @param {Object} gettext * @param {Object} $qExtensions * @param {Object} modal - * @param {Object} toast * @returns {Object} list messages service * @description Brings up the polling messages modal dialog. * On submit, poll messages from given queues. * On cancel, do nothing. */ function listMessageService( - $q, basePath, policy, zaqar, events, gettext, $qExtensions, modal, toast + $q, basePath, gettext, $qExtensions, modal ) { // schema var schema = { type: "object", properties: { - postMessages: { + listMessages: { title: gettext("List Messages"), type: "string" } @@ -86,16 +78,21 @@ // model var model; - var message = { - success: gettext('Messages has been posted to queue %s successfully.') - }; - var service = { initAction: initAction, perform: perform, allowed: allowed }; + // modal config + var config = { + "title": gettext('List Messages'), + "submitText": gettext('List Messages'), + "schema": schema, + "form": form, + "model": model + }; + return service; ////////////// @@ -108,29 +105,22 @@ } function perform(selected) { - model = { + config.model = { id: selected.id, name: selected.name }; - // modal config - var config = { - "title": gettext('List Messages'), - "submitText": gettext('List Messages'), - "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 zaqar.postMessages(id, context.model).then(function() { - toast.add('success', interpolate(message.success, [name])); - }); + config.model = { + id: id, + name: name + }; + // display new dialog + modal.open(config).then(submit); } } })();