@@ -56,6 +56,7 @@ qx.Class.define("osparc.vipStore.VIPStore", {
5656 members : {
5757 __anatomicalModelsModel : null ,
5858 __anatomicalModels : null ,
59+ __sortByButton : null ,
5960
6061 __buildLayout : async function ( ) {
6162 const toolbarLayout = new qx . ui . container . Composite ( new qx . ui . layout . HBox ( 10 ) ) . set ( {
@@ -64,7 +65,7 @@ qx.Class.define("osparc.vipStore.VIPStore", {
6465 } ) ;
6566 this . _add ( toolbarLayout ) ;
6667
67- const sortModelsButtons = new osparc . vipStore . SortModelsButtons ( ) . set ( {
68+ const sortModelsButtons = this . __sortByButton = new osparc . vipStore . SortModelsButtons ( ) . set ( {
6869 alignY : "bottom" ,
6970 maxHeight : 27 ,
7071 } ) ;
@@ -73,7 +74,7 @@ qx.Class.define("osparc.vipStore.VIPStore", {
7374 const filter = new osparc . filter . TextFilter ( "text" , "vipModels" ) . set ( {
7475 alignY : "middle" ,
7576 allowGrowY : false ,
76- minWidth : 200 ,
77+ minWidth : 170 ,
7778 } ) ;
7879 this . addListener ( "appear" , ( ) => filter . getChildControl ( "textfield" ) . focus ( ) ) ;
7980 toolbarLayout . add ( filter ) ;
@@ -137,12 +138,11 @@ qx.Class.define("osparc.vipStore.VIPStore", {
137138 const resp = await fetch ( "https://itis.swiss/PD_DirectDownload/getDownloadableItems/AnatomicalModels" , { method :"POST" } ) ;
138139 const anatomicalModelsRaw = await resp . json ( ) ;
139140 this . __anatomicalModels = this . self ( ) . curateAnatomicalModels ( anatomicalModelsRaw ) ;
141+
140142 this . __populateModels ( ) ;
141143 } ,
142144
143145 __populateModels : function ( ) {
144- this . __anatomicalModelsModel . removeAll ( ) ;
145-
146146 const models = [ ] ;
147147 this . __anatomicalModels . forEach ( model => {
148148 const anatomicalModel = { } ;
@@ -152,8 +152,32 @@ qx.Class.define("osparc.vipStore.VIPStore", {
152152 anatomicalModel [ "date" ] = new Date ( model [ "Features" ] [ "date" ] ) ;
153153 models . push ( anatomicalModel ) ;
154154 } ) ;
155+
156+ this . __anatomicalModelsModel . removeAll ( ) ;
155157 models . sort ( ( a , b ) => a [ "name" ] . localeCompare ( b [ "name" ] ) ) ;
156158 models . forEach ( model => this . __anatomicalModelsModel . append ( qx . data . marshal . Json . createModel ( model ) ) ) ;
159+
160+ this . __sortByButton . addListener ( "sortBy" , e => {
161+ const sortBy = e . getData ( ) ;
162+ this . __anatomicalModelsModel . removeAll ( ) ;
163+ models . sort ( ( a , b ) => {
164+ if ( sortBy [ "sort" ] === "name" ) {
165+ if ( sortBy [ "orderBy" ] === "down" ) {
166+ return a [ "name" ] . localeCompare ( b [ "name" ] ) ;
167+ } else {
168+ return b [ "name" ] . localeCompare ( a [ "name" ] ) ;
169+ }
170+ } else if ( sortBy [ "sort" ] === "date" ) {
171+ if ( sortBy [ "orderBy" ] === "down" ) {
172+ return a [ "date" ] - b [ "date" ] ;
173+ } else {
174+ return b [ "date" ] - a [ "date" ] ;
175+ }
176+ }
177+ return a [ "name" ] . localeCompare ( b [ "name" ] ) ;
178+ } ) ;
179+ models . forEach ( model => this . __anatomicalModelsModel . append ( qx . data . marshal . Json . createModel ( model ) ) ) ;
180+ } , this ) ;
157181 } ,
158182 }
159183} ) ;
0 commit comments