[Cherrypick] Dashboard Manager View
- added ng-drag-drop
- deleted old customize dashboard
- managing dashboards
Change-Id: I41c54ab7c6582f565cef363c9d93d22cda011292
diff --git a/views/ngXosViews/dashboardManager/src/js/dashboard-form.directive.js b/views/ngXosViews/dashboardManager/src/js/dashboard-form.directive.js
new file mode 100644
index 0000000..b6751b2
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/src/js/dashboard-form.directive.js
@@ -0,0 +1,130 @@
+(function () {
+ 'use strict';
+
+ angular.module('xos.dashboardManager')
+ .directive('dashboardForm', function(){
+ return {
+ restrict: 'E',
+ scope: {},
+ bindToController: true,
+ controllerAs: 'vm',
+ templateUrl: 'templates/dashboard-form.tpl.html',
+ controller: function($stateParams, $log, Dashboards){
+
+ this.dashboard = {
+ enabled: true
+ };
+
+ if($stateParams.id){
+ Dashboards.get({id: $stateParams.id}).$promise
+ .then(dash => {
+ this.dashboard = dash;
+ })
+ .catch(e => {
+ console.log(e);
+ })
+ }
+
+ this.formConfig = {
+ exclude: [
+ 'backend_register',
+ 'controllers',
+ 'deployments',
+ 'enacted',
+ 'humanReadableName',
+ 'lazy_blocked',
+ 'no_policy',
+ 'no_sync',
+ 'policed',
+ 'write_protect'
+ ],
+ actions: [
+ {
+ label: 'Save',
+ icon: 'ok',
+ cb: (item) => {
+ this.createOrUpdateDashboard(item);
+ },
+ class: 'success'
+ },
+ {
+ label: 'Esport to TOSCA',
+ icon: 'export',
+ cb: (item) => {
+ this.toTosca(item);
+ },
+ class: 'primary'
+ }
+ ],
+ formName: 'dashboardForm',
+ feedback: {
+ show: false,
+ message: 'Form submitted successfully !!!',
+ type: 'success'
+ },
+ fields: {
+ name: {
+ type: 'string',
+ validators: {
+ required: true
+ }
+ },
+ url: {
+ type: 'string',
+ validators: {
+ required: true
+ }
+ },
+ enabled: {
+ type: 'boolean'
+ }
+ }
+ };
+
+ this.createOrUpdateDashboard = dashboard => {
+ let p;
+ if(dashboard.id){
+ delete dashboard.controllers;
+ delete dashboard.deployments;
+ p = dashboard.$save();
+ }
+ else{
+ p = Dashboards.save(dashboard).$promise;
+ }
+
+ p.then(res => {
+ this.formConfig.feedback.show = true;
+ })
+ .catch(e => {
+ $log.info(e);
+ this.formConfig.feedback.show = true;
+ this.formConfig.feedback.message = e;
+ this.formConfig.feedback.type = 'error';
+ })
+ };
+
+ this.toTosca = dashboard => {
+ const yaml = {}
+ yaml[dashboard.name] = {
+ type: 'tosca.nodes.DashboardView',
+ properties: {
+ url: dashboard.url
+ }
+ };
+ this.tosca = jsyaml.dump(yaml).replace(/'/g, '');
+
+ const yamlRequirements = {
+ requirements: []
+ };
+ const dashboardRequirements = {};
+ dashboardRequirements[`${dashboard.name.toLowerCase()}_dashboard`] = {
+ node: dashboard.name,
+ relationship: 'tosca.relationships.UsesDashboard'
+ }
+ yamlRequirements.requirements.push(dashboardRequirements);
+ this.toscaRequirements = jsyaml.dump(yamlRequirements).replace(/'/g, '');
+ };
+ }
+ }
+ });
+})();
\ No newline at end of file