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

Client show page #14

Open
wants to merge 9 commits into
base: stable
Choose a base branch
from
Open
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
18 changes: 17 additions & 1 deletion app/assets/javascripts/clients/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions app/assets/stylesheets/clients/show.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body[id='clients-show'] {
table#csi-scores {
th, td {
min-width: 160px;
}
.align-middle {
vertical-align: middle;
}
}
}
37 changes: 27 additions & 10 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
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|
clients = list_clients_filter
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)
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
5 changes: 5 additions & 0 deletions app/helpers/clients_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}%") }
Expand Down
1 change: 1 addition & 0 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions app/models/referral.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Referral < ActiveRecord::Base
belongs_to :client
end
21 changes: 21 additions & 0 deletions app/views/clients/_csi_scores.haml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 14 additions & 9 deletions app/views/clients/_table_body.haml
Original file line number Diff line number Diff line change
@@ -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')
82 changes: 82 additions & 0 deletions app/views/clients/show.haml
Original file line number Diff line number Diff line change
@@ -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')
32 changes: 17 additions & 15 deletions app/views/custom_table/_table_body.haml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion app/views/custom_table/_table_header.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
%th= t('.district')
- if params[:columns].nil? || params[:columns][:current_province] == '1'
%th= t('.current_province')

3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/locales/km.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: កម្ពុជា
Expand Down Expand Up @@ -298,6 +300,7 @@ km:
other: "%{count} កំហុស បានហាមឃាត់ %{resource} ពីការរក្សាទុក"
layouts:
side_menu:
clients: អតិថិជន
edit_profile: កែសម្រួលព័ត៌មានផ្ទាល់ខ្លួន
dashboard: តារាងទិន្នន័យ
logout: ចាកចេញ
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down