summaryrefslogtreecommitdiff
path: root/src/main/webapp/WEB-INF/jsp/dashboard_main.jsp
blob: 71f667946c21c280b5ebe16f08d711f225f022e3 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<%--
  ~ Copyright (c) 2016 Google Inc. All Rights Reserved.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License"); you
  ~ may not use this file except in compliance with the License. You may
  ~ obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  ~ implied. See the License for the specific language governing
  ~ permissions and limitations under the License.
  --%>
<%@ page contentType='text/html;charset=UTF-8' language='java' %>
<%@ taglib prefix='fn' uri='http://java.sun.com/jsp/jstl/functions' %>
<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>

<html>
  <link rel='stylesheet' href='/css/dashboard_main.css'>
  <%@ include file='header.jsp' %>
  <body>
    <script>
        var allTests = ${allTestsJson};
        var testSet = new Set(allTests);
        var subscriptionMap = ${subscriptionMapJson};

        var addFavorite = function() {
            if ($(this).hasClass('disabled')) {
                return;
            }
            var test = $('#input-box').val();
            if (!testSet.has(test) || test in subscriptionMap) {
                return;
            }
            $('#add-button').addClass('disabled');
            $.post('/api/favorites', { testName: test}).then(function(data) {
                if (!data.key) {
                    return;
                }
                subscriptionMap[test] = data.key;
                var wrapper = $('<div></div>');
                var a = $('<a></a>')
                    .attr('href', '${resultsUrl}?testName=' + test);
                var div = $('<div class="col s11 card hoverable option"></div>');
                div.addClass('valign-wrapper waves-effect');
                div.appendTo(a);
                var span = $('<span class="entry valign"></span>').text(test);
                span.appendTo(div);
                a.appendTo(wrapper);

                var btnContainer = $('<div class="col s1 center btn-container"></div>');
                var silence = $('<a class="col s6 btn-flat notification-button active"></a>');
                silence.append('<i class="material-icons">notifications_active</i>');
                silence.attr('test', test);
                silence.attr('title', 'Disable notifications');
                silence.appendTo(btnContainer);
                silence.click(toggleNotifications);

                var clear = $('<a class="col s6 btn-flat remove-button"></a>');
                clear.append('<i class="material-icons">clear</i>');
                clear.attr('test', test);
                clear.attr('title', 'Remove favorite');
                clear.appendTo(btnContainer);
                clear.click(removeFavorite);

                btnContainer.appendTo(wrapper);

                wrapper.prependTo('#options').hide()
                                          .slideDown(150);
                $('#input-box').val(null);
                Materialize.updateTextFields();
            }).always(function() {
                $('#add-button').removeClass('disabled');
            });
        }

        var toggleNotifications = function() {
            var self = $(this);
            if (self.hasClass('disabled')) {
                return;
            }
            self.addClass('disabled');
            var test = self.attr('test');
            if (!(test in subscriptionMap)) {
                return;
            }
            var muteStatus = self.hasClass('active');
            var element = self;
            $.post('/api/favorites', { userFavoritesKey: subscriptionMap[test], muteNotifications: muteStatus}).then(function(data) {
                element = self.clone();
                if (element.hasClass('active')) {
                    element.find('i').text('notifications_off')
                    element.removeClass('active');
                    element.addClass('inactive');
                    element.attr('title', 'Enable notifications');
                } else {
                    element.find('i').text('notifications_active')
                    element.removeClass('inactive');
                    element.addClass('active');
                    element.attr('title', 'Disable notifications');
                }
                element.click(toggleNotifications);
                self.replaceWith(function() {
                    return element;
                });
            }).always(function() {
                element.removeClass('disabled');
            });
        }

        var removeFavorite = function() {
            var self = $(this);
            if (self.hasClass('disabled')) {
                return;
            }
            var test = self.attr('test');
            if (!(test in subscriptionMap)) {
                return;
            }
            self.addClass('disabled');
            $.ajax({
                url: '/api/favorites/' + subscriptionMap[test],
                type: 'DELETE'
            }).always(function() {
                self.removeClass('disabled');
            }).then(function() {
                delete subscriptionMap[test];
                self.parent().parent().slideUp(150, function() {
                    self.remove();
                });
            });
        }

        var addFavoriteButton = function() {
          var self = $(this);
          var test = self.attr('test');

          $.post('/api/favorites', { testName: test}).then(function(data) {
            if (data.key) {
              subscriptionMap[test] = data.key;

              self.children().text("star");
              self.switchClass("add-fav-button", "min-fav-button", 0);

              self.off('click', addFavoriteButton);
              self.on('click', removeFavoriteButton);
            }
          })
          .fail(function() {
            alert( "Error occurred on registering your favorite test case!" );
          });
        }

        var removeFavoriteButton = function() {
          var self = $(this);
          var test = self.attr('test');

          $.ajax({
            url: '/api/favorites/' + subscriptionMap[test],
            type: 'DELETE'
          }).then(function() {
            delete subscriptionMap[test];

            self.children().text("star_border");
            self.switchClass("min-fav-button", "add-fav-button", 0);

            self.off('click', removeFavoriteButton);
            self.on('click', addFavoriteButton);
          });
        }

        $.widget('custom.sizedAutocomplete', $.ui.autocomplete, {
            _resizeMenu: function() {
                this.menu.element.outerWidth($('#input-box').width());
            }
        });

        $(function() {
            $('#input-box').sizedAutocomplete({
                source: allTests,
                classes: {
                    'ui-autocomplete': 'card'
                }
            });

            $('#input-box').keyup(function(event) {
                if (event.keyCode == 13) {  // return button
                    $('#add-button').click();
                }
            });

            $('.remove-button').click(removeFavorite);
            $('.notification-button').click(toggleNotifications);
            $('#add-button').click(addFavorite);

            $('.add-fav-button').click(addFavoriteButton);

            $('.min-fav-button').click(removeFavoriteButton);

            $('#favoritesLink').click(function() {
                window.open('/', '_self');
            });
            $('#allLink').click(function() {
                window.open('/?showAll=true', '_self');
            });
            $('#acksLink').click(function() {
                window.open('/show_test_acknowledgments', '_self');
            });
        });
    </script>
    <div class='container wide'>

      <c:if test="${!showAll}">
        <ul id="guide_collapsible" class="collapsible" data-collapsible="accordion">
          <li>
            <div class="collapsible-header">
              <i class="material-icons">library_books</i>
              Notice
              <span class="new badge right" style="position: inherit;">1</span>
            </div>
            <div class="collapsible-body">
              <div class='row'>
                <div class='col s12' style="margin: 15px 0px 0px 30px;">
                  <c:choose>
                    <c:when test="${fn:endsWith(serverName, 'googleplex.com')}">
                      <c:set var="dataVersion" scope="page" value="new"/>
                      <c:choose>
                        <c:when test="${fn:startsWith(serverName, 'android-vts-internal')}">
                          <c:set var="dataLink" scope="page" value="https://android-vts.appspot.com"/>
                        </c:when>
                        <c:when test="${fn:startsWith(serverName, 'android-vts-staging')}">
                          <c:set var="dataLink" scope="page" value="https://android-vts-staging.appspot.com"/>
                        </c:when>
                        <c:otherwise>
                          <c:set var="dataLink" scope="page" value="https://android-vts-staging.appspot.com"/>
                        </c:otherwise>
                      </c:choose>
                    </c:when>
                    <c:when test="${fn:endsWith(serverName, 'appspot.com')}">
                      <c:set var="dataVersion" scope="page" value="previous"/>
                      <c:choose>
                        <c:when test="${fn:startsWith(serverName, 'android-vts-staging')}">
                          <c:set var="dataLink" scope="page" value="https://android-vts-staging.googleplex.com"/>
                        </c:when>
                        <c:when test="${fn:startsWith(serverName, 'android-vts')}">
                          <c:set var="dataLink" scope="page" value="https://android-vts-internal.googleplex.com"/>
                        </c:when>
                        <c:otherwise>
                          <c:set var="dataLink" scope="page" value="https://android-vts-staging.googleplex.com"/>
                        </c:otherwise>
                      </c:choose>
                    </c:when>
                    <c:otherwise>
                      <c:set var="dataVersion" scope="page" value="local dev"/>
                      <c:set var="dataLink" scope="page" value="http://localhost"/>
                    </c:otherwise>
                  </c:choose>
                  Recently, we launched new appspot servers for dashboard. Thus you will have two diffrent versions of server for each staging and production data.
                  <br/>
                  If you want to find the <c:out value = "${dataVersion}"/> test data, please visit the next url <a href="<c:out value = "${dataLink}"/>"><c:out value = "${dataLink}"/></a>.
                </div>
              </div>
            </div>
          </li>
        </ul>
      </c:if>

      <c:choose>
        <c:when test='${not empty error}'>
          <div id='error-container' class='row card'>
            <div class='col s12 center-align'>
              <h5>${error}</h5>
            </div>
          </div>
        </c:when>
        <c:otherwise>
          <div class='row home-tabs-row'>
            <div class='col s12'>
              <ul class='tabs'>
                <li class='tab col s4' id='favoritesLink'><a class='${showAll ? "inactive" : "active"}'>Favorites</a></li>
                <li class='tab col s4' id='allLink'><a class='${showAll ? "active" : "inactive"}'>All Tests</a></li>
                <li class='tab col s4' id='acksLink'><a>Test Acknowledgements</a></li>
              </ul>
            </div>
          </div>
          <c:set var='width' value='${showAll ? 11 : 11}' />
          <c:if test='${not showAll}'>
            <div class='row'>
              <div class='input-field col s8'>
                <input type='text' id='input-box'></input>
                <label for='input-box'>Search for tests to add to favorites</label>
              </div>
              <div id='add-button-wrapper' class='col s1 valign-wrapper'>
                <a id='add-button' class='btn-floating btn waves-effect waves-light red valign'><i class='material-icons'>add</i></a>
              </div>
            </div>
          </c:if>
          <div class='row' id='options'>
            <c:forEach items='${testNames}' var='test'>
              <div>
                <a href='${resultsUrl}?testName=${test.name}'>
                  <div class='col s${width} card hoverable option valign-wrapper waves-effect'>
                    <span class='entry valign'>${test.name}
                      <c:if test='${test.failCount >= 0 && test.passCount >= 0}'>
                        <c:set var='color' value='${test.failCount > 0 ? "red" : (test.passCount > 0 ? "green" : "grey")}' />
                        <span class='indicator right center ${color}'>
                          ${test.passCount} / ${test.passCount + test.failCount}
                        </span>
                      </c:if>
                    </span>
                  </div>
                </a>
                <c:choose>
                  <c:when test="${showAll}">
                    <div class="col s1 center btn-container">
                      <c:choose>
                        <c:when test="${test.isFavorite}">
                          <a class="col s6 btn-flat min-fav-button" test="${test.name}" title="Remove favorite">
                            <i class="material-icons">star</i>
                          </a>
                        </c:when>
                        <c:otherwise>
                          <a class="col s6 btn-flat add-fav-button" test="${test.name}" title="Add favorite">
                            <i class="material-icons">star_border</i>
                          </a>
                        </c:otherwise>
                      </c:choose>
                    </div>
                  </c:when>
                  <c:otherwise>
                    <div class='col s1 center btn-container'>
                      <a class='col s6 btn-flat notification-button ${test.muteNotifications ? "inactive" : "active"}' test='${test.name}' title='${test.muteNotifications ? "Enable" : "Disable"} notifications'>
                        <i class='material-icons'>notifications_${test.muteNotifications ? "off" : "active"}</i>
                      </a>
                      <a class='col s6 btn-flat remove-button' test='${test.name}' title='Remove favorite'>
                        <i class='material-icons'>clear</i>
                      </a>
                    </div>
                  </c:otherwise>
                </c:choose>
              </div>
            </c:forEach>
          </div>
        </c:otherwise>
      </c:choose>
    </div>
    <%@ include file='footer.jsp' %>
  </body>
</html>