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 Community to CustomForm entity and uses CustomForm with Community #1764

Draft
wants to merge 5 commits into
base: vibol/community
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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 app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
//= require client_books/index
//= require calls/form
//= require communities/form
//= require communities/show
//= require quantitative_types/index
//= require calls/index
//= require referees/index
Expand Down
8 changes: 8 additions & 0 deletions app/assets/javascripts/communities/show.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CIF.CommunitiesShow = do ->
_init = ->
_buttonHelpTextPophover()

_buttonHelpTextPophover = ->
$("button[data-content]").popover();

{ init: _init }
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
78 changes: 78 additions & 0 deletions app/assets/stylesheets/communities/show.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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;
}

.btn-fit {
min-width: 170px;
}

// .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
21 changes: 18 additions & 3 deletions app/views/communities/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@

.col-md-3
.col-sm-12
.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.btn-fit{ class: ('disabled' if @group_community_custom_fields.empty?), data: { toggle: "dropdown", trigger: 'hover', html: 'true', content: "#{I18n.t('inline_help.communities.show.active_form')}", placement: "bottom" } }
= 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.btn-fit{ class: ('disabled' if @free_community_forms.empty?), data: { toggle: "dropdown", trigger: 'hover', html: 'true', content: "#{I18n.t('inline_help.communities.show.add_form')}", placement: "bottom" } }
= 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: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,8 @@ en:
new:
new_community_title: New Community
show:
add_form: Add Form
additional_forms: Community's Active Forms
address: Address
all_beneficiaries: To Count All Beneficiaries (direct members and their household members)
are_you_sure: Are you sure you want to delete?
Expand Down
4 changes: 4 additions & 0 deletions config/locales/inline_help_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ en:
reject: Reject indicates your organization cannot work with the client for some reason. The case will remain in the database and show <strong>Exited</strong> status with exit circumstance as <strong>Reject Referral</strong>.
status: "<strong>Accepted </strong>– Organization has accepted the case and working with the client. <strong>Active</strong> – Client is enrolled in one or more program streams. <strong>Exited</strong> – Organization has rejected the case or no longer supporting the client. <strong>Referred</strong> – Client record exists in the OSCaR system but not yet accepted or rejected."
tasks: View all the overdue, current and upcoming tasks here. This is a read-only option for Managers and Caseworkers. New tasks can’t be added here.
communities:
show:
active_form: Add/View/Edit the custom forms already applied to the community.
add_form: These custom forms are specific to your NGO. Select one from the list to load the form. Once you fill and save it, the form will be attached to the community.
custom:
custom_id1: Alternate case identification (ID) number related to the client. In the case of jointly managed clients or clients referred through other organization(s), enter the ID that was used on the previous paperwork, record, or database. This will help in tracking client record. Admin, This field name is customizable. To change the name, go to <strong>Manage >> Setting >> Custom Labels</strong>. <i class="fa fa-exclamation-triangle text-danger" aria-hidden="true"></i> This is different from Client ID auto-generated in OSCaR for every case.
custom_id2: Alternate case identification (ID) number related to the client. In the case of jointly managed clients or clients referred through other organization(s), enter the ID that was used on the previous paperwork, record, or database. This will help in tracking client record. Admin, This field name is customizable. To change the name, go to <strong>Manage >> Setting >> Custom Labels</strong>.
Expand Down
4 changes: 4 additions & 0 deletions config/locales/inline_help_km.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ km:
Exited - អង្គការមិនទទួលយកករណី ឬលែងជួយដល់អតិថិជន។
Referred - កំណត់ត្រាអតិថិជនមាននៅក្នុងប្រព័ន្ធ OSCaR ប៉ុន្តែមិនទាន់មានការទទួលយក ឬមិនទទួលយកនៅឡើយទេ។
tasks: សូមមើលកាតព្វកិច្ចដែលផុតកំណត់ កាតព្វកិច្ចសព្វថ្ងៃ ព្រមទាំងកាតព្វកិច្ចបន្ទាប់ នៅទីនេះ។ កាត្វកិច្ចទាំងនេះ គ្រាន់តែអាចអានបានតែប៉ុណ្ណោះ សម្រាប់អ្នកគ្រប់គ្រង និងបុគ្គលិកគ្រប់គ្រងករណី។ កាតព្វកិច្ចថ្មីមិនអាចបន្ថែមនៅត្រង់នេះបានទេ។
communities:
show:
active_form: បន្ថែម/មើល/កែតម្រូវ ទម្រង់បែបបទផ្សេងៗ ដែលត្រូវបានបង្កើតរួចរាល់ សម្រាប់សហគមន៍។
add_form: ទម្រង់បែបបទទាំងនេះគឺប្រើប្រាស់ សម្រាប់តែអង្គការរបស់អ្នក។ ជ្រើសយកមួយពីក្នុងបញ្ជី ដើម្បីទាញយកទម្រង់បែបបទនេះ។ បន្ទាប់ពីអ្នកបំពេញរួចរាល់ ហើយរក្សាវាទុក ទម្រង់បែបបទនឹងត្រូវបានភ្ជាប់ ទៅនឹងប្រវត្តិរូបរបស់សហគមន៍។
custom:
custom_id1: |-
លេខសម្គាល់ករណីជំនួស (ID)ទាក់ទងនឹងអតិថិជន។ ក្នុងករណីដែលអតិថិជនគ្រប់គ្រងរួមគ្នា ឬអតិថិជនដែលត្រូវបានបញ្ជូនមកតាមរយៈអង្គភាពផ្សេង សូមបញ្ចូលលេខសម្គាល់ ដែលធ្លាប់បានប្រើនៅលើក្រដាសឯកសារ កំណត់ត្រា ឬទិន្នន័យមូលដ្ឋានពីមុន។ ការនេះនឹងជួយនៅក្នុងការតាមដានកំណត់ត្រាអតិថិជន។</br>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/inline_help_my.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ my:
reject: Reject indicates your organization cannot work with the client for some reason. The case will remain in the database and show Exited status with exit circumstance as Reject Referral.
status: Accepted – Organization has accepted the case and working with the client. Active – Client is enrolled in one or more program streams. Exited – Organization has rejected the case or no longer supporting the client. Referred – Client record exists in the OSCaR system but not yet accepted or rejected.
tasks: View all the overdue, current and upcoming tasks here. This is a read-only option for Managers and Caseworkers. New tasks can’t be added here.
communities:
show:
active_form: Add/View/Edit the custom forms already applied to the community.
add_form: These custom forms are specific to your NGO. Select one from the list to load the form. Once you fill and save it, the form will be attached to the community.
custom:
custom_id1: Alternate case identification (ID) number related to the client. In the case of jointly managed clients or clients referred through other organization(s), enter the ID that was used on the previous paperwork, record, or database. This will help in tracking client record. Admin, This field name is customizable. To change the name, go to Manage >> Setting >> Custom Labels. This is different from Client ID auto-generated in OSCaR for every case.
custom_id2: Alternate case identification (ID) number related to the client. In the case of jointly managed clients or clients referred through other organization(s), enter the ID that was used on the previous paperwork, record, or database. This will help in tracking client record. Admin, This field name is customizable. To change the name, go to Manage >> Setting >> Custom Labels.
Expand Down
2 changes: 2 additions & 0 deletions config/locales/km.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,8 @@ km:
new:
new_community_title: New Community
show:
add_form: Add Form
additional_forms: Community's Active Forms
address: Address
all_beneficiaries: To Count All Beneficiaries (direct members and their household members)
are_you_sure: Are you sure you want to delete?
Expand Down
2 changes: 2 additions & 0 deletions config/locales/my.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,8 @@ my:
new:
new_community_title: New Community
show:
add_form: Add Form
additional_forms: Community's Active Forms
address: Address
all_beneficiaries: To Count All Beneficiaries (direct members and their household members)
are_you_sure: Are you sure you want to delete?
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
4 changes: 4 additions & 0 deletions spec/models/community_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
describe Community, 'associations' do
it { is_expected.to have_many(:custom_field_properties).dependent(:destroy) }
it { is_expected.to have_many(:custom_fields).through(:custom_field_properties) }
end
17 changes: 15 additions & 2 deletions spec/models/custom_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe CustomField, 'associations' do
it { is_expected.to have_many(:custom_field_properties).dependent(:restrict_with_error) }
it { is_expected.to have_many(:clients).through(:custom_field_properties).source(:custom_formable) }
it { is_expected.to have_many(:communities).through(:custom_field_properties).source(:custom_formable) }
it { is_expected.to have_many(:families).through(:custom_field_properties).source(:custom_formable) }
it { is_expected.to have_many(:partners).through(:custom_field_properties).source(:custom_formable) }
it { is_expected.to have_many(:users).through(:custom_field_properties).source(:custom_formable) }
Expand Down Expand Up @@ -99,14 +100,26 @@
is_expected.not_to include(other_custom_field)
end
end

context 'community forms' do
let!(:custom_field) { create(:custom_field, form_title: 'Community Form', entity_type: 'Community') }
let!(:other_custom_field) { create(:custom_field, form_title: 'Prison Record', entity_type: 'Partner') }
subject { CustomField.community_forms }
it 'should include forms with community entity type' do
is_expected.to include(custom_field)
end
it 'should not include forms without community entity type' do
is_expected.not_to include(other_custom_field)
end
end
end

describe CustomField, 'CONSTANTS' do
it 'FREQUENCIES' do
expect(CustomField::FREQUENCIES).to eq(['Daily', 'Weekly', 'Monthly', 'Yearly'])
end
it 'ENTITY_TYPES' do
expect(CustomField::ENTITY_TYPES).to eq(['Client', 'Family', 'Partner', 'User'])
expect(CustomField::ENTITY_TYPES).to eq(['Client', 'Community', 'Family', 'Partner', 'User'])
end
end

Expand Down Expand Up @@ -149,4 +162,4 @@
end
end
end
end
end