2022-10-13 14:26:43 +00:00
|
|
|
{% extends "base.html" %}
|
|
|
|
{% load static %}
|
|
|
|
{% load joinsep %}
|
2022-11-29 07:20:39 +00:00
|
|
|
{% block content %}
|
2022-10-13 14:26:43 +00:00
|
|
|
|
|
|
|
<div class="grid-stack" id="grid-stack-main">
|
2022-11-29 07:20:39 +00:00
|
|
|
<!-- <div class="grid-stack-item" gs-w="5" gs-h="14" gs-y="0" gs-x="1">
|
2022-11-14 18:29:07 +00:00
|
|
|
<div class="grid-stack-item-content">
|
|
|
|
<nav class="panel">
|
|
|
|
<p class="panel-heading" style="padding: .2em; line-height: .5em;">
|
|
|
|
<i class="fa-solid fa-arrows-up-down-left-right has-text-grey-light"></i>
|
|
|
|
Controls
|
|
|
|
</p>
|
|
|
|
<article class="panel-block is-active">
|
|
|
|
{% include 'window-content/controls.html' %}
|
|
|
|
</article>
|
|
|
|
</nav>
|
|
|
|
</div>
|
2022-11-29 07:20:39 +00:00
|
|
|
</div> -->
|
2022-11-29 07:20:39 +00:00
|
|
|
<!-- <div class="grid-stack-item" gs-w="4" gs-h="25" gs-y="0" gs-x="6">
|
2022-10-13 14:26:43 +00:00
|
|
|
<div class="grid-stack-item-content">
|
|
|
|
<nav class="panel">
|
|
|
|
<p class="panel-heading" style="padding: .2em; line-height: .5em;">
|
|
|
|
<i class="fa-solid fa-arrows-up-down-left-right has-text-grey-light"></i>
|
|
|
|
Home
|
|
|
|
</p>
|
|
|
|
<article class="panel-block is-active">
|
|
|
|
{% include 'window-content/main.html' %}
|
|
|
|
</article>
|
|
|
|
</nav>
|
|
|
|
</div>
|
2022-11-29 07:20:39 +00:00
|
|
|
</div> -->
|
2022-11-14 18:29:07 +00:00
|
|
|
|
2022-11-29 07:20:39 +00:00
|
|
|
<script>
|
|
|
|
var grid = GridStack.init({
|
|
|
|
cellHeight: 20,
|
|
|
|
cellWidth: 50,
|
|
|
|
cellHeightUnit: 'px',
|
|
|
|
auto: true,
|
|
|
|
float: true,
|
|
|
|
draggable: {handle: '.panel-heading', scroll: false, appendTo: 'body'},
|
|
|
|
removable: false,
|
|
|
|
animate: true,
|
|
|
|
});
|
|
|
|
// GridStack.init();
|
2022-11-14 18:29:07 +00:00
|
|
|
|
2022-11-29 07:20:39 +00:00
|
|
|
// a widget is ready to be loaded
|
|
|
|
document.addEventListener('load-widget', function(event) {
|
2022-11-29 07:20:39 +00:00
|
|
|
let containers = htmx.findAll('#widget');
|
|
|
|
console.log("CONTAINERS", containers);
|
|
|
|
for (let x = 0, len = containers.length; x < len; x++) {
|
|
|
|
container = containers[x];
|
|
|
|
console.log("CONTAINER", container);
|
|
|
|
// get the scripts, they won't be run on the new element so we need to eval them
|
|
|
|
let widgetelement = container.firstElementChild.cloneNode(true);
|
|
|
|
console.log(widgetelement);
|
|
|
|
var scripts = htmx.findAll(widgetelement, "script");
|
|
|
|
var new_id = widgetelement.id;
|
2022-10-13 14:26:43 +00:00
|
|
|
|
2022-11-29 07:20:39 +00:00
|
|
|
// check if there's an existing element like the one we want to swap
|
|
|
|
let grid_element = htmx.find('#grid-stack-main');
|
|
|
|
let existing_widget = htmx.find(grid_element, "#"+new_id);
|
2022-10-13 14:26:43 +00:00
|
|
|
|
2022-11-29 07:20:39 +00:00
|
|
|
// get the size and position attributes
|
|
|
|
if (existing_widget) {
|
|
|
|
let attrs = existing_widget.getAttributeNames();
|
|
|
|
for (let i = 0, len = attrs.length; i < len; i++) {
|
|
|
|
if (attrs[i].startsWith('gs-')) { // only target gridstack attributes
|
|
|
|
widgetelement.setAttribute(attrs[i], existing_widget.getAttribute(attrs[i]));
|
|
|
|
}
|
2022-11-29 07:20:39 +00:00
|
|
|
}
|
2022-10-13 14:26:43 +00:00
|
|
|
}
|
2022-11-29 07:20:39 +00:00
|
|
|
// clear the queue element
|
|
|
|
container.outerHTML = "";
|
|
|
|
// container.firstElementChild.outerHTML = "";
|
|
|
|
grid.addWidget(widgetelement);
|
2022-10-13 14:26:43 +00:00
|
|
|
|
2022-11-29 07:20:39 +00:00
|
|
|
// re-create the HTMX JS listeners, otherwise HTMX won't work inside the grid
|
|
|
|
htmx.process(widgetelement);
|
2022-10-13 14:26:43 +00:00
|
|
|
|
2022-11-29 07:20:39 +00:00
|
|
|
// update the size of the widget according to its content
|
|
|
|
var added_widget = htmx.find(grid_element, "#"+new_id);
|
|
|
|
var itemContent = htmx.find(added_widget, ".control");
|
|
|
|
var scrollheight = itemContent.scrollHeight+80;
|
|
|
|
var verticalmargin = 0;
|
|
|
|
var cellheight = grid.opts.cellHeight;
|
|
|
|
var height = Math.ceil((scrollheight + verticalmargin) / (cellheight + verticalmargin));
|
|
|
|
var opts = {
|
|
|
|
h: height,
|
|
|
|
}
|
|
|
|
grid.update(
|
|
|
|
added_widget,
|
|
|
|
opts
|
|
|
|
);
|
2022-10-13 14:26:43 +00:00
|
|
|
|
2022-11-29 07:20:39 +00:00
|
|
|
// run the JS scripts inside the added element again
|
|
|
|
for (var i = 0; i < scripts.length; i++) {
|
|
|
|
eval(scripts[i].innerHTML);
|
|
|
|
}
|
2022-11-29 07:20:39 +00:00
|
|
|
}
|
2022-11-29 07:20:39 +00:00
|
|
|
// clear the containers we just added
|
|
|
|
// for (let x = 0, len = containers.length; x < len; x++) {
|
|
|
|
// container = containers[x];
|
|
|
|
// container.inner = "";
|
|
|
|
// }
|
|
|
|
grid.compact();
|
2022-11-29 07:20:39 +00:00
|
|
|
});
|
|
|
|
</script>
|
2022-11-29 07:20:39 +00:00
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
|
|
|
hx-get="{% url 'positions' type='widget' %}"
|
|
|
|
hx-target="#widgets-here"
|
|
|
|
hx-trigger="load"
|
|
|
|
hx-swap="afterend"
|
|
|
|
style="display: none;"></div>
|
|
|
|
<div
|
|
|
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
|
|
|
hx-get="{% url 'strategies' type='widget' %}"
|
|
|
|
hx-target="#widgets-here"
|
|
|
|
hx-trigger="load"
|
|
|
|
hx-swap="afterend"
|
|
|
|
style="display: none;"></div>
|
|
|
|
<div
|
|
|
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
|
|
|
hx-get="{% url 'profit' type='widget' %}"
|
|
|
|
hx-target="#widgets-here"
|
|
|
|
hx-trigger="load"
|
|
|
|
hx-swap="afterend"
|
|
|
|
style="display: none;"></div>
|
|
|
|
</div>
|
2022-10-13 14:26:43 +00:00
|
|
|
|
|
|
|
{% endblock %}
|