blob: 3feeb4aaab44cd2be2b44186191978dec4784dcd [file] [log] [blame]
Matteo Scandolo8b55d9f2016-04-25 17:50:28 -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
12 angular.module('xos.uiComponents')
13
14 /**
15 * @ngdoc directive
16 * @name xos.uiComponents.directive:xosSmartTable
17 * @restrict E
18 * @description The xos-table directive
19 * @param {Object} config The configuration for the component.
20 * @scope
21 * @example
22 */
23
24 .directive('xosSmartTable', function(){
25 return {
26 restrict: 'E',
27 scope: {
28 config: '='
29 },
30 template: `
31 <xos-table config="vm.tableConfig" data="vm.data"></xos-table>
32 `,
33 bindToController: true,
34 controllerAs: 'vm',
35 controller: function($injector, LabelFormatter, _){
36
37 this.tableConfig = {
38 columns: [
39 ],
40 // actions: [
41 // {
42 // label: 'delete',
43 // icon: 'remove',
44 // cb: (user) => {
45 // console.log(user);
46 // // _.remove(this.users, {id: user.id});
47 // },
48 // color: 'red'
49 // }
50 // ],
51 filter: 'field',
52 order: true,
53 pagination: {
54 pageSize: 10
55 }
56 };
57
58 let Resource = $injector.get(this.config.resource);
59
60 Resource.query().$promise
61 .then((res) => {
62
63 let props = Object.keys(res[0]);
64
65 _.remove(props, p => {
66 return p == 'id' || p == 'password' || p == 'validators'
67 });
68
69 let labels = props.map(p => LabelFormatter.format(p));
70
71 console.log(props, labels);
72
73 props.forEach((p, i) => {
74 this.tableConfig.columns.push({
75 label: labels[i],
76 prop: p
77 });
78 });
79
80
81 console.log(this.tableConfig.columns);
82
83 this.data = res;
84 })
85 }
86 };
87 });
88})();