Add update queue action

This patch adds Update Queue action into item_actions.

- show item action
- show workflow (set "name" input as disabled)
- load data into workflow
- post data to REST API
- treat result

We need wait for following implementation in Zaqar API,
so these things is not scope of this patch.
- provide available metadata
- remove existing metadata

Change-Id: I21e05b49fa757ed7fb3459c0e87767df7c0926c6
This commit is contained in:
shu-mutou 2016-03-01 16:30:35 +09:00
parent a84224324b
commit 79eb829d73
11 changed files with 215 additions and 17 deletions

View File

@ -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

View File

@ -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):

View File

@ -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.'));
});
}
}
}());

View File

@ -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')
}
});

View File

@ -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

View File

@ -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;
}
})();

View File

@ -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'
};
}

View File

@ -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;
////////////////////////

View File

@ -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 $}">
<p class="help-block alert alert-danger"
ng-show="queueDetailsForm.name.$invalid && queueDetailsForm.name.$dirty">

View File

@ -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) {

View File

@ -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;
}
}
})();