[Toaster] [PATCH] toaster: correctly revert to default sort when column is hidden
Barros Pena, Belen
belen.barros.pena at intel.com
Fri Apr 22 05:39:29 PDT 2016
On 22/04/2016 12:34, "toaster-bounces at yoctoproject.org on behalf of Elliot
Smith" <toaster-bounces at yoctoproject.org on behalf of
elliot.smith at intel.com> wrote:
>If a column is hidden while being used as the sort column for
>a ToasterTable, and the default sort column for the table uses
>a reverse sort (e.g. -completed_on), we don't catch the correspondence
>between the default orderby for the table and this column. The
>result is that the sort stays on the hidden column.
>
>Fix this by making sure that we consider default_orderby params
>which have a leading "-".
>
>Also fix how we determine the default sort order for a table, so that
>when the sort is reverted, and the table has a default reverse sort
>like "-completed_on", reapply that reverse sort. (Previously, we
>sorted by the column, but only in ascending order.)
>
>[YOCTO #9011]
This works for me in the 2 offending tables left: all builds and project
builds.
Thanks!
Belén
>
>Signed-off-by: Elliot Smith <elliot.smith at intel.com>
>---
> bitbake/lib/toaster/toastergui/static/js/table.js | 48
>++++++++++++++++++-----
> 1 file changed, 39 insertions(+), 9 deletions(-)
>
>diff --git a/bitbake/lib/toaster/toastergui/static/js/table.js
>b/bitbake/lib/toaster/toastergui/static/js/table.js
>index f738144..eecd2b6 100644
>--- a/bitbake/lib/toaster/toastergui/static/js/table.js
>+++ b/bitbake/lib/toaster/toastergui/static/js/table.js
>@@ -219,6 +219,17 @@ function tableInit(ctx){
> var title = $('<a href=\"#\" ></a>');
>
> title.data('field-name', col.field_name);
>+
>+ // track the direction of the ordering to apply when this column
>+ // is clicked (desc/asc); this enables us to apply the correct
>+ // orderby direction if the sort reverts to the default, e.g.
>+ // when the current column being used for sorting is hidden
>+ var direction = 'asc';
>+ if ('-' + col.field_name === tableData.default_orderby) {
>+ direction = 'desc';
>+ }
>+ title.attr('data-orderby-direction', direction);
>+
> title.text(col.title);
> title.click(sortColumnClicked);
>
>@@ -239,10 +250,12 @@ function tableInit(ctx){
> }
> }
>
>- if (col.field_name === tableData.default_orderby){
>- title.addClass("default-orderby");
>- }
>-
>+ // remove leading "-" (used for reverse default orderby)
>+ var default_orderby = tableData.default_orderby;
>+ default_orderby = default_orderby.replace(/^\-/, "");
>+ if (col.field_name === default_orderby){
>+ title.addClass("default-orderby");
>+ }
> } else {
> /* Not orderable */
> header.css("font-weight", "normal");
>@@ -346,19 +359,36 @@ function tableInit(ctx){
> function sortColumnClicked(e){
> e.preventDefault();
>
>+ var fieldName = $(this).data('field-name');
>+ var alreadySorted = $(this).hasClass('sorted');
>+
> /* We only have one sort at a time so remove any existing sort
>indicators */
> $("#"+ctx.tableName+" th .icon-caret-down").hide();
> $("#"+ctx.tableName+" th .icon-caret-up").hide();
> $("#"+ctx.tableName+" th a").removeClass("sorted");
>
>- var fieldName = $(this).data('field-name');
>+ var sortDescending = false;
>
>- /* if we're already sorted sort the other way */
>- if (tableParams.orderby === fieldName &&
>- tableParams.orderby.indexOf('-') === -1) {
>+ if (alreadySorted) {
>+ // if we're already sorted by this column, sort the other way
>+ if (tableParams.orderby.indexOf('-') === -1) {
>+ // currently sorted in ascending order, so reverse it
>+ sortDescending = true;
>+ }
>+ }
>+ else {
>+ // set the sort order according to the default sort order for this
>field
>+ if ($(this).attr('data-orderby-direction') === 'desc') {
>+ sortDescending = true;
>+ }
>+ }
>+
>+ // apply the sort
>+ if (sortDescending) {
> tableParams.orderby = '-' + $(this).data('field-name');
> $(this).parent().children('.icon-caret-up').show();
>- } else {
>+ }
>+ else {
> tableParams.orderby = $(this).data('field-name');
> $(this).parent().children('.icon-caret-down').show();
> }
>--
>1.9.3
>
>---------------------------------------------------------------------
>Intel Corporation (UK) Limited
>Registered No. 1134945 (England)
>Registered Office: Pipers Way, Swindon SN3 1RJ
>VAT No: 860 2173 47
>
>This e-mail and any attachments may contain confidential material for
>the sole use of the intended recipient(s). Any review or distribution
>by others is strictly prohibited. If you are not the intended
>recipient, please contact the sender and delete all copies.
>
>--
>_______________________________________________
>toaster mailing list
>toaster at yoctoproject.org
>https://lists.yoctoproject.org/listinfo/toaster
More information about the toaster
mailing list