admin order line
This commit is contained in:
@@ -269,6 +269,54 @@ def captcha_status():
|
||||
return jsonify({'captcha_active': active})
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /dashboard/commands/queue
|
||||
# Returns pending+executing BUILD commands for a specific town,
|
||||
# ordered by their manual position (for the per-town build queue UI).
|
||||
# ------------------------------------------------------------------
|
||||
@dashboard.route('/dashboard/commands/queue', methods=['GET'])
|
||||
def get_town_build_queue():
|
||||
player_id = request.args.get('player_id')
|
||||
town_id = request.args.get('town_id')
|
||||
conn = get_db()
|
||||
rows = conn.execute('''
|
||||
SELECT id, town_id, town_name, type, payload, status, result_msg, position, created_at, updated_at
|
||||
FROM commands
|
||||
WHERE player_id = ? AND town_id = ? AND type = 'build'
|
||||
AND status IN ('pending', 'executing')
|
||||
ORDER BY position ASC, id ASC
|
||||
''', (player_id, town_id)).fetchall()
|
||||
conn.close()
|
||||
return jsonify([dict(r) for r in rows])
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# POST /dashboard/commands/reorder
|
||||
# Accepts { player_id, town_id, order: [id1, id2, ...] }
|
||||
# and updates position for each command in the list.
|
||||
# ------------------------------------------------------------------
|
||||
@dashboard.route('/dashboard/commands/reorder', methods=['POST'])
|
||||
def reorder_commands():
|
||||
data = request.get_json(silent=True) or {}
|
||||
player_id = data.get('player_id')
|
||||
town_id = data.get('town_id')
|
||||
order = data.get('order', []) # list of command ids in desired order
|
||||
|
||||
if not player_id or not town_id or not order:
|
||||
return jsonify({'error': 'missing player_id, town_id or order'}), 400
|
||||
|
||||
conn = get_db()
|
||||
for idx, cmd_id in enumerate(order):
|
||||
conn.execute('''
|
||||
UPDATE commands
|
||||
SET position = ?
|
||||
WHERE id = ? AND player_id = ? AND town_id = ?
|
||||
''', (idx + 1, cmd_id, player_id, str(town_id)))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'ok': True})
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /dashboard/commands
|
||||
# Returns command history (last 50) for the log panel.
|
||||
@@ -326,14 +374,26 @@ def create_command():
|
||||
return jsonify({'error': 'client_offline', 'message': 'Το script είναι offline — δεν μπορείτε να στείλετε εντολές.'}), 503
|
||||
|
||||
c = conn.cursor()
|
||||
|
||||
# Assign position = one more than the current max for this town's pending build queue
|
||||
if cmd_type == 'build':
|
||||
pos_row = c.execute('''
|
||||
SELECT MAX(position) as max_pos FROM commands
|
||||
WHERE player_id = ? AND town_id = ? AND type = 'build' AND status IN (''pending'', ''executing'')
|
||||
''', (str(data['player_id']), str(data['town_id']))).fetchone()
|
||||
position = (pos_row['max_pos'] or 0) + 1
|
||||
else:
|
||||
position = None
|
||||
|
||||
c.execute('''
|
||||
INSERT INTO commands (town_id, town_name, type, payload, status, created_at, updated_at, player_id)
|
||||
VALUES (?, ?, ?, ?, 'pending', ?, ?, ?)
|
||||
INSERT INTO commands (town_id, town_name, type, payload, status, position, created_at, updated_at, player_id)
|
||||
VALUES (?, ?, ?, ?, 'pending', ?, ?, ?, ?)
|
||||
''', (
|
||||
str(data['town_id']),
|
||||
data.get('town_name', ''),
|
||||
cmd_type,
|
||||
json.dumps(data['payload']),
|
||||
position,
|
||||
datetime.utcnow().isoformat(),
|
||||
datetime.utcnow().isoformat(),
|
||||
str(data['player_id'])
|
||||
|
||||
Reference in New Issue
Block a user