From e8a4652f70284c414ceafc086669dfd4b935573d Mon Sep 17 00:00:00 2001 From: Steven Saunders Date: Wed, 12 Aug 2015 08:48:07 -0600 Subject: Add demo-ui folder. This folder contains HTML/CSS/Javascript code for the VCPE Demo UI. The Demo UI allows you to CRUD CoS instances, and EPL instances, and will also display information about EVCs and UNIs that were created as well Change-Id: I32eea1121c21e0b451efc057a0c0f30fe5601cd5 Signed-off-by: Steven Saunders --- demo-ui/app/controllers/CosController.js | 381 +++++++++++++++++++++ demo-ui/app/controllers/EplController.js | 528 ++++++++++++++++++++++++++++++ demo-ui/app/controllers/MainController.js | 31 ++ demo-ui/app/controllers/MefController.js | 117 +++++++ 4 files changed, 1057 insertions(+) create mode 100644 demo-ui/app/controllers/CosController.js create mode 100644 demo-ui/app/controllers/EplController.js create mode 100644 demo-ui/app/controllers/MainController.js create mode 100644 demo-ui/app/controllers/MefController.js (limited to 'demo-ui/app/controllers') diff --git a/demo-ui/app/controllers/CosController.js b/demo-ui/app/controllers/CosController.js new file mode 100644 index 0000000..523f3c1 --- /dev/null +++ b/demo-ui/app/controllers/CosController.js @@ -0,0 +1,381 @@ +(function() { + +var CosController = function($scope, $http, $interval, $log, cosServices, model, dbg ) { + + // + // Controller Set Up + // + + dbg.p("---> in CosController()"); + + actionState = { + IDLE : 1, ADD : 2, UPDATE : 3, DEL : 4 + } + + // $scope variables + $scope.cosList = null; + $scope.selectedCosIdx = -1; + $scope.cosToEdit = null; + $scope.cosActionButtonText = "unset"; + + $scope.availableBWs = [ + { + name : "10M", + cir : 10000 + }, + { + name : "100M", + cir : 100000 + }, + { + name : "1G", + cir : 1000000 + }, + { + name : "10G", + cir : 10000000 + }, + ]; + + dbg.p("bandwidths avaialble:") + dbg.pj($scope.availableBWs); + + // congroller variables + var cosActionState = actionState.IDLE; + var newCos = null; + var uniqueId = true; + var nameNum = 1; + + + // cos constructor + var Cos = function(){ + if ( uniqueId ) + this.id = "new"+ nameNum; + else + this.id = "new"; + this.commitedInfoRate = 50; + this.availbility = 95.5; + this.frameDelay = 2.2; + this.jitter = 3.3; + this.frameLoss = 4.4 ; + } + + // + // utility fxns + // + + var validCosIdx = function(idx) { + return ( idx >= 0 && idx < $scope.cosList.length ) + } + + var cosIdxReset = function() { + return ( $scope.cosList.length > 0 ? 0 : -1); + } + + var cosIdxAfter = function( action ) { + switch ( action ) { + case actionState.DEL: + if ( validCosIdx($scope.selectedCosIdx) ) + return $scope.selectedCosIdx; + else if ( validCosIdx($scope.selectedCosIdx-1) ) + return $scope.selectedCosIdx-1; + else + return cosIdxReset(); + break; + case actionState.ADD: + return ( $scope.cosList.length >= 0 ? + $scope.cosList.length-1 : cosIdxReset() ); + break; + case actionState.UPDATE: + return ( validCosIdx($scope.selectedCosIdx) ? + $scope.selectedCosIdx : cosIdxReset() ); + break; + default: + dbg.e("invalid action state"); + break; + } + } + + $scope.cosExists = function(cosId) { + var nameCheck = function (cosElm) { return cosElm.id == cosId; } + return ( $scope.cosList && + $scope.cosList.filter(nameCheck).length > 0 ); + } + + $scope.bwText = function(cos) { + if (cos) { + switch ( cos.commitedInfoRate ) { + case 10000 : return "10M"; + case 100000 : return "100M"; + case 1000000 : return "1G"; + case 10000000 : return "10G"; + } + return "invalid BW"; + } + else { + return "null cos"; + } + } + + // return index of avilable BW based cir (-1 if not found) + var availableBwIdx = function (cir) { + for ( var i = 0; i < $scope.availableBWs.length; i++ ) { + if ($scope.availableBWs[i].cir == cir) { + return i; + } + } + return -1; + } + + // return index of cos in current list (-1 if not found) + var cosNameToIdx = function ( cosName ) { + if ( !cosName || !$scope.cosList ) + return -1; + + for ( var i = 0; i < $scope.cosList.length; i++ ) { + if ($scope.cosList[i].id == cosName ) { + return i; + } + } + return -1; + } + + // + // HTTP Repsponse Handlers + // + + var onRequestError = function(reason){ + dbg.e("HTTP Request Problem\n" + JSON.stringify(reason)); + }; + var onCosListResp = function(data) { + dbg.p("in onCosListResp()"); + $scope.cosList = data; + + if ( $scope.cosList && $scope.cosList.length > 0 ) + $scope.selectedCosIdx = 0; + else + $scope.selectedCosIdx = -1; + + dbg.p("selectedCosIdx = " + $scope.selectedCosIdx,1); + }; + var onCosCreateResp = function(data) { + dbg.p("in onCosCreateResp()"); + dbg.p("following cos returned from create cmd", 1); + dbg.pj(data); + $scope.cosList.push(newCos); + $scope.selectedCosIdx = cosIdxAfter(actionState.ADD); + nameNum++; + newCos = null; + $scope.cosToEdit = null; + dbg.p("selectedCosIdx = " + $scope.selectedCosIdx,1); + }; + var onCosUpdateResp = function(data) { + dbg.p("in onCosUpdateResp()"); + dbg.p("following cos returned after update", 1); + dbg.pj(data); + $scope.selectedCosIdx = cosIdxAfter(actionState.UPDATE); + $scope.cosToEdit = null; + dbg.p("selectedCosIdx = " + $scope.selectedCosIdx,1); + }; + var onCosDeleteResp = function(data) { + dbg.p("in onCosDeleteResp()"); + dbg.p("following returned after delete", 1); + dbg.pj(data); + if ( validCosIdx($scope.selectedCosIdx) ) + $scope.cosList.splice($scope.selectedCosIdx,1); + $scope.selectedCosIdx = cosIdxAfter(actionState.DEL); + dbg.p("selectedCosIdx = " + $scope.selectedCosIdx,1); + }; + + // + // CoS Event Handlers & Utils + // + + $scope.onCosClick = function (i) { + dbg.p("in onCosClick(): clicked ("+i+")"); + $scope.selectedCosIdx = i; + cosActionState = actionState.IDLE; + dbg.p("selectedCosIdx = "+ $scope.selectedCosIdx,1); + } + $scope.onAddCos = function () { + dbg.p("in onAddCos()"); + cosActionState = actionState.ADD; + $scope.cosActionButtonText = "Create"; + newCos = new Cos(); + $scope.cosToEdit = newCos; + + if ($scope.availableBWs.length >=3 ) + $scope.cosToEdit.bwSelected = $scope.availableBWs[2]; + else + $scope.cosToEdit.bwSelected = $scope.availableBWs[0]; + + dbg.pj(newCos); + } + $scope.onUpdateCos = function () { + dbg.p("in onUpdateCos()"); + if ( $scope.cosList.length <= 0 ) + { + dbg.p("nos CoS's exist, no action being taken"); + return; + } + cosActionState = actionState.UPDATE; + $scope.cosActionButtonText = "Update"; + $scope.cosToEdit = $scope.cosList[$scope.selectedCosIdx]; + + dbg.p("looking for dd list bw: " + $scope.cosToEdit.commitedInfoRate); + var availBwIdx = availableBwIdx($scope.cosToEdit.commitedInfoRate); + if ( availBwIdx < 0 || availBwIdx > $scope.availableBWs.length-1 ) { + dbg.e("invalid selected BW idx: "+availBwIdx+"(setting to 0)"); + $scope.cosToEdit.bwSelected = $scope.availableBWs[0]; + } + else { + $scope.cosToEdit.bwSelected = $scope.availableBWs[availBwIdx]; + } + + dbg.p("about to edit cos:"); + dbg.pj($scope.cosToEdit); + + + } + $scope.onDelCos = function () { + dbg.p("in onDelCos()"); + if ( $scope.cosList.length <= 0 ) + { + dbg.p("nos CoS's exist, no action being taken"); + return; + } + cosActionState = actionState.DEL; + $scope.cosActionButtonText = "Delete"; + } + + $scope.onCosInputSubmit = function () { + dbg.p("in onCosInputSubmit()"); + + var cosToOperateOn = null; + if ( cosActionState === actionState.ADD) + cosToOperateOn = newCos; + else + cosToOperateOn = $scope.cosList[$scope.selectedCosIdx]; + + switch(cosActionState) { + + case actionState.DEL: + dbg.p("about to delete " + cosToOperateOn.id,1); + cosServices.deleteCos(cosToOperateOn) + .then(onCosDeleteResp, onRequestError); + break; + + case actionState.ADD: + cosToOperateOn.commitedInfoRate = cosToOperateOn.bwSelected.cir; + delete cosToOperateOn.bwSelected; + dbg.p("about to add " + cosToOperateOn.id, 1); + cosServices.createCos(cosToOperateOn) + .then(onCosCreateResp, onRequestError); + break; + + case actionState.UPDATE: + cosToOperateOn.commitedInfoRate = cosToOperateOn.bwSelected.cir; + delete cosToOperateOn.bwSelected; + dbg.p("about to update " + cosToOperateOn.id, 1); + cosServices.updateCos(cosToOperateOn) + .then(onCosUpdateResp, onRequestError); + break; + + default: + dbg.e("invalid action state"); + break; + } + + cosActionState = actionState.IDLE; + } + + // + // State query fxns + // + + $scope.cosActionInProgress = function () { + return ( cosActionState != actionState.IDLE ) + } + $scope.cosEditInProgress = function () { + return ( cosActionState === actionState.ADD || + cosActionState === actionState.UPDATE ); + } + $scope.cosUpdateInProgress = function () { + return ( cosActionState === actionState.UPDATE ); + } + $scope.cosAddInProgress = function () { + return ( cosActionState === actionState.ADD ); + } + $scope.cosDelInProgress = function () { + return ( cosActionState === actionState.DEL ); + } + $scope.cosNameConflict = function () { + return ( $scope.cosAddInProgress() && + $scope.cosExists($scope.cosToEdit.id)); + } + $scope.showCosInputs = function () { + return $scope.cosEditInProgress(); + } + $scope.showCosValues = function () { + return (!$scope.showCosInputs() && + validCosIdx($scope.selectedCosIdx)); + } + $scope.showCosNameInput = function () { + return $scope.cosAddInProgress(); + } + $scope.showCosName = function () { + return (! $scope.showCosNameInput()); + } + $scope.showCosActionButton = function () { + return ( $scope.cosAddInProgress() || + ($scope.cosActionInProgress() && + $scope.cosList.length > 0 )); + } + $scope.activateCosActionButton = function () { + return ( $scope.cosActionInProgress() && + !$scope.cosNameConflict() ) + } + + // + // Watchers + // + + // we can't get our initial CoS list until + // the URL has been set by config file read in + cosUrlWatcher = function () { return cosServices.getCosUrl(); } + onCosUrlChange = function (newCosUrl, oldCosUrl) { + if (newCosUrl !== oldCosUrl) { + dbg.p("detected cos url change, getting cos list"); + cosServices.getCosList() + .then(onCosListResp, onRequestError); + } + } + $scope.$watch( cosUrlWatcher, onCosUrlChange ); + + // Watch for change in selected EPL so tht + // we can set the appropraite CoS as selected + eplWatcher = function () { return model.getCurrentEpl(); } + onEplChange = function (newEpl, oldEpl) { + dbg.p("in CosController:onEplChange"); + //dbg.p("oldEpl:"); dbg.pj(oldEpl); + //dbg.p("newEpl:"); dbg.pj(newEpl); + + // only make a chance if we have an + if ( newEpl ) { + var cosIdx = cosNameToIdx(newEpl.cos); + dbg.p("changing selected CoS to: " + newEpl.cos + + " [idx="+cosIdx+"]", 1); + if ( validCosIdx(cosIdx) ) { + cosActionState = actionState.IDLE + $scope.selectedCosIdx = cosIdx; + } + } + } + $scope.$watch( eplWatcher, onEplChange ); + +}; + +// register controller in the module +app.controller("CosController", CosController); + +}()); \ No newline at end of file diff --git a/demo-ui/app/controllers/EplController.js b/demo-ui/app/controllers/EplController.js new file mode 100644 index 0000000..8dbdc90 --- /dev/null +++ b/demo-ui/app/controllers/EplController.js @@ -0,0 +1,528 @@ +(function() { + +var EplController = function($scope, $http, $interval, $log, + eplServices, cosServices, model, dbg ) { + + // + // Controller Set Up + // + // + + dbg.p("---> in EplController()"); + + actionState = { + IDLE : 1, ADD : 2, UPDATE : 3, DEL : 4 + }; + + // $scope variables + $scope.eplList = []; + $scope.selectedEplIdx = -1; + $scope.eplToEdit = null; + $scope.eplActionButtonText = "unset"; + $scope.availableUnis = []; + $scope.availableCosIds = []; + + // for trouble shooting + $scope.availableCosIds.push("unset cos 0"); + $scope.availableCosIds.push("unset cos 1"); + $scope.availableCosIds.push("unset cos 2"); + + // controller variables + var _uniqueId = true; + var _nameNum = 1; + var _eplActionState = actionState.IDLE; + var _newEpl = null; + + // start out with null until we do list query) + model.setCurrentEpl(null); + + // + // utility fxns + // + + var validEplIdx = function(idx) { + return ( idx >= 0 && idx < $scope.eplList.length ) + } + var eplIdxReset = function() { + return ( $scope.eplList.length > 0 ? 0 : -1); + } + var cosIdxReset = function() { + return ( $scope.eplList.length > 0 ? 0 : -1); + } + var eplIdxAfter = function( action ) { + switch ( action ) { + case actionState.DEL: + if ( validEplIdx($scope.selectedEplIdx) ) + return $scope.selectedEplIdx; + else if ( validEplIdx($scope.selectedEplIdx-1) ) + return $scope.selectedEplIdx-1; + else + return eplIdxReset(); + break; + case actionState.ADD: + return ( $scope.eplList.length >= 0 ? + $scope.eplList.length-1 : eplIdxReset() ); + break; + case actionState.UPDATE: + return ( validEplIdx($scope.selectedEplIdx) ? + $scope.selectedEplIdx : eplIdxReset() ); + break; + default: + dbg.e("invalid action state"); + return -1; + break; + } + } + $scope.eplExists = function(eplId) { + var nameCheck = function (eplElm) { return eplElm.id == eplId; } + return ( $scope.eplList && + $scope.eplList.filter(nameCheck).length > 0 ); + } + var setEplUniInfo = function(epl, uniIdx1, uniIdx2) { + + if ( $scope.availableUnis.length < 2 ) { + dbg.e("Can't set unis in constructor, avaulable uni list too short") + return; + } + + epl.numCustLocations = 2; + + if ( uniIdx1 < 0 || uniIdx1 > 1) { + epl.uniHostIpList.push($scope.availableUnis[0].ip); + epl.uniHostMacList.push($scope.availableUnis[0].mac); + epl.custAddressList.push($scope.availableUnis[0].address); + } + else { + epl.uniHostIpList.push($scope.availableUnis[uniIdx1].ip); + epl.uniHostMacList.push($scope.availableUnis[uniIdx1].mac); + epl.custAddressList.push($scope.availableUnis[uniIdx1].address); + } + + if ( uniIdx2 < 0 || uniIdx2 > 1) { + epl.uniHostIpList.push($scope.availableUnis[0].ip); + epl.uniHostMacList.push($scope.availableUnis[0].mac); + epl.custAddressList.push($scope.availableUnis[0].address); + } + else { + epl.uniHostIpList.push($scope.availableUnis[uniIdx2].ip); + epl.uniHostMacList.push($scope.availableUnis[uniIdx2].mac); + epl.custAddressList.push($scope.availableUnis[uniIdx2].address); + } + } + + // return index of avilable Uni based on IP (-1 if not found) + var availableUniIdx = function (uniIp) { + for ( var i = 0; i < $scope.availableUnis.length; i++ ) { + if ($scope.availableUnis[i].ip == uniIp) { + return i; + } + } + return -1; + } + + var updateEplWithSelectedUnis = function(epl) { + + if ( epl == null || $scope.eplToEdit == null ) { + dbg.e("can't update EPL with UNIS, missing object"); + return + } + + epl.uniHostIpList = []; + epl.uniHostIpList.push($scope.eplToEdit.uni1Selected.ip); + epl.uniHostIpList.push($scope.eplToEdit.uni2Selected.ip); + + epl.uniHostMacList = []; + epl.uniHostMacList.push($scope.eplToEdit.uni1Selected.mac); + epl.uniHostMacList.push($scope.eplToEdit.uni2Selected.mac); + + epl.custAddressList = []; + epl.custAddressList.push($scope.eplToEdit.uni1Selected.address); + epl.custAddressList.push($scope.eplToEdit.uni2Selected.address); + } + + // + // epl constructor + // + + var Epl = function(){ + dbg.pj("constructing EPL"); + if ( _uniqueId ) + this.id = "new"+ _nameNum; + else + this.id = "new"; + + // Don't set COS here, we have to wait until we get the latest cos list + this.cos = "unset"; + + // EVC ID set by lower layers + // TODO : how does evc ID cat capture at EPL layer?? + this.evcId = "unset"; + + this.uniHostIpList = []; + this.uniHostMacList = []; + this.custAddressList = []; + + if ( $scope.availableUnis.length >= 2 ) + setEplUniInfo(this, 0, 1); + else { + dbg.e("can't construct EPL, not enough uni's in the available uni list"); + return; + } + + dbg.pj(this); + } + + var copyReturnedEplParams = function(srcEpl, destEpl ) { + destEpl.evcId = srcEpl.evcId; + } + + var setModalActiveEpl =function () { + if ( $scope.selectedEplIdx >= 0 && + $scope.selectedEplIdx < $scope.eplList.length ) + { + model.setCurrentEpl($scope.eplList[$scope.selectedEplIdx]); + } + else + { + model.setCurrentEpl(null); + } + } + + // + // EPL HTTP Response Handlers + // + + var onRequestError = function(reason){ + dbg.e("HTTP Request Problem\n" + JSON.stringify(reason)); + }; + + var onEplListResp = function(data) { + dbg.p("in onEplListResp()"); + $scope.eplList = data; + + if ( $scope.eplList && $scope.eplList.length > 0 ) { + $scope.selectedEplIdx = 0; + model.setCurrentEpl($scope.eplList[$scope.selectedEplIdx]); + dbg.p("selectedEplIdx/Id = "+ $scope.selectedEplIdx + "/" + + $scope.eplList[$scope.selectedEplIdx].id, 1); + } + else { + $scope.selectedEplIdx = -1; + model.setCurrentEpl(null); + dbg.p("selectedEplIdx = "+ $scope.selectedEplIdx, 1); + } + _eplActionState = actionState.IDLE; + }; + var onEplCreateResp = function(returnedEpl) { + dbg.p("in onEplCreateResp()"); + dbg.p("following epl returned from create cmd", 1); + dbg.pj(returnedEpl); + + // grab entire returned Epl, since we don't know what + // the svcmgr may have changed on creation + $scope.eplList.push(returnedEpl); + + // a safer alternative? + //copyReturnedEplParams(returnedEpl, _newEpl ); + //$scope.eplList.push(_newEpl); + + $scope.selectedEplIdx = eplIdxAfter(actionState.ADD); + setModalActiveEpl(); + + _nameNum++; + _newEpl = null; + $scope.eplToEdit = null; + dbg.p("selectedEplIdx = " + $scope.selectedEplIdx,1); + }; + var onEplUpdateResp = function(returnedEpl) { + dbg.p("in onEplUpdateResp()"); + dbg.p("following epl returned after update", 1); + dbg.pj(returnedEpl); + + // splice in entire returned Epl, since we don't know what + // the svcmgr may have changed on update (esp evc) + $scope.eplList[$scope.selectedEplIdx] = returnedEpl; + + // a safer alternative? + // copyReturnedEplParams(returnedEpl, eplToEdit ); + + + + $scope.selectedEplIdx = eplIdxAfter(actionState.UPDATE); + + // To force a refresh + model.setCurrentEpl(null); + setModalActiveEpl(); + + $scope.eplToEdit = null; + dbg.p("selectedEplIdx = " + $scope.selectedEplIdx,1); + }; + var onEplDeleteResp = function(data) { + dbg.p("in onEplDeleteResp()"); + dbg.p("following returned after delete", 1); + dbg.pj(data); + if ( validEplIdx($scope.selectedEplIdx) ) + $scope.eplList.splice($scope.selectedEplIdx,1); + $scope.selectedEplIdx = eplIdxAfter(actionState.DEL); + setModalActiveEpl(); + dbg.p("selectedEplIdx = " + $scope.selectedEplIdx,1); + }; + + // + // Epl Event Handlers + // + + $scope.onEplClick = function (i) { + dbg.p("in onEplClick(): clicked ("+i+")"); + $scope.selectedEplIdx = i; + _eplActionState = actionState.IDLE; + eplToOperateOn = $scope.eplList[$scope.selectedEplIdx] + model.setCurrentEpl(eplToOperateOn); + dbg.p("selectedEplIdx/Id = "+ $scope.selectedEplIdx + "/" + + eplToOperateOn.id, 1); + } + $scope.onAddEpl = function () { + dbg.p("in onAddEpl()"); + _eplActionState = actionState.ADD; + $scope.eplActionButtonText = "Create"; + + var updateEplToAddOnCosListResponse = function(data) { + dbg.p("in updateNewEplCosOnCosListResponse()", 1); + var cosList = data; + + $scope.availableCosIds = []; + for ( var i = 0; i < cosList.length; i++ ) + $scope.availableCosIds.push(cosList[i].id); + + dbg.p("Avilable CoS List"); + dbg.pj($scope.availableCosIds); + + // defaults for drop down lists + if ( $scope.availableCosIds.length > 0 ) + $scope.eplToEdit.cos = $scope.availableCosIds[0]; + + $scope.eplToEdit.uni1Selected = $scope.availableUnis[0]; + $scope.eplToEdit.uni2Selected = $scope.availableUnis[1]; + + dbg.p("Newly created EPL to add after CoS list retrieved"); + dbg.pj($scope.eplToEdit); + }; + + _newEpl = new Epl(); + $scope.eplToEdit = _newEpl; + + // need to get the current cos list before adding new EPL + cosServices.getCosList() + .then(updateEplToAddOnCosListResponse, + onRequestError); + } + $scope.onUpdateEpl = function () { + dbg.p("in onUpdateEpl()"); + if ( $scope.eplList.length <= 0 ) + { + dbg.p("nos Epl's exist, no action being taken"); + return; + } + _eplActionState = actionState.UPDATE; + $scope.eplActionButtonText = "Update"; + + var updateEplToEditOnCosListResponse = function(data) { + dbg.p("in onCosListResp()"); + var cosList = data; + $scope.availableCosIds = []; + for ( var i = 0; i < cosList.length; i++ ) + $scope.availableCosIds.push(cosList[i].id); + dbg.p("Avilable CoS List"); + dbg.pj($scope.availableCosIds); + + $scope.eplToEdit = $scope.eplList[$scope.selectedEplIdx]; + + // TODO (if time): put below stuff in fxn since duplicated twice + dbg.p("looking for dd list ip: " + $scope.eplToEdit.uniHostIpList[0] ); + var availUniIdx = availableUniIdx($scope.eplToEdit.uniHostIpList[0]); + if ( availUniIdx < 0 || availUniIdx > $scope.availableUnis.length-1 ) { + dbg.e("invalid selected uni-1 idx: "+availUniIdx+"(setting to 0)"); + $scope.eplToEdit.uni1Selected = $scope.availableUnis[0]; + } + else { + $scope.eplToEdit.uni1Selected = $scope.availableUnis[availUniIdx]; + } + + dbg.p("looking for dd list ip: " + $scope.eplToEdit.uniHostIpList[1] ); + availUniIdx = availableUniIdx($scope.eplToEdit.uniHostIpList[1]); + if ( availUniIdx < 0 || availUniIdx > $scope.availableUnis.length-1 ) { + dbg.e("invalid selected uni-2 idx: "+availUniIdx+"(setting to 0)"); + $scope.eplToEdit.uni2Selected = $scope.availableUnis[0] + } + else { + $scope.eplToEdit.uni2Selected = $scope.availableUnis[availUniIdx]; + } + + dbg.p("about to edit epl:"); + dbg.pj($scope.eplToEdit); + }; + + // need to get the current cos list before editing + cosServices.getCosList() + .then(updateEplToEditOnCosListResponse, + onRequestError); + } + + $scope.onDelEpl = function () { + dbg.p("in onDelEpl()"); + if ( $scope.eplList.length <= 0 ) + { + dbg.p("nos Epl's exist, no action being taken"); + return; + } + _eplActionState = actionState.DEL; + $scope.eplActionButtonText = "Delete"; + } + + $scope.onEplInputSubmit = function () { + dbg.p("in onEplInputSubmit()"); + + var eplToOperateOn = null; + if ( _eplActionState === actionState.ADD) + eplToOperateOn = _newEpl; + else + eplToOperateOn = $scope.eplList[$scope.selectedEplIdx]; + + switch(_eplActionState) { + + case actionState.DEL: + + dbg.p("about to delete " + eplToOperateOn.id,1); + eplServices.deleteEpl(eplToOperateOn) + .then(onEplDeleteResp, onRequestError); + break; + + case actionState.ADD: + + updateEplWithSelectedUnis(eplToOperateOn); + + delete $scope.eplToEdit.uni1Selected; + delete $scope.eplToEdit.uni2Selected; + + dbg.p("about to add " + eplToOperateOn.id, 1); + dbg.pj(eplToOperateOn); + eplServices.createEpl(eplToOperateOn) + .then(onEplCreateResp, onRequestError); + break; + + case actionState.UPDATE: + + updateEplWithSelectedUnis(eplToOperateOn); + + delete $scope.eplToEdit.uni1Selected; + delete $scope.eplToEdit.uni2Selected; + + dbg.p("about to update " + eplToOperateOn.id, 1); + eplServices.updateEpl(eplToOperateOn) + .then(onEplUpdateResp, onRequestError); + break; + + default: + dbg.e("invalid action state"); + break; + } + + _eplActionState = actionState.IDLE; + } + + // + // State query fxns + // + + $scope.eplActionInProgress = function () { + return ( _eplActionState != actionState.IDLE ) + } + $scope.eplEditInProgress = function () { + return ( _eplActionState === actionState.ADD || + _eplActionState === actionState.UPDATE ); + } + $scope.eplUpdateInProgress = function () { + return ( _eplActionState === actionState.UPDATE ); + } + $scope.eplAddInProgress = function () { + return ( _eplActionState === actionState.ADD ); + } + $scope.eplDelInProgress = function () { + return ( _eplActionState === actionState.DEL ); + } + $scope.cosExists = function () { + return ( $scope.availableCosIds && + $scope.availableCosIds.length > 0 ); + } + $scope.cosConflict = function () { + return ( $scope.eplAddInProgress() && + !$scope.cosExists() ); + } + $scope.eplNameConflict = function () { + return ( $scope.eplAddInProgress() && + $scope.eplExists($scope.eplToEdit.id)); + } + $scope.uniConflict = function () { + return ( $scope.eplToEdit && + $scope.eplToEdit.uni1Selected && + $scope.eplToEdit.uni2Selected && + $scope.eplEditInProgress() && + ( $scope.eplToEdit.uni1Selected.ip == + $scope.eplToEdit.uni2Selected.ip )); + } + $scope.showEplInputs = function () { + return $scope.eplEditInProgress(); + } + $scope.showEplValues = function () { + return (!$scope.showEplInputs() && + validEplIdx($scope.selectedEplIdx)); + } + $scope.showEplNameInput = function () { + return $scope.eplAddInProgress(); + } + $scope.showEplName = function () { + return (! $scope.showEplNameInput()); + } + $scope.showEplActionButton = function () { + return ( $scope.eplAddInProgress() || + ($scope.eplActionInProgress() && + $scope.eplList.length > 0 )); + } + $scope.activateEplActionButton = function () { + return ( $scope.eplActionInProgress() && + !$scope.eplNameConflict() && + !$scope.uniConflict() && + !$scope.cosConflict() ) + } + + // + // Initial Page Set Up + // + + eplUrlWatcher = function () { return eplServices.getEplUrl(); } + onEplUrlChange = function (newEplUrl, oldEplUrl) { + if (newEplUrl !== oldEplUrl) { + dbg.p("detected epl url change, getting epl list"); + eplServices.getEplList() + .then(onEplListResp, onRequestError); + } + } + $scope.$watch( eplUrlWatcher, onEplUrlChange ); + + + uniListWatcher = function () { return model.getAvailableUnis(); } + onUniListChange = function (newUniList, oldUniList) { + if (newUniList !== oldUniList) { + dbg.p("detected uni list change") + dbg.p("new avilable uni list:") + $scope.availableUnis = newUniList; + dbg.pj($scope.availableUnis); + } + } + $scope.$watch( uniListWatcher, onUniListChange ); +}; + +// register controller in the module +app.controller("EplController", EplController); + +}()); \ No newline at end of file diff --git a/demo-ui/app/controllers/MainController.js b/demo-ui/app/controllers/MainController.js new file mode 100644 index 0000000..199048b --- /dev/null +++ b/demo-ui/app/controllers/MainController.js @@ -0,0 +1,31 @@ +// Create our module +var app = angular.module("vcpe", []); + +(function() { +var MainController = function($http, $log, cosServices, eplServices, mefServices, model, dbg ) { + + dbg.p("---> in MainController()"); + + // config our app + var cfgFile = "../config.json"; + $http.get(cfgFile). + success(function(data) { + dbg.p("in cfgFile read callback"); + dbg.p("incoming data"); + dbg.pj(data); + cosServices.setCosUrl(data.cosMgr); + eplServices.setEplUrl(data.eplMgr); + mefServices.setEvcUrl(data.evcMgr); + mefServices.setUniUrl(data.uniMgr); + mefServices.setEvcPathUrl(data.evcPathMgr); + model.setAvailableUnis(data.uniList); + }). + error(function() { + dbg.e("Could not read " + cfgFile); + }); +}; + +// register controller in the module +app.controller("MainController", MainController); + +}()); \ No newline at end of file diff --git a/demo-ui/app/controllers/MefController.js b/demo-ui/app/controllers/MefController.js new file mode 100644 index 0000000..9531b49 --- /dev/null +++ b/demo-ui/app/controllers/MefController.js @@ -0,0 +1,117 @@ +(function() { + +var MefController = function($scope, $log, mefServices, model, dbg ) { + + // + // Controller Set Up + // + + dbg.p("---> in MefController()"); + $scope.currentEpl = null; + $scope.currentEplEvc = null; + $scope.currentEvcUnis = []; + + // + // Utils + // + + $scope.curEplEvcToJson = function () { + return angular.toJson($scope.currentEplEvc, true); + }; + + + $scope.uniToSpeedString = function(uni) { + if (uni) { + speed = uni.uni[0].speed; + return Object.getOwnPropertyNames(speed)[0];s + } + else + return ""; + } + // + // HTTP Response Handlers + // + + var onRequestError = function(reason){ + dbg.e("HTTP Request Problem\n" + JSON.stringify(reason)); + }; + + + var onUniGetResp = function(data) { + dbg.p("in onUniGetResp()"); + dbg.pj(data); + + // dbg.p("current EVC UNI list before adding"); + //oSpeedString($scop dbg.pj($scope.currentEvcUnis); + + $scope.currentEvcUnis.push(data); + + // dbg.p("current EVC UNI list after adding"); + // dbg.pj($scope.currentEvcUnis); + } + + var onEvcGetResp = function(data) { + dbg.p("in onEvcGetResp()"); + dbg.pj(data); + $scope.currentEplEvc = data; + + // out with the old unis + $scope.currentEvcUnis = []; + + // in with the new unis + mefServices.getUni($scope.currentEplEvc.uniIdList[0]) + .then(onUniGetResp, onRequestError); + mefServices.getUni($scope.currentEplEvc.uniIdList[1]) + .then(onUniGetResp, onRequestError); + }; + + // + // State query fxns + // + + $scope.showEvcValues = function () { + return ( $scope.currentEplEvc != null ); + } + + $scope.showUniValues = function () { + return ( $scope.currentEvcUnis != null ); + } + + // + // Watch for change in selected EPL so tht we can + // update the corresponding EVC info + // + + eplWatcher = function () { return model.getCurrentEpl(); } + onEplChange = function (newEpl, oldEpl) { + dbg.p("in MefController:onEplChange"); + // dbg.p("oldEpl:"); dbg.pj(oldEpl); + // dbg.p("newEpl:"); dbg.pj(newEpl); + + // only make a chance if we have a new EPL object + if ( newEpl ) { + var newEplId = newEpl.id; + var oldEplId = "null"; + if (oldEpl) oldId = oldEpl.id + + dbg.p("detected selected EPL change from " + + oldEplId + " to " + newEplId, 1); + $scope.currentEpl = newEpl; + + // get the EVC info + mefServices.getEvc($scope.currentEpl.evcId) + .then(onEvcGetResp, onRequestError); + } + else { + $scope.currentEplEvc = null; + $scope.currentEvcUnis = null; + } + + } + $scope.$watch( eplWatcher, onEplChange ); +}; + +// register controller in the module +app.controller("MefController", MefController); + +}()); \ No newline at end of file -- cgit 1.2.3-korg