@@ -40,17 +40,18 @@ qx.Class.define("osparc.jobs.JobsTableModel", {
4040 } ,
4141
4242 properties : {
43- filters : {
44- check : "Object" ,
45- init : null
46- } ,
47-
4843 isFetching : {
4944 check : "Boolean" ,
5045 init : false ,
5146 event : "changeFetching"
5247 } ,
5348
49+ filters : {
50+ check : "Object" ,
51+ init : null ,
52+ apply : "reloadData" , // force reload
53+ } ,
54+
5455 orderBy : {
5556 check : "Object" ,
5657 init : {
@@ -68,6 +69,31 @@ qx.Class.define("osparc.jobs.JobsTableModel", {
6869 } ,
6970
7071 members : {
72+ // this should be done by the backend
73+ __filterJobs : function ( jobs ) {
74+ const filters = this . getFilters ( ) ;
75+ return jobs . filter ( job => {
76+ if ( filters ) {
77+ let match = false ;
78+ [
79+ "jobId" ,
80+ "solver" ,
81+ "status" ,
82+ "instance" ,
83+ ] . forEach ( filterableField => {
84+ const getter = "get" + qx . lang . String . firstUp ( filterableField ) ;
85+ const value = job [ getter ] ( ) ;
86+ // lowercase both
87+ if ( ! match && value && value . toLowerCase ( ) . includes ( filters . text . toLowerCase ( ) ) ) {
88+ match = true ;
89+ }
90+ } ) ;
91+ return match ;
92+ }
93+ return true ;
94+ } ) ;
95+ } ,
96+
7197 // overridden
7298 sortByColumn ( columnIndex , ascending ) {
7399 this . setOrderBy ( {
@@ -94,7 +120,8 @@ qx.Class.define("osparc.jobs.JobsTableModel", {
94120 } ;
95121 osparc . store . Jobs . getInstance ( ) . fetchJobs ( urlParams , options )
96122 . then ( jobs => {
97- this . _onRowCountLoaded ( jobs . length ) ;
123+ const filteredJobs = this . __filterJobs ( jobs ) ;
124+ this . _onRowCountLoaded ( filteredJobs . length ) ;
98125 } )
99126 . catch ( ( ) => this . _onRowCountLoaded ( null ) ) ;
100127 } ,
@@ -118,9 +145,10 @@ qx.Class.define("osparc.jobs.JobsTableModel", {
118145 } ;
119146 return osparc . store . Jobs . getInstance ( ) . fetchJobs ( urlParams )
120147 . then ( jobs => {
148+ const filteredJobs = this . __filterJobs ( jobs ) ;
121149 const data = [ ] ;
122150 const jobsCols = osparc . jobs . JobsTable . COLS ;
123- jobs . forEach ( job => {
151+ filteredJobs . forEach ( job => {
124152 data . push ( {
125153 [ jobsCols . JOB_ID . id ] : job . getJobId ( ) ,
126154 [ jobsCols . SOLVER . id ] : job . getSolver ( ) ,
0 commit comments