File: ps_bootstrap.js

package info (click to toggle)
phpsysinfo 3.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,900 kB
  • sloc: javascript: 22,511; php: 20,651; xml: 18,293; sh: 196; python: 58; makefile: 12
file content (85 lines) | stat: -rw-r--r-- 3,611 bytes parent folder | download | duplicates (2)
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
function renderPlugin_ps(data) {

    var directives = {
        MemoryUsage: {
            html: function () {
                return '<div class="progress"><div class="progress-bar progress-bar-info" style="width:' + this.MemoryUsage + '%;"></div>' +
                        '</div><div class="percent">' + this.MemoryUsage + '%</div>';
            }
        },
        CPUUsage: {
            html: function () {
                return '<div class="progress"><div class="progress-bar progress-bar-info" style="width:' + this.CPUUsage + '%;"></div>' +
                        '</div><div class="percent">' + this.CPUUsage + '%</div>';
            }
        },
        Name: {
            html: function () {
                return this.Name.replace(/AAAAAAAA/g, "A<wbr>A<wbr>A<wbr>A<wbr>A<wbr>A<wbr>A<wbr>A<wbr>").replace(/,/g, ",<wbr>").replace(/\s/g, " <wbr>").replace(/\./g, ".<wbr>").replace(/-/g, "<wbr>-").replace(/\//g, "<wbr>/"); /* split long name */
            }
        }
    };

    if (data.Plugins.Plugin_PS !== undefined) {
        var psitems = items(data.Plugins.Plugin_PS.Process);
        if (psitems.length > 0) {

            var html = "", ps_item = [], expanded = 0, memwas = false, cpuwas = false;
            for (var i = 0; i < psitems.length ; i++) {
                ps_item = psitems[i]["@attributes"];

                if (ps_item.ParentID === "0") {
                    html+="<tr id=\"ps-" + (i+1) + "\" class=\"treegrid-ps-" + (i+1) + "\" style=\"display:none;\" >";
                } else {
                    html+="<tr id=\"ps-" + (i+1) + "\" class=\"treegrid-ps-" + (i+1) + " treegrid-parent-ps-" + ps_item.ParentID + "\" style=\"display:none;\" >";
                }
                html+="<td><span class=\"treegrid-span\" data-bind=\"Name\"></span></td>";
                html+="<td><span data-bind=\"PID\"></span></td>";
                html+="<td><span data-bind=\"PPID\"></span></td>";
                html+="<td style=\"width:10%;\"><span data-bind=\"MemoryUsage\"></span></td>";
                html+="<td style=\"width:10%;\"><span data-bind=\"CPUUsage\"></span></td>";
                html+="</tr>";
            }

            $("#ps-data").empty().append(html);

            $('#ps').treegrid({
                initialState: 'expanded',
                expanderExpandedClass: 'normalicon normalicon-down',
                expanderCollapsedClass: 'normalicon normalicon-right'
            });

            for (var j = 0; j < psitems.length ; j++) {
                ps_item = psitems[j]["@attributes"];
                $('#ps-'+(j+1)).render(ps_item, directives);
                if (!memwas && (ps_item.MemoryUsage !== undefined)) {
                    memwas = true;
                }
                if (!cpuwas && (ps_item.CPUUsage !== undefined)) {
                    cpuwas = true;
                }
                expanded = ps_item.Expanded;
                if ((expanded !== undefined) && (expanded === "0")) {
                    $('#ps-'+(j+1)).treegrid('collapse');
                }
            }

            if (memwas) {
                $('#ps td:nth-child(4),#ps th:nth-child(4)').show();
            } else {
                $('#ps td:nth-child(4),#ps th:nth-child(4)').hide();
            }
            if (cpuwas) {
                $('#ps td:nth-child(5),#ps th:nth-child(5)').show();
            } else {
                $('#ps td:nth-child(5),#ps th:nth-child(5)').hide();
            }

            $('#block_ps').show();
        } else {
            $('#block_ps').hide();
        }
    } else {
        $('#block_ps').hide();
    }
}