aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/bug_chomper/templates/bug_chomper.html
blob: df08570b8653370ab93d1d3af936bb88407f159a (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
<html>
<head>
<title>{{.Title}}</title>
<link rel="stylesheet" type="text/css" href="res/style.css" />
<link rel="icon" type="image/ico" href="res/favicon.ico" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript" src="res/third_party/jquery.tablednd.js"></script>
<script type="text/javascript">
"use strict";

var issues = {{.BugsJson}};
var edited = {};

function edit_label(bug_id, old_value, new_value) {
    console.log("issue[" + bug_id + "]: " + old_value + " -> " + new_value);
    if (!edited[bug_id]) {
        edited[bug_id] = JSON.parse(JSON.stringify(issues[bug_id]));
    }
    var old_index = edited[bug_id]["labels"].indexOf(old_value);
    if (old_index > -1) {
        edited[bug_id]["labels"][old_index] = new_value;
    } else {
        edited[bug_id]["labels"].push(new_value)
    }
    if (JSON.stringify(issues[bug_id]) == JSON.stringify(edited[bug_id])) {
        console.log("Not changing " + bug_id);
        delete edited[bug_id]
    }
    document.getElementById("all_edits").value = JSON.stringify(edited);
}

</script>
</head>
<body>
<h1>BugChomper</h1>

<form method="post">
<input type="hidden" name="all_edits" id="all_edits" value="{}" />
<input type="submit" value="Submit changes to issue tracker" />
</form>
<table id="buglist">
  <thead>
    <tr id="table_header" class="nodrag tr_head">
      <td colspan=3><h2>Open bugs for {{.User}}</h2></td>
    </tr>
    <tr id="table_subheader" class="nodrag tr_head">
      <td>ID</td>
      <td>Priority</td>
      <td>Title</td>
    </tr>
  </thead>
  <tbody>
    {{with $all_data := .}}
      {{range $index, $priority := index $all_data.Priorities}}
        <tr id="priority_{{$priority}}"
            class="{{if eq $index 0}}nodrop{{else}}{{end}} nodrag priority_row priority_{{$priority}}"
            >
          <td colspan=3 class="priority_td">Priority {{$priority}}</td>
        </tr>
        {{range $index, $bug := index $all_data.BugsByPriority $priority}}
          <tr id="{{$bug.Id}}" class="priority_{{$priority}}">
            <td id="id_{{$bug.Id}}">
              <a href="{{$bug.URL}}" target="_blank">{{$bug.Id}}</a>
            </td>
            <td id="priority_{{$bug.Id}}">{{$priority}}</td>
            <td id="title_{{$bug.Id}}">{{$bug.Title}}</td>
          </tr>
        {{end}}
      {{end}}
    {{end}}
  </tbody>
</table>

<script type="text/javascript">
$(document).ready(function() {
    $("#buglist").tableDnD({
        onDrop: function(table, dropped_row) {
            var id = dropped_row.id;
            var css_priority_prefix = "priority_"
            var new_priority = null;
            var dropped_index = null;
            var thead_rows = table.tHead.rows;
            var tbody_rows = table.tBodies[0].rows;
            var all_rows = [];
            for (var i = 0; i < thead_rows.length; i++) {
                all_rows.push(thead_rows[i]);
            }
            for (var i = 0; i < tbody_rows.length; i++) {
                all_rows.push(tbody_rows[i]);
            }
            for (var i = 0; i < all_rows.length; i++) {
                if (all_rows[i].id) {
                    if (all_rows[i].id.indexOf(css_priority_prefix) == 0) {
                        new_priority = all_rows[i].id.substring(css_priority_prefix.length);
                    }
                    if (all_rows[i].id == id) {
                        break;
                    }
                } else {
                  console.warn("No id for:");
                  console.warn(all_rows[i]);
                }
            }
            if (new_priority) {
                priority_td = document.getElementById(css_priority_prefix + id);
                old_priority = priority_td.innerHTML;
                if (priority_td && new_priority != old_priority) {
                    priority_td.innerHTML = new_priority;
                    document.getElementById(id).className = css_priority_prefix + new_priority;
                    edit_label(id, "{{.PriorityPrefix}}" + old_priority, "{{.PriorityPrefix}}" + new_priority);
                }
            }
        }
    });
});
</script>
</body>
</html>