Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Memory View Module |
| 19 | */ |
| 20 | (function () { |
| 21 | 'use strict'; |
| 22 | |
| 23 | // injected references |
| 24 | var $log, $scope, $location, ks, fs, cbs, ns; |
| 25 | |
| 26 | var hasDeviceId; |
| 27 | var barsNb = 3; |
| 28 | |
| 29 | var labels = new Array(1); |
| 30 | var data = new Array(barsNb); |
| 31 | for (var i = 0; i < barsNb; i++) { |
| 32 | data[i] = new Array(1); |
| 33 | data[i][0] = 0; |
| 34 | } |
| 35 | |
| 36 | angular.module('ovMemory', ["chart.js"]) |
| 37 | .controller('OvMemoryCtrl', |
| 38 | ['$log', '$scope', '$location', 'FnService', 'ChartBuilderService', 'NavService', |
| 39 | |
| 40 | function (_$log_, _$scope_, _$location_, _fs_, _cbs_, _ns_) { |
| 41 | var params; |
| 42 | $log = _$log_; |
| 43 | $scope = _$scope_; |
| 44 | $location = _$location_; |
| 45 | fs = _fs_; |
| 46 | cbs = _cbs_; |
| 47 | ns = _ns_; |
| 48 | |
| 49 | params = $location.search(); |
| 50 | |
| 51 | if (params.hasOwnProperty('devId')) { |
| 52 | $scope.devId = params['devId']; |
| 53 | hasDeviceId = true; |
| 54 | } else { |
| 55 | hasDeviceId = false; |
| 56 | } |
| 57 | |
| 58 | cbs.buildChart({ |
| 59 | scope: $scope, |
| 60 | tag: 'memory', |
| 61 | query: params |
| 62 | }); |
| 63 | |
| 64 | $scope.$watch('chartData', function () { |
| 65 | if (!fs.isEmptyObject($scope.chartData)) { |
| 66 | $scope.showLoader = false; |
| 67 | var length = $scope.chartData.length; |
| 68 | labels = new Array(length); |
| 69 | for (var i = 0; i < barsNb; i++) { |
| 70 | data[i] = new Array(length); |
| 71 | } |
| 72 | |
| 73 | $scope.chartData.forEach( |
| 74 | function (cm, idx) { |
| 75 | data[0][idx] = cm.memory_used; |
| 76 | data[1][idx] = cm.memory_free; |
| 77 | data[2][idx] = cm.memory_total; |
| 78 | |
| 79 | labels[idx] = cm.label; |
| 80 | } |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | $scope.labels = labels; |
| 85 | $scope.data = data; |
| 86 | |
| 87 | $scope.options = { |
| 88 | scales: { |
| 89 | yAxes: [{ |
| 90 | type: 'linear', |
| 91 | position: 'left', |
| 92 | id: 'y-axis-memory', |
| 93 | ticks: { |
| 94 | beginAtZero: true, |
| 95 | fontSize: 28, |
| 96 | }, |
| 97 | scaleLabel: { |
| 98 | display: true, |
| 99 | labelString: 'Memory Utilization (GBytes)', |
| 100 | fontSize: 28, |
| 101 | } |
| 102 | }], |
| 103 | xAxes: [{ |
| 104 | id: 'x-axis-servers', |
| 105 | ticks: { |
| 106 | fontSize: 28, |
| 107 | }, |
| 108 | scaleLabel: { |
| 109 | display: false, |
| 110 | fontSize: 28, |
| 111 | } |
| 112 | }] |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | $scope.onClick = function (points, evt) { |
| 117 | var label = labels[points[0]._index]; |
| 118 | if (label) { |
| 119 | ns.navTo('memory', { devId: label }); |
| 120 | $log.log(label); |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | if (!fs.isEmptyObject($scope.annots)) { |
| 125 | $scope.deviceIds = JSON.parse($scope.annots.deviceIds); |
| 126 | } |
| 127 | |
| 128 | $scope.onChange = function (deviceId) { |
| 129 | ns.navTo('memory', { devId: deviceId }); |
| 130 | }; |
| 131 | }); |
| 132 | |
| 133 | $scope.series = new Array(barsNb); |
| 134 | $scope.series[0] = 'Memory - Used'; |
| 135 | $scope.series[1] = 'Memory - Free'; |
| 136 | $scope.series[2] = 'Memory - Total'; |
| 137 | |
| 138 | $scope.labels = labels; |
| 139 | $scope.data = data; |
| 140 | |
| 141 | $scope.showLoader = true; |
| 142 | |
| 143 | $log.log('OvMemoryCtrl has been created'); |
| 144 | }]); |
| 145 | |
| 146 | }()); |