Skip to content

Commit

Permalink
Fix a bunch of UI issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriae committed Dec 21, 2024
1 parent d331d1b commit cb8093c
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 334 deletions.
28 changes: 5 additions & 23 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,9 @@ def __init__(self, data):
self.notes = data.get("notes", "")
self.scouter_id = data.get("scouter_id")
self.created_at = data.get("created_at")

# Handle the nested scouter data
scouter_data = data.get("scouter", {})
self.scouter = {
"username": scouter_data.get("username", "Unknown"),
"team_number": scouter_data.get("team_number"),
"email": scouter_data.get("email"),
}

# Handle scouter name from the aggregation pipeline
self.scouter_name = data.get("scouter_name", "Unknown")

@property
def id(self):
Expand All @@ -101,9 +96,7 @@ def create_from_db(data):
data["_id"] = ObjectId(data["_id"])

# Ensure scouter_id is ObjectId
if "scouter_id" in data and not isinstance(
data["scouter_id"], ObjectId
):
if "scouter_id" in data and not isinstance(data["scouter_id"], ObjectId):
data["scouter_id"] = ObjectId(data["scouter_id"])

return TeamData(data)
Expand All @@ -120,28 +113,17 @@ def to_dict(self):
"total_points": self.total_points,
"notes": self.notes,
"scouter_id": str(self.scouter_id),
"scouter_name": self.scouter_name,
"created_at": self.created_at,
"scouter": self.scouter,
}

@property
def scouter_name(self):
"""Returns formatted scouter name with team number if available"""
username = self.scouter.get("username", "Unknown")
team_number = self.scouter.get("team_number")
return f"{username} ({team_number})"

@property
def formatted_date(self):
"""Returns formatted creation date"""
if self.created_at:
return self.created_at.strftime("%Y-%m-%d %H:%M:%S")
return "N/A"

@property
def is_owner(self):
"""Returns whether the current user is the owner of the data"""
return str(self.scouter_id) != str(self.scouter.get("team_number"))

class PitScouting:
def __init__(self, data: Dict):
Expand Down
29 changes: 26 additions & 3 deletions app/scout/scouting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,37 @@ def get_all_scouting_data(self):
"from": "users",
"localField": "scouter_id",
"foreignField": "_id",
"as": "scouter",
"as": "scouter"
}
},
{"$unwind": {"path": "$scouter", "preserveNullAndEmptyArrays": True}},
{"$unwind": "$scouter"},
{
"$project": {
"_id": 1,
"team_number": 1,
"event_code": 1,
"match_number": 1,
"auto_points": 1,
"teleop_points": 1,
"endgame_points": 1,
"total_points": 1,
"notes": 1,
"scouter_id": 1,
"scouter_name": {"$ifNull": ["$scouter.username", "Unknown"]},
"created_at": 1
}
},
{"$sort": {"created_at": -1}}
]

team_data = list(self.db.team_data.aggregate(pipeline))
return [TeamData.create_from_db(td) for td in team_data]

# Transform the data using create_from_db
transformed_data = []
for td in team_data:
transformed_data.append(TeamData.create_from_db(td))

return transformed_data
except Exception as e:
logger.error(f"Error fetching scouting data: {str(e)}")
return []
Expand Down
18 changes: 15 additions & 3 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@
</div>
<div class="flex space-x-4">
{% if current_user.is_authenticated %}
<a href="{{ url_for('auth.profile', username=current_user.username) }}" class="py-4 px-2 hover:text-blue-500">{{current_user.username}}</a>
<div class="flex items-center space-x-2">
<img src="{{ url_for('auth.profile_picture', user_id=current_user.get_id()) }}"
alt="Profile Picture"
class="w-8 h-8 rounded-full">
<a href="{{ url_for('auth.profile', username=current_user.username) }}"
class="py-4 px-2 hover:text-blue-500">{{current_user.username}}</a>
</div>
<a href="{{ url_for('auth.logout') }}" class="py-4 px-2 hover:text-blue-500">Logout</a>
{% else %}
<a href="{{ url_for('auth.login') }}" class="py-4 px-2 hover:text-blue-500">Login</a>
Expand All @@ -66,7 +72,7 @@
</div>
</nav>
</div>
<nav class="bg-white shadow-lg sm:hidden rounded-xl bg-[#f6f5f3] fixed left-0 top-0 w-full z-50">
<nav class="shadow-lg sm:hidden rounded-xl bg-[#f6f5f3] fixed left-0 top-0 w-full z-50">
<div class="max-w-6xl mx-auto px-4">
<div class="flex justify-between items-center py-4">
<a href="{{ url_for('index') }}" class="font-bold text-blue-500">
Expand All @@ -91,7 +97,13 @@
<a href="{{ url_for('team.join_team_page') }}" class="block py-4 px-4 hover:bg-gray-100 text-green-600">Join Team</a>
{% endif %}
<hr className="align-middle border-gray-500 my-3 w-[50%] overflow-x-hidden m-auto"/>
<span class="block py-4 px-4">{{ current_user.username }}</span>
<div class="flex items-center px-4 py-2">
<img src="{{ url_for('auth.profile_picture', user_id=current_user.get_id()) }}"
alt="Profile Picture"
class="w-10 h-10 rounded-full mr-2">
<a href="{{ url_for('auth.profile', username=current_user.username) }}"
class="hover:text-blue-500">{{current_user.username}}</a>
</div>
<a href="{{ url_for('auth.logout') }}" class="block py-4 px-4 hover:bg-gray-100">Logout</a>
{% else %}
<hr className="align-middle border-gray-500 my-3 w-[50%] overflow-x-hidden m-auto"/>
Expand Down
105 changes: 65 additions & 40 deletions app/templates/scouting/list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% block content %}
<div class="max-w-6xl mx-auto">
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
Expand Down Expand Up @@ -29,17 +29,17 @@ <h2 class="text-lg font-semibold text-gray-700 mb-2">Pending Entries</h2>
</div>
</div>

<div class="flex justify-between items-center mb-8">
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-8 gap-4">
<h1 class="text-2xl font-bold">Team Data</h1>
<div class="flex items-center space-x-4">
<div class="flex flex-col sm:flex-row items-stretch sm:items-center gap-4 w-full sm:w-auto">
<input
type="text"
id="teamSearch"
placeholder="Search teams..."
class="px-4 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500"
class="px-4 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 w-full sm:w-auto"
>
<a href="{{ url_for('scouting.add_scouting_data') }}"
class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">
class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 text-center">
Add New Data
</a>
</div>
Expand All @@ -53,66 +53,91 @@ <h1 class="text-2xl font-bold">Team Data</h1>
{% set _ = event_groups[data.event_code].append(data) %}
{% endfor %}

<div id="teamDataContainer">
<div id="teamDataContainer" class="-mx-4 sm:mx-0">
{% for event_code, teams in event_groups.items() %}
<div class="event-section mb-8" data-event-code="{{ event_code }}">
<h2 class="text-xl font-semibold mb-4 bg-gray-100 rounded">
<h2 class="text-xl font-semibold mb-4 bg-gray-100 rounded px-4 py-2">
{{ event_code }}
</h2>
<div class="overflow-x-auto">
<div class="overflow-x-auto shadow-sm rounded-lg">
<table class="min-w-full divide-y divide-gray-200">
<thead>
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Team Number
<th class="px-3 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Team #
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<th class=" sm:table-cell px-3 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Match
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Auto Points
<th class=" md:table-cell px-3 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Auto
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Teleop Points
<th class=" md:table-cell px-3 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Teleop
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Endgame Points
<th class=" md:table-cell px-3 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Endgame
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Total Points
<th class="px-3 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Total
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<th class=" lg:table-cell px-3 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Notes
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Scouter (Team #)
<th class="px-3 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Scouter
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<th class="px-3 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Actions
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
{% for data in teams %}
<tr class="team-row"
data-team-number="{{ data.team_number }}"
<tr class="team-row hover:bg-gray-50"
data-team-number="{{ data.team_number|string }}"
data-event-code="{{ data.event_code }}"
data-notes="{{ data.notes }}"
data-scouter="{{ data.scouter_name }}">
<td class="px-6 py-4 whitespace-nowrap">{{ data.team_number }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ data.match_number }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ data.auto_points }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ data.teleop_points }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ data.endgame_points }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ data.total_points }}</td>
<td class="px-6 py-4 whitespace-normal ">{{ data.notes }}</td>
<td class="px-6 py-4 whitespace-nowrap">{{ data.scouter_name }}</td>
<td class="px-6 py-4 whitespace-nowrap">
<a href="{{ url_for('scouting.edit_scouting_data', id=data.id) }}"
class="text-indigo-600 hover:text-indigo-900 mr-4">Edit</a>
<a href="{{ url_for('scouting.delete_scouting_data', id=data.id) }}"
class="text-red-600 hover:text-red-900"
onclick="return confirm('Are you sure you want to delete this?')">Delete</a>
<td class="px-3 sm:px-6 py-4 whitespace-nowrap">
<div class="text-sm font-medium text-gray-900">
{{ data.team_number }}
</div>
</td>
<td class="sm:table-cell px-3 sm:px-6 py-4 whitespace-nowrap">{{ data.match_number }}</td>
<td class="md:table-cell px-3 sm:px-6 py-4 whitespace-nowrap">{{ data.auto_points }}</td>
<td class="md:table-cell px-3 sm:px-6 py-4 whitespace-nowrap">{{ data.teleop_points }}</td>
<td class="md:table-cell px-3 sm:px-6 py-4 whitespace-nowrap">{{ data.endgame_points }}</td>
<td class="px-3 sm:px-6 py-4 whitespace-nowrap">{{ data.total_points }}</td>
<td class="lg:table-cell px-3 sm:px-6 py-4 whitespace-normal max-w-xs truncate">{{ data.notes }}</td>
<td class="px-3 sm:px-6 py-4 whitespace-nowrap">
<div class="flex items-center space-x-2">
<img src="{{ url_for('auth.profile_picture', user_id=data.scouter_id) }}"
alt="Profile Picture"
class="w-6 h-6 sm:w-8 sm:h-8 rounded-full">
<div class="flex flex-col sm:flex-row sm:items-center sm:space-x-1">
<a class="text-blue-600 hover:text-blue-900 text-sm"
href="{{ url_for('auth.profile', username=data.scouter_name) }}">
{{ data.scouter_name }}
</a>
<span class="sm:inline"><a href="{{ url_for('team.view_team', team_number=data.team_number) }}" class="hover:text-blue-500">({{ data.team_number }})</a></span>
</div>
</div>
</td>
<td class="px-3 sm:px-6 py-4 whitespace-nowrap">
<div class="flex space-x-2">
<a href="{{ url_for('scouting.edit_scouting_data', id=data.id) }}"
class="text-indigo-600 hover:text-indigo-900">
<span class="hidden sm:inline">Edit</span>
<span class="sm:hidden">📝</span>
</a>
<a href="{{ url_for('scouting.delete_scouting_data', id=data.id) }}"
class="text-red-600 hover:text-red-900"
onclick="return confirm('Are you sure you want to delete this?')">
<span class="hidden sm:inline">Delete</span>
<span class="sm:hidden">🗑️</span>
</a>
</div>
</td>
</tr>
{% endfor %}
Expand Down
Loading

0 comments on commit cb8093c

Please sign in to comment.