1/** 2 * Copyright (c) 2017 Google Inc. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you 5 * may not use this file except in compliance with the License. You may 6 * obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 * implied. See the License for the specific language governing 14 * permissions and limitations under the License. 15 */ 16 17(function ($, moment) { 18 19 /** 20 * Display test plan metadata in a vertical popout. 21 * @param container The jquery object in which to insert the plan metadata. 22 * @param metadataList The list of metadata objects to render on the display. 23 */ 24 function renderCard(container, entry) { 25 var card = $('<a class="col s12 m6 l4"></a>'); 26 var link = ( 27 '/show_plan_run?plan=' + entry.testPlanRun.testPlanName + 28 '&time=' + entry.testPlanRun.startTimestamp); 29 card.attr('href', link); 30 card.appendTo(container); 31 var div = $('<div class="hoverable card release-entry"></div>'); 32 var startTime = entry.testPlanRun.startTimestamp; 33 var endTime = entry.testPlanRun.endTimestamp; 34 div.appendTo(card); 35 var span = $('<span></span>'); 36 span.addClass('plan-run-metadata'); 37 span.appendTo(div); 38 $('<b></b>').text(entry.deviceInfo).appendTo(span); 39 span.append('<br>'); 40 $('<b></b>').text('VTS Build: ').appendTo(span); 41 span.append(entry.testPlanRun.testBuildId).append('<br>'); 42 var timeString = ( 43 moment().renderTime(startTime, false) + ' - ' + 44 moment().renderTime(endTime, true) + ' (' + 45 moment().renderDuration(endTime - startTime) + ')'); 46 span.append(timeString); 47 var counter = $('<span></span>'); 48 var color = entry.testPlanRun.failCount > 0 ? 'red' : 'green'; 49 counter.addClass('counter center ' + color); 50 counter.append( 51 entry.testPlanRun.passCount + '/' + 52 (entry.testPlanRun.passCount + entry.testPlanRun.failCount)); 53 counter.appendTo(div); 54 } 55 56 $.fn.showPlanRuns = function(data) { 57 var self = $(this); 58 data.forEach(function (entry) { 59 renderCard(self, entry); 60 }) 61 } 62 63})(jQuery, moment); 64