Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for Deployed Dashboards Enhancement Using Drag & Drop Functionality #2052

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cd87376
add gridstack.js to create app dashboard pages
jannikbecher Jul 7, 2023
953dadb
save layout and show in deployed app
jannikbecher Jul 7, 2023
c83c4e6
WIP
jannikbecher Jul 8, 2023
2526763
WIP
jannikbecher Jul 10, 2023
a10fbdd
WIP
jannikbecher Jul 10, 2023
e17bb5b
WIP
jannikbecher Jul 10, 2023
eeebf8d
WIP
jannikbecher Jul 11, 2023
a7a5cc6
Add new canvas view
jannikbecher Jul 11, 2023
5bf643e
Send canvas_settings update to canvas
jannikbecher Jul 11, 2023
1e92ccd
Render iframes in canvas
jannikbecher Jul 11, 2023
e3b3b2d
remove old deploy functionality
jannikbecher Jul 11, 2023
46ae045
add pop out functionality
jannikbecher Jul 11, 2023
408ba9a
formatting
jannikbecher Jul 11, 2023
6d55169
WIP deploy app
jannikbecher Jul 11, 2023
1489455
Apply indicators suggestions
jannikbecher Jul 12, 2023
e0473e6
hide move to canvas button when output is already on canvas
jannikbecher Jul 12, 2023
3dc3635
Add move output to notebook button
jannikbecher Jul 12, 2023
8a3e33c
hide canvas options in sub menu
jannikbecher Jul 12, 2023
3370fd6
Implement suggested view mode UI
jannikbecher Jul 12, 2023
8b70d5e
fix nasty popped out window bug
jannikbecher Jul 12, 2023
6439841
Apply suggestions
jannikbecher Jul 17, 2023
91e956d
Fix click twice to enable canvas mode bug
jannikbecher Jul 17, 2023
386f0ab
Use pubsub for window popin/popout communication
jannikbecher Jul 17, 2023
1c5a61d
Since Broadcast Channel API is used for client PubSub, broadcast func…
jannikbecher Jul 18, 2023
9bbe1b2
Revert "Since Broadcast Channel API is used for client PubSub, broadc…
jannikbecher Jul 18, 2023
bfe0ebe
Revert "Use pubsub for window popin/popout communication"
jannikbecher Jul 18, 2023
f0241db
Move eventlistener to gridstack hook
jannikbecher Jul 18, 2023
50bbf44
Some refactoring
jannikbecher Jul 19, 2023
e106553
Add gridstack to popped out window
jannikbecher Jul 20, 2023
59a66f1
Add show canvas options to app settings
jannikbecher Jul 20, 2023
23449fd
Add canvas deployment
jannikbecher Jul 20, 2023
0859c43
Remove canvas settings
jannikbecher Jul 20, 2023
d30b795
Get session updates in popout window
jannikbecher Jul 20, 2023
ff8b531
Some cleanup
jannikbecher Jul 20, 2023
992e9fd
Add client_id to popout window & handle /popout-window navigation
jannikbecher Jul 20, 2023
ade354f
Fix not rendering markdown
jannikbecher Jul 21, 2023
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
26 changes: 15 additions & 11 deletions assets/js/hooks/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ const Gridstack = {
if (this.props.externWindow) {
this.handleBeforeUnloadEvent = this.handleBeforeUnloadEvent.bind(this);
window.addEventListener("beforeunload", this.handleBeforeUnloadEvent);
this.getElement("canvas-close-button").addEventListener(
"click",
(event) => this.handleCanvasCloseClick()
);
this.getElement("canvas-popin-button").addEventListener(
"click",
(event) => this.handleCanvasPopinClick()
);
} else {
this.getElement("canvas-popout-button").addEventListener(
"click",
(event) => this.handleCanvasPopoutClick()
);
}

this.getElement("canvas-close-button").addEventListener("click", (event) =>
this.handleCanvasCloseClick()
);

const options = {
//acceptWidgets: true,
//removeable: true,
Expand Down Expand Up @@ -70,24 +75,23 @@ const Gridstack = {
globalPubSub.broadcast("js_views", { type: "reposition" });
},
handleBeforeUnloadEvent(event) {
this.sendToParent("popin");
globalPubSub.broadcast("session", { type: "canvas_popin_clicked" });
},
handleCanvasCloseClick() {
window.removeEventListener("beforeunload", this.handleBeforeUnloadEvent);
this.sendToParent("close");
window.close();
globalPubSub.broadcast("session", { type: "canvas_close_clicked" });
},
handleCanvasPopinClick() {
window.removeEventListener("beforeunload", this.handleBeforeUnloadEvent);
this.sendToParent("popin");
globalPubSub.broadcast("session", { type: "canvas_popin_clicked" });
window.close();
},
handleCanvasPopoutClick() {
globalPubSub.broadcast("session", { type: "canvas_popout_clicked" });
},
getElement(name) {
return document.querySelector(`[data-el-${name}]`);
},
sendToParent(message) {
window.opener.postMessage(message, window.location.origin);
},
};

export default Gridstack;
52 changes: 22 additions & 30 deletions assets/js/hooks/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ const Session = {
this.followedClientId = null;
this.canvasWindow = null;

this.handleCanvasWindowMessage = this.handleCanvasWindowMessage.bind(this);

setFavicon(this.faviconForEvaluationStatus(this.props.globalStatus));

this.updateSectionListHighlight();
Expand Down Expand Up @@ -142,14 +140,6 @@ const Session = {
this.handleCellIndicatorsClick(event)
);

this.getElement("canvas-close-button").addEventListener("click", (event) =>
this.handleCanvasCloseClick()
);

this.getElement("canvas-popout-button").addEventListener("click", (event) =>
this.handleCanvasPopoutClick()
);

this.getElement("views").addEventListener("click", (event) => {
this.handleViewsClick(event);
});
Expand Down Expand Up @@ -691,10 +681,13 @@ const Session = {
"_blank",
"toolbar=no, location=no, directories=no, titlebar=no, toolbar=0, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=600, height=600"
);
window.addEventListener("message", this.handleCanvasWindowMessage);
this.el.setAttribute("data-js-view", "canvas-popped-out");
},

handleCanvasPopinClick() {
this.el.setAttribute("data-js-view", "canvas");
},

handleViewCanvasPoppedoutClick() {
this.closeCanvasWindow();
this.el.setAttribute("data-js-view", "canvas");
Expand Down Expand Up @@ -1210,11 +1203,24 @@ const Session = {
// Session event handlers

handleSessionEvent(event) {
if (event.type === "cursor_selection_changed") {
this.sendLocationReport({
focusableId: event.focusableId,
selection: event.selection,
});
switch (event.type) {
case "cursor_selection_changed":
this.sendLocationReport({
focusableId: event.focusableId,
selection: event.selection,
});
break;
case "canvas_popout_clicked":
this.handleCanvasPopoutClick();
break;
case "canvas_popin_clicked":
this.handleCanvasPopinClick();
break;
case "canvas_close_clicked":
this.handleCanvasCloseClick();
break;
default:
console.log("Unknown event type: ", event.type);
}
},

Expand Down Expand Up @@ -1396,22 +1402,8 @@ const Session = {
return this.view === "presentation";
},
closeCanvasWindow() {
window.removeEventListener("message", this.handleCanvasWindowMessage);
this.canvasWindow && this.canvasWindow.close();
},
handleCanvasWindowMessage(event) {
if (event.origin != window.location.origin) return;
switch (event.data) {
case "popin":
this.el.setAttribute("data-js-view", "canvas");
break;
case "close":
this.el.removeAttribute("data-js-view");
break;
default:
console.log("Got unkown message: ", event);
}
},
};

/**
Expand Down
26 changes: 25 additions & 1 deletion assets/js/lib/pub_sub.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* A basic pub-sub implementation for client-side communication.
* A basic pub-sub implementation for client-side communication using the Broadcast Channel API.
jannikbecher marked this conversation as resolved.
Show resolved Hide resolved
*/
export default class PubSub {
constructor() {
this.subscribersByTopic = {};
this.channelsByTopic = {};
}

/**
Expand All @@ -20,6 +21,18 @@ export default class PubSub {
this.subscribersByTopic[topic] = [];
}

if (!this.channelsByTopic[topic]) {
this.channelsByTopic[topic] = new BroadcastChannel(topic);

this.channelsByTopic[topic].addEventListener("message", (event) => {
if (Array.isArray(this.subscribersByTopic[topic])) {
this.subscribersByTopic[topic].forEach((callback) => {
callback(event.data);
});
}
});
}

this.subscribersByTopic[topic].push(callback);

return () => {
Expand All @@ -39,13 +52,24 @@ export default class PubSub {
if (idx !== -1) {
this.subscribersByTopic[topic].splice(idx, 1);
}

if (this.subscribersByTopic[topic].length === 0) {
this.channelsByTopic[topic].close();
delete this.channelsByTopic[topic];
}
}

/**
* Calls all functions linked to the given topic
* and passes `payload` as the argument.
*/
broadcast(topic, payload) {
if (!this.channelsByTopic[topic]) {
this.channelsByTopic[topic] = new BroadcastChannel(topic);
}

this.channelsByTopic[topic].postMessage(payload);

if (Array.isArray(this.subscribersByTopic[topic])) {
this.subscribersByTopic[topic].forEach((callback) => {
callback(payload);
Expand Down