management school report feature

openi_sso
winse 6 years ago
parent 0f2493e877
commit 372db525bd

1
.gitignore vendored

@ -22,6 +22,7 @@
.DS_Store
public/api_doc/
/.metadata
.byebug_history
vendor/cache
/files
/public/images/avatars

@ -0,0 +1,5 @@
class Managements::BaseController < ApplicationController
layout 'base_management'
before_filter :require_admin
end

@ -0,0 +1,20 @@
class Managements::SchoolsController < Managements::BaseController
before_filter :set_navigation_bar
before_filter :set_default_sort_params, only: :statistics
def statistics
@sub_type = 1
schools = Management::SchoolReportService.new(params).call
@schools = paginateHelper schools
end
private
def set_navigation_bar
@menu_type = 1
end
def set_default_sort_params
params[:sort_by] ||= :teacher_count
params[:sort_direction] ||= :desc
end
end

@ -668,6 +668,11 @@ module ApplicationHelper
def managements_navigation_bar_show menu_type, sub_type, grandchild_type={}
case menu_type
when 1
case sub_type
when 1 then "统计总表"
when 2 then "变化报表"
end
when 2
sub_type == 1 ? "课程列表" : (sub_type == 2? "课堂列表" : (sub_type == 3? "实训作业" : "项目列表"))
when 3
@ -5509,6 +5514,27 @@ challengeProgramNames=(CHALLENGEPROGRAMNAMES)"
return sort_projects
end
end
def sort_tag(content, **opts)
options = {}
options[:sort_by] = opts.delete(:name)
is_current_sort = params[:sort_by].to_s == options[:sort_by]
options[:sort_direction] = is_current_sort && params[:sort_direction].to_s == 'desc' ? 'asc' : 'desc'
path = opts.delete(:path) + "?" + params.merge(options).to_query
arrow_class = case params[:sort_direction].to_s
when 'desc' then 'fa-long-arrow-down'
when 'asc' then 'fa-long-arrow-up'
else ''
end
content_tag(:span, opts) do
link_to path, remote: true do
content += content_tag(:i, '', class: "fa color-light-green ml5 #{arrow_class}") if is_current_sort
raw content
end
end
end
end
def user_url_in_org(user_id)

@ -0,0 +1,45 @@
module CustomSortable
extend ActiveSupport::Concern
included do |base|
base.instance_variable_set("@_sort_options", {})
base.instance_variable_set("@_sort_columns", [])
base.instance_variable_set("@_sort_directions", %w(asc desc))
end
def custom_sort(relations, sort_by, sort_direction)
sort_by ||= self.class.sort_options[:default_by]
sort_direction ||= self.class.sort_options[:default_direction]
return relations unless self.class.check_sort_parameter_validate(sort_by, sort_direction)
order_method = self.class.sort_options[:reorder] ? :reorder : :order
relations.send(order_method, "#{sort_by} #{sort_direction}")
end
def multiple_custom_sort(relations, **opts)
opts.each do |sort_by, sort_direction|
relations = custom_sort(relations, sort_by, sort_direction)
end
relations
end
module ClassMethods
def sort_columns(*columns)
opts = columns.extract_options!
@_sort_options[:default_by] = opts[:default_by].to_s
@_sort_options[:default_direction] = opts[:default_direction].to_s
@_sort_options[:reorder] = opts[:reorder]
@_sort_columns = columns.map(&:to_s)
end
def check_sort_parameter_validate(sort_by, sort_direction)
(sort_by.blank? || @_sort_columns.include?(sort_by)) && @_sort_directions.include?(sort_direction)
end
def sort_options
@_sort_options
end
end
end

@ -0,0 +1,58 @@
class Management::SchoolReportService
include CustomSortable
attr_reader :params
sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count,
:course_count, :active_course_count, :nearly_course_time,
default_by: :teacher_count, default_direction: :desc
def initialize(params)
@params = params
end
def call
schools = School.select(select_columns_sql)
keyword = params[:keyword]&.to_s&.strip
if keyword.present?
schools = schools.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%")
end
schools = custom_sort(schools, params[:sort_by], params[:sort_direction])
schools
end
private
def select_columns_sql
<<-SQL
schools.id, schools.name,
(
SELECT COUNT(*) FROM users u
LEFT JOIN user_extensions ue ON ue.user_id = u.id
LEFT JOIN ec_school_users esu ON esu.user_id = u.id
WHERE esu.school_id = schools.id AND ue.identity = #{User::STUDENT}
) student_count,
(
SELECT COUNT(*) FROM users u
LEFT JOIN user_extensions ue ON ue.user_id = u.id
LEFT JOIN ec_school_users esu ON esu.user_id = u.id
WHERE esu.school_id = schools.id AND ue.identity = #{User::TEACHER}
) teacher_count,
(
SELECT COUNT(*) FROM homework_commons hc
LEFT JOIN courses ON courses.id = hc.course_id
WHERE courses.school_id = schools.id
) homework_count,
(
SELECT COUNT(*) FROM homework_commons hc
LEFT JOIN courses ON courses.id = hc.course_id
WHERE courses.school_id = schools.id AND hc.homework_type IN (1,3)
) other_homework_count,
(SELECT COUNT(*) FROM courses cs WHERE cs.school_id = schools.id) course_count ,
(SELECT MAX(cs.updated_at) FROM courses cs WHERE cs.school_id = schools.id) nearly_course_time ,
(SELECT COUNT(*) FROM courses acs WHERE acs.school_id = schools.id AND acs.is_end = false) active_course_count
SQL
end
end

@ -32,6 +32,11 @@
</p>
<ul class="edu-admin-nav clearfix bor-grey-e">
<!--<li class="fl edu-admin-nav-li"><a href="javascript:void(0);" class="edu-admin-nav-a">主页</a></li>-->
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 1 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">学校+</a>
<ul class="edu-admin-nav-inner edu-absolute">
<li><%= link_to '统计总表', school_report_managements_path %></li>
</ul>
</li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 2 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">课堂+</a>
<ul class="edu-admin-nav-inner edu-absolute">
<li><%= link_to "课程列表", classroom_managements_path %></li>

@ -0,0 +1,43 @@
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed">
<thead>
<tr>
<th width="6%">序号</th>
<th width="6%">ID</th>
<th width="14%" class="edu-txt-left">单位名称</th>
<th width="10%"><%= sort_tag('教师总人数', name: 'teacher_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('学生总人数', name: 'student_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('课堂总数', name: 'course_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('正在进行课堂数', name: 'active_course_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('实训作业总数', name: 'homework_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('其它作业总数', name: 'other_homework_count', path: school_report_managements_path) %></th>
<th width="14%"><%= sort_tag('动态时间', name: 'nearly_course_time', path: school_report_managements_path) %></th>
</tr>
</thead>
<tbody>
<% @schools.as_json.each_with_index do |data, index| %>
<tr>
<% school = data["school"] %>
<td><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td>
<td><%= school['id'] %></td>
<td class="edu-txt-left"><%= school['name'] %></td>
<td><%= school['teacher_count'] %></td>
<td><%= school['student_count'] %></td>
<td><%= school['course_count'] %></td>
<td><%= school['active_course_count'] %></td>
<td><%= school['homework_count'] %></td>
<td><%= school['other_homework_count'] %></td>
<td><%= format_time school['nearly_course_time'] %></td>
</tr>
<% end %>
</tbody>
</table>
<div style="text-align:center;" class="new_expand">
<div class="pages_user_show" style="width:auto; display:inline-block;margin: 18px 0;">
<ul id="school_report_ref_pages">
<%= pagination_links_full @obj_pages, @obj_count, per_page_links: false, remote: true, flag: true, is_new: true, path: school_report_managements_path(params.except(:page)) %>
</ul>
<div class="cl"></div>
</div>
</div>

@ -0,0 +1,19 @@
<div class="edu-con-top clearfix xmt10 bor-grey-e mt10">
<%= form_tag(school_report_managements_path(params), method: :get, remote: true, id: 'school_report_search_form') do %>
<%= text_field_tag :keyword, params[:keyword], placeholder: '请输入单位名称或者ID关键字进行搜索',
class: 'fl task-form-30 task-height-30 mt10', style: 'margin: 10px 10px 10px 25px;' %>
<%= link_to '搜索', 'javascript:void(0)', class: 'fl task-btn task-btn-orange ml5 mt10', onclick: "$('#school_report_search_form').submit();" %>
<%= link_to '清除', 'javascript:clearSearchCondition()', class: 'fl task-btn ml5 mt2 mt10' %>
<% end %>
</div>
<div class="edu-con-bg01 mt15" id="managements_school_report">
<%= render 'managements/schools/statistics_list'%>
</div>
<script>
function clearSearchCondition(){
$("#school_report_search_form input[name='keyword']").val("");
$('#school_report_search_form').submit();
}
</script>

@ -0,0 +1 @@
$("#managements_school_report").html("<%= j(render 'managements/schools/statistics_list') %>")

@ -720,6 +720,7 @@ RedmineApp::Application.routes.draw do ## oauth相关
post :add_customers
delete :delete_customers
get :customers_list
get :school_report, controller: 'managements::schools', action: 'statistics'
end
end
# Enable Grack support

@ -158,7 +158,8 @@ $(function(){
}
var new_href = href.replace(/page=(\d*)/, 'page=' + page);
console.log(new_href);
$.get(new_href);
// $.get(new_href);
$.ajax({url: new_href, dataType: 'script'})
return false;
}
}

Loading…
Cancel
Save