blob: ce55be0d707b1077714fa376084f680dac763147 [file] [log] [blame]
rama-huaweic78f3092016-05-19 18:09:29 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
rama-huaweic78f3092016-05-19 18:09:29 +05303 *
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 sfc web gui overlay implementation.
19 */
20
21(function () {
22 'use strict';
23
24 // injected refs
25 var $log, fs, flash, wss, tds, ds, handlerMap = {};
26
27 // constants
28 var displayStart = 'sfcwebTopovDisplayStart',
29 showSfcInf = 'showSfcInfo',
30 clearMessage = 'sfcTopovClear',
Phaneendra Mandab212bc92016-07-08 16:50:11 +053031 configSfpMessage = 'configSfpMessage',
32 sfcPath = 'showSfcPath' ;
rama-huaweic78f3092016-05-19 18:09:29 +053033
34 // internal state
35 var currentMode = null;
Phaneendra Mandab212bc92016-07-08 16:50:11 +053036 var sfpInfo;
rama-huaweic78f3092016-05-19 18:09:29 +053037
38 // === Main API functions
39
40 function start() {
41 handlerMap[showSfcInf] = showSfcInformation;
Phaneendra Mandab212bc92016-07-08 16:50:11 +053042 handlerMap[sfcPath] = showSfcPath;
rama-huaweic78f3092016-05-19 18:09:29 +053043 wss.bindHandlers(handlerMap);
44 wss.sendEvent(displayStart);
45 }
46
Phaneendra Mandab212bc92016-07-08 16:50:11 +053047 function dOkSfp() {
48 var tdString;
49 var i = 0;
rama-huaweic78f3092016-05-19 18:09:29 +053050
Phaneendra Mandab212bc92016-07-08 16:50:11 +053051 sfpInfo.a.forEach( function () {
52 var sfpId = d3.select("#sfp-value-id-"+i).property("checked");
53 if (sfpId)
54 {
55 tdString = sfpInfo.a[i];
56 }
57 i++;
58 } );
59
60 if (!tdString) {
61 $log.debug("No SFP ID is selected.");
rama-huaweic78f3092016-05-19 18:09:29 +053062 }
63
rama-huaweic78f3092016-05-19 18:09:29 +053064 wss.sendEvent(configSfpMessage, {
Phaneendra Mandab212bc92016-07-08 16:50:11 +053065 id: tdString
rama-huaweic78f3092016-05-19 18:09:29 +053066 });
67
68 flash.flash('SFP ID query:');
69 }
70
71 function dClose() {
72 $log.debug('Dialog Close button clicked (or Esc pressed)');
73 }
74
Phaneendra Mandab212bc92016-07-08 16:50:11 +053075 function createUserTextSfp(data) {
76 console.log(data);
77
rama-huaweic78f3092016-05-19 18:09:29 +053078 var content = ds.createDiv();
79 var form = content.append('form');
80 var p = form.append('p');
Phaneendra Mandab212bc92016-07-08 16:50:11 +053081 var i = 0;
rama-huaweic78f3092016-05-19 18:09:29 +053082
Phaneendra Mandab212bc92016-07-08 16:50:11 +053083 p.append('span').text('SFP IDs');
rama-huaweic78f3092016-05-19 18:09:29 +053084 p.append('br');
Phaneendra Mandab212bc92016-07-08 16:50:11 +053085 sfpInfo = data;
86 data.a.forEach( function () {
87
88 p.append('input').attr({
89 id: 'sfp-value-id-'+i,
90 type: 'radio',
91 name: 'sfp-id-name',
92 value: data.a[i]
93 });
94
95 p.append('span').text(data.a[i]);
96 p.append('br');
97 i++;
98 } );
rama-huaweic78f3092016-05-19 18:09:29 +053099
100 return content;
101 }
102
Phaneendra Mandab212bc92016-07-08 16:50:11 +0530103 function showSfcInformation(data) {
rama-huaweic78f3092016-05-19 18:09:29 +0530104 tds.openDialog()
Phaneendra Mandab212bc92016-07-08 16:50:11 +0530105 .setTitle('List of active service functions')
106 .addContent(createUserTextSfp(data))
107 .addOk(dOkSfp, 'Select SFP ID')
108 .addCancel(dClose, 'Close')
109 .bindKeys();
110
rama-huaweic78f3092016-05-19 18:09:29 +0530111 }
112
Phaneendra Mandab212bc92016-07-08 16:50:11 +0530113 function createSfcPathText(data) {
rama-huaweic78f3092016-05-19 18:09:29 +0530114
Phaneendra Mandab212bc92016-07-08 16:50:11 +0530115 var content = ds.createDiv();
116 var form = content.append('form');
117 var p = form.append('p');
118 var i = 0;
rama-huaweic78f3092016-05-19 18:09:29 +0530119
Phaneendra Mandab212bc92016-07-08 16:50:11 +0530120 p.append('span').text('SFC Path');
121 p.append('br');
122 data.sfcPathList.forEach( function (val, idx) {
123 p.append('span').text(val);
124 p.append('br')
125 } );
rama-huaweic78f3092016-05-19 18:09:29 +0530126
Phaneendra Mandab212bc92016-07-08 16:50:11 +0530127 return content;
128 }
rama-huaweic78f3092016-05-19 18:09:29 +0530129
Phaneendra Mandab212bc92016-07-08 16:50:11 +0530130 function showSfcPath(data) {
131 tds.openDialog()
132 .setTitle('Service function path')
133 .addContent(createSfcPathText(data))
134 .addCancel(dClose, 'Close')
135 .bindKeys();
rama-huaweic78f3092016-05-19 18:09:29 +0530136 }
137
138 function clear() {
139 wss.sendEvent(clearMessage);
140 flash.flash('Cleared SFC overlay');
141 }
142
143 // === ---------------------------
144 // === Module Factory Definition
145 angular.module('ovSfcwebTopov', [])
146 .factory('SfcwebTopovDemoService',
147 ['$log', 'FnService', 'FlashService', 'WebSocketService', 'TopoDialogService', 'DialogService',
148 function (_$log_, _fs_, _flash_, _wss_, _tds_, _ds_) {
149 $log = _$log_;
150 fs = _fs_;
151 flash = _flash_;
152 wss = _wss_;
153 tds = _tds_;
154 ds = _ds_;
155 return {
156 start: start,
157 showSfcInformation: showSfcInformation,
Phaneendra Mandab212bc92016-07-08 16:50:11 +0530158 showSfcPath : showSfcPath,
159 clear: clear
rama-huaweic78f3092016-05-19 18:09:29 +0530160 };
161 }]);
162
163}());