source: tmcsimulator/trunk/webapps/einotebook/scripts/Event.js @ 551

Revision 551, 8.0 KB checked in by jdalbey, 6 years ago (diff)

Multi-file commit to implement saving evaluation ratings from einotebook to a log file and merging with unified log. Also fix defect #212. cgi-bin/saveEvals.py cgi-bin/saveRatingsToLog.py common/js/displayutils.js common/js/fileutils.js common/js/revision_number.dat common/unifiedlog.css dynamicdata/CADcomments.log dynamicdata/caddetails.csv dynamicdata cms_messages.json dynamicdata/har_messages.json dynamicdata highway_status.json dynamicdata/ratings.csv dynamicdata/unifiedlog.csv dynamicdata/unifiedlog_final.csv einotebook/roles/index.html einotebook roles/roles.js einotebook/script/index.html einotebook/script scrollframe.js einotebook/scripts/Evaluation.js einotebook/scripts/Event.js mergelogs.bash unifiedlogdisplay.html unifiedlogmonitor.html

  • Property svn:executable set to *
Line 
1/**
2 * Represents an event.
3 * @param time {Time}
4 * @param incident {Incident}
5 * @param properties {Properties}
6 * @param properties {Evaluations}
7 */
8function Event(time, incident, properties, evaluations)
9{
10        //========== private static members ==========//
11        Event.invalidID = -1;
12       
13        //========== private static members ==========//
14        Event.id = (typeof Event.id == 'undefined') ? 0 : ++Event.id;
15       
16        //========== public constants ==========//
17        this.id = Event.id;
18        this.expandOptionID = "eventExpandOption" + this.id;
19        this.dataID = "eventData" + this.id;
20        this.eventHeaderID = "eventHeader" + this.id;
21       
22        //========== public read-only members ==========//
23        this.expanded = true;
24        this.highlighted = false;
25        this.time = time;
26        this.incident = incident;
27        this.evaluations = evaluations;
28        this.properties = properties;
29       
30        //========== public methods ==========//
31        this.html = html;
32        this.expandAction = expandAction;
33        this.highlight = highlight;
34        this.unhighlight = unhighlight;
35    this.normalize = normalize;
36        this.focus = focus;
37    this.get_html_headerRow = get_html_headerRow;
38       
39        //========== private methods ==========//
40        this.expandOptionSymbol = expandOptionSymbol;
41        this.headerHTML = headerHTML;
42        this.expandOptionHTML = expandOptionHTML;
43        this.refresh = refresh;
44        this.dataHTML = dataHTML;
45        this.expandAction = expandAction;
46        this.html = html;
47
48    // Color constants (TODO: assign incident numbers dynamically)
49/*    var incidentColor = {
50187: "#d8f0f3",        // PowderBlue
51188: "#dfecdf",        // DarkSeaGreen
52189: "#fff5cc",        // CornSilk
53190: "#ffe8e6",        // MistyRose
54191: "#ffffcc",       // Dark Orange
55181: "#d8f0f3" }
56*/
57       
58        //========== function definitions ===========//
59        /**
60         * Returns the symbol for the expand/collapse option.
61         * @return "+" or "-" depending on whether this event is collapsed or expanded.
62         */
63        function expandOptionSymbol() 
64        { 
65                return this.expanded ? "–" : "+"; 
66        }
67         
68        /**
69         * @return The rectangle containing the expand/collapse symbol,
70         *         incident time, incident number and
71         *         incident title that this event belongs to.
72         */
73        function headerHTML()
74        {
75        if (this.incident == undefined)
76        {
77            console.log(this.time.format());
78        }
79                return "<table class='eventHeader'>" +
80                                "<tr class='eventHeader'>" +
81                                "<td class='eventExpandOption'>" + this.expandOptionHTML() + "</td>" +
82                                "<td class='eventTime'>Time: " + this.time.format() + "</td>" +
83                                "<td class='eventNumber'>" + this.incident.number + "</td>" +
84                                "<td class='eventTitle'>" + this.incident.title + "</td>" + 
85                                "</tr>" +
86                                "</table>";
87        }
88       
89        /**
90         * @return The html of the expand/collapse symbol.
91         */
92        function expandOptionHTML()
93        {
94        return "&nbsp;"
95/*  In 2019 we don't think we want expand option any longer
96                return "<button class='eventExpandButton' id='" + this.expandOptionID +
97                                "' onclick='events.get(" +
98                                this.id + ").expandAction();'>" + this.expandOptionSymbol()
99                                + "</button>";
100*/
101        }
102
103        /**
104         * Updates the expand option symbol and the visibility of the event data depending on
105         * whether this event is collapsed or expanded.
106         */
107        function refresh()
108        {
109                events.doc.getElementById(this.dataID).innerHTML = 
110                        this.expanded ? this.dataHTML() : "";
111                       
112                // IF the event is highlighted THEN
113                if (this.highlighted)
114                {
115                        this.highlight();
116                }
117                else
118                {
119                        this.unhighlight();
120                }
121                       
122                events.doc.getElementById(this.expandOptionID).innerHTML = 
123                        this.expandOptionSymbol();
124        }
125       
126        /**
127         * @return The html for the properties and the evaluations.
128         */
129        function dataHTML()
130        {
131                return properties.html() + evaluations.html();
132        }
133
134        /**
135         * Expands or collapses this event depending on whether this event is
136         * already expanded or collapsed.
137         */
138        function expandAction() 
139        { 
140                this.expanded = !this.expanded; 
141                this.refresh(); 
142        }
143
144        /**
145         * @return The html representation of this event.
146         */
147        function html()
148        {
149                return "<table class='event'>" +
150                           "<tr>" +
151                           "<td class='eventHeader' style='background-color:" + this.incident.color + "'" +
152               "id='" + this.eventHeaderID + "'>" + 
153                              this.headerHTML() + "</td>" +
154                           "</tr>" +
155                           "<tr>" + 
156                           "<td class='eventData' style='background-color:" + this.incident.color + "' id='" + this.dataID + "'>" + 
157                           (this.expanded ? this.dataHTML() : "") + 
158                           "</td>" +
159                           "</tr>" +
160                           "</table>";
161        }
162        /**
163         * @return The html representation of only the header for this event.
164     * Used by Roles page.
165         */
166        function get_html_headerRow()
167        {
168                return "<tr>" +
169                           "<td class='eventHeader' style='background-color:" + this.incident.color + "'" +
170               "id='" + this.eventHeaderID + "'>" + 
171                              this.headerHTML() + "</td>" +
172                           "</tr>";
173        }       
174        /**
175         * Scrolls the window to this Event.
176         * @param window The window to scroll.
177         */
178        function focus()
179        {
180                /* This next 3 lines were discarded because it moved the scroll bar of the parent of
181                 * the given window in addition to the scroll bar of the given window..
182                var positionOfPound = window.location.indexOf("#");
183                var rootLocation = window.location.substring(0, positionOfPound);
184                window.location = rootLocation + "#" + eventAnchorName;
185                */
186                events.win.scrollTo(0, absoluteTop(events.doc.getElementById(this.eventHeaderID)));
187        }
188       
189        /**
190         * Highlights this Event.
191         */
192        function highlight()
193        {
194                this.highlighted = true;
195        if (events.doc.getElementById(this.eventHeaderID) != null)
196        {
197                events.doc.getElementById(this.eventHeaderID).style.borderColor = "blue";
198                events.doc.getElementById(this.eventHeaderID).style.backgroundColor = "yellow";
199                events.doc.getElementById(this.eventHeaderID).style.color = "black";
200                events.doc.getElementById(this.dataID).style.color = "black";
201        events.doc.getElementById(this.dataID).style.backgroundColor = this.incident.color;
202               
203                // IF this event is expanded THEN
204                if (this.expanded) 
205                {
206                        events.doc.getElementById(this.dataID).style.border = "2px solid blue";
207                }
208                else
209                {
210                        events.doc.getElementById(this.dataID).style.border = "none";
211                }
212        }
213        }
214       
215        /**
216         * Unhighlights this event.
217         * @return
218         */
219        function unhighlight()
220        {
221                this.highlighted = false;
222        if (events.doc.getElementById(this.eventHeaderID) != null)
223        {
224            events.doc.getElementById(this.eventHeaderID).style.backgroundColor = "white";
225            events.doc.getElementById(this.eventHeaderID).style.borderColor = "gainsboro";
226            events.doc.getElementById(this.eventHeaderID).style.color = "gray";
227            events.doc.getElementById(this.dataID).style.border = "0px solid red";
228            events.doc.getElementById(this.dataID).style.backgroundColor = "white";
229            events.doc.getElementById(this.dataID).style.color = "gray";
230        }
231        }
232        /**
233         * Normalize this Event: provide normal background and text colors.
234         */
235        function normalize()
236        {
237        var myColor = this.incident.color;
238        // On the Roles page, we don't list every event, so some will be null
239        // This check will make sure we don't try to normalize non-existing events
240        if (events.doc.getElementById(this.eventHeaderID) != null)
241        {
242            events.doc.getElementById(this.eventHeaderID).style.backgroundColor = "white";
243            events.doc.getElementById(this.eventHeaderID).style.borderColor = "black";
244            events.doc.getElementById(this.eventHeaderID).style.color = "black";
245            events.doc.getElementById(this.dataID).style.color = "black";
246            events.doc.getElementById(this.dataID).style.backgroundColor = myColor;
247            events.doc.getElementById(this.eventHeaderID).style.backgroundColor = myColor;
248        }
249    }           
250
251       
252        /**
253         * Returns the number of pixels from the top of the given element to the top
254         * of the body element.
255         * @param elem The element whose y-coordinate will be found.
256         * @return The y-coordinate of the given element.
257         */
258        function absoluteTop(elem)
259        {
260                var offset = elem.offsetTop;
261                var parent = elem.offsetParent;
262               
263                if (parent.tagName == "BODY")
264                {
265                        return offset;
266                }
267                else
268                {
269                        return offset + absoluteTop(parent);
270                }
271        }
272}
Note: See TracBrowser for help on using the repository browser.