Skip to content

Commit dce1d12

Browse files
committed
Now item order changes, added UI and fixed scheduling
1 parent 6436b0d commit dce1d12

5 files changed

Lines changed: 51 additions & 25 deletions

File tree

controller/queue_item.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,18 @@ def update_item_order(self, queue_id, new_order):
7878

7979
if queue_id is None:
8080
return jsonify(error="No id provided."), 400
81-
82-
if self.user.is_admin():
83-
queue_dao = QueueItemDAO()
84-
response = queue_dao.update_item_order(queue_id, new_order)
85-
if response == 0:
86-
return jsonify("Approval updated"), 200
81+
if self.email is not None:
82+
if self.user.is_admin():
83+
queue_dao = QueueItemDAO()
84+
response = queue_dao.update_item_order(queue_id, new_order)
85+
if response == 0:
86+
return jsonify("Order updated"), 200
87+
else:
88+
return jsonify(error="Couldn't update Order"), 500
8789
else:
88-
return jsonify(error="Couldn't update approval"), 500
89-
else:
90-
return jsonify(error="Unauthorized."), 403
90+
return jsonify(error="Unauthorized."),
91+
92+
return jsonify(error="Unauthorized. No token."), 401
9193

9294
def deleteQueueItemById(self, queue_id):
9395
dao = QueueItemDAO()

model/queue_item.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def update_item_order(self, queue_id: int, new_order: int):
8585
status = 1
8686
query = None
8787
cursor = self.conn.cursor()
88-
old_order = self.getQueueItemById(queue_id)["display_order"]
88+
old_order = self.getQueueItemById(queue_id)[5]
8989
if new_order < old_order:
9090
query = "UPDATE queue_item SET display_order = display_order + 1 WHERE display_order >= ? AND display_order < ?"
9191
elif new_order > old_order:
@@ -154,10 +154,10 @@ def getScheduledDesigns(self):
154154
d.updated_at
155155
FROM queue_item q
156156
JOIN design d ON q.design_id = d.design_id
157-
WHERE d.is_approved = 1
158-
ORDER BY
159-
CASE WHEN q.scheduled = 1 THEN q.start_time ELSE '9999-12-31 23:59:59' END ASC,
160-
q.display_order ASC;
157+
WHERE d.is_approved = 1 AND q.scheduled = 1
158+
AND strftime('%Y-%m-%d %H:%M:%S', q.start_time) <= strftime('%Y-%m-%d %H:%M:%S', 'now')
159+
AND strftime('%Y-%m-%d %H:%M:%S', q.end_time) >= strftime('%Y-%m-%d %H:%M:%S', 'now')
160+
ORDER BY q.display_order ASC;
161161
"""
162162
try:
163163
cursor.execute(query)
@@ -185,9 +185,7 @@ def get_all_items_paginated(self, page, page_size):
185185
d.is_approved
186186
FROM queue_item q
187187
JOIN design d ON q.design_id = d.design_id
188-
ORDER BY
189-
CASE WHEN q.scheduled = 1 THEN q.start_time ELSE '9999-12-31 23:59:59' END ASC,
190-
q.display_order ASC
188+
ORDER BY q.display_order ASC
191189
LIMIT ? OFFSET ?;
192190
"""
193191
cursor.execute(query, (page_size, offset))

view/src/pages/QueueAdminPage.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,15 @@ function QueueAdminPage() {
135135
<div className="text-base">
136136
<strong>Order:</strong> {" "}
137137
<select
138+
className="order-select"
138139
value={item.display_order}
139-
onChange={(e) =>
140+
onChange={(e) => {
141+
const newPos = Number(e.target.value);
140142
showConfirm(
141-
`Move item to position ${e.target.value}?`,
142-
() => handleOrderUpdate(item.queue_id, Number(e.target.value))
143-
)
144-
}
143+
`Move item to position ${newPos}?`,
144+
() => handleOrderUpdate(item.queue_id, newPos)
145+
);
146+
}}
145147
>
146148
{Array.from({ length: total }).map((_, idx) => (
147149
<option key={idx + 1} value={idx + 1}>

view/src/pages/UploadPage.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ function UploadPage() {
208208
// Otherwise, compute the next available slot.
209209
const now = new Date();
210210
const nextAvailableStart = new Date(now.getTime() + 60 * 1000); // 1 minute from now
211-
const defaultDurationSeconds = 60; // default duration (60 seconds)
212-
const nextAvailableEnd = new Date(nextAvailableStart.getTime() + defaultDurationSeconds * 1000);
211+
// const defaultDurationSeconds = 60; // default duration (60 seconds)
212+
const oneDayMs = 24 * 60 * 60 * 1000; // If not given a schedule items will stay one day in the active queue
213+
const nextAvailableEnd = new Date(nextAvailableStart.getTime() + oneDayMs);
213214
finalStart = nextAvailableStart.toISOString().substring(0, 19);
214215
finalEnd = nextAvailableEnd.toISOString().substring(0, 19);
215216
}
@@ -231,7 +232,7 @@ function UploadPage() {
231232
showAlert("Image successfully added to queue.");
232233
}
233234
} catch (error) {
234-
showAlert("Error adding image to queue.");
235+
showAlert("Error adding image to queue.", error);
235236
}
236237
};
237238

view/src/pages/styles/QueueAdmin.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2+
.order-select {
3+
appearance: none;
4+
-webkit-appearance: none;
5+
padding-right: 2rem;
6+
padding-left: .5rem;
7+
min-height: 28px;
8+
border: 1px solid black;
9+
border-radius: 6px;
10+
background-color: #fff;
11+
12+
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 8 5' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23000000'/%3E%3C/svg%3E");
13+
background-repeat: no-repeat;
14+
background-position: right .5rem center;
15+
background-size: 8px 5px;
16+
}
17+
18+
.order-select:focus {
19+
outline: none;
20+
border-color: #2563eb;
21+
box-shadow: 0 0 0 2px rgba(37,99,235,.3);
22+
}
23+
124
.approval-label {
225
font-family: "Pixelify Sans", sans-serif;
326
border-radius: 24px;

0 commit comments

Comments
 (0)