view dashboard.js @ 15:306db29669c7

Fade in new bug reports
author Atul Varma <varmaa@toolness.com>
date Mon, 08 Mar 2010 22:50:56 -0800
parents 1c1e538d7df7
children c4de72b56b3e
line wrap: on
line source

$(window).ready(
  function() {
    function sortByLastChanged(bugs) {
      var lctimes = {};

      bugs.forEach(
        function(bug) {
          lctimes[bug.id] = dateFromISO8601(bug.last_change_time);
        });

      function compare(a, b) {
        var alc = lctimes[a.id];
        var blc = lctimes[b.id];

        if (alc < blc)
          return -1;
        if (alc > blc)
          return 1;
        return 0;
      }

      bugs.sort(compare);
    }

    function showBugs(query, bugs) {
      var table = $("#templates .bugs").clone();
      var rowTemplate = table.find(".bug-row").remove();
      sortByLastChanged(bugs);
      bugs.reverse();
      bugs.forEach(
        function(bug) {
          var row = rowTemplate.clone();
          row.attr("id", "bug-id-" + bug.id);
          row.find(".summary").text(bug.summary);
          row.addClass("status-" + bug.status);
          if (bug.priority != "--") {
            row.addClass(bug.priority);
            row.addClass(bug.severity);
          }
          console.log(bug.last_change_time, bug.summary);
          row.find(".last-changed").text(prettyDate(bug.last_change_time));

          row.click(
            function onClick() {
              window.open(Bugzilla.getShowBugURL(bug.id));
            });

          row.hover(
            function onIn() {
              var tooltip = $("#templates .bug-tooltip").clone();
              tooltip.find(".priority").text(bug.priority);
              // TODO: Show more information in tooltip.
              $(this).append(tooltip);
            },
            function onOut() {
              $(this).find(".bug-tooltip").remove();
            });

          table.append(row);
        });
      query.append(table);
      table.hide();
      table.fadeIn();
    }

    // Remove duplicate bugs, preferring the first listing of a bug in
    // the DOM to later ones. This is b/c the reports further down the
    // page are the less "interesting" ones, and we want to capture
    // the most "interesting" part of each bug.
    function removeDuplicateBugs() {
      var visited = {};
      $("#reports .bug-row").each(
        function() {
          var id = $(this).attr("id");
          if (id in visited)
            $(this).remove();
          else
            visited[id] = true;
        });
    }

    function report(selector, searchTerms) {
      var newTerms = {__proto__: defaults};
      for (name in searchTerms)
        newTerms[name.replace(/_DOT_/g, ".")] = searchTerms[name];
      Bugzilla.search(newTerms,
                      function(response) {
                        showBugs($(selector), response.bugs);
                        removeDuplicateBugs();
                      });
    }

    function timeAgo(ms) {
      var now = new Date();
      var then = new Date(now - ms);
      return dateToISO8601(then);
    }

    const MS_PER_HOUR = 1000 * 60 * 60;
    const MS_PER_DAY =  MS_PER_HOUR * 24;
    const MS_PER_WEEK = MS_PER_DAY * 7;

    var defaults = {
      changed_after: timeAgo(MS_PER_WEEK * 14)
    };

    report("#assigned-bugs",
           {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"],
            email1: "avarma@mozilla.com",
            email1_type: "equals",
            email1_assigned_to: 1});

    report("#fixed-bugs",
           {resolution: ["FIXED"],
            changed_after: timeAgo(MS_PER_WEEK),
            email1: "avarma@mozilla.com",
            email1_type: "equals",
            email1_assigned_to: 1,
            email1_reporter: 1,
            email1_cc: 1});

    report("#code-reviews",
           {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"],
            flag_DOT_requestee: "avarma@mozilla.com"});

    report("#reported-bugs",
           {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"],
            email1: "avarma@mozilla.com",
            email1_type: "equals",
            email1_reporter: 1,
            email2: "avarma@mozilla.com",
            email2_type: "not_equals",
            email2_assigned_to: 1});

    report("#cc-bugs",
           {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"],
            email1: "avarma@mozilla.com",
            email1_type: "equals",
            email1_cc: 1,
            email2: "avarma@mozilla.com",
            email2_type: "not_equals",
            email2_assigned_to: 1,
            email2_reporter: 1});
  });