Add delete action for capsule
This patch adds delete action for capsule as batch action. Also, adds delete force action as item action. Change-Id: Iaa27808d55a92f813d4f268ff7cc11cfbc584613 Implements: blueprint capsule
This commit is contained in:
parent
05e5bb1b99
commit
327f0c9e8c
@ -284,6 +284,10 @@ def capsule_create(request, **kwargs):
|
|||||||
return zunclient(request).capsules.create(**args)
|
return zunclient(request).capsules.create(**args)
|
||||||
|
|
||||||
|
|
||||||
|
def capsule_delete(request, **kwargs):
|
||||||
|
return zunclient(request).capsules.delete(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def image_list(request, limit=None, marker=None, sort_key=None,
|
def image_list(request, limit=None, marker=None, sort_key=None,
|
||||||
sort_dir=None, detail=False):
|
sort_dir=None, detail=False):
|
||||||
# FIXME(shu-mutou): change "detail" param to True, if it enabled.
|
# FIXME(shu-mutou): change "detail" param to True, if it enabled.
|
||||||
|
@ -178,6 +178,16 @@ class Capsules(generic.View):
|
|||||||
result = client.capsule_list(request)
|
result = client.capsule_list(request)
|
||||||
return {'items': [i.to_dict() for i in result]}
|
return {'items': [i.to_dict() for i in result]}
|
||||||
|
|
||||||
|
@rest_utils.ajax(data_required=True)
|
||||||
|
def delete(self, request):
|
||||||
|
"""Delete one or more Capsules by id.
|
||||||
|
|
||||||
|
Returns HTTP 204 (no content) on successful deletion.
|
||||||
|
"""
|
||||||
|
for id in request.DATA:
|
||||||
|
opts = {'id': id}
|
||||||
|
client.capsule_delete(request, **opts)
|
||||||
|
|
||||||
@rest_utils.ajax(data_required=True)
|
@rest_utils.ajax(data_required=True)
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
"""Create a new Capsule.
|
"""Create a new Capsule.
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
'horizon.framework.conf.resource-type-registry.service',
|
'horizon.framework.conf.resource-type-registry.service',
|
||||||
'horizon.framework.util.i18n.gettext',
|
'horizon.framework.util.i18n.gettext',
|
||||||
'horizon.dashboard.container.capsules.actions.create.service',
|
'horizon.dashboard.container.capsules.actions.create.service',
|
||||||
|
'horizon.dashboard.container.capsules.actions.delete.service',
|
||||||
'horizon.dashboard.container.capsules.actions.refresh.service',
|
'horizon.dashboard.container.capsules.actions.refresh.service',
|
||||||
'horizon.dashboard.container.capsules.resourceType'
|
'horizon.dashboard.container.capsules.resourceType'
|
||||||
];
|
];
|
||||||
@ -41,6 +42,7 @@
|
|||||||
registry,
|
registry,
|
||||||
gettext,
|
gettext,
|
||||||
createCapsuleService,
|
createCapsuleService,
|
||||||
|
deleteCapsuleService,
|
||||||
refreshCapsuleService,
|
refreshCapsuleService,
|
||||||
resourceType
|
resourceType
|
||||||
) {
|
) {
|
||||||
@ -55,7 +57,16 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME(shu-mutow): refresh action is dummy. remove it when add other item action.
|
capsulesResourceType.batchActions
|
||||||
|
.append({
|
||||||
|
id: 'deleteCapsuleAction',
|
||||||
|
service: deleteCapsuleService,
|
||||||
|
template: {
|
||||||
|
type: 'delete-selected',
|
||||||
|
text: gettext('Delete')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
capsulesResourceType.itemActions
|
capsulesResourceType.itemActions
|
||||||
.append({
|
.append({
|
||||||
id: 'refreshCapsuleAction',
|
id: 'refreshCapsuleAction',
|
||||||
@ -63,6 +74,14 @@
|
|||||||
template: {
|
template: {
|
||||||
text: gettext('Refresh')
|
text: gettext('Refresh')
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.append({
|
||||||
|
id: 'deleteCapsuleAction',
|
||||||
|
service: deleteCapsuleService,
|
||||||
|
template: {
|
||||||
|
type: 'delete',
|
||||||
|
text: gettext('Delete')
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,158 @@
|
|||||||
|
/**
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use self 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';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ngDoc factory
|
||||||
|
* @name horizon.dashboard.container.capsules.actions.delete.service
|
||||||
|
* @Description
|
||||||
|
* Brings up the delete capsules confirmation modal dialog.
|
||||||
|
* On submit, delete selected resources.
|
||||||
|
* On cancel, do nothing.
|
||||||
|
*/
|
||||||
|
angular
|
||||||
|
.module('horizon.dashboard.container.capsules.actions')
|
||||||
|
.factory('horizon.dashboard.container.capsules.actions.delete.service', deleteService);
|
||||||
|
|
||||||
|
deleteService.$inject = [
|
||||||
|
'$location',
|
||||||
|
'$q',
|
||||||
|
'$rootScope',
|
||||||
|
'horizon.app.core.openstack-service-api.zun',
|
||||||
|
'horizon.app.core.openstack-service-api.policy',
|
||||||
|
'horizon.framework.util.actions.action-result.service',
|
||||||
|
'horizon.framework.util.i18n.gettext',
|
||||||
|
'horizon.framework.util.q.extensions',
|
||||||
|
'horizon.framework.widgets.modal.deleteModalService',
|
||||||
|
'horizon.framework.widgets.table.events',
|
||||||
|
'horizon.framework.widgets.toast.service',
|
||||||
|
'horizon.dashboard.container.capsules.resourceType',
|
||||||
|
'horizon.dashboard.container.capsules.events'
|
||||||
|
];
|
||||||
|
|
||||||
|
function deleteService(
|
||||||
|
$location, $q, $rootScope, zun, policy, actionResult, gettext, $qExtensions, deleteModal,
|
||||||
|
tableEvents, toast, resourceType, events
|
||||||
|
) {
|
||||||
|
var scope;
|
||||||
|
var context = {
|
||||||
|
labels: null,
|
||||||
|
deleteEntity: deleteEntity,
|
||||||
|
successEvent: events.DELETE_SUCCESS
|
||||||
|
};
|
||||||
|
var service = {
|
||||||
|
initAction: initAction,
|
||||||
|
allowed: allowed,
|
||||||
|
perform: perform
|
||||||
|
};
|
||||||
|
var notAllowedMessage = gettext("You are not allowed to delete capsules: %s");
|
||||||
|
|
||||||
|
return service;
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
|
||||||
|
function initAction() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function allowed() {
|
||||||
|
// only row actions pass in capsule
|
||||||
|
// otherwise, assume it is a batch action
|
||||||
|
return $qExtensions.booleanAsPromise(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete selected resource objects
|
||||||
|
function perform(selected, newScope) {
|
||||||
|
scope = newScope;
|
||||||
|
selected = angular.isArray(selected) ? selected : [selected];
|
||||||
|
context.labels = labelize(selected.length);
|
||||||
|
return $qExtensions.allSettled(selected.map(checkPermission)).then(afterCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
function labelize(count) {
|
||||||
|
return {
|
||||||
|
title: ngettext('Confirm Delete Capsule',
|
||||||
|
'Confirm Delete Capsules', count),
|
||||||
|
/* eslint-disable max-len */
|
||||||
|
message: ngettext('You have selected "%s". Please confirm your selection. Deleted capsule is not recoverable.',
|
||||||
|
'You have selected "%s". Please confirm your selection. Deleted capsules are not recoverable.', count),
|
||||||
|
/* eslint-enable max-len */
|
||||||
|
submit: ngettext('Delete Capsule',
|
||||||
|
'Delete Capsules', count),
|
||||||
|
success: ngettext('Deleted Capsule: %s.',
|
||||||
|
'Deleted Capsules: %s.', count),
|
||||||
|
error: ngettext('Unable to delete Capsule: %s.',
|
||||||
|
'Unable to delete Capsules: %s.', count)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// for batch delete
|
||||||
|
function checkPermission(selected) {
|
||||||
|
return {promise: allowed(selected), context: selected};
|
||||||
|
}
|
||||||
|
|
||||||
|
// for batch delete
|
||||||
|
function afterCheck(result) {
|
||||||
|
var outcome = $q.reject(); // Reject the promise by default
|
||||||
|
if (result.fail.length > 0) {
|
||||||
|
toast.add('error', getMessage(notAllowedMessage, result.fail));
|
||||||
|
outcome = $q.reject(result.fail);
|
||||||
|
}
|
||||||
|
if (result.pass.length > 0) {
|
||||||
|
outcome = deleteModal.open(scope, result.pass.map(getEntity), context).then(createResult);
|
||||||
|
}
|
||||||
|
return outcome;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createResult(deleteModalResult) {
|
||||||
|
// To make the result of this action generically useful, reformat the return
|
||||||
|
// from the deleteModal into a standard form
|
||||||
|
var result = actionResult.getActionResult();
|
||||||
|
deleteModalResult.pass.forEach(function markDeleted(item) {
|
||||||
|
result.updated(resourceType, getEntity(item).id);
|
||||||
|
});
|
||||||
|
deleteModalResult.fail.forEach(function markFailed(item) {
|
||||||
|
result.failed(resourceType, getEntity(item).id);
|
||||||
|
});
|
||||||
|
var indexPath = '/project/container/capsules';
|
||||||
|
var currentPath = $location.path();
|
||||||
|
if (result.result.failed.length === 0 && result.result.updated.length > 0 &&
|
||||||
|
currentPath !== indexPath) {
|
||||||
|
$location.path(indexPath);
|
||||||
|
} else {
|
||||||
|
$rootScope.$broadcast(tableEvents.CLEAR_SELECTIONS);
|
||||||
|
return result.result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMessage(message, entities) {
|
||||||
|
return interpolate(message, [entities.map(getName).join(", ")]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getName(result) {
|
||||||
|
return getEntity(result).name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for batch delete
|
||||||
|
function getEntity(result) {
|
||||||
|
return result.context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// call delete REST API
|
||||||
|
function deleteEntity(id) {
|
||||||
|
return zun.deleteCapsule(id, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
@ -56,6 +56,7 @@
|
|||||||
getCapsules: getCapsules,
|
getCapsules: getCapsules,
|
||||||
getCapsule: getCapsule,
|
getCapsule: getCapsule,
|
||||||
createCapsule: createCapsule,
|
createCapsule: createCapsule,
|
||||||
|
deleteCapsule: deleteCapsule,
|
||||||
pullImage: pullImage,
|
pullImage: pullImage,
|
||||||
getImages: getImages,
|
getImages: getImages,
|
||||||
deleteImage: deleteImage,
|
deleteImage: deleteImage,
|
||||||
@ -220,6 +221,14 @@
|
|||||||
return apiService.post(capsulesPath, params).error(error(msg));
|
return apiService.post(capsulesPath, params).error(error(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteCapsule(id, suppressError) {
|
||||||
|
var promise = apiService.delete(capsulesPath, [id]);
|
||||||
|
return suppressError ? promise : promise.error(function() {
|
||||||
|
var msg = gettext('Unable to delete the Capsule with id: %(id)s');
|
||||||
|
toastService.add('error', interpolate(msg, { id: id }, true));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
// Images //
|
// Images //
|
||||||
////////////
|
////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user