diff --git a/trove_dashboard/api/rest/__init__.py b/trove_dashboard/api/rest/__init__.py new file mode 100644 index 0000000..8aa5ed2 --- /dev/null +++ b/trove_dashboard/api/rest/__init__.py @@ -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 diff --git a/trove_dashboard/api/rest/trove.py b/trove_dashboard/api/rest/trove.py new file mode 100644 index 0000000..4347e2d --- /dev/null +++ b/trove_dashboard/api/rest/trove.py @@ -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[^/]+)$' + + @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()) diff --git a/trove_dashboard/content/ng_database_backups/__init__.py b/trove_dashboard/content/ng_database_backups/__init__.py index e69de29..a7e6dcf 100644 --- a/trove_dashboard/content/ng_database_backups/__init__.py +++ b/trove_dashboard/content/ng_database_backups/__init__.py @@ -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 diff --git a/trove_dashboard/content/ng_database_backups/templates/ng_database_backups/index.html b/trove_dashboard/content/ng_database_backups/templates/ng_database_backups/index.html index b8c3ceb..a6f0f97 100644 --- a/trove_dashboard/content/ng_database_backups/templates/ng_database_backups/index.html +++ b/trove_dashboard/content/ng_database_backups/templates/ng_database_backups/index.html @@ -3,8 +3,9 @@ {% block title %}{% trans "Backups" %}{% endblock %} {% block page_header %} - + {% endblock page_header %} {% block main %} + {% endblock %} diff --git a/trove_dashboard/content/ng_database_backups/urls.py b/trove_dashboard/content/ng_database_backups/urls.py index 290154e..f7d9180 100644 --- a/trove_dashboard/content/ng_database_backups/urls.py +++ b/trove_dashboard/content/ng_database_backups/urls.py @@ -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'), +] diff --git a/trove_dashboard/enabled/_1731_project_database_backups_panel.py b/trove_dashboard/enabled/_1731_project_database_backups_panel.py index 6e1c295..bc82107 100644 --- a/trove_dashboard/enabled/_1731_project_database_backups_panel.py +++ b/trove_dashboard/enabled/_1731_project_database_backups_panel.py @@ -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' +] diff --git a/trove_dashboard/static/app/core/openstack-service-api/trove.service.js b/trove_dashboard/static/app/core/openstack-service-api/trove.service.js new file mode 100644 index 0000000..7206a97 --- /dev/null +++ b/trove_dashboard/static/app/core/openstack-service-api/trove.service.js @@ -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.')); + }); + } + } + +}()); diff --git a/trove_dashboard/static/dashboard/project/ngbackups/table/table.config.js b/trove_dashboard/static/dashboard/project/ngbackups/table/table.config.js new file mode 100644 index 0000000..3e3cc5b --- /dev/null +++ b/trove_dashboard/static/dashboard/project/ngbackups/table/table.config.js @@ -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; + } +})(); \ No newline at end of file diff --git a/trove_dashboard/static/dashboard/project/ngbackups/table/table.controller.js b/trove_dashboard/static/dashboard/project/ngbackups/table/table.controller.js new file mode 100644 index 0000000..9b60f37 --- /dev/null +++ b/trove_dashboard/static/dashboard/project/ngbackups/table/table.controller.js @@ -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; + } + } + +})(); diff --git a/trove_dashboard/static/dashboard/project/ngbackups/table/table.controller.spec.js b/trove_dashboard/static/dashboard/project/ngbackups/table/table.controller.spec.js new file mode 100644 index 0000000..e69de29 diff --git a/trove_dashboard/static/dashboard/project/ngbackups/table/table.html b/trove_dashboard/static/dashboard/project/ngbackups/table/table.html new file mode 100644 index 0000000..11ca25f --- /dev/null +++ b/trove_dashboard/static/dashboard/project/ngbackups/table/table.html @@ -0,0 +1,7 @@ +
+ + +
\ No newline at end of file