today_ai_weather/app/views/cities/_admin_panel.html.erb
songtianlun 973a0882ed feat: add admin panel and update database URL
- Implemented a new admin panel that allows administrators to view
  statistics and manage weather art. The panel includes:
  - A card displaying total images and today's images
  - Buttons to generate new art and edit the city

- Added `admin?` helper method to check if the current user is an
  administrator.

- Updated database configuration to use safer credentials lookup
  method `dig` for development database URL instead of the
  previous method, improving reliability in accessing nested
  credentials.
2025-02-11 16:56:51 +08:00

45 lines
1.8 KiB
Plaintext

<% if admin? %>
<div class="card bg-warning/10 border border-warning/20 shadow-lg p-6">
<div class="flex items-center gap-3 mb-4">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-warning" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
</svg>
<h3 class="font-display font-bold text-lg">Admin Panel</h3>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<!-- 统计数据 -->
<div class="space-y-4">
<h4 class="font-semibold">Statistics</h4>
<div class="stats stats-vertical lg:stats-horizontal shadow">
<div class="stat">
<div class="stat-title">Total Images</div>
<div class="stat-value"><%= @weather_art.city.weather_arts.count %></div>
</div>
<div class="stat">
<div class="stat-title">Today's Images</div>
<div class="stat-value"><%= @weather_art.city.weather_arts.where("created_at >= ?", Time.zone.now.beginning_of_day).count %></div>
</div>
</div>
</div>
<!-- 操作按钮 -->
<div class="space-y-4">
<h4 class="font-semibold">Actions</h4>
<div class="flex flex-wrap gap-4">
<%= button_to "Generate New Art", "#",
method: :post,
data: {
controller: "generate-art",
action: "generate-art#generate",
city_id: @weather_art.city.id
},
class: "btn btn-primary" %>
<%= link_to "Edit City", edit_city_path(@weather_art.city), class: "btn btn-secondary" %>
</div>
</div>
</div>
</div>
<% end %>