Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
This commit is contained in:
commit
098b8094b1
2
Gemfile
2
Gemfile
|
@ -16,6 +16,8 @@ gem "coderay", "~> 1.0.6"
|
|||
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
|
||||
gem "builder", "3.0.0"
|
||||
gem 'acts-as-taggable-on', '2.4.1'
|
||||
gem 'spreadsheet'
|
||||
gem 'ruby-ole'
|
||||
|
||||
group :development do
|
||||
gem 'better_errors', path: 'lib/better_errors'
|
||||
|
|
|
@ -192,6 +192,7 @@ GEM
|
|||
rails (>= 3.2.0)
|
||||
sass-rails
|
||||
rmagick (2.13.2)
|
||||
ruby-ole (1.2.11.7)
|
||||
ruby-openid (2.1.8)
|
||||
rubyzip (1.1.6)
|
||||
sass (3.3.10)
|
||||
|
@ -214,6 +215,8 @@ GEM
|
|||
spork (0.9.2)
|
||||
spork-testunit (0.0.8)
|
||||
spork (>= 0.6.0)
|
||||
spreadsheet (1.0.0)
|
||||
ruby-ole (>= 1.0)
|
||||
sprockets (2.2.2)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
|
@ -272,11 +275,13 @@ DEPENDENCIES
|
|||
rails (= 3.2.13)
|
||||
rich (= 1.4.6)
|
||||
rmagick (>= 2.0.0)
|
||||
ruby-ole
|
||||
ruby-openid (~> 2.1.4)
|
||||
sass-rails (~> 3.2.3)
|
||||
seems_rateable!
|
||||
selenium-webdriver (~> 2.42.0)
|
||||
shoulda (~> 3.5.0)
|
||||
spork-testunit (~> 0.0.8)
|
||||
spreadsheet
|
||||
therubyracer
|
||||
uglifier (>= 1.0.3)
|
||||
|
|
|
@ -498,6 +498,7 @@ class BidsController < ApplicationController
|
|||
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score
|
||||
FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1
|
||||
WHERE table1.t_score IS NULL")
|
||||
@not_batch_homework = true
|
||||
@cur_type = 1
|
||||
else
|
||||
all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*,
|
||||
|
|
|
@ -21,6 +21,7 @@ class HomeworkAttachController < ApplicationController
|
|||
|
||||
#获取未批作业列表
|
||||
def get_not_batch_homework
|
||||
@not_batch_homework = true
|
||||
sort, direction = params[:sort] || "s_socre", params[:direction] || "desc"
|
||||
get_not_batch_homework_list sort,direction, @bid.id
|
||||
@cur_page = params[:page] || 1
|
||||
|
@ -28,12 +29,17 @@ class HomeworkAttachController < ApplicationController
|
|||
@direction = direction == 'asc'? 'desc' : 'asc'
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.xls {
|
||||
send_data(homework_to_xls(@all_homework_list), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "not_rated_homework_#{Time.now.strftime("%Y%m%d")}.xls")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
#获取已评作业列表
|
||||
def get_batch_homeworks
|
||||
sort, direction = params[:sort] || "s_socre", params[:direction] || "desc"
|
||||
@is_batch_homeworks = true
|
||||
if sort == 't_socre'
|
||||
order_by = "t_score #{direction}"
|
||||
elsif sort == 's_socre'
|
||||
|
@ -53,33 +59,18 @@ class HomeworkAttachController < ApplicationController
|
|||
@direction = direction == 'asc'? 'desc' : 'asc'
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.csv {
|
||||
send_data(homework_to_csv(all_homework_list), :type => 'text/csv; header=present', :filename => 'issues.csv')
|
||||
format.xls {
|
||||
send_data(homework_to_xls(all_homework_list), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "been_rated_homework_#{Time.now.strftime("%Y%m%d")}.xls")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def homework_to_csv items
|
||||
encoding = l(:general_csv_encoding)
|
||||
columns = ["student_id","user_name","login","student_num","mail","work_name","teacher_score","ni_score","commit_time"]
|
||||
|
||||
|
||||
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||
# csv header fields
|
||||
csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c, encoding) }
|
||||
# csv lines
|
||||
items.each do |homework|
|
||||
csv << [homework.user.id,Redmine::CodesetUtil.from_utf8(homework.user.lastname.to_s + homework.user.firstname.to_s, encoding),Redmine::CodesetUtil.from_utf8(homework.user.login, encoding),
|
||||
Redmine::CodesetUtil.from_utf8(homework.user.user_extensions.student_id, encoding),Redmine::CodesetUtil.from_utf8(homework.user.mail, encoding),Redmine::CodesetUtil.from_utf8(homework.name, encoding),
|
||||
Redmine::CodesetUtil.from_utf8((homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score), encoding),
|
||||
Redmine::CodesetUtil.from_utf8( homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score), encoding),Redmine::CodesetUtil.from_utf8(format_time(homework.created_at), encoding)]
|
||||
end
|
||||
end
|
||||
export
|
||||
end
|
||||
|
||||
#获取所有作业列表
|
||||
def get_homeworks
|
||||
@is_all_homeworks = true
|
||||
sort, direction = params[:sort] || "s_socre", params[:direction] || "desc"
|
||||
if sort == 't_socre'
|
||||
order_by = "t_score #{direction}"
|
||||
|
@ -99,6 +90,10 @@ class HomeworkAttachController < ApplicationController
|
|||
@direction = direction == 'asc'? 'desc' : 'asc'
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.xls {
|
||||
send_data(homework_to_xls(all_homework_list), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "all_homework_#{Time.now.strftime("%Y%m%d")}.xls")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -582,18 +577,65 @@ class HomeworkAttachController < ApplicationController
|
|||
elsif sort == 'time'
|
||||
order_by = "created_at #{direction}"
|
||||
end
|
||||
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
|
||||
@all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
|
||||
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score,
|
||||
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score
|
||||
FROM homework_attaches WHERE bid_id = #{bid_id}
|
||||
ORDER BY #{order_by}) AS table1
|
||||
WHERE table1.t_score IS NULL")
|
||||
@homework_list = paginateHelper all_homework_list,10
|
||||
@homework_list = paginateHelper @all_homework_list,10
|
||||
end
|
||||
|
||||
#获取指定作业的所有成员
|
||||
def users_for_homework homework
|
||||
homework.nil? ? [] : (homework.users + [homework.user])
|
||||
end
|
||||
|
||||
def homework_to_csv items
|
||||
encoding = l(:general_csv_encoding)
|
||||
columns = ["student_id","user_name","login","student_num","mail","work_name","teacher_score","ni_score","commit_time"]
|
||||
|
||||
|
||||
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||
# csv header fields
|
||||
csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c, encoding) }
|
||||
# csv lines
|
||||
items.each do |homework|
|
||||
csv << [homework.user.id,Redmine::CodesetUtil.from_utf8(homework.user.lastname.to_s + homework.user.firstname.to_s, encoding),Redmine::CodesetUtil.from_utf8(homework.user.login, encoding),
|
||||
Redmine::CodesetUtil.from_utf8(homework.user.user_extensions.student_id, encoding),Redmine::CodesetUtil.from_utf8(homework.user.mail, encoding),Redmine::CodesetUtil.from_utf8(homework.name, encoding),
|
||||
Redmine::CodesetUtil.from_utf8((homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score), encoding),
|
||||
Redmine::CodesetUtil.from_utf8( homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score), encoding),Redmine::CodesetUtil.from_utf8(format_time(homework.created_at), encoding)]
|
||||
end
|
||||
end
|
||||
export
|
||||
end
|
||||
|
||||
def homework_to_xls items
|
||||
xls_report = StringIO.new
|
||||
book = Spreadsheet::Workbook.new
|
||||
sheet1 = book.create_worksheet :name => "homework"
|
||||
|
||||
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
||||
sheet1.row(0).default_format = blue
|
||||
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),
|
||||
l(:excel_t_score),l(:excel_n_score),l(:excel_commit_time)])
|
||||
count_row = 1
|
||||
items.each do |homework|
|
||||
sheet1[count_row,0]=homework.user.id
|
||||
sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s
|
||||
sheet1[count_row,2] = homework.user.login
|
||||
sheet1[count_row,3] = homework.user.user_extensions.student_id
|
||||
sheet1[count_row,4] = homework.user.mail
|
||||
sheet1[count_row,5] = homework.name
|
||||
sheet1[count_row,6] =(homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score)
|
||||
sheet1[count_row,7] = homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score)
|
||||
sheet1[count_row,8] = format_time(homework.created_at)
|
||||
count_row += 1
|
||||
end
|
||||
|
||||
book.write xls_report
|
||||
xls_report.string
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
:locals => {:homeworks => @homework_list,
|
||||
:homework_count => @obj_count,
|
||||
:remote => false,
|
||||
:is_student_batch_homework => @is_student_batch_homework}%>
|
||||
:not_batch_homework => @not_batch_homework,:is_student_batch_homework => @is_student_batch_homework}%>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<% is_teacher = is_course_teacher(User.current,@bid.courses.first) %>
|
||||
<% is_my_homework ||= false %>
|
||||
<% is_student_batch_homework ||= false %>
|
||||
|
||||
<% is_batch_homeworks ||= false %>
|
||||
<% not_batch_homework ||= false %>
|
||||
<% is_all_homeworks ||= false %>
|
||||
<% unless is_my_homework || is_student_batch_homework %>
|
||||
<div class="code_list">
|
||||
<span>
|
||||
|
@ -9,7 +11,10 @@
|
|||
(<font color="#CC0000">
|
||||
<%= homework_count%>
|
||||
</font>)
|
||||
</span>
|
||||
<%= link_to l(:label_export_excel), get_batch_homeworks_homework_attach_index_path(:bid_id => @bid.id,:format => 'xls'),:class=>'xls' if is_batch_homeworks%>
|
||||
<%= link_to l(:label_export_excel), get_not_batch_homework_homework_attach_index_path(:bid_id => @bid.id,:format => 'xls'),:class=>'xls' if not_batch_homework%>
|
||||
<%= link_to l(:label_export_excel), get_homeworks_homework_attach_index_path(:bid_id => @bid.id,:format => 'xls'),:class=>'xls' if is_all_homeworks%>
|
||||
</span>
|
||||
<span class="fr">
|
||||
按
|
||||
<%= link_to l(:label_anonymous_comments), sort_homework_path(@bid, 's_socre', @direction), {:remote => true}%>
|
||||
|
@ -63,10 +68,4 @@
|
|||
<span style="color: red;">
|
||||
<%= anonymous_comment_notice(@bid, @bid.courses.first) %>
|
||||
</span>
|
||||
<% other_formats_links do |f| %>
|
||||
<%= f.link_to 'CSV', :url => params %>
|
||||
<% end %>
|
||||
<!--<div>
|
||||
导出 <a>csv</a>
|
||||
</div> -->
|
||||
<% end %>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list',
|
||||
:locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true} )) %>');
|
||||
:locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true,:is_batch_homeworks => @is_batch_homeworks} )) %>');
|
||||
for(var i=1;i<=4;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
|
||||
$("#tb_2").removeClass().addClass("hovertab");
|
|
@ -1,5 +1,5 @@
|
|||
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list',
|
||||
:locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true} )) %>');
|
||||
:locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true,:is_all_homeworks => @is_all_homeworks} )) %>');
|
||||
for(var i=1;i<=4;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
|
||||
$("#tb_3").removeClass().addClass("hovertab");
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list',
|
||||
:locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true} )) %>');
|
||||
:locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true,:not_batch_homework => @not_batch_homework} )) %>');
|
||||
for(var i=1;i<=4;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
|
||||
$("#tb_1").removeClass().addClass("hovertab");
|
|
@ -1,4 +1,5 @@
|
|||
# Add new mime types for use in respond_to blocks:
|
||||
|
||||
Mime::SET << Mime::CSV unless Mime::SET.include?(Mime::CSV)
|
||||
Mime::Type.register "text/excel", :xls
|
||||
|
||||
|
|
|
@ -2090,6 +2090,16 @@ zh:
|
|||
label_contest_delete: 删除竞赛
|
||||
label_noawards_current: 暂未评奖
|
||||
|
||||
excel_user_id: 学生id
|
||||
excel_user_name: 用户名
|
||||
excel_nickname: 昵称
|
||||
excel_student_id: 学号
|
||||
excel_mail: 电子邮箱
|
||||
excel_homework_name: 作品名
|
||||
excel_t_score: 教师评分
|
||||
excel_n_score: 匿名评分
|
||||
excel_commit_time: 提交时间
|
||||
label_export_excel: 导出Excel
|
||||
|
||||
label_softapplication: 应用软件
|
||||
label_attending_contest: 参加竞赛
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
class CreateProForSearchMember < ActiveRecord::Migration
|
||||
def up
|
||||
sql_delete = ("DROP PROCEDURE IF EXISTS `member_score`;")
|
||||
sql = ("
|
||||
CREATE PROCEDURE `member_score`(IN courseid INT, IN groupid INT,IN start_from INT, IN nums INT, IN sort_by VARCHAR(10))
|
||||
BEGIN
|
||||
|
||||
|
||||
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS mems (
|
||||
id INT ,
|
||||
user_id INT,
|
||||
course_id INT,
|
||||
created_on DATETIME,
|
||||
course_group_id INT,
|
||||
score FLOAT DEFAULT 0
|
||||
);
|
||||
TRUNCATE TABLE mems;
|
||||
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS mem_home (
|
||||
id INT,
|
||||
user_id INT,
|
||||
course_id INT,
|
||||
created_on DATETIME,
|
||||
course_group_id INT,
|
||||
home_id INT,
|
||||
score FLOAT DEFAULT 0
|
||||
);
|
||||
TRUNCATE TABLE mem_home;
|
||||
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS t_scores (
|
||||
|
||||
home_id INT,
|
||||
score FLOAT
|
||||
);
|
||||
TRUNCATE TABLE t_scores;
|
||||
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS s_scores (
|
||||
|
||||
home_id INT,
|
||||
score FLOAT
|
||||
);
|
||||
TRUNCATE TABLE s_scores;
|
||||
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS scores (
|
||||
|
||||
user_id INT,
|
||||
score FLOAT
|
||||
);
|
||||
TRUNCATE TABLE scores;
|
||||
|
||||
|
||||
|
||||
INSERT INTO mems (id, user_id, course_id, created_on, course_group_id)
|
||||
(SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id
|
||||
FROM members,students_for_courses WHERE members.course_id = courseid
|
||||
AND members.course_id = students_for_courses.course_id AND members.user_id =students_for_courses.student_id);
|
||||
|
||||
INSERT INTO mem_home (id, user_id, course_id, created_on, course_group_id,home_id)
|
||||
(SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id, homework_attaches.id
|
||||
FROM members, homework_attaches WHERE course_id = courseid
|
||||
AND members.user_id = homework_attaches.user_id AND members.user_id IN (SELECT student_id FROM students_for_courses WHERE course_id = courseid)
|
||||
AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = courseid ));
|
||||
|
||||
INSERT INTO t_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars)
|
||||
FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home)
|
||||
AND is_teacher_score = 1
|
||||
GROUP BY rateable_id);
|
||||
|
||||
INSERT INTO s_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars)
|
||||
FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home)
|
||||
AND is_teacher_score = 0
|
||||
GROUP BY rateable_id) ;
|
||||
|
||||
UPDATE mem_home, t_scores SET mem_home.score = t_scores.score WHERE mem_home.home_id = t_scores.home_id ;
|
||||
|
||||
UPDATE mem_home, s_scores SET mem_home.score = s_scores.score WHERE mem_home.home_id = s_scores.home_id AND mem_home.score = 0;
|
||||
|
||||
INSERT INTO scores (user_id, score) (SELECT user_id, SUM(score) FROM mem_home GROUP BY user_id);
|
||||
UPDATE mems, scores SET mems.score = scores.score WHERE mems.user_id = scores.user_id;
|
||||
IF sort_by = '' OR sort_by = 'desc' THEN
|
||||
IF groupid <> 0 THEN
|
||||
SELECT * FROM mems WHERE course_group_id = groupid ORDER BY score DESC;
|
||||
ELSE
|
||||
IF nums <> 0 THEN
|
||||
SELECT * FROM mems ORDER BY score DESC LIMIT start_from, nums;
|
||||
ELSE
|
||||
SELECT * FROM mems ORDER BY score DESC;
|
||||
end IF;
|
||||
END if;
|
||||
ELSE
|
||||
IF groupid <> 0 THEN
|
||||
SELECT * FROM mems WHERE course_group_id = groupid ORDER BY score ASC ;
|
||||
ELSE
|
||||
IF nums <> 0 THEN
|
||||
SELECT * FROM mems ORDER BY score ASC LIMIT start_from, nums;
|
||||
ELSE
|
||||
SELECT * FROM mems ORDER BY score ASC;
|
||||
end IF;
|
||||
END IF;
|
||||
END IF;
|
||||
END;
|
||||
")
|
||||
execute(sql_delete)
|
||||
execute(sql)
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20141230034253) do
|
||||
ActiveRecord::Schema.define(:version => 20141230062844) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
|
@ -1431,3 +1431,11 @@ ul.contest-notification-list li span{
|
|||
.softapplications-div table td{
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
a.xls {
|
||||
background: url('../images/icon_excel.gif') no-repeat scroll 1px 50% transparent;
|
||||
padding: 2px 0px 3px 16px;
|
||||
font-family:微软雅黑 !important;
|
||||
font-size: 12px !important;
|
||||
color: #136b3b !important;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ ul,li{ list-style-type:none}
|
|||
.cl{ clear:both; overflow:hidden; }
|
||||
#resource a{ text-decoration:none; text-align:center; }
|
||||
a:hover{ text-decoration:underline;}
|
||||
|
||||
/**** 常用***/
|
||||
.f_l{ float:left;}
|
||||
.f_r{ float:right;}
|
||||
|
|
Loading…
Reference in New Issue