Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.ceilometerDashboard', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
| 6 | 'ngLodash', |
| 7 | 'ui.router', |
| 8 | 'xos.helpers', |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 9 | 'ngAnimate', |
Matteo Scandolo | 0f5e163 | 2015-12-09 16:09:59 -0800 | [diff] [blame] | 10 | 'chart.js', |
| 11 | 'ui.bootstrap.accordion' |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 12 | ]) |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 13 | .config(($stateProvider, $urlRouterProvider) => { |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 14 | $stateProvider |
| 15 | .state('ceilometerDashboard', { |
| 16 | url: '/', |
| 17 | template: '<ceilometer-dashboard></ceilometer-dashboard>' |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 18 | }) |
| 19 | .state('samples', { |
| 20 | url: '/:name/:tenant/samples', |
| 21 | template: '<ceilometer-samples></ceilometer-samples>' |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 22 | }); |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 23 | $urlRouterProvider.otherwise('/'); |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 24 | }) |
| 25 | .config(function($httpProvider){ |
| 26 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 27 | }) |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 28 | .run(function($rootScope){ |
| 29 | $rootScope.stateName = 'ceilometerDashboard'; |
| 30 | $rootScope.$on('$stateChangeStart', (event, toState) => { |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 31 | $rootScope.stateName = toState.name; |
| 32 | }) |
| 33 | }) |
Matteo Scandolo | 5dd9418 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 34 | .service('Ceilometer', function($http, $q, lodash){ |
Matteo Scandolo | d3e696d | 2015-12-08 15:24:23 -0800 | [diff] [blame] | 35 | |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 36 | this.getMeters = () => { |
| 37 | let deferred = $q.defer(); |
| 38 | |
Matteo Scandolo | 5dd9418 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 39 | $http.get('/xoslib/meters/', {cache: true}) |
| 40 | // $http.get('../meters_mock.json', {cache: true}) |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 41 | .then((res) => { |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 42 | deferred.resolve(res.data) |
| 43 | }) |
| 44 | .catch((e) => { |
| 45 | deferred.reject(e); |
| 46 | }); |
| 47 | |
| 48 | return deferred.promise; |
| 49 | } |
| 50 | |
| 51 | this.getSamples = (name, tenant) => { |
| 52 | let deferred = $q.defer(); |
| 53 | |
Matteo Scandolo | 6c78843 | 2015-12-07 17:32:39 -0800 | [diff] [blame] | 54 | $http.get(`/xoslib/metersamples/`, {params: {meter: name, tenant: tenant}}) |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 55 | .then((res) => { |
| 56 | deferred.resolve(res.data) |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 57 | }) |
| 58 | .catch((e) => { |
| 59 | deferred.reject(e); |
| 60 | }); |
| 61 | |
| 62 | return deferred.promise; |
| 63 | } |
Matteo Scandolo | 5dd9418 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 64 | |
| 65 | this.getStats = (sliceName) => { |
| 66 | let deferred = $q.defer(); |
| 67 | |
| 68 | $http.get('/xoslib/meterstatistics/', {cache: true}) |
| 69 | // $http.get('../stats_mock.son', {cache: true}) |
| 70 | .then((res) => { |
| 71 | deferred.resolve(lodash.filter(res.data, {slice: sliceName})) |
| 72 | }) |
| 73 | .catch((e) => { |
| 74 | deferred.reject(e); |
| 75 | }); |
| 76 | |
| 77 | return deferred.promise; |
| 78 | }; |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 79 | |
| 80 | // hold dashboard status (opened service, slice, resource) |
| 81 | this.selectedService = null; |
| 82 | this.selectedSlice = null; |
| 83 | this.selectedResource = null; |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 84 | }) |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 85 | .directive('ceilometerDashboard', function(lodash){ |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 86 | return { |
| 87 | restrict: 'E', |
| 88 | scope: {}, |
| 89 | bindToController: true, |
| 90 | controllerAs: 'vm', |
| 91 | templateUrl: 'templates/ceilometer-dashboard.tpl.html', |
| 92 | controller: function(Ceilometer){ |
| 93 | |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 94 | // this open the accordion |
| 95 | this.accordion = { |
| 96 | open: {} |
Matteo Scandolo | 0bbfb0d | 2016-01-28 14:50:16 -0800 | [diff] [blame] | 97 | }; |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * Open the active panel base on the service stored values |
| 101 | */ |
| 102 | this.openPanels = () => { |
| 103 | if(Ceilometer.selectedService){ |
| 104 | this.accordion.open[Ceilometer.selectedService] = true; |
| 105 | if(Ceilometer.selectedSlice){ |
| 106 | this.selectedSlice = Ceilometer.selectedSlice; |
| 107 | this.selectedResources = this.projects[Ceilometer.selectedService][Ceilometer.selectedSlice] |
| 108 | if(Ceilometer.selectedResource){ |
| 109 | this.selectedResource = Ceilometer.selectedResource; |
| 110 | this.selectedMeters = this.selectedResources[Ceilometer.selectedResource]; |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 116 | this.loadMeters = () => { |
| 117 | this.loader = true; |
| 118 | |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 119 | // TODO rename projects in meters |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 120 | Ceilometer.getMeters() |
| 121 | .then(meters => { |
Matteo Scandolo | 30c23c7 | 2015-12-09 15:23:51 -0800 | [diff] [blame] | 122 | //group project by service |
| 123 | this.projects = lodash.groupBy(meters, 'service'); |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 124 | lodash.forEach(Object.keys(this.projects), (project) => { |
Matteo Scandolo | 30c23c7 | 2015-12-09 15:23:51 -0800 | [diff] [blame] | 125 | // inside each service group by slice |
| 126 | this.projects[project] = lodash.groupBy(this.projects[project], 'slice'); |
| 127 | lodash.forEach(Object.keys(this.projects[project]), (slice) => { |
| 128 | // inside each service => slice group by resource |
Matteo Scandolo | a918ea8 | 2015-12-14 14:26:20 -0800 | [diff] [blame] | 129 | this.projects[project][slice] = lodash.groupBy(this.projects[project][slice], 'resource_name'); |
Matteo Scandolo | 30c23c7 | 2015-12-09 15:23:51 -0800 | [diff] [blame] | 130 | }); |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 131 | }); |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 132 | |
| 133 | // open selected panels |
| 134 | this.openPanels(); |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 135 | }) |
| 136 | .catch(err => { |
Matteo Scandolo | a918ea8 | 2015-12-14 14:26:20 -0800 | [diff] [blame] | 137 | this.error = err.data.detail; |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 138 | }) |
| 139 | .finally(() => { |
| 140 | this.loader = false; |
| 141 | }); |
| 142 | } |
| 143 | |
| 144 | this.loadMeters(); |
| 145 | |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 146 | /** |
| 147 | * Select Resources for a slice |
| 148 | * |
| 149 | * @param Array resources The list of selected resources |
| 150 | * @returns void |
| 151 | */ |
| 152 | this.selectedResources = null; |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 153 | this.selectResources = (resources, slice, service) => { |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 154 | //cleaning |
| 155 | this.selectedResources = null; |
| 156 | this.selectedResource = null; |
| 157 | this.selectedMeters = null; |
| 158 | |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 159 | // hold the resource list for the current slice |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 160 | this.selectedResources = resources; |
| 161 | this.selectedSlice = slice; |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 162 | this.selectedService = service; |
| 163 | |
| 164 | // store the status |
| 165 | Ceilometer.selectedSlice = slice; |
| 166 | Ceilometer.selectedService = service; |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Select Meters for a resource |
| 171 | * |
| 172 | * @param Array meters The list of selected resources |
| 173 | * @returns void |
| 174 | */ |
| 175 | this.selectedMeters = null; |
| 176 | this.selectMeters = (meters, resource) => { |
| 177 | this.selectedMeters = meters; |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 178 | |
| 179 | Ceilometer.selectedResource = resource; |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 180 | this.selectedResource = resource; |
| 181 | } |
| 182 | |
Matteo Scandolo | e3de73d | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 183 | } |
| 184 | }; |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 185 | }) |
| 186 | .directive('ceilometerSamples', function(lodash, $stateParams){ |
| 187 | return { |
| 188 | restrict: 'E', |
| 189 | scope: { |
| 190 | name: '=name', |
| 191 | tenant: '=tenant' |
| 192 | }, |
| 193 | bindToController: true, |
| 194 | controllerAs: 'vm', |
| 195 | templateUrl: 'templates/ceilometer-samples.tpl.html', |
| 196 | controller: function(Ceilometer) { |
| 197 | |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 198 | // console.log(Ceilometer.selectResource); |
| 199 | |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 200 | this.chartColors = [ |
Matteo Scandolo | d3e696d | 2015-12-08 15:24:23 -0800 | [diff] [blame] | 201 | '#286090', |
| 202 | '#F7464A', |
| 203 | '#46BFBD', |
| 204 | '#FDB45C', |
| 205 | '#97BBCD', |
| 206 | '#4D5360', |
| 207 | '#8c4f9f' |
| 208 | ]; |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 209 | |
| 210 | this.chart = { |
| 211 | series: [], |
| 212 | labels: [], |
| 213 | data: [] |
| 214 | } |
| 215 | |
| 216 | Chart.defaults.global.colours = this.chartColors; |
Matteo Scandolo | d3e696d | 2015-12-08 15:24:23 -0800 | [diff] [blame] | 217 | |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 218 | this.chartType = 'line'; |
| 219 | |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 220 | if($stateParams.name && $stateParams.tenant){ |
| 221 | this.name = $stateParams.name; |
| 222 | this.tenant = $stateParams.tenant; |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 223 | // TODO rename tenant in project_id |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 224 | } |
Matteo Scandolo | 48d890f | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 225 | else{ |
| 226 | throw new Error('Missing Name and Tenant Params!'); |
| 227 | } |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 228 | |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 229 | /** |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 230 | * Goes trough the array and format date to be used as labels |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 231 | * |
| 232 | * @param Array data |
| 233 | * @returns Array a list of labels |
| 234 | */ |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 235 | |
Matteo Scandolo | 52193d3 | 2015-12-05 18:44:45 -0800 | [diff] [blame] | 236 | this.getLabels = (data) => { |
| 237 | return data.reduce((list, item) => { |
| 238 | let date = new Date(item.timestamp); |
| 239 | list.push(`${date.getHours()}:${(date.getMinutes()<10?'0':'') + date.getMinutes()}:${date.getSeconds()}`); |
| 240 | return list; |
| 241 | }, []); |
| 242 | }; |
| 243 | |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 244 | /** |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 245 | * Goes trough the array and return a flat array of values |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 246 | * |
| 247 | * @param Array data |
| 248 | * @returns Array a list of values |
| 249 | */ |
| 250 | |
Matteo Scandolo | 52193d3 | 2015-12-05 18:44:45 -0800 | [diff] [blame] | 251 | this.getData = (data) => { |
| 252 | return data.reduce((list, item) => { |
| 253 | list.push(item.volume); |
| 254 | return list; |
| 255 | }, []); |
| 256 | } |
| 257 | |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 258 | /** |
| 259 | * Add a samples to the chart |
| 260 | * |
| 261 | * @param string resource_id |
| 262 | */ |
| 263 | this.chartMeters = []; |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 264 | this.addMeterToChart = (project_id) => { |
| 265 | this.chart['labels'] = this.getLabels(lodash.sortBy(this.samplesList[project_id], 'timestamp')); |
| 266 | this.chart['series'].push(project_id); |
| 267 | this.chart['data'].push(this.getData(lodash.sortBy(this.samplesList[project_id], 'timestamp'))); |
| 268 | this.chartMeters.push(this.samplesList[project_id][0]); //use the 0 as are all samples for the same resource and I need the name |
| 269 | lodash.remove(this.sampleLabels, {id: project_id}); |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Matteo Scandolo | edea1db | 2015-12-14 14:42:28 -0800 | [diff] [blame] | 272 | this.removeFromChart = (meter) => { |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 273 | this.chart.data.splice(this.chart.series.indexOf(meter.project_id), 1); |
| 274 | this.chart.series.splice(this.chart.series.indexOf(meter.project_id), 1); |
| 275 | this.chartMeters.splice(lodash.findIndex(this.chartMeters, {project_id: meter.project_id}), 1); |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 276 | this.sampleLabels.push({ |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 277 | id: meter.project_id, |
| 278 | name: meter.resource_name || meter.project_id |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 279 | }) |
| 280 | }; |
| 281 | |
| 282 | /** |
| 283 | * Format samples to create a list of labels and ids |
| 284 | */ |
| 285 | |
| 286 | this.formatSamplesLabels = (samples) => { |
| 287 | |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 288 | return lodash.uniq(samples, 'project_id') |
Matteo Scandolo | 9e1bc29 | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 289 | .reduce((labels, item) => { |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 290 | labels.push({ |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 291 | id: item.project_id, |
| 292 | name: item.resource_name || item.project_id |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 293 | }); |
| 294 | return labels; |
Matteo Scandolo | 9e1bc29 | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 295 | }, []); |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 299 | /** |
| 300 | * Load the samples and format data |
| 301 | */ |
| 302 | |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 303 | this.showSamples = () => { |
| 304 | this.loader = true; |
Matteo Scandolo | c2d3110 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 305 | // Ceilometer.getSamples(this.name, this.tenant) //fetch one |
| 306 | Ceilometer.getSamples(this.name) //fetch all |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 307 | .then(res => { |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 308 | |
| 309 | // setup data for visualization |
Matteo Scandolo | d9e1c41 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 310 | this.samplesList = lodash.groupBy(res, 'project_id'); |
Matteo Scandolo | c6a7898 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 311 | this.sampleLabels = this.formatSamplesLabels(res); |
| 312 | |
| 313 | // add current meter to chart |
| 314 | this.addMeterToChart(this.tenant); |
| 315 | |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 316 | }) |
| 317 | .catch(err => { |
Matteo Scandolo | 30c23c7 | 2015-12-09 15:23:51 -0800 | [diff] [blame] | 318 | this.error = err.data.detail; |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 319 | }) |
| 320 | .finally(() => { |
| 321 | this.loader = false; |
| 322 | }); |
| 323 | }; |
| 324 | |
| 325 | this.showSamples(); |
Matteo Scandolo | ec8ad42 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 326 | } |
| 327 | } |
Matteo Scandolo | 5dd9418 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 328 | }) |
Matteo Scandolo | 0bbfb0d | 2016-01-28 14:50:16 -0800 | [diff] [blame] | 329 | // NOTE reading this on demand for a single |
Matteo Scandolo | 5dd9418 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 330 | .directive('ceilometerStats', function(){ |
| 331 | return { |
| 332 | restrict: 'E', |
| 333 | scope: { |
| 334 | name: '=name', |
| 335 | }, |
| 336 | bindToController: true, |
| 337 | controllerAs: 'vm', |
| 338 | templateUrl: 'templates/ceilometer-stats.tpl.html', |
| 339 | controller: function($scope, Ceilometer) { |
| 340 | this.getStats = () => { |
| 341 | this.loader = true; |
| 342 | Ceilometer.getStats(this.name) |
| 343 | .then(res => { |
| 344 | this.stats = res; |
| 345 | }) |
| 346 | .catch(err => { |
| 347 | this.error = err.data; |
| 348 | }) |
| 349 | .finally(() => { |
| 350 | this.loader = false; |
| 351 | }); |
| 352 | }; |
| 353 | |
| 354 | this.getStats(); |
| 355 | |
| 356 | $scope.$watch(() => this.name, () => {this.getStats();}); |
| 357 | } |
| 358 | } |
Matteo Scandolo | 76b4e98 | 2015-12-10 10:15:20 -0800 | [diff] [blame] | 359 | }) |
| 360 | .filter('orderObjectByKey', function(lodash) { |
Matteo Scandolo | a918ea8 | 2015-12-14 14:26:20 -0800 | [diff] [blame] | 361 | return function(items) { |
Matteo Scandolo | 76b4e98 | 2015-12-10 10:15:20 -0800 | [diff] [blame] | 362 | |
| 363 | if(!items){ |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | return lodash.reduce(Object.keys(items).reverse(), (list, key) => { |
| 368 | list[key] = items[key]; |
| 369 | return list; |
| 370 | }, {}); |
| 371 | |
| 372 | }; |
| 373 | }); |
| 374 | ; |