Skip to content

Commit bd67682

Browse files
authored
Random fixes (#551)
* Make Quotes admin button active * Change how quote attribution displays 'yrs' (by removing from text) * Quick quote display changes * Change assns in report * Remove model declarations from WorkshopLog that are applicable to all Reports * Update report spec to match new assn definitions
1 parent e0d3747 commit bd67682

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

app/controllers/dashboard_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def admin
3939
bg_color: "bg-gray-50", text_color: "text-gray-800" },
4040
{ title: "Event Registrations", path: event_registrations_path, icon: "🎟️",
4141
bg_color: "bg-blue-100", text_color: "text-blue-800" },
42-
{ title: "!!!Quotes", path: authenticated_root_path, icon: "💬",
42+
{ title: "Quotes", path: quotes_path, icon: "💬",
4343
bg_color: "bg-gray-50", text_color: "text-gray-800" },
4444
{ title: "Story Ideas", path: story_ideas_path, icon: "✍️️",
4545
bg_color: "bg-rose-100", text_color: "text-rose-800" },

app/decorators/quote_decorator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def attribution
1313
name = speaker_name.presence || "anonymous"
1414

1515
details = []
16-
details << "#{age}yrs" if age.present?
16+
details << "#{age.gsub("years","").gsub("yrs","")} yrs" if age.present?
1717
details << gender if gender.present?
1818

1919
if details.any?

app/models/report.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ class Report < ApplicationRecord
66
has_one :form, as: :owner
77
has_many :bookmarks, as: :bookmarkable, dependent: :destroy
88
has_many :notifications, as: :noticeable, dependent: :destroy
9-
has_many :quotable_item_quotes, as: :quotable, dependent: :destroy
10-
has_many :report_form_field_answers, dependent: :destroy
9+
has_many :quotable_item_quotes, as: :quotable, dependent: :nullify, inverse_of: :quotable
10+
has_many :report_form_field_answers,
11+
foreign_key: :report_id, inverse_of: :report,
12+
dependent: :destroy
1113
has_many :sectorable_items, as: :sectorable, dependent: :destroy
1214
# Images
1315
has_one_attached :image # old paperclip -- TODO convert these to MainImage records
@@ -22,14 +24,20 @@ class Report < ApplicationRecord
2224

2325
# has_many through
2426
has_many :form_fields, through: :form
25-
has_many :quotes, through: :quotable_item_quotes, dependent: :destroy
27+
has_many :all_quotable_item_quotes,
28+
->(wl) { where(quotable_id: wl.id,
29+
quotable_type: %w[WorkshopLog Report]) }, # needed bc some are stored w type Report
30+
class_name: "QuotableItemQuote",
31+
inverse_of: :quotable
32+
has_many :quotes, through: :all_quotable_item_quotes, dependent: :nullify
2633
has_many :sectors, through: :sectorable_items, dependent: :destroy
2734

2835
# Nested attributes
2936
accepts_nested_attributes_for :media_files, allow_destroy: true, reject_if: :all_blank
3037
accepts_nested_attributes_for :main_image, allow_destroy: true, reject_if: :all_blank
3138
accepts_nested_attributes_for :gallery_images, allow_destroy: true, reject_if: :all_blank
32-
accepts_nested_attributes_for :quotable_item_quotes
39+
accepts_nested_attributes_for :all_quotable_item_quotes, allow_destroy: true, reject_if: :all_blank
40+
accepts_nested_attributes_for :quotable_item_quotes, allow_destroy: true, reject_if: :all_blank
3341
accepts_nested_attributes_for :report_form_field_answers,
3442
reject_if: proc { |object|
3543
object["_create"].to_i == 0 && object["answer"].nil? }

app/models/workshop_log.rb

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
11
class WorkshopLog < Report
22
belongs_to :workshop
3-
belongs_to :user
4-
belongs_to :project
5-
has_many :quotable_item_quotes, as: :quotable, dependent: :nullify, inverse_of: :quotable
6-
has_many :all_quotable_item_quotes,
7-
->(wl) { where(quotable_id: wl.id,
8-
quotable_type: %w[WorkshopLog Report]) }, # needed bc some are stored w type Report
9-
class_name: "QuotableItemQuote",
10-
inverse_of: :quotable
11-
has_many :quotes, through: :all_quotable_item_quotes
12-
has_many :report_form_field_answers,
13-
foreign_key: :report_id, inverse_of: :report,
14-
dependent: :destroy
15-
# Image associations
16-
has_many :media_files, dependent: :destroy # TODO - convert these to GalleryImages
17-
has_many :gallery_images, -> { where(type: "Images::GalleryImage") },
18-
as: :owner, class_name: "Images::GalleryImage", dependent: :destroy
19-
20-
# Nested attributes
21-
accepts_nested_attributes_for :gallery_images, allow_destroy: true, reject_if: :all_blank
22-
accepts_nested_attributes_for :quotable_item_quotes, allow_destroy: true,
23-
reject_if: ->(attributes) { false } # allow empty
24-
accepts_nested_attributes_for :all_quotable_item_quotes, allow_destroy: true, reject_if: :all_blank
25-
accepts_nested_attributes_for :report_form_field_answers, allow_destroy: true,
26-
reject_if: ->(attributes) { false } # allow empty
273

284
# Validations
5+
validates :date, presence: true
296
validates :children_ongoing, :teens_ongoing, :adults_ongoing,
307
:children_first_time, :teens_first_time, :adults_first_time,
318
numericality: { greater_than_or_equal_to: 0, only_integer: true }
32-
validates :date, presence: true
339

3410
# Callbacks
3511
after_save :update_owner_and_date

app/views/quotes/_form.html.erb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,24 @@
2828
<div>
2929
<%= f.input :speaker_name,
3030
label: "Speaker name",
31-
input_html: { class: "w-full" },
31+
input_html: { value: f.object.speaker_name, class: "w-full" },
3232
wrapper_html: { class: "w-full" }
3333
%>
3434
</div>
3535

3636
<div>
37-
<%= f.input :age,
38-
as: :integer,
39-
label: "Age",
40-
input_html: { min: 0, class: "w-full" }
41-
%>
37+
<!-- Check if quote was created with a string for an age-->
38+
<% if f.object.age.present? && f.object.age.to_s.match?(/\D/) %>
39+
<%= f.input :age,
40+
as: :string,
41+
label: "Age",
42+
input_html: { class: "w-full" } %>
43+
<% else %>
44+
<%= f.input :age,
45+
as: :integer,
46+
label: "Age",
47+
input_html: { min: 0, class: "w-full" } %>
48+
<% end %>
4249
</div>
4350

4451
<div>

app/views/quotes/index.html.erb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@
5656
<%= quote.attribution %>
5757
<%= "@ " + quote.created_at.strftime("%m-%d-%-Y") %>
5858
<%= ("re " + link_to(quote.workshop.title, workshop_path(quote.workshop),
59-
class: "hover:underline") if quote.workshop).to_s.html_safe %>
59+
class: "hover:underline") if quote.workshop).to_s.html_safe %>
60+
<% quote.quotable_item_quotes.each do |qiq| %>
61+
<% if qiq.quotable %>
62+
from: <%= link_to qiq.quotable.title,
63+
polymorphic_path(qiq.quotable),
64+
class: "hover:underline" %>
65+
<% end %>
66+
<% end %>
6067
</div>
6168
</td>
6269
<td class="px-4 py-2 text-center whitespace-nowrap">

app/views/quotes/show.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<div class="min-h-screen py-8">
55
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
6-
<div class="bg-gray-50 border border-gray-200 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-200 p-6">
6+
<div class="p-6">
77
<!-- Top Right Utility Buttons -->
88
<div class="text-right mb-4 space-x-1">
99
<span class="inline-block text-sm">
@@ -49,8 +49,10 @@
4949
<div class="flex items-center gap-2">
5050
<h3 class="text-sm font-medium text-gray-500">Status:</h3>
5151
<% if @quote.inactive? %>
52-
<span class="px-2 py-1 text-xs bg-red-100 text-red-700 rounded-full">
53-
Inactive
52+
<span class="inline-flex items-center px-2 py-0.5 rounded-full
53+
text-xs font-medium bg-blue-100 text-gray-600 whitespace-nowrap">
54+
<i class="fa-solid fa-eye-slash mr-1"></i>
55+
Hidden
5456
</span>
5557
<% else %>
5658
<span class="px-2 py-1 text-xs bg-green-100 text-green-700 rounded-full">

spec/models/report_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
it { should have_many(:gallery_images) }
1212
it { should have_many(:form_fields).through(:form) }
1313
it { should have_many(:report_form_field_answers).dependent(:destroy) }
14-
it { should have_many(:quotable_item_quotes).dependent(:destroy) }
15-
it { should have_many(:quotes).through(:quotable_item_quotes).dependent(:destroy) }
14+
it { should have_many(:quotable_item_quotes).dependent(:nullify) }
15+
it { should have_many(:quotes).through(:all_quotable_item_quotes).dependent(:nullify) }
1616
it { should have_many(:notifications).dependent(:destroy) }
1717
it { should have_many(:sectorable_items).dependent(:destroy) }
1818
it { should have_many(:sectors).through(:sectorable_items).dependent(:destroy) }

0 commit comments

Comments
 (0)