diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 382ad4d1d..c1f873541 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -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" }, diff --git a/app/decorators/quote_decorator.rb b/app/decorators/quote_decorator.rb index e2c9c3e81..25ccc8837 100644 --- a/app/decorators/quote_decorator.rb +++ b/app/decorators/quote_decorator.rb @@ -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? diff --git a/app/models/report.rb b/app/models/report.rb index 773a3e151..130930616 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -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 @@ -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? } diff --git a/app/models/workshop_log.rb b/app/models/workshop_log.rb index def955bfa..495810ce5 100644 --- a/app/models/workshop_log.rb +++ b/app/models/workshop_log.rb @@ -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 diff --git a/app/views/quotes/_form.html.erb b/app/views/quotes/_form.html.erb index f24ec0ab2..26c60e534 100644 --- a/app/views/quotes/_form.html.erb +++ b/app/views/quotes/_form.html.erb @@ -28,17 +28,24 @@
<%= 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" } %>
- <%= f.input :age, - as: :integer, - label: "Age", - input_html: { min: 0, class: "w-full" } - %> + + <% 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 %>
diff --git a/app/views/quotes/index.html.erb b/app/views/quotes/index.html.erb index 9f2749f9b..28b9100b8 100644 --- a/app/views/quotes/index.html.erb +++ b/app/views/quotes/index.html.erb @@ -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 %>
diff --git a/app/views/quotes/show.html.erb b/app/views/quotes/show.html.erb index 51a763d73..54536c9d6 100644 --- a/app/views/quotes/show.html.erb +++ b/app/views/quotes/show.html.erb @@ -3,7 +3,7 @@
-
+
@@ -49,8 +49,10 @@

Status:

<% if @quote.inactive? %> - - Inactive + + + Hidden <% else %> diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 1b2348707..d2ebe51ba 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -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) }