Skip to content

Commit

Permalink
🐛 Frontend: Fix open issue (ITISFoundation#5818)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored May 16, 2024
1 parent 255431f commit a14ec1b
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 211 deletions.
113 changes: 59 additions & 54 deletions services/static-webserver/client/source/class/osparc/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,69 +315,74 @@ qx.Class.define("osparc.Application", {
view.addListener("done", () => this.__restart(), this);
},

__loadMainPage: async function(studyId = null) {
__loadMainPage: function(studyId = null) {
// logged in
const profile = await osparc.data.Resources.getOne("profile");
if (profile) {
this.__connectWebSocket();

if (osparc.auth.Data.getInstance().isGuest()) {
const msg = osparc.utils.Utils.createAccountMessage();
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
} else if ("expirationDate" in profile) {
const now = new Date();
const today = new Date(now.toISOString().slice(0, 10));
const expirationDay = new Date(profile["expirationDate"]);
const daysToExpiration = osparc.utils.Utils.daysBetween(today, expirationDay);
if (daysToExpiration < 7) {
const msg = osparc.utils.Utils.expirationMessage(daysToExpiration);
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
}
}
osparc.data.Resources.getOne("profile")
.then(profile => {
if (profile) {
this.__connectWebSocket();

if (osparc.auth.Data.getInstance().isGuest()) {
const msg = osparc.utils.Utils.createAccountMessage();
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
} else if ("expirationDate" in profile) {
const now = new Date();
const today = new Date(now.toISOString().slice(0, 10));
const expirationDay = new Date(profile["expirationDate"]);
const daysToExpiration = osparc.utils.Utils.daysBetween(today, expirationDay);
if (daysToExpiration < 7) {
const msg = osparc.utils.Utils.expirationMessage(daysToExpiration);
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
}
}

if ("preferences" in profile) {
const bePreferences = profile["preferences"];
const fePreferences = Object.keys(qx.util.PropertyUtil.getProperties(osparc.Preferences));
const preferencesSettings = osparc.Preferences.getInstance();
Object.entries(bePreferences).forEach(([key, data]) => {
const value = data.value;
switch (key) {
case "themeName":
if (value) {
preferencesSettings.setThemeName(value);
}
break;
case "preferredWalletId":
if (value) {
preferencesSettings.setPreferredWalletId(parseInt(value));
}
break;
default:
if (fePreferences.includes(key)) {
preferencesSettings.set(key, value);
if ("preferences" in profile) {
const bePreferences = profile["preferences"];
const fePreferences = Object.keys(qx.util.PropertyUtil.getProperties(osparc.Preferences));
const preferencesSettings = osparc.Preferences.getInstance();
Object.entries(bePreferences).forEach(([key, data]) => {
const value = data.value;
switch (key) {
case "themeName":
if (value) {
preferencesSettings.setThemeName(value);
}
break;
case "preferredWalletId":
if (value) {
preferencesSettings.setPreferredWalletId(parseInt(value));
}
break;
default:
if (fePreferences.includes(key)) {
preferencesSettings.set(key, value);
}
}
});
}
});
}

if (studyId) {
osparc.store.Store.getInstance().setCurrentStudyId(studyId);
}
if (studyId) {
osparc.store.Store.getInstance().setCurrentStudyId(studyId);
}

let mainPage = null;
if (osparc.product.Utils.getProductName().includes("s4ldesktop")) {
mainPage = new osparc.desktop.MainPageDesktop();
} else {
mainPage = new osparc.desktop.MainPage();
}
this.__mainPage = mainPage;
this.__loadView(mainPage);
}
let mainPage = null;
if (osparc.product.Utils.getProductName().includes("s4ldesktop")) {
mainPage = new osparc.desktop.MainPageDesktop();
} else {
mainPage = new osparc.desktop.MainPage();
}
this.__mainPage = mainPage;
this.__loadView(mainPage);
}
})
.catch(err => console.error(err));
},

__loadNodeViewerPage: async function(studyId, viewerNodeId) {
this.__connectWebSocket();
this.__loadView(new osparc.viewer.MainPage(studyId, viewerNodeId));
const mainPage = new osparc.viewer.MainPage(studyId, viewerNodeId);
this.__mainPage = mainPage;
this.__loadView(mainPage);
},

__loadView: function(view, opts, clearUrl=true) {
Expand All @@ -388,7 +393,7 @@ qx.Class.define("osparc.Application", {
right: 0,
...opts
};
this.assert(view!==null);

// Update root document and currentness
let doc = this.getRoot();
if (doc.hasChildren()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ qx.Class.define("osparc.auth.LoginPage", {
}
case "login-view": {
control = new osparc.auth.ui.LoginView();
control.addListener("done", msg => {
control.resetValues();
this.fireDataEvent("done", msg);
}, this);
this.getChildControl("pages-stack").add(control);
break;
}
Expand Down Expand Up @@ -249,12 +253,6 @@ qx.Class.define("osparc.auth.LoginPage", {
osparc.FlashMessenger.getInstance().logAs(this.tr("Your account has been created.<br>You can now use your credentials to login."));
}

// Transitions between pages
login.addListener("done", msg => {
login.resetValues();
this.fireDataEvent("done", msg);
}, this);

login.addListener("toRegister", () => {
pages.setSelection([registration]);
login.resetValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
construct: function() {
this.base(arguments);

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

this._showLoadingPage(this.tr("Starting..."));

this.addListener("appear", () => this._moreResourcesRequired());
Expand Down Expand Up @@ -184,7 +182,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
scroll.getChildControl("pane").addListener("scrollY", () => this._moreResourcesRequired(), this);
control = this._createLayout();
scroll.add(control);
this._add(scroll, {
this._addToMainLayout(scroll, {
flex: 1
});
break;
Expand All @@ -207,15 +205,15 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {

_createResourcesLayout: function() {
const topBar = this.__createTopBar();
this._add(topBar);
this._addToMainLayout(topBar);

const toolbar = this._toolbar = new qx.ui.toolbar.ToolBar().set({
backgroundColor: "transparent",
spacing: 10,
paddingRight: 8,
alignY: "middle"
});
this._add(toolbar);
this._addToMainLayout(toolbar);

this.__viewModeLayout = new qx.ui.toolbar.Part();

Expand All @@ -226,7 +224,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
resourcesContainer.addListener("publishTemplate", e => this.fireDataEvent("publishTemplate", e.getData()));
resourcesContainer.addListener("tagClicked", e => this._searchBarFilter.addTagActiveFilter(e.getData()));
resourcesContainer.addListener("emptyStudyClicked", e => this._deleteResourceRequested(e.getData()));
this._add(resourcesContainer);
this._addToMainLayout(resourcesContainer);
},

__createTopBar: function() {
Expand Down Expand Up @@ -329,12 +327,6 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
}
},

_showMainLayout: function(show) {
this._getChildren().forEach(children => {
children.setVisibility(show ? "visible" : "excluded");
});
},

_checkLoggedIn: function() {
let isLogged = osparc.auth.Manager.getInstance().isLoggedIn();
if (!isLogged) {
Expand Down Expand Up @@ -381,6 +373,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
},

_startStudyById: function(studyId, openCB, cancelCB, isStudyCreation = false) {
this._showLoadingPage(this.tr("Starting ") + osparc.product.Utils.getStudyAlias());
this.self().startStudyById(studyId, openCB, cancelCB, isStudyCreation);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ qx.Class.define("osparc.dashboard.ServiceBrowser", {
return;
}

this._showLoadingPage(this.tr("Creating Study"));
this._showLoadingPage(this.tr("Creating ") + osparc.product.Utils.getStudyAlias());
osparc.study.Utils.createStudyFromService(key, version)
.then(studyId => {
const openCB = () => this._hideLoadingPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ qx.Class.define("osparc.desktop.MainPage", {
members: {
__navBar: null,
__dashboard: null,
__dashboardLayout: null,
__loadingPage: null,
__studyEditor: null,

Expand Down Expand Up @@ -195,7 +194,7 @@ qx.Class.define("osparc.desktop.MainPage", {
const mainPageHandler = osparc.desktop.MainPageHandler.getInstance();
mainPageHandler.setStack(mainStack);

const dashboardLayout = this.__dashboardLayout = this.__createDashboardStack();
const dashboardLayout = this.__createDashboardLayout();
mainPageHandler.addDashboard(dashboardLayout);

const loadingPage = this.__loadingPage = new osparc.ui.message.Loading();
Expand All @@ -204,12 +203,10 @@ qx.Class.define("osparc.desktop.MainPage", {
const studyEditor = this.__studyEditor = this.__getStudyEditor();
mainPageHandler.addStudyEditor(studyEditor);

mainPageHandler.addListener("syncStudyEditor", e => this.__syncStudyEditor(e.getData()));

return mainStack;
},

__createDashboardStack: function() {
__createDashboardLayout: function() {
const dashboard = this.__dashboard = new osparc.dashboard.Dashboard();
const tabsBar = dashboard.getChildControl("bar");
tabsBar.set({
Expand Down Expand Up @@ -283,7 +280,6 @@ qx.Class.define("osparc.desktop.MainPage", {
osparc.desktop.MainPageHandler.getInstance().showDashboard();
this.__navBar.show();
this.__navBar.setStudy(null);
this.__navBar.setPageContext("dashboard");
this.__dashboard.getStudyBrowser().resetSelection();
if (this.__studyEditor) {
this.__studyEditor.destruct();
Expand Down Expand Up @@ -403,14 +399,6 @@ qx.Class.define("osparc.desktop.MainPage", {
osparc.data.Resources.fetch("studies", "close", params);
},

__syncStudyEditor: function(pageContext = "workbench") {
const studyEditor = this.__studyEditor;
const study = studyEditor.getStudy();
this.__navBar.setStudy(study);
this.__navBar.setPageContext(pageContext);
studyEditor.setPageContext(pageContext);
},

__getStudyEditor: function() {
if (this.__studyEditor) {
return this.__studyEditor;
Expand All @@ -429,17 +417,10 @@ qx.Class.define("osparc.desktop.MainPage", {
studyEditor.addListener("backToDashboardPressed", () => this.__backToDashboardPressed(), this);
studyEditor.addListener("forceBackToDashboard", () => this.__showDashboard(), this);
studyEditor.addListener("userIdled", () => this.__backToDashboard(), this);
studyEditor.addListener("slidesEdit", () => {
studyEditor.editSlides();
}, this);
studyEditor.addListener("slidesAppStart", () => {
this.__navBar.setPageContext(osparc.navigation.NavigationBar.PAGE_CONTEXT[2]);
studyEditor.setPageContext(osparc.navigation.NavigationBar.PAGE_CONTEXT[2]);
}, this);
studyEditor.addListener("slidesStop", () => {
this.__navBar.setPageContext(osparc.navigation.NavigationBar.PAGE_CONTEXT[1]);
this.__studyEditor.setPageContext(osparc.navigation.NavigationBar.PAGE_CONTEXT[1]);
}, this);
studyEditor.addListener("changeStudy", e => {
const study = e.getData();
this.__navBar.setStudy(study);
});
return studyEditor;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
extend: qx.core.Object,
type: "singleton",

events: {
"syncStudyEditor": "qx.event.type.Data"
},

members: {
__stack: null,
__loadingPage: null,
Expand Down Expand Up @@ -79,8 +75,7 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
const msg = qx.locale.Manager.tr("Study not found");
throw new Error(msg);
}
const pageContext = osparc.data.model.Study.getUiMode(studyData) || "workbench";
this.loadStudy(studyData, pageContext);
this.loadStudy(studyData);
})
.catch(err => {
osparc.FlashMessenger.getInstance().logAs(err.message, "ERROR");
Expand All @@ -89,7 +84,7 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
});
},

loadStudy: function(studyData, pageContext) {
loadStudy: function(studyData) {
let locked = false;
let lockedBy = false;
if ("state" in studyData && "locked" in studyData["state"]) {
Expand All @@ -104,6 +99,8 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
}`;
throw new Error(msg);
}
this.setLoadingPageHeader(qx.locale.Manager.tr("Loading ") + studyData.name);
this.showLoadingPage();
const store = osparc.store.Store.getInstance();
store.getInaccessibleServices(studyData)
.then(inaccessibleServices => {
Expand All @@ -112,13 +109,12 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
throw new Error(msg);
}
this.showStudyEditor();
this.__studyEditor.setStudyData(studyData)
.then(() => this.fireDataEvent("syncStudyEditor", pageContext));
this.__studyEditor.setStudyData(studyData);
})
.catch(err => {
osparc.FlashMessenger.getInstance().logAs(err.message, "ERROR");
this.showDashboard();
return;
throw new Error(err);
});
}
}
Expand Down
Loading

0 comments on commit a14ec1b

Please sign in to comment.