Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions manager/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,25 @@ def main_menu():

@app.route('/get_participants', methods=['GET'])
def get_parts():
participants = get_participants() # Replace with your function to fetch participants
online_participants_ids = get_participants() # Replace with your function to fetch participants
all_participants = get_participants_for_view()
# participants = None
# if not participants:
# participants = PARTICIPANTS
if len(participants) > 0 and not isinstance(participants[0], dict):
# Add some dummy data
participants = [{"id": i, # Convert i to int
"firstName": f"Participant {i}",
"lastName": f"Lastname {i}",
"age": 20, # Convert i to int before adding
"gender": "Male",
"email": f"{i}@gmail.com",
"phone": f"1234567{i}"} for i in participants]
return jsonify(participants)

if len(online_participants_ids) > 0 and not isinstance(online_participants_ids[0], dict):
# make every id in the list, from a '003' to '3'
online_participants_ids = [int(x) for x in online_participants_ids]

online_participants = []
for part in all_participants:
# convert from string to dict
part = json.loads(part)
if part['pid'] in online_participants_ids:
online_participants.append(part)

return jsonify(online_participants)
return jsonify(all_participants)


@app.route('/lobbies', methods=['GET'])
Expand All @@ -78,19 +83,18 @@ def create_lobby_action():
selected_participants = request.form.getlist('selected_participants') # Get all selected participants
if len(selected_participants) != 2: # Ensure exactly two participants are selected
return "Exactly two participants must be selected to create a lobby.", 400

lobby_id = create_lobby(selected_participants)
if not lobby_id:
return "Failed to create lobby.", 500

return redirect(url_for('lobby', lobby_id=lobby_id, selected_participants=",".join(selected_participants)))

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



@app.route('/delete_lobby', methods=['GET'])
def delete_lobby_action():
lobby_id = request.args.get('lobby_id')
Expand Down Expand Up @@ -195,6 +199,8 @@ def stop_game_route():
except Exception as e:
Logger.log_error(f"Unexpected error in /stop_game: {e}")
return jsonify({"status": "error", "message": "Internal server error"}), 500


@app.route('/get_lobby', methods=['POST'])
def get_lobby_route():
lobby_id = request.json.get('lobby_id')
Expand All @@ -212,7 +218,6 @@ def get_lobby_route():

@app.route('/update_session_order', methods=['POST'])
def update_session_order():

data = request.json
lobby_id = data.get('lobby_id')
session_order = data.get('session_order')
Expand Down Expand Up @@ -243,8 +248,6 @@ def get_sessions_route():
return jsonify({"status": "error", "message": "Internal server error"}), 500




@app.route('/add_session', methods=['POST'])
def add_session():
data = request.json
Expand Down Expand Up @@ -296,6 +299,7 @@ def game_type_from_name():
game_type = game_type_name
return jsonify({'status': 'success', 'gameType': game_type})


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

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


@app.route('/add_participant', methods=['POST'])
def add_part():
try:
Expand All @@ -347,21 +352,21 @@ def add_part():
def remove_part():
try:
if remove_participant(request.json.get('id')):
return jsonify({"success":True})
return jsonify({"success": True})
return jsonify({"status": "error", "message": "Failed to remove participant"}), 500
except Exception as e:
Logger.log_error(f"Error removing participant: {e}")
return jsonify({"status": "error", "message": "Internal server error"}), 500



###################### OPERATORS ######################
@app.route('/operators', methods=['GET'])
def operators_menu():
if 'username' not in session:
return redirect(url_for('login'))
return render_template('operators.html')


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


@app.route('/get_operators', methods=['GET'])
def get_opers():
return get_operators()


@app.route('/remove_operator', methods=['DELETE'])
def remove_oper():
return remove_operator(request.json.get('username'))


# @app.route('/edit_operator', methods=['PUT'])
# def edit_operator():
# return jsonify({"success":True})
Expand Down
8 changes: 8 additions & 0 deletions manager/src/managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

RUNNING_LOCAL = False



if RUNNING_LOCAL:
URL = "http://localhost:8080"
else:
URL = "http://ims-game-server:8080/"


GAL = False

if GAL:
URL = "https://ims-project.cs.bgu.ac.il:8640/"


class server_request:
# {
# "type": "string",
Expand Down
4 changes: 3 additions & 1 deletion manager/src/templates/lobbies.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ <h2>Create Lobby</h2>
<table class="online-participants-table">
<thead>
<tr>
<th>Participant Name</th>
<th>ID</th>
<th>Participant</th>
<th>Select</th>
</tr>
</thead>
Expand Down Expand Up @@ -165,6 +166,7 @@ <h2>Create Lobby</h2>
data.forEach(participant => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${participant.pid}</td>
<td>${participant.firstName} ${participant.lastName}</td>
<td><input type="checkbox" name="selected_participants" value="${participant.id}"></td>
`;
Expand Down