Skip to content

Commit 8291d93

Browse files
authored
🎨 [Frontend] Functions Browser: sorting (#8267)
1 parent b5836c9 commit 8291d93

File tree

9 files changed

+82
-89
lines changed

9 files changed

+82
-89
lines changed

services/static-webserver/client/source/class/osparc/dashboard/SearchBarFilterExtended.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,18 @@ qx.Class.define("osparc.dashboard.SearchBarFilterExtended", {
177177

178178
const contextDropDown = this.getChildControl("context-drop-down");
179179
this.getChildControl("my-projects-button");
180-
this.getChildControl("templates-button");
181-
this.getChildControl("public-projects-button");
182-
this.getChildControl("functions-button");
180+
if (osparc.product.Utils.showTemplates()) {
181+
this.getChildControl("templates-button");
182+
}
183+
if (osparc.product.Utils.showPublicProjects()) {
184+
this.getChildControl("public-projects-button");
185+
}
186+
if (osparc.product.Utils.showFunctions()) {
187+
this.getChildControl("functions-button");
188+
}
189+
if (contextDropDown.getChildren().length === 1) {
190+
contextDropDown.hide();
191+
}
183192
contextDropDown.addListener("changeSelection", e => {
184193
const selection = e.getData();
185194
if (selection.length) {

services/static-webserver/client/source/class/osparc/dashboard/SortedByMenuButton.js

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,21 @@ qx.Class.define("osparc.dashboard.SortedByMenuButton", {
3434
this.setMenu(sortedByMenu);
3535

3636
const options = this.self().getSortByOptions();
37-
3837
options.forEach((option, idx) => {
39-
const btn = new qx.ui.menu.Button();
40-
btn.btnId = option.id;
41-
btn.set({
42-
label: option.label,
43-
icon: null
44-
});
38+
const btn = new qx.ui.menu.Button(option.label);
39+
btn.field = option.id;
4540
// Sort by last modified date
4641
if (idx === options.length -1) {
47-
this.__menuButton = btn;
42+
this.__selectedMenuButton = btn;
4843
btn.setIcon("@FontAwesome5Solid/arrow-down/14");
4944
}
5045
sortedByMenu.add(btn);
5146

52-
btn.addListener("execute", () => {
53-
this.__buttonExecuted(btn)
54-
});
47+
btn.addListener("execute", () => this.__buttonExecuted(btn));
5548
});
56-
57-
this.addListener("changeSort", e => {
58-
const sort = e.getData();
59-
this.__handelSortEvent(sort)
60-
}, this);
6149
},
6250

6351
statics: {
64-
DefaultSorting: {
65-
field: "last_change_date",
66-
direction: "desc"
67-
},
68-
6952
getSortByOptions: function() {
7053
return [{
7154
id: "name",
@@ -96,45 +79,40 @@ qx.Class.define("osparc.dashboard.SortedByMenuButton", {
9679
},
9780
nullable: false,
9881
event: "changeSort",
99-
apply: "__applySort"
82+
apply: "__handelSortEvent",
10083
}
10184
},
10285

10386
members: {
104-
__menuButton: null,
87+
__selectedMenuButton: null,
88+
10589
__buttonExecuted: function(btn) {
106-
if (this.__menuButton) {
107-
this.__menuButton.setIcon(null);
90+
if (this.__selectedMenuButton) {
91+
this.__selectedMenuButton.setIcon(null);
10892
}
109-
this.__menuButton = btn;
93+
this.__selectedMenuButton = btn;
11094
this.set({
11195
label: btn.getLabel(),
11296
icon: "@FontAwesome5Solid/chevron-down/10"
11397
});
11498

115-
const data = {
116-
"id": btn.btnId,
117-
};
118-
this.__handelSort(data.id);
119-
},
120-
121-
__handelSort: function(field) {
99+
const field = btn.field;
122100
if (field === this.getSort().field) {
123101
const { direction } = this.getSort();
124102
this.setSort({
125103
field,
126104
direction: !direction
127-
})
128-
return;
105+
});
106+
} else {
107+
this.setSort({
108+
field,
109+
direction: true
110+
});
129111
}
130-
this.setSort({
131-
field,
132-
direction: true
133-
})
134112
},
135113

136114
__handelSortEvent: function({field, direction}) {
137-
this.__menuButton.setIcon(direction ? "@FontAwesome5Solid/arrow-down/14" : "@FontAwesome5Solid/arrow-up/14")
115+
this.__selectedMenuButton.setIcon(direction ? "@FontAwesome5Solid/arrow-down/14" : "@FontAwesome5Solid/arrow-up/14")
138116
this.setIcon(direction ? "@FontAwesome5Solid/arrow-down/14" : "@FontAwesome5Solid/arrow-up/14")
139117
const sort = {
140118
field: field,
@@ -143,8 +121,15 @@ qx.Class.define("osparc.dashboard.SortedByMenuButton", {
143121
this.fireDataEvent("sortByChanged", sort);
144122
},
145123

146-
__applySort: function(value, old) {
124+
hideOptionButton: function(field) {
125+
const btn = this.getMenu().getChildren().find(btn => btn.field === field);
126+
if (btn) {
127+
btn.exclude();
128+
}
129+
},
147130

148-
}
131+
showAllOptions: function() {
132+
this.getMenu().getChildren().forEach(btn => btn.show());
133+
},
149134
}
150135
});

services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,12 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
806806
currentParams[key] = value;
807807
}
808808
});
809+
if ([
810+
osparc.dashboard.StudyBrowser.CONTEXT.FUNCTIONS,
811+
osparc.dashboard.StudyBrowser.CONTEXT.SEARCH_FUNCTIONS,
812+
].includes(this.getCurrentContext())) {
813+
currentParams.orderBy = osparc.store.Functions.curateOrderBy(currentParams.orderBy);
814+
}
809815

810816
// check the entries in currentParams are the same as the reqParams
811817
let sameContext = true;
@@ -890,7 +896,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
890896
break;
891897
case osparc.dashboard.StudyBrowser.CONTEXT.FUNCTIONS:
892898
case osparc.dashboard.StudyBrowser.CONTEXT.SEARCH_FUNCTIONS:
893-
delete requestParams.orderBy; // functions do not support ordering yet
894899
requestParams.includeExtras = "true";
895900
break;
896901
case osparc.dashboard.StudyBrowser.CONTEXT.SEARCH_PROJECTS: {
@@ -972,7 +977,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
972977
},
973978

974979
invalidateFunctions: function() {
975-
osparc.store.Functions.invalidateFunctions();
976980
this.__resetStudiesList();
977981
if (this._resourcesContainer.getFlatList()) {
978982
this._resourcesContainer.getFlatList().nextRequest = null;
@@ -1360,8 +1364,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
13601364
this._searchBarFilter.setEnabled(true);
13611365
// workspaces will exclude it
13621366
this._toolbar.show();
1363-
// functions will exclude it
1364-
this.__sortByButton.show();
1367+
// functions will hide some option
1368+
this.__sortByButton.showAllOptions();
13651369

13661370
switch (this.getCurrentContext()) {
13671371
case osparc.dashboard.StudyBrowser.CONTEXT.PROJECTS:
@@ -1413,8 +1417,9 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
14131417
this._searchBarFilter.resetFilters();
14141418
}
14151419
this._searchBarFilter.getChildControl("text-field").setPlaceholder("Search in Functions");
1416-
// functions can't be sorted yet
1417-
this.__sortByButton.exclude();
1420+
// functions don't support all options yet
1421+
this.__sortByButton.hideOptionButton("name");
1422+
this.__sortByButton.hideOptionButton("prj_owner");
14181423
this._loadingResourcesBtn.setFetching(false);
14191424
this.invalidateFunctions();
14201425
this.__reloadStudies();

services/static-webserver/client/source/class/osparc/data/Resources.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,11 @@ qx.Class.define("osparc.data.Resources", {
634634
},
635635
getPage: {
636636
method: "GET",
637-
url: statics.API + "/functions?include_extras=true&offset={offset}&limit={limit}"
637+
url: statics.API + "/functions?include_extras=true&offset={offset}&limit={limit}&order_by={orderBy}"
638638
},
639639
getPageSearch: {
640640
method: "GET",
641-
url: statics.API + "/functions?include_extras=true&offset={offset}&limit={limit}&search={text}"
641+
url: statics.API + "/functions?include_extras=true&offset={offset}&limit={limit}&search={text}&order_by={orderBy}"
642642
},
643643
create: {
644644
method: "POST",

services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,11 @@ qx.Class.define("osparc.navigation.NavigationBar", {
378378
// quick starts and manuals
379379
osparc.store.Support.addQuickStartToMenu(menu);
380380
osparc.store.Support.addGuidedToursToMenu(menu);
381-
osparc.store.Support.addManualButtonsToMenu(menu, menuButton);
381+
osparc.store.Support.addManualsToMenu(menu);
382382
menu.addSeparator();
383383

384384
// feedback
385-
osparc.store.Support.addSupportButtonsToMenu(menu, menuButton);
385+
osparc.store.Support.addSupportButtonsToMenu(menu);
386386
osparc.store.Support.addReleaseNotesToMenu(menu);
387387

388388
return menuButton;

services/static-webserver/client/source/class/osparc/navigation/UserMenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ qx.Class.define("osparc.navigation.UserMenu", {
215215
// quick starts and manuals
216216
osparc.store.Support.addQuickStartToMenu(this);
217217
osparc.store.Support.addGuidedToursToMenu(this);
218-
osparc.store.Support.addManualButtonsToMenu(this);
218+
osparc.store.Support.addManualsToMenu(this);
219219
this.addSeparator();
220220

221221
// feedbacks

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ qx.Class.define("osparc.store.Functions", {
1919
type: "static",
2020

2121
statics: {
22-
__functions: null,
23-
__functionsPromiseCached: null,
24-
2522
__createFunctionData: function(templateData, name, description, defaultInputs = {}, exposedInputs = {}, exposedOutputs = {}) {
2623
const functionData = {
2724
"projectId": templateData["uuid"],
@@ -101,7 +98,10 @@ qx.Class.define("osparc.store.Functions", {
10198
curatedOrderBy.field = "created_at";
10299
break;
103100
case "name":
104-
// stays the same
101+
// Backend does not currently support sorting by 'name'.
102+
// Fallback: sort by 'modified_at' instead.
103+
// TODO: Remove this workaround once backend supports sorting by 'name'.
104+
curatedOrderBy.field = "modified_at";
105105
break;
106106
default:
107107
// only those three are supported
@@ -223,12 +223,5 @@ qx.Class.define("osparc.store.Functions", {
223223
throw err;
224224
});
225225
},
226-
227-
invalidateFunctions: function() {
228-
this.__functions = null;
229-
if (this.__functionsPromiseCached) {
230-
this.__functionsPromiseCached = null;
231-
}
232-
},
233226
}
234227
});

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,35 @@ qx.Class.define("osparc.store.Support", {
7575
}
7676
},
7777

78-
addManualButtonsToMenu: function(menu, menuButton) {
78+
addManualsToMenu: function(menu) {
7979
const manuals = osparc.store.Support.getManuals();
80-
if (menuButton) {
81-
menuButton.setVisibility(manuals && manuals.length ? "visible" : "excluded");
82-
}
83-
manuals.forEach(manual => {
84-
const manualBtn = new qx.ui.menu.Button(manual.label, "@FontAwesome5Solid/book/14");
85-
manualBtn.getChildControl("label").set({
86-
rich: true
80+
const addManuals = mn => {
81+
manuals.forEach(manual => {
82+
const manualBtn = new qx.ui.menu.Button(manual.label, "@FontAwesome5Solid/book/14");
83+
manualBtn.getChildControl("label").set({
84+
rich: true
85+
});
86+
manualBtn.addListener("execute", () => window.open(manual.url), this);
87+
mn.add(manualBtn);
8788
});
88-
manualBtn.addListener("execute", () => window.open(manual.url), this);
89-
menu.add(manualBtn);
90-
});
89+
};
90+
if (manuals.length > 1) {
91+
// if there are more than 1 manuals, add them in their own menu
92+
const ownMenu = new qx.ui.menu.Menu().set({
93+
appearance: "menu-wider",
94+
});
95+
const manualsBtn = new qx.ui.menu.Button(qx.locale.Manager.tr("Manuals"), "@FontAwesome5Solid/book/14");
96+
manualsBtn.setMenu(ownMenu);
97+
menu.add(manualsBtn);
98+
addManuals(ownMenu);
99+
} else {
100+
addManuals(menu);
101+
}
91102
},
92103

93-
addSupportButtonsToMenu: function(menu, menuButton) {
104+
addSupportButtonsToMenu: function(menu) {
94105
const issues = osparc.store.VendorInfo.getIssues();
95106
const supports = osparc.store.VendorInfo.getSupports();
96-
if (menuButton) {
97-
menuButton.setVisibility(issues.length || supports.length ? "visible" : "excluded");
98-
}
99107
issues.forEach(issueInfo => {
100108
const label = issueInfo["label"];
101109
const issueButton = new qx.ui.menu.Button(label, "@FontAwesome5Solid/comments/14");

services/static-webserver/client/source/class/osparc/vipMarket/SortModelsButtons.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ qx.Class.define("osparc.vipMarket.SortModelsButtons", {
7777
"sortBy": "qx.event.type.Data"
7878
},
7979

80-
statics: {
81-
DefaultSorting: {
82-
"sort": "name",
83-
"order": "down"
84-
}
85-
},
86-
8780
members: {
8881
__buttonExecuted: function(btn) {
8982
this.set({

0 commit comments

Comments
 (0)