Skip to content

Commit f44a2ba

Browse files
committed
Closes #12119: Lock & unlock dashboard layout
1 parent 29fbe6e commit f44a2ba

File tree

4 files changed

+71
-25
lines changed

4 files changed

+71
-25
lines changed

netbox/project-static/dist/netbox.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/netbox.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/src/dashboard.ts

+32
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ import { GridStack, GridStackOptions, GridStackWidget } from 'gridstack';
22
import { createToast } from './bs';
33
import { apiPatch, hasError } from './util';
44

5+
function lockDashboard(): void {
6+
const dashboard = document.getElementById('dashboard') as any;
7+
if (dashboard) {
8+
dashboard.gridstack.disable();
9+
}
10+
}
11+
12+
function unlockDashboard(): void {
13+
const dashboard = document.getElementById('dashboard') as any;
14+
if (dashboard) {
15+
dashboard.gridstack.enable();
16+
}
17+
}
18+
519
async function saveDashboardLayout(
620
url: string,
721
gridData: GridStackWidget[] | GridStackOptions,
@@ -22,13 +36,31 @@ export function initDashboard(): void {
2236
// Initialize the grid
2337
let grid = GridStack.init({
2438
cellHeight: 100,
39+
disableDrag: true,
40+
disableResize: true,
2541
draggable: {
2642
handle: '.grid-stack-item-content .card-header',
2743
appendTo: 'body',
2844
scroll: true
2945
}
3046
});
3147

48+
// Create a listener for the dashboard lock button
49+
const gridLockButton = document.getElementById('lock_dashboard') as HTMLButtonElement;
50+
if (gridLockButton) {
51+
gridLockButton.addEventListener('click', () => {
52+
lockDashboard();
53+
});
54+
}
55+
56+
// Create a listener for the dashboard unlock button
57+
const gridUnlockButton = document.getElementById('unlock_dashboard') as HTMLButtonElement;
58+
if (gridUnlockButton) {
59+
gridUnlockButton.addEventListener('click', () => {
60+
unlockDashboard();
61+
});
62+
}
63+
3264
// Create a listener for the dashboard save button
3365
const gridSaveButton = document.getElementById('save_dashboard') as HTMLButtonElement;
3466
if (gridSaveButton === null) {

netbox/templates/home.html

+32-18
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,39 @@ <h6 class="alert-heading">
2929
{% include 'extras/dashboard/widget.html' %}
3030
{% endfor %}
3131
</div>
32-
<div class="d-flex px-3">
33-
<div class="flex-grow-1">
34-
<a href="#"
35-
hx-get="{% url 'extras:dashboardwidget_add' %}"
36-
hx-target="#htmx-modal-content"
37-
data-bs-toggle="modal"
38-
data-bs-target="#htmx-modal"
39-
class="btn btn-success btn-sm"
40-
>
41-
<i class="mdi mdi-plus"></i> Add Widget
42-
</a>
32+
<div class="collapse multi-collapse show">
33+
<div class="d-flex px-3">
34+
<div class="flex-grow-1">
35+
<button type="button" id="unlock_dashboard" class="btn btn-light btn-sm" data-bs-toggle="collapse" data-bs-target=".multi-collapse">
36+
<i class="mdi mdi-lock-open-outline"></i> Unlock Dashboard
37+
</button>
38+
</div>
4339
</div>
44-
<div>
45-
<button id="save_dashboard" class="btn btn-primary btn-sm" data-url="{% url 'extras-api:dashboard' %}">
46-
<i class="mdi mdi-content-save-outline"></i> Save Layout
47-
</button>
48-
<a href="{% url 'extras:dashboard_reset' %}" class="btn btn-danger btn-sm">
49-
<i class="mdi mdi-backspace"></i> Reset Dashboard
50-
</a>
40+
</div>
41+
<div class="collapse multi-collapse">
42+
<div class="d-flex px-3">
43+
<div class="flex-grow-1">
44+
<button type="button" id="lock_dashboard" class="btn btn-light btn-sm" data-bs-toggle="collapse" data-bs-target=".multi-collapse">
45+
<i class="mdi mdi-lock-outline"></i> Lock Dashboard
46+
</button>
47+
</div>
48+
<div>
49+
<a href="#"
50+
hx-get="{% url 'extras:dashboardwidget_add' %}"
51+
hx-target="#htmx-modal-content"
52+
data-bs-toggle="modal"
53+
data-bs-target="#htmx-modal"
54+
class="btn btn-success btn-sm"
55+
>
56+
<i class="mdi mdi-plus"></i> Add Widget
57+
</a>
58+
<button id="save_dashboard" class="btn btn-primary btn-sm" data-url="{% url 'extras-api:dashboard' %}">
59+
<i class="mdi mdi-content-save-outline"></i> Save Layout
60+
</button>
61+
<a href="{% url 'extras:dashboard_reset' %}" class="btn btn-danger btn-sm">
62+
<i class="mdi mdi-backspace"></i> Reset Dashboard
63+
</a>
64+
</div>
5165
</div>
5266
</div>
5367
{% endblock content-wrapper %}

0 commit comments

Comments
 (0)