Fixed tests
diff --git a/views/ngXosLib/bower.json b/views/ngXosLib/bower.json
index 5677d00..08a02e3 100644
--- a/views/ngXosLib/bower.json
+++ b/views/ngXosLib/bower.json
@@ -20,7 +20,8 @@
"angular-cookies": "1.4.7",
"angular-animate": "1.4.7",
"lodash": "~4.11.1",
- "angular-chart.js": "~0.10.2"
+ "angular-chart.js": "~0.10.2",
+ "d3": "~3.5.17"
},
"devDependencies": {
"angular-mocks": "1.4.7",
diff --git a/views/ngXosLib/generator-xos/app/templates/bower.json b/views/ngXosLib/generator-xos/app/templates/bower.json
index bbddc5b..9dafc2b 100644
--- a/views/ngXosLib/generator-xos/app/templates/bower.json
+++ b/views/ngXosLib/generator-xos/app/templates/bower.json
@@ -26,6 +26,7 @@
"angular-resource": "1.4.7",
"lodash": "~4.11.1",
"bootstrap-css": "3.3.6",
- "angular-chart.js": "~0.10.2"
+ "angular-chart.js": "~0.10.2",
+ "d3": "~3.5.17"
}
}
diff --git a/views/ngXosLib/generator-xos/test/generator.spec.js b/views/ngXosLib/generator-xos/test/generator.spec.js
index f75f444..4ae1602 100644
--- a/views/ngXosLib/generator-xos/test/generator.spec.js
+++ b/views/ngXosLib/generator-xos/test/generator.spec.js
@@ -14,7 +14,12 @@
cwd: path.join(__dirname, '../../'), // pretending to be in the ngXosLib root
exclude: ['Chart.js']
});
-bowerDeps = bowerDeps.js.map(d => d.match(/bower_components\/([a-zA-Z\-`.]+)\//)[1]);
+bowerDeps = bowerDeps.js.map(d => {
+ let path = d.match(/bower_components\/([1-9a-zA-Z\-`.]+)\//);
+ if(path){
+ return path[1];
+ }
+});
// test values
const viewName = 'testDashboard';
diff --git a/views/ngXosLib/xosHelpers/spec/ui/table.test.js b/views/ngXosLib/xosHelpers/spec/ui/table.test.js
index d00d19e..9247cae 100644
--- a/views/ngXosLib/xosHelpers/spec/ui/table.test.js
+++ b/views/ngXosLib/xosHelpers/spec/ui/table.test.js
@@ -287,6 +287,52 @@
expect($(td1).text().trim()).toEqual('Formatted Content');
});
});
+
+ describe('and is icon', () => {
+
+ beforeEach(() => {
+ scope.config = {
+ columns: [
+ {
+ label: 'Label 1',
+ prop: 'label-1',
+ type: 'icon',
+ formatter: item => {
+ switch (item['label-1']){
+ case 1:
+ return 'ok';
+ case 2:
+ return 'remove';
+ case 3:
+ return 'plus'
+ }
+ }
+ }
+ ]
+ };
+ scope.data = [
+ {
+ 'label-1': 1
+ },
+ {
+ 'label-1': 2
+ },
+ {
+ 'label-1': 3
+ }
+ ];
+ compileElement();
+ });
+
+ it('should render a custom icon', () => {
+ let td1 = $(element).find('tbody tr:first-child td')[0];
+ let td2 = $(element).find('tbody tr:nth-child(2) td')[0];
+ let td3 = $(element).find('tbody tr:last-child td')[0];
+ expect($(td1).find('i')).toHaveClass('glyphicon-ok');
+ expect($(td2).find('i')).toHaveClass('glyphicon-remove');
+ expect($(td3).find('i')).toHaveClass('glyphicon-plus');
+ });
+ });
});
describe('when a link property is provided', () => {
@@ -421,6 +467,23 @@
expect(arrows.length).toEqual(4);
});
+ describe('and a default ordering is passed', () => {
+
+ beforeEach(() => {
+ scope.config.order = {
+ field: 'label-1',
+ reverse: true
+ };
+ compileElement();
+ });
+
+ it('should orderBy the default order', () => {
+ var tr = $(element).find('tr');
+ expect($(tr[1]).text()).toContain('Sample 2.2');
+ expect($(tr[2]).text()).toContain('Sample 1.1');
+ });
+ });
+
describe('and an order is set', () => {
beforeEach(() => {
isolatedScope.orderBy = 'label-1';
@@ -429,6 +492,7 @@
});
it('should orderBy', function() {
+ // console.log($(element).find('table'));
var tr = $(element).find('tr');
expect($(tr[1]).text()).toContain('Sample 2.2');
expect($(tr[2]).text()).toContain('Sample 1.1');
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/Services.js b/views/ngXosLib/xosHelpers/src/services/rest/Services.js
new file mode 100644
index 0000000..eda57e4
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/Services.js
@@ -0,0 +1,15 @@
+(function() {
+ 'use strict';
+
+ angular.module('xos.helpers')
+ /**
+ * @ngdoc service
+ * @name xos.helpers.Services
+ * @description Angular resource to fetch /api/core/services/:id/
+ **/
+ .service('Services', function($resource){
+ return $resource('/api/core/services/:id/', { id: '@id' }, {
+ update: { method: 'PUT' }
+ });
+ })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/Tenant.js b/views/ngXosLib/xosHelpers/src/services/rest/Tenant.js
new file mode 100644
index 0000000..8feb102
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/Tenant.js
@@ -0,0 +1,15 @@
+(function() {
+ 'use strict';
+
+ angular.module('xos.helpers')
+ /**
+ * @ngdoc service
+ * @name xos.helpers.Tenant
+ * @description Angular resource to fetch /api/core/tenant/:id/
+ **/
+ .service('Tenants', function($resource){
+ return $resource('/api/core/tenants/:id/', { id: '@id' }, {
+ update: { method: 'PUT' }
+ });
+ })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/service_graph.service.js b/views/ngXosLib/xosHelpers/src/services/service_graph.service.js
new file mode 100644
index 0000000..8a732a2
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/service_graph.service.js
@@ -0,0 +1,44 @@
+(function() {
+ 'use strict';
+
+ /**
+ * @ngdoc service
+ * @name xos.helpers.ServiceGraph
+ * @description This factory define a set of helper function to query the service tenancy graph
+ **/
+
+ angular
+ .module('xos.helpers')
+ .service('GraphService', function($q, Tenants, Services) {
+
+ this.loadCoarseData = () => {
+
+ let services;
+
+ let deferred = $q.defer();
+
+ Services.query().$promise
+ .then((res) => {
+ services = res;
+ return Tenants.query({kind: 'coarse'}).$promise;
+ })
+ .then((tenants) => {
+ deferred.resolve({
+ tenants: tenants,
+ services: services
+ });
+ })
+
+ return deferred.promise;
+ }
+
+ this.getCoarseGraph = () => {
+ this.loadCoarseData()
+ .then((res) => {
+ console.log(res);
+ })
+ return 'ciao';
+ };
+
+ })
+})();
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/table/table.component.js b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/table/table.component.js
index 8b49932..dfbb700 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/table/table.component.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/table/table.component.js
@@ -22,7 +22,10 @@
* columns: [
* {
* label: 'Human readable name',
- * prop: 'Property to read in the model object'
+ * prop: 'Property to read in the model object',
+ * type: 'boolean'| 'array'| 'object'| 'custom'| 'date' | 'icon' // see examples for more details
+ formatter: fn(), // receive the whole item if tipe is custom and return a string
+ link: fn() // receive the whole item and return an url
* }
* ],
* classes: 'table table-striped table-bordered',
@@ -37,7 +40,7 @@
}
],
filter: 'field', // can be by `field` or `fulltext`
- order: true // whether to show ordering arrows
+ order: true | {field: 'property name', reverse: true | false} // whether to show ordering arrows, or a configuration for a default ordering
* }
* ```
* @param {Array} data The data that should be rendered
@@ -223,6 +226,16 @@
label: 'Details',
prop: 'details',
type: 'object'
+ },
+ {
+ label: 'Created',
+ prop: 'created',
+ type: 'date'
+ },
+ {
+ label: 'Icon',
+ type: 'icon',
+ formatter: item => item.icon //note that this refer to [Bootstrap Glyphicon](http://getbootstrap.com/components/#glyphicons)
}
]
};
@@ -235,7 +248,9 @@
details: {
c_tag: '243',
s_tag: '444'
- }
+ },
+ created: new Date('December 17, 1995 03:24:00'),
+ icon: 'music'
},
{
name: 'Gili',
@@ -244,7 +259,9 @@
details: {
c_tag: '675',
s_tag: '893'
- }
+ },
+ created: new Date(),
+ icon: 'camera'
}
]
});
@@ -385,7 +402,11 @@
</dl>
</span>
<span ng-if="col.type === 'custom'">
- {{col.formatter(item[col.prop])}}
+ {{col.formatter(item)}}
+ </span>
+ <span ng-if="col.type === 'icon'">
+ <i class="glyphicon glyphicon-{{col.formatter(item)}}">
+ </i>
</span>
</td>
<td ng-if="vm.config.actions">
@@ -426,8 +447,14 @@
throw new Error('[xosTable] Please provide a columns list in the configuration');
}
- // if columns with type 'custom' are provide
- // check that a custom formatted is provided too
+ // handle default ordering
+ if(this.config.order && angular.isObject(this.config.order)){
+ this.reverse = this.config.order.reverse || false;
+ this.orderBy = this.config.order.field || 'id';
+ }
+
+ // if columns with type 'custom' are provided
+ // check that a custom formatte3 is provided too
let customCols = _.filter(this.config.columns, {type: 'custom'});
if(angular.isArray(customCols) && customCols.length > 0){
_.forEach(customCols, (col) => {
@@ -437,6 +464,17 @@
})
}
+ // if columns with type 'icon' are provided
+ // check that a custom formatte3 is provided too
+ let iconCols = _.filter(this.config.columns, {type: 'icon'});
+ if(angular.isArray(iconCols) && iconCols.length > 0){
+ _.forEach(iconCols, (col) => {
+ if(!col.formatter || !angular.isFunction(col.formatter)){
+ throw new Error('[xosTable] You have provided an icon field type, a formatter function should provided too.');
+ }
+ })
+ }
+
// if a link property is passed,
// it should be a function
let linkedColumns = _.filter(this.config.columns, col => angular.isDefined(col.link));
diff --git a/views/ngXosViews/serviceGrid/.bowerrc b/views/ngXosViews/serviceGrid/.bowerrc
new file mode 100644
index 0000000..e491038
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/.bowerrc
@@ -0,0 +1,3 @@
+{
+ "directory": "src/vendor/"
+}
\ No newline at end of file
diff --git a/views/ngXosViews/serviceGrid/.eslintrc b/views/ngXosViews/serviceGrid/.eslintrc
new file mode 100644
index 0000000..c852748
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/.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/serviceGrid/.gitignore b/views/ngXosViews/serviceGrid/.gitignore
new file mode 100644
index 0000000..567aee4
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/.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/serviceGrid/bower.json b/views/ngXosViews/serviceGrid/bower.json
new file mode 100644
index 0000000..0cac826
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/bower.json
@@ -0,0 +1,32 @@
+{
+ "name": "xos-serviceGrid",
+ "version": "0.0.0",
+ "authors": [
+ "Matteo Scandolo <teo@onlab.us>"
+ ],
+ "description": "The serviceGrid view",
+ "license": "MIT",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "bower_components",
+ "static/js/vendor/",
+ "test",
+ "tests"
+ ],
+ "dependencies": {
+ },
+ "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.13"
+ }
+}
diff --git a/views/ngXosViews/serviceGrid/env/default.js b/views/ngXosViews/serviceGrid/env/default.js
new file mode 100644
index 0000000..07017a6
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/env/default.js
@@ -0,0 +1,13 @@
+// This is a default configuration for your development environment.
+// You can duplicate this configuration for any of your Backend Environments.
+// Different configurations are loaded setting a NODE_ENV variable that contain the config file name.
+// `NODE_ENV=local npm start`
+//
+// If xoscsrftoken or xossessionid are not specified the browser value are used
+// (works only for local environment as both application are served on the same domain)
+
+module.exports = {
+ host: 'http://xos.dev:9999/',
+ xoscsrftoken: '528Q93KwEJn88ET6TZipc1gsc7qjhaTz',
+ xossessionid: '8ij3xax15jxwr3abkwohkczwrfivfbzk'
+};
diff --git a/views/ngXosViews/serviceGrid/gulp/build.js b/views/ngXosViews/serviceGrid/gulp/build.js
new file mode 100644
index 0000000..b582642
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/gulp/build.js
@@ -0,0 +1,163 @@
+'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.serviceGrid')
+.run(['$location', function(a){
+ a.path('/');
+}])
+`
+
+module.exports = function(options){
+
+ // delete previous builded file
+ gulp.task('clean', function(){
+ return del(
+ [
+ options.dashboards + 'xosServiceGrid.html',
+ options.static + 'css/xosServiceGrid.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('xosServiceGrid.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('xosServiceGrid.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.serviceGrid',
+ 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.*)*\n<!-- endbower --><!-- endcss -->/, ''))
+ .pipe(replace(/<!-- bower:js -->(\n.*)*\n<!-- endbower --><!-- endjs -->/, ''))
+ // injecting minified files
+ .pipe(
+ inject(
+ gulp.src([
+ options.static + 'js/vendor/xosServiceGridVendor.js',
+ options.static + 'js/xosServiceGrid.js',
+ options.static + 'css/xosServiceGrid.css'
+ ]),
+ {ignorePath: '/../../../xos/core/xoslib'}
+ )
+ )
+ .pipe(rename('xosServiceGrid.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('xosServiceGridVendor.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',
+ 'templates',
+ 'babel',
+ 'scripts',
+ 'wiredep',
+ 'css',
+ 'copyCss',
+ 'copyHtml',
+ 'cleanTmp'
+ );
+ });
+};
\ No newline at end of file
diff --git a/views/ngXosViews/serviceGrid/gulp/server.js b/views/ngXosViews/serviceGrid/gulp/server.js
new file mode 100644
index 0000000..c0678d9
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/gulp/server.js
@@ -0,0 +1,168 @@
+'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');
+
+const environment = process.env.NODE_ENV;
+
+if (environment){
+ var conf = require(`../env/${environment}.js`);
+}
+else{
+ var conf = require('../env/default.js')
+}
+
+var proxy = httpProxy.createProxyServer({
+ target: conf.host || 'http://0.0.0.0:9999'
+});
+
+
+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(
+ // to be removed, deprecated API
+ // req.url.indexOf('/xos/') !== -1 ||
+ // req.url.indexOf('/xoslib/') !== -1 ||
+ // req.url.indexOf('/hpcapi/') !== -1 ||
+ 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/serviceGrid/gulpfile.js b/views/ngXosViews/serviceGrid/gulpfile.js
new file mode 100644
index 0000000..08df554
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/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/serviceGrid/karma.conf.js b/views/ngXosViews/serviceGrid/karma.conf.js
new file mode 100644
index 0000000..4123be9
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/karma.conf.js
@@ -0,0 +1,88 @@
+// 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);
+});
+
+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/**/*.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/serviceGrid/package.json b/views/ngXosViews/serviceGrid/package.json
new file mode 100644
index 0000000..c33c615
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/package.json
@@ -0,0 +1,63 @@
+{
+ "name": "xos-serviceGrid",
+ "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/serviceGrid/spec/sample.test.js b/views/ngXosViews/serviceGrid/spec/sample.test.js
new file mode 100644
index 0000000..38958fd
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/spec/sample.test.js
@@ -0,0 +1,37 @@
+'use strict';
+
+describe('The User List', () => {
+
+ var scope, element, isolatedScope, httpBackend;
+
+ beforeEach(module('xos.serviceGrid'));
+ 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: 'teo@onlab.us',
+ firstname: 'Matteo',
+ lastname: 'Scandolo'
+ }
+ ]);
+
+ scope = $rootScope.$new();
+ element = angular.element('<users-list></users-list>');
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ it('should load 1 users', () => {
+ httpBackend.flush();
+ expect(isolatedScope.users.length).toBe(1);
+ expect(isolatedScope.users[0].email).toEqual('teo@onlab.us');
+ 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/serviceGrid/src/css/main.css b/views/ngXosViews/serviceGrid/src/css/main.css
new file mode 100644
index 0000000..ae13614
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/src/css/main.css
@@ -0,0 +1,15 @@
+#xosServiceGrid service-graph {
+ display: block;
+ width: 100%;
+ height: 600px; }
+
+#xosServiceGrid .node {
+ stroke: #337ab7;
+ fill: white; }
+
+#xosServiceGrid .node.xos {
+ fill: #d9534f; }
+
+#xosServiceGrid .link {
+ stroke: black;
+ stroke-width: 2px; }
diff --git a/views/ngXosViews/serviceGrid/src/index.html b/views/ngXosViews/serviceGrid/src/index.html
new file mode 100644
index 0000000..d9e7fec
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/src/index.html
@@ -0,0 +1,35 @@
+<!-- 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.serviceGrid" id="xosServiceGrid" 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-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>
+<!-- endbower -->
+<!-- endjs -->
+<!-- inject:js -->
+<script src="/../../../xos/core/xoslib/static/js/vendor/ngXosHelpers.js"></script>
+<script src="/.tmp/main.js"></script>
+<script src="/.tmp/service-graph.js"></script>
+<!-- endinject -->
\ No newline at end of file
diff --git a/views/ngXosViews/serviceGrid/src/js/main.js b/views/ngXosViews/serviceGrid/src/js/main.js
new file mode 100644
index 0000000..88a0f95
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/src/js/main.js
@@ -0,0 +1,89 @@
+'use strict';
+
+angular.module('xos.serviceGrid', [
+ 'ngResource',
+ 'ngCookies',
+ 'ui.router',
+ 'xos.helpers'
+])
+.config(($stateProvider) => {
+ $stateProvider
+ .state('serviceGrid', {
+ url: '/',
+ template: '<service-grid></service-grid>'
+ })
+ .state('serviceGraph', {
+ url: '/graph',
+ template: '<service-graph></service-graph>'
+ });
+})
+.config(function($httpProvider){
+ $httpProvider.interceptors.push('NoHyperlinks');
+})
+.directive('serviceGrid', function(){
+ return {
+ restrict: 'E',
+ scope: {},
+ bindToController: true,
+ controllerAs: 'vm',
+ templateUrl: 'templates/service-grid.tpl.html',
+ controller: function(Services, _){
+
+ this.tableConfig = {
+ columns: [
+ {
+ label: 'Status',
+ prop: 'status',
+ type: 'icon',
+ formatter: item => {
+ let status = parseInt(item.backend_status.match(/^[0-9]/)[0]);
+ switch(status){
+ case 0:
+ return 'time';
+ case 1:
+ return 'ok';
+ case 2:
+ return 'remove';
+ }
+ }
+ },
+ {
+ label: 'Name',
+ prop: 'name',
+ link: item => `${item.view_url.replace(/\$[a-z]+\$/, item.id)}`
+ },
+ {
+ label: 'Kind',
+ prop: 'kind'
+ },
+ {
+ label: 'Enabled',
+ prop: 'enabled',
+ type: 'boolean'
+ }
+ ],
+ filter: 'field',
+ order: {
+ field: 'name'
+ }
+ };
+
+ // retrieving user list
+ Services.query().$promise
+ .then((services) => {
+ this.services = _.map(services, s => {
+ // parse backend_status string in a boolean for display
+ // NOTE they are not boolean:
+ // - start with 0 = provisioning
+ // - start with 1 = good
+ // - start with 2 = error
+ s.status = parseInt(s.backend_status.match(/^[0-9]/)[0]) === 0 ? false : true;
+ return s;
+ })
+ })
+ .catch((e) => {
+ throw new Error(e);
+ });
+ }
+ };
+});
\ No newline at end of file
diff --git a/views/ngXosViews/serviceGrid/src/js/service-graph.js b/views/ngXosViews/serviceGrid/src/js/service-graph.js
new file mode 100644
index 0000000..51a711a
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/src/js/service-graph.js
@@ -0,0 +1,180 @@
+(function () {
+ 'use strict';
+
+ angular.module('xos.serviceGrid')
+ .directive('serviceGraph', function(){
+ return {
+ restrict: 'E',
+ scope: {},
+ bindToController: true,
+ controllerAs: 'vm',
+ templateUrl: 'templates/service-graph.tpl.html',
+ controller: function($element, GraphService){
+
+ let svg;
+ let el = $element[0];
+ let node;
+ let link;
+
+ const tick = (e) => {
+ // Push different nodes in different directions for clustering.
+
+ node
+ // .attr('cx', d => d.x)
+ // .attr('cy', d => d.y)
+ .attr({
+ transform: d => `translate(${d.x}, ${d.y})`
+ });
+
+ link.attr('x1', d => d.source.x)
+ .attr('y1', d => d.source.y)
+ .attr('x2', d => d.target.x)
+ .attr('y2', d => d.target.y);
+ }
+
+ GraphService.loadCoarseData()
+ .then((res) => {
+
+ // build links
+ res.tenants = res.tenants.map(t => {
+ return {
+ source: t.provider_service,
+ target: t.subscriber_service
+ }
+ });
+
+ // add xos as a node
+ res.services.push({
+ name: 'XOS',
+ class: 'xos',
+ x: el.clientWidth / 2,
+ y: el.clientHeight / 2,
+ fixed: true
+ })
+
+ handleSvg(el);
+
+ var force = d3.layout.force()
+ .nodes(res.services)
+ .links(res.tenants)
+ .charge(-1060)
+ .gravity(0.1)
+ .linkDistance(200)
+ .size([el.clientWidth, el.clientHeight])
+ .on('tick', tick)
+ .start();
+
+ link = svg.selectAll('.link')
+ .data(res.tenants).enter().insert('line')
+ .attr('class', 'link');
+
+ node = svg.selectAll('.node')
+ .data(res.services)
+ .enter().append('g')
+ .call(force.drag)
+ .on("mousedown", function() { d3.event.stopPropagation(); });
+
+ node.append('circle')
+ .attr({
+ class: d => `node ${d.class || ''}`,
+ r: 10
+ });
+
+ node.append('text')
+ .attr({
+ 'text-anchor': 'middle'
+ })
+ .text(d => d.name)
+
+ node.select('circle')
+ .attr({
+ r: function(d){
+ let parent = d3.select(this).node().parentNode;
+ let sib = d3.select(parent).select('text').node().getBBox()
+ return (sib.width / 2) + 10
+
+ }
+ })
+
+ })
+
+ const handleSvg = (el) => {
+ d3.select(el).select('svg').remove();
+
+ svg = d3.select(el)
+ .append('svg')
+ .style('width', `${el.clientWidth}px`)
+ .style('height', `${el.clientHeight}px`);
+ }
+ }
+ };
+ })
+})();
+
+// Draw services around xos and calculate coarse tenant as links
+
+// var width = 960, height = 500;
+
+// var fill = d3.scale.category10();
+
+// var nodes = [
+// {id: 1},
+// {id: 2},
+// {id: 3},
+// {id: 4},
+// {id: 5}
+// ];
+
+// var links = [
+// {source: 1, target: 2},
+// {source: 2, target: 3}
+// ];
+
+// var svg = d3.select("body").append("svg")
+// .attr("width", width)
+// .attr("height", height);
+
+// var force = d3.layout.force()
+// .nodes(nodes)
+// .links(links)
+// .charge(-8*12)
+// .gravity(0.1)
+// .size([width, height])
+// .on("tick", tick)
+// .start();
+
+// svg.append('circle')
+// .attr({
+// "class": "xos",
+// r: 20,
+// cx: () => width / 2,
+// cy: () => height / 2,
+// })
+
+// var node = svg.selectAll(".node")
+// .data(nodes)
+// .enter().append("circle")
+// .attr("class", "node")
+// .attr("cx", ({ x }) => x)
+// .attr("cy", ({ y }) => y)
+// .attr("r", 8)
+// .style("fill", ({}, index) => fill(index & 3))
+// .style("stroke", ({}, index) => d3.rgb(fill(index & 3)).darker(2))
+// .call(force.drag)
+// .on("mousedown", ({}) => d3.event.stopPropagation());
+
+// var link = svg.selectAll(".link")
+// .data(links).enter().insert("line")
+// .attr("class", "link");
+
+// function tick(e) {
+// // Push different nodes in different directions for clustering.
+
+// node.attr("cx", function(d) { return d.x; })
+// .attr("cy", function(d) { return d.y; });
+
+// link.attr("x1", function(d) { return d.source.x; })
+// .attr("y1", function(d) { return d.source.y; })
+// .attr("x2", function(d) { return d.target.x; })
+// .attr("y2", function(d) { return d.target.y; });
+// }
diff --git a/views/ngXosViews/serviceGrid/src/sass/main.scss b/views/ngXosViews/serviceGrid/src/sass/main.scss
new file mode 100644
index 0000000..bc8d14a
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/src/sass/main.scss
@@ -0,0 +1,23 @@
+@import '../../../../style/sass/lib/_variables.scss';
+
+#xosServiceGrid {
+ service-graph {
+ display: block;
+ width: 100%;
+ height: 600px;
+ }
+
+ .node {
+ stroke: $brand-primary;
+ fill: white;
+ }
+
+ .node.xos {
+ fill: $brand-danger;
+ }
+
+ .link {
+ stroke: black;
+ stroke-width: 2px;
+ }
+}
\ No newline at end of file
diff --git a/views/ngXosViews/serviceGrid/src/templates/service-graph.tpl.html b/views/ngXosViews/serviceGrid/src/templates/service-graph.tpl.html
new file mode 100644
index 0000000..c61da91
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/src/templates/service-graph.tpl.html
@@ -0,0 +1,17 @@
+<div class="row">
+ <div class="col-sm-10">
+ <h1>Graph</h1>
+ <ul>
+ <li>Use D3 to create a service chart based on coarse services?</li>
+ </ul>
+ </div>
+ <div class="col-sm-2">
+ <a href="/admin/core/service/add" class="btn btn-success btn-block">
+ <i class="glyphicon glyphicon-plus"></i>
+ Add Service
+ </a>
+ <a href="#/" class="btn btn-default btn-block">
+ Service List
+ </a>
+ </div>
+</div>
\ No newline at end of file
diff --git a/views/ngXosViews/serviceGrid/src/templates/service-grid.tpl.html b/views/ngXosViews/serviceGrid/src/templates/service-grid.tpl.html
new file mode 100644
index 0000000..26f7281
--- /dev/null
+++ b/views/ngXosViews/serviceGrid/src/templates/service-grid.tpl.html
@@ -0,0 +1,14 @@
+<div class="row">
+ <div class="col-sm-10">
+ <xos-table config="vm.tableConfig" data="vm.services"></xos-table>
+ </div>
+ <div class="col-sm-2">
+ <a href="/admin/core/service/add" class="btn btn-success btn-block">
+ <i class="glyphicon glyphicon-plus"></i>
+ Add Service
+ </a>
+ <!-- <a href="#/graph" class="btn btn-default btn-block">
+ Tenancy Graph
+ </a> -->
+ </div>
+</div>
\ No newline at end of file
diff --git a/views/style/bs-config.js b/views/style/bs-config.js
index 2bc1416..b2eedc4 100644
--- a/views/style/bs-config.js
+++ b/views/style/bs-config.js
@@ -5,8 +5,10 @@
'../../xos/core/xoslib/static/**/*.js',
'../../xos/core/xoslib/static/**/*.css',
'../../xos/core/dashboard/views/*.py',
+ '../../xos/core/views/*.py',
'../../xos/templates/**/*.html',
- '../../xos/core/static/xos.css'
+ '../../xos/core/static/xos.css',
+ '../../xos/xos/**/*.py'
],
proxy: "xos.dev:9999",
open: true