aboutsummaryrefslogtreecommitdiffstats
path: root/demo-ui/app/controllers/MefController.js
blob: 9531b495a7e81cf1cbba7ada30f971a4c0303b7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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);

}());