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

adds learning hour topics to learning hours #5172

Merged
merged 11 commits into from
Sep 20, 2023
2 changes: 2 additions & 0 deletions .allow_skipping_tests
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ controllers/learning_hour_types_controller.rb
controllers/mileage_reports_controller.rb
controllers/placements_controller.rb
controllers/users/sessions_controller.rb
controllers/learning_hour_topics_controller.rb
datatables/application_datatable.rb
decorators/application_decorator.rb
decorators/case_assignment_decorator.rb
decorators/court_date_decorator.rb
decorators/learning_hour_decorator.rb
decorators/learning_hour_topic_decorator.rb
helpers/all_casa_admins/casa_orgs_helper.rb
helpers/api_base_helper.rb
helpers/date_helper.rb
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/casa_org_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class CasaOrgController < ApplicationController
before_action :set_hearing_types, only: %i[edit update]
before_action :set_judges, only: %i[edit update]
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 :require_organization!
after_action :verify_authorized
Expand Down Expand Up @@ -52,7 +53,8 @@ def casa_org_update_params
:twilio_phone_number,
:twilio_api_key_sid,
:twilio_api_key_secret,
:twilio_enabled
:twilio_enabled,
:learning_topic_active
)
end

Expand All @@ -76,4 +78,8 @@ def set_learning_hour_types
def set_sent_emails
@sent_emails = SentEmail.for_organization(@casa_org).order("created_at DESC").limit(10)
end

def set_learning_hour_topics
@learning_hour_topics = LearningHourTopic.for_organization(@casa_org)
end
end
46 changes: 46 additions & 0 deletions app/controllers/learning_hour_topics_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class LearningHourTopicsController < ApplicationController
before_action :set_learning_hour_topic, only: %i[edit update]
after_action :verify_authorized

def new
authorize LearningHourTopic
@learning_hour_topic = LearningHourTopic.new
end

def edit
authorize @learning_hour_topic
end

def create
authorize LearningHourTopic
@learning_hour_topic = LearningHourTopic.new(learning_hour_topic_params)

if @learning_hour_topic.save
redirect_to edit_casa_org_path(current_organization), notice: "Learning Topic was successfully created."
else
render :new
end
end

def update
authorize @learning_hour_topic

if @learning_hour_topic.update(learning_hour_topic_params)
redirect_to edit_casa_org_path(current_organization), notice: "Learning Topic was successfully updated."
else
render :edit
end
end

private

def set_learning_hour_topic
@learning_hour_topic = LearningHourTopic.find(params[:id])
end

def learning_hour_topic_params
params.require(:learning_hour_topic).permit(:name, :active).merge(
casa_org: current_organization
)
end
end
4 changes: 2 additions & 2 deletions app/controllers/learning_hours_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def set_learning_hour

def learning_hours_params
params.require(:learning_hour).permit(:occurred_at, :duration_minutes, :duration_hours, :name, :user_id,
:learning_hour_type_id)
:learning_hour_type_id, :learning_hour_topic_id)
end

def update_learning_hours_params
params.require(:learning_hour).permit(:occurred_at, :duration_minutes, :duration_hours, :name,
:learning_hour_type_id)
:learning_hour_type_id, :learning_hour_topic_id)
end
end
12 changes: 12 additions & 0 deletions app/decorators/learning_hour_topic_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class LearningHourTopicDecorator < ApplicationDecorator
delegate_all

# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a %m/%d/%y")
# end
# end
end
2 changes: 2 additions & 0 deletions app/models/casa_org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CasaOrg < ApplicationRecord
has_many :placements, through: :casa_cases
has_many :banners, dependent: :destroy
has_many :learning_hour_types, dependent: :destroy
has_many :learning_hour_topics, dependent: :destroy
has_many :case_groups, dependent: :destroy
has_one_attached :logo
has_one_attached :court_report_template
Expand Down Expand Up @@ -127,6 +128,7 @@ def normalize_phone_number
# address :string
# display_name :string
# footer_links :string default([]), is an Array
# learning_topic_active :boolean default(FALSE)
# name :string not null
# show_driving_reimbursement :boolean default(TRUE)
# show_fund_request :boolean default(FALSE)
Expand Down
30 changes: 19 additions & 11 deletions app/models/learning_hour.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
class LearningHour < ApplicationRecord
belongs_to :user
belongs_to :learning_hour_type
belongs_to :learning_hour_topic, optional: true

validates :duration_minutes, presence: true
validates :duration_minutes, numericality: {greater_than: 0}, if: :zero_duration_hours?
validates :name, presence: {message: "/ Title cannot be blank"}
validates :occurred_at, presence: true
validate :occurred_at_not_in_future
validates :learning_hour_topic, presence: true, if: :user_org_learning_topic_enable?

private

Expand All @@ -21,26 +23,32 @@ def occurred_at_not_in_future
errors.add(:date, "cannot be in the future")
end
end

def user_org_learning_topic_enable?
user.casa_org.learning_topic_active
end
end

# == Schema Information
#
# Table name: learning_hours
#
# id :bigint not null, primary key
# duration_hours :integer not null
# duration_minutes :integer not null
# name :string not null
# occurred_at :datetime not null
# created_at :datetime not null
# updated_at :datetime not null
# learning_hour_type_id :bigint
# user_id :bigint not null
# id :bigint not null, primary key
# duration_hours :integer not null
# duration_minutes :integer not null
# name :string not null
# occurred_at :datetime not null
# created_at :datetime not null
# updated_at :datetime not null
# learning_hour_topic_id :bigint
# learning_hour_type_id :bigint
# user_id :bigint not null
#
# Indexes
#
# index_learning_hours_on_learning_hour_type_id (learning_hour_type_id)
# index_learning_hours_on_user_id (user_id)
# index_learning_hours_on_learning_hour_topic_id (learning_hour_topic_id)
# index_learning_hours_on_learning_hour_type_id (learning_hour_type_id)
# index_learning_hours_on_user_id (user_id)
#
# Foreign Keys
#
Expand Down
32 changes: 32 additions & 0 deletions app/models/learning_hour_topic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class LearningHourTopic < ApplicationRecord
belongs_to :casa_org
validates :name, presence: true, uniqueness: {scope: %i[casa_org], case_sensitive: false}
before_validation :strip_name
scope :for_organization, ->(org) { where(casa_org: org).order(:name) }

private

def strip_name
self.name = name.strip if name
end
end

# == Schema Information
#
# Table name: learning_hour_topics
#
# id :bigint not null, primary key
# name :string not null
# position :integer default(1)
# created_at :datetime not null
# updated_at :datetime not null
# casa_org_id :bigint not null
#
# Indexes
#
# index_learning_hour_topics_on_casa_org_id (casa_org_id)
#
# Foreign Keys
#
# fk_rails_... (casa_org_id => casa_orgs.id)
#
50 changes: 50 additions & 0 deletions app/views/casa_org/_learning_hour_topics.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<div class="row">
<div class="col-lg-12">
<div class="card-style mb-30">
<div class="row align-items-center">
<div class="col-md-6">
<h3>Learning Topic</h3>
</div>
<div class="col-md-6">
<div class="breadcrumb-wrapper">
<span class="ml-5">
<%= link_to new_learning_hour_topic_path, class: "btn-sm main-btn primary-btn btn-hover" do %>
<i class="lni lni-plus mr-10"></i>
New Learning Topic
<% end %>
</span>
</div>
</div>
</div>
<div class="table-wrapper table-responsive">
<table class="table striped-table">
<thead>
<tr>
<th>Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% @learning_hour_topics.each do |learning_hour_topic| %>
<tr id="learning_hour_topic-<%= learning_hour_topic.id %>">
<td scope="row" class="min-width">
<%= learning_hour_topic.name %>
</td>

<td>
<%= link_to edit_learning_hour_topic_path(learning_hour_topic) do %>
<div class="action">
<button class="text-danger">
<i class="lni lni-pencil-alt"></i> Edit
</button>
</div>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
7 changes: 7 additions & 0 deletions app/views/casa_org/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<%= form.check_box :show_driving_reimbursement, class: 'form-check-input' %>
<%= form.label :show_driving_reimbursement, "Show driving reimbursement", class: 'form-check-label mb-2' %>
</div>
<div class="form-check checkbox-style mb-20">
<%= form.check_box :learning_topic_active, class: 'form-check-input' %>
<%= form.label :learning_topic_active, "Enable Learning Topic", class: 'form-check-label mb-2' %>
</div>
<div class="form-check checkbox-style mb-20">
<%= form.check_box :twilio_enabled, class: 'form-check-input accordionTwilio' %>
<%= form.label :twilio_enabled, "Enable Twilio", class: 'form-check-label mb-2' %>
Expand Down Expand Up @@ -137,3 +141,6 @@
<div class="tables-wrapper">
<%= render "learning_hour_types" %>
</div>
<div class="tables-wrapper">
<%= render "learning_hour_topics" %>
</div>
31 changes: 31 additions & 0 deletions app/views/learning_hour_topics/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="title-wrapper pt-30">
<div class="row align-items-center">
<div class="col-md-6">
<div class="title mb-30">
<h1>
<%= title %>
</h1>
</div>
</div>
</div>
</div><!-- ==== end title ==== -->

<!-- ========== card start ========== -->
<div class="card-style mb-30">
<%= form_with(model: learning_hour_topic, local: true) do |form| %>
<div class="alert-box danger-alert">
<%= render "/shared/error_messages", resource: learning_hour_topic %>
</div>
<div class="input-style-1">
<%= form.label :name, "Name" %>
<%= form.text_field :name, class: "form-control", required: true %>
</div>

<div class="actions mb-10">
<%= button_tag(type: "submit", class: "btn-sm main-btn primary-btn btn-hover") do %>
<i class="lni lni-checkmark-circle mr-5"></i> Submit
<% end %>
</div>
<% end %>
</div>
<!-- card end -->
1 change: 1 addition & 0 deletions app/views/learning_hour_topics/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "form", locals: {title: "Learning Topic", learning_hour_topic: @learning_hour_topic} %>
1 change: 1 addition & 0 deletions app/views/learning_hour_topics/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "form", locals: {title: "New Learning Topic", learning_hour_topic: @learning_hour_topic} %>
15 changes: 14 additions & 1 deletion app/views/learning_hours/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ id: "learning-hours-form" do |form| %>
value: @learning_hour.learning_hour_type_id %>
</div>
</div>
</div>
<% if current_user.casa_org.learning_topic_active %>
<div class="select-style-1">
<%= form.label :learning_hour_topic_id, "Learning Topic" %>
<div class="select-position">
<%= form.collection_select :learning_hour_topic_id,
LearningHourTopic.for_organization(current_user.casa_org),
:id,
:name,
prompt: "Select learning topic",
value: @learning_hour.learning_hour_topic_id %>
</div>
</div>
<% end %>
</div>
<div class="field-card duration mt-4">
<h5 class="mb-3">Learning Duration</h5>
<div class="input-style-1 duration-hours">
Expand Down
13 changes: 13 additions & 0 deletions app/views/learning_hours/_update_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
value: @learning_hour.learning_hour_type_id %>
</div>
</div>
<% if current_user.casa_org.learning_topic_active %>
<div class="select-style-1">
<%= form.label :learning_hour_topic_id, "Learning Topic" %>
<div class="select-position">
<%= form.collection_select :learning_hour_topic_id,
LearningHourTopic.for_organization(current_user.casa_org),
:id,
:name,
prompt: "Select learning topic",
value: @learning_hour.learning_hour_topic_id %>
</div>
</div>
<% end %>
</div>
<div class="field-card duration mt-4">
<h5 class="mb-3">Learning Duration</h5>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
resources :missing_data_reports, only: %i[index]
resources :learning_hours_reports, only: %i[index]
resources :learning_hour_types, only: %i[new create edit update]
resources :learning_hour_topics, only: %i[new create edit update]
resources :followup_reports, only: :index
resources :placement_reports, only: :index
resources :banners, only: %i[index new edit create update destroy]
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20230817144910_create_learning_hour_topics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateLearningHourTopics < ActiveRecord::Migration[7.0]
def change
create_table :learning_hour_topics do |t|
t.string :name, null: false
t.references :casa_org, null: false, foreign_key: true
t.integer :position, default: 1

t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddLearningHourTopicIdToLearningHour < ActiveRecord::Migration[7.0]
disable_ddl_transaction!

def change
add_reference :learning_hours, :learning_hour_topic, index: {algorithm: :concurrently}
end
end
Loading