u
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user