diff options
Diffstat (limited to 'demo-ui/app/controllers/MefController.js')
-rw-r--r-- | demo-ui/app/controllers/MefController.js | 117 |
1 files changed, 117 insertions, 0 deletions
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 |