From 39f6b6e1f5f602f31fa7cd844809a4a7d4e579d2 Mon Sep 17 00:00:00 2001 From: Israel Madueme Date: Tue, 1 May 2018 17:32:45 -0400 Subject: Bug 1453759 - Port OrangeFactor extension to treeherder --- extensions/OrangeFactor/web/js/orange_factor.js | 59 +++++++++---------------- 1 file changed, 21 insertions(+), 38 deletions(-) (limited to 'extensions/OrangeFactor/web/js') diff --git a/extensions/OrangeFactor/web/js/orange_factor.js b/extensions/OrangeFactor/web/js/orange_factor.js index fa9411cf8..78fbb5eb3 100644 --- a/extensions/OrangeFactor/web/js/orange_factor.js +++ b/extensions/OrangeFactor/web/js/orange_factor.js @@ -8,21 +8,17 @@ $(function() { 'use strict'; - var dayMs = 24 * 60 * 60 * 1000; - var limit = 7; function getOrangeCount(data) { - data = data.oranges; - var total = 0, - days = [], - date = getCurrentDateMs() - limit * dayMs; - for(var i = 0; i < limit; i++) { - var iso = dateString(new Date(date)); - var count = data[iso] ? data[iso].orangecount : 0; - days.push(count); - total += count; - date += dayMs; - } + let days = []; + let total = 0; + + data.forEach(entry => { + let failureCount = entry["failure_count"]; + days.push(failureCount); + total += failureCount; + }); + displayGraph(days); displayCount(total); } @@ -53,39 +49,26 @@ $(function() { $('#orange-count').text(count + ' failures on trunk in the past week'); } - function dateString(date) { - function norm(part) { - return JSON.stringify(part).length == 2 ? part : '0' + part; - } - return date.getFullYear() - + "-" + norm(date.getMonth() + 1) - + "-" + norm(date.getDate()); - } - - function getCurrentDateMs() { - var d = new Date; - return d.getTime(); - }; - function orangify() { - $('#orange-count') - .text('Loading...') - .show(); - var bugId = document.forms['changeform'].id.value; - var request = { + let $orangeCount = $('#orange-count'); + let queryParams = $.param({ + bug: $orangeCount.data('bug-id'), + startday: $orangeCount.data('date-start'), + endday: $orangeCount.data('date-end'), + tree: 'trunk' + }); + let request = { dataType: "json", - xhrFields: { - withCredentials: true - }, - url: "https://brasstacks.mozilla.com/orangefactor/api/count?" + - "bugid=" + encodeURIComponent(bugId) + "&tree=trunk" + url: `https://treeherder.mozilla.org/api/failurecount/?${queryParams}` }; + + $orangeCount.text('Loading...').show(); $.ajax(request) .done(function(data) { getOrangeCount(data); }) .fail(function() { - $('#orange-count').text('Please sign into OrangeFactor first'); + $orangeCount.text('Unable to load OrangeFactor at this time.'); }); } -- cgit v1.2.3-24-g4f1b