Skip to content

Commit 88abc43

Browse files
committed
filterJobs in the frontend
1 parent 332ef05 commit 88abc43

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

services/static-webserver/client/source/class/osparc/jobs/JobsBrowser.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ qx.Class.define("osparc.jobs.JobsBrowser", {
2424

2525
this._setLayout(new qx.ui.layout.VBox(10));
2626

27-
this.getChildControl("jobs-filter");
27+
const jobsFilter = this.getChildControl("jobs-filter");
2828
this.getChildControl("jobs-ongoing");
29-
this.getChildControl("jobs-table");
29+
const jobsTable = this.getChildControl("jobs-table");
30+
31+
jobsFilter.getChildControl("textfield").addListener("input", e => {
32+
const filterText = e.getData();
33+
jobsTable.getTableModel().setFilters({
34+
text: filterText,
35+
});
36+
});
3037
},
3138

3239
statics: {

services/static-webserver/client/source/class/osparc/jobs/JobsTableModel.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)