diff options
| author | Elliot Smith <elliot.smith@intel.com> | 2016-01-15 13:00:50 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-15 16:29:59 +0000 |
| commit | 809046c6fbd544907b5d5f3bb554b71724c74661 (patch) | |
| tree | 9a20e81100395ba67934f3e865c6e9356f4e0232 /bitbake/lib/toaster/toastergui/static | |
| parent | 294579b531d5a96a17aa863554e71f4680d35812 (diff) | |
| download | poky-809046c6fbd544907b5d5f3bb554b71724c74661.tar.gz | |
bitbake: toastergui: refactor ToasterTable filtering
The filter code for ToasterTable was difficult to follow
and inflexible (not allowing different types of filter, for example).
Refactor to a set of filter classes to make the structure cleaner
and provide the flexibility needed for other filter types
(e.g. date range filter).
[YOCTO #8738]
(Bitbake rev: 94031bb30bdaf665d0c8c68b591fcb7a17b6674d)
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static')
| -rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/table.js | 80 |
1 files changed, 59 insertions, 21 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/table.js b/bitbake/lib/toaster/toastergui/static/js/table.js index c69c205d50..fa01ddf47e 100644 --- a/bitbake/lib/toaster/toastergui/static/js/table.js +++ b/bitbake/lib/toaster/toastergui/static/js/table.js | |||
| @@ -415,38 +415,76 @@ function tableInit(ctx){ | |||
| 415 | data: params, | 415 | data: params, |
| 416 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | 416 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, |
| 417 | success: function (filterData) { | 417 | success: function (filterData) { |
| 418 | var filterActionRadios = $('#filter-actions-'+ctx.tableName); | 418 | /* |
| 419 | filterData structure: | ||
| 420 | |||
| 421 | { | ||
| 422 | title: '<title for the filter popup>', | ||
| 423 | filter_actions: [ | ||
| 424 | { | ||
| 425 | title: '<label for radio button inside the popup>', | ||
| 426 | name: '<name of the filter action>', | ||
| 427 | count: <number of items this filter will show> | ||
| 428 | } | ||
| 429 | ] | ||
| 430 | } | ||
| 419 | 431 | ||
| 420 | $('#filter-modal-title-'+ctx.tableName).text(filterData.title); | 432 | each filter_action gets a radio button; the value of this is |
| 433 | set to filterName + ':' + filter_action.name; e.g. | ||
| 421 | 434 | ||
| 422 | filterActionRadios.text(""); | 435 | in_current_project:in_project |
| 423 | 436 | ||
| 424 | for (var i in filterData.filter_actions){ | 437 | specifies the "in_project" action of the "in_current_project" |
| 425 | var filterAction = filterData.filter_actions[i]; | 438 | filter |
| 426 | 439 | ||
| 427 | var action = $('<label class="radio"><input type="radio" name="filter" value=""><span class="filter-title"></span></label>'); | 440 | the filterName is set on the column filter icon, and corresponds |
| 428 | var actionTitle = filterAction.title + ' (' + filterAction.count + ')'; | 441 | to a value in the table's filters property |
| 429 | 442 | ||
| 430 | var radioInput = action.children("input"); | 443 | when the filter popup's "Apply" button is clicked, the |
| 444 | value for the radio button which is checked is passed in the | ||
| 445 | querystring and applied to the queryset on the table | ||
| 446 | */ | ||
| 431 | 447 | ||
| 432 | if (Number(filterAction.count) == 0){ | 448 | var filterActionRadios = $('#filter-actions-'+ctx.tableName); |
| 433 | radioInput.attr("disabled", "disabled"); | ||
| 434 | } | ||
| 435 | 449 | ||
| 436 | action.children(".filter-title").text(actionTitle); | 450 | $('#filter-modal-title-'+ctx.tableName).text(filterData.title); |
| 437 | 451 | ||
| 438 | radioInput.val(filterName + ':' + filterAction.name); | 452 | filterActionRadios.text(""); |
| 439 | 453 | ||
| 440 | /* Setup the current selected filter, default to 'all' if | 454 | for (var i in filterData.filter_actions) { |
| 441 | * no current filter selected. | 455 | var filterAction = filterData.filter_actions[i]; |
| 442 | */ | 456 | var action = null; |
| 443 | if ((tableParams.filter && | 457 | |
| 444 | tableParams.filter === radioInput.val()) || | 458 | if (filterAction.type === 'toggle') { |
| 445 | filterAction.name == 'all') { | 459 | var actionTitle = filterAction.title + ' (' + filterAction.count + ')'; |
| 446 | radioInput.attr("checked", "checked"); | 460 | |
| 461 | action = $('<label class="radio">' + | ||
| 462 | '<input type="radio" name="filter" value="">' + | ||
| 463 | '<span class="filter-title">' + | ||
| 464 | actionTitle + | ||
| 465 | '</span>' + | ||
| 466 | '</label>'); | ||
| 467 | |||
| 468 | var radioInput = action.children("input"); | ||
| 469 | if (Number(filterAction.count) == 0) { | ||
| 470 | radioInput.attr("disabled", "disabled"); | ||
| 471 | } | ||
| 472 | |||
| 473 | radioInput.val(filterData.name + ':' + filterAction.action_name); | ||
| 474 | |||
| 475 | /* Setup the current selected filter, default to 'all' if | ||
| 476 | * no current filter selected. | ||
| 477 | */ | ||
| 478 | if ((tableParams.filter && | ||
| 479 | tableParams.filter === radioInput.val()) || | ||
| 480 | filterAction.action_name == 'all') { | ||
| 481 | radioInput.attr("checked", "checked"); | ||
| 482 | } | ||
| 447 | } | 483 | } |
| 448 | 484 | ||
| 449 | filterActionRadios.append(action); | 485 | if (action) { |
| 486 | filterActionRadios.append(action); | ||
| 487 | } | ||
| 450 | } | 488 | } |
| 451 | 489 | ||
| 452 | $('#filter-modal-'+ctx.tableName).modal('show'); | 490 | $('#filter-modal-'+ctx.tableName).modal('show'); |
