Skip to content

Commit b4d1303

Browse files
authored
Merge pull request #18 from Yuval-Roth/cosmetic-fixes
cosmetics
2 parents c359df1 + 08153ce commit b4d1303

3 files changed

Lines changed: 39 additions & 20 deletions

File tree

manager/src/app.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,25 @@ def main_menu():
4343

4444
@app.route('/get_participants', methods=['GET'])
4545
def get_parts():
46-
participants = get_participants() # Replace with your function to fetch participants
46+
online_participants_ids = get_participants() # Replace with your function to fetch participants
47+
all_participants = get_participants_for_view()
4748
# participants = None
4849
# if not participants:
4950
# participants = PARTICIPANTS
50-
if len(participants) > 0 and not isinstance(participants[0], dict):
51-
# Add some dummy data
52-
participants = [{"id": i, # Convert i to int
53-
"firstName": f"Participant {i}",
54-
"lastName": f"Lastname {i}",
55-
"age": 20, # Convert i to int before adding
56-
"gender": "Male",
57-
"email": f"{i}@gmail.com",
58-
"phone": f"1234567{i}"} for i in participants]
59-
return jsonify(participants)
51+
52+
if len(online_participants_ids) > 0 and not isinstance(online_participants_ids[0], dict):
53+
# make every id in the list, from a '003' to '3'
54+
online_participants_ids = [int(x) for x in online_participants_ids]
55+
56+
online_participants = []
57+
for part in all_participants:
58+
# convert from string to dict
59+
part = json.loads(part)
60+
if part['pid'] in online_participants_ids:
61+
online_participants.append(part)
62+
63+
return jsonify(online_participants)
64+
return jsonify(all_participants)
6065

6166

6267
@app.route('/lobbies', methods=['GET'])
@@ -78,19 +83,18 @@ def create_lobby_action():
7883
selected_participants = request.form.getlist('selected_participants') # Get all selected participants
7984
if len(selected_participants) != 2: # Ensure exactly two participants are selected
8085
return "Exactly two participants must be selected to create a lobby.", 400
81-
86+
8287
lobby_id = create_lobby(selected_participants)
8388
if not lobby_id:
8489
return "Failed to create lobby.", 500
85-
90+
8691
return redirect(url_for('lobby', lobby_id=lobby_id, selected_participants=",".join(selected_participants)))
8792

8893
except Exception as e:
8994
Logger.log_error(f"Error creating lobby: {e}")
9095
return f"Error: {e}", 500
9196

9297

93-
9498
@app.route('/delete_lobby', methods=['GET'])
9599
def delete_lobby_action():
96100
lobby_id = request.args.get('lobby_id')
@@ -195,6 +199,8 @@ def stop_game_route():
195199
except Exception as e:
196200
Logger.log_error(f"Unexpected error in /stop_game: {e}")
197201
return jsonify({"status": "error", "message": "Internal server error"}), 500
202+
203+
198204
@app.route('/get_lobby', methods=['POST'])
199205
def get_lobby_route():
200206
lobby_id = request.json.get('lobby_id')
@@ -212,7 +218,6 @@ def get_lobby_route():
212218

213219
@app.route('/update_session_order', methods=['POST'])
214220
def update_session_order():
215-
216221
data = request.json
217222
lobby_id = data.get('lobby_id')
218223
session_order = data.get('session_order')
@@ -243,8 +248,6 @@ def get_sessions_route():
243248
return jsonify({"status": "error", "message": "Internal server error"}), 500
244249

245250

246-
247-
248251
@app.route('/add_session', methods=['POST'])
249252
def add_session():
250253
data = request.json
@@ -296,6 +299,7 @@ def game_type_from_name():
296299
game_type = game_type_name
297300
return jsonify({'status': 'success', 'gameType': game_type})
298301

302+
299303
@app.route('/delete_session', methods=['POST'])
300304
def delete_session_route():
301305
# return jsonify({"status": "success"})
@@ -326,6 +330,7 @@ def participants_menu():
326330

327331
return render_template('participants.html', participants=participants)
328332

333+
329334
@app.route('/add_participant', methods=['POST'])
330335
def add_part():
331336
try:
@@ -347,21 +352,21 @@ def add_part():
347352
def remove_part():
348353
try:
349354
if remove_participant(request.json.get('id')):
350-
return jsonify({"success":True})
355+
return jsonify({"success": True})
351356
return jsonify({"status": "error", "message": "Failed to remove participant"}), 500
352357
except Exception as e:
353358
Logger.log_error(f"Error removing participant: {e}")
354359
return jsonify({"status": "error", "message": "Internal server error"}), 500
355360

356361

357-
358362
###################### OPERATORS ######################
359363
@app.route('/operators', methods=['GET'])
360364
def operators_menu():
361365
if 'username' not in session:
362366
return redirect(url_for('login'))
363367
return render_template('operators.html')
364368

369+
365370
@app.route('/add_operator', methods=['POST'])
366371
def add_oper():
367372
# fetch(url, {
@@ -375,13 +380,17 @@ def add_oper():
375380
return add_operator(username, password)
376381
# return jsonify({"success":True})
377382

383+
378384
@app.route('/get_operators', methods=['GET'])
379385
def get_opers():
380386
return get_operators()
387+
388+
381389
@app.route('/remove_operator', methods=['DELETE'])
382390
def remove_oper():
383391
return remove_operator(request.json.get('username'))
384392

393+
385394
# @app.route('/edit_operator', methods=['PUT'])
386395
# def edit_operator():
387396
# return jsonify({"success":True})

manager/src/managers/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44

55
RUNNING_LOCAL = False
66

7+
8+
79
if RUNNING_LOCAL:
810
URL = "http://localhost:8080"
911
else:
1012
URL = "http://ims-game-server:8080/"
1113

1214

15+
GAL = False
16+
17+
if GAL:
18+
URL = "https://ims-project.cs.bgu.ac.il:8640/"
19+
20+
1321
class server_request:
1422
# {
1523
# "type": "string",

manager/src/templates/lobbies.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ <h2>Create Lobby</h2>
6060
<table class="online-participants-table">
6161
<thead>
6262
<tr>
63-
<th>Participant Name</th>
63+
<th>ID</th>
64+
<th>Participant</th>
6465
<th>Select</th>
6566
</tr>
6667
</thead>
@@ -165,6 +166,7 @@ <h2>Create Lobby</h2>
165166
data.forEach(participant => {
166167
const row = document.createElement('tr');
167168
row.innerHTML = `
169+
<td>${participant.pid}</td>
168170
<td>${participant.firstName} ${participant.lastName}</td>
169171
<td><input type="checkbox" name="selected_participants" value="${participant.id}"></td>
170172
`;

0 commit comments

Comments
 (0)