Refresh views after actions

This patch fixes to refresh views after actions,
also adds refresh action as item action for manual refreshing.

Adding refresh action is trivial fix. Ideally, refresh action
should be implemented by Horizon framework.

Change-Id: I1b0b5084a7a3a3df96e04200add8f3843587cb76
This commit is contained in:
Shu Muto 2017-04-05 15:09:34 +09:00
parent 2d1094c363
commit 3ed91caa43
11 changed files with 132 additions and 24 deletions

View File

@ -42,6 +42,7 @@
'horizon.dashboard.container.containers.unpause.service',
'horizon.dashboard.container.containers.execute.service',
'horizon.dashboard.container.containers.kill.service',
'horizon.dashboard.container.containers.refresh.service',
'horizon.dashboard.container.containers.resourceType'
];
@ -58,6 +59,7 @@
unpauseContainerService,
executeContainerService,
killContainerService,
refreshContainerService,
resourceType
) {
var containersResourceType = registry.getResourceType(resourceType);
@ -83,6 +85,13 @@
});
containersResourceType.itemActions
.append({
id: 'refreshContainerAction',
service: refreshContainerService,
template: {
text: gettext('Refresh')
}
})
.append({
id: 'startContainerAction',
service: startContainerService,

View File

@ -74,8 +74,6 @@
return {data: {items: response.data.items.map(modifyItem)}};
function modifyItem(item) {
// we should set 'trackBy' as follows ideally.
// var timestamp = item.updated_at ? item.updated_at : item.created_at;
var timestamp = new Date();
item.trackBy = item.id.concat(timestamp.getTime());
return item;

View File

@ -26,6 +26,7 @@
$scope
) {
var ctrl = this;
$scope.context.loadPromise.then(onGetContainer);
function onGetContainer(container) {

View File

@ -29,6 +29,8 @@
executeContainerService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.i18n.gettext',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.form.ModalFormService',
@ -36,7 +38,7 @@
];
function executeContainerService(
zun, gettext, $qExtensions, modal, toast
zun, resourceType, actionResult, gettext, $qExtensions, modal, toast
) {
// schema
var schema = {
@ -112,6 +114,8 @@
delete context.model.name;
return zun.executeContainer(id, context.model).then(function() {
toast.add('success', interpolate(message.success, [name]));
var result = actionResult.getActionResult().updated(resourceType, id);
return result.result;
});
}
}

View File

@ -30,6 +30,8 @@
killContainerService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.basePath',
'horizon.dashboard.container.containers.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.i18n.gettext',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.form.ModalFormService',
@ -37,7 +39,7 @@
];
function killContainerService(
zun, basePath, gettext, $qExtensions, modal, toast
zun, basePath, resourceType, actionResult, gettext, $qExtensions, modal, toast
) {
// schema
var schema = {
@ -122,6 +124,8 @@
delete context.model.name;
return zun.killContainer(id, context.model).then(function() {
toast.add('success', interpolate(message.success, [name]));
var result = actionResult.getActionResult().updated(resourceType, id);
return result.result;
});
}
}

View File

@ -26,12 +26,16 @@
.factory('horizon.dashboard.container.containers.pause.service', pauseService);
pauseService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.toast.service',
'horizon.app.core.openstack-service-api.zun'
'horizon.framework.widgets.toast.service'
];
function pauseService($qExtensions, toast, zun) {
function pauseService(
zun, resourceType, actionResult, $qExtensions, toast
) {
var message = {
success: gettext('Container %s was successfully paused.')
@ -62,6 +66,8 @@
function success() {
toast.add('success', interpolate(message.success, [selected.name]));
var result = actionResult.getActionResult().updated(resourceType, selected.id);
return result.result;
}
}
}

View File

@ -26,13 +26,15 @@
.factory('horizon.dashboard.container.containers.reboot.service', rebootService);
rebootService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.toast.service',
'horizon.app.core.openstack-service-api.zun'
'horizon.framework.widgets.toast.service'
];
function rebootService(
$qExtensions, toast, zun
zun, resourceType, actionResult, $qExtensions, toast
) {
var message = {
@ -60,8 +62,10 @@
function perform(selected) {
// reboot selected container
return zun.rebootContainer(selected.id).success(function() {
return zun.rebootContainer(selected.id).then(function() {
toast.add('success', interpolate(message.success, [selected.name]));
var result = actionResult.getActionResult().updated(resourceType, selected.id);
return result.result;
});
}
}

View File

@ -0,0 +1,68 @@
/**
* 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.containers.refresh.service
* @Description
* refresh container.
*/
angular
.module('horizon.dashboard.container.containers')
.factory('horizon.dashboard.container.containers.refresh.service', refreshService);
refreshService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.q.extensions'
];
function refreshService(
zun, resourceType, actionResult, $qExtensions
) {
var service = {
initAction: initAction,
allowed: allowed,
perform: perform
};
return service;
//////////////
// include this function in your service
// if you plan to emit events to the parent controller
function initAction() {
}
function allowed() {
return $qExtensions.booleanAsPromise(true);
}
function perform(selected) {
// refresh selected container
return $qExtensions.booleanAsPromise(true).then(success);
function success() {
var result = actionResult.getActionResult().updated(resourceType, selected.id);
return result.result;
}
}
}
})();

View File

@ -26,13 +26,15 @@
.factory('horizon.dashboard.container.containers.start.service', startService);
startService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.toast.service',
'horizon.app.core.openstack-service-api.zun'
'horizon.framework.widgets.toast.service'
];
function startService(
$qExtensions, toast, zun
zun, resourceType, actionResult, $qExtensions, toast
) {
var message = {
@ -60,8 +62,10 @@
function perform(selected) {
// start selected container
return zun.startContainer(selected.id).success(function() {
return zun.startContainer(selected.id).then(function() {
toast.add('success', interpolate(message.success, [selected.name]));
var result = actionResult.getActionResult().updated(resourceType, selected.id);
return result.result;
});
}
}

View File

@ -26,13 +26,15 @@
.factory('horizon.dashboard.container.containers.stop.service', stopService);
stopService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.toast.service',
'horizon.app.core.openstack-service-api.zun'
'horizon.framework.widgets.toast.service'
];
function stopService(
$qExtensions, toast, zun
zun, resourceType, actionResult, $qExtensions, toast
) {
var message = {
@ -60,8 +62,10 @@
function perform(selected) {
// start selected container
return zun.stopContainer(selected.id).success(function() {
return zun.stopContainer(selected.id).then(function() {
toast.add('success', interpolate(message.success, [selected.name]));
var result = actionResult.getActionResult().updated(resourceType, selected.id);
return result.result;
});
}
}

View File

@ -26,13 +26,15 @@
.factory('horizon.dashboard.container.containers.unpause.service', unpauseService);
unpauseService.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.containers.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.framework.util.q.extensions',
'horizon.framework.widgets.toast.service',
'horizon.app.core.openstack-service-api.zun'
'horizon.framework.widgets.toast.service'
];
function unpauseService(
$qExtensions, toast, zun
zun, resourceType, actionResult, $qExtensions, toast
) {
var message = {
@ -60,9 +62,13 @@
function perform(selected) {
// unpause selected container
return zun.unpauseContainer(selected.id).success(function() {
return zun.unpauseContainer(selected.id).then(success);
function success() {
toast.add('success', interpolate(message.success, [selected.name]));
});
var result = actionResult.getActionResult().updated(resourceType, selected.id);
return result.result;
}
}
}
})();