Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 9D60FE00E27; Fri, 22 Apr 2016 05:39:54 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high * trust * [134.134.136.65 listed in list.dnswl.org] Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 3BEE7E00CC3 for ; Fri, 22 Apr 2016 05:39:52 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 22 Apr 2016 05:39:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,517,1455004800"; d="scan'208";a="937987021" Received: from irsmsx105.ger.corp.intel.com ([163.33.3.28]) by orsmga001.jf.intel.com with ESMTP; 22 Apr 2016 05:39:31 -0700 Received: from irsmsx110.ger.corp.intel.com ([169.254.15.10]) by irsmsx105.ger.corp.intel.com ([169.254.7.35]) with mapi id 14.03.0248.002; Fri, 22 Apr 2016 13:39:29 +0100 From: "Barros Pena, Belen" To: "Smith, Elliot" , "toaster@yoctoproject.org" Thread-Topic: [Toaster] [PATCH] toaster: correctly revert to default sort when column is hidden Thread-Index: AQHRnJQDEGkyYpp3/U2BpjKRs+OFVg== Date: Fri, 22 Apr 2016 12:39:29 +0000 Message-ID: References: <1461324871-12091-1-git-send-email-elliot.smith@intel.com> In-Reply-To: <1461324871-12091-1-git-send-email-elliot.smith@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/14.6.3.160329 x-originating-ip: [10.252.12.74] MIME-Version: 1.0 Subject: Re: [PATCH] toaster: correctly revert to default sort when column is hidden X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Apr 2016 12:39:54 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-ID: <7582181995691543AC3D7ABAC6DD13D1@intel.com> Content-Transfer-Encoding: quoted-printable On 22/04/2016 12:34, "toaster-bounces@yoctoproject.org on behalf of Elliot Smith" 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=E9n > >Signed-off-by: Elliot Smith >--- > 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 =3D $(''); >=20 > 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 =3D 'asc'; >+ if ('-' + col.field_name =3D=3D=3D tableData.default_orderby) { >+ direction =3D 'desc'; >+ } >+ title.attr('data-orderby-direction', direction); >+ > title.text(col.title); > title.click(sortColumnClicked); >=20 >@@ -239,10 +250,12 @@ function tableInit(ctx){ > } > } >=20 >- if (col.field_name =3D=3D=3D tableData.default_orderby){ >- title.addClass("default-orderby"); >- } >- >+ // remove leading "-" (used for reverse default orderby) >+ var default_orderby =3D tableData.default_orderby; >+ default_orderby =3D default_orderby.replace(/^\-/, ""); >+ if (col.field_name =3D=3D=3D 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(); >=20 >+ var fieldName =3D $(this).data('field-name'); >+ var alreadySorted =3D $(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"); >=20 >- var fieldName =3D $(this).data('field-name'); >+ var sortDescending =3D false; >=20 >- /* if we're already sorted sort the other way */ >- if (tableParams.orderby =3D=3D=3D fieldName && >- tableParams.orderby.indexOf('-') =3D=3D=3D -1) { >+ if (alreadySorted) { >+ // if we're already sorted by this column, sort the other way >+ if (tableParams.orderby.indexOf('-') =3D=3D=3D -1) { >+ // currently sorted in ascending order, so reverse it >+ sortDescending =3D true; >+ } >+ } >+ else { >+ // set the sort order according to the default sort order for this >field >+ if ($(this).attr('data-orderby-direction') =3D=3D=3D 'desc') { >+ sortDescending =3D true; >+ } >+ } >+ >+ // apply the sort >+ if (sortDescending) { > tableParams.orderby =3D '-' + $(this).data('field-name'); > $(this).parent().children('.icon-caret-up').show(); >- } else { >+ } >+ else { > tableParams.orderby =3D $(this).data('field-name'); > $(this).parent().children('.icon-caret-down').show(); > } >--=20 >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. > >--=20 >_______________________________________________ >toaster mailing list >toaster@yoctoproject.org >https://lists.yoctoproject.org/listinfo/toaster