added export and filter for users

This commit is contained in:
Harry Bomrah 2017-06-29 16:06:30 +08:00
parent 85d753d49d
commit 6cc56bee26
10 changed files with 338 additions and 3 deletions

View File

@ -5,8 +5,26 @@ class Admin::MemberCounselorsController < OrbitAdminController
@table_fields = ["member_counselor.file_date","member_counselor.file_title", "member_counselor.downloaded_times", "member_counselor.account", "member_counselor.user_type", "actions"]
end
def results
@files = HpsResult.all.desc(:created_at).page(params[:page]).per(10)
@table_fields = ["member_counselor.file_date","member_counselor.file_title", "member_counselor.downloaded_times", "member_counselor.account", "member_counselor.user_type", "actions"]
end
def records
@records = HpsCounselingRecord.all.desc(:created_at).page(params[:page]).per(10)
@table_fields = ["member_counselor.file_date","member_counselor.title", "member_counselor.event_title", "member_counselor.account", "actions"]
end
def index
@counselors = HpsMember.all.desc(:created_at).page(params[:page]).per(10)
if !params[:user_type].present?
@counselors = HpsMember.all.desc(:created_at)
else
types = params[:user_type].collect{|ut| ut.to_i if ut.is_i?}
types.delete(nil)
@counselors = HpsMember.where(:user_type.in => params[:user_type])
end
@counselors = search_data(@counselors,[:name, :account]).page(params[:page]).per(10)
@table_fields = ["member_counselor.account","member_counselor.name", "member_counselor.user_type"]
end
@ -59,6 +77,31 @@ class Admin::MemberCounselorsController < OrbitAdminController
redirect_to uploads_admin_member_counselors_path
end
def destroy_result
hpresult = HpsResult.find(params[:id])
hpresult.destroy
redirect_to results_admin_member_counselors_path
end
def destroy_record
record = HpsCounselingRecord.find(params[:id])
record.destroy
redirect_to records_admin_member_counselors_path
end
def showrecord
@record = HpsCounselingRecord.find(params[:id])
end
def export_records
@records = HpsCounselingRecord.all.desc(:created_at)
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="counselor_records.xlsx"'
}
end
end
private
def counselor_params

View File

@ -0,0 +1,51 @@
# encoding: utf-8
wb = xlsx_package.workbook
wb.add_worksheet(name: "Counselor Records") do |sheet|
heading = sheet.styles.add_style(:b => true, :locked => true)
row = []
row << "新增日期"
row << "縣市"
row << "對象"
row << "輔導日期"
row << "方式"
row << "會議/活動名稱"
row << "縣市輔導項目(可複選)"
row << "學校輔導項目(可複選)"
row << "內容記要(如:所輔導內容、所解決困難、所達成共識、待解決問題…):"
row << "委員建議(如:對該縣市健康促進計畫推動、輔導學校之建議…):"
sheet.add_row row, :style => heading
@records.each do |record|
row = []
row << record.created_at.strftime("%Y-%m-%d %H:%M:%S")
row << (record.get_city.name rescue "") + "/" + (record.get_county.name rescue "")
row << record.get_school.name
row << record.counseling_date.strftime("%Y-%m-%d %H:%M:%S")
s = ""
record.counseling_method.each do |methd|
s = s + methd
end
s = s + (record.counseling_method_description rescue "") if record.counseling_method.include?("個別議題輔導")
row << s
row << record.event_title
s = ""
record.purpose_for_county.each do |methd|
s = s + methd
end
s = s + (record.purpose_for_county_extra rescue "") if record.purpose_for_county.include?("(8)其他(請填寫):")
row << s
s = ""
record.purpose_for_school.each do |methd|
s = s + methd
end
s = s + (record.purpose_for_school_extra rescue "") if record.purpose_for_school.include?("(7)其他(請填寫):")
row << record.minutes_of_event
row << record.evaluation_of_event
sheet.add_row row
end
end

View File

@ -1,3 +1,37 @@
<% content_for :right_nav do %>
<div class="searchClear pull-left">
<form id="module-search-form">
<input type="text" id="filter-input" class="search-query input-medium" placeholder="<%= t(:search_) %>" name="keywords" value="<%=params[:keywords]%>">
<% if params[:keywords].present? %>
<a href="<%= admin_member_counselors_path %>" class="btn btn-link btn-small"><i class="icons-cycle"></i> <%= t(:clear) %></a>
<% end %>
</form>
</div>
<div class="pull-right">
<ul class="nav nav-pills filter-nav pull-right">
<li class="accordion-group <%= params[:user_type].present? ? "active" : "" %>">
<div class="accordion-heading">
<a href="#collapse-type" data-toggle="collapse" data-parent="#filter" class="accordion-toggle">User Type</a>
</div>
</li>
</ul>
<div class="filter-group accordion-group">
<div class="accordion-body <%= params[:user_type].present? ? "" : "collapse" %>" id="collapse-type">
<div class="accordion-inner pagination-right" >
<form action="" method="get" id="filter-form" >
<label style="display: inline;" for="user_type_0"><input id="user_type_0" type="checkbox" name="user_type[]" <%= params[:user_type].present? && params[:user_type].include?("0") ? "checked=checked" : "" %> value="0" class="filterable"> <%= t("member_counselor.type1") %></label>
<label style="display: inline;" for="user_type_1"><input id="user_type_1" type="checkbox" name="user_type[]" <%= params[:user_type].present? && params[:user_type].include?("1") ? "checked=checked" : "" %> value="1" class="filterable"> <%= t("member_counselor.type2") %></label>
<label style="display: inline;" for="user_type_2"><input id="user_type_2" type="checkbox" name="user_type[]" <%= params[:user_type].present? && params[:user_type].include?("2") ? "checked=checked" : "" %> value="2" class="filterable"> <%= t("member_counselor.type3") %></label>
</form>
</div>
<% if params[:user_type].present? %>
<div class="filter-clear">
<a href="<%= admin_member_counselors_path %>" class="btn btn-link btn-small"><i class="icons-cycle"></i> <%= t(:clear) %></a>
</div>
<% end %>
</div>
</div>
<% end %>
<table class="table main-list">
<thead>
<tr class="sort-header">
@ -38,4 +72,20 @@
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@counselors), class: "pagination pagination-centered"
end
%>
%>
<script type="text/javascript">
$(function() {
$("#filter-form").submit(function() {
$(this).find(":input").filter(function(){ return !this.value; }).attr("disabled", "disabled");
return true; // ensure form still submits
});
});
$(".filterable").on("click",function(){
$("#filter-form").submit();
})
$("#filter-input").on("keyup",function(){
if(e.keycode == 13){
$("#module-search-form").submit();
}
})
</script>

View File

@ -0,0 +1,37 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @records.each do |record| %>
<tr>
<td>
<%= record.created_at.strftime("%Y/%m/%d") %>
</td>
<td>
<a href="<%= showrecord_admin_member_counselor_path(record) %>"><%= record.get_title %></a>
</td>
<td>
<%= record.event_title %>
</td>
<td>
<%= record.hps_member.account %>
</td>
<td>
<a href="<%= destroy_record_admin_member_counselor_path(record) %>" data-method="delete" data-confirm="Are you sure?" class="text-error">Delete</a>
</td>
</tr>
<% end %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@records), class: "pagination pagination-centered"
link_to t("member_counselor.export"), export_records_admin_member_counselors_path(:format => "xlsx"), :class => "pull-right btn btn-info", :target => "_blank"
end
%>

View File

@ -0,0 +1,39 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @files.each do |file| %>
<tr>
<td>
<%= file.created_at.strftime("%Y/%m/%d") %>
</td>
<td>
<a href="<%= file.file.url %>" target="_blank"><%= file.title %></a>
</td>
<td>
<%= file.download_count %>
</td>
<td>
<%= file.hps_member.account %>
</td>
<td>
<%= file.hps_member.get_user_type %>
</td>
<td>
<a href="<%= destroy_result_admin_member_counselor_path(file) %>" data-method="delete" data-confirm="Are you sure?" class="text-error">Delete</a>
</td>
</tr>
<% end %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@files), class: "pagination pagination-centered"
end
%>

View File

@ -0,0 +1,87 @@
<table width="100%" border="1">
<tr>
<td>新增日期</td>
<td id="date-time"><%= @record.created_at.strftime("%Y-%m-%d %H:%M:%S") %></td>
</tr>
<tr>
<td>縣市</td>
<td>
<%= @record.get_city.name rescue "" %>/<%= @record.get_county.name rescue "" %>
</td>
</tr>
<tr>
<td>對象</td>
<td>
<%= @record.get_school.name rescue "" %>
</td>
</tr>
<tr>
<td>輔導日期</td>
<td>
<%= @record.counseling_date.strftime("%Y-%m-%d %H:%M:%S") %>
</td>
</tr>
<tr>
<td>方式</td>
<td>
<% @record.counseling_method.each do |methd| %>
<%= methd %>
<% if methd != "個別議題輔導" %>
<br/>
<% end %>
<% end %>
<% if @record.counseling_method.include?("個別議題輔導") %>
<%= @record.counseling_method_description %>
<% end %>
</td>
</tr>
<tr>
<td>會議/活動名稱</td>
<td>
<%= @record.event_title %>
</td>
</tr>
<tr>
<td>
縣市輔導項目(可複選)
</td>
<td>
<% @record.purpose_for_county.each do |methd| %>
<%= methd %>
<% if methd != "(8)其他(請填寫):" %>
<br/>
<% end %>
<% end %>
<% if @record.purpose_for_county.include?("(8)其他(請填寫):") %>
<%= @record.purpose_for_county_extra %>
<% end %>
</td>
</tr>
<tr>
<td>學校輔導項目(可複選)</td>
<td>
<% @record.purpose_for_school.each do |methd| %>
<%= methd %>
<% if methd != "(7)其他(請填寫):" %>
<br/>
<% end %>
<% end %>
<% if @record.purpose_for_school.include?("(7)其他(請填寫):") %>
<%= @record.purpose_for_school_extra %>
<% end %>
</td>
</tr>
<tr>
<td width="20%">內容記要(如:所輔導內容、所解決困難、所達成共識、待解決問題…):</td>
<td><%= @record.minutes_of_event %></td>
</tr>
<tr>
<td>委員建議(如:對該縣市健康促進計畫推動、輔導學校之建議…):</td>
<td><%= @record.evaluation_of_event %></td>
</tr>
<tr>
<td colspan="2">
<a href="" onclick="window.history.back();return false;" class="btn">Back</a>
</td>
</tr>
</table>

View File

@ -3,6 +3,9 @@ en:
member_counselor: HPS Members
new_user: Create User
all_members: All Members
uploads: Uploads
results: Results
records: Counselor Records
account: User Account
password: Password
confirm_password: Confirm Password
@ -10,7 +13,9 @@ en:
name: Name
organization: Organization
title: Title
event_title: Event Title
county: County
export: Export
address: Address
email: Email
telephone: Telphone

View File

@ -3,6 +3,9 @@ zh_tw:
member_counselor: HPS Members
new_user: Create User
all_members: All Members
uploads: Uploads
results: Results
records: Counselor Records
account: 帳號
password: 密碼
confirm_password: 確認密碼
@ -10,6 +13,8 @@ zh_tw:
name: 姓名
organization: 服務機關
title: 職稱
event_title: 會議/活動名稱
export: Export
county: 縣市
address: 地址
email: 電子信箱

View File

@ -6,10 +6,16 @@ Rails.application.routes.draw do
resources :member_counselors do
collection do
get "uploads"
get "results"
get "records"
get "export_records"
get "get_info"
end
member do
delete "destroy_upload"
delete "destroy_result"
delete "destroy_record"
get "showrecord"
end
end
end

View File

@ -19,12 +19,24 @@ module MemberCounselor
active_for_controllers (['admin/member_counselors'])
head_link_path "uploads_admin_member_counselors_path"
context_link 'all',
context_link 'member_counselor.uploads',
:link_path=>"uploads_admin_member_counselors_path" ,
:priority=>1,
:active_for_action=>{'admin/member_counselors'=>"uploads"},
:available_for => 'admin'
context_link 'member_counselor.results',
:link_path=>"results_admin_member_counselors_path" ,
:priority=>1,
:active_for_action=>{'admin/member_counselors'=>"results"},
:available_for => 'admin'
context_link 'member_counselor.records',
:link_path=>"records_admin_member_counselors_path" ,
:priority=>1,
:active_for_action=>{'admin/member_counselors'=>"records"},
:available_for => 'admin'
context_link 'member_counselor.all_members',
:link_path=>"admin_member_counselors_path" ,
:priority=>1,