diff options
author | Michael Wood <michael.g.wood@intel.com> | 2015-05-18 20:08:28 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-05-29 11:59:45 +0100 |
commit | 2de01a68eb6a9ca74384957c674928944c235269 (patch) | |
tree | 7dbe5a8a2a169dac697bed032263c624e9c2be7e /bitbake/lib/toaster/toastergui/static/js | |
parent | a0ea663b83ecf5f286844420b071101feefc3d22 (diff) | |
download | poky-2de01a68eb6a9ca74384957c674928944c235269.tar.gz |
bitbake: toaster: Port layerdetails to ToasterTables
This ports the layerdetails page to using ToasterTables
Also some whitespace and strict clean ups in the existing layerdetails
js and html template.
(Bitbake rev: 8ce35f81631e31539aeb82f8a85abbb3312e5097)
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js')
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/layerdetails.js | 70 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/libtoaster.js | 3 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/table.js | 77 |
3 files changed, 103 insertions, 47 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js index 3c4d632563..3746ea26e3 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js | |||
@@ -1,4 +1,4 @@ | |||
1 | "use strict" | 1 | "use strict"; |
2 | 2 | ||
3 | function layerDetailsPageInit (ctx) { | 3 | function layerDetailsPageInit (ctx) { |
4 | 4 | ||
@@ -54,7 +54,7 @@ function layerDetailsPageInit (ctx) { | |||
54 | 54 | ||
55 | /* Add dependency layer button click handler */ | 55 | /* Add dependency layer button click handler */ |
56 | layerDepBtn.click(function(){ | 56 | layerDepBtn.click(function(){ |
57 | if (currentLayerDepSelection == undefined) | 57 | if (currentLayerDepSelection === undefined) |
58 | return; | 58 | return; |
59 | 59 | ||
60 | addRemoveDep(currentLayerDepSelection.id, true, function(){ | 60 | addRemoveDep(currentLayerDepSelection.id, true, function(){ |
@@ -122,13 +122,6 @@ function layerDetailsPageInit (ctx) { | |||
122 | }); | 122 | }); |
123 | }); | 123 | }); |
124 | 124 | ||
125 | $(".build-target-btn").click(function(){ | ||
126 | /* fire a build */ | ||
127 | var target = $(this).data('target-name'); | ||
128 | libtoaster.startABuild(ctx.projectBuildUrl, libtoaster.ctx.projectId, target, null, null); | ||
129 | window.location.replace(libtoaster.ctx.projectPageUrl); | ||
130 | }); | ||
131 | |||
132 | function defaultAddBtnText(){ | 125 | function defaultAddBtnText(){ |
133 | var text = " Add the "+ctx.layerVersion.name+" layer to your project"; | 126 | var text = " Add the "+ctx.layerVersion.name+" layer to your project"; |
134 | addRmLayerBtn.text(text); | 127 | addRmLayerBtn.text(text); |
@@ -155,9 +148,48 @@ function layerDetailsPageInit (ctx) { | |||
155 | } | 148 | } |
156 | } | 149 | } |
157 | 150 | ||
158 | window.location.hash = "targets"; | 151 | window.location.hash = "recipes"; |
159 | } | 152 | } |
160 | 153 | ||
154 | $("#recipestable").on('table-done', function(e, total, tableParams){ | ||
155 | ctx.numTargets = total; | ||
156 | |||
157 | if (total === 0 && !tableParams.search) { | ||
158 | $("#no-recipes-yet").show(); | ||
159 | } else { | ||
160 | $("#no-recipes-yet").hide(); | ||
161 | } | ||
162 | |||
163 | $("#targets-tab").removeClass("muted"); | ||
164 | if (window.location.hash === "#recipes"){ | ||
165 | /* re run the machinesTabShow to update the text */ | ||
166 | targetsTabShow(); | ||
167 | } | ||
168 | |||
169 | $(".build-target-btn").unbind('click'); | ||
170 | $(".build-target-btn").click(function(){ | ||
171 | /* fire a build */ | ||
172 | var target = $(this).data('target-name'); | ||
173 | libtoaster.startABuild(ctx.projectBuildUrl, libtoaster.ctx.projectId, target, null, null); | ||
174 | window.location.replace(libtoaster.ctx.projectPageUrl); | ||
175 | }); | ||
176 | }); | ||
177 | |||
178 | $("#machinestable").on('table-done', function(e, total, tableParams){ | ||
179 | ctx.numMachines = total; | ||
180 | |||
181 | if (total === 0 && !tableParams.search) | ||
182 | $("#no-machines-yet").show(); | ||
183 | else | ||
184 | $("#no-machines-yet").hide(); | ||
185 | |||
186 | $("#machines-tab").removeClass("muted"); | ||
187 | if (window.location.hash === "#machines"){ | ||
188 | /* re run the machinesTabShow to update the text */ | ||
189 | machinesTabShow(); | ||
190 | } | ||
191 | }); | ||
192 | |||
161 | $("#targets-tab").on('show', targetsTabShow); | 193 | $("#targets-tab").on('show', targetsTabShow); |
162 | 194 | ||
163 | function machinesTabShow(){ | 195 | function machinesTabShow(){ |
@@ -187,7 +219,7 @@ function layerDetailsPageInit (ctx) { | |||
187 | /* Enables the Build target and Select Machine buttons and switches the | 219 | /* Enables the Build target and Select Machine buttons and switches the |
188 | * add/remove button | 220 | * add/remove button |
189 | */ | 221 | */ |
190 | function setLayerInCurrentPrj(added, depsList) { | 222 | function setLayerInCurrentPrj(added) { |
191 | ctx.layerVersion.inCurrentPrj = added; | 223 | ctx.layerVersion.inCurrentPrj = added; |
192 | 224 | ||
193 | if (added){ | 225 | if (added){ |
@@ -224,18 +256,20 @@ function layerDetailsPageInit (ctx) { | |||
224 | } | 256 | } |
225 | } | 257 | } |
226 | 258 | ||
227 | $("#dismiss-alert").click(function(){ $(this).parent().hide() }); | 259 | $("#dismiss-alert").click(function(){ |
260 | $(this).parent().fadeOut(); | ||
261 | }); | ||
228 | 262 | ||
229 | /* Add or remove this layer from the project */ | 263 | /* Add or remove this layer from the project */ |
230 | addRmLayerBtn.click(function() { | 264 | addRmLayerBtn.click(function() { |
231 | 265 | ||
232 | var add = ($(this).data('directive') === "add") | 266 | var add = ($(this).data('directive') === "add"); |
233 | 267 | ||
234 | libtoaster.addRmLayer(ctx.layerVersion, add, function (layersList){ | 268 | libtoaster.addRmLayer(ctx.layerVersion, add, function (layersList){ |
235 | var alertMsg = $("#alert-msg"); | 269 | var alertMsg = $("#alert-msg"); |
236 | alertMsg.html(libtoaster.makeLayerAddRmAlertMsg(ctx.layerVersion, layersList, add)); | 270 | alertMsg.html(libtoaster.makeLayerAddRmAlertMsg(ctx.layerVersion, layersList, add)); |
237 | 271 | ||
238 | setLayerInCurrentPrj(add, layersList); | 272 | setLayerInCurrentPrj(add); |
239 | 273 | ||
240 | $("#alert-area").show(); | 274 | $("#alert-area").show(); |
241 | }); | 275 | }); |
@@ -250,9 +284,9 @@ function layerDetailsPageInit (ctx) { | |||
250 | * from. | 284 | * from. |
251 | */ | 285 | */ |
252 | var entryElement = mParent.find("input"); | 286 | var entryElement = mParent.find("input"); |
253 | if (entryElement.length == 0) | 287 | if (entryElement.length === 0) |
254 | entryElement = mParent.find("textarea"); | 288 | entryElement = mParent.find("textarea"); |
255 | if (entryElement.length == 0) { | 289 | if (entryElement.length === 0) { |
256 | console.warn("Could not find element to get data from for this change"); | 290 | console.warn("Could not find element to get data from for this change"); |
257 | return; | 291 | return; |
258 | } | 292 | } |
@@ -293,7 +327,7 @@ function layerDetailsPageInit (ctx) { | |||
293 | 327 | ||
294 | /* Disable the change button when we have no data in the input */ | 328 | /* Disable the change button when we have no data in the input */ |
295 | $("dl input, dl textarea").on("input",function() { | 329 | $("dl input, dl textarea").on("input",function() { |
296 | if ($(this).val().length == 0) | 330 | if ($(this).val().length === 0) |
297 | $(this).parent().children(".change-btn").attr("disabled", "disabled"); | 331 | $(this).parent().children(".change-btn").attr("disabled", "disabled"); |
298 | else | 332 | else |
299 | $(this).parent().children(".change-btn").removeAttr("disabled"); | 333 | $(this).parent().children(".change-btn").removeAttr("disabled"); |
@@ -322,7 +356,7 @@ function layerDetailsPageInit (ctx) { | |||
322 | }); | 356 | }); |
323 | 357 | ||
324 | /* Hide the right column if it contains no information */ | 358 | /* Hide the right column if it contains no information */ |
325 | if ($("dl.item-info").children(':visible').length == 0) { | 359 | if ($("dl.item-info").children(':visible').length === 0) { |
326 | $("dl.item-info").parent().hide(); | 360 | $("dl.item-info").parent().hide(); |
327 | } | 361 | } |
328 | 362 | ||
diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 1ac26d4c7f..99e1f03095 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js | |||
@@ -216,6 +216,9 @@ var libtoaster = (function (){ | |||
216 | str += "&"; | 216 | str += "&"; |
217 | } | 217 | } |
218 | 218 | ||
219 | /* Maintain the current hash */ | ||
220 | str += window.location.hash; | ||
221 | |||
219 | return str; | 222 | return str; |
220 | } | 223 | } |
221 | 224 | ||
diff --git a/bitbake/lib/toaster/toastergui/static/js/table.js b/bitbake/lib/toaster/toastergui/static/js/table.js index 97370fd020..2e35e3871c 100644 --- a/bitbake/lib/toaster/toastergui/static/js/table.js +++ b/bitbake/lib/toaster/toastergui/static/js/table.js | |||
@@ -64,10 +64,12 @@ function tableInit(ctx){ | |||
64 | 64 | ||
65 | function updateTable(tableData) { | 65 | function updateTable(tableData) { |
66 | var tableBody = table.children("tbody"); | 66 | var tableBody = table.children("tbody"); |
67 | var paginationBtns = $('#pagination-'+ctx.tableName); | 67 | var pagination = $('#pagination-'+ctx.tableName); |
68 | var paginationBtns = pagination.children('ul'); | ||
69 | var tableContainer = $("#table-container-"+ctx.tableName); | ||
68 | 70 | ||
71 | tableContainer.css("visibility", "hidden"); | ||
69 | /* To avoid page re-layout flicker when paging set fixed height */ | 72 | /* To avoid page re-layout flicker when paging set fixed height */ |
70 | table.css("visibility", "hidden"); | ||
71 | table.css("padding-bottom", table.height()); | 73 | table.css("padding-bottom", table.height()); |
72 | 74 | ||
73 | /* Reset table components */ | 75 | /* Reset table components */ |
@@ -83,19 +85,30 @@ function tableInit(ctx){ | |||
83 | tableTotal = tableData.total; | 85 | tableTotal = tableData.total; |
84 | 86 | ||
85 | if (tableData.total === 0){ | 87 | if (tableData.total === 0){ |
86 | $("#table-container-"+ctx.tableName).hide(); | 88 | tableContainer.hide(); |
87 | $("#new-search-input-"+ctx.tableName).val(tableParams.search); | 89 | /* If we were searching show the new search bar and return */ |
88 | $("#no-results-"+ctx.tableName).show(); | 90 | if (tableParams.search){ |
91 | $("#new-search-input-"+ctx.tableName).val(tableParams.search); | ||
92 | $("#no-results-"+ctx.tableName).show(); | ||
93 | } | ||
94 | table.trigger("table-done", [tableData.total, tableParams]); | ||
95 | |||
89 | return; | 96 | return; |
97 | |||
98 | /* We don't want to clutter the place with the table chrome if there | ||
99 | * are only a few results */ | ||
100 | } else if (tableData.total <= 10 && | ||
101 | !tableParams.filter && | ||
102 | !tableParams.search){ | ||
103 | $("#table-chrome-"+ctx.tableName).hide(); | ||
104 | pagination.hide(); | ||
90 | } else { | 105 | } else { |
91 | $("#table-container-"+ctx.tableName).show(); | 106 | tableContainer.show(); |
92 | $("#no-results-"+ctx.tableName).hide(); | 107 | $("#no-results-"+ctx.tableName).hide(); |
93 | } | 108 | } |
94 | 109 | ||
95 | |||
96 | setupTableChrome(tableData); | 110 | setupTableChrome(tableData); |
97 | 111 | ||
98 | |||
99 | /* Add table data rows */ | 112 | /* Add table data rows */ |
100 | for (var i in tableData.rows){ | 113 | for (var i in tableData.rows){ |
101 | var row = $("<tr></tr>"); | 114 | var row = $("<tr></tr>"); |
@@ -137,26 +150,31 @@ function tableInit(ctx){ | |||
137 | var end = tableParams.page + 2; | 150 | var end = tableParams.page + 2; |
138 | var numPages = Math.ceil(tableData.total/tableParams.limit); | 151 | var numPages = Math.ceil(tableData.total/tableParams.limit); |
139 | 152 | ||
140 | if (tableParams.page < 3) | 153 | if (numPages > 1){ |
141 | end = 5; | 154 | if (tableParams.page < 3) |
155 | end = 5; | ||
142 | 156 | ||
143 | for (var page_i=1; page_i <= numPages; page_i++){ | 157 | for (var page_i=1; page_i <= numPages; page_i++){ |
144 | if (page_i >= start && page_i <= end){ | 158 | if (page_i >= start && page_i <= end){ |
145 | var btn = $('<li><a href="#" class="page">'+page_i+'</a></li>'); | 159 | var btn = $('<li><a href="#" class="page">'+page_i+'</a></li>'); |
146 | 160 | ||
147 | if (page_i === tableParams.page){ | 161 | if (page_i === tableParams.page){ |
148 | btn.addClass("active"); | 162 | btn.addClass("active"); |
149 | } | 163 | } |
150 | 164 | ||
151 | /* Add the click handler */ | 165 | /* Add the click handler */ |
152 | btn.click(pageButtonClicked); | 166 | btn.click(pageButtonClicked); |
153 | paginationBtns.append(btn); | 167 | paginationBtns.append(btn); |
168 | } | ||
154 | } | 169 | } |
155 | } | 170 | } |
156 | table.css("padding-bottom", 0); | 171 | |
157 | loadColumnsPreference(); | 172 | loadColumnsPreference(); |
158 | 173 | ||
159 | $("table").css("visibility", "visible"); | 174 | table.css("padding-bottom", 0); |
175 | tableContainer.css("visibility", "visible"); | ||
176 | |||
177 | table.trigger("table-done", [tableData.total, tableParams]); | ||
160 | } | 178 | } |
161 | 179 | ||
162 | function setupTableChrome(tableData){ | 180 | function setupTableChrome(tableData){ |
@@ -374,9 +392,9 @@ function tableInit(ctx){ | |||
374 | data: params, | 392 | data: params, |
375 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | 393 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, |
376 | success: function (filterData) { | 394 | success: function (filterData) { |
377 | var filterActionRadios = $('#filter-actions'); | 395 | var filterActionRadios = $('#filter-actions-'+ctx.tableName); |
378 | 396 | ||
379 | $('#filter-modal-title').text(filterData.title); | 397 | $('#filter-modal-title-'+ctx.tableName).text(filterData.title); |
380 | 398 | ||
381 | filterActionRadios.text(""); | 399 | filterActionRadios.text(""); |
382 | 400 | ||
@@ -404,7 +422,7 @@ function tableInit(ctx){ | |||
404 | filterActionRadios.append(action); | 422 | filterActionRadios.append(action); |
405 | } | 423 | } |
406 | 424 | ||
407 | $('#filter-modal').modal('show'); | 425 | $('#filter-modal-'+ctx.tableName).modal('show'); |
408 | } | 426 | } |
409 | }); | 427 | }); |
410 | } | 428 | } |
@@ -417,17 +435,18 @@ function tableInit(ctx){ | |||
417 | e.stopPropagation(); | 435 | e.stopPropagation(); |
418 | }); | 436 | }); |
419 | 437 | ||
420 | $(".pagesize").val(tableParams.limit); | 438 | $(".pagesize-"+ctx.tableName).val(tableParams.limit); |
421 | 439 | ||
422 | /* page size selector */ | 440 | /* page size selector */ |
423 | $(".pagesize").change(function(){ | 441 | $(".pagesize-"+ctx.tableName).change(function(e){ |
424 | tableParams.limit = Number(this.value); | 442 | tableParams.limit = Number(this.value); |
425 | if ((tableParams.page * tableParams.limit) > tableTotal) | 443 | if ((tableParams.page * tableParams.limit) > tableTotal) |
426 | tableParams.page = 1; | 444 | tableParams.page = 1; |
427 | 445 | ||
428 | loadData(tableParams); | 446 | loadData(tableParams); |
429 | /* sync the other selectors on the page */ | 447 | /* sync the other selectors on the page */ |
430 | $(".pagesize").val(this.value); | 448 | $(".pagesize-"+ctx.tableName).val(this.value); |
449 | e.preventDefault(); | ||
431 | }); | 450 | }); |
432 | 451 | ||
433 | $("#search-submit-"+ctx.tableName).click(function(e){ | 452 | $("#search-submit-"+ctx.tableName).click(function(e){ |
@@ -463,12 +482,12 @@ function tableInit(ctx){ | |||
463 | e.preventDefault(); | 482 | e.preventDefault(); |
464 | }); | 483 | }); |
465 | 484 | ||
466 | $("#clear-filter-btn").click(function(){ | 485 | $("#clear-filter-btn-"+ctx.tableName).click(function(){ |
467 | tableParams.filter = null; | 486 | tableParams.filter = null; |
468 | loadData(tableParams); | 487 | loadData(tableParams); |
469 | }); | 488 | }); |
470 | 489 | ||
471 | $("#filter-modal-form").submit(function(e){ | 490 | $("#filter-modal-form-"+ctx.tableName).submit(function(e){ |
472 | e.preventDefault(); | 491 | e.preventDefault(); |
473 | 492 | ||
474 | tableParams.filter = $(this).find("input[type='radio']:checked").val(); | 493 | tableParams.filter = $(this).find("input[type='radio']:checked").val(); |