1
0
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:
jeremystretch
2023-04-05 09:59:22 -04:00
parent 29fbe6e4ee
commit f44a2ba0ee
4 changed files with 71 additions and 25 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -2,6 +2,20 @@ import { GridStack, GridStackOptions, GridStackWidget } from 'gridstack';
import { createToast } from './bs';
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(
url: string,
gridData: GridStackWidget[] | GridStackOptions,
@@ -22,6 +36,8 @@ export function initDashboard(): void {
// Initialize the grid
let grid = GridStack.init({
cellHeight: 100,
disableDrag: true,
disableResize: true,
draggable: {
handle: '.grid-stack-item-content .card-header',
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
const gridSaveButton = document.getElementById('save_dashboard') as HTMLButtonElement;
if (gridSaveButton === null) {