diff --git a/app/assets/javascripts/clients/index.coffee b/app/assets/javascripts/clients/index.coffee index e7d5169..bc046b1 100644 --- a/app/assets/javascripts/clients/index.coffee +++ b/app/assets/javascripts/clients/index.coffee @@ -7,6 +7,20 @@ OSCAR.ClientsIndex = do -> _initAdavanceSearchFilter() _toggleCollapseFilter() _handleAutoCollapse() + _getClientPath() + # _appendCsiScores() + # + # _appendCsiScores = -> + # $('#csiScores').on 'show.bs.modal', (event) -> + # button = $(event.relatedTarget) + # recipient = button.data('whatever') + # modal = $(this) + # modal.find('.modal-body').text recipient + + _getClientPath = -> + $('table.clients tbody tr').click (e) -> + return if $(@).text().trim() == 'No data available in table' || $(e.target).hasClass('btn') || $(e.target).hasClass('fa') || $(e.target).is('a') + window.open($(@).data('href'), '_blank') _hideClientFilters = -> dataFilters = $('#client-search-form .datagrid-filter') @@ -148,7 +162,9 @@ OSCAR.ClientsIndex = do -> $('fonts font name', styles).attr('val', 'Khmer OS Content') } ] - ) + drawCallback: (settings) -> + _getClientPath() + ) $('table.clients thead tr:eq(1) th input[name="gender"]').on 'keyup', -> table.columns(1).search("^" + @value, true, false).draw(); diff --git a/app/assets/stylesheets/clients/show.scss b/app/assets/stylesheets/clients/show.scss new file mode 100644 index 0000000..2ee23fb --- /dev/null +++ b/app/assets/stylesheets/clients/show.scss @@ -0,0 +1,10 @@ +body[id='clients-show'] { + table#csi-scores { + th, td { + min-width: 160px; + } + .align-middle { + vertical-align: middle; + } + } +} diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index be2d4f3..d938e65 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -1,6 +1,7 @@ class ClientsController < AdminController before_action :find_params_advanced_search, :client_builder_fields, :build_advanced_search, only: :index before_action :basic_params, if: :has_params? + before_action :find_client, :find_csi_domains, only: :show def index respond_to do |f| @@ -8,11 +9,13 @@ def index f.html do @clients_count = clients.count @clients = clients - # @clients = Kaminari.paginate_array(clients).page(params[:page]).per(20) end end end + def show + end + private def clients_ordered(clients) @@ -30,17 +33,16 @@ def clients_ordered(clients) end def fetch_clients - # org_short_names = Organization.pluck(:short_name) org_short_names = Organization.cambodian.visible.pluck(:short_name) - clients = [] + all_clients = [] org_short_names.each do |short_name| Organization.switch_to(short_name) next unless Setting.first.sharing_data? - clients << clients_query - clients.flatten.to_a + clients = clients_query + all_clients << { ngo: short_name, clients: clients.flatten } end Organization.switch_to('public') - clients.flatten + all_clients end def decorate_clients(value) @@ -52,7 +54,6 @@ def client_filter_adavnced_searches basic_rules = JSON.parse @basic_filter_params basicfield_ngo = [] org_short_names = Organization.cambodian.visible.pluck(:short_name) - # org_short_names = Organization.pluck(:short_name) filter_client_advanced_serach(org_short_names, basic_rules) end @@ -89,13 +90,15 @@ def list_clients_filter end def filter_client_advanced_serach(ngos, basic_rules) - clients = ngos.map do |short_name| + all_clients = [] + ngos.each do |short_name| Organization.switch_to(short_name) next unless Setting.first.sharing_data? - AdvancedSearches::ClientAdvancedSearch.new(basic_rules, clients_query).filter.reload + clients = AdvancedSearches::ClientAdvancedSearch.new(basic_rules, clients_query).filter.reload + all_clients << { ngo: short_name, clients: clients.flatten } end Organization.switch_to('public') - clients.flatten + all_clients end def clients_query @@ -105,4 +108,18 @@ def clients_query (SELECT COUNT(id) FROM assessments WHERE assessments.client_id = clients.id AND assessments.default = true) as assessment_count ") end + + def find_client + crypt = ActiveSupport::MessageEncryptor.new(ENV['SLUG_ENCRYPTION_KEY']) + client_id = crypt.decrypt_and_verify(params[:id]) + ngo_short_name = params[:ngo] + + Organization.switch_to(ngo_short_name) + + @client = clients_query.friendly.find(client_id) + end + + def find_csi_domains + @csi_domains = Domain.csi_domains + end end diff --git a/app/helpers/clients_helper.rb b/app/helpers/clients_helper.rb index 9bd6500..5d70d5c 100644 --- a/app/helpers/clients_helper.rb +++ b/app/helpers/clients_helper.rb @@ -87,4 +87,9 @@ def problem_rank(client, problem) # end # end # end + def encrypted_client_slug(id) + key = ENV['SLUG_ENCRYPTION_KEY'] + crypt = ActiveSupport::MessageEncryptor.new(key) + encrypted_data = crypt.encrypt_and_sign(id) + end end diff --git a/app/models/client.rb b/app/models/client.rb index 52ae883..ecf6843 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -40,6 +40,7 @@ class Client < ActiveRecord::Base has_many :assessments, dependent: :destroy has_many :client_enrollments, dependent: :destroy has_many :program_streams, through: :client_enrollments + has_many :referrals, dependent: :destroy scope :live_with_like, ->(value) { where('clients.live_with iLIKE ?', "%#{value}%") } scope :current_address_like, ->(value) { where('clients.current_address iLIKE ?', "%#{value}%") } diff --git a/app/models/domain.rb b/app/models/domain.rb index c1855b7..e259996 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -6,6 +6,7 @@ class Domain < ActiveRecord::Base has_many :domain_program_streams, dependent: :restrict_with_error has_many :program_streams, through: :domain_program_streams + default_scope { order('domain_group_id ASC, name ASC') } scope :csi_domains, -> { where(custom_domain: false) } scope :order_by_identity, -> { order(:identity) } end diff --git a/app/models/referral.rb b/app/models/referral.rb new file mode 100644 index 0000000..e639c8c --- /dev/null +++ b/app/models/referral.rb @@ -0,0 +1,3 @@ +class Referral < ActiveRecord::Base + belongs_to :client +end diff --git a/app/views/clients/_csi_scores.haml b/app/views/clients/_csi_scores.haml new file mode 100644 index 0000000..454cd6d --- /dev/null +++ b/app/views/clients/_csi_scores.haml @@ -0,0 +1,21 @@ +#csiScores.modal.fade{"aria-labelledby" => "csiScoresLabel", :role => "dialog", :tabindex => "-1"} + .modal-dialog{:role => "document"} + .modal-content + .modal-header + %button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"} + %span{"aria-hidden" => "true"} × + %h4#csiScoresLabel.modal-title Modal title + .modal-body + -# %table.table.table-bordered.table-striped.table-hover + -# %thead + -# %tr + -# %th Date of Assessment + -# - Domain.csi_domains.each do |domain| + -# %th= domain.name + -# %tbody + -# + -# %tr + -# %td + .modal-footer + %button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Close + %button.btn.btn-primary{:type => "button"} Save changes diff --git a/app/views/clients/_table_body.haml b/app/views/clients/_table_body.haml index 8792fad..7cef231 100644 --- a/app/views/clients/_table_body.haml +++ b/app/views/clients/_table_body.haml @@ -1,10 +1,15 @@ -- clients.each do |client| - %tr - %td= client.display_age - %td= client.gender.try(&:titleize) - %td= client.status - %td.text-center - = client.enrollment_count - %td= client.province_name - %td= client.district_name +- clients.each do |clients_hash| + - clients_hash[:clients].each do |client| + - url = encrypted_client_slug("#{client.slug}") + %tr{ data: { href: "/clients/#{url}?ngo=#{clients_hash[:ngo]}" } } + %td= client.display_age + %td= client.gender.try(&:titleize) + %td= client.status + %td.text-center + = client.enrollment_count + %td= client.province_name + %td= client.district_name + + -# = render 'csi_scores' + - Organization.switch_to('public') diff --git a/app/views/clients/show.haml b/app/views/clients/show.haml new file mode 100644 index 0000000..1a155b3 --- /dev/null +++ b/app/views/clients/show.haml @@ -0,0 +1,82 @@ +-# .row +-# .col-xs-12 +-# .row +-# .col-md-3 +-# .client-info +-# = @client.gender.titleize +-# .col-md-6 +-# %table.table.small.m-b-xs +-# %tbody +-# %tr +-# +-# %td +-# = "#{t('.age')} : " +-# %strong= @client.display_age +-# %td +-# = "#{t('.current_province')} : " +-# %strong= @client.province_name + +.row.mini-margin + .col-xs-12 + .ibox + .ibox-title + %h5= t('.about_client') + .ibox-content + .row + .col-sm-12.col-md-6.first-table + %table.table.table-bordered + %tr + %td + = t('.current_province') + %td + %strong + = @client.province_name + %tr + %td + = t('.district') + %td + %strong + = @client.district_name + %tr + %td + = t('.age') + %td + %strong + = @client.display_age + .col-sm-12.col-md-6.second-table + %table.table.table-bordered + %tr + %td + = t('.number_active_program') + %td + %strong + = @client.enrollment_count + %tr + %td + = t('.status') + %td + %strong + = @client.status + %tr + %td + = t('.gender') + %td + %strong + = @client.gender.try(:titleize) + .col-xs-12 + .table-responsive + %table.table.table-bordered#csi-scores + %tr + %th.text-center.align-middle Date of Assessment + - @csi_domains.each do |domain| + %th.text-center.align-middle= domain.identity + - if @client.assessments.any? + - @client.assessments.most_recents.each do |assessment| + %tr + %td.text-center= date_format(assessment.created_at) + - @csi_domains.each do |domain| + %td.text-center= assessment.assessment_domains.find_by(domain: domain).try(:score) + - else + %tr + %td{ colspan: @csi_domains.count + 1 } No data +- Organization.switch_to('public') diff --git a/app/views/custom_table/_table_body.haml b/app/views/custom_table/_table_body.haml index c23f1c1..08fb22e 100644 --- a/app/views/custom_table/_table_body.haml +++ b/app/views/custom_table/_table_body.haml @@ -1,15 +1,17 @@ -- clients.compact.each do |client| - %tr - - if params[:columns].nil? || params[:columns][:age] == '1' - %td= client.display_age - - if params[:columns].nil? || params[:columns][:gender] == '1' - %td= client.gender.try(:titleize) - - if params[:columns].nil? || params[:columns][:status] == '1' - %td= client.status - - if params[:columns].nil? || params[:columns][:number_active_program] == '1' - %td.text-center - = client.enrollment_count - - if params[:columns].nil? || params[:columns][:district] == '1' - %td= client.district_name - - if params[:columns].nil? || params[:columns][:current_province] == '1' - %td= client.province_name +- clients.each do |clients_hash| + - clients_hash[:clients].each do |client| + - url = encrypted_client_slug("#{client.slug}") + %tr{ data: { href: "/clients/#{url}?ngo=#{clients_hash[:ngo]}" } } + - if params[:columns].nil? || params[:columns][:age] == '1' + %td= client.display_age + - if params[:columns].nil? || params[:columns][:gender] == '1' + %td= client.gender.try(:titleize) + - if params[:columns].nil? || params[:columns][:status] == '1' + %td= client.status + - if params[:columns].nil? || params[:columns][:number_active_program] == '1' + %td.text-center + = client.enrollment_count + - if params[:columns].nil? || params[:columns][:district] == '1' + %td= client.district_name + - if params[:columns].nil? || params[:columns][:current_province] == '1' + %td= client.province_name diff --git a/app/views/custom_table/_table_header.haml b/app/views/custom_table/_table_header.haml index 9075487..719c469 100644 --- a/app/views/custom_table/_table_header.haml +++ b/app/views/custom_table/_table_header.haml @@ -10,4 +10,3 @@ %th= t('.district') - if params[:columns].nil? || params[:columns][:current_province] == '1' %th= t('.current_province') - diff --git a/config/locales/en.yml b/config/locales/en.yml index e5026a3..391fe5b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -293,7 +293,8 @@ en: one: '1 error prohibited this %{resource} from being saved:' other: "%{count} errors prohibited this %{resource} from being saved:" layouts: - site_menu: + side_menu: + clients: Clients edit_profile: Edit Profile dashboard: Dashboard logout: Logout diff --git a/config/locales/km.yml b/config/locales/km.yml index 68f4284..3e75b56 100644 --- a/config/locales/km.yml +++ b/config/locales/km.yml @@ -67,9 +67,11 @@ km: district: ស្រុក/ខណ្ឌ number_active_program: ចំនួនកម្មវិធីដែលកុមារចូលរួម status: ស្ថានភាព + gender: ភេទ custom_table: basic_fields: ពត៌មានទូទៅរបស់អតិថិជន form_one_title: + active_program_stream: ចំនួនកម្មវិធីដែលកុមារចូលរួម age: អាយុ birth_province: ស្រុកកំណើត cambodia: កម្ពុជា @@ -298,6 +300,7 @@ km: other: "%{count} កំហុស បានហាមឃាត់ %{resource} ពីការរក្សាទុក" layouts: side_menu: + clients: អតិថិជន edit_profile: កែសម្រួលព័ត៌មានផ្ទាល់ខ្លួន dashboard: តារាងទិន្នន័យ logout: ចាកចេញ diff --git a/config/routes.rb b/config/routes.rb index 9271575..573b8e8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ match "/#{code}", to: 'errors#show', code: code, via: :all end - resources :clients, only: [:index] + resources :clients, only: [:index, :show] resources :advanced_search_save_queries scope 'admin' do