-
Notifications
You must be signed in to change notification settings - Fork 445
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
Closed
Changes from 33 commits
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 953dadb
save layout and show in deployed app
jannikbecher c83c4e6
WIP
jannikbecher 2526763
WIP
jannikbecher a10fbdd
WIP
jannikbecher e17bb5b
WIP
jannikbecher eeebf8d
WIP
jannikbecher a7a5cc6
Add new canvas view
jannikbecher 5bf643e
Send canvas_settings update to canvas
jannikbecher 1e92ccd
Render iframes in canvas
jannikbecher e3b3b2d
remove old deploy functionality
jannikbecher 46ae045
add pop out functionality
jannikbecher 408ba9a
formatting
jannikbecher 6d55169
WIP deploy app
jannikbecher 1489455
Apply indicators suggestions
jannikbecher e0473e6
hide move to canvas button when output is already on canvas
jannikbecher 3dc3635
Add move output to notebook button
jannikbecher 8a3e33c
hide canvas options in sub menu
jannikbecher 3370fd6
Implement suggested view mode UI
jannikbecher 8b70d5e
fix nasty popped out window bug
jannikbecher 6439841
Apply suggestions
jannikbecher 91e956d
Fix click twice to enable canvas mode bug
jannikbecher 386f0ab
Use pubsub for window popin/popout communication
jannikbecher 1c5a61d
Since Broadcast Channel API is used for client PubSub, broadcast func…
jannikbecher 9bbe1b2
Revert "Since Broadcast Channel API is used for client PubSub, broadc…
jannikbecher bfe0ebe
Revert "Use pubsub for window popin/popout communication"
jannikbecher f0241db
Move eventlistener to gridstack hook
jannikbecher 50bbf44
Some refactoring
jannikbecher e106553
Add gridstack to popped out window
jannikbecher 59a66f1
Add show canvas options to app settings
jannikbecher 23449fd
Add canvas deployment
jannikbecher 0859c43
Remove canvas settings
jannikbecher d30b795
Get session updates in popout window
jannikbecher ff8b531
Some cleanup
jannikbecher 992e9fd
Add client_id to popout window & handle /popout-window navigation
jannikbecher ade354f
Fix not rendering markdown
jannikbecher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import "gridstack/dist/gridstack.min.css"; | ||
import { GridStack } from "gridstack"; | ||
|
||
/** | ||
* A hook for creating app dashboard. | ||
*/ | ||
const AppCanvas = { | ||
mounted() { | ||
const self = this; | ||
|
||
const options = { | ||
staticGrid: true, | ||
float: true, | ||
margin: 0, | ||
cellHeight: "4rem", | ||
}; | ||
|
||
this.grid = GridStack.init(options, this.el); | ||
|
||
this.handleEvent("init", ({ payload }) => { | ||
const grid_items = Object.entries(payload).map(([id, value]) => ({ | ||
id, | ||
...value, | ||
})); | ||
this.grid.load(grid_items); | ||
console.log(this.grid.el.children); | ||
Array.from(this.grid.el.children).forEach((item) => { | ||
const output_id = `[id^=outputs-${item.id}]`; | ||
const output_el = document.querySelector(output_id); | ||
item.firstChild.appendChild(output_el); | ||
}); | ||
}); | ||
}, | ||
}; | ||
|
||
export default AppCanvas; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { getAttributeOrThrow, parseInteger } from "../lib/attribute"; | ||
import { globalPubSub } from "../lib/pub_sub"; | ||
import "gridstack/dist/gridstack.min.css"; | ||
import { GridStack } from "gridstack"; | ||
|
||
/** | ||
* A hook for creating a canvas with gridstackjs. | ||
*/ | ||
const Canvas = { | ||
mounted() { | ||
this.props = this.getProps(); | ||
console.log("Gridstack mounted"); | ||
const self = this; | ||
|
||
const options = { | ||
styleInHead: true, | ||
float: true, | ||
resizable: { handles: "all" }, | ||
margin: 0, | ||
cellHeight: "4rem", | ||
}; | ||
|
||
this.grid = GridStack.init(options, this.el); | ||
|
||
this.handleEvent("reload", ({ payload }) => { | ||
const grid_items = Object.entries(payload).map(([id, value]) => ({ | ||
id, | ||
...value, | ||
})); | ||
this.grid.load(grid_items); | ||
Array.from(this.grid.el.children).forEach((item) => { | ||
console.log(item.attributes); | ||
const output_id = `[id^=outputs-${item.attributes["gs-id"].value}]`; | ||
const output_el = document.querySelector(output_id); | ||
item.firstChild.appendChild(output_el); | ||
}); | ||
}); | ||
|
||
this.grid.on("change", function (event, items) { | ||
console.log("ITEMS changed: ", items); | ||
let new_items = items.reduce((acc, item) => { | ||
acc[item.id] = { | ||
x: item.x, | ||
y: item.y, | ||
w: item.w, | ||
h: item.h, | ||
}; | ||
return acc; | ||
}, {}); | ||
self.pushEventTo(self.props.phxTarget, "items_changed", new_items); | ||
self.repositionIframe(); | ||
}); | ||
|
||
this.grid.on("removed", (event, items) => { | ||
console.log("REMOVED", event); | ||
}); | ||
|
||
this.grid.on("drag", function (event, item) { | ||
// TODO update iframe position when dragging | ||
//self.repositionIframe(); | ||
}); | ||
}, | ||
updated() { | ||
this.props = this.getProps(); | ||
console.log("Gridstack updated", this.grid); | ||
}, | ||
getProps() { | ||
return { | ||
phxTarget: getAttributeOrThrow(this.el, "data-phx-target", parseInteger), | ||
}; | ||
}, | ||
repositionIframe() { | ||
globalPubSub.broadcast("js_views", { type: "reposition" }); | ||
}, | ||
}; | ||
|
||
export default Canvas; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* A hook for popped out windows. | ||
*/ | ||
const PopoutWindow = { | ||
mounted() { | ||
this.props = this.getProps(); | ||
console.log("PopoutWindow mounted"); | ||
const self = this; | ||
|
||
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() | ||
); | ||
}, | ||
updated() { | ||
this.props = this.getProps(); | ||
console.log("PopoutWindow updated"); | ||
}, | ||
getProps() { | ||
return {}; | ||
}, | ||
handleBeforeUnloadEvent(event) { | ||
this.sendToParent("canvas_popin_clicked"); | ||
}, | ||
handleCanvasCloseClick() { | ||
window.removeEventListener("beforeunload", this.handleBeforeUnloadEvent); | ||
this.sendToParent("canvas_close_clicked"); | ||
}, | ||
handleCanvasPopinClick() { | ||
window.removeEventListener("beforeunload", this.handleBeforeUnloadEvent); | ||
this.sendToParent("canvas_popin_clicked"); | ||
}, | ||
getElement(name) { | ||
return document.querySelector(`[data-el-${name}]`); | ||
}, | ||
sendToParent(message) { | ||
window.opener.postMessage(message, window.location.origin); | ||
}, | ||
}; | ||
|
||
export default PopoutWindow; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably very bad idea to do it this way, but I couldn't come up with another solution...
I just remount the existing outputs into the gridstack items
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't put more effort into it yet, because I'm tinkering around with implementing a liveview compatible drag&drop solution