Matteo Scandolo | 896bb7b | 2016-05-06 14:10:11 -0700 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.serviceGrid', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
| 6 | 'ui.router', |
| 7 | 'xos.helpers' |
| 8 | ]) |
| 9 | .config(($stateProvider) => { |
| 10 | $stateProvider |
| 11 | .state('serviceGrid', { |
| 12 | url: '/', |
| 13 | template: '<service-grid></service-grid>' |
| 14 | }) |
| 15 | .state('serviceGraph', { |
| 16 | url: '/graph', |
| 17 | template: '<service-graph></service-graph>' |
| 18 | }); |
| 19 | }) |
| 20 | .config(function($httpProvider){ |
| 21 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 22 | }) |
| 23 | .directive('serviceGrid', function(){ |
| 24 | return { |
| 25 | restrict: 'E', |
| 26 | scope: {}, |
| 27 | bindToController: true, |
| 28 | controllerAs: 'vm', |
| 29 | templateUrl: 'templates/service-grid.tpl.html', |
| 30 | controller: function(Services, _){ |
| 31 | |
| 32 | this.tableConfig = { |
| 33 | columns: [ |
| 34 | { |
| 35 | label: 'Status', |
| 36 | prop: 'status', |
| 37 | type: 'boolean', |
| 38 | }, |
| 39 | { |
| 40 | label: 'Name', |
| 41 | prop: 'name', |
| 42 | link: item => `${item.view_url.replace(/\$[a-z]+\$/, item.id)}` |
| 43 | }, |
| 44 | { |
| 45 | label: 'Kind', |
| 46 | prop: 'kind' |
| 47 | }, |
| 48 | { |
| 49 | label: 'Enabled', |
| 50 | prop: 'enabled', |
| 51 | type: 'boolean' |
| 52 | } |
| 53 | ], |
| 54 | filter: 'field', |
| 55 | order: true |
| 56 | }; |
| 57 | |
| 58 | // retrieving user list |
| 59 | Services.query().$promise |
| 60 | .then((services) => { |
| 61 | this.services = _.map(services, s => { |
| 62 | // parse backend_status string in a boolean for display |
| 63 | s.status = parseInt(s.backend_status.match(/^[0-9]/)[0]) === 0 ? false : true; |
| 64 | return s; |
| 65 | }) |
| 66 | }) |
| 67 | .catch((e) => { |
| 68 | throw new Error(e); |
| 69 | }); |
| 70 | } |
| 71 | }; |
| 72 | }); |