Added custom_icons attribute to autogenerated TOSCA for dashboards

Change-Id: I277eebc1913f71eeef798cee661d5fbe4d9fd544
diff --git a/views/ngXosViews/openVPNDashboard/gulp/build.js b/views/ngXosViews/openVPNDashboard/gulp/build.js
index 26fc1fe..ec430e6 100644
--- a/views/ngXosViews/openVPNDashboard/gulp/build.js
+++ b/views/ngXosViews/openVPNDashboard/gulp/build.js
@@ -26,6 +26,9 @@
 var autoprefixer = require('autoprefixer');
 var mqpacker = require('css-mqpacker');
 var csswring = require('csswring');
+var yaml = require('js-yaml');
+var colors = require('colors/safe');
+var fs =  require('fs');
 
 const TEMPLATE_FOOTER = `
 angular.module('xos.openVPNDashboard')
@@ -74,7 +77,7 @@
 
   // copy images in correct folder
   gulp.task('copyImages', ['wait'], function(){
-    return gulp.src([`${options.icon}/openVPNDashboard-icon.png`,`${options.icon}/openVPNDashboard-icon-active.png`])
+    return gulp.src([`${options.icon}/openVPNDashboard-icon.png`, `${options.icon}/openVPNDashboard-icon-active.png`])
     .pipe(gulp.dest(options.static + 'images/'))
   });
 
@@ -155,6 +158,56 @@
     }, 1000);
   });
 
+  gulp.task('tosca', function (cb) {
+
+    // TOSCA to register the dashboard in the system
+    const dashboardJson = {};
+    dashboardJson['OpenVPNDashboard'] = {
+      type: 'tosca.nodes.DashboardView',
+      properties: {
+        url: 'template:xosOpenVPNDashboard'
+      }
+    };
+
+    // check for custom icons
+    if(
+      fs.existsSync(`${options.icon}/openVPNDashboard-icon.png`) &&
+      fs.existsSync(`${options.icon}/openVPNDashboard-icon-active.png`)
+    ){
+      dashboardJson['OpenVPNDashboard'].properties.custom_icon = true;
+    }
+
+    const dashboardTosca = yaml.dump(dashboardJson).replace(/'/gmi, '');
+
+    // TOSCA to add the dashboard to the user
+    const userDashboardJson = {};
+    userDashboardJson['openVPNDashboard_dashboard'] = {
+      node: 'OpenVPNDashboard',
+      relationship: 'tosca.relationships.UsesDashboard'
+    };
+    const userJson = {
+      'padmin@vicci.org': {
+        type: 'tosca.nodes.User',
+        properties: {
+          'no-create': true,
+          'no-delete': true
+        },
+        requirements: [userDashboardJson]
+      }
+    };
+    const userTosca = yaml.dump(userJson).replace(/'/gmi, '');
+
+
+    // the output is in a timeout so that it get printed after the gulp logs
+    setTimeout(function () {
+      console.log(colors.cyan('\n\n# You can use this recipe to load the dashboard in the system:'));
+      console.log(colors.yellow(dashboardTosca));
+      console.log(colors.cyan('# And this recipe to activate the dashboard for a user:'));
+      console.log(colors.yellow(userTosca));
+    }, 1000);
+    cb();
+  });
+
   gulp.task('build', function() {
     runSequence(
       'clean',
@@ -167,7 +220,8 @@
       'copyCss',
       'copyImages',
       'copyHtml',
-      'cleanTmp'
+      'cleanTmp',
+      'tosca'
     );
   });
 };
\ No newline at end of file
diff --git a/views/ngXosViews/openVPNDashboard/package.json b/views/ngXosViews/openVPNDashboard/package.json
index 09631e4..4dacdcb 100644
--- a/views/ngXosViews/openVPNDashboard/package.json
+++ b/views/ngXosViews/openVPNDashboard/package.json
@@ -5,6 +5,7 @@
   "scripts": {
     "prestart": "npm install && bower install",
     "start": "gulp serve",
+    "tosca": "gulp tosca",
     "prebuild": "npm install && bower install",
     "build": "gulp",
     "test": "karma start",
@@ -16,12 +17,13 @@
     "Angular",
     "XOSlib"
   ],
-  "author": "Jeremy Mowery",
+  "author": "Matteo Scandolo",
   "license": "Apache-2.0",
   "dependencies": {},
   "devDependencies": {
     "autoprefixer": "^6.3.3",
     "browser-sync": "^2.9.11",
+    "colors": "^1.1.2",
     "css-mqpacker": "^4.0.0",
     "csswring": "^4.2.1",
     "del": "^2.0.2",
@@ -46,6 +48,7 @@
     "http-proxy": "^1.12.0",
     "ink-docstrap": "^0.5.2",
     "jasmine-core": "~2.3.4",
+    "js-yaml": "^3.6.1",
     "karma": "^0.13.14",
     "karma-babel-preprocessor": "~5.2.2",
     "karma-coverage": "^0.5.3",