Skip to content

Commit 342f7a7

Browse files
authored
🎨 [Frontend] Enh UX: Number of Active Jobs (#8061)
1 parent 80cde20 commit 342f7a7

File tree

6 files changed

+108
-27
lines changed

6 files changed

+108
-27
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,13 +790,15 @@ qx.Class.define("osparc.dashboard.CardBase", {
790790
}
791791
},
792792

793-
// pipelineState: ["NOT_STARTED", "STARTED", "SUCCESS", "ABORTED", "FAILED", "UNKNOWN"]
793+
// pipelineState: ["NOT_STARTED", "PUBLISHED", "STOPPING", "STARTED", "SUCCESS", "ABORTED", "FAILED", "UNKNOWN"]
794794
__applyPipelineState: function(pipelineState) {
795795
let iconSource;
796796
let toolTipText;
797797
let borderColor;
798798
switch (pipelineState) {
799+
case "PUBLISHED":
799800
case "STARTED":
801+
case "STOPPING":
800802
iconSource = "@FontAwesome5Solid/spinner/10";
801803
toolTipText = this.tr("Running");
802804
borderColor = "info";

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

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ qx.Class.define("osparc.jobs.JobsButton", {
3232
toolTipText: this.tr("Activity Center"),
3333
});
3434

35-
this.addListener("tap", () => osparc.jobs.ActivityCenterWindow.openWindow(), this);
36-
37-
const jobsStore = osparc.store.Jobs.getInstance();
38-
jobsStore.addListener("changeJobsActive", e => this.__updateJobsButton(e.getData()), this);
39-
jobsStore.fetchJobsLatest();
35+
this.addListener("tap", () => {
36+
osparc.jobs.ActivityCenterWindow.openWindow();
37+
this.__fetchNJobs();
38+
}, this);
39+
40+
this.__fetchNJobs();
41+
42+
const socket = osparc.wrapper.WebSocket.getInstance();
43+
if (socket.isConnected()) {
44+
this.__attachSocketListener();
45+
} else {
46+
socket.addListener("connect", () => this.__attachSocketListener());
47+
}
4048
},
4149

4250
members: {
@@ -56,29 +64,83 @@ qx.Class.define("osparc.jobs.JobsButton", {
5664
});
5765
break;
5866
}
59-
case "number":
60-
control = new qx.ui.basic.Label().set({
61-
backgroundColor: "background-main-1",
62-
font: "text-12"
67+
case "is-active-icon-outline":
68+
control = new qx.ui.basic.Image("@FontAwesome5Solid/circle/12").set({
69+
textColor: osparc.navigation.NavigationBar.BG_COLOR,
70+
});
71+
this._add(control, {
72+
bottom: 10,
73+
right: 2
6374
});
64-
control.getContentElement().setStyles({
65-
"border-radius": "4px"
75+
break;
76+
case "is-active-icon":
77+
control = new qx.ui.basic.Image("@FontAwesome5Solid/circle/8").set({
78+
textColor: "strong-main",
6679
});
6780
this._add(control, {
68-
bottom: 8,
81+
bottom: 12,
6982
right: 4
7083
});
7184
break;
7285
}
7386
return control || this.base(arguments, id);
7487
},
7588

76-
__updateJobsButton: function(nActiveJobs) {
89+
__fetchNJobs: function() {
90+
const jobsStore = osparc.store.Jobs.getInstance();
91+
const runningOnly = true;
92+
const offset = 0;
93+
const limit = 1;
94+
const orderBy = undefined; // use default order
95+
const filters = undefined; // use default filters
96+
const resolveWResponse = true;
97+
jobsStore.fetchJobsLatest(runningOnly, offset, limit, orderBy, filters, resolveWResponse)
98+
.then(resp => {
99+
// here we have the real number of jobs running
100+
this.__updateJobsButton(Boolean(resp["_meta"]["total"]));
101+
});
102+
},
103+
104+
__attachSocketListener: function() {
105+
const socket = osparc.wrapper.WebSocket.getInstance();
106+
107+
socket.on("projectStateUpdated", content => {
108+
// for now, we can only access the activity of my user, not the whole project...
109+
if (osparc.study.Utils.amIRunningTheStudy(content)) {
110+
// we know that I am running at least one study
111+
this.__updateJobsButton(true);
112+
}
113+
// ...in the next iteration: listen to main store's "studyStateChanged", which will cover all users
114+
}, this);
115+
},
116+
117+
__updateJobsButton: function(isActive) {
77118
this.getChildControl("icon");
78-
const number = this.getChildControl("number");
119+
[
120+
this.getChildControl("is-active-icon-outline"),
121+
this.getChildControl("is-active-icon"),
122+
].forEach(control => {
123+
control.set({
124+
visibility: isActive ? "visible" : "excluded"
125+
});
126+
});
127+
128+
// Start or restart timer when isActive is true
129+
if (isActive) {
130+
this.__startRefreshTimer();
131+
}
132+
},
133+
134+
__startRefreshTimer: function() {
135+
// Stop existing timer if running
136+
if (this.__refreshTimer) {
137+
this.__refreshTimer.stop();
138+
this.__refreshTimer.dispose();
139+
}
79140

80-
const nJobs = nActiveJobs > osparc.store.Jobs.SERVER_MAX_LIMIT ? (osparc.store.Jobs.SERVER_MAX_LIMIT + "+") : nActiveJobs;
81-
number.setValue(nJobs.toString());
141+
this.__refreshTimer = new qx.event.Timer(20000);
142+
this.__refreshTimer.addListener("interval", () => this.__fetchNJobs(), this);
143+
this.__refreshTimer.start();
82144
},
83145
}
84146
});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ qx.Class.define("osparc.navigation.NavigationBar", {
5050
paddingLeft: 10,
5151
paddingRight: 10,
5252
height: this.self().HEIGHT,
53-
backgroundColor: "background-main-1",
53+
backgroundColor: this.self().BG_COLOR,
5454
});
5555

5656
osparc.utils.Utils.setIdToWidget(this, "navigationBar");
@@ -72,6 +72,7 @@ qx.Class.define("osparc.navigation.NavigationBar", {
7272
},
7373

7474
statics: {
75+
BG_COLOR: "background-main-1",
7576
HEIGHT: 50,
7677
SMALL_SCREEN_BREAKPOINT: 800,
7778

@@ -353,7 +354,7 @@ qx.Class.define("osparc.navigation.NavigationBar", {
353354
const readOnlyInfo = this.getChildControl("read-only-info")
354355
if (study) {
355356
this.getChildControl("study-title-options").setStudy(study);
356-
study.bind("savePending", readOnlyInfo, "visibility", {
357+
study.bind("savePending", savingStudyIcon, "visibility", {
357358
converter: value => value && ["workbench", "pipeline"].includes(study.getUi().getMode()) ? "visible" : "excluded"
358359
});
359360
study.bind("readOnly", readOnlyInfo, "visibility", {

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ qx.Class.define("osparc.store.Jobs", {
2828
},
2929
},
3030

31-
events: {
32-
"changeJobsActive": "qx.event.type.Data",
33-
},
34-
3531
statics: {
3632
SERVER_MAX_LIMIT: 49,
3733
},
@@ -62,9 +58,6 @@ qx.Class.define("osparc.store.Jobs", {
6258
};
6359
return osparc.data.Resources.fetch("runs", "getPageLatest", params, options)
6460
.then(jobsResp => {
65-
if (runningOnly) {
66-
this.fireDataEvent("changeJobsActive", jobsResp["_meta"]["total"]);
67-
}
6861
const jobsActive = [];
6962
if ("data" in jobsResp) {
7063
jobsResp["data"].forEach(jobActiveData => {

services/static-webserver/client/source/class/osparc/study/Utils.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,29 @@ qx.Class.define("osparc.study.Utils", {
397397
return null;
398398
},
399399

400+
// used in the "projectStateUpdated" socket event
401+
amIRunningTheStudy: function(content) {
402+
if (
403+
content &&
404+
"data" in content &&
405+
"locked" in content["data"] &&
406+
"owner" in content["data"]["locked"] &&
407+
"user_id" in content["data"]["locked"]["owner"] &&
408+
content["data"]["locked"]["owner"]["user_id"] === osparc.auth.Data.getInstance().getUserId()
409+
) {
410+
return (
411+
content["data"]["state"] &&
412+
content["data"]["state"]["value"] &&
413+
[
414+
"PUBLISHED",
415+
"STARTED",
416+
"STOPPING",
417+
].includes(content["data"]["state"]["value"])
418+
);
419+
}
420+
return false;
421+
},
422+
400423
__getBlockedState: function(studyData) {
401424
if (studyData["services"] === null) {
402425
return "UNKNOWN_SERVICES";

services/static-webserver/client/source/class/osparc/task/TasksButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ qx.Class.define("osparc.task.TasksButton", {
5656
}
5757
case "number":
5858
control = new qx.ui.basic.Label().set({
59-
backgroundColor: "background-main-1",
59+
backgroundColor: osparc.navigation.NavigationBar.BG_COLOR,
6060
paddingLeft: 4,
6161
font: "text-12"
6262
});

0 commit comments

Comments
 (0)