rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | 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 Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 31 | configSfpMessage = 'configSfpMessage', |
| 32 | sfcPath = 'showSfcPath' ; |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 33 | |
| 34 | // internal state |
| 35 | var currentMode = null; |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 36 | var sfpInfo; |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 37 | |
| 38 | // === Main API functions |
| 39 | |
| 40 | function start() { |
| 41 | handlerMap[showSfcInf] = showSfcInformation; |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 42 | handlerMap[sfcPath] = showSfcPath; |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 43 | wss.bindHandlers(handlerMap); |
| 44 | wss.sendEvent(displayStart); |
| 45 | } |
| 46 | |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 47 | function dOkSfp() { |
| 48 | var tdString; |
| 49 | var i = 0; |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 50 | |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 51 | 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-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 62 | } |
| 63 | |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 64 | wss.sendEvent(configSfpMessage, { |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 65 | id: tdString |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 66 | }); |
| 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 Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 75 | function createUserTextSfp(data) { |
| 76 | console.log(data); |
| 77 | |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 78 | var content = ds.createDiv(); |
| 79 | var form = content.append('form'); |
| 80 | var p = form.append('p'); |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 81 | var i = 0; |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 82 | |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 83 | p.append('span').text('SFP IDs'); |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 84 | p.append('br'); |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 85 | 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-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 99 | |
| 100 | return content; |
| 101 | } |
| 102 | |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 103 | function showSfcInformation(data) { |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 104 | tds.openDialog() |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 105 | .setTitle('List of active service functions') |
| 106 | .addContent(createUserTextSfp(data)) |
| 107 | .addOk(dOkSfp, 'Select SFP ID') |
| 108 | .addCancel(dClose, 'Close') |
| 109 | .bindKeys(); |
| 110 | |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 111 | } |
| 112 | |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 113 | function createSfcPathText(data) { |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 114 | |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 115 | var content = ds.createDiv(); |
| 116 | var form = content.append('form'); |
| 117 | var p = form.append('p'); |
| 118 | var i = 0; |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 119 | |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 120 | 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-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 126 | |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 127 | return content; |
| 128 | } |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 129 | |
Phaneendra Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 130 | function showSfcPath(data) { |
| 131 | tds.openDialog() |
| 132 | .setTitle('Service function path') |
| 133 | .addContent(createSfcPathText(data)) |
| 134 | .addCancel(dClose, 'Close') |
| 135 | .bindKeys(); |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 136 | } |
| 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 Manda | 2360d25 | 2016-06-15 18:53:30 +0530 | [diff] [blame^] | 158 | showSfcPath : showSfcPath, |
| 159 | clear: clear |
rama-huawei | 4ecc6a7 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 160 | }; |
| 161 | }]); |
| 162 | |
| 163 | }()); |