Merge "Show actions according to container status"

This commit is contained in:
Jenkins 2017-08-20 05:55:14 +00:00 committed by Gerrit Code Review
commit be8daba64b
11 changed files with 96 additions and 32 deletions

View File

@ -38,12 +38,13 @@
'horizon.framework.widgets.modal.deleteModalService',
'horizon.framework.widgets.toast.service',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.events'
'horizon.dashboard.container.containers.events',
'horizon.dashboard.container.containers.validStates'
];
function deleteForceService(
$location, $q, zun, policy, actionResult, gettext, $qExtensions, deleteModal,
toast, resourceType, events
toast, resourceType, events, validStates
) {
var scope;
var context = {
@ -65,8 +66,10 @@
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
function allowed(container) {
return $qExtensions.booleanAsPromise(
validStates.delete_force.indexOf(container.status) >= 0
);
}
// delete selected resource objects

View File

@ -38,12 +38,13 @@
'horizon.framework.widgets.modal.deleteModalService',
'horizon.framework.widgets.toast.service',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.events'
'horizon.dashboard.container.containers.events',
'horizon.dashboard.container.containers.validStates'
];
function deleteService(
$location, $q, zun, policy, actionResult, gettext, $qExtensions, deleteModal,
toast, resourceType, events
toast, resourceType, events, validStates
) {
var scope;
var context = {
@ -65,8 +66,16 @@
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
function allowed(container) {
// only row actions pass in container
// otherwise, assume it is a batch action
if (container) {
return $qExtensions.booleanAsPromise(
validStates.delete.indexOf(container.status) >= 0
);
} else {
return $qExtensions.booleanAsPromise(true);
}
}
// delete selected resource objects

View File

@ -30,6 +30,7 @@
executeContainerService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.validStates',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.i18n.gettext',
'horizon.framework.util.q.extensions',
@ -39,7 +40,7 @@
];
function executeContainerService(
zun, resourceType, actionResult, gettext, $qExtensions, modal, waitSpinner, toast
zun, resourceType, validStates, actionResult, gettext, $qExtensions, modal, waitSpinner, toast
) {
// schema
var schema = {
@ -121,8 +122,10 @@
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
function allowed(container) {
return $qExtensions.booleanAsPromise(
validStates.execute.indexOf(container.status) >= 0
);
}
function perform(selected) {

View File

@ -31,6 +31,7 @@
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.basePath',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.validStates',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.i18n.gettext',
'horizon.framework.util.q.extensions',
@ -39,7 +40,7 @@
];
function killContainerService(
zun, basePath, resourceType, actionResult, gettext, $qExtensions, modal, toast
zun, basePath, resourceType, validStates, actionResult, gettext, $qExtensions, modal, toast
) {
// schema
var schema = {
@ -96,8 +97,10 @@
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
function allowed(container) {
return $qExtensions.booleanAsPromise(
validStates.kill.indexOf(container.status) >= 0
);
}
function perform(selected) {

View File

@ -28,13 +28,14 @@
pauseService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.validStates',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.toast.service'
];
function pauseService(
zun, resourceType, actionResult, $qExtensions, toast
zun, resourceType, validStates, actionResult, $qExtensions, toast
) {
var message = {
@ -56,8 +57,10 @@
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
function allowed(container) {
return $qExtensions.booleanAsPromise(
validStates.pause.indexOf(container.status) >= 0
);
}
function perform(selected) {

View File

@ -29,6 +29,7 @@
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.basePath',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.validStates',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.i18n.gettext',
'horizon.framework.util.q.extensions',
@ -37,7 +38,7 @@
];
function restartService(
zun, basePath, resourceType, actionResult, gettext, $qExtensions, modal, toast
zun, basePath, resourceType, validStates, actionResult, gettext, $qExtensions, modal, toast
) {
// schema
var schema = {
@ -93,8 +94,10 @@
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
function allowed(container) {
return $qExtensions.booleanAsPromise(
validStates.restart.indexOf(container.status) >= 0
);
}
function perform(selected) {

View File

@ -28,13 +28,14 @@
startService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.validStates',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.toast.service'
];
function startService(
zun, resourceType, actionResult, $qExtensions, toast
zun, resourceType, validStates, actionResult, $qExtensions, toast
) {
var message = {
@ -56,8 +57,10 @@
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
function allowed(container) {
return $qExtensions.booleanAsPromise(
validStates.start.indexOf(container.status) >= 0
);
}
function perform(selected) {

View File

@ -29,6 +29,7 @@
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.basePath',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.validStates',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.i18n.gettext',
'horizon.framework.util.q.extensions',
@ -37,7 +38,7 @@
];
function stopService(
zun, basePath, resourceType, actionResult, gettext, $qExtensions, modal, toast
zun, basePath, resourceType, validStates, actionResult, gettext, $qExtensions, modal, toast
) {
// schema
var schema = {
@ -93,8 +94,10 @@
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
function allowed(container) {
return $qExtensions.booleanAsPromise(
validStates.stop.indexOf(container.status) >= 0
);
}
function perform(selected) {

View File

@ -28,13 +28,14 @@
unpauseService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.validStates',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.toast.service'
];
function unpauseService(
zun, resourceType, actionResult, $qExtensions, toast
zun, resourceType, validStates, actionResult, $qExtensions, toast
) {
var message = {
@ -56,8 +57,10 @@
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
function allowed(container) {
return $qExtensions.booleanAsPromise(
validStates.unpause.indexOf(container.status) >= 0
);
}
function perform(selected) {

View File

@ -25,9 +25,11 @@
.factory('horizon.dashboard.container.containers.update.service', updateService);
updateService.$inject = [
'$q',
'horizon.app.core.openstack-service-api.policy',
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.dashboard.container.containers.validStates',
'horizon.dashboard.container.containers.workflow',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.i18n.gettext',
@ -37,7 +39,7 @@
];
function updateService(
policy, zun, resourceType, workflow,
$q, policy, zun, resourceType, validStates, workflow,
actionResult, gettext, $qExtensions, modal, toast
) {
var message = {
@ -98,8 +100,13 @@
return modal.open(config).then(submit);
}
function allowed() {
return policy.ifAllowed({ rules: [['container', 'edit_container']] });
function allowed(container) {
return $q.all([
policy.ifAllowed({ rules: [['container', 'edit_container']] }),
$qExtensions.booleanAsPromise(
validStates.update.indexOf(container.status) >= 0
)
]);
}
function submit(context) {

View File

@ -30,6 +30,7 @@
'horizon.dashboard.container.containers.details'
])
.constant('horizon.dashboard.container.containers.events', events())
.constant('horizon.dashboard.container.containers.validStates', validStates())
.constant('horizon.dashboard.container.containers.resourceType', 'OS::Zun::Container')
.run(run)
.config(config);
@ -47,6 +48,29 @@
};
}
function validStates() {
var states = {
ERROR: 'Error', RUNNING: 'Running', STOPPED: 'Stopped',
PAUSED: 'Paused', UNKNOWN: 'Unknown', CREATING: 'Creating',
CREATED: 'Created', DELETED: 'Deleted'
};
return {
update: [states.CREATED, states.RUNNING, states.STOPPED, states.PAUSED],
start: [states.CREATED, states.STOPPED, states.ERROR],
stop: [states.RUNNING],
restart: [states.CREATED, states.RUNNING, states.STOPPED, states.ERROR],
pause: [states.RUNNING],
unpause: [states.PAUSED],
execute: [states.RUNNING],
kill: [states.RUNNING],
delete: [states.CREATED, states.ERROR, states.STOPPED, states.DELETED],
delete_force: [
states.CREATED, states.CREATING, states.ERROR, states.RUNNING,
states.STOPPED, states.UNKNOWN, states.DELETED
]
};
}
run.$inject = [
'horizon.framework.conf.resource-type-registry.service',
'horizon.app.core.openstack-service-api.zun',