Versie 0.3.3
This commit is contained in:
1 parent
1cf6eeed29
commit
6e741a51fe
57 files changed
+1362
-2135
No files matched your search
@@ -1,4 +1,4 @@
|
||||
// Generated, do not edit. sha256:ebca807e87ebabedc0e0ca214ca3bec781ace05d2be4dc4ed8d664c767fe1d63
|
||||
// Generated, do not edit. sha256:1cab6c030597184175a0db5bb668aea9074d983a3f04b5255055f6a7df3c07d8
|
||||
import * as db from '../db.js';
|
||||
import { DASHBOARD } from '../../shared/config.js';
|
||||
import { toSearchName } from '../../shared/search-name.js';
|
||||
@@ -84,16 +84,20 @@ function assertWidgetType(type) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function addWidget(profileId, { instanceKey, type, gridX = 0, gridY = 0, assetId = null, settings = null }) {
|
||||
export async function addWidget(profileId, { instanceKey, type, gridX = 0, gridY = 0, assetId = null, settings = null, spanWidth = null }) {
|
||||
if (!db.one(`SELECT id FROM DashboardProfile WHERE id = ?`, [profileId])) {
|
||||
fail('dashboard.unknownProfile', { id: profileId }, `Dashboard profile #${profileId} does not exist.`);
|
||||
}
|
||||
assertWidgetType(type);
|
||||
const span = spanWidth ?? DASHBOARD.WIDGETS[type].defaultSpan;
|
||||
if (!Number.isInteger(span) || span < 1 || span > DASHBOARD.GRID_COLUMNS) {
|
||||
throw new Error(`Widget width ${spanWidth} is not 1 to ${DASHBOARD.GRID_COLUMNS} columns.`);
|
||||
}
|
||||
const key = instanceKey || type;
|
||||
if (db.one(`SELECT 1 AS x FROM DashboardWidget WHERE profileId = ? AND instanceKey = ?`, [profileId, key])) return false;
|
||||
const json = settings && typeof settings === 'object' && Object.keys(settings).length ? JSON.stringify(settings) : null;
|
||||
db.run(`INSERT INTO DashboardWidget (profileId, assetId, instanceKey, gridX, gridY, spanWidth, spanHeight, type, settings)
|
||||
VALUES (?,?,?,?,?,?,NULL,?,?)`, [profileId, assetId, key, gridX, gridY, DASHBOARD.WIDGETS[type].defaultSpan, type, json]);
|
||||
VALUES (?,?,?,?,?,?,NULL,?,?)`, [profileId, assetId, key, gridX, gridY, span, type, json]);
|
||||
await db.persist();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user