From 1f51ca042baffb9077804046598ca75c0cbbdd79 Mon Sep 17 00:00:00 2001 From: Pirun Seng Date: Thu, 24 Dec 2020 10:40:43 +0700 Subject: [PATCH] adds Community to CustomForm entity and uses CustomForm with Community --- app/assets/stylesheets/application.scss | 1 + app/assets/stylesheets/communities/show.scss | 74 +++++++++++++++++++ app/classes/ability.rb | 3 + app/controllers/communities_controller.rb | 6 +- .../custom_field_properties_controller.rb | 2 + app/models/community.rb | 2 + app/models/custom_field.rb | 4 +- app/views/communities/show.html.haml | 18 +++++ config/locales/en.yml | 2 +- config/routes.rb | 4 +- 10 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 app/assets/stylesheets/communities/show.scss diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 49e2865a95..197be2cece 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -44,6 +44,7 @@ @import 'user/custom_fields/*'; @import 'clients/*'; @import 'client_books/index'; +@import 'communities/*'; @import 'families/*'; @import 'users/*'; @import 'partners/*'; diff --git a/app/assets/stylesheets/communities/show.scss b/app/assets/stylesheets/communities/show.scss new file mode 100644 index 0000000000..433e7d988b --- /dev/null +++ b/app/assets/stylesheets/communities/show.scss @@ -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; + } + } +} diff --git a/app/classes/ability.rb b/app/classes/ability.rb index 00cf899a9c..193067423d 100644 --- a/app/classes/ability.rb +++ b/app/classes/ability.rb @@ -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 @@ -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 @@ -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 diff --git a/app/controllers/communities_controller.rb b/app/controllers/communities_controller.rb index 64a0238fb0..879b0735dd 100644 --- a/app/controllers/communities_controller.rb +++ b/app/controllers/communities_controller.rb @@ -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 diff --git a/app/controllers/custom_field_properties_controller.rb b/app/controllers/custom_field_properties_controller.rb index 4b6bcff470..060eec6181 100644 --- a/app/controllers/custom_field_properties_controller.rb +++ b/app/controllers/custom_field_properties_controller.rb @@ -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 diff --git a/app/models/community.rb b/app/models/community.rb index c074cfc0ee..47bf35772b 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -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 diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 7fa288ac29..77127c9833 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -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 @@ -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) } diff --git a/app/views/communities/show.html.haml b/app/views/communities/show.html.haml index 9a89d9403e..be17bad4c3 100644 --- a/app/views/communities/show.html.haml +++ b/app/views/communities/show.html.haml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index c350408b38..d8ab6dd604 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 6b09ee1769..35ed166244 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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