Please clarify "pending" reporting at build.webkit.org/dashboard
[WebKit-https.git] / Tools / BuildSlaveSupport / build.webkit.org-config / public_html / dashboard / Scripts / StatusLineView.js
1 /*
2  * Copyright (C) 2013 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 StatusLineView = function(message, status, label, repeatCount, url)
27 {
28     BaseObject.call(this);
29
30     console.assert(message);
31
32     this.element = document.createElement("div");
33     this.element.classList.add("status-line");
34     this.element.__statusLineView = this;
35
36     this._statusBubbleElement = document.createElement("div");
37     this._statusBubbleElement.classList.add("bubble");
38     if (status != StatusLineView.Status.NoBubble)
39         this.element.appendChild(this._statusBubbleElement);
40
41     this._labelElement = document.createElement("div");
42     this._labelElement.classList.add("label");
43
44     this._messageElement = document.createElement("div");
45     this._messageElement.classList.add("message");
46     this.element.appendChild(this._messageElement);
47
48     this.status = status || StatusLineView.Status.Neutral;
49     this.message = message || "";
50     this.label = label || "";
51     this.repeatCount = repeatCount || 0;
52     this.url = url || null;
53
54     if (url) {
55         this.element.addEventListener("click", this._clicked.bind(this));
56         this.element.classList.add("linked");
57     }
58 };
59
60 StatusLineView.Status = {
61     NoBubble: "no-bubble",
62     Neutral: "neutral",
63     Good: "good",
64     Danger: "danger",
65     Bad: "bad"
66 };
67
68 BaseObject.addConstructorFunctions(StatusLineView);
69
70 StatusLineView.prototype = {
71     constructor: StatusLineView,
72     __proto__: BaseObject.prototype,
73
74     get status()
75     {
76         return this._status;
77     },
78
79     set status(x)
80     {
81         console.assert(x);
82         if (!x)
83             return;
84
85         this.element.classList.remove(this._status);
86
87         this._status = x;
88
89         this.element.classList.add(this._status);
90     },
91
92     get repeatCount()
93     {
94         return this._repeatCount;
95     },
96
97     set repeatCount(x)
98     {
99         this._repeatCount = x;
100
101         if (this._repeatCount) {
102             this._statusBubbleElement.textContent = this._repeatCount;
103             this._statusBubbleElement.classList.remove("pictogram");
104         } else {
105             this._statusBubbleElement.classList.add("pictogram");
106
107             switch (this._status) {
108             case StatusLineView.Status.Neutral:
109                 this._statusBubbleElement.textContent = "?";
110                 break;
111
112             case StatusLineView.Status.Good:
113                 this._statusBubbleElement.textContent = "";
114                 break;
115
116             case StatusLineView.Status.Danger:
117                 this._statusBubbleElement.textContent = "!";
118                 break;
119
120             case StatusLineView.Status.Bad:
121                 this._statusBubbleElement.textContent = "\u2715";
122                 break;
123             }
124         }
125     },
126
127     get label()
128     {
129         return this._labelElement.textContent;
130     },
131
132     set label(x)
133     {
134         if (x) {
135             this._labelElement.textContent = x;
136             this.element.insertBefore(this._labelElement, this._messageElement);
137             this.element.classList.remove("no-label");
138         } else {
139             this._labelElement.removeChildren();
140             this._labelElement.remove();
141             this.element.classList.add("no-label");
142         }
143     },
144
145     get message()
146     {
147         return this._messageElement.textContent;
148     },
149
150     set message(x)
151     {
152         if (x instanceof Node) {
153             this._messageElement.removeChildren();
154             this._messageElement.appendChild(x);
155         } else {
156             this._messageElement.textContent = x;
157         }
158     },
159
160     _clicked: function(event)
161     {
162         if (!this.url)
163             return;
164
165         var anchor = document.createElement("a");
166         anchor.href = this.url;
167         anchor.target = "_blank";
168
169         anchor.click();
170     }
171 };