[Cherrypick] Dashboard Manager View
- added ng-drag-drop
- deleted old customize dashboard
- managing dashboards
Change-Id: I41c54ab7c6582f565cef363c9d93d22cda011292
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/Dashboards.js b/views/ngXosLib/xosHelpers/src/services/rest/Dashboards.js
new file mode 100644
index 0000000..42af90b
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/Dashboards.js
@@ -0,0 +1,31 @@
+(function() {
+ 'use strict';
+
+ angular.module('xos.helpers')
+ /**
+ * @ngdoc service
+ * @name xos.helpers.Dashboards
+ * @description Angular resource to fetch /api/core/dashboardviews/:id/
+ **/
+ .service('Dashboards', function($resource, $q, $http){
+ const r = $resource('/api/core/dashboardviews/:id/', { id: '@id' }, {
+ update: { method: 'PUT' }
+ });
+
+ r.prototype.$save = function(){
+ const d = $q.defer();
+
+ $http.put(`/api/core/dashboardviews/${this.id}/`, this)
+ .then((res) => {
+ d.resolve(res.data);
+ })
+ .catch(e => {
+ d.reject(e.data);
+ });
+
+ return d.promise;
+ }
+
+ return r;
+ })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form/form.scss b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form/form.scss
index b61f8e2..20a60ae 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form/form.scss
+++ b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form/form.scss
@@ -5,4 +5,8 @@
button {
margin-bottom: $form-group-margin-bottom;
}
+
+ button + button {
+ margin-left: $form-group-margin-bottom;
+ }
}
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/.bowerrc b/views/ngXosViews/dashboardManager/.bowerrc
new file mode 100644
index 0000000..e491038
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/.bowerrc
@@ -0,0 +1,3 @@
+{
+ "directory": "src/vendor/"
+}
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/.eslintrc b/views/ngXosViews/dashboardManager/.eslintrc
new file mode 100644
index 0000000..c852748
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/.eslintrc
@@ -0,0 +1,42 @@
+{
+ "ecmaFeatures": {
+ "blockBindings": true,
+ "forOf": true,
+ "destructuring": true,
+ "arrowFunctions": true,
+ "templateStrings": true
+ },
+ "env": {
+ "browser": true,
+ "node": true,
+ "es6": true
+ },
+ "plugins": [
+ //"angular"
+ ],
+ "rules": {
+ "quotes": [2, "single"],
+ "camelcase": [1, {"properties": "always"}],
+ "no-underscore-dangle": 1,
+ "eqeqeq": [2, "smart"],
+ "no-alert": 1,
+ "key-spacing": [1, { "beforeColon": false, "afterColon": true }],
+ "indent": [2, 2],
+ "no-irregular-whitespace": 1,
+ "eol-last": 0,
+ "max-nested-callbacks": [2, 4],
+ "comma-spacing": [1, {"before": false, "after": true}],
+ "no-trailing-spaces": [1, { skipBlankLines: true }],
+ "no-unused-vars": [1, {"vars": "all", "args": "after-used"}],
+ "new-cap": 0,
+
+ //"angular/ng_module_name": [2, '/^xos\.*[a-z]*$/'],
+ //"angular/ng_controller_name": [2, '/^[a-z].*Ctrl$/'],
+ //"angular/ng_service_name": [2, '/^[A-Z].*Service$/'],
+ //"angular/ng_directive_name": [2, '/^[a-z]+[[A-Z].*]*$/'],
+ //"angular/ng_di": [0, "function or array"]
+ },
+ "globals" :{
+ "angular": true
+ }
+}
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/.gitignore b/views/ngXosViews/dashboardManager/.gitignore
new file mode 100644
index 0000000..567aee4
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/.gitignore
@@ -0,0 +1,6 @@
+dist/
+src/vendor
+.tmp
+node_modules
+npm-debug.log
+dist/
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/bower.json b/views/ngXosViews/dashboardManager/bower.json
new file mode 100644
index 0000000..5c05525
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/bower.json
@@ -0,0 +1,35 @@
+{
+ "name": "xos-dashboardManager",
+ "version": "0.0.0",
+ "authors": [
+ "Matteo Scandolo <matteo.scandolo@gmail.com>"
+ ],
+ "description": "The dashboardManager view",
+ "license": "MIT",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "bower_components",
+ "static/js/vendor/",
+ "test",
+ "tests"
+ ],
+ "dependencies": {
+ "angular-drag-and-drop-lists": "~1.4.0",
+ "js-yaml": "~3.6.1"
+ },
+ "devDependencies": {
+ "jquery": "2.1.4",
+ "angular-mocks": "1.4.7",
+ "angular": "1.4.7",
+ "angular-ui-router": "0.2.15",
+ "angular-cookies": "1.4.7",
+ "angular-animate": "1.4.7",
+ "angular-resource": "1.4.7",
+ "lodash": "~4.11.1",
+ "bootstrap-css": "3.3.6",
+ "angular-chart.js": "~0.10.2",
+ "d3": "~3.5.17",
+ "angular-recursion": "~1.0.5"
+ }
+}
diff --git a/views/ngXosViews/dashboardManager/gulp/build.js b/views/ngXosViews/dashboardManager/gulp/build.js
new file mode 100644
index 0000000..96b7cd2
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/gulp/build.js
@@ -0,0 +1,164 @@
+'use strict';
+
+// BUILD
+//
+// The only purpose of this gulpfile is to build a XOS view and copy the correct files into
+// .html => dashboards
+// .js (minified and concat) => static/js
+//
+// The template are parsed and added to js with angular $templateCache
+
+var gulp = require('gulp');
+var ngAnnotate = require('gulp-ng-annotate');
+var uglify = require('gulp-uglify');
+var templateCache = require('gulp-angular-templatecache');
+var runSequence = require('run-sequence');
+var concat = require('gulp-concat-util');
+var del = require('del');
+var wiredep = require('wiredep');
+var angularFilesort = require('gulp-angular-filesort');
+var _ = require('lodash');
+var eslint = require('gulp-eslint');
+var inject = require('gulp-inject');
+var rename = require('gulp-rename');
+var replace = require('gulp-replace');
+var postcss = require('gulp-postcss');
+var autoprefixer = require('autoprefixer');
+var mqpacker = require('css-mqpacker');
+var csswring = require('csswring');
+
+const TEMPLATE_FOOTER = `
+angular.module('xos.dashboardManager')
+.run(['$location', function(a){
+ a.path('/');
+}])
+`
+
+module.exports = function(options){
+
+ // delete previous builded file
+ gulp.task('clean', function(){
+ return del(
+ [
+ options.dashboards + 'xosDashboardManager.html',
+ options.static + 'css/xosDashboardManager.css'
+ ],
+ {force: true}
+ );
+ });
+
+ // minify css
+ gulp.task('css', function () {
+ var processors = [
+ autoprefixer({browsers: ['last 1 version']}),
+ mqpacker,
+ csswring
+ ];
+
+ gulp.src([
+ `${options.css}**/*.css`,
+ `!${options.css}dev.css`
+ ])
+ .pipe(postcss(processors))
+ .pipe(gulp.dest(options.tmp + '/css/'));
+ });
+
+ // copy css in correct folder
+ gulp.task('copyCss', ['wait'], function(){
+ return gulp.src([`${options.tmp}/css/*.css`])
+ .pipe(concat('xosDashboardManager.css'))
+ .pipe(gulp.dest(options.static + 'css/'))
+ });
+
+ // compile and minify scripts
+ gulp.task('scripts', function() {
+ return gulp.src([
+ options.tmp + '**/*.js'
+ ])
+ .pipe(ngAnnotate())
+ .pipe(angularFilesort())
+ .pipe(concat('xosDashboardManager.js'))
+ .pipe(concat.header('//Autogenerated, do not edit!!!\n'))
+ .pipe(concat.footer(TEMPLATE_FOOTER))
+ .pipe(uglify())
+ .pipe(gulp.dest(options.static + 'js/'));
+ });
+
+ // set templates in cache
+ gulp.task('templates', function(){
+ return gulp.src('./src/templates/*.html')
+ .pipe(templateCache({
+ module: 'xos.dashboardManager',
+ root: 'templates/'
+ }))
+ .pipe(gulp.dest(options.tmp));
+ });
+
+ // copy html index to Django Folder
+ gulp.task('copyHtml', function(){
+ return gulp.src(options.src + 'index.html')
+ // remove dev dependencies from html
+ .pipe(replace(/<!-- bower:css -->(\n^<link.*)*\n<!-- endbower -->/gmi, ''))
+ .pipe(replace(/<!-- bower:js -->(\n^<script.*)*\n<!-- endbower -->/gmi, ''))
+ // injecting minified files
+ .pipe(
+ inject(
+ gulp.src([
+ options.static + 'js/vendor/xosDashboardManagerVendor.js',
+ options.static + 'js/xosDashboardManager.js',
+ options.static + 'css/xosDashboardManager.css'
+ ]),
+ {ignorePath: '/../../../xos/core/xoslib'}
+ )
+ )
+ .pipe(rename('xosDashboardManager.html'))
+ .pipe(gulp.dest(options.dashboards));
+ });
+
+ // minify vendor js files
+ gulp.task('wiredep', function(){
+ var bowerDeps = wiredep().js;
+ if(!bowerDeps){
+ return;
+ }
+
+ // remove angular (it's already loaded)
+ _.remove(bowerDeps, function(dep){
+ return dep.indexOf('angular/angular.js') !== -1;
+ });
+
+ return gulp.src(bowerDeps)
+ .pipe(concat('xosDashboardManagerVendor.js'))
+ .pipe(uglify())
+ .pipe(gulp.dest(options.static + 'js/vendor/'));
+ });
+
+ gulp.task('lint', function () {
+ return gulp.src(['src/js/**/*.js'])
+ .pipe(eslint())
+ .pipe(eslint.format())
+ .pipe(eslint.failAfterError());
+ });
+
+ gulp.task('wait', function (cb) {
+ // setTimeout could be any async task
+ setTimeout(function () {
+ cb();
+ }, 1000);
+ });
+
+ gulp.task('build', function() {
+ runSequence(
+ 'clean',
+ 'sass',
+ 'templates',
+ 'babel',
+ 'scripts',
+ 'wiredep',
+ 'css',
+ 'copyCss',
+ 'copyHtml',
+ 'cleanTmp'
+ );
+ });
+};
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/gulp/server.js b/views/ngXosViews/dashboardManager/gulp/server.js
new file mode 100644
index 0000000..1e40a34
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/gulp/server.js
@@ -0,0 +1,170 @@
+'use strict';
+
+var gulp = require('gulp');
+var browserSync = require('browser-sync').create();
+var inject = require('gulp-inject');
+var runSequence = require('run-sequence');
+var angularFilesort = require('gulp-angular-filesort');
+var babel = require('gulp-babel');
+var wiredep = require('wiredep').stream;
+var httpProxy = require('http-proxy');
+var del = require('del');
+var sass = require('gulp-sass');
+var fs = require('fs');
+var path = require('path');
+
+const environment = process.env.NODE_ENV;
+
+if(!fs.existsSync(path.join(__dirname, `../../../env/${environment || 'default'}.js`))){
+ if(!environment){
+ throw new Error('You should define a default.js config in /views/env folder.');
+ }
+ else{
+ throw new Error(`Since you are loading a custom environment, you should define a ${environment}.js config in /views/env folder.`);
+ }
+}
+
+var conf = require(path.join(__dirname, `../../../env/${environment || 'default'}.js`));
+
+var proxy = httpProxy.createProxyServer({
+ target: conf.host
+});
+
+
+proxy.on('error', function(error, req, res) {
+ res.writeHead(500, {
+ 'Content-Type': 'text/plain'
+ });
+
+ console.error('[Proxy]', error);
+});
+
+module.exports = function(options){
+
+ gulp.task('browser', function() {
+ browserSync.init({
+ startPath: '#/',
+ snippetOptions: {
+ rule: {
+ match: /<!-- browserSync -->/i
+ }
+ },
+ server: {
+ baseDir: options.src,
+ routes: {
+ '/xos/core/xoslib/static/js/vendor': options.helpers,
+ '/xos/core/static': options.static + '../../static/'
+ },
+ middleware: function(req, res, next){
+ if(
+ req.url.indexOf('/api/') !== -1
+ ){
+ if(conf.xoscsrftoken && conf.xossessionid){
+ req.headers.cookie = `xoscsrftoken=${conf.xoscsrftoken}; xossessionid=${conf.xossessionid}`;
+ req.headers['x-csrftoken'] = conf.xoscsrftoken;
+ }
+ proxy.web(req, res);
+ }
+ else{
+ next();
+ }
+ }
+ }
+ });
+
+ gulp.watch(options.src + 'js/**/*.js', ['js-watch']);
+ gulp.watch(options.src + 'vendor/**/*.js', ['bower'], function(){
+ browserSync.reload();
+ });
+ gulp.watch(options.src + '**/*.html', function(){
+ browserSync.reload();
+ });
+ gulp.watch(options.css + '**/*.css', function(){
+ browserSync.reload();
+ });
+ gulp.watch(`${options.sass}/**/*.scss`, ['sass'], function(){
+ browserSync.reload();
+ });
+
+ gulp.watch([
+ options.helpers + 'ngXosHelpers.js',
+ options.static + '../../static/xosNgLib.css'
+ ], function(){
+ browserSync.reload();
+ });
+ });
+
+ // compile sass
+ gulp.task('sass', function () {
+ return gulp.src(`${options.sass}/**/*.scss`)
+ .pipe(sass().on('error', sass.logError))
+ .pipe(gulp.dest(options.css));
+ });
+
+ // transpile js with sourceMaps
+ gulp.task('babel', function(){
+ return gulp.src(options.scripts + '**/*.js')
+ .pipe(babel({sourceMaps: true}))
+ .pipe(gulp.dest(options.tmp));
+ });
+
+ // inject scripts
+ gulp.task('injectScript', ['cleanTmp', 'babel'], function(){
+ return gulp.src(options.src + 'index.html')
+ .pipe(
+ inject(
+ gulp.src([
+ options.tmp + '**/*.js',
+ options.helpers + 'ngXosHelpers.js'
+ ])
+ .pipe(angularFilesort()),
+ {
+ ignorePath: [options.src, '/../../ngXosLib']
+ }
+ )
+ )
+ .pipe(gulp.dest(options.src));
+ });
+
+ // inject CSS
+ gulp.task('injectCss', function(){
+ return gulp.src(options.src + 'index.html')
+ .pipe(
+ inject(
+ gulp.src([
+ options.src + 'css/*.css',
+ options.static + '../../static/xosNgLib.css'
+ ]),
+ {
+ ignorePath: [options.src]
+ }
+ )
+ )
+ .pipe(gulp.dest(options.src));
+ });
+
+ // inject bower dependencies with wiredep
+ gulp.task('bower', function () {
+ return gulp.src(options.src + 'index.html')
+ .pipe(wiredep({devDependencies: true}))
+ .pipe(gulp.dest(options.src));
+ });
+
+ gulp.task('js-watch', ['injectScript'], function(){
+ browserSync.reload();
+ });
+
+ gulp.task('cleanTmp', function(){
+ return del([options.tmp + '**/*']);
+ });
+
+ gulp.task('serve', function() {
+ runSequence(
+ 'sass',
+ 'bower',
+ 'injectScript',
+ 'injectCss',
+ ['browser']
+ );
+ });
+};
diff --git a/views/ngXosViews/dashboardManager/gulpfile.js b/views/ngXosViews/dashboardManager/gulpfile.js
new file mode 100644
index 0000000..08df554
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/gulpfile.js
@@ -0,0 +1,26 @@
+'use strict';
+
+var gulp = require('gulp');
+var wrench = require('wrench');
+
+var options = {
+ src: 'src/',
+ css: 'src/css/',
+ sass: 'src/sass/',
+ scripts: 'src/js/',
+ tmp: 'src/.tmp',
+ dist: 'dist/',
+ api: '../../ngXosLib/api/',
+ helpers: '../../../xos/core/xoslib/static/js/vendor/',
+ static: '../../../xos/core/xoslib/static/', // this is the django static folder
+ dashboards: '../../../xos/core/xoslib/dashboards/' // this is the django html folder
+};
+
+wrench.readdirSyncRecursive('./gulp')
+.map(function(file) {
+ require('./gulp/' + file)(options);
+});
+
+gulp.task('default', function () {
+ gulp.start('build');
+});
diff --git a/views/ngXosViews/dashboardManager/karma.conf.js b/views/ngXosViews/dashboardManager/karma.conf.js
new file mode 100644
index 0000000..5d00727
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/karma.conf.js
@@ -0,0 +1,99 @@
+'use strict';
+// Karma configuration
+// Generated on Tue Oct 06 2015 09:27:10 GMT+0000 (UTC)
+
+/* eslint indent: [2,2], quotes: [2, "single"]*/
+
+/*eslint-disable*/
+var wiredep = require('wiredep');
+var path = require('path');
+
+var bowerComponents = wiredep( {devDependencies: true} )[ 'js' ].map(function( file ){
+ return path.relative(process.cwd(), file);
+});
+
+// dirt trick to load angular as first
+var ngIndex = bowerComponents.findIndex((item) => {
+ return item === 'src/vendor/angular/angular.js';
+});
+
+bowerComponents.splice(ngIndex, 1);
+bowerComponents.unshift('src/vendor/angular/angular.js');
+// end dirty trick to load angular as first
+
+module.exports = function(config) {
+/*eslint-enable*/
+ config.set({
+
+ // base path that will be used to resolve all patterns (eg. files, exclude)
+ basePath: '',
+
+
+ // frameworks to use
+ // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
+ frameworks: ['jasmine'],
+
+
+ // list of files / patterns to load in the browser
+ files: bowerComponents.concat([
+ '../../../xos/core/xoslib/static/js/vendor/ngXosVendor.js',
+ '../../../xos/core/xoslib/static/js/vendor/ngXosHelpers.js',
+ 'src/js/main.js',
+ 'src/js/**/*.js',
+ 'spec/**/*.mock.js',
+ 'spec/**/*.test.js',
+ 'src/**/*.html'
+ ]),
+
+
+ // list of files to exclude
+ exclude: [
+ ],
+
+
+ // preprocess matching files before serving them to the browser
+ // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
+ preprocessors: {
+ 'src/js/**/*.js': ['babel'],
+ 'spec/**/*.test.js': ['babel'],
+ 'src/**/*.html': ['ng-html2js']
+ },
+
+ ngHtml2JsPreprocessor: {
+ stripPrefix: 'src/', //strip the src path from template url (http://stackoverflow.com/questions/22869668/karma-unexpected-request-when-testing-angular-directive-even-with-ng-html2js)
+ moduleName: 'templates' // define the template module name
+ },
+
+ // test results reporter to use
+ // possible values: 'dots', 'progress'
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
+ reporters: ['mocha'],
+
+
+ // web server port
+ port: 9876,
+
+
+ // enable / disable colors in the output (reporters and logs)
+ colors: true,
+
+
+ // level of logging
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
+ logLevel: config.LOG_INFO,
+
+
+ // enable / disable watching file and executing tests whenever any file changes
+ autoWatch: true,
+
+
+ // start these browsers
+ // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
+ browsers: ['PhantomJS'],
+
+
+ // Continuous Integration mode
+ // if true, Karma captures browsers, runs the tests and exits
+ singleRun: false
+ });
+};
diff --git a/views/ngXosViews/dashboardManager/package.json b/views/ngXosViews/dashboardManager/package.json
new file mode 100644
index 0000000..5f562df
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/package.json
@@ -0,0 +1,63 @@
+{
+ "name": "xos-dashboardManager",
+ "version": "1.0.0",
+ "description": "Angular Application for XOS, created with generator-xos",
+ "scripts": {
+ "prestart": "npm install && bower install",
+ "start": "gulp serve",
+ "prebuild": "npm install && bower install",
+ "build": "gulp",
+ "test": "karma start",
+ "test:ci": "karma start --single-run",
+ "lint": "eslint src/js/"
+ },
+ "keywords": [
+ "XOS",
+ "Angular",
+ "XOSlib"
+ ],
+ "author": "Matteo Scandolo",
+ "license": "MIT",
+ "dependencies": {},
+ "devDependencies": {
+ "autoprefixer": "^6.3.3",
+ "browser-sync": "^2.9.11",
+ "css-mqpacker": "^4.0.0",
+ "csswring": "^4.2.1",
+ "del": "^2.0.2",
+ "easy-mocker": "^1.2.0",
+ "eslint": "^1.8.0",
+ "eslint-plugin-angular": "linkmesrl/eslint-plugin-angular",
+ "gulp": "^3.9.0",
+ "gulp-angular-filesort": "^1.1.1",
+ "gulp-angular-templatecache": "^1.8.0",
+ "gulp-babel": "^5.3.0",
+ "gulp-concat": "^2.6.0",
+ "gulp-concat-util": "^0.5.5",
+ "gulp-eslint": "^1.0.0",
+ "gulp-inject": "^3.0.0",
+ "gulp-minify-html": "^1.0.4",
+ "gulp-ng-annotate": "^1.1.0",
+ "gulp-postcss": "^6.0.1",
+ "gulp-rename": "^1.2.2",
+ "gulp-replace": "^0.5.4",
+ "gulp-sass": "^2.2.0",
+ "gulp-uglify": "^1.4.2",
+ "http-proxy": "^1.12.0",
+ "ink-docstrap": "^0.5.2",
+ "jasmine-core": "~2.3.4",
+ "karma": "^0.13.14",
+ "karma-babel-preprocessor": "~5.2.2",
+ "karma-coverage": "^0.5.3",
+ "karma-jasmine": "~0.3.6",
+ "karma-mocha-reporter": "~1.1.1",
+ "karma-ng-html2js-preprocessor": "^0.2.0",
+ "karma-phantomjs-launcher": "~0.2.1",
+ "lodash": "^3.10.1",
+ "phantomjs": "^1.9.19",
+ "proxy-middleware": "^0.15.0",
+ "run-sequence": "^1.1.4",
+ "wiredep": "^3.0.0-beta",
+ "wrench": "^1.5.8"
+ }
+}
diff --git a/views/ngXosViews/dashboardManager/spec/sample.test.js b/views/ngXosViews/dashboardManager/spec/sample.test.js
new file mode 100644
index 0000000..d71f63e
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/spec/sample.test.js
@@ -0,0 +1,39 @@
+'use strict';
+
+// TODO angular-drag-drop is inject in the wrong place, test failing
+
+describe('The User List', () => {
+
+ var scope, element, isolatedScope, httpBackend;
+
+ beforeEach(module('xos.dashboardManager'));
+ beforeEach(module('templates'));
+
+ beforeEach(inject(function($httpBackend, $compile, $rootScope){
+
+ httpBackend = $httpBackend;
+ // Setting up mock request
+ $httpBackend.expectGET('/api/core/users/?no_hyperlinks=1').respond([
+ {
+ email: 'matteo.scandolo@gmail.com',
+ firstname: 'Matteo',
+ lastname: 'Scandolo'
+ }
+ ]);
+
+ scope = $rootScope.$new();
+ element = angular.element('<users-list></users-list>');
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ xit('should load 1 users', () => {
+ httpBackend.flush();
+ expect(isolatedScope.users.length).toBe(1);
+ expect(isolatedScope.users[0].email).toEqual('matteo.scandolo@gmail.com');
+ expect(isolatedScope.users[0].firstname).toEqual('Matteo');
+ expect(isolatedScope.users[0].lastname).toEqual('Scandolo');
+ });
+
+});
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/src/css/main.css b/views/ngXosViews/dashboardManager/src/css/main.css
new file mode 100644
index 0000000..01c272a
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/src/css/main.css
@@ -0,0 +1,23 @@
+#xosDashboardManager {
+ /* DRAG AND DROP STYLING */ }
+ #xosDashboardManager .col-xs-10 + .col-xs-2.text-right {
+ padding-top: 20px; }
+ #xosDashboardManager ul[dnd-list] {
+ min-height: 42px;
+ border: 1px dashed #337ab7;
+ padding: 20px;
+ margin-bottom: 0; }
+ #xosDashboardManager ul[dnd-list] li {
+ list-style: none; }
+ #xosDashboardManager ul[dnd-list] li:not(:last-child) {
+ margin-bottom: 20px; }
+ #xosDashboardManager ul[dnd-list] li:hover {
+ cursor: pointer; }
+ #xosDashboardManager ul[dnd-list] li.dndDraggingSource {
+ display: none; }
+ #xosDashboardManager ul[dnd-list] > li, #xosDashboardManager .dashboard-container {
+ display: block;
+ border: 1px solid #337ab7;
+ padding: 20px; }
+ #xosDashboardManager ul[dnd-list] > li a, #xosDashboardManager .dashboard-container a {
+ float: right; }
diff --git a/views/ngXosViews/dashboardManager/src/index.html b/views/ngXosViews/dashboardManager/src/index.html
new file mode 100644
index 0000000..371caa2
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/src/index.html
@@ -0,0 +1,39 @@
+<!-- browserSync -->
+<!-- bower:css -->
+<link rel="stylesheet" href="vendor/bootstrap-css/css/bootstrap.min.css" />
+<link rel="stylesheet" href="vendor/angular-chart.js/dist/angular-chart.css" />
+<!-- endbower -->
+<!-- endcss -->
+<!-- inject:css -->
+<link rel="stylesheet" href="/css/main.css">
+<link rel="stylesheet" href="/../../../xos/core/static/xosNgLib.css">
+<!-- endinject -->
+
+<div ng-app="xos.dashboardManager" id="xosDashboardManager" class="container-fluid">
+ <div ui-view></div>
+</div>
+
+<!-- bower:js -->
+<script src="vendor/jquery/dist/jquery.js"></script>
+<script src="vendor/angular/angular.js"></script>
+<script src="vendor/angular-drag-and-drop-lists/angular-drag-and-drop-lists.js"></script>
+<script src="vendor/js-yaml/dist/js-yaml.js"></script>
+<script src="vendor/angular-mocks/angular-mocks.js"></script>
+<script src="vendor/angular-ui-router/release/angular-ui-router.js"></script>
+<script src="vendor/angular-cookies/angular-cookies.js"></script>
+<script src="vendor/angular-animate/angular-animate.js"></script>
+<script src="vendor/angular-resource/angular-resource.js"></script>
+<script src="vendor/lodash/lodash.js"></script>
+<script src="vendor/bootstrap-css/js/bootstrap.min.js"></script>
+<script src="vendor/Chart.js/Chart.js"></script>
+<script src="vendor/angular-chart.js/dist/angular-chart.js"></script>
+<script src="vendor/d3/d3.js"></script>
+<script src="vendor/angular-recursion/angular-recursion.js"></script>
+<!-- endbower -->
+<!-- endjs -->
+<!-- inject:js -->
+<script src="/../../../xos/core/xoslib/static/js/vendor/ngXosHelpers.js"></script>
+<script src="/.tmp/main.js"></script>
+<script src="/.tmp/user-dashboards.directive.js"></script>
+<script src="/.tmp/dashboard-form.directive.js"></script>
+<!-- endinject -->
\ No newline at end of file
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
diff --git a/views/ngXosViews/dashboardManager/src/js/main.js b/views/ngXosViews/dashboardManager/src/js/main.js
new file mode 100644
index 0000000..025e95d
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/src/js/main.js
@@ -0,0 +1,55 @@
+'use strict';
+
+angular.module('xos.dashboardManager', [
+ 'ngResource',
+ 'ngCookies',
+ 'ui.router',
+ 'xos.helpers',
+ 'dndLists'
+])
+.config(($stateProvider) => {
+ $stateProvider
+ .state('manage-user-dashboards', {
+ url: '/',
+ template: '<user-dashboards></user-dashboards>'
+ })
+ .state('add-dashboards', {
+ url: '/add',
+ template: '<dashboard-form></dashboard-form>'
+ })
+ .state('edit-dashboards', {
+ url: '/dashboards/:id',
+ template: '<dashboard-form></dashboard-form>'
+ });
+})
+.config(function($httpProvider){
+ $httpProvider.interceptors.push('NoHyperlinks');
+})
+.service('UserDashboards', function($http, $q){
+ this.query = () => {
+ const d = $q.defer();
+
+ $http.get('/api/utility/dashboards')
+ .then(res => {
+ d.resolve(res.data);
+ })
+ .catch(err => {
+ d.reject(err);
+ });
+
+ return {$promise: d.promise};
+ }
+
+ this.update = (dashboard) => {
+ const d = $q.defer();
+ $http.post('/api/utility/dashboards/', dashboard)
+ .then(res => {
+ d.resolve(res.data);
+ })
+ .catch(err => {
+ d.reject(err);
+ });
+
+ return {$promise: d.promise};
+ }
+});
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/src/js/user-dashboards.directive.js b/views/ngXosViews/dashboardManager/src/js/user-dashboards.directive.js
new file mode 100644
index 0000000..2912ad7
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/src/js/user-dashboards.directive.js
@@ -0,0 +1,98 @@
+(function () {
+ angular.module('xos.dashboardManager')
+ .directive('userDashboards', function(){
+ return {
+ restrict: 'E',
+ scope: {},
+ bindToController: true,
+ controllerAs: 'vm',
+ templateUrl: 'templates/user-dashboards.tpl.html',
+ controller: function($q, _, UserDashboards, Dashboards){
+
+ // retrieving user list
+ $q.all([
+ UserDashboards.query().$promise,
+ Dashboards.query({enabled: 'False'}).$promise,
+ ])
+ .then((res) => {
+ let [dashboards, disabled] = res;
+ this.disabled = disabled;
+ this.list = {
+ enabled: _.filter(dashboards, {shown: true}),
+ disabled: _.filter(dashboards, {shown: false})
+ };
+ })
+ .catch((e) => {
+ throw new Error(e);
+ });
+
+ this.removeFromList = (listName, itemId) => {
+ _.remove(this.list[listName], {id: itemId});
+ };
+
+ this.addToList = (listName, item) => {
+ this.list[listName].push(item)
+ };
+
+ this.isInList = (listName, item) => {
+ return _.find(this.list[listName], item);
+ };
+
+ this.reorderList = (list, newPos, oldPos, item) => {
+
+ let listToOrder = _.filter(list, i => {
+ // if is the item, skip it, it is already updated
+ if(i.id === item.id){
+ return false;
+ }
+ if(i.order < oldPos){
+ return true;
+ }
+ if(i.order >= newPos){
+ return true;
+ }
+ return false;
+ });
+
+ listToOrder = listToOrder.map(i => {
+ i.order++;
+ return i;
+ })
+ };
+
+ this.addedToList = (event, index, item, external, list) => {
+ let originalPosition;
+
+ // load the item in the list
+ let itemInList = this.isInList(list, item);
+ if(itemInList){
+ // if is in the list update it
+ originalPosition = item.order;
+ itemInList.order = index;
+ item.order = index;
+ }
+ else {
+ // create a new one
+ item.order = this.list[list].length;
+ item.shown = !item.shown;
+ }
+
+ const otherList = list === 'enabled' ? 'disabled' : 'enabled';
+
+ UserDashboards.update(item).$promise
+ .then((item) => {
+ if(!itemInList){
+ // if it is not in the list, update both lists
+ this.addToList(list, item);
+ this.removeFromList(otherList, item.id);
+ }
+ else {
+ // reorder
+ this.reorderList(this.list[list], index, originalPosition, item);
+ }
+ });
+ }
+ }
+ };
+ });
+})();
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/src/sass/main.scss b/views/ngXosViews/dashboardManager/src/sass/main.scss
new file mode 100644
index 0000000..a8aff76
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/src/sass/main.scss
@@ -0,0 +1,42 @@
+@import '../../../../style/sass/lib/_variables.scss';
+@import '../../../../style/sass/bootstrap/bootstrap/_variables.scss';
+
+#xosDashboardManager {
+
+ .col-xs-10 + .col-xs-2.text-right {
+ padding-top: $line-height-computed;
+ }
+
+ /* DRAG AND DROP STYLING */
+ ul[dnd-list] {
+ min-height: 42px;
+ border: 1px dashed $brand-primary;
+ padding: $line-height-computed;;
+ margin-bottom: 0;
+
+ li {
+ list-style: none;
+ }
+
+ li:not(:last-child){
+ margin-bottom: $line-height-computed;;
+ }
+
+ li:hover{
+ cursor: pointer;
+ }
+
+ li.dndDraggingSource {
+ display: none;
+ }
+ }
+
+ ul[dnd-list] > li, .dashboard-container {
+ display: block;
+ border: 1px solid $brand-primary;
+ padding: $line-height-computed;
+ a {
+ float: right;
+ }
+ }
+}
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/src/templates/dashboard-form.tpl.html b/views/ngXosViews/dashboardManager/src/templates/dashboard-form.tpl.html
new file mode 100644
index 0000000..6a584e4
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/src/templates/dashboard-form.tpl.html
@@ -0,0 +1,39 @@
+<div class="row">
+ <div class="col-xs-10">
+ <h1>Manage Dashboard</h1>
+ </div>
+ <div class="col-xs-2 text-right">
+ <a ui-sref="manage-user-dashboards" class="btn btn-success">Back</a>
+ </div>
+</div>
+<div class="row">
+ <div class="col-xs-12">
+ <xos-form ng-model="vm.dashboard" config="vm.formConfig"></xos-form>
+ </div>
+</div>
+<div class="row" ng-show="vm.tosca">
+ <div class="col-sm-6">
+ <div class="row">
+ <div class="col-xs-12">
+ <xos-alert show="true" config="{type: 'info'}">
+ Include this lines in a TOSCA recipe to load the {{vm.dashboard.name}} dashboard in the system.
+ </xos-alert>
+ </div>
+ <div class="col-xs-12">
+ <pre>{{vm.tosca}}</pre>
+ </div>
+ </div>
+ </div>
+ <div class="col-sm-6">
+ <div class="row">
+ <div class="col-xs-12">
+ <xos-alert show="true" config="{type: 'info'}">
+ Add this lines as a requirement for the user in a TOSCA recipe to assign the {{vm.dashboard.name}} to the user.
+ </xos-alert>
+ </div>
+ <div class="col-xs-12">
+ <pre>{{vm.toscaRequirements}}</pre>
+ </div>
+ </div>
+ </div>
+</div>
\ No newline at end of file
diff --git a/views/ngXosViews/dashboardManager/src/templates/user-dashboards.tpl.html b/views/ngXosViews/dashboardManager/src/templates/user-dashboards.tpl.html
new file mode 100644
index 0000000..d43f19d
--- /dev/null
+++ b/views/ngXosViews/dashboardManager/src/templates/user-dashboards.tpl.html
@@ -0,0 +1,66 @@
+<div class="row">
+ <div class="col-xs-10">
+ <h1>Manage Your Dashboards</h1>
+ </div>
+ <div class="col-xs-2 text-right">
+ <a ui-sref="add-dashboards" class="btn btn-success">Add</a>
+ </div>
+</div>
+
+<div class="row">
+ <div class="col-xs-6">
+ <div class="panel panel-primary">
+ <div class="panel-heading">
+ <h3 class="panel-title">
+ Available Dashboards
+ </h3>
+ </div>
+ <div class="panel-body">
+ <ul dnd-list="vm.list.disabled"
+ dnd-drop="vm.addedToList(event, index, item, external, 'disabled')">
+ <li ng-repeat="item in vm.list.disabled"
+ dnd-moved="vm.removeFromList('disabled', item.id)"
+ dnd-draggable="item">
+ {{item.name}}
+ <a ui-sref="edit-dashboards({id: item.id,})"><i class="glyphicon glyphicon-pencil"></i></a>
+ </li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ <div class="col-xs-6">
+ <div class="panel panel-primary">
+ <div class="panel-heading">
+ <h3 class="panel-title">
+ Enabled Dashboards
+ </h3>
+ </div>
+ <div class="panel-body">
+ <ul dnd-list="vm.list.enabled"
+ dnd-drop="vm.addedToList(event, index, item, external, 'enabled')">
+ <li ng-repeat="item in vm.list.enabled | orderBy : 'order'"
+ dnd-moved="vm.removeFromList('enabled', item.id)"
+ dnd-draggable="item">
+ {{item.name}}
+ <a ui-sref="edit-dashboards({id: item.id,})"><i class="glyphicon glyphicon-pencil"></i></a>
+ </li>
+ </ul>
+ </div>
+ </div>
+ </div>
+</div>
+<div class="row" ng-show="vm.disabled.length > 0">
+ <div class="col-xs-12">
+ <h1>Disabled Dashboard</h1>
+ </div>
+ <div class="col-xs-12">
+ <div class="row">
+ <div class="col-sm-2" ng-repeat="item in vm.disabled | orderBy : 'id'">
+ <span class="dashboard-container">
+ {{item.name}}
+ <a ui-sref="edit-dashboards({id: item.id,})"><i class="glyphicon glyphicon-pencil"></i></a>
+ </span>
+ </div>
+ </div>
+ </div>
+</div>