Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,29 @@ qx.Class.define("osparc.desktop.StudyEditor", {
this.__listenToEvent();
this.__listenToServiceStatus();
this.__listenToStatePorts();

const socket = osparc.wrapper.WebSocket.getInstance();
[
"connect",
"reconnect",
].forEach(evtName => {
socket.addListener(evtName, () => {
// after a reconnect, re-sync the project document
console.log("WebSocket reconnected, re-syncing project document");
const studyId = this.getStudy().getUuid();
osparc.store.Study.getInstance().getOne(studyId)
.then(latestStudyData => {
const latestData = {
"version": this.__lastSyncedProjectVersion, // do not increase the version
"document": latestStudyData,
};
this.__applyProjectDocument(latestData);
})
.catch(err => {
console.error("Failed to re-sync project document after WebSocket reconnect:", err);
});
});
});
},

__listenToProjectDocument: function() {
Expand Down Expand Up @@ -727,13 +750,14 @@ qx.Class.define("osparc.desktop.StudyEditor", {
osparc.data.Resources.fetch("runPipeline", "startPipeline", params)
.then(resp => this.__onPipelineSubmitted(resp))
.catch(err => {
let msg = err.message;
const errStatus = err.status;
if (errStatus == "409") {
this.getStudyLogger().error(null, "Pipeline is already running");
osparc.FlashMessenger.logError(err);
const msg = osparc.FlashMessenger.extractMessage(err);
this.getStudyLogger().error(null, msg);
} else if (errStatus == "422") {
this.getStudyLogger().info(null, "The pipeline is up-to-date");
msg = this.tr("The pipeline is up-to-date. Do you want to re-run it?");
const msg = this.tr("The pipeline is up-to-date. Do you want to re-run it?");
const win = new osparc.ui.window.Confirmation(msg).set({
caption: this.tr("Re-run"),
confirmText: this.tr("Run"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ qx.Class.define("osparc.navigation.StudyTitleWOptions", {
});
});
break;
case "study-menu-share":
control = new qx.ui.menu.Button().set({
label: this.tr("Share..."),
icon: "@FontAwesome5Solid/share-alt/14",
...this.self().BUTTON_OPTIONS
});
control.addListener("execute", () => this.__openAccessRights());
break;
case "study-menu-reload":
control = new qx.ui.menu.Button().set({
label: this.tr("Reload"),
Expand Down Expand Up @@ -100,6 +108,7 @@ qx.Class.define("osparc.navigation.StudyTitleWOptions", {
const optionsMenu = new qx.ui.menu.Menu();
optionsMenu.setAppearance("menu-wider");
optionsMenu.add(this.getChildControl("study-menu-info"));
optionsMenu.add(this.getChildControl("study-menu-share"));
optionsMenu.add(this.getChildControl("study-menu-reload"));
optionsMenu.add(this.getChildControl("study-menu-conversations"));
if (osparc.product.Utils.showConvertToPipeline()) {
Expand Down Expand Up @@ -133,6 +142,17 @@ qx.Class.define("osparc.navigation.StudyTitleWOptions", {
return control || this.base(arguments, id);
},

__openAccessRights: function() {
const studyData = this.getStudy().serialize();
studyData["resourceType"] = this.getStudy().getTemplateType() ? "template" : "study";
const collaboratorsView = osparc.info.StudyUtils.openAccessRights(studyData);
collaboratorsView.addListener("updateAccessRights", e => {
const updatedData = e.getData();
this.getStudy().setAccessRights(updatedData["accessRights"]);
this.fireDataEvent("updateStudy", updatedData);
}, this);
},

__reloadIFrame: function() {
const nodes = this.getStudy().getWorkbench().getNodes();
if (Object.keys(nodes).length === 1) {
Expand All @@ -145,6 +165,9 @@ qx.Class.define("osparc.navigation.StudyTitleWOptions", {
const editTitle = this.getChildControl("edit-title-label");
study.bind("name", editTitle, "value");

const shareButton = this.getChildControl("study-menu-share");
shareButton.setEnabled(osparc.data.model.Study.canIWrite(study.getAccessRights()));

const reloadButton = this.getChildControl("study-menu-reload");
study.getUi().bind("mode", reloadButton, "visibility", {
converter: mode => mode === "standalone" ? "visible" : "excluded"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from common_library.logging.logging_errors import create_troubleshooting_log_kwargs
from models_library.api_schemas_webserver.socketio import SocketIORoomStr
from models_library.products import ProductName
from models_library.projects import ProjectID
from models_library.socketio import SocketMessageDict
from models_library.users import UserID
from pydantic import TypeAdapter
Expand All @@ -23,7 +24,7 @@
from ..groups.api import list_user_groups_ids_with_read_access
from ..login.decorators import login_required
from ..products import products_web
from ..resource_manager.user_sessions import managed_resource
from ..resource_manager.user_sessions import PROJECT_ID_KEY, managed_resource
from ._utils import EnvironDict, SocketID, get_socket_server, register_socketio_handler
from .messages import SOCKET_IO_HEARTBEAT_EVENT, send_message_to_user

Expand Down Expand Up @@ -99,6 +100,21 @@ async def _set_user_in_group_rooms(
await sio.enter_room(socket_id, SocketIORoomStr.from_user_id(user_id))


async def _set_user_in_project_rooms(
app: web.Application, user_id: UserID, client_session_id: str, socket_id: SocketID
) -> None:
"""Adds user in project rooms in case he has any project open"""
project_ids = []
with managed_resource(user_id, client_session_id, app) as user_session:
project_ids = await user_session.find_all_resources_of_user(PROJECT_ID_KEY)

sio = get_socket_server(app)
for project_id in project_ids:
await sio.enter_room(
socket_id, SocketIORoomStr.from_project_id(ProjectID(project_id))
)


#
# socketio event handlers
#
Expand Down Expand Up @@ -135,6 +151,7 @@ async def connect(
)

await _set_user_in_group_rooms(app, user_id, socket_id)
await _set_user_in_project_rooms(app, user_id, client_session_id, socket_id)

_logger.debug("Sending set_heartbeat_emit_interval with %s", _EMIT_INTERVAL_S)

Expand Down
Loading