This commit is contained in:
sebseb7
2025-12-25 02:09:06 +01:00
parent 2c6ddf61f5
commit db4f27302b
3 changed files with 70 additions and 25 deletions

View File

@@ -148,7 +148,7 @@ module.exports = {
app.get('/api/views/:id', (req, res) => {
try {
const stmt = db.prepare('SELECT * FROM views WHERE id = ?');
const stmt = db.prepare('SELECT * FROM views ORDER BY position ASC, id ASC');
const view = stmt.get(req.params.id);
if (view) {
view.config = JSON.parse(view.config);
@@ -192,6 +192,24 @@ module.exports = {
}
});
// Reorder Views
app.post('/api/views/reorder', requireAdmin, (req, res) => {
const { order } = req.body;
if (!Array.isArray(order)) return res.status(400).json({ error: 'Invalid format' });
const updateStmt = db.prepare('UPDATE views SET position = ? WHERE id = ?');
const updateMany = db.transaction((items) => {
for (const item of items) updateStmt.run(item.position, item.id);
});
try {
updateMany(order);
res.json({ success: true });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
// GET /api/devices
// Returns list of unique device/channel pairs
app.get('/api/devices', (req, res) => {