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));