Matteo Scandolo | 70bc45f | 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', |
Matteo Scandolo | ba678a9 | 2016-06-20 17:16:15 -0700 | [diff] [blame] | 30 | controller: function(Services, ToscaEncoder, _){ |
Matteo Scandolo | 70bc45f | 2016-05-06 14:10:11 -0700 | [diff] [blame] | 31 | |
| 32 | this.tableConfig = { |
| 33 | columns: [ |
| 34 | { |
| 35 | label: 'Status', |
| 36 | prop: 'status', |
Matteo Scandolo | 83369f3 | 2016-05-13 10:39:38 -0700 | [diff] [blame] | 37 | type: 'icon', |
| 38 | formatter: item => { |
| 39 | let status = parseInt(item.backend_status.match(/^[0-9]/)[0]); |
| 40 | switch(status){ |
| 41 | case 0: |
| 42 | return 'time'; |
| 43 | case 1: |
| 44 | return 'ok'; |
| 45 | case 2: |
| 46 | return 'remove'; |
| 47 | } |
| 48 | } |
Matteo Scandolo | 70bc45f | 2016-05-06 14:10:11 -0700 | [diff] [blame] | 49 | }, |
| 50 | { |
| 51 | label: 'Name', |
| 52 | prop: 'name', |
| 53 | link: item => `${item.view_url.replace(/\$[a-z]+\$/, item.id)}` |
| 54 | }, |
| 55 | { |
| 56 | label: 'Kind', |
| 57 | prop: 'kind' |
| 58 | }, |
| 59 | { |
| 60 | label: 'Enabled', |
| 61 | prop: 'enabled', |
| 62 | type: 'boolean' |
| 63 | } |
| 64 | ], |
| 65 | filter: 'field', |
Matteo Scandolo | 83369f3 | 2016-05-13 10:39:38 -0700 | [diff] [blame] | 66 | order: { |
| 67 | field: 'name' |
Matteo Scandolo | ba678a9 | 2016-06-20 17:16:15 -0700 | [diff] [blame] | 68 | }, |
| 69 | actions: [ |
| 70 | { |
| 71 | label: 'export', |
| 72 | icon: 'export', |
| 73 | cb: service => { |
| 74 | this.tosca = ''; |
| 75 | ToscaEncoder.serviceToTosca(service) |
| 76 | .then(tosca => { |
| 77 | this.showFeedback = true; |
| 78 | this.tosca = tosca; |
| 79 | }); |
| 80 | } |
| 81 | } |
| 82 | ] |
Matteo Scandolo | 70bc45f | 2016-05-06 14:10:11 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | // retrieving user list |
| 86 | Services.query().$promise |
| 87 | .then((services) => { |
| 88 | this.services = _.map(services, s => { |
| 89 | // parse backend_status string in a boolean for display |
Matteo Scandolo | 206d748 | 2016-05-13 09:26:54 -0700 | [diff] [blame] | 90 | // NOTE they are not boolean: |
| 91 | // - start with 0 = provisioning |
| 92 | // - start with 1 = good |
| 93 | // - start with 2 = error |
Matteo Scandolo | 70bc45f | 2016-05-06 14:10:11 -0700 | [diff] [blame] | 94 | s.status = parseInt(s.backend_status.match(/^[0-9]/)[0]) === 0 ? false : true; |
| 95 | return s; |
| 96 | }) |
| 97 | }) |
| 98 | .catch((e) => { |
| 99 | throw new Error(e); |
| 100 | }); |
| 101 | } |
| 102 | }; |
| 103 | }); |