nextjs-rewrite #5

Merged
david merged 56 commits from nextjs-rewrite into main 2026-03-30 02:30:16 +00:00
3 changed files with 178 additions and 0 deletions
Showing only changes of commit c5f6b2f6b3 - Show all commits
+73
View File
@@ -0,0 +1,73 @@
# frozen_string_literal: true
module EuchreCamp
module Actions
module Admin
class Index < EuchreCamp::Action
include Deps[
players_repo: 'repositories.players',
events_repo: 'repositories.events',
matches_repo: 'repositories.matches'
]
def handle(request, response)
# Check if user has permission to view admin panel
user = current_user(request)
unless user && EuchreCamp::Services::Authorization.can?(user, :view_admin_panel)
response.flash[:error] = 'Access denied'
response.redirect_to '/rankings'
return
end
# Get dashboard statistics
total_players = players_repo.all.length
active_tournaments = events_repo.upcoming.length
completed_tournaments = events_repo.completed.length
recent_matches = get_recent_matches
user = current_user(request)
render_with_player(request, response,
total_players: total_players,
active_tournaments: active_tournaments,
completed_tournaments: completed_tournaments,
recent_matches: recent_matches,
current_user: user
)
end
private
def get_recent_matches
rom = EuchreCamp::App["persistence.rom"]
matches = rom.relations[:matches]
.order(Sequel.desc(:id))
.limit(5)
.to_a
# Get player names
all_players = rom.relations[:players].to_a.to_h { |p| [p[:id], p] }
matches.map do |match|
team_1 = [
all_players[match[:team_1_p1_id]],
all_players[match[:team_1_p2_id]]
].compact
team_2 = [
all_players[match[:team_2_p1_id]],
all_players[match[:team_2_p2_id]]
].compact
{
id: match[:id],
team_1: team_1,
team_2: team_2,
score: "#{match[:team_1_score]}-#{match[:team_2_score]}",
status: match[:status],
played_at: match[:played_at]
}
end
end
end
end
end
end
+91
View File
@@ -0,0 +1,91 @@
<h1>Admin Dashboard</h1>
<div class="dashboard-stats">
<div class="stat-card">
<div class="stat-value"><%= total_players %></div>
<div class="stat-label">Total Players</div>
<a href="/admin/players" class="stat-link">Manage Players →</a>
</div>
<div class="stat-card">
<div class="stat-value"><%= active_tournaments %></div>
<div class="stat-label">Active Tournaments</div>
<a href="/admin/tournaments" class="stat-link">Manage Tournaments →</a>
</div>
<div class="stat-card">
<div class="stat-value"><%= completed_tournaments %></div>
<div class="stat-label">Completed Tournaments</div>
<a href="/admin/tournaments" class="stat-link">View History →</a>
</div>
<div class="stat-card">
<div class="stat-value"><%= recent_matches.count %></div>
<div class="stat-label">Recent Matches</div>
<a href="/admin/matches" class="stat-link">Record Match →</a>
</div>
</div>
<hr>
<div class="quick-actions">
<h2>Quick Actions</h2>
<div class="action-buttons">
<% if defined?(current_user) && current_user %>
<a href="/admin/matches/new" class="btn btn-primary">Record Match Result</a>
<% if EuchreCamp::Services::Authorization.can?(current_user, :create_tournament) %>
<a href="/admin/tournaments/new" class="btn btn-primary">Create Tournament</a>
<% end %>
<% if EuchreCamp::Services::Authorization.can?(current_user, :edit_any_record) %>
<a href="/admin/players/new" class="btn btn-primary">Add Player</a>
<% end %>
<a href="/admin/matches/upload" class="btn">Upload CSV</a>
<% else %>
<a href="/admin/matches/new" class="btn btn-primary">Record Match Result</a>
<% end %>
</div>
</div>
<hr>
<div class="recent-activity">
<h2>Recent Matches</h2>
<% if recent_matches.any? %>
<table>
<thead>
<tr>
<th>Match ID</th>
<th>Team 1</th>
<th>Score</th>
<th>Team 2</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<% recent_matches.each do |match| %>
<tr>
<td><%= match[:id] %></td>
<td><%= match[:team_1].map { |p| p[:name] }.join(' + ') %></td>
<td><strong><%= match[:score] %></strong></td>
<td><%= match[:team_2].map { |p| p[:name] }.join(' + ') %></td>
<td><%= match[:played_at]&.strftime('%Y-%m-%d') || '-' %></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p>No matches recorded yet.</p>
<% end %>
</div>
<hr>
<div class="admin-links">
<h2>Admin Sections</h2>
<ul>
<li><a href="/admin/players">Player Management</a> - Add, edit, and manage players</li>
<li><a href="/admin/tournaments">Tournament Management</a> - Create and manage tournaments</li>
<li><a href="/admin/matches">Match Entry</a> - Record individual match results</li>
<li><a href="/admin/matches/upload">CSV Upload</a> - Bulk import matches from CSV</li>
</ul>
</div>
+14
View File
@@ -0,0 +1,14 @@
# frozen_string_literal: true
module EuchreCamp
module Views
module Admin
class Index < EuchreCamp::View
expose :total_players
expose :active_tournaments
expose :completed_tournaments
expose :recent_matches
end
end
end
end