diff --git a/zaqar_ui/api/rest/zaqar.py b/zaqar_ui/api/rest/zaqar.py index e0590e3..fee72b6 100644 --- a/zaqar_ui/api/rest/zaqar.py +++ b/zaqar_ui/api/rest/zaqar.py @@ -28,7 +28,19 @@ class Queue(generic.View): @rest_utils.ajax() def get(self, request, queue_name): """Get a specific queue""" - return zaqar.queue_show(request, queue_name).to_dict() + return zaqar.queue_get(request, queue_name).to_dict() + + @rest_utils.ajax(data_required=True) + def post(self, request, queue_name): + """Update a queue. + + Returns the updated queue object on success. + """ + queue = zaqar.queue_update(request, queue_name, **request.DATA) + location = '/api/zaqar/queue/%s' % queue._name + response = {'name': queue._name, + 'metadata': queue._metadata} + return rest_utils.CreatedResponse(location, response) @urls.register diff --git a/zaqar_ui/api/zaqar.py b/zaqar_ui/api/zaqar.py index a3c1fd7..22163d8 100644 --- a/zaqar_ui/api/zaqar.py +++ b/zaqar_ui/api/zaqar.py @@ -76,6 +76,7 @@ def queue_update(request, queue_name, metadata): queue = zaqarclient(request).queue(queue_name, auto_create=False) queue.metadata(new_meta=metadata) + return queue def queue_get(request, queue_name): 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 eb4e206..0f851ba 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 @@ -30,7 +30,8 @@ var service = { getQueues: getQueues, createQueue: createQueue, - deleteQueue: deleteQueue + deleteQueue: deleteQueue, + updateQueue: updateQueue }; return service; @@ -54,6 +55,12 @@ function deleteQueue(queueName) { return apiService.delete('/api/zaqar/queues/', [queueName]); } - } + function updateQueue(queue) { + return apiService.post('/api/zaqar/queue/' + queue.queue_name, {"metadata": queue.metadata}) + .error(function() { + toastService.add('error', gettext('Unable to update the queue.')); + }); + } + } }()); diff --git a/zaqar_ui/static/dashboard/project/queues/actions/actions.module.js b/zaqar_ui/static/dashboard/project/queues/actions/actions.module.js index 27af840..03e0193 100644 --- a/zaqar_ui/static/dashboard/project/queues/actions/actions.module.js +++ b/zaqar_ui/static/dashboard/project/queues/actions/actions.module.js @@ -31,6 +31,7 @@ 'horizon.framework.conf.resource-type-registry.service', 'horizon.dashboard.project.queues.actions.createService', 'horizon.dashboard.project.queues.actions.deleteService', + 'horizon.dashboard.project.queues.actions.updateService', 'horizon.dashboard.project.queues.resourceType' ]; @@ -38,15 +39,24 @@ registry, createService, deleteService, + updateService, resourceType ) { var queueResourceType = registry.getResourceType(resourceType); queueResourceType.itemActions .append({ - id: 'queuesRowDelete', + id: 'queuesItemUpdate', + service: updateService, + template: { + text: gettext('Update') + } + }) + .append({ + id: 'queuesItemDelete', service: deleteService, template: { + type: 'delete', text: gettext('Delete') } }); diff --git a/zaqar_ui/static/dashboard/project/queues/actions/update.service.js b/zaqar_ui/static/dashboard/project/queues/actions/update.service.js new file mode 100644 index 0000000..3a50b13 --- /dev/null +++ b/zaqar_ui/static/dashboard/project/queues/actions/update.service.js @@ -0,0 +1,108 @@ +/** + * Copyright 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + + (function() { + 'use strict'; + + angular + .module('horizon.dashboard.project.queues') + .factory('horizon.dashboard.project.queues.actions.updateService', updateService); + + updateService.$inject = [ + 'horizon.app.core.metadata.service', + 'horizon.app.core.openstack-service-api.policy', + 'horizon.dashboard.project.queues.events', + 'horizon.dashboard.project.queues.actions.updateWorkflow', + 'horizon.app.core.openstack-service-api.zaqar', + 'horizon.framework.widgets.modal.wizard-modal.service', + 'horizon.framework.widgets.toast.service' + ]; + + /** + * @ngDoc factory + * @name horizon.dashboard.project.queues.actions.updateService + * @Description A service to open the queues wizard. + */ + function updateService(meta, policy, events, updateWorkflow, zaqar, wizard, toast) { + + var message = { + success: gettext('Queue %s was successfully updated.') + }; + + var scope; + var model = { + queue_name: null, + metadata: {} + }; + + var service = { + initScope: initScope, + perform: perform, + allowed: allowed + }; + + return service; + + ////////////// + + // we define initScope so that the table controller + // will know when a queue has been updated + function initScope($scope) { + scope = $scope; + var queueWatcher = $scope.$on(events.DETAILS_CHANGED, onDetailChange); + var metadataWatcher = $scope.$on(events.METADATA_CHANGED, onMetadataChange); + $scope.$on('$destroy', function destroy() { + queueWatcher(); + metadataWatcher(); + }); + } + + function onDetailChange(e, queue) { + angular.extend(model, queue); + e.stopPropagation(); + } + + function onMetadataChange(e, metadata) { + model.metadata = metadata; + e.stopPropagation(); + } + + function perform(queue) { + model = queue; + scope.queue = model; + model.queue_name = queue.name; + wizard.modal({ + scope: scope, + workflow: updateWorkflow, + submit: submit + }); + } + + function allowed(queue) { + return policy.ifAllowed({ rules: [['queue', 'update_queue']] });; + } + + function submit() { + return zaqar.updateQueue(model).then(success); + } + + function success(response) { + toast.add('success', interpolate(message.success, [response.data.name])); + scope.$emit(events.UPDATE_SUCCESS, response.data); + } + + } // end of updateService +})(); // end of IIFE diff --git a/zaqar_ui/static/dashboard/project/queues/actions/update.workflow.service.js b/zaqar_ui/static/dashboard/project/queues/actions/update.workflow.service.js new file mode 100644 index 0000000..92a94da --- /dev/null +++ b/zaqar_ui/static/dashboard/project/queues/actions/update.workflow.service.js @@ -0,0 +1,44 @@ +/** + * Copyright 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + + (function() { + 'use strict'; + + angular + .module('horizon.dashboard.project.queues') + .factory('horizon.dashboard.project.queues.actions.updateWorkflow', updateWorkflow); + + updateWorkflow.$inject = [ + 'horizon.dashboard.project.queues.actions.createWorkflow', + 'horizon.dashboard.project.queues.basePath', + 'horizon.framework.util.i18n.gettext' + ]; + + /** + * @ngdoc factory + * @name horizon.dashboard.project.queues.actions.updateWorkflow + * @description A workflow for the update queue action. + */ + function updateWorkflow(createWorkflow, basePath, gettext) { + + var workflow = angular.copy(createWorkflow); + workflow.title = gettext('Update Queue'); + workflow.btnText = { finish: gettext('Update') }; + + return workflow; + } + +})(); diff --git a/zaqar_ui/static/dashboard/project/queues/queues.module.js b/zaqar_ui/static/dashboard/project/queues/queues.module.js index 275187f..1777533 100644 --- a/zaqar_ui/static/dashboard/project/queues/queues.module.js +++ b/zaqar_ui/static/dashboard/project/queues/queues.module.js @@ -45,7 +45,8 @@ CREATE_SUCCESS: 'horizon.dashboard.project.queues.CREATE_SUCCESS', DETAILS_CHANGED: 'horizon.dashboard.project.queues.DETAILS_CHANGED', METADATA_CHANGED: 'horizon.dashboard.project.queues.METADATA_CHANGED', - DELETE_SUCCESS: 'horizon.dashboard.project.queues.DELETE_SUCCESS' + DELETE_SUCCESS: 'horizon.dashboard.project.queues.DELETE_SUCCESS', + UPDATE_SUCCESS: 'horizon.dashboard.project.queues.UPDATE_SUCCESS' }; } diff --git a/zaqar_ui/static/dashboard/project/queues/steps/queue-details/queue-details.controller.js b/zaqar_ui/static/dashboard/project/queues/steps/queue-details/queue-details.controller.js index a2ddbb3..4ccf8cc 100644 --- a/zaqar_ui/static/dashboard/project/queues/steps/queue-details/queue-details.controller.js +++ b/zaqar_ui/static/dashboard/project/queues/steps/queue-details/queue-details.controller.js @@ -35,7 +35,8 @@ function controller($scope, zaqar, events) { var ctrl = this; - ctrl.queue = {}; + ctrl.queue = $scope.queue? $scope.queue: {}; + ctrl.update = $scope.queue? true: false; //////////////////////// diff --git a/zaqar_ui/static/dashboard/project/queues/steps/queue-details/queue-details.html b/zaqar_ui/static/dashboard/project/queues/steps/queue-details/queue-details.html index 373ed5b..7db841b 100644 --- a/zaqar_ui/static/dashboard/project/queues/steps/queue-details/queue-details.html +++ b/zaqar_ui/static/dashboard/project/queues/steps/queue-details/queue-details.html @@ -19,6 +19,7 @@ type="text" class="form-control" ng-model="detailsCtrl.queue.queue_name" ng-maxlength="255" + ng-disabled="detailsCtrl.update" placeholder="{$ 'Enter a queue name'|translate $}">

diff --git a/zaqar_ui/static/dashboard/project/queues/steps/queue-metadata/queue-metadata.controller.js b/zaqar_ui/static/dashboard/project/queues/steps/queue-metadata/queue-metadata.controller.js index 15cafa3..76a628d 100644 --- a/zaqar_ui/static/dashboard/project/queues/steps/queue-metadata/queue-metadata.controller.js +++ b/zaqar_ui/static/dashboard/project/queues/steps/queue-metadata/queue-metadata.controller.js @@ -52,14 +52,13 @@ function init() { $q.all({ - available: standardDefinitions(), + available: standardDefinitions(queue), existing: getExistingMetdataPromise(queue) }) .then(onMetadataGet); } function onMetadataGet(response) { - console.log(response); ctrl.tree = new metaTree.Tree( response.available.data.items, response.existing.data @@ -70,26 +69,31 @@ return ctrl.tree.getExisting(); } - function standardDefinitions() { + function standardDefinitions(queue) { // TODO: currently, there is no standard metadefinitions // should add some reserved/fixed definition here // preferably it should come from zaqar and not hardcoded here - var deferred = $q.defer(); - deferred.resolve({data: []}); - return deferred.promise; + // however available metadata is needed for showing to be updated, + // so now we set existing metadata to available metadata. + if (angular.isDefined(queue.id)) { + return {data: queue.metadata}; + } else { + var deferred = $q.defer(); + deferred.resolve({data: []}); + return deferred.promise; + } } function getExistingMetdataPromise(queue) { - //if (angular.isDefined(queue.id)) { - // return metadata.getMetadata('queue', queue.id); - //} - //else { + if (angular.isDefined(queue.id)) { + return {data: queue.metadata}; + } else { var deferred = $q.defer(); deferred.resolve({data: []}); return deferred.promise; - //} + } } function onMetadataChanged(newValue, oldValue) { diff --git a/zaqar_ui/static/dashboard/project/queues/table/table.controller.js b/zaqar_ui/static/dashboard/project/queues/table/table.controller.js index e653f35..30d8210 100644 --- a/zaqar_ui/static/dashboard/project/queues/table/table.controller.js +++ b/zaqar_ui/static/dashboard/project/queues/table/table.controller.js @@ -52,9 +52,11 @@ function initScope() { var createWatcher = $scope.$on(events.CREATE_SUCCESS, onCreateSuccess); var deleteWatcher = $scope.$on(events.DELETE_SUCCESS, onDeleteSuccess); + var updateWatcher = $scope.$on(events.UPDATE_SUCCESS, onUpdateSuccess); $scope.$on('$destroy', function destroy() { createWatcher(); deleteWatcher(); + updateWatcher(); }) } @@ -92,6 +94,13 @@ // clear selections upon deletion $scope.$emit('hzTable:clearSelected'); } + + function onUpdateSuccess(e, queue) { + e.stopPropagation(); + queue.id = queue.name; + // update queue + ctrl.queuesSrc[queue.id] = queue; + } } })();