source: tmcsimulator/trunk/webapps/common/js/displayutils.js @ 650

Revision 650, 3.1 KB checked in by jdalbey, 4 years ago (diff)

Multiple updates - catchup webapps files I've been hoarding (sorry).

Line 
1/** Hide an html element given its id */
2function hideElementById(id)
3{
4    // hide the element by setting css attribute
5    document.getElementById(id).style.display = 'none'
6}
7
8// Show the subversion revision number in the page title
9function showRevision()
10{
11    var title = document.title;
12    title = title + revisionNumber;
13    document.title = title;
14}
15
16// Load a CSV file and convert to a string of formatted HTML
17// @param filename the file containing the CSV input
18// @param targetDiv the div element in which the HTML should be placed.
19// @param sortOrder true if the items are shown in ascending order by time
20function loadLog(filename, targetDiv, sortOrder)
21{
22    // Asynchronous file read of unified log data
23    loadJSON("dynamicdata/" + filename, function(response)
24    {
25        // Split the file into rows
26        var allRows = response.split(/\r?\n|\r/);
27        targetDiv.innerHTML = formatTable(allRows, sortOrder);
28    }
29    );
30}
31
32// Format the csv data into an HTML table
33function formatTable(allRows, sortOrder)
34{
35    var table = '<table>';
36    if (sortOrder) // ascending order of time (most recent last)
37    {
38        // Put the last log entry at the BOTTOM of the table
39        for (var singleRow = 0; singleRow <= allRows.length-1; singleRow++)
40        {
41            // split each row into fields
42            var fields = allRows[singleRow].split(',');
43            table += formatRow(fields)
44        }
45    }
46    else  // descending order of time (most recent first)
47    {
48        // Put the last log entry at the TOP of the table
49        for (var singleRow = allRows.length-1; singleRow >= 0; singleRow--)
50        {
51            // split each row into fields
52            var fields = allRows[singleRow].split(',');
53            table += formatRow(fields)
54        }
55    }
56   
57    table += '</table>';
58    return table;
59}
60
61// Format a single row of fields into a table row
62function formatRow(rowCells)
63{
64        var msg_type = ""; // color white is default
65
66        // trimming white space in the type field
67        // ingore the empty line
68        if (rowCells.length > 1) 
69        {
70            rowCells[1] = rowCells[1].trim();
71        }
72        var label = String(rowCells[1]);
73        var info = String(rowCells[3]).trim();
74        // Implement ticket #190
75        // Checking for the type of logging information
76        if (label.startsWith("CAD")) {
77            msg_type = "class=\"CAD\"";
78            if (info.startsWith("Detail")) {
79                msg_type = "class=\"CADdetail\"";
80            }
81        } else if (label.startsWith("Activity")) {
82            msg_type = "class=\"Activity\"";
83        //} else if (rowCells[1] == "CMS Activated.") {
84        } else if (label.startsWith("CMS")) {
85            msg_type = "class=\"CMS\"";
86        } else if (label.startsWith("Eval")) {
87            msg_type = "class=\"Evaluation\"";
88        } 
89
90        // add the message type class to that row
91        var row = '<tr ' + msg_type + '>';
92        for (var rowCell = 0; rowCell < rowCells.length; rowCell++)
93        {
94            row += '<td>';
95            row += rowCells[rowCell];
96            row += '</td>';
97        }
98        row += '</tr>';
99        return row;
100}
Note: See TracBrowser for help on using the repository browser.