Skip to content

Commit 4845c71

Browse files
authored
Small fixes (#576)
* Decorate bookmarks * set bookmarkable_types using constant * Change workshop_variations index logic based on super_user * Add detail methods to decorators so they work on recent_activity * Fix bug on recent_activity for Address * Delegate windows_type to workshop for workshop_variations * Call class.name on bookmarkable.object, since it's decorated * Add white background to inner form * Flex display of fields on stories form * Change display of audit data on stories form * Remove white background on workshop_ideas search boxes * Remove border from workshop_ideas form * Fix text on workshop_logs new page * Add admin-only class before bg-blue-100 * Make workshop_variations index match format * Change display of sectors on workshops form * Show total on index to be total_entries
1 parent b12eb6b commit 4845c71

24 files changed

+262
-118
lines changed

app/controllers/bookmarks_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def tally
9090
# Resolve polymorphic objects + sort desc
9191
@bookmark_counts = grouped_counts.group_by(&:first).flat_map do |type, rows|
9292
ids = rows.map { |_, id, _| id }
93-
found = type.constantize.where(id: ids).index_by(&:id)
93+
found = type.constantize.where(id: ids).decorate.index_by(&:id)
9494

9595
rows.filter_map do |(_, id, count)|
9696
[found[id], count] if found[id]
@@ -99,6 +99,8 @@ def tally
9999

100100
@windows_types_array = WindowsType::TYPES
101101

102+
@bookmarkable_types = Bookmark::BOOKMARKABLE_MODELS.map{ |type| [ type, type ] }
103+
102104
@workshops = Workshop.where("led_count > 0").order(led_count: :desc)
103105
end
104106

app/controllers/workshop_variations_controller.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
class WorkshopVariationsController < ApplicationController
22

33
def index
4-
if current_user.super_user?
5-
@workshop_variations = WorkshopVariation.joins(:workshop).
6-
where(workshops: { inactive: false }).
7-
order('workshops.title, workshop_variations.name').
8-
paginate(page: params[:page], per_page: 25)
9-
else
4+
unless current_user.super_user?
105
redirect_to authenticated_root_path
6+
return
117
end
8+
9+
@workshop_variations =
10+
WorkshopVariation
11+
.joins(:workshop)
12+
.includes(:workshop)
13+
.where(workshops: { inactive: false })
14+
.order("workshops.title, workshop_variations.name")
15+
.paginate(page: params[:page], per_page: 25)
16+
.decorate
1217
end
1318

1419
def new
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class AddressDecorator < ApplicationDecorator
2+
3+
def title
4+
name
5+
end
6+
7+
def detail
8+
"Address for #{addressable&.name}"
9+
end
10+
11+
def url
12+
Rails.application.routes.url_helpers.polymorphic_path(addressable)
13+
end
14+
15+
end

app/decorators/workshop_log_decorator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class WorkshopLogDecorator < ApplicationDecorator
22

3+
def detail(length: nil)
4+
length ? description&.truncate(length) : description
5+
end
6+
37
def main_image_url
48
if main_image&.file&.attached?
59
Rails.application.routes.url_helpers.url_for(main_image.file)

app/decorators/workshop_variation_decorator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ def breadcrumbs
44
"#{workshop_link} >> #{name}".html_safe
55
end
66

7+
def detail(length: nil)
8+
length ? description&.truncate(length) : description
9+
end
10+
711
def display_code
812
if legacy
913
html = Nokogiri::HTML(code)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
module AdminDashboardCardsHelper
2+
# -----------------------------
3+
# SYSTEM / ADMIN CARDS
4+
# -----------------------------
5+
def system_cards
6+
[
7+
model_card(:banners, icon: "📣"),
8+
model_card(:community_news, icon: "📰"),
9+
model_card(:events, icon: "📆"),
10+
model_card(:faqs, icon: "❔", title: "FAQs"),
11+
model_card(:stories, icon: "🗣️"),
12+
custom_card("Tagging counts", taggings_matrix_path, icon: "🧮", color: :lime),
13+
model_card(:resources, icon: "📚"),
14+
model_card(:workshops, icon: "🎨"),
15+
model_card(:projects, icon: "🏫"),
16+
model_card(:facilitators, icon: "🧑‍🎨"),
17+
model_card(:users, icon: "👥", title: "User accounts")
18+
]
19+
end
20+
21+
# -----------------------------
22+
# USER CONTENT CARDS
23+
# -----------------------------
24+
def user_content_cards
25+
[
26+
custom_card("Activity logs", dashboard_recent_activities_path, icon: "🧭"),
27+
custom_card("Bookmarks tally", tally_bookmarks_path, icon: "🔖"),
28+
model_card(:event_registrations, icon: "🎟️", intensity: 100, title: "Event Registrations"),
29+
model_card(:quotes, icon: "💬", intensity: 100),
30+
model_card(:story_ideas, icon: "✍️", intensity: 100),
31+
custom_card("Tags", tags_path, icon: "🏷️", color: :lime, intensity: 100),
32+
model_card(:workshop_variations, icon: "🔀", intensity: 100),
33+
model_card(:workshop_ideas, icon: "💡", intensity: 100),
34+
model_card(:workshop_logs, icon: "📝", intensity: 100),
35+
]
36+
end
37+
38+
# -----------------------------
39+
# REFERENCE CARDS
40+
# -----------------------------
41+
def reference_cards
42+
[
43+
custom_card("Categories", authenticated_root_path, icon: "🗂️"),
44+
custom_card("Sectors", authenticated_root_path, icon: "🏭"),
45+
custom_card("Project Statuses", authenticated_root_path, icon: "🧮"),
46+
custom_card("Windows Types", windows_types_path, icon: "🪟"),
47+
]
48+
end
49+
50+
# ============================================================
51+
# CARD BUILDERS
52+
# ============================================================
53+
def model_card(key, title: nil, icon:, intensity: 50)
54+
{
55+
title: title || key.to_s.humanize,
56+
path: polymorphic_path(key.to_s.classify.constantize),
57+
icon: icon,
58+
bg_color: DomainTheme.bg_class_for(key, intensity: intensity),
59+
hover_bg_color: DomainTheme.bg_class_for(key, intensity: intensity == 50 ? 100 : intensity + 100, hover: true),
60+
text_color: "text-gray-800"
61+
}
62+
end
63+
64+
def custom_card(title, path, icon:, color: :gray, intensity: 50)
65+
{
66+
title: title,
67+
path: path,
68+
icon: icon,
69+
bg_color: "bg-#{color}-#{intensity}",
70+
hover_bg_color: "hover:bg-#{color}-#{intensity == 50 ? 100 : intensity + 100}",
71+
text_color: "text-gray-800"
72+
}
73+
end
74+
end

app/models/workshop_variation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class WorkshopVariation < ApplicationRecord
1616

1717
scope :active, -> { where(inactive: false) }
1818

19+
delegate :windows_type, to: :workshop
20+
1921
def description
2022
code # TODO - rename this field
2123
end

app/views/bookmarks/tally.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
bookmarkable_id: bookmarkable.id),
2727
class: "hover:underline" %></td>
2828
<td>
29-
<%= bookmarkable.class.name %>
29+
<%= bookmarkable.object.class.name %>
3030
</td>
3131
<td class="px-4 py-2">
3232
<% if bookmarkable.is_a?(Workshop) || (bookmarkable.is_a?(Resource) && bookmarkable.windows_type_id) %>

app/views/dashboard/_recent_activity.html.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ overflow-hidden flex flex-col md:flex-row">
3636
</div>
3737

3838
<div class="flex-1 p-4">
39-
<% path = (activity.object.is_a?(Resource) ? activity.url ||
40-
resource_path(activity) : polymorphic_path(activity)) %>
39+
<% if activity.object.is_a?(Resource) || activity.object.is_a?(Address) %>
40+
<% path = activity.url || resource_path(activity) %>
41+
<% else %>
42+
<% path = polymorphic_path(activity) %>
43+
<% end %>
44+
4145
<%= link_to path, class: "hover:underline" do %>
4246
<h3 class="text-lg font-semibold text-gray-900">
4347
<%= link_to activity.title,

app/views/facilitators/index.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<!-- Filter form -->
2020
<%= render "search_boxes" %>
2121

22-
<div class="overflow-x-auto">
22+
<div class="rounded-xl bg-white p-6">
23+
<div class="overflow-x-auto">
2324
<table class="w-full border-collapse border border-gray-200">
2425
<thead class="bg-gray-100">
2526
<tr>
@@ -90,6 +91,7 @@
9091
</tbody>
9192
</table>
9293
</div>
94+
</div>
9395

9496
<!-- Empty state -->
9597
<% unless @facilitators.any? %>

0 commit comments

Comments
 (0)