Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.hpc', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
| 6 | 'ui.router', |
| 7 | 'xos.helpers' |
| 8 | ]) |
| 9 | .config(($stateProvider) => { |
| 10 | $stateProvider |
| 11 | .state('hpc-list', { |
| 12 | url: '/', |
| 13 | template: '<hpcs-list></hpcs-list>' |
| 14 | }); |
| 15 | }) |
| 16 | .config(function($httpProvider){ |
| 17 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 18 | }) |
| 19 | .service('Hpc', function($q, $http){ |
| 20 | this.query = (params) => { |
| 21 | const d = $q.defer(); |
| 22 | |
| 23 | $http.get('/xoslib/hpcview', {params: params}) |
| 24 | .then((res) => { |
| 25 | d.resolve(res.data); |
| 26 | }) |
| 27 | .catch(d.reject); |
| 28 | |
| 29 | return {$promise: d.promise}; |
| 30 | }; |
| 31 | }) |
| 32 | .directive('hpcsList', function(){ |
| 33 | return { |
| 34 | restrict: 'E', |
| 35 | scope: {}, |
| 36 | bindToController: true, |
| 37 | controllerAs: 'vm', |
| 38 | templateUrl: 'templates/hpc-list.tpl.html', |
| 39 | controller: function(Hpc){ |
| 40 | |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 41 | const secondsToHms = d => { |
| 42 | d = Number(d); |
| 43 | var h = Math.floor(d / 3600); |
| 44 | var m = Math.floor(d % 3600 / 60); |
| 45 | var s = Math.floor(d % 3600 % 60); |
| 46 | return ((h > 0 ? h + 'h ' + (m < 10 ? '0' :'') :'') + m + 'm ' + (s < 10 ? '0' :'') + s + 's'); |
| 47 | }; |
| 48 | |
| 49 | const toDuration = (property) => { |
| 50 | return (item) => { |
| 51 | if(!angular.isNumber(item[property])){ |
| 52 | return item[property] |
| 53 | } |
| 54 | return secondsToHms(item[property]); |
| 55 | } |
| 56 | }; |
| 57 | |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 58 | this.routerConfig = { |
| 59 | filter: 'field', |
| 60 | order: true, |
| 61 | columns: [ |
| 62 | { |
| 63 | label: 'Name', |
| 64 | prop: 'name' |
| 65 | }, |
| 66 | { |
| 67 | label: 'Ip Address', |
| 68 | prop: 'ip' |
| 69 | }, |
| 70 | { |
| 71 | label: 'Record Checker', |
| 72 | prop: 'watcher.DNS.msg' |
| 73 | }, |
| 74 | { |
| 75 | label: 'Name Servers', |
| 76 | prop: 'nameservers', |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 77 | type: 'array' |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 78 | }, |
| 79 | { |
| 80 | label: 'Dns Demux Config Age', |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 81 | prop: 'dnsdemux_config_age', |
| 82 | type: 'custom', |
| 83 | formatter: toDuration('dnsdemux_config_age') |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 84 | }, |
| 85 | { |
| 86 | label: 'Dns Redir Config Age', |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 87 | prop: 'dnsredir_config_age', |
| 88 | type: 'custom', |
| 89 | formatter: toDuration('dnsredir_config_age') |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 90 | } |
| 91 | ] |
| 92 | }; |
| 93 | |
| 94 | this.cacheConfig = { |
| 95 | filter: 'field', |
| 96 | order: true, |
| 97 | columns: [ |
| 98 | { |
| 99 | label: 'Name', |
| 100 | prop: 'name' |
| 101 | }, |
| 102 | { |
| 103 | label: 'Prober', |
| 104 | prop: 'watcher.HPC-hb.msg' |
| 105 | }, |
| 106 | { |
| 107 | label: 'Fetcher', |
| 108 | prop: 'watcher.HPC-fetch.msg' |
| 109 | }, |
| 110 | { |
| 111 | label: 'Config Age', |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 112 | prop: 'config_age', |
| 113 | type: 'custom', |
| 114 | formatter: toDuration('config_age') |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 115 | } |
| 116 | ] |
| 117 | }; |
Matteo Scandolo | 5eac68a | 2016-06-17 10:04:28 -0700 | [diff] [blame] | 118 | |
| 119 | |
| 120 | this.fetch = () => { |
| 121 | Hpc.query().$promise |
| 122 | .then((hpcs) => { |
| 123 | this.routers = hpcs[0].dnsdemux; |
| 124 | this.caches = hpcs[0].hpc; |
| 125 | }) |
| 126 | .catch((e) => { |
| 127 | throw new Error(e); |
| 128 | }); |
| 129 | }; |
| 130 | |
| 131 | this.fetch(); |
Matteo Scandolo | a8cbc9c | 2016-06-16 17:03:24 -0700 | [diff] [blame] | 132 | } |
| 133 | }; |
| 134 | }); |