diff options
author | Elliot Smith <elliot.smith@intel.com> | 2016-01-15 13:00:53 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-15 16:30:00 +0000 |
commit | f8d383d87f0b9d4a4c9ae7b1a6c8ceebf90ef9b0 (patch) | |
tree | cda7dc3eb23a5b6a97241c965bbd9b0dcddc02eb /bitbake/lib/toaster/toastergui/static | |
parent | b929889cdd4a36846f9569d89fabd9987e94b39e (diff) | |
download | poky-f8d383d87f0b9d4a4c9ae7b1a6c8ceebf90ef9b0.tar.gz |
bitbake: toastergui: implement date range filters for builds
Implement the completed_on and started_on filtering for
builds.
Also separate the name of a filter ("filter" in the querystring)
from its value ("filter_value" in the querystring). This enables
filtering to be defined in the querystring more intuitively,
and also makes it easier to add other types of filter (e.g.
by day).
[YOCTO #8738]
(Bitbake rev: d47c32e88c2d4a423f4d94d49759e557f425a539)
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 | 196 |
1 files changed, 165 insertions, 31 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/table.js b/bitbake/lib/toaster/toastergui/static/js/table.js index 63f8a1fed7..b0a8ffb8f9 100644 --- a/bitbake/lib/toaster/toastergui/static/js/table.js +++ b/bitbake/lib/toaster/toastergui/static/js/table.js | |||
@@ -397,11 +397,140 @@ function tableInit(ctx){ | |||
397 | $.cookie("cols", JSON.stringify(disabled_cols)); | 397 | $.cookie("cols", JSON.stringify(disabled_cols)); |
398 | } | 398 | } |
399 | 399 | ||
400 | /** | ||
401 | * Create the DOM/JS for the client side of a TableFilterActionToggle | ||
402 | * | ||
403 | * filterName: (string) internal name for the filter action | ||
404 | * filterActionData: (object) | ||
405 | * filterActionData.count: (number) The number of items this filter will | ||
406 | * show when selected | ||
407 | */ | ||
408 | function createActionToggle(filterName, filterActionData) { | ||
409 | var actionStr = '<div class="radio">' + | ||
410 | '<input type="radio" name="filter"' + | ||
411 | ' value="' + filterName + '"'; | ||
412 | |||
413 | if (Number(filterActionData.count) == 0) { | ||
414 | actionStr += ' disabled="disabled"'; | ||
415 | } | ||
416 | |||
417 | actionStr += ' id="' + filterName + '">' + | ||
418 | '<input type="hidden" name="filter_value" value="on"' + | ||
419 | ' data-value-for="' + filterName + '">' + | ||
420 | '<label class="filter-title"' + | ||
421 | ' for="' + filterName + '">' + | ||
422 | filterActionData.title + | ||
423 | ' (' + filterActionData.count + ')' + | ||
424 | '</label>' + | ||
425 | '</div>'; | ||
426 | |||
427 | return $(actionStr); | ||
428 | } | ||
429 | |||
430 | /** | ||
431 | * Create the DOM/JS for the client side of a TableFilterActionDateRange | ||
432 | * | ||
433 | * filterName: (string) internal name for the filter action | ||
434 | * filterValue: (string) from,to date range in format yyyy-mm-dd,yyyy-mm-dd; | ||
435 | * used to select the current values for the from/to datepickers; | ||
436 | * if this is partial (e.g. "yyyy-mm-dd,") only the applicable datepicker | ||
437 | * will have a date pre-selected; if empty, neither will | ||
438 | * filterActionData: (object) data for generating the action's HTML | ||
439 | * filterActionData.title: label for the radio button | ||
440 | * filterActionData.max: (string) maximum date for the pickers, in ISO 8601 | ||
441 | * datetime format | ||
442 | * filterActionData.min: (string) minimum date for the pickers, ISO 8601 | ||
443 | * datetime | ||
444 | */ | ||
445 | function createActionDateRange(filterName, filterValue, filterActionData) { | ||
446 | var action = $('<div class="radio">' + | ||
447 | '<input type="radio" name="filter"' + | ||
448 | ' value="' + filterName + '" ' + | ||
449 | ' id="' + filterName + '">' + | ||
450 | '<input type="hidden" name="filter_value" value=""' + | ||
451 | ' data-value-for="' + filterName + '">' + | ||
452 | '<label class="filter-title"' + | ||
453 | ' for="' + filterName + '">' + | ||
454 | filterActionData.title + | ||
455 | '</label>' + | ||
456 | '<input type="text" maxlength="10" class="input-small"' + | ||
457 | ' data-date-from-for="' + filterName + '">' + | ||
458 | '<span class="help-inline">to</span>' + | ||
459 | '<input type="text" maxlength="10" class="input-small"' + | ||
460 | ' data-date-to-for="' + filterName + '">' + | ||
461 | '<span class="help-inline get-help">(yyyy-mm-dd)</span>' + | ||
462 | '</div>'); | ||
463 | |||
464 | var radio = action.find('[type="radio"]'); | ||
465 | var value = action.find('[data-value-for]'); | ||
466 | |||
467 | // make the datepickers for the range | ||
468 | var options = { | ||
469 | dateFormat: 'yy-mm-dd', | ||
470 | maxDate: new Date(filterActionData.max), | ||
471 | minDate: new Date(filterActionData.min) | ||
472 | }; | ||
473 | |||
474 | // create date pickers, setting currently-selected from and to | ||
475 | // dates | ||
476 | var selectedFrom = null; | ||
477 | var selectedTo = null; | ||
478 | |||
479 | var selectedFromAndTo = []; | ||
480 | if (filterValue) { | ||
481 | selectedFromAndTo = filterValue.split(','); | ||
482 | } | ||
483 | |||
484 | if (selectedFromAndTo.length == 2) { | ||
485 | selectedFrom = selectedFromAndTo[0]; | ||
486 | selectedTo = selectedFromAndTo[1]; | ||
487 | } | ||
488 | |||
489 | options.defaultDate = selectedFrom; | ||
490 | var inputFrom = | ||
491 | action.find('[data-date-from-for]').datepicker(options); | ||
492 | inputFrom.val(selectedFrom); | ||
493 | |||
494 | options.defaultDate = selectedTo; | ||
495 | var inputTo = | ||
496 | action.find('[data-date-to-for]').datepicker(options); | ||
497 | inputTo.val(selectedTo); | ||
498 | |||
499 | // set filter_value based on date pickers when | ||
500 | // one of their values changes | ||
501 | var changeHandler = function () { | ||
502 | value.val(inputFrom.val() + ',' + inputTo.val()); | ||
503 | }; | ||
504 | |||
505 | inputFrom.change(changeHandler); | ||
506 | inputTo.change(changeHandler); | ||
507 | |||
508 | // check the associated radio button on clicking a date picker | ||
509 | var checkRadio = function () { | ||
510 | radio.prop('checked', 'checked'); | ||
511 | }; | ||
512 | |||
513 | inputFrom.focus(checkRadio); | ||
514 | inputTo.focus(checkRadio); | ||
515 | |||
516 | // selecting a date in a picker constrains the date you can | ||
517 | // set in the other picker | ||
518 | inputFrom.change(function () { | ||
519 | inputTo.datepicker('option', 'minDate', inputFrom.val()); | ||
520 | }); | ||
521 | |||
522 | inputTo.change(function () { | ||
523 | inputFrom.datepicker('option', 'maxDate', inputTo.val()); | ||
524 | }); | ||
525 | |||
526 | return action; | ||
527 | } | ||
528 | |||
400 | function filterOpenClicked(){ | 529 | function filterOpenClicked(){ |
401 | var filterName = $(this).data('filter-name'); | 530 | var filterName = $(this).data('filter-name'); |
402 | 531 | ||
403 | /* We need to pass in the curren search so that the filter counts take | 532 | /* We need to pass in the current search so that the filter counts take |
404 | * into account the current search filter | 533 | * into account the current search term |
405 | */ | 534 | */ |
406 | var params = { | 535 | var params = { |
407 | 'name' : filterName, | 536 | 'name' : filterName, |
@@ -443,46 +572,44 @@ function tableInit(ctx){ | |||
443 | when the filter popup's "Apply" button is clicked, the | 572 | when the filter popup's "Apply" button is clicked, the |
444 | value for the radio button which is checked is passed in the | 573 | value for the radio button which is checked is passed in the |
445 | querystring and applied to the queryset on the table | 574 | querystring and applied to the queryset on the table |
446 | */ | 575 | */ |
576 | var filterActionRadios = $('#filter-actions-' + ctx.tableName); | ||
447 | 577 | ||
448 | var filterActionRadios = $('#filter-actions-'+ctx.tableName); | 578 | $('#filter-modal-title-' + ctx.tableName).text(filterData.title); |
449 | 579 | ||
450 | $('#filter-modal-title-'+ctx.tableName).text(filterData.title); | 580 | filterActionRadios.empty(); |
451 | |||
452 | filterActionRadios.text(""); | ||
453 | 581 | ||
582 | // create a radio button + form elements for each action associated | ||
583 | // with the filter on this column of the table | ||
454 | for (var i in filterData.filter_actions) { | 584 | for (var i in filterData.filter_actions) { |
455 | var filterAction = filterData.filter_actions[i]; | ||
456 | var action = null; | 585 | var action = null; |
586 | var filterActionData = filterData.filter_actions[i]; | ||
587 | var filterName = filterData.name + ':' + | ||
588 | filterActionData.action_name; | ||
457 | 589 | ||
458 | if (filterAction.type === 'toggle') { | 590 | if (filterActionData.type === 'toggle') { |
459 | var actionTitle = filterAction.title + ' (' + filterAction.count + ')'; | 591 | action = createActionToggle(filterName, filterActionData); |
460 | 592 | } | |
461 | action = $('<label class="radio">' + | 593 | else if (filterActionData.type === 'daterange') { |
462 | '<input type="radio" name="filter" value="">' + | 594 | var filterValue = tableParams.filter_value; |
463 | '<span class="filter-title">' + | 595 | |
464 | actionTitle + | 596 | action = createActionDateRange( |
465 | '</span>' + | 597 | filterName, |
466 | '</label>'); | 598 | filterValue, |
467 | 599 | filterActionData | |
468 | var radioInput = action.children("input"); | 600 | ); |
469 | if (Number(filterAction.count) == 0) { | 601 | } |
470 | radioInput.attr("disabled", "disabled"); | ||
471 | } | ||
472 | |||
473 | radioInput.val(filterData.name + ':' + filterAction.action_name); | ||
474 | 602 | ||
475 | /* Setup the current selected filter, default to 'all' if | 603 | if (action) { |
476 | * no current filter selected. | 604 | // Setup the current selected filter, default to 'all' if |
477 | */ | 605 | // no current filter selected |
606 | var radioInput = action.children('input[name="filter"]'); | ||
478 | if ((tableParams.filter && | 607 | if ((tableParams.filter && |
479 | tableParams.filter === radioInput.val()) || | 608 | tableParams.filter === radioInput.val()) || |
480 | filterAction.action_name == 'all') { | 609 | filterActionData.action_name == 'all') { |
481 | radioInput.attr("checked", "checked"); | 610 | radioInput.attr("checked", "checked"); |
482 | } | 611 | } |
483 | } | ||
484 | 612 | ||
485 | if (action) { | ||
486 | filterActionRadios.append(action); | 613 | filterActionRadios.append(action); |
487 | } | 614 | } |
488 | } | 615 | } |
@@ -571,7 +698,14 @@ function tableInit(ctx){ | |||
571 | filterBtnActive($(filterBtn), false); | 698 | filterBtnActive($(filterBtn), false); |
572 | }); | 699 | }); |
573 | 700 | ||
574 | tableParams.filter = $(this).find("input[type='radio']:checked").val(); | 701 | // checked radio button |
702 | var checkedFilter = $(this).find("input[name='filter']:checked"); | ||
703 | tableParams.filter = checkedFilter.val(); | ||
704 | |||
705 | // hidden field holding the value for the checked filter | ||
706 | var checkedFilterValue = $(this).find("input[data-value-for='" + | ||
707 | tableParams.filter + "']"); | ||
708 | tableParams.filter_value = checkedFilterValue.val(); | ||
575 | 709 | ||
576 | var filterBtn = $("#" + tableParams.filter.split(":")[0]); | 710 | var filterBtn = $("#" + tableParams.filter.split(":")[0]); |
577 | 711 | ||