Skip to content

Commit b12eb6b

Browse files
authored
DRY up domain colors (#575)
* Add DomainTheme to lib and reference it for colors * Remove hard-coded colors and replace w calls to DomainTheme.bg_class_for * Replace button tailwind classes w btn btn-danger-outline * Use tagging_label partial to show sector and category buttons * Adjust sector word to Service populations, and change taggings index to match format
1 parent 617701e commit b12eb6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+436
-267
lines changed

app/controllers/taggings_controller.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ def matrix
4444
# ------------------------------------------------------------------
4545
@model_heatmap_stats = {}
4646

47-
Tag::TAGGABLE_MODELS.each do |key, model_class|
47+
Tag::TAGGABLE_META.each do |key, data|
48+
klass = data[:klass]
4849
@model_heatmap_stats[key] = { sector: {}, category: {} }
4950

50-
model_class
51+
klass
5152
.published
5253
.joins(:sectors)
5354
.group("sectors.id")
@@ -56,7 +57,7 @@ def matrix
5657
@model_heatmap_stats[key][:sector][sector_id] = count
5758
end
5859

59-
model_class
60+
klass
6061
.published
6162
.joins(:categories)
6263
.group("categories.id")

app/decorators/facilitator_decorator.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ def badges
3737
years = member_since ? (Time.zone.now.year - member_since.year) : 0
3838
badges = []
3939
badges << ["Legacy Facilitator (10+ years)", "yellow"] if years >= 10
40-
badges << ["Seasoned Facilitator (3-10 years)", "gray"] if member_since.present? && years >= 3
40+
badges << ["Seasoned Facilitator (3-10 years)", DomainTheme.bg_class_for(:facilitators)] if member_since.present? && years >= 3
4141
badges << ["New Facilitator (<3 years)", "green"] if member_since.present? && years < 3
4242
badges << ["Spotlighted Facilitator", "gray"] if stories_as_spotlighted_facilitator
43-
badges << ["Events Attended", "blue"] if user.events.any?
44-
badges << ["Workshop Author", "indigo"] if user.workshops.any? # indigo
45-
badges << ["Story Author", "rose"] if user.stories_as_creator.any? # pink
46-
badges << ["Sector Leader", "purple"] if sectorable_items.where(is_leader: true).any?
43+
badges << ["Events Attended", DomainTheme.bg_class_for(:events)] if user.events.any?
44+
badges << ["Workshop Author", DomainTheme.bg_class_for(:workshops)] if user.workshops.any? # indigo
45+
badges << ["Story Author", DomainTheme.bg_class_for(:stories)] if user.stories_as_creator.any? # pink
46+
badges << ["Sector Leader", DomainTheme.bg_class_for(:sectors)] if sectorable_items.where(is_leader: true).any?
4747
badges << ["Blog Contributor", "orange"] if true # || user.respond_to?(:blogs) && user.blogs.any? # red
4848
badges
4949
end

app/helpers/tag_matrix_helper.rb

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,64 +27,19 @@ def tag_link_for(model, tag:, type:)
2727
def heatmap_class_for(count, model_key:, type:, quantiles:)
2828
return "bg-white" if count.zero?
2929

30-
q = quantiles[model_key][type]
31-
return base_color(model_key, 200) if q.nil?
32-
30+
q = quantiles.dig(model_key, type)
3331
shade =
34-
if count <= q[:q20]
35-
50
36-
elsif count <= q[:q40]
37-
100
38-
elsif count <= q[:q60]
32+
if q.nil?
3933
200
40-
elsif count <= q[:q80]
41-
300
42-
else
43-
400
34+
elsif count <= q[:q20] then 50
35+
elsif count <= q[:q40] then 100
36+
elsif count <= q[:q60] then 200
37+
elsif count <= q[:q80] then 300
38+
else 400
4439
end
4540

46-
base_color(model_key, shade)
41+
base_color = DomainTheme::COLORS[model_key] || :gray
42+
"bg-#{base_color}-#{shade}"
4743
end
4844

49-
def base_color(model_key, shade)
50-
color = Tag::TAGGABLE_COLORS.fetch(model_key, :gray)
51-
{
52-
indigo: {
53-
50 => "bg-indigo-50", 100 => "bg-indigo-100",
54-
200 => "bg-indigo-200", 300 => "bg-indigo-300", 400 => "bg-indigo-400"
55-
},
56-
violet: {
57-
50 => "bg-violet-50", 100 => "bg-violet-100",
58-
200 => "bg-violet-200", 300 => "bg-violet-300", 400 => "bg-violet-400"
59-
},
60-
orange: {
61-
50 => "bg-orange-50", 100 => "bg-orange-100",
62-
200 => "bg-orange-200", 300 => "bg-orange-300", 400 => "bg-orange-400"
63-
},
64-
rose: {
65-
50 => "bg-rose-50", 100 => "bg-rose-100",
66-
200 => "bg-rose-200", 300 => "bg-rose-300", 400 => "bg-rose-400"
67-
},
68-
blue: {
69-
50 => "bg-blue-50", 100 => "bg-blue-100",
70-
200 => "bg-blue-200", 300 => "bg-blue-300", 400 => "bg-blue-400"
71-
},
72-
sky: {
73-
50 => "bg-sky-50", 100 => "bg-sky-100",
74-
200 => "bg-sky-200", 300 => "bg-sky-300", 400 => "bg-sky-400"
75-
},
76-
cyan: {
77-
50 => "bg-cyan-50", 100 => "bg-cyan-100",
78-
200 => "bg-cyan-200", 300 => "bg-cyan-300", 400 => "bg-cyan-400"
79-
},
80-
emerald: {
81-
50 => "bg-emerald-50", 100 => "bg-emerald-100",
82-
200 => "bg-emerald-200", 300 => "bg-emerald-300", 400 => "bg-emerald-400"
83-
},
84-
gray: {
85-
50 => "bg-gray-50", 100 => "bg-gray-100",
86-
200 => "bg-gray-200", 300 => "bg-gray-300", 400 => "bg-gray-400"
87-
}
88-
}.dig(color, shade) || "bg-gray-100"
89-
end
9045
end

app/helpers/taggings_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module TaggingsHelper
22

33
def tagged_index_path(type, sector_names:, category_names:)
4-
model = Tag::TAGGABLE_MODELS.fetch(type)
4+
klass = Tag::TAGGABLE_META.fetch(type)[:klass]
55

66
params = {}
77

@@ -15,7 +15,7 @@ def tagged_index_path(type, sector_names:, category_names:)
1515
params[:categories] = hashify_ids(category_ids)
1616
end
1717

18-
polymorphic_path(model, params)
18+
polymorphic_path(klass, params)
1919
end
2020

2121
private

app/models/tag.rb

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,58 @@
11
class Tag
2-
TAGGABLE_MODELS = {
3-
workshops: Workshop,
4-
resources: Resource,
5-
community_news: CommunityNews,
6-
stories: Story,
7-
events: Event,
8-
facilitators: Facilitator,
9-
projects: ::Project,
10-
quotes: Quote
11-
}
2+
TAGGABLE_META = {
3+
workshops: {
4+
icon: "🎨",
5+
path: -> { Rails.application.routes.url_helpers.workshops_path },
6+
klass: Workshop
7+
},
8+
resources: {
9+
icon: "📚",
10+
path: -> { Rails.application.routes.url_helpers.resources_path },
11+
klass: Resource
12+
},
13+
community_news: {
14+
icon: "📰",
15+
path: -> { Rails.application.routes.url_helpers.community_news_index_path },
16+
klass: CommunityNews
17+
},
18+
stories: {
19+
icon: "🗣️",
20+
path: -> { Rails.application.routes.url_helpers.stories_path },
21+
klass: Story
22+
},
23+
events: {
24+
icon: "📆",
25+
path: -> { Rails.application.routes.url_helpers.events_path },
26+
klass: Event
27+
},
28+
facilitators: {
29+
icon: "🧑‍🎨",
30+
path: -> { Rails.application.routes.url_helpers.facilitators_path },
31+
klass: Facilitator
32+
},
33+
projects: {
34+
icon: "🏫",
35+
path: -> { Rails.application.routes.url_helpers.projects_path },
36+
klass: ::Project
37+
},
38+
quotes: {
39+
icon: "💬",
40+
path: -> { Rails.application.routes.url_helpers.quotes_path },
41+
klass: Quote
42+
}
43+
}.freeze
1244

13-
TAGGABLE_COLORS = {
14-
workshops: :indigo,
15-
workshops_variations: :purple,
16-
workshop_logs: :teal,
17-
resources: :violet,
18-
community_news: :orange,
19-
stories: :rose,
20-
events: :blue,
21-
facilitators: :sky,
22-
projects: :emerald,
23-
quotes: :slate,
24-
tags: :lime
25-
}
45+
def self.dashboard_card_for(key)
46+
meta = TAGGABLE_META.fetch(key)
2647

27-
def self.color_for(key)
28-
TAGGABLE_COLORS[key.to_sym]
48+
{
49+
title: key.to_s.humanize,
50+
path: meta[:path].call,
51+
icon: meta[:icon],
52+
bg_color: DomainTheme.bg_class_for(key),
53+
hover_bg_color: DomainTheme.bg_class_for(key, intensity: 100),
54+
text_color: "text-gray-800"
55+
}
2956
end
3057

31-
def self.bg_class_for(key, intensity: 50)
32-
color = color_for(key)
33-
color ? "bg-#{color}-#{intensity}" : "bg-gray-50"
34-
end
35-
36-
def self.text_class_for(key, intensity: 700)
37-
color = color_for(key)
38-
color ? "text-#{color}-#{intensity}" : "text-gray-700"
39-
end
4058
end

app/services/tagging_search_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def self.call(sector_names:, category_names: nil,
8282
end
8383

8484
def self.empty_results(per_page)
85-
Tag::TAGGABLE_MODELS.keys.index_with do
85+
Tag::TAGGABLE_META.keys.index_with do
8686
WillPaginate::Collection.create(1, per_page || 9, 0) { |pager| pager.replace([]) }
8787
end
8888
end

app/views/categories/_tagging_label.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<% category ||= nil %>
22
<% name_only ||= false %>
3+
<% bg_color ||= DomainTheme.bg_class_for(:sectors) %>
4+
<%# bg_hover_color ||= DomainTheme.bg_class_for(:sectors, hover: true) %>
5+
<% bg_hover_color ||= "bg-lime-200" %>
36

47
<% if category %>
58

69
<%= link_to taggings_path(category_names: category.name),
710
class: "inline-flex items-center
811
rounded-md
9-
border border-gray-300
10-
bg-white
12+
border border-gray-300 hover:border-gray-400
13+
#{ bg_color } hover:#{ bg_hover_color }
1114
text-gray-500
1215
px-3 py-1
1316
text-sm font-medium
14-
hover:bg-gray-100 hover:border-gray-400
1517
transition" do %>
1618
<%= "#{category.category_type&.name}: " if !name_only && category.category_type %><%= category.name %>
1719
<% end %>

app/views/community_news/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<% if @community_news.persisted? && current_user&.super_user? %>
6464
<%= link_to "Delete", @community_news, method: :delete,
6565
data: { confirm: "Are you sure?" },
66-
class: "inline-flex items-center px-4 py-2 border border-red-300 text-red-700 bg-white hover:bg-red-50 rounded-lg transition" %>
66+
class: "btn btn-danger-outline" %>
6767
<% end %>
6868

6969
<%= link_to "Cancel", community_news_index_path,

app/views/community_news/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="min-h-screen py-8">
22
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
3-
<div class="bg-orange-50 border border-gray-200 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-200 p-6">
3+
<div class="<%= DomainTheme.bg_class_for(:community_news) %> border border-gray-200 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-200 p-6">
44
<!-- Header Row -->
55
<div class="w-full">
66
<div class="flex items-start justify-between mb-6">

app/views/community_news/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<% community_news_title = ERB::Util.url_encode(@community_news.title) %>
33
<div class="min-h-screen py-8">
44
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
5-
<div class="bg-orange-50 border border-gray-200 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-200 p-6">
5+
<div class="<%= DomainTheme.bg_class_for(:community_news) %> border border-gray-200 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-200 p-6">
66
<!-- Top Right Utility Buttons -->
77
<div class="text-right mb-4 space-x-1">
88
<span class="inline-block text-sm">

0 commit comments

Comments
 (0)