Skip to content

Commit

Permalink
Merge branch 'master' into frontend-disk-usage-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Mar 6, 2024
2 parents 5968650 + 12eb43e commit dc41fbb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,65 +706,8 @@ qx.Class.define("osparc.dashboard.CardBase", {
return moreOpts;
},

_checkLoggedIn: function() {
let isLogged = osparc.auth.Manager.getInstance().isLoggedIn();
if (!isLogged) {
const msg = this.tr("You need to be logged in to create a study");
osparc.FlashMessenger.getInstance().logAs(msg);
}
return isLogged;
},

_startStudyById: function(studyId, openCB, cancelCB, isStudyCreation = false) {
if (!this._checkLoggedIn()) {
return;
}

const openStudy = () => {
if (openCB) {
openCB();
}
osparc.desktop.MainPageHandler.getInstance().startStudy(studyId);
};

const walletsEnabled = osparc.desktop.credits.Utils.areWalletsEnabled();
if (walletsEnabled) {
const params = {
url: {
studyId
}
};
osparc.data.Resources.fetch("studies", "getWallet", params)
.then(wallet => {
if (isStudyCreation || wallet === null || osparc.desktop.credits.Utils.getWallet(wallet["walletId"]) === null) {
// pop up study options if the study was just created or if it has no wallet assigned or user has no access to it
const resourceSelector = new osparc.study.StudyOptions(studyId);
const win = osparc.study.StudyOptions.popUpInWindow(resourceSelector);
resourceSelector.addListener("startStudy", () => {
win.close();
openStudy();
});
resourceSelector.addListener("cancel", () => {
win.close();
if (cancelCB) {
cancelCB();
}
});
// listen to "tap" instead of "execute": the "execute" is not propagated
win.getChildControl("close-button").addListener("tap", () => {
cancelCB();
});
} else {
openStudy();
}
})
.catch(err => {
console.error(err);
osparc.FlashMessenger.logAs(err.message, "ERROR");
});
} else {
openStudy();
}
osparc.dashboard.ResourceBrowserBase.startStudyById(studyId, openCB, cancelCB, isStudyCreation);
},

openData: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,67 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
statics: {
PAGINATED_STUDIES: 10,

checkLoggedIn: function() {
const isLogged = osparc.auth.Manager.getInstance().isLoggedIn();
if (!isLogged) {
const msg = qx.locale.Manager.tr("You need to be logged in to create a study");
osparc.FlashMessenger.getInstance().logAs(msg);
}
return isLogged;
},

startStudyById: function(studyId, openCB, cancelCB, isStudyCreation = false) {
if (!osparc.dashboard.ResourceBrowserBase.checkLoggedIn()) {
return;
}

const openStudy = () => {
if (openCB) {
openCB();
}
osparc.desktop.MainPageHandler.getInstance().startStudy(studyId);
};

const walletsEnabled = osparc.desktop.credits.Utils.areWalletsEnabled();
if (walletsEnabled) {
const params = {
url: {
studyId
}
};
osparc.data.Resources.fetch("studies", "getWallet", params)
.then(wallet => {
if (isStudyCreation || wallet === null || osparc.desktop.credits.Utils.getWallet(wallet["walletId"]) === null) {
// pop up study options if the study was just created or if it has no wallet assigned or user has no access to it
const resourceSelector = new osparc.study.StudyOptions(studyId);
const win = osparc.study.StudyOptions.popUpInWindow(resourceSelector);
resourceSelector.addListener("startStudy", () => {
win.close();
openStudy();
});
resourceSelector.addListener("cancel", () => {
win.close();
if (cancelCB) {
cancelCB();
}
});
// listen to "tap" instead of "execute": the "execute" is not propagated
win.getChildControl("close-button").addListener("tap", () => {
cancelCB();
});
} else {
openStudy();
}
})
.catch(err => {
console.error(err);
osparc.FlashMessenger.logAs(err.message, "ERROR");
});
} else {
openStudy();
}
},

sortStudyList: function(studyList) {
const sortByProperty = function(prop) {
return function(a, b) {
Expand Down Expand Up @@ -310,55 +371,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
},

_startStudyById: function(studyId, openCB, cancelCB, isStudyCreation = false) {
if (!this._checkLoggedIn()) {
return;
}

const openStudy = () => {
if (openCB) {
openCB();
}
osparc.desktop.MainPageHandler.getInstance().startStudy(studyId);
};

const walletsEnabled = osparc.desktop.credits.Utils.areWalletsEnabled();
if (walletsEnabled) {
const params = {
url: {
studyId
}
};
osparc.data.Resources.fetch("studies", "getWallet", params)
.then(wallet => {
if (isStudyCreation || wallet === null || osparc.desktop.credits.Utils.getWallet(wallet["walletId"]) === null) {
// pop up study options if the study was just created or if it has no wallet assigned or user has no access to it
const resourceSelector = new osparc.study.StudyOptions(studyId);
const win = osparc.study.StudyOptions.popUpInWindow(resourceSelector);
resourceSelector.addListener("startStudy", () => {
win.close();
openStudy();
});
resourceSelector.addListener("cancel", () => {
win.close();
if (cancelCB) {
cancelCB();
}
});
// listen to "tap" instead of "execute": the "execute" is not propagated
win.getChildControl("close-button").addListener("tap", () => {
cancelCB();
});
} else {
openStudy();
}
})
.catch(err => {
console.error(err);
osparc.FlashMessenger.logAs(err.message, "ERROR");
});
} else {
openStudy();
}
this.self().startStudyById(studyId, openCB, cancelCB, isStudyCreation);
},

_createStudyFromTemplate: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,12 @@ qx.Class.define("osparc.notification.NotificationUI", {
studyDataCopy["resourceType"] = notification.getCategory() === "TEMPLATE_SHARED" ? "template" : "study";
const moreOpts = new osparc.dashboard.ResourceMoreOptions(studyDataCopy);
const win = osparc.dashboard.ResourceMoreOptions.popUpInWindow(moreOpts);
moreOpts.addListener("openingStudy", () => win.close());
moreOpts.addListener("openStudy", () => {
if (notification.getCategory() === "STUDY_SHARED") {
const openCB = () => win.close();
osparc.dashboard.ResourceBrowserBase.startStudyById(studyId, openCB);
}
});
}
})
.catch(err => {
Expand Down

0 comments on commit dc41fbb

Please sign in to comment.