File size: 3,573 Bytes
27867f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
$(document).ready(setTimeout(function(){
    var tunerstatus = {}
    var schedstatus = []
    var expire = 0

    function getDashboardStatus(){
        return $.getJSON("/api/dashstatus.json").then(function(json){
            return json;
        });
    }

    function populateDashboard() {
        getDashboardStatus().then(function(json_dashboard) {
            tunerstatus = json_dashboard['tunerstatus']
            schedstatus = json_dashboard['schedstatus']
            tuner_active = populateTuner(tunerstatus);
            sched_active = populateSchedule(schedstatus);
            if ( tuner_active || sched_active ) {
                expire = 1000;
            } else if (expire < 30000) {
                expire = expire + 3000;
            }
            setTimeout(function(){
                if($("#dashboard").length !== 0) {
                    populateDashboard();
                }
            }, expire);
        });
    }

    function populateTuner(tuner_data) {
        $('#dashboard').html('<h3 style="margin:0;">Tuner Status</h3><table id="tuners" ></table>');
        $('#tuners').append('<thead><tr><th class="header" style="min-width: 10ch;">State</th>'
            + '<th class="header" style="min-width: 10ch;">Plugin</th>'
            + '<th class="header" style="min-width: 7ch;">Tuner</th>'
            + '<th class="header" style="min-width: 10ch;">Instance</th>'
            + '<th class="header" style="min-width: 7ch;">Channel</th>'
            + '<th class="header" style="min-width: 7ch;">Clients</th></thead>'
            );
        var active = false;
        if ( tuner_data === null ) {
            $('#tuners').append('<tr><td colspan=5>Tuner Status is Down, check 5004 process</td></tr>');
        } else {
            $.each(tuner_data, function(key1, list_value) {
                if(list_value !== null) {
                    if (typeof list_value === 'object' ) {
                        $.each(list_value, function(key2, tuner_status) {
                            if (typeof tuner_status === 'object' ) {
                                $('#tuners').append('<tr><td>' + tuner_status.status +'</td><td>' + key1 + '</td><td>tuner' + key2 + '</td><td>' + tuner_status.instance + '</td><td>' + tuner_status.ch + '</td><td>' + tuner_status.mux + '</td></tr>');
                                active = true;
                                console.log(tuner_status);
                            }
                        });
                    }
                }
            });
        }
        return active;
    }

    function populateSchedule(sched_data) {
        $('#dashboard').append('<br><h3 style="margin:0;">Scheduler Status</h3><table id="sched" ></table>');
        $('#sched').append('<thead><tr><th class="header" style="min-width: 10ch;">State</th>'
            + '<th class="header" style="min-width: 10ch;">Area</th>'
            + '<th class="header" style="min-width: 10ch;">Title</th>'
            + '<th class="header" style="min-width: 10ch;">Plugin</th>'
            + '<th class="header" style="min-width: 10ch;">Instance</th></thead>'
            );
        var active = false;
        $.each(sched_data, function(key1, dict_value) {
            if(dict_value !== null) {
                $('#sched').append('<tr><td>Running</td><td>' + dict_value.area + '</td><td>' + dict_value.title + '</td><td>' + dict_value.namespace + '</td><td>' + dict_value.instance + '</td></tr>');
                active = true
            }
        });
        return active;
    }
    populateDashboard();
}, 1000));