garden-o-matic should have a "rebaseline" button
[WebKit-https.git] / Tools / Scripts / webkitpy / tool / servers / data / gardeningserver / main.js
1 (function() {
2
3 function dismissButterbar()
4 {
5     $('.butterbar').fadeOut('fast');
6 }
7
8 function displayOnButterbar(message)
9 {
10     $('.butterbar .status').text(message);
11     $('.butterbar').fadeIn();
12 }
13
14 function setIconState(hasFailures)
15 {
16     var faviconURL = 'favicon-' + (hasFailures ? 'red' : 'green') + '.png';
17     $('#favicon').attr('href', faviconURL);
18 }
19
20 function showResults(onsuccess)
21 {
22     results.fetchResultsByBuilder(config.builders, function(resultsByBuilder) {
23         var unexpectedFailures = results.unexpectedFailuresByTest(resultsByBuilder);
24         var hasFailures = !$.isEmptyObject(unexpectedFailures)
25         if (!hasFailures) {
26             $('.results').text('No failures. Party time!');
27             var partyTime = $('<div class="partytime"><img src="partytime.gif"></div>');
28             $('.results').append(partyTime);
29             partyTime.fadeIn(1200).delay(7000).fadeOut();
30         } else {
31             var regressions = $('<div class="results-summary regression"></div>');
32             $.each(unexpectedFailures, function(testName, resultNodesByBuilder) {
33                 var testSummary = ui.summarizeTest(testName, resultNodesByBuilder);
34                 regressions.append(testSummary);
35
36                 var builderNameList = base.keys(resultNodesByBuilder);
37                 results.unifyRegressionRanges(builderNameList, testName, function(oldestFailingRevision, newestPassingRevision) {
38                     $('.regression-range', testSummary).append(ui.summarizeRegressionRange(oldestFailingRevision, newestPassingRevision));
39                     if (!newestPassingRevision)
40                         return;
41                     checkout.existsAtRevision(checkout.subversionURLForTest(testName), newestPassingRevision, function(testExistedBeforeFailure) {
42                         $(testSummary).attr('data-new-test', !testExistedBeforeFailure);
43                     });
44                 });
45                 results.countFailureOccurances(builderNameList, testName, function(failureCount) {
46                     $(testSummary).attr(config.kFailureCountAttr, failureCount);
47                     $('.failure-count', testSummary).text(ui.failureCount(failureCount));
48                 });
49             });
50             $('.results').append(regressions);
51         }
52         setIconState(hasFailures);
53         onsuccess();
54     });
55 }
56
57 function showResultsDetail()
58 {
59     var testBlock = $(this).parents('.test');
60     var builderName = $(this).attr(config.kBuilderNameAttr);
61     var testName = $('.what', testBlock).text();
62
63     // FIXME: It's lame that we have two different representations of multiple failure types.
64     var failureTypes = testBlock.attr(config.kFailureTypesAttr);
65     var failureTypeList = failureTypes.split(' ');
66
67     var content = $('.results-detail .content');
68     if ($('.failure-details', content).attr(config.kBuilderNameAttr) == builderName &&
69         $('.failure-details', content).attr(config.kTestNameAttr) == testName &&
70         $('.failure-details', content).attr(config.kFailureTypesAttr) == failureTypes)
71         return;
72
73     displayOnButterbar('Loading...');
74
75     results.fetchResultsURLs(builderName, testName, failureTypeList, function(resultsURLs) {
76         var status = $('.results-detail .toolbar .status');
77
78         function updateResults()
79         {
80             status.text(testName + ' [' + builderName + ']');
81             content.empty();
82             content.append(ui.failureDetails(resultsURLs));
83             $('.results-detail .actions .rebaseline').toggle(results.canRebaseline(failureTypeList));
84             $('.failure-details', content).attr(config.kBuilderNameAttr, builderName);
85             $('.failure-details', content).attr(config.kTestNameAttr, testName);
86             $('.failure-details', content).attr(config.kFailureTypesAttr, failureTypes);
87         }
88
89         var children = content.children();
90         if (children.length && $('.results-detail').is(":visible")) {
91             // The results-detail pane is already open. Let's do a quick cross-fade.
92             status.fadeOut('fast');
93             children.fadeOut('fast', function() {
94                 updateResults();
95                 status.fadeIn('fast');
96                 content.children().hide().fadeIn('fast', dismissButterbar);
97             });
98         } else {
99             updateResults();
100             $('.results-detail').fadeIn('fast', dismissButterbar);
101         }
102     });
103 }
104
105 function hideResultsDetail()
106 {
107     $('.results-detail').fadeOut('fast', function() {
108         $('.results-detail .content').empty();
109     });
110 }
111
112 function rebaselineResults()
113 {
114     var failureDetails = $('.failure-details', $(this).parents('.results-detail'));
115
116     var builderName = failureDetails.attr(config.kBuilderNameAttr);
117     var testName = failureDetails.attr(config.kTestNameAttr);
118     var failureTypes = failureDetails.attr(config.kFailureTypesAttr);
119     var failureTypeList = failureTypes.split(' ');
120
121     displayOnButterbar('Rebaselining...');
122     checkout.rebaseline(builderName, testName, failureTypeList, dismissButterbar);
123 }
124
125 $('.regression .where a').live('click', showResultsDetail);
126 $('.results-detail .actions .dismiss').live('click', hideResultsDetail);
127 $('.results-detail .actions .rebaseline').live('click', rebaselineResults);
128
129 $(document).ready(function() {
130     showResults(function() {
131         $('.butterbar').fadeOut();
132     });
133 });
134
135 })();