Skip to content

Commit 35b3cb4

Browse files
committed
sort sub-runs
1 parent 81d8bed commit 35b3cb4

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ qx.Class.define("osparc.jobs.SubRunsTableModel", {
2727
const colIDs = Object.values(subJobsCols).map(col => col.id);
2828
this.setColumns(colLabels, colIDs);
2929

30-
this.setSortColumnIndexWithoutSortingData(subJobsCols.START.column); // It can only be sorted by started_at
30+
this.setSortColumnIndexWithoutSortingData(subJobsCols.START.column);
3131
this.setSortAscendingWithoutSortingData(false);
3232
Object.values(subJobsCols).forEach(col => {
33-
this.setColumnSortable(col.column, false);
33+
this.setColumnSortable(col.column, Boolean(col.sortableMap));
3434
});
3535

3636
this.setProjectUuid(projectUuid);
@@ -47,12 +47,31 @@ qx.Class.define("osparc.jobs.SubRunsTableModel", {
4747
init: false,
4848
event: "changeFetching"
4949
},
50+
51+
orderBy: {
52+
check: "Object",
53+
init: {
54+
field: "started_at", // started_at
55+
direction: "desc"
56+
}
57+
},
5058
},
5159

5260
members: {
61+
// overridden
62+
sortByColumn(columnIndex, ascending) {
63+
const subJobsCols = osparc.jobs.SubRunsTable.COLS;
64+
const colInfo = Object.values(subJobsCols).find(col => col.column === columnIndex);
65+
this.setOrderBy({
66+
field: colInfo.sortableMap,
67+
direction: ascending ? "asc" : "desc"
68+
})
69+
this.base(arguments, columnIndex, ascending)
70+
},
71+
5372
// overridden
5473
_loadRowCount() {
55-
osparc.store.Jobs.getInstance().fetchSubJobs(this.getProjectUuid())
74+
osparc.store.Jobs.getInstance().fetchSubJobs(this.getProjectUuid(), this.getOrderBy())
5675
.then(subJobs => {
5776
this._onRowCountLoaded(subJobs.length)
5877
})
@@ -68,7 +87,7 @@ qx.Class.define("osparc.jobs.SubRunsTableModel", {
6887
const lastRow = Math.min(qxLastRow, this._rowCount - 1);
6988
// Returns a request promise with given offset and limit
7089
const getFetchPromise = () => {
71-
return osparc.store.Jobs.getInstance().fetchSubJobs(this.getProjectUuid())
90+
return osparc.store.Jobs.getInstance().fetchSubJobs(this.getProjectUuid(), this.getOrderBy())
7291
.then(subJobs => {
7392
const data = [];
7493
const subJobsCols = osparc.jobs.SubRunsTable.COLS;

services/static-webserver/client/source/class/osparc/store/Jobs.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,17 @@ qx.Class.define("osparc.store.Jobs", {
119119
.catch(err => console.error(err));
120120
},
121121

122-
fetchSubJobs: function(projectUuid) {
122+
fetchSubJobs: function(
123+
projectUuid,
124+
orderBy = {
125+
field: "started_at",
126+
direction: "desc"
127+
},
128+
) {
123129
const params = {
124130
url: {
125131
studyId: projectUuid,
132+
orderBy: JSON.stringify(orderBy),
126133
includeChildren: false,
127134
}
128135
};

0 commit comments

Comments
 (0)