Table component with action
diff --git a/views/ngXosLib/karma.conf.js b/views/ngXosLib/karma.conf.js
index 060e7dd..ae486dc 100644
--- a/views/ngXosLib/karma.conf.js
+++ b/views/ngXosLib/karma.conf.js
@@ -43,7 +43,7 @@
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
- '**/*.test.js': ['babel']
+ 'xosHelpers/**/*.js': ['babel'],
},
babelPreprocessor: {
diff --git a/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
index 560f4dc..a3646e3 100644
--- a/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
+++ b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
@@ -9,43 +9,45 @@
(function () {
'use strict';
- describe('The NoHyperlinks factory', () => {
+ describe('The xos.helper module', function(){
+ describe('The NoHyperlinks factory', () => {
- let httpProviderObj, httpBackend, http, noHyperlinks;
+ let httpProviderObj, httpBackend, http, noHyperlinks;
- beforeEach(() => {
- module(
- 'xos.helpers',
- ($httpProvider) => {
- //save our interceptor
- httpProviderObj = $httpProvider;
- }
- );
+ beforeEach(() => {
+ module(
+ 'xos.helpers',
+ ($httpProvider) => {
+ //save our interceptor
+ httpProviderObj = $httpProvider;
+ }
+ );
- inject(function (_$httpBackend_, _$http_, _NoHyperlinks_) {
- httpBackend = _$httpBackend_;
- http = _$http_;
- noHyperlinks = _NoHyperlinks_
+ inject(function (_$httpBackend_, _$http_, _NoHyperlinks_) {
+ httpBackend = _$httpBackend_;
+ http = _$http_;
+ noHyperlinks = _NoHyperlinks_
+ });
+
+ httpProviderObj.interceptors.push('NoHyperlinks');
+
});
- httpProviderObj.interceptors.push('NoHyperlinks');
+ it('should set NoHyperlinks interceptor', () => {
+ expect(httpProviderObj.interceptors).toContain('NoHyperlinks');
+ });
+
+ it('should attach ?no_hyperlinks=1 to the request url', () => {
+ let result = noHyperlinks.request({url: 'sample.url'});
+ expect(result.url).toEqual('sample.url?no_hyperlinks=1');
+ });
+
+ it('should NOT attach ?no_hyperlinks=1 to the request url if is HTML', () => {
+ let result = noHyperlinks.request({url: 'sample.html'});
+ expect(result.url).toEqual('sample.html');
+ });
});
-
- it('should set NoHyperlinks interceptor', () => {
- expect(httpProviderObj.interceptors).toContain('NoHyperlinks');
- });
-
- it('should attach ?no_hyperlinks=1 to the request url', () => {
- let result = noHyperlinks.request({url: 'sample.url'});
- expect(result.url).toEqual('sample.url?no_hyperlinks=1');
- });
-
- it('should NOT attach ?no_hyperlinks=1 to the request url if is HTML', () => {
- let result = noHyperlinks.request({url: 'sample.html'});
- expect(result.url).toEqual('sample.html');
- });
-
});
})();
diff --git a/views/ngXosLib/xosHelpers/spec/ui/table.test.js b/views/ngXosLib/xosHelpers/spec/ui/table.test.js
new file mode 100644
index 0000000..e4c33f1
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/spec/ui/table.test.js
@@ -0,0 +1,83 @@
+/**
+ * © OpenCORD
+ *
+ * Created by teone on 3/24/16.
+ */
+
+(function () {
+ 'use strict';
+
+ describe('The xos.helper module', function(){
+ describe('The xos-table component', () => {
+
+ beforeEach(module('xos.helpers'));
+
+ it('should throw an error if no config is specified', inject(($compile, $rootScope) => {
+ function errorFunctionWrapper(){
+ $compile(angular.element('<xos-table></xos-table>'))($rootScope);
+ $rootScope.$digest();
+ }
+ expect(errorFunctionWrapper).toThrow(new Error('[xosTable] Please provide a configuration via the "config" attribute'));
+ }));
+
+ it('should throw an error if no config columns are specified', inject(($compile, $rootScope) => {
+ function errorFunctionWrapper(){
+ // setup the parent scope
+ let scope = $rootScope.$new();
+ scope.config = 'green';
+ $compile(angular.element('<xos-table config="config"></xos-table>'))(scope);
+ $rootScope.$digest();
+ }
+ expect(errorFunctionWrapper).toThrow(new Error('[xosTable] Please provide a columns list in the configuration'));
+ }));
+
+ });
+
+ describe('when correctly configured', function() {
+ var scope, element, isolatedScope;
+
+ beforeEach(inject(function ($compile, $rootScope) {
+ scope = $rootScope.$new();
+
+ scope.config = {
+ columns: [
+ {
+ label: 'Label 1',
+ prop: 'label-1'
+ },
+ {
+ label: 'Label 2',
+ prop: 'label-2'
+ }
+ ]
+ };
+
+ scope.data = [
+ {
+ 'label-1': 'Sample 1.1',
+ 'label-2': 'Sample 1.2'
+ },
+ {
+ 'label-1': 'Sample 2.1',
+ 'label-2': 'Sample 2.2'
+ }
+ ]
+
+ element = angular.element('<xos-table config="config" data="data"></xos-table>');
+ $compile(element)(scope);
+ // scope.$apply();
+ element.scope().$apply();
+ isolatedScope = element.isolateScope();
+ console.log(element, isolatedScope);
+ }));
+
+ xit('should contain 2 columns', function() {
+ console.log('aaa', isolatedScope);
+
+ // one is the filter, the other two are the products, one is the pagination
+ expect(isolatedScope.columns).toEqual(2);
+ });
+ });
+ });
+})();
+
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/table/table.component.js b/views/ngXosLib/xosHelpers/src/ui_components/table/table.component.js
index 0a81475..f1b6682 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/table/table.component.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/table/table.component.js
@@ -24,11 +24,19 @@
<thead>
<tr>
<th ng-repeat="col in vm.columns">{{col.label}}</th>
+ <th ng-if="vm.config.actions">Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in vm.data">
<td ng-repeat="col in vm.columns">{{item[col.prop]}}</td>
+ <td ng-if="vm.config.actions">
+ <i
+ ng-repeat="action in vm.config.actions"
+ ng-click="action.cb(item)"
+ class="glyphicon glyphicon-{{action.icon}}"
+ style="color: {{action.color}};"></i>
+ </td>
</tr>
</tbody>
</table>
@@ -48,7 +56,10 @@
this.columns = this.config.columns;
this.classes = this.config.classes || 'table table-striped table-bordered';
- console.log('Bella dello zio, RELOAD');
+ if(this.config.actions){
+
+ }
+
}
}
})
diff --git a/views/ngXosViews/sampleView/spec/sample.test.js b/views/ngXosViews/sampleView/spec/sample.test.js
index f0db699..6005af7 100644
--- a/views/ngXosViews/sampleView/spec/sample.test.js
+++ b/views/ngXosViews/sampleView/spec/sample.test.js
@@ -15,7 +15,7 @@
{
email: 'teo@onlab.us',
firstname: 'Matteo',
- lastname: 'Scandolo'
+ lastname: 'Scandolo'
}
]);
diff --git a/views/ngXosViews/sampleView/src/js/main.js b/views/ngXosViews/sampleView/src/js/main.js
index 51f3282..5d94851 100644
--- a/views/ngXosViews/sampleView/src/js/main.js
+++ b/views/ngXosViews/sampleView/src/js/main.js
@@ -41,7 +41,17 @@
prop: 'lastname'
}
],
- classes: 'table table-striped table-condensed'
+ classes: 'table table-striped table-condensed',
+ actions: [
+ {
+ label: 'delete',
+ icon: 'remove',
+ cb: (user) => {
+ console.log(user);
+ },
+ color: 'red'
+ }
+ ]
};
// retrieving user list