Add backups table to ng-backups panel

This patch is a simple rendering of the trove datastore
backups table using angular to display the backups data.
To view the angular panel and test this patch, change disabled
to false in trove-dashboard/trove_dashboard/enabled/
_1731_project_database_backups_panel.py

Change-Id: I1b3af4255a19d9c3605b752dd1b75288a980dfad
This commit is contained in:
Ishita Mandhan 2016-03-31 10:49:24 -07:00
parent 1c05349cb0
commit fb28910d4c
11 changed files with 331 additions and 8 deletions

View File

@ -0,0 +1,16 @@
# 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.
# import REST API modules here
from trove_dashboard.api.rest import trove # noqa

View File

@ -0,0 +1,82 @@
# 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.
from django.views import generic
from trove_dashboard.api import trove
from openstack_dashboard.api.rest import urls
from openstack_dashboard.api.rest import utils as rest_utils
@urls.register
class Backup(generic.View):
"""API for retrieving information about a single backup.
"""
url_regex = r'trove_dashboard/backups/(?P<backup_name>[^/]+)$'
@rest_utils.ajax()
def get(self, request, backup_id):
"""Get a specific backup.
"""
return trove.backup_get(request, backup_id).to_dict()
@urls.register
class Backups(generic.View):
"""API for backups.
"""
url_regex = r'trove/backups/$'
@rest_utils.ajax()
def get(self, request):
"""Get a list of the Backups.
The returned result is an object with property 'items' and each
item under this is a backup.
"""
result = trove.backup_list(request)
backups = []
for b in result:
instance = trove.instance_get(request, b.instance_id)
backups.append({'id': b.id,
'name': b.name,
'datastore': b.datastore.get('type'),
'datastoreversion': b.datastore.get('version'),
'created': b.created,
'database': instance.name,
'incremental': bool(b.parent_id),
'status': b.status
})
return backups
@rest_utils.ajax(data_required=True)
def delete(self, request):
"""Delete one or more backup by name.
Returns HTTP 204 (no content) on successful deletion.
"""
for backup_id in request.DATA:
trove.backup_delete(request, backup_id)
@rest_utils.ajax(data_required=True)
def create(self, request):
"""Create a new backup.
Returns the new backup object on success.
"""
new_backup = trove.backup_create(request, **request.DATA)
return rest_utils.CreatedResponse(
'/api/messaging/backups/%s' % new_backup.name,
new_backup.to_dict())

View File

@ -0,0 +1,17 @@
# 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.
# Register the REST API URLs so they can be called from the JavaScript files
import trove_dashboard.api.rest # noqa

View File

@ -3,8 +3,9 @@
{% block title %}{% trans "Backups" %}{% endblock %}
{% block page_header %}
<hz-page-header header="{$ 'Backups' | translate $}"></hz-page-header>
<base href="{{ WEBROOT }}">
{% endblock page_header %}
{% block main %}
<ng-include src="'{{STATIC_URL}}/dashboard/project/ngbackups/table/table.html'"></ng-include>
{% endblock %}

View File

@ -12,12 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls import patterns
from django.conf.urls import url
from django.conf import urls
from trove_dashboard.content.ng_database_backups import views
urlpatterns = patterns(
'',
url(r'^$', views.IndexView.as_view(), name='index'),
)
urlpatterns = [
urls.url(r'^$', views.IndexView.as_view(), name='index'),
]

View File

@ -25,5 +25,18 @@ DISABLED = True
# Python panel class of the PANEL to be added.
ADD_PANEL = ('trove_dashboard.content.ng_database_backups.panel.NGBackups')
ADD_ANGULAR_MODULES = ['horizon.dashboard.project.backups']
AUTO_DISCOVER_STATIC_FILES = True
ADD_SCSS_FILES = ['dashboard/project/ngbackups/backups.scss']
ADD_JS_FILES = [
'dashboard/project/ngbackups/backups.module.js',
'dashboard/project/ngbackups/table/table.controller.js',
'dashboard/project/ngbackups/table/table.config.js',
'app/core/openstack-service-api/trove.service.js'
]
ADD_JS_SPEC_FILES = [
'dashboard/project/ngbackups/backups.module.spec.js',
'dashboard/project/ngbackups/table/table.controller.spec.js'
]

View File

@ -0,0 +1,50 @@
/**
* 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';
/**
* @ngdoc overview
* @name horizon.dashboard.project.ngbackups
* @description Dashboard module for the ngbackups panel.
*/
angular
.module('horizon.app.core.openstack-service-api')
.factory('horizon.app.core.openstack-service-api.trove', TroveAPI);
TroveAPI.$inject = [
'horizon.framework.util.http.service',
'horizon.framework.widgets.toast.service'
];
function TroveAPI(apiService, toastService) {
var service = {
getBackups: getBackups
};
return service;
function getBackups() {
return apiService.get('/api/trove/backups/')
.error(function() {
toastService.add('error', gettext('Unable to retrieve the Backups.'));
});
}
}
}());

View File

@ -0,0 +1,81 @@
/**
* 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.backups')
.factory('horizon.dashboard.project.backups.tableConfigService',
tableConfigService);
tableConfigService.$inject = [
'horizon.framework.util.extensible.service'
];
/**
* @ngdoc service
* @name horizon.dashboard.project.ngbackups.tableConfigService
* @description Backup table attributes
*/
function tableConfigService(extensibleService) {
var config = {
selectAll: true,
expand: true,
trackId: 'id',
columns: [{
id: 'name',
title: gettext('Name'),
priority: 1,
sortDefault: true
},
{
id: 'datastore',
title: gettext('Datastore'),
priority: 1,
},
{
id: 'datastoreversion',
title: gettext('Datastore Version'),
priority: 1,
},
{
id: 'created',
title: gettext('Created'),
priority: 1,
},
{
id: 'database',
title: gettext('Database'),
priority: 1,
},
{
id: 'incremental',
title: gettext('Incremental'),
filters: ['yesno'],
priority: 1,
},
{
id: 'status',
title: gettext('status'),
priority: 1,
}]
};
extensibleService(config, config.columns);
return config;
}
})();

View File

@ -0,0 +1,58 @@
/**
* 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.backups')
.controller('horizon.dashboard.project.backups.tableController', backupsTableController);
backupsTableController.$inject = [
'$scope',
'horizon.app.core.openstack-service-api.trove',
'horizon.dashboard.project.backups.tableConfigService'
];
/**
* @ngdoc controller
* @name horizon.dashboard.project.backups.tableController
*
* @description
* Controller for the backups table
*/
function backupsTableController($scope, trove, config) {
var ctrl = this;
ctrl.config = config;
ctrl.backups = [];
ctrl.backupsSrc = [];
init();
//////////
function init() {
trove.getBackups().success(getBackupsSuccess);
}
function getBackupsSuccess(response) {
ctrl.backups = response;
}
}
})();

View File

@ -0,0 +1,7 @@
<div ng-controller="horizon.dashboard.project.backups.tableController as table">
<hz-dynamic-table
config="table.config"
items="table.backups"
safe-src-items="table.backupsSrc">
</hz-dynamic-table>
</div>