Merge "Migrate Swift to use ResourceType"

This commit is contained in:
Jenkins 2016-11-16 11:08:41 +00:00 committed by Gerrit Code Review
commit bd69fb8acc
10 changed files with 127 additions and 110 deletions

View File

@ -26,8 +26,16 @@
* to support and display the project containers panel.
*/
angular
.module('horizon.dashboard.project.containers', ['ngRoute'])
.config(config);
.module('horizon.dashboard.project.containers', [
'ngRoute',
'horizon.framework',
'horizon.app.core.openstack-service-api'
])
.constant('horizon.dashboard.project.containers.account.resourceType', 'OS::Swift::Account')
.constant('horizon.dashboard.project.containers.container.resourceType', 'OS::Swift::Container')
.constant('horizon.dashboard.project.containers.object.resourceType', 'OS::Swift::Object')
.config(config)
.run(run);
config.$inject = [
'$provide',
@ -65,4 +73,40 @@
templateUrl: path + 'objects.html'
});
}
run.$inject = [
'horizon.dashboard.project.containers.account.resourceType',
'horizon.dashboard.project.containers.container.resourceType',
'horizon.dashboard.project.containers.object.resourceType',
'horizon.framework.conf.resource-type-registry.service'
];
function run(accountResCode, containerResCode, objectResCode, registryService) {
registryService.getResourceType(accountResCode)
.setNames(gettext('Swift Account'), gettext('Swift Accounts'));
registryService.getResourceType(containerResCode)
.setNames(gettext('Swift Container'), gettext('Swift Containers'));
var objectResourceType = registryService.getResourceType(objectResCode);
objectResourceType.setNames(gettext('Object'), gettext('Objects'))
.setProperty('name', {label: gettext('Name')})
.setProperty('size', { label: gettext('Size')});
objectResourceType.tableColumns.append({
id: 'name', priority: 1, sortDefault: true,
template: '<a ng-if="item.is_subdir" ng-href="{$ table.objectURL(item) $}">' +
'{$ item.name $}</a><span ng-if="item.is_object">{$ item.name $}</span>'
})
.append({
id: 'size', priority: 1,
template: '<span ng-if="item.is_object">{$item.bytes | bytes$}</span>' +
'<span ng-if="item.is_subdir" translate>Folder</span>'
});
objectResourceType.filterFacets.append({
label: gettext('Name'),
name: 'name',
singleton: true
});
}
})();

View File

@ -17,14 +17,21 @@
'use strict';
describe('horizon.dashboard.project.containers.containerRoute constant', function () {
var baseRoute, containerRoute;
var baseRoute, containerRoute, registry;
beforeEach(module('horizon.dashboard.project.containers'));
beforeEach(inject(function ($injector) {
baseRoute = $injector.get('horizon.dashboard.project.containers.baseRoute');
containerRoute = $injector.get('horizon.dashboard.project.containers.containerRoute');
registry = $injector.get('horizon.framework.conf.resource-type-registry.service');
}));
it('should define types', function () {
expect(registry.getResourceType('OS::Swift::Account')).toBeDefined();
expect(registry.getResourceType('OS::Swift::Container')).toBeDefined();
expect(registry.getResourceType('OS::Swift::Object')).toBeDefined();
});
it('should define routes', function () {
expect(baseRoute).toBeDefined();
expect(containerRoute).toBeDefined();

View File

@ -34,7 +34,7 @@
var element = angular.element(
'<div><input type="file" on-file-change="changed" ng-model="model" />' +
'<span>{{ model }}</span></div>'
'<span>{$ model $}</span></div>'
);
element = $compile(element)($scope);
$scope.$apply();

View File

@ -19,50 +19,44 @@
angular
.module('horizon.dashboard.project.containers')
.factory('horizon.dashboard.project.containers.objects-batch-actions', batchActions)
.factory('horizon.dashboard.project.containers.objects-batch-actions.create-folder',
createFolderService)
.factory('horizon.dashboard.project.containers.objects-batch-actions.delete', deleteService)
.factory('horizon.dashboard.project.containers.objects-batch-actions.upload', uploadService);
.factory('horizon.dashboard.project.containers.objects-batch-actions.upload', uploadService)
.run(registerActions);
batchActions.$inject = [
registerActions.$inject = [
'horizon.framework.conf.resource-type-registry.service',
'horizon.dashboard.project.containers.object.resourceType',
'horizon.dashboard.project.containers.objects-batch-actions.create-folder',
'horizon.dashboard.project.containers.objects-batch-actions.delete',
'horizon.dashboard.project.containers.objects-batch-actions.upload'
];
/**
* @ngdoc factory
* @name horizon.app.core.images.table.row-actions.service
* @description A list of row actions.
* @name registerActions
* @description Register batch and global actions.
*/
function batchActions(
function registerActions(
registryService,
objectResCode,
createFolderService,
deleteService,
uploadService
) {
return {
actions: actions
};
///////////////
function actions() {
return [
{
service: uploadService,
template: {text: '<span class="fa fa-upload"></span>'}
},
{
service: createFolderService,
template: {text: '<span class="fa fa-plus"></span>&nbsp;' + gettext('Folder')}
},
{
service: deleteService,
template: {text: '', type: 'delete-selected'}
}
];
}
registryService.getResourceType(objectResCode).batchActions
.append({
service: uploadService,
template: {text: '<span class="fa fa-upload"></span>'}
})
.append({
service: createFolderService,
template: {text: '<span class="fa fa-plus"></span>&nbsp;' + gettext('Folder')}
})
.append({
service: deleteService,
template: {text: '', type: 'delete-selected'}
});
}
function uploadModal(html, $modal) {

View File

@ -32,7 +32,9 @@
var batchActions, modalWaitSpinnerService, model, $q, $rootScope, swiftAPI, toast;
beforeEach(inject(function inject($injector, _$q_, _$rootScope_) {
batchActions = $injector.get('horizon.dashboard.project.containers.objects-batch-actions');
var resourceService = $injector.get('horizon.framework.conf.resource-type-registry.service');
var objectResCode = $injector.get('horizon.dashboard.project.containers.object.resourceType');
batchActions = resourceService.getResourceType(objectResCode).batchActions;
modalWaitSpinnerService = $injector.get(
'horizon.framework.widgets.modal-wait-spinner.service'
);
@ -55,10 +57,8 @@
}));
it('should create an actions list', function test() {
expect(batchActions.actions).toBeDefined();
var actions = batchActions.actions();
expect(actions.length).toEqual(3);
angular.forEach(actions, function check(action) {
expect(batchActions.length).toEqual(3);
angular.forEach(batchActions, function check(action) {
expect(action.service).toBeDefined();
expect(action.template).toBeDefined();
expect(action.template.text).toBeDefined();

View File

@ -19,13 +19,15 @@
angular
.module('horizon.dashboard.project.containers')
.factory('horizon.dashboard.project.containers.objects-row-actions', rowActions)
.factory('horizon.dashboard.project.containers.objects-actions.delete', deleteService)
.factory('horizon.dashboard.project.containers.objects-actions.download', downloadService)
.factory('horizon.dashboard.project.containers.objects-actions.edit', editService)
.factory('horizon.dashboard.project.containers.objects-actions.view', viewService);
.factory('horizon.dashboard.project.containers.objects-actions.view', viewService)
.run(registerActions);
rowActions.$inject = [
registerActions.$inject = [
'horizon.framework.conf.resource-type-registry.service',
'horizon.dashboard.project.containers.object.resourceType',
'horizon.dashboard.project.containers.objects-actions.delete',
'horizon.dashboard.project.containers.objects-actions.download',
'horizon.dashboard.project.containers.objects-actions.edit',
@ -33,43 +35,35 @@
'horizon.framework.util.i18n.gettext'
];
/**
* @ngdoc factory
* @name horizon.app.core.images.table.row-actions.service
* @description A list of row actions.
* @name registerActions
* @description Register the row actions for objects.
*/
function rowActions(
function registerActions(
registryService,
objectResCode,
deleteService,
downloadService,
editService,
viewService,
gettext
) {
return {
actions: actions
};
///////////////
function actions() {
return [
{
service: downloadService,
template: {text: gettext('Download')}
},
{
service: editService,
template: {text: gettext('Edit')}
},
{
service: viewService,
template: {text: gettext('View Details')}
},
{
service: deleteService,
template: {text: gettext('Delete'), type: 'delete'}
}
];
}
registryService.getResourceType(objectResCode).itemActions
.append({
service: downloadService,
template: {text: gettext('Download')}
})
.append({
service: viewService,
template: {text: gettext('View Details')}
})
.append({
service: editService,
template: {text: gettext('Edit')}
})
.append({
service: deleteService,
template: {text: gettext('Delete'), type: 'delete'}
});
}
downloadService.$inject = [

View File

@ -32,17 +32,17 @@
var rowActions, $modal, $rootScope, model;
beforeEach(inject(function inject($injector, _$modal_, _$rootScope_) {
rowActions = $injector.get('horizon.dashboard.project.containers.objects-row-actions');
var resourceService = $injector.get('horizon.framework.conf.resource-type-registry.service');
var objectResCode = $injector.get('horizon.dashboard.project.containers.object.resourceType');
rowActions = resourceService.getResourceType(objectResCode).itemActions;
model = $injector.get('horizon.dashboard.project.containers.containers-model');
$modal = _$modal_;
$rootScope = _$rootScope_;
}));
it('should create an actions list', function test() {
expect(rowActions.actions).toBeDefined();
var actions = rowActions.actions();
expect(actions.length).toEqual(4);
angular.forEach(actions, function check(action) {
expect(rowActions.length).toEqual(4);
angular.forEach(rowActions, function check(action) {
expect(action.service).toBeDefined();
expect(action.template).toBeDefined();
expect(action.template.text).toBeDefined();

View File

@ -30,28 +30,29 @@
.controller('horizon.dashboard.project.containers.ObjectsController', ObjectsController);
ObjectsController.$inject = [
'horizon.framework.conf.resource-type-registry.service',
'horizon.dashboard.project.containers.containers-model',
'horizon.dashboard.project.containers.containerRoute',
'horizon.dashboard.project.containers.objects-batch-actions',
'horizon.dashboard.project.containers.objects-row-actions',
'horizon.dashboard.project.containers.object.resourceType',
'horizon.framework.widgets.table.events',
'$q',
'$routeParams',
'$scope'
];
function ObjectsController(containersModel,
function ObjectsController(registryService,
containersModel,
containerRoute,
batchActions,
rowActions,
objectResCode,
hzTableEvents,
$q,
$routeParams,
$scope) {
var ctrl = this;
var objectResourceType = registryService.getResourceType(objectResCode);
ctrl.rowActions = rowActions;
ctrl.batchActions = batchActions;
ctrl.rowActions = objectResourceType.itemActions;
ctrl.batchActions = objectResourceType.batchActions;
ctrl.model = containersModel;
ctrl.numSelected = 0;
@ -76,30 +77,13 @@
});
});
ctrl.filterFacets = [
{
label: gettext('Name'),
name: 'name',
singleton: true
}
];
ctrl.filterFacets = objectResourceType.filterFacets;
ctrl.tableConfig = {
selectAll: true,
expand: false,
trackId: 'path',
columns: [
{
id: 'name', title: 'Name', priority: 1, sortDefault: true,
template: '<a ng-if="item.is_subdir" ng-href="{$ table.objectURL(item) $}">' +
'{$ item.name $}</a><span ng-if="item.is_object">{$ item.name $}</span>'
},
{
id: 'size', title: 'Size', priority: 1,
template: '<span ng-if="item.is_object">{$item.bytes | bytes$}</span>' +
'<span ng-if="item.is_subdir" translate>Folder</span>'
}
]
columns: objectResourceType.getTableColumns()
};
ctrl.getBreadcrumbs = getBreadcrumbs;

View File

@ -16,8 +16,8 @@
items="oc.model.objects"
table="oc"
filter-facets="oc.filterFacets"
batch-actions="oc.batchActions.actions"
item-actions="oc.rowActions.actions"
batch-actions="oc.batchActions"
item-actions="oc.rowActions"
result-handler="oc.actionResultHandler">
</hz-dynamic-table>
</div>

View File

@ -60,12 +60,6 @@
.setNames(gettext('Volume Snapshot'), gettext('Volume Snapshots'));
registry.getResourceType('OS::Cinder::Volume')
.setNames(gettext('Volume'), gettext('Volumes'));
registry.getResourceType('OS::Swift::Account')
.setNames(gettext('Object Account'), gettext('Object Accounts'));
registry.getResourceType('OS::Swift::Container')
.setNames(gettext('Object Container'), gettext('Object Containers'));
registry.getResourceType('OS::Swift::Object')
.setNames(gettext('Object'), gettext('Objects'));
registry.getResourceType('OS::Neutron::HealthMonitor')
.setNames(gettext('Network Health Monitor'), gettext('Network Health Monitors'));
registry.getResourceType('OS::Neutron::Net')