Skip to content

Commit

Permalink
adds Community to CustomForm entity and uses CustomForm with Community
Browse files Browse the repository at this point in the history
  • Loading branch information
PirunSeng committed Dec 26, 2020
1 parent 31095b2 commit 1f51ca0
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
@import 'user/custom_fields/*';
@import 'clients/*';
@import 'client_books/index';
@import 'communities/*';
@import 'families/*';
@import 'users/*';
@import 'partners/*';
Expand Down
74 changes: 74 additions & 0 deletions app/assets/stylesheets/communities/show.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
body[id='communities-show'] {

.community {
.community-detail {
padding-top: 5px;
padding-bottom: 5px;
}
}

.agreegate table {
font-weight: 600;

.spacing-first-col {
width: 70%;
}
}

.small-btn-margin {
margin-top: 8px;
}

// .h3-header {
// margin: 0;
// width: 87%;
// }

// small.top-right-icon {
// position: absolute;
// top: 16px;
// right: 30px;

// i {
// font-size: 24px;
// padding-top: 5px;
// }
// }

td.spacing-first-col {
width: 217px;
}

// .pushing-top {
// margin-top: 15px;
// }

// .pushing-bottom {
// margin-bottom: 15px;
// }

.label.label-default {
line-height: 2.2;
margin-right: 3px;
}

.scrollable-dropdown-menu {
height: auto;
max-height: 200px;
overflow-x: hidden;
padding: 15px;
width: 300px;
}

@media screen and (min-width: 768px) {
.scrollable-dropdown-menu {
width: 350px;
}
}

@media screen and (min-width: 991px){
.scrollable-dropdown-menu {
width: 400px;
}
}
}
3 changes: 3 additions & 0 deletions app/classes/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def initialize(user)
can :manage, Client, case_worker_clients: { user_id: user.id }
can :manage, CustomFieldProperty, custom_formable_type: 'Client'
can :manage, CustomFieldProperty, custom_formable_type: 'Family'
can :manage, CustomFieldProperty, custom_formable_type: 'Community'
can :manage, ClientEnrollment
can :manage, ClientEnrollmentTracking
can :manage, LeaveProgram
Expand Down Expand Up @@ -68,6 +69,7 @@ def initialize(user)
can :manage, CustomFieldProperty, custom_formable_type: 'Client'
can :manage, CustomFieldProperty, custom_formable_type: 'Family'
can :manage, CustomFieldProperty, custom_formable_type: 'Partner'
can :manage, CustomFieldProperty, custom_formable_type: 'Community'
can :manage, CustomField
can :manage, ClientEnrollment
can :manage, ClientEnrollmentTracking
Expand All @@ -92,6 +94,7 @@ def initialize(user)
can :manage, Client
can :manage, CustomFieldProperty, custom_formable_type: 'Client'
can :manage, CustomFieldProperty, custom_formable_type: 'Family'
can :manage, CustomFieldProperty, custom_formable_type: 'Community'
can :manage, ClientEnrollment
can :manage, ClientEnrollmentTracking
can :manage, LeaveProgram
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/communities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def create
end
end

def show;end
def show
custom_field_ids = @community.custom_field_properties.pluck(:custom_field_id)
@free_community_forms = CustomField.community_forms.not_used_forms(custom_field_ids).order_by_form_title
@group_community_custom_fields = @community.custom_field_properties.group_by(&:custom_field_id)
end

def edit
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/custom_field_properties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def find_entity
@custom_formable = Partner.includes(custom_field_properties: [:custom_field]).find(params[:partner_id])
elsif params[:user_id].present?
@custom_formable = User.includes(custom_field_properties: [:custom_field]).find(params[:user_id])
elsif params[:community_id].present?
@custom_formable = Community.includes(custom_field_properties: [:custom_field]).find(params[:community_id])
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/community.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Community < ActiveRecord::Base
has_many :quantitative_cases, through: :community_quantitative_cases
has_many :viewable_quantitative_cases, -> { joins(:quantitative_type).where('quantitative_types.visible_on LIKE ?', "%community%") }, through: :community_quantitative_cases, source: :quantitative_case

has_many :custom_field_properties, as: :custom_formable, dependent: :destroy
has_many :custom_fields, through: :custom_field_properties, as: :custom_formable
has_many :community_members, dependent: :destroy

accepts_nested_attributes_for :community_members, reject_if: :all_blank, allow_destroy: true
Expand Down
4 changes: 3 additions & 1 deletion app/models/custom_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ class CustomField < ActiveRecord::Base
include UpdateFieldLabelsFormBuilder

FREQUENCIES = ['Daily', 'Weekly', 'Monthly', 'Yearly'].freeze
ENTITY_TYPES = ['Client', 'Family', 'Partner', 'User'].freeze
ENTITY_TYPES = ['Client', 'Community', 'Family', 'Partner', 'User'].freeze

has_many :custom_field_properties, dependent: :restrict_with_error
has_many :clients, through: :custom_field_properties, source: :custom_formable, source_type: 'Client'
has_many :users, through: :custom_field_properties, source: :custom_formable, source_type: 'User'
has_many :partners, through: :custom_field_properties, source: :custom_formable, source_type: 'Partner'
has_many :families, through: :custom_field_properties, source: :custom_formable, source_type: 'Family'
has_many :communities, through: :custom_field_properties, source: :custom_formable, source_type: 'Community'
has_many :custom_field_permissions, dependent: :destroy
has_many :user_permissions, through: :custom_field_permissions

Expand All @@ -30,6 +31,7 @@ class CustomField < ActiveRecord::Base
scope :by_form_title, ->(value) { where('form_title iLIKE ?', "%#{value.squish}%") }
scope :client_forms, -> { where(entity_type: 'Client') }
scope :family_forms, -> { where(entity_type: 'Family') }
scope :community_forms, -> { where(entity_type: 'Community') }
scope :partner_forms, -> { where(entity_type: 'Partner') }
scope :user_forms, -> { where(entity_type: 'User') }
scope :not_used_forms, ->(value) { where.not(id: value) }
Expand Down
18 changes: 18 additions & 0 deletions app/views/communities/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@
.panel.panel-default.case-management-tool-set
.panel-body.text-center{ style: 'min-height: 50px; background-color: yellow;' }
%h3 Case Management Tool Set
.btn-group.small-btn-margin
%button.btn-sm.btn.btn-success.dropdown-toggle{ 'data-toggle' => 'dropdown', class: ('disabled' if @group_community_custom_fields.empty?) }
= t('.additional_forms')
%span.caret
%ul.dropdown-menu.scrollable-dropdown-menu
- @group_community_custom_fields.each do |_, community_custom_fields|
%li
%p= link_to community_custom_fields.first.custom_field.form_title, community_custom_field_properties_path(@community, custom_field_id: community_custom_fields.first.custom_field_id)

- if can? :manage, CustomFieldProperty
.btn-group.small-btn-margin
%button.btn-sm.btn.btn-success.dropdown-toggle{ 'data-toggle' => 'dropdown', class: ('disabled' if @free_community_forms.empty?) }
= t('.add_form')
%span.caret
%ul.dropdown-menu.scrollable-dropdown-menu
- @free_community_forms.each do |custom_field|
%li
%p= link_to custom_field.form_title, new_community_custom_field_property_path(@community, custom_field_id: custom_field)

.ibox.mini-margin
.ibox-title
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3843,7 +3843,7 @@ en:
new_family_title: New Family
show:
add_form: Add Form
additional_forms: Family's Active Forms
additional_forms: Community's Active Forms
additional_info: Additional Information
address: Address
adult_name: Name of Adult Member
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@
get 'version' => 'families#version'
end

resources :communities
resources :communities do
resources :custom_field_properties
end

resources :partners do
resources :custom_field_properties
Expand Down

0 comments on commit 1f51ca0

Please sign in to comment.