2 * @copyright 2017 highstreet technologies GmbH and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 define(['app/mwtnTdm/mwtnTdm.module',
11 'app/mwtnTdm/mwtnTdm.services'],
12 function (mwtnTdmApp) {
14 mwtnTdmApp.register.controller('mwtnTdmCtrl', ['$scope', '$rootScope', '$timeout', '$mwtnLog', '$mwtnTdm', '$translate', 'OnfNetworkElement', 'uiGridConstants',
15 function ($scope, $rootScope, $timeout, $mwtnLog, $mwtnTdm, $translate, OnfNetworkElement, uiGridConstants) {
17 var COMPONENT = 'mwtnTdmCtrl';
18 $rootScope.section_logo = 'src/app/mwtnTdm/images/mwtnTdm.png'; // Add your topbar logo location here such as 'assets/images/logo_topology.gif'
20 $scope.highlightFilteredHeader = $mwtnTdm.highlightFilteredHeader;
21 $scope.gridOptions = JSON.parse(JSON.stringify($mwtnTdm.gridOptions));
22 $scope.gridOptions.onRegisterApi = function (gridApi) {
23 $scope.gridApi = gridApi;
25 $scope.gridOptions.columnDefs = [
26 // { field: 'id', type: 'number', displayName: 'No.', headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true },
27 { field: 'nodeId', type: 'string', displayName: 'Node', headerCellClass: $scope.highlightFilteredHeader, width: 200 },
28 { field: 'layer', type: 'string', displayName: 'Layer', headerCellClass: $scope.highlightFilteredHeader, width: 100 },
29 { field: 'ltpRef', type: 'string', displayName: 'Logical termiantion point', headerCellClass: $scope.highlightFilteredHeader, width: 300 },
30 { field: 'reserved', type: 'number', displayName: 'Reserved E1', headerCellClass: $scope.highlightFilteredHeader, width: 150, cellClass: 'number' },
31 { field: 'configured', type: 'number', displayName: 'Configured E1', headerCellClass: $scope.highlightFilteredHeader, width: 150, cellClass: 'number' },
32 { field: 'utilization', type: 'number', displayName: 'Utilization [%]', headerCellClass: $scope.highlightFilteredHeader, width: 150, cellClass: 'number', sort: {
33 direction: uiGridConstants.ASC,
38 $scope.gridOptions.data = [];
40 var getUtilization = function(row) {
41 if (row.reserved === '?' || row.configured === '?' || row.reserved < 1) {
44 return (( row.configured / row.reserved ) * 100).toFixed(2);
47 var cleanProgess = function() {
56 var cleanMessage = function() {
66 var finish = function() {
67 $scope.message.endTime = new Date().toISOString();
68 $scope.message.duration = ((new Date($scope.message.endTime) - new Date($scope.message.startTime))/1000).toFixed(1) + 's';
69 $scope.gridOptions.columnDefs.filter(function(column){
70 return column.field === 'utilization';
71 }).map(function(column){
72 column.sort.direction = uiGridConstants.ASC;
73 $scope.gridApi.core.refresh();
75 $timeout(cleanProgess, 1000);
77 $scope.scan = function() {
79 $scope.progress.show = true;
80 $scope.message.startTime = new Date().toISOString();
82 $mwtnTdm.getMountPoints().then(function (mountpoints) {
83 $scope.gridOptions.data = [];
84 if (mountpoints.length === 0) {
85 $timeout(cleanProgess, 1000);
87 mountpoints.filter(function (mountpoint) {
88 return mountpoint['netconf-node-topology:connection-status'] === 'connected';
89 }).map(function (mountpoint) {
90 $mwtnTdm.getActualNetworkElement(mountpoint['node-id'], '2017-03-24').then(function (success) {
91 var onfNetworkElement = new OnfNetworkElement(success['network-element']);
92 var tdmLtps = onfNetworkElement.getLTPMwsList().filter(function (ltp) {
93 return ltp.getConditionalPackages()[0].contains('hybrid');
94 }).map(function (ltp) {
95 $scope.progress.max = $scope.progress.max + 1;
97 ltpId: [ltp.getId(), onfNetworkElement.getId()].join('@'),
98 nodeId: onfNetworkElement.getName(),
100 ltpRef: ltp.getLabel(),
107 nodeId: mountpoint['node-id'],
108 revision: '2017-03-24',
109 pacId: 'microwave-model:mw-hybrid-mw-structure-pac',
110 layerProtocolId: ltp.getLayerProtocols()[0].getId(),
111 partId: 'hybrid-mw-structure-configuration'
113 $mwtnTdm.getPacParts(specConfig).then(function(success){
114 success = $mwtnTdm.yangifyObject(success);
115 row.reserved = success['hybrid-mw-structure-configuration']['number-of-tdm-segments-to-be-reserved'];
116 row.utilization = getUtilization(row);
122 nodeId: mountpoint['node-id'],
123 revision: '2017-03-24',
124 pacId: 'microwave-model:mw-hybrid-mw-structure-pac',
125 layerProtocolId: ltp.getLayerProtocols()[0].getId(),
126 partId: 'hybrid-mw-structure-status'
128 $mwtnTdm.getPacParts(specStatus).then(function(success){
129 success = $mwtnTdm.yangifyObject(success);
130 row.configured = success['hybrid-mw-structure-status']['segment-status-list'].filter(function(item){
131 return item['segment-is-reserved-for-tdm'] === true;
133 row.utilization = getUtilization(row);
134 $scope.progress.value = $scope.progress.value + 1;
135 if ($scope.progress.max === $scope.progress.value) {
142 $scope.gridOptions.data.push(row);
144 console.warn(JSON.stringify(tdmLtps));
145 if (tdmLtps.length === 0 && $scope.progress.max === $scope.progress.value) {
149 }, function (error) {
150 $scope.gridOptions.data = [];