Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Contact Topics (#5388) #5517

Merged
merged 9 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
jobs:
docker:
runs-on: ubuntu-latest
timeout-minutes: 20
env:
RAILS_ENV: test
steps:
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ruby 3.2.2
yarn 1.22.19
12 changes: 12 additions & 0 deletions app/assets/stylesheets/shared/form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ form {
input {
border: 1px solid globals.$red;
}

}

.read-more {
display: inline;
}

.alert.alert-danger {
Expand All @@ -27,3 +32,10 @@ form {
margin-left: 30px;
display: initial;
}

.details__topics-label {
span {
display: initial;
}

}
22 changes: 22 additions & 0 deletions app/assets/stylesheets/shared/typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,25 @@ body {
option {
font-family: Helvetica, Arial, sans-serif;
}

.content-1 {
font-family: Inter;
font-size: 16px;
font-weight: 500;
}

.content-2 {
font-family: Inter;
font-size: 14px;
font-weight: 500;
}

.content-3 {
font-family: Inter;
font-size: 14px;
font-weight: 400;
}

.pre-line {
white-space: pre-line;
}
16 changes: 16 additions & 0 deletions app/components/dropdown_menu_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="dropdown <%= @class %>">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<% if icon? %>
<%= render_icon %>
<% else %>
<svg width="5" height="20" viewBox="0 0 5 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<title><%= @menu_title %></title>
<path d="M2.5 0.9375C1.82292 0.9375 1.23698 1.17188 0.742187 1.64063C0.247396 2.10938 -7.68364e-08 2.69531 -1.07571e-07 3.39844C-1.38306e-07 4.10156 0.247396 4.70052 0.742187 5.19531C1.23698 5.6901 1.82292 5.9375 2.5 5.9375C3.17708 5.9375 3.76302 5.6901 4.25781 5.19531C4.7526 4.70052 5 4.10156 5 3.39844C5 2.69531 4.7526 2.10938 4.25781 1.64063C3.76302 1.17188 3.17708 0.9375 2.5 0.9375ZM2.5 7.5C1.82292 7.5 1.23698 7.7474 0.742187 8.24219C0.247395 8.73698 -3.66538e-07 9.32292 -3.96134e-07 10C-4.25731e-07 10.6771 0.247395 11.263 0.742187 11.7578C1.23698 12.2526 1.82292 12.5 2.5 12.5C3.17708 12.5 3.76302 12.2526 4.25781 11.7578C4.7526 11.263 5 10.6771 5 10C5 9.32292 4.7526 8.73698 4.25781 8.24219C3.76302 7.7474 3.17708 7.5 2.5 7.5ZM2.5 14.0625C1.82292 14.0625 1.23698 14.3099 0.742187 14.8047C0.247395 15.2995 -6.53963e-07 15.8984 -6.84698e-07 16.6016C-7.15432e-07 17.3047 0.247395 17.8906 0.742187 18.3594C1.23698 18.8281 1.82292 19.0625 2.5 19.0625C3.17708 19.0625 3.76302 18.8281 4.25781 18.3594C4.7526 17.8906 5 17.3047 5 16.6016C5 15.8984 4.7526 15.2995 4.25781 14.8047C3.76302 14.3099 3.17708 14.0625 2.5 14.0625Z" fill="#5D657B" />
</svg>
<% end %>
<%= button_label %>
</button>
<ul class="dropdown-menu">
<%= content %>
</ul>
</div>
31 changes: 31 additions & 0 deletions app/components/dropdown_menu_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

class DropdownMenuComponent < ViewComponent::Base
renders_one :icon

def initialize(menu_title:, icon_name: nil, hide_label: false, render_check: true, klass: nil)
@menu_title = menu_title
@render_check = render_check
@hide_label = hide_label
@icon_name = icon_name
@class = klass
end

def render_icon
return icon if icon.present?

content_tag(:i, nil, class: "lni mr-10 lni-#{@icon_name}")
end

def icon?
icon.present? || @icon_name.present?
end

def render?
@render_check && @menu_title.present? && content.present?
end

def button_label
content_tag(:span, @menu_title, class: @hide_label ? "sr-only" : nil)
end
end
3 changes: 3 additions & 0 deletions app/components/modal/body_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="modal-body <%= @class %>">
<%= body_content %>
</div>
21 changes: 21 additions & 0 deletions app/components/modal/body_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class Modal::BodyComponent < ViewComponent::Base
def initialize(text: nil, klass: nil, render_check: true)
@text = text
@render_check = render_check
@class = klass
end

def body_content
return content if content.present?

Array.wrap(@text).map do |text|
content_tag :p, text
end.join.html_safe
end
Comment on lines +10 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty restrictive to what can go in to the body. Why not just insert what the content is and do something like this when rendering...?

<% component.with_body do %>
  <p>
    This topic and its related questions...
  </p>
  <p>
    This will not affect case contacts that...
  </p>
<% end %>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do that, currently if you provide a block it overrides and text is optional.

It's just if you provide text as a string or array of strings. It gets wrapped in ptags.

it "renders the body with content" do


def render?
@render_check && (@text.present? || content.present?)
end
end
4 changes: 4 additions & 0 deletions app/components/modal/footer_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="modal-footer <%= @class %>">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<%= content %>
</div>
12 changes: 12 additions & 0 deletions app/components/modal/footer_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class Modal::FooterComponent < ViewComponent::Base
def initialize(klass: nil, render_check: true)
@render_check = render_check
@class = klass
end

def render?
@render_check && content.present?
end
end
9 changes: 9 additions & 0 deletions app/components/modal/group_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="modal fade <%= @class %>" id="<%= @id %>" tabindex="-1" aria-labelledby="<%= @id %>-label" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<%= header %>
<%= body %>
<%= footer %>
</div>
</div>
</div>
17 changes: 17 additions & 0 deletions app/components/modal/group_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class Modal::GroupComponent < ViewComponent::Base
renders_one :header, Modal::HeaderComponent
renders_one :body, Modal::BodyComponent
renders_one :footer, Modal::FooterComponent

def initialize(id:, klass: nil, render_check: true)
@id = id
@class = klass
@render_check = render_check
end

def render?
@render_check && (body.present? || header.present?)
end
end
4 changes: 4 additions & 0 deletions app/components/modal/header_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="modal-header <%= @class %>">
<%= header_content %>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
24 changes: 24 additions & 0 deletions app/components/modal/header_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class Modal::HeaderComponent < ViewComponent::Base
def initialize(id:, text: nil, icon: nil, klass: nil, render_check: true)
@text = text
@id = id
@icon = icon
@render_check = render_check
@class = klass
end

def header_content
return content if content.present?

content_tag :h1, class: "modal-title fs-5", id: "#{@id}-label" do
concat(content_tag(:i, nil, class: "lni mr-10 lni-#{@icon}")) if @icon.present?
concat(@text)
end
end

def render?
@render_check && (@text.present? || content.present?)
end
end
6 changes: 6 additions & 0 deletions app/components/modal/open_button_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<button type="button" class="btn <%= @class %>" data-bs-toggle="modal" data-bs-target="<%= "##{@target}" %>">
<% if @icon %>
<i class="lni mr-10 lni-<%= @icon %>"></i>
<% end %>
<%= open_button %>
</button>
21 changes: 21 additions & 0 deletions app/components/modal/open_button_component.rb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you're using this anymore. Is there a reason to keep this?
Screenshot 2024-03-09 at 11 18 51 AM

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to provide two different options to open the model. As a button tag and a link tag, they format slightly differently.

In most situations you would want to use a button because it's semantically correct. But in some situations you're forced to use a link like in my case. So I wanted to have both.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class Modal::OpenButtonComponent < ViewComponent::Base
def initialize(target:, text: nil, klass: nil, icon: nil, render_check: true)
@target = target
@text = text
@icon = icon
@render_check = render_check
@class = klass
end

def open_button
return content if content.present?

@text
end

def render?
@render_check && (@text.present? || content.present?)
end
end
6 changes: 6 additions & 0 deletions app/components/modal/open_link_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<a href="#" role="button" class="btn <%= @class %>" data-bs-toggle="modal" data-bs-target="<%= "##{@target}" %>">
<% if @icon %>
<i class="lni mr-10 lni-<%= @icon %>"></i>
<% end %>
<%= open_link %>
</a>
21 changes: 21 additions & 0 deletions app/components/modal/open_link_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class Modal::OpenLinkComponent < ViewComponent::Base
def initialize(target:, text: nil, icon: nil, klass: nil, render_check: true)
@target = target
@text = text
@icon = icon
@class = klass
@render_check = render_check
end

def open_link
return content if content.present?

@text
end

def render?
@render_check && (@text.present? || content.present?)
end
end
2 changes: 1 addition & 1 deletion app/controllers/all_casa_admins/casa_orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create
@casa_org = CasaOrg.new(casa_org_params)

if @casa_org.save
@casa_org.generate_contact_types_and_hearing_types
@casa_org.generate_defaults
respond_to do |format|
format.html do
redirect_to all_casa_admins_casa_org_path(@casa_org),
Expand Down
1 change: 1 addition & 0 deletions app/controllers/casa_cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def show

respond_to do |format|
format.html {}
# TODO: add contact topic for generation
elasticspoon marked this conversation as resolved.
Show resolved Hide resolved
format.csv do
case_contacts = @casa_case.decorate.case_contacts_ordered_by_occurred_at
csv = CaseContactsExportCsvService.new(case_contacts).perform
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/casa_org_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class CasaOrgController < ApplicationController
before_action :set_learning_hour_types, only: %i[edit update]
before_action :set_learning_hour_topics, only: %i[edit update]
before_action :set_sent_emails, only: %i[edit update]
before_action :set_contact_topics, only: %i[edit update]
before_action :require_organization!
after_action :verify_authorized
before_action :set_active_storage_url_options, only: %i[edit update]
Expand Down Expand Up @@ -84,6 +85,10 @@ def set_learning_hour_topics
@learning_hour_topics = LearningHourTopic.for_organization(@casa_org)
end

def set_contact_topics
@contact_topics = @casa_org.contact_topics.where(soft_delete: false)
end

def set_active_storage_url_options
ActiveStorage::Current.url_options = {host: request.base_url}
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/case_contacts/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def create_additional_case_contacts(case_contact)
other_expenses_describe: ae.other_expenses_describe
)
end
case_contact.contact_topic_answers.each do |cta|
new_case_contact.contact_topic_answers << cta.dup
end

new_case_contact.save!
end
end
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/case_contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ def new
[]
end

@case_contact = CaseContact.create(creator: current_user, draft_case_ids: draft_case_ids)
redirect_to case_contact_form_path(CaseContact::FORM_STEPS.first, case_contact_id: @case_contact.id)
@case_contact = CaseContact.create_with_answers(current_organization,
creator: current_user, draft_case_ids: draft_case_ids)

if @case_contact.errors.any?
flash[:alert] = @case_contact.errors.full_messages.join("\n")
redirect_to request.referer
else
redirect_to case_contact_form_path(CaseContact::FORM_STEPS.first, case_contact_id: @case_contact.id)
end
end

def edit
Expand Down
1 change: 1 addition & 0 deletions app/controllers/case_court_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def assigned_cases
end
end

# TODO: Add contact topics here somewhere?
elasticspoon marked this conversation as resolved.
Show resolved Hide resolved
def generate_report_to_string(casa_case, time_zone)
return unless casa_case

Expand Down
Loading
Loading