Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/bookmarks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def tally
# Resolve polymorphic objects + sort desc
@bookmark_counts = grouped_counts.group_by(&:first).flat_map do |type, rows|
ids = rows.map { |_, id, _| id }
found = type.constantize.where(id: ids).index_by(&:id)
found = type.constantize.where(id: ids).decorate.index_by(&:id)

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

@windows_types_array = WindowsType::TYPES

@bookmarkable_types = Bookmark::BOOKMARKABLE_MODELS.map{ |type| [ type, type ] }

@workshops = Workshop.where("led_count > 0").order(led_count: :desc)
end

Expand Down
17 changes: 11 additions & 6 deletions app/controllers/workshop_variations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
class WorkshopVariationsController < ApplicationController

def index
if current_user.super_user?
@workshop_variations = WorkshopVariation.joins(:workshop).
where(workshops: { inactive: false }).
order('workshops.title, workshop_variations.name').
paginate(page: params[:page], per_page: 25)
else
unless current_user.super_user?
redirect_to authenticated_root_path
return
end

@workshop_variations =
WorkshopVariation
.joins(:workshop)
.includes(:workshop)
.where(workshops: { inactive: false })
.order("workshops.title, workshop_variations.name")
.paginate(page: params[:page], per_page: 25)
.decorate
end

def new
Expand Down
15 changes: 15 additions & 0 deletions app/decorators/address_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class AddressDecorator < ApplicationDecorator

def title
name
end

def detail
"Address for #{addressable&.name}"
end

def url
Rails.application.routes.url_helpers.polymorphic_path(addressable)
end

end
4 changes: 4 additions & 0 deletions app/decorators/workshop_log_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class WorkshopLogDecorator < ApplicationDecorator

def detail(length: nil)
length ? description&.truncate(length) : description
end

def main_image_url
if main_image&.file&.attached?
Rails.application.routes.url_helpers.url_for(main_image.file)
Expand Down
4 changes: 4 additions & 0 deletions app/decorators/workshop_variation_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ def breadcrumbs
"#{workshop_link} >> #{name}".html_safe
end

def detail(length: nil)
length ? description&.truncate(length) : description
end

def display_code
if legacy
html = Nokogiri::HTML(code)
Expand Down
74 changes: 74 additions & 0 deletions app/helpers/admin_dashboard_cards_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
module AdminDashboardCardsHelper
# -----------------------------
# SYSTEM / ADMIN CARDS
# -----------------------------
def system_cards
[
model_card(:banners, icon: "📣"),
model_card(:community_news, icon: "📰"),
model_card(:events, icon: "📆"),
model_card(:faqs, icon: "❔", title: "FAQs"),
model_card(:stories, icon: "🗣️"),
custom_card("Tagging counts", taggings_matrix_path, icon: "🧮", color: :lime),
model_card(:resources, icon: "📚"),
model_card(:workshops, icon: "🎨"),
model_card(:projects, icon: "🏫"),
model_card(:facilitators, icon: "🧑‍🎨"),
model_card(:users, icon: "👥", title: "User accounts")
]
end

# -----------------------------
# USER CONTENT CARDS
# -----------------------------
def user_content_cards
[
custom_card("Activity logs", dashboard_recent_activities_path, icon: "🧭"),
custom_card("Bookmarks tally", tally_bookmarks_path, icon: "🔖"),
model_card(:event_registrations, icon: "🎟️", intensity: 100, title: "Event Registrations"),
model_card(:quotes, icon: "💬", intensity: 100),
model_card(:story_ideas, icon: "✍️", intensity: 100),
custom_card("Tags", tags_path, icon: "🏷️", color: :lime, intensity: 100),
model_card(:workshop_variations, icon: "🔀", intensity: 100),
model_card(:workshop_ideas, icon: "💡", intensity: 100),
model_card(:workshop_logs, icon: "📝", intensity: 100),
]
end

# -----------------------------
# REFERENCE CARDS
# -----------------------------
def reference_cards
[
custom_card("Categories", authenticated_root_path, icon: "🗂️"),
custom_card("Sectors", authenticated_root_path, icon: "🏭"),
custom_card("Project Statuses", authenticated_root_path, icon: "🧮"),
custom_card("Windows Types", windows_types_path, icon: "🪟"),
]
end

# ============================================================
# CARD BUILDERS
# ============================================================
def model_card(key, title: nil, icon:, intensity: 50)
{
title: title || key.to_s.humanize,
path: polymorphic_path(key.to_s.classify.constantize),
icon: icon,
bg_color: DomainTheme.bg_class_for(key, intensity: intensity),
hover_bg_color: DomainTheme.bg_class_for(key, intensity: intensity == 50 ? 100 : intensity + 100, hover: true),
text_color: "text-gray-800"
}
end

def custom_card(title, path, icon:, color: :gray, intensity: 50)
{
title: title,
path: path,
icon: icon,
bg_color: "bg-#{color}-#{intensity}",
hover_bg_color: "hover:bg-#{color}-#{intensity == 50 ? 100 : intensity + 100}",
text_color: "text-gray-800"
}
end
end
2 changes: 2 additions & 0 deletions app/models/workshop_variation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class WorkshopVariation < ApplicationRecord

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

delegate :windows_type, to: :workshop

def description
code # TODO - rename this field
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/bookmarks/tally.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
bookmarkable_id: bookmarkable.id),
class: "hover:underline" %></td>
<td>
<%= bookmarkable.class.name %>
<%= bookmarkable.object.class.name %>
</td>
<td class="px-4 py-2">
<% if bookmarkable.is_a?(Workshop) || (bookmarkable.is_a?(Resource) && bookmarkable.windows_type_id) %>
Expand Down
8 changes: 6 additions & 2 deletions app/views/dashboard/_recent_activity.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ overflow-hidden flex flex-col md:flex-row">
</div>

<div class="flex-1 p-4">
<% path = (activity.object.is_a?(Resource) ? activity.url ||
resource_path(activity) : polymorphic_path(activity)) %>
<% if activity.object.is_a?(Resource) || activity.object.is_a?(Address) %>
<% path = activity.url || resource_path(activity) %>
<% else %>
<% path = polymorphic_path(activity) %>
<% end %>

<%= link_to path, class: "hover:underline" do %>
<h3 class="text-lg font-semibold text-gray-900">
<%= link_to activity.title,
Expand Down
4 changes: 3 additions & 1 deletion app/views/facilitators/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<!-- Filter form -->
<%= render "search_boxes" %>

<div class="overflow-x-auto">
<div class="rounded-xl bg-white p-6">
<div class="overflow-x-auto">
<table class="w-full border-collapse border border-gray-200">
<thead class="bg-gray-100">
<tr>
Expand Down Expand Up @@ -90,6 +91,7 @@
</tbody>
</table>
</div>
</div>

<!-- Empty state -->
<% unless @facilitators.any? %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
</div>

<!-- Projects table -->
<div class="overflow-x-auto">
<div class="rounded-xl bg-white p-6">
<div class="overflow-x-auto">
<table class="min-w-full border border-gray-200 rounded-lg divide-y divide-gray-200">
<thead class="bg-gray-100">
<tr>
Expand Down Expand Up @@ -145,6 +146,7 @@
</tbody>
</table>
</div>
</div>

<!-- Pagination -->
<div class="mt-6 flex justify-center">
Expand Down
4 changes: 3 additions & 1 deletion app/views/quotes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= simple_form_for(@quote) do |f| %>
<div class="rounded-xl bg-white p-6">
<%= simple_form_for(@quote) do |f| %>
<div class="space-y-6">
<!-- Workshop -->
<div>
Expand Down Expand Up @@ -80,3 +81,4 @@
</div>

<% end %>
</div>
4 changes: 3 additions & 1 deletion app/views/quotes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
</div>
</div>

<div class="overflow-x-auto">
<div class="rounded-xl bg-white p-6">
<div class="overflow-x-auto">
<table class="w-full border-collapse border border-gray-200">
<thead class="bg-gray-100">
<tr>
Expand Down Expand Up @@ -76,6 +77,7 @@
</tbody>
</table>
</div>
</div>

<!-- Empty state -->
<% unless @quotes.any? %>
Expand Down
27 changes: 17 additions & 10 deletions app/views/stories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@
</div>

<div class="flex gap-4 mb-6">
<%= f.input :youtube_url,
as: :text,
hint: "To embed youtube video",
input_html: { rows: 1, value: f.object.youtube_url || @story_idea&.youtube_url } %>
<%= f.input :website_url,
as: :text,
hint: "To link to external website",
input_html: { rows: 1, value: f.object.website_url || @story_idea&.website_url } %>
<div class="flex-1">
<%= f.input :youtube_url,
as: :text,
hint: "Embed a youtube video",
input_html: { rows: 1, value: f.object.youtube_url || @story_idea&.youtube_url } %>
</div>

<div class="flex-1">
<%= f.input :website_url,
as: :text,
hint: "Redirect to this website",
input_html: { rows: 1, value: f.object.website_url || @story_idea&.website_url } %>
</div>
</div>

<div class="flex flex-col md:flex-row md:space-x-4">
Expand Down Expand Up @@ -104,9 +109,11 @@
<%= f.hidden_field :updated_by_id, value: current_user.id %>

<% if f.object.persisted? %>
<div class="flex-1 mb-4 md:mb-0 ms-3 ps-3">
<div class="flex-1 mb-4 md:mb-0 ms-3 ps-3 text-gray-500">
Last updated by: <br>
<%= f.object.updated_by&.full_name %> @ <%= f.object.updated_at.in_time_zone.strftime("%Y-%m-%d %I:%M %P") %>
<%= f.object.updated_by&.full_name %>
<br>
<%= f.object.updated_at.in_time_zone.strftime("%Y-%m-%d %I:%M %P") %>
</div>
<% end %>
</div>
Expand Down
6 changes: 4 additions & 2 deletions app/views/workshop_ideas/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="w-full mx-auto" data-controller="timeframe">
<%= simple_form_for @workshop_idea do |f| %>
<div class="rounded-xl bg-white p-6">
<div class="w-full mx-auto" data-controller="timeframe">
<%= simple_form_for @workshop_idea do |f| %>
<!-- Errors -->
<% if workshop_idea.errors.any? %>
<%= render 'shared/errors', resource: workshop_idea %>
Expand Down Expand Up @@ -299,6 +300,7 @@
<%= f.submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>

<script>
Expand Down
2 changes: 1 addition & 1 deletion app/views/workshop_ideas/_search_boxes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<%= text_field_tag field,
params[field],
placeholder: field == :query ? "Keywords" : field.to_s.humanize,
class: "w-full bg-white border border-gray-300 rounded-lg px-3 py-2 pr-10 focus:ring-blue-500 focus:border-blue-500" %>
class: "w-full border border-gray-300 rounded-lg px-3 py-2 pr-10 focus:ring-blue-500 focus:border-blue-500" %>
<button
type="submit"
class="absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700"
Expand Down
4 changes: 3 additions & 1 deletion app/views/workshop_ideas/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
<!-- Filter form -->
<%= render "search_boxes" %>

<div class="overflow-x-auto">
<div class="rounded-xl bg-white p-6">
<div class="overflow-x-auto">
<table class="w-full border-collapse border border-gray-200">
<thead class="bg-gray-100">
<tr>
Expand Down Expand Up @@ -66,6 +67,7 @@
</tbody>
</table>
</div>
</div>

<!-- Empty state -->
<% unless @workshop_ideas.any? %>
Expand Down
1 change: 0 additions & 1 deletion app/views/workshop_ideas/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<br>Please enter the details of your creation below. Most fields are optional.</p>
</div>

<div class="border-b border-gray-300 mb-6"></div>

<div class="space-y-6">
<div class="mt-4">
Expand Down
4 changes: 3 additions & 1 deletion app/views/workshop_logs/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= simple_form_for(@workshop_log) do |f| %>
<div class="rounded-xl bg-white p-6">
<%= simple_form_for(@workshop_log) do |f| %>
<%= f.input :user_id, as: :hidden, input_html: { value: params[:user_id] || current_user.id } %>
<%= f.input :windows_type_id, as: :hidden, input_html: { value: @windows_type_id } %>

Expand Down Expand Up @@ -114,3 +115,4 @@
<%= f.button :submit, "Save Log", class: "btn btn-primary" %>
</div>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/views/workshop_logs/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<!-- Title -->
<h1 class="text-3xl font-semibold text-gray-900 tracking-tight">
Submit <%= @workshop_log.class.model_name.human %>
New <%= @workshop_log.class.model_name.human %>
</h1>

<!-- Description -->
Expand Down
6 changes: 4 additions & 2 deletions app/views/workshop_variations/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= simple_form_for @workshop_variation, html: { multipart: true } do |f| %>
<div class="rounded-xl bg-white p-6">
<%= simple_form_for @workshop_variation, html: { multipart: true } do |f| %>
<%= hidden_field_tag(:from, params[:from]) %>

<%= render 'shared/errors', resource: workshop_variation if workshop_variation.errors.any? %>
Expand Down Expand Up @@ -43,7 +44,7 @@
<%= render "shared/form_image_fields", f: f, include_main_image: true %>

<% if current_user.super_user? %>
<div class="flex items-start gap-6 bg-blue-50 p-4 rounded-lg">
<div class="flex items-start gap-6 admin-only bg-blue-100 p-4 rounded-lg">
<%= f.input :inactive, as: :boolean, label: "Hidden?", input_html: { checked: f.object.id ? f.object.inactive : false } %>

<%= f.input :ordering, as: :integer, label: "Ordering", input_html: { class: "w-24" } %>
Expand Down Expand Up @@ -84,3 +85,4 @@
class: "btn btn-primary" %>
</div>
<% end %>
</div>
Loading