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
2 changes: 1 addition & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def admin
bg_color: "bg-gray-50", text_color: "text-gray-800" },
{ title: "Event Registrations", path: event_registrations_path, icon: "🎟️",
bg_color: "bg-blue-100", text_color: "text-blue-800" },
{ title: "!!!Quotes", path: authenticated_root_path, icon: "💬",
{ title: "Quotes", path: quotes_path, icon: "💬",
bg_color: "bg-gray-50", text_color: "text-gray-800" },
{ title: "Story Ideas", path: story_ideas_path, icon: "✍️️",
bg_color: "bg-rose-100", text_color: "text-rose-800" },
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/quote_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def attribution
name = speaker_name.presence || "anonymous"

details = []
details << "#{age}yrs" if age.present?
details << "#{age.gsub("years","").gsub("yrs","")} yrs" if age.present?
details << gender if gender.present?

if details.any?
Expand Down
16 changes: 12 additions & 4 deletions app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class Report < ApplicationRecord
has_one :form, as: :owner
has_many :bookmarks, as: :bookmarkable, dependent: :destroy
has_many :notifications, as: :noticeable, dependent: :destroy
has_many :quotable_item_quotes, as: :quotable, dependent: :destroy
has_many :report_form_field_answers, dependent: :destroy
has_many :quotable_item_quotes, as: :quotable, dependent: :nullify, inverse_of: :quotable
has_many :report_form_field_answers,
foreign_key: :report_id, inverse_of: :report,
dependent: :destroy
has_many :sectorable_items, as: :sectorable, dependent: :destroy
# Images
has_one_attached :image # old paperclip -- TODO convert these to MainImage records
Expand All @@ -22,14 +24,20 @@ class Report < ApplicationRecord

# has_many through
has_many :form_fields, through: :form
has_many :quotes, through: :quotable_item_quotes, dependent: :destroy
has_many :all_quotable_item_quotes,
->(wl) { where(quotable_id: wl.id,
quotable_type: %w[WorkshopLog Report]) }, # needed bc some are stored w type Report
class_name: "QuotableItemQuote",
inverse_of: :quotable
has_many :quotes, through: :all_quotable_item_quotes, dependent: :nullify
has_many :sectors, through: :sectorable_items, dependent: :destroy

# Nested attributes
accepts_nested_attributes_for :media_files, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :main_image, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :gallery_images, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :quotable_item_quotes
accepts_nested_attributes_for :all_quotable_item_quotes, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :quotable_item_quotes, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :report_form_field_answers,
reject_if: proc { |object|
object["_create"].to_i == 0 && object["answer"].nil? }
Expand Down
26 changes: 1 addition & 25 deletions app/models/workshop_log.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
class WorkshopLog < Report
belongs_to :workshop
belongs_to :user
belongs_to :project
has_many :quotable_item_quotes, as: :quotable, dependent: :nullify, inverse_of: :quotable
has_many :all_quotable_item_quotes,
->(wl) { where(quotable_id: wl.id,
quotable_type: %w[WorkshopLog Report]) }, # needed bc some are stored w type Report
class_name: "QuotableItemQuote",
inverse_of: :quotable
has_many :quotes, through: :all_quotable_item_quotes
has_many :report_form_field_answers,
foreign_key: :report_id, inverse_of: :report,
dependent: :destroy
# Image associations
has_many :media_files, dependent: :destroy # TODO - convert these to GalleryImages
has_many :gallery_images, -> { where(type: "Images::GalleryImage") },
as: :owner, class_name: "Images::GalleryImage", dependent: :destroy

# Nested attributes
accepts_nested_attributes_for :gallery_images, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :quotable_item_quotes, allow_destroy: true,
reject_if: ->(attributes) { false } # allow empty
accepts_nested_attributes_for :all_quotable_item_quotes, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :report_form_field_answers, allow_destroy: true,
reject_if: ->(attributes) { false } # allow empty

# Validations
validates :date, presence: true
validates :children_ongoing, :teens_ongoing, :adults_ongoing,
:children_first_time, :teens_first_time, :adults_first_time,
numericality: { greater_than_or_equal_to: 0, only_integer: true }
validates :date, presence: true

# Callbacks
after_save :update_owner_and_date
Expand Down
19 changes: 13 additions & 6 deletions app/views/quotes/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,24 @@
<div>
<%= f.input :speaker_name,
label: "Speaker name",
input_html: { class: "w-full" },
input_html: { value: f.object.speaker_name, class: "w-full" },
wrapper_html: { class: "w-full" }
%>
</div>

<div>
<%= f.input :age,
as: :integer,
label: "Age",
input_html: { min: 0, class: "w-full" }
%>
<!-- Check if quote was created with a string for an age-->
<% if f.object.age.present? && f.object.age.to_s.match?(/\D/) %>
<%= f.input :age,
as: :string,
label: "Age",
input_html: { class: "w-full" } %>
<% else %>
<%= f.input :age,
as: :integer,
label: "Age",
input_html: { min: 0, class: "w-full" } %>
<% end %>
</div>

<div>
Expand Down
9 changes: 8 additions & 1 deletion app/views/quotes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@
<%= quote.attribution %>
<%= "@ " + quote.created_at.strftime("%m-%d-%-Y") %>
<%= ("re " + link_to(quote.workshop.title, workshop_path(quote.workshop),
class: "hover:underline") if quote.workshop).to_s.html_safe %>
class: "hover:underline") if quote.workshop).to_s.html_safe %>
<% quote.quotable_item_quotes.each do |qiq| %>
<% if qiq.quotable %>
from: <%= link_to qiq.quotable.title,
polymorphic_path(qiq.quotable),
class: "hover:underline" %>
<% end %>
<% end %>
</div>
</td>
<td class="px-4 py-2 text-center whitespace-nowrap">
Expand Down
8 changes: 5 additions & 3 deletions app/views/quotes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<div class="min-h-screen py-8">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="bg-gray-50 border border-gray-200 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-200 p-6">
<div class="p-6">
<!-- Top Right Utility Buttons -->
<div class="text-right mb-4 space-x-1">
<span class="inline-block text-sm">
Expand Down Expand Up @@ -49,8 +49,10 @@
<div class="flex items-center gap-2">
<h3 class="text-sm font-medium text-gray-500">Status:</h3>
<% if @quote.inactive? %>
<span class="px-2 py-1 text-xs bg-red-100 text-red-700 rounded-full">
Inactive
<span class="inline-flex items-center px-2 py-0.5 rounded-full
text-xs font-medium bg-blue-100 text-gray-600 whitespace-nowrap">
<i class="fa-solid fa-eye-slash mr-1"></i>
Hidden
</span>
<% else %>
<span class="px-2 py-1 text-xs bg-green-100 text-green-700 rounded-full">
Expand Down
4 changes: 2 additions & 2 deletions spec/models/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
it { should have_many(:gallery_images) }
it { should have_many(:form_fields).through(:form) }
it { should have_many(:report_form_field_answers).dependent(:destroy) }
it { should have_many(:quotable_item_quotes).dependent(:destroy) }
it { should have_many(:quotes).through(:quotable_item_quotes).dependent(:destroy) }
it { should have_many(:quotable_item_quotes).dependent(:nullify) }
it { should have_many(:quotes).through(:all_quotable_item_quotes).dependent(:nullify) }
it { should have_many(:notifications).dependent(:destroy) }
it { should have_many(:sectorable_items).dependent(:destroy) }
it { should have_many(:sectors).through(:sectorable_items).dependent(:destroy) }
Expand Down