blob: b8b5915187191b31cc6f2ca9c15a1e946ce4c6c2 [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
Matteo Scandoloaaa733d2016-04-26 08:42:51 -070060 console.log('query', Resource.query.toString(), Resource.test(`I'm Alive!`));
61
Matteo Scandolo8b55d9f2016-04-25 17:50:28 -070062 Resource.query().$promise
63 .then((res) => {
Matteo Scandoloaaa733d2016-04-26 08:42:51 -070064 console.log('Data!!');
Matteo Scandolo8b55d9f2016-04-25 17:50:28 -070065 let props = Object.keys(res[0]);
66
67 _.remove(props, p => {
68 return p == 'id' || p == 'password' || p == 'validators'
69 });
70
71 let labels = props.map(p => LabelFormatter.format(p));
72
73 console.log(props, labels);
74
75 props.forEach((p, i) => {
76 this.tableConfig.columns.push({
77 label: labels[i],
78 prop: p
79 });
80 });
81
82
83 console.log(this.tableConfig.columns);
84
85 this.data = res;
86 })
87 }
88 };
89 });
90})();