Merge lp:~christopher-bradshaw-b/tiqit/attr into lp:tiqit

Proposed by Christopher Bradshaw
Status: Needs review
Proposed branch: lp:~christopher-bradshaw-b/tiqit/attr
Merge into: lp:tiqit
Diff against target: 169 lines (+45/-25)
3 files modified
scripts/pages/results.py (+12/-8)
static/scripts/multiedit.js (+27/-16)
static/scripts/updateresults.js (+6/-1)
To merge this branch: bzr merge lp:~christopher-bradshaw-b/tiqit/attr
Reviewer Review Type Date Requested Status
Matthew Earl Pending
Review via email: mp+279107@code.launchpad.net

Description of the change

Adding structure for plugins to add their own attribute fields
Adding custom event generator for "AttributesChanged"

To post a comment you must log in.
Revision history for this message
Sam Stoll (samstoll1) :

Unmerged revisions

6. By Christopher Bradshaw <email address hidden>

Adding structure for plugins to specify which additional attribute fields.
Adding custom event listener "AttributesChanged", when one of the attributes fields is changed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/pages/results.py'
2--- scripts/pages/results.py 2014-11-10 14:11:37 +0000
3+++ scripts/pages/results.py 2015-12-01 12:30:39 +0000
4@@ -68,19 +68,22 @@
5 # Build up the list of fields we need for correct operation
6 # These are parent fields and bannedIf fields of all the selected fields
7 #
8-parents = set()
9+attr_fields = set()
10 for field in selection:
11 for parent in field._parentFields:
12- parents.add(allFields[parent])
13+ attr_fields.add(allFields[parent])
14
15 for bannedIf in field._bannedIf.keys():
16- parents.add(allFields[bannedIf])
17+ attr_fields.add(allFields[bannedIf])
18
19 for defWith in field.defaultsWith:
20- parents.add(allFields[defWith])
21+ attr_fields.add(allFields[defWith])
22+
23+ for pluginField in plugins.getAttributeFields():
24+ attr_fields.add(allFields[pluginField])
25
26 # We actually request the selected ones, and their dependees
27-requested = selection + list(parents)
28+requested = selection + list(attr_fields)
29
30 states, proj, buglist, usertype, username = parseAdvanced(args)
31
32@@ -97,6 +100,7 @@
33 function init() {
34 tiqitFilterInit("results");
35 tiqitTableInit("results", true, true);
36+ generateCustomEvent('ResultsLoad', document.getElementsByTagName('table'));
37 }
38 tiqitSearchName = "%s";
39 tiqitSearchQuery = %s;
40@@ -217,7 +221,7 @@
41 printTableHeader(prikey, tableNameCounter)
42
43 # We'll be adding attributes to each row, so get the names once
44- attr_names = [x.name for x in parents]
45+ attr_names = [x.name for x in attr_fields]
46
47 for bug in matches:
48 # Check whether we need to start a new table
49@@ -232,11 +236,11 @@
50 # Construct the parent list. All parents should be there as
51 # attributes whether their values are empty or not
52 #
53- attr_values = ["'%s'" % encodeHTML(bug[x.name]) for x in parents]
54+ attr_values = ["'%s'" % encodeHTML(bug[x.name]) for x in attr_fields]
55 attributes = map("=".join, zip(attr_names, attr_values))
56
57 pretty_vals = [bug.getSanitisedValue(x.name, outputType == FORMAT_NORMAL) for x in selection]
58-
59+
60 print "<tr id='%s' lastupdate='%s'%s><td>%s</td></tr>" % (bug['Identifier'], bug['Sys-Last-Updated'], " ".join(attributes), "</td><td>".join(pretty_vals))
61
62 printTableFooter()
63
64=== modified file 'static/scripts/multiedit.js'
65--- static/scripts/multiedit.js 2014-06-05 14:38:53 +0000
66+++ static/scripts/multiedit.js 2015-12-01 12:30:39 +0000
67@@ -42,25 +42,28 @@
68 }
69 }
70
71- // Add a double click event handler
72- tables[i].addEventListener('dblclick', function(event) {
73- var cell = getAncestorOfType(event.target, 'TD');
74- if (cell) {
75- var row = getAncestorOfType(cell, 'TR');
76- if (!row.tiqitSaving) {
77- var table = getAncestorOfType(row, 'TABLE');
78- var colIndex = cell.cellIndex;
79- var field = table.tHead.rows[0].cells[colIndex].getAttribute('field');
80- if (contains(allEditableFields, field)) {
81- if (cell.tiqitEditing) {
82- stopEditingCell(row, cell, field);
83- } else {
84- startEditingCell(row, cell, field);
85+ // Add a double click event handler unless disabled in preferences
86+ if (Tiqit.prefs['miscDisableDblclkEdit'] == undefined ||
87+ Tiqit.prefs['miscDisableDblclkEdit'] == 'false') {
88+ tables[i].addEventListener('dblclick', function(event) {
89+ var cell = getAncestorOfType(event.target, 'TD');
90+ if (cell) {
91+ var row = getAncestorOfType(cell, 'TR');
92+ if (!row.tiqitSaving) {
93+ var table = getAncestorOfType(row, 'TABLE');
94+ var colIndex = cell.cellIndex;
95+ var field = table.tHead.rows[0].cells[colIndex].getAttribute('field');
96+ if (contains(allEditableFields, field)) {
97+ if (cell.tiqitEditing) {
98+ stopEditingCell(row, cell, field);
99+ } else {
100+ startEditingCell(row, cell, field);
101+ }
102 }
103 }
104 }
105- }
106- }, false);
107+ }, false);
108+ }
109 }
110 }
111
112@@ -213,12 +216,17 @@
113 if (event.target.status == 200 && event.target.responseXML) {
114 var bugs = event.target.responseXML.getElementsByTagName('bug');
115 for (var i = 0; i < bugs.length; i++) {
116+ var attributesChanged = false;
117 var row = document.getElementById(bugs[i].getAttribute('identifier'));
118 var table = getAncestorOfType(row, 'TABLE');
119 var fields = event.target.responseXML.getElementsByTagName('field');
120 cancelRowSave(row);
121 row.setAttribute('lastupdate', bugs[i].getAttribute('lastupdate'));
122 for (var j = 0; j < fields.length; j++) {
123+ if (row.hasAttribute(fields[j].getAttribute('name'))) {
124+ row.setAttribute(fields[j].getAttribute('name'), fields[j].textContent.trim());
125+ attributesChanged = true;
126+ }
127 for (var k = 0; k < table.tHead.rows[0].cells.length; k++) {
128 var head = table.tHead.rows[0].cells[k];
129 var field = head.getAttribute('field');
130@@ -245,6 +253,9 @@
131 }
132 }
133 }
134+ if (attributesChanged) {
135+ generateCustomEvent("AttributesChanged", row);
136+ }
137 }
138 } else if (event.target.responseXML) {
139 var msgs = event.target.responseXML.getElementsByTagName('message');
140
141=== modified file 'static/scripts/updateresults.js'
142--- static/scripts/updateresults.js 2014-06-05 14:38:53 +0000
143+++ static/scripts/updateresults.js 2015-12-01 12:30:39 +0000
144@@ -289,12 +289,14 @@
145 var fields = bugs[i].getElementsByTagName('field');
146
147 if (oldLine) {
148+ var attributesChanged = false;
149 for (var j = 0; j < fields.length; j++) {
150 var field = fields[j].getAttribute('name');
151 var colIndex = colForField(field);
152 // If there is an attribute for this field, then update it.
153 if (oldLine.hasAttribute(field)) {
154- oldLine.setAttribute(field, fields[j].textContent.trim());
155+ attributesChanged = true;
156+ oldLine.setAttribute(field, fields[j].textContent.trim());
157 }
158
159 // Now check whether this field is displayed
160@@ -421,6 +423,9 @@
161 oldLine.style.outline = 'solid red 2px';
162 oldLine.style.backgroundColor = 'rgb(255, 240, 220)';
163 }
164+ if (attributesChanged) {
165+ generateCustomEvent("AttributesChanged", oldLine);
166+ }
167 } else {
168 // This is a brand new bug. Add a new line for it.
169 // We'll re-filter and group at the end, so just stick it in first

Subscribers

People subscribed via source and target branches