mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #12119: Lock & unlock dashboard layout
This commit is contained in:
12
netbox/project-static/dist/netbox.js
vendored
12
netbox/project-static/dist/netbox.js
vendored
File diff suppressed because one or more lines are too long
2
netbox/project-static/dist/netbox.js.map
vendored
2
netbox/project-static/dist/netbox.js.map
vendored
File diff suppressed because one or more lines are too long
@ -2,6 +2,20 @@ import { GridStack, GridStackOptions, GridStackWidget } from 'gridstack';
|
|||||||
import { createToast } from './bs';
|
import { createToast } from './bs';
|
||||||
import { apiPatch, hasError } from './util';
|
import { apiPatch, hasError } from './util';
|
||||||
|
|
||||||
|
function lockDashboard(): void {
|
||||||
|
const dashboard = document.getElementById('dashboard') as any;
|
||||||
|
if (dashboard) {
|
||||||
|
dashboard.gridstack.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function unlockDashboard(): void {
|
||||||
|
const dashboard = document.getElementById('dashboard') as any;
|
||||||
|
if (dashboard) {
|
||||||
|
dashboard.gridstack.enable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function saveDashboardLayout(
|
async function saveDashboardLayout(
|
||||||
url: string,
|
url: string,
|
||||||
gridData: GridStackWidget[] | GridStackOptions,
|
gridData: GridStackWidget[] | GridStackOptions,
|
||||||
@ -22,6 +36,8 @@ export function initDashboard(): void {
|
|||||||
// Initialize the grid
|
// Initialize the grid
|
||||||
let grid = GridStack.init({
|
let grid = GridStack.init({
|
||||||
cellHeight: 100,
|
cellHeight: 100,
|
||||||
|
disableDrag: true,
|
||||||
|
disableResize: true,
|
||||||
draggable: {
|
draggable: {
|
||||||
handle: '.grid-stack-item-content .card-header',
|
handle: '.grid-stack-item-content .card-header',
|
||||||
appendTo: 'body',
|
appendTo: 'body',
|
||||||
@ -29,6 +45,22 @@ export function initDashboard(): void {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Create a listener for the dashboard lock button
|
||||||
|
const gridLockButton = document.getElementById('lock_dashboard') as HTMLButtonElement;
|
||||||
|
if (gridLockButton) {
|
||||||
|
gridLockButton.addEventListener('click', () => {
|
||||||
|
lockDashboard();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a listener for the dashboard unlock button
|
||||||
|
const gridUnlockButton = document.getElementById('unlock_dashboard') as HTMLButtonElement;
|
||||||
|
if (gridUnlockButton) {
|
||||||
|
gridUnlockButton.addEventListener('click', () => {
|
||||||
|
unlockDashboard();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Create a listener for the dashboard save button
|
// Create a listener for the dashboard save button
|
||||||
const gridSaveButton = document.getElementById('save_dashboard') as HTMLButtonElement;
|
const gridSaveButton = document.getElementById('save_dashboard') as HTMLButtonElement;
|
||||||
if (gridSaveButton === null) {
|
if (gridSaveButton === null) {
|
||||||
|
@ -29,8 +29,23 @@
|
|||||||
{% include 'extras/dashboard/widget.html' %}
|
{% include 'extras/dashboard/widget.html' %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="collapse multi-collapse show">
|
||||||
<div class="d-flex px-3">
|
<div class="d-flex px-3">
|
||||||
<div class="flex-grow-1">
|
<div class="flex-grow-1">
|
||||||
|
<button type="button" id="unlock_dashboard" class="btn btn-light btn-sm" data-bs-toggle="collapse" data-bs-target=".multi-collapse">
|
||||||
|
<i class="mdi mdi-lock-open-outline"></i> Unlock Dashboard
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="collapse multi-collapse">
|
||||||
|
<div class="d-flex px-3">
|
||||||
|
<div class="flex-grow-1">
|
||||||
|
<button type="button" id="lock_dashboard" class="btn btn-light btn-sm" data-bs-toggle="collapse" data-bs-target=".multi-collapse">
|
||||||
|
<i class="mdi mdi-lock-outline"></i> Lock Dashboard
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
<a href="#"
|
<a href="#"
|
||||||
hx-get="{% url 'extras:dashboardwidget_add' %}"
|
hx-get="{% url 'extras:dashboardwidget_add' %}"
|
||||||
hx-target="#htmx-modal-content"
|
hx-target="#htmx-modal-content"
|
||||||
@ -40,8 +55,6 @@
|
|||||||
>
|
>
|
||||||
<i class="mdi mdi-plus"></i> Add Widget
|
<i class="mdi mdi-plus"></i> Add Widget
|
||||||
</a>
|
</a>
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<button id="save_dashboard" class="btn btn-primary btn-sm" data-url="{% url 'extras-api:dashboard' %}">
|
<button id="save_dashboard" class="btn btn-primary btn-sm" data-url="{% url 'extras-api:dashboard' %}">
|
||||||
<i class="mdi mdi-content-save-outline"></i> Save Layout
|
<i class="mdi mdi-content-save-outline"></i> Save Layout
|
||||||
</button>
|
</button>
|
||||||
@ -50,6 +63,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock content-wrapper %}
|
{% endblock content-wrapper %}
|
||||||
|
|
||||||
{% block modals %}
|
{% block modals %}
|
||||||
|
Reference in New Issue
Block a user