blob: 0a81475d7dcc6a82b046247ff9e0247144b15ca8 [file] [log] [blame]
Matteo Scandolo66351432016-03-24 15:29:52 -07001/**
2 * © OpenCORD
3 *
4 * Visit http://guide.xosproject.org/devguide/addview/ for more information
5 *
6 * Created by teone on 3/24/16.
7 */
8
9(function () {
10 'use strict';
11
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070012
Matteo Scandolo66351432016-03-24 15:29:52 -070013 angular.module('xos.uiComponents.table', [])
14 .directive('xosTable', function(){
15 return {
16 restrict: 'E',
17 scope: {
18 data: '=',
Matteo Scandolodcc65242016-04-14 12:06:50 -070019 config: '='
Matteo Scandolo66351432016-03-24 15:29:52 -070020 },
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070021 template: `
Matteo Scandolodcc65242016-04-14 12:06:50 -070022 <!-- <pre>{{vm.data | json}}</pre> -->
23 <table ng-class="vm.classes" ng-show="vm.data.length > 0">
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070024 <thead>
25 <tr>
Matteo Scandolodcc65242016-04-14 12:06:50 -070026 <th ng-repeat="col in vm.columns">{{col.label}}</th>
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070027 </tr>
28 </thead>
29 <tbody>
30 <tr ng-repeat="item in vm.data">
Matteo Scandolodcc65242016-04-14 12:06:50 -070031 <td ng-repeat="col in vm.columns">{{item[col.prop]}}</td>
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070032 </tr>
33 </tbody>
34 </table>
35 `,
Matteo Scandolo66351432016-03-24 15:29:52 -070036 bindToController: true,
37 controllerAs: 'vm',
38 controller: function(){
Matteo Scandolodcc65242016-04-14 12:06:50 -070039
40 if(!this.config){
41 throw new Error('[xosTable] Please provide a configuration via the "config" attribute');
42 }
43
44 if(!this.config.columns){
45 throw new Error('[xosTable] Please provide a columns list in the configuration');
46 }
47
48 this.columns = this.config.columns;
49 this.classes = this.config.classes || 'table table-striped table-bordered';
50
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070051 console.log('Bella dello zio, RELOAD');
Matteo Scandolo66351432016-03-24 15:29:52 -070052 }
53 }
54 })
55})();