This commit is contained in:
huang 2015-06-26 10:04:48 +08:00
commit 5d0cd4520e
17 changed files with 389 additions and 41 deletions

View File

@ -247,7 +247,7 @@ module Mobile
end
get "course_dynamic/:id" do
cs = CoursesService.new
count = cs.course_dynamic(params,current_user)
count = cs.all_course_dynamics(params,current_user)
present :data, count, with: Mobile::Entities::CourseDynamic
present :status, 0
end

View File

@ -1,13 +1,18 @@
module Mobile
module Entities
class Attachment < Grape::Entity
include Redmine::I18n
def self.attachment_expose(field)
expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field)
f[field]
elsif f.is_a?(::Attachment)
if f.respond_to?(field)
f.send(field)
if field == :created_on
format_time(f.send(field))
else
f.send(field)
end
else
#case field
# when ""
@ -21,6 +26,7 @@ module Mobile
attachment_expose :description
attachment_expose :downloads
attachment_expose :quotes
attachment_expose :created_on
end
end
end

View File

@ -6,6 +6,62 @@ module Mobile
expose field do |c,opt|
if field == :update_time
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field)))
elsif field == :news_count
obj = nil
c[:dynamics].each do |d|
if d[:type] == 1
obj = d[:count]
end
end
obj
elsif field == :document_count
obj = nil
c[:dynamics].each do |d|
if d[:type] == 3
obj = d[:count]
end
end
obj
elsif field == :topic_count
obj = nil
c[:dynamics].each do |d|
if d[:type] == 2
obj = d[:count]
end
end
obj
elsif field == :homework_count
obj = nil
c[:dynamics].each do |d|
if d[:type] == 4
obj = d[:count]
end
end
obj
elsif field == :homework_submit_num
obj = nil
c[:dynamics].each do |d|
if d[:type] == 4
obj = d[:submit_count]
end
end
obj
elsif field == :homework_submit_students
obj = nil
c[:dynamics].each do |d|
if d[:type] == 4
obj = d[:studentlist]
end
end
obj
elsif field == :homework_status
obj = nil
c[:dynamics].each do |d|
if d[:type] == 4
obj = d[:homework_status]
end
end
obj
else
c[field] if (c.is_a?(Hash) && c.key?(field))
end
@ -21,6 +77,53 @@ module Mobile
course_dynamic_expose :course_img_url
course_dynamic_expose :message
course_dynamic_expose :update_time
course_dynamic_expose :count
course_dynamic_expose :news_count
course_dynamic_expose :document_count
course_dynamic_expose :topic_count
course_dynamic_expose :homework_count
course_dynamic_expose :homework_submit_students
course_dynamic_expose :homework_submit_num
course_dynamic_expose :homework_status
#在dynamics里解析出四种动态
expose :document,using:Mobile::Entities::Attachment do |f,opt|
obj = nil
f[:dynamics].each do |d|
if d[:type] == 3
obj = d[:documents]
end
end
obj
end
expose :topic,using:Mobile::Entities::Message do |f,opt|
obj = nil
f[:dynamics].each do |d|
if d[:type] == 2
obj = d[:topic]
end
end
obj
end
expose :homework,using:Mobile::Entities::Homework do |f,opt|
obj = nil
f[:dynamics].each do |d|
if d[:type] == 4
obj = d[:homework]
end
end
obj
end
expose :news,using:Mobile::Entities::News do |f,opt|
obj = nil
f[:dynamics].each do |d|
if d[:type] == 1
obj = d
end
end
obj
end
end
end
end

View File

@ -1,3 +1,4 @@
# 这个模块由于作业模块的改变,里边的注释以及属性不可信
module Mobile
module Entities
class Homework < Grape::Entity
@ -14,7 +15,12 @@ module Mobile
if f.respond_to?(field)
f.send(field)
else
case field
when :homework_name
f.send(:name)
when :homework_notsubmit_num
f.course.members.count - f.student_works.count
end
end
end
end
@ -60,6 +66,12 @@ module Mobile
f[:homework_for_anonymous_comments] if f.is_a?(Hash) && f.key?(:homework_for_anonymous_comments)
end
homework_expose :homework_notsubmit_num
expose :submit_student_list ,using:Mobile::Entities::User do |f,opt|
f[:studentlist]
end
end
end
end

View File

@ -0,0 +1,46 @@
module Mobile
module Entities
class Message < Grape::Entity
include ApplicationHelper
include ApiHelper
def self.message_expose(f)
expose f do |u,opt|
if u.is_a?(Hash) && u.key?(f)
u[f]
elsif u.is_a?(::Message)
if u.respond_to?(f)
if f == :created_on
format_time( u.send(f))
else
u.send(f)
end
else
# case f
# when :xx
# #
# end
end
end
end
end
expose :user, using: Mobile::Entities::User do |c, opt|
if c.is_a?(::Message)
c.author
end
end
message_expose :board_id
message_expose :subject
message_expose :content
message_expose :replies_count
message_expose :created_on
message_expose :id
expose :message_children,using:Mobile::Entities::Message do |c,opt|
if c.is_a? (::Message)
c.children
end
end
end
end
end

View File

@ -37,6 +37,14 @@ class MessagesController < ApplicationController
# Show a topic and its replies
def show
if @course
topic_id = params[:r]?params[:r]:params[:id]
parent_id = params[:id]
url = course_boards_path(@course,:topic_id => topic_id,:parent_id=>parent_id);
redirect_to url
return;
end
@isReply = true
page = params[:page]
# Find the page of the requested reply

View File

@ -245,15 +245,19 @@ class StudentWorkController < ApplicationController
def student_work_absence_penalty
render_403 unless User.current.allowed_to?(:as_teacher,@course)
order = params[:order] || "desc"
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
@stundet_works = StudentWork.find_by_sql("SELECT *,(all_count - has_count) AS absence FROM(
if @homework.student_works.empty?
@stundet_works = []
else
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
@stundet_works = StudentWork.find_by_sql("SELECT *,(all_count - has_count) AS absence FROM(
SELECT * ,
(SELECT COUNT(*) FROM `student_works_evaluation_distributions` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS all_count,
(SELECT COUNT(*) FROM `student_works_scores` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS has_count
FROM `student_works`
WHERE homework_common_id = #{@homework.id}
) AS table_1
ORDER BY absence #{order}")
) AS table_1
ORDER BY absence #{order}")
end
@order = order == "desc" ? "asc" : "desc"
respond_to do |format|
format.html

View File

@ -330,7 +330,7 @@ class CoursesService
def homework_list params,current_user
course = Course.find(params[:id])
if course.is_public != 0 || current_user.member_of_course?(course)
bids = course.homework_commons.order('end_time DESC')
bids = course.homework_commons.page(1).per(3).order('end_time DESC')
bids = bids.like(params[:name]) if params[:name].present?
homeworks = []
bids.each do |bid|
@ -540,14 +540,35 @@ class CoursesService
#student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count
description = bid.description
#if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2
state = bid.homework_detail_manual.comment_status
#state = bid.homework_detail_manual.comment_status
if !bid.nil?
if bid.homework_type == 1 && bid.homework_detail_manual
case bid.homework_detail_manual.comment_status
when 1
state = show_homework_deadline bid
when 2
state = "正在匿评中"
when 3
state = "匿评已结束"
end
elsif bid.homework_type == 0
state = "未启用匿评"
elsif bid.homework_type == 2
state = "编程作业"
else
end
end
studentlist = []
bid.student_works.order("created_at desc").page(1).per(6).each do |work|
studentlist << work.user
end
unless is_course_teacher
homework_for_anonymous_comments = get_student_batch_homework_list bid,current_user
end
#end
open_anonymous_evaluation = bid.homework_detail_manual.comment_status
{:course_name => course.name,:course_id => course.id,:id => bid.id, :author => bid.user,:author_real_name => author_real_name, :homework_times => many_times, :homework_name => name, :homework_count => homework_count,:student_questions_count => 0,
:description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation,:homework_for_anonymous_comments => homework_for_anonymous_comments,:created_on => bid.created_at,:deadline => bid.end_time}
:description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation,:homework_for_anonymous_comments => homework_for_anonymous_comments,:created_on => bid.created_at,:deadline => bid.end_time,:studentlist => studentlist}
end
@ -615,9 +636,103 @@ class CoursesService
homework_scores
end
#app新版api
#
#
#课程动态
public
def all_course_dynamics params, current_user
#获取当前用户的所有课程
@user = User.find(params[:id])
if current_user.nil? && !current_user.admin? && !@user.active?
raise '404'
return
end
if current_user == @user || current_user.admin?
membership = @user.coursememberships.page(1).per(10)
else
membership = @user.coursememberships.page(1).per(10).all(:conditions => Course.visible_condition(current_user))
end
if membership.nil? || membership.count == 0
raise l(:label_no_courses, :locale => get_user_language(current_user))
end
membership.sort! { |older, newer| newer.created_on <=> older.created_on }
#定义一个数组集合存放hash数组该hash数组包括课程的信息并包含课程的最新发布的资源最新的讨论区留言最新的作业最新的通知
result = []
#对用户所有的课程进行循环,找到每个课程最新发布的资源,最新的讨论区留言,最新的作业,最新的通知,并存进数组
membership.each do |mp|
course = mp.course
latest_course_dynamics = []
dynamics_count = 0
# 课程通知
latest_news = course.news.order("created_on desc").first
unless latest_news.nil?
latest_course_dynamics << {:type => 1, :time => latest_news.created_on,:count=>course.news.count,
:news => latest_news}
dynamics_count += 1
end
# 课程讨论区
latest_message = course.boards.first.topics[0]
unless latest_message.nil?
latest_course_dynamics << {:type => 2, :time => latest_message.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count,
:topic => latest_message}
dynamics_count += 1
end
# 课程资源
latest_attachment = course.attachments.order("created_on desc").first
unless latest_attachment.nil?
latest_course_dynamics << {:type => 3, :time => latest_attachment.created_on,:count =>course.attachments.count , :documents=>latest_attachment}
dynamics_count += 1
end
#课程作业 已经交的学生列表暂定显示6人未交的学生列表作业的状态
homework = course.homework_commons.order('created_at desc').first
homework_status = "";
# 判断作业所处的状态,如果是刚发布,就获取剩余时间
#如果是匿评状态,显示正在匿评
#如果是匿评结束,显示匿评结束
#获取作业提交的前6个人不足6个显示所有
studentlist = []
if !homework.nil?
if homework.homework_type == 1 && homework.homework_detail_manual
case homework.homework_detail_manual.comment_status
when 1
homework_status = show_homework_deadline homework
when 2
homework_status = "正在匿评中"
when 3
homework_status = "匿评已结束"
end
elsif homework.homework_type == 0
homework_status = "未启用匿评"
elsif homework.homework_type == 2
homework_status = "编程作业"
else
end
# 获取提交作业的前六个学生的名字 和 头像路径
homework.student_works.order("created_at desc").page(1).per(6).each do |work|
studentlist << {:image_url=> url_to_avatar(work.user),:user_name=>work.user.realname}
end
latest_course_dynamics << {:type => 4, :time => homework.updated_at, :count=>course.homework_commons.count,:submit_count => homework.student_works.count , :homework => homework, :homework_status => homework_status, :studentlist => studentlist}
dynamics_count += 1
end
latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] }
latest_course_dynamic = latest_course_dynamics.first
unless latest_course_dynamic.nil?
result << {:course_name => course.name, :course_id => course.id, :course_img_url => url_to_avatar(course), :course_time => course.time, :course_term => course.term,:message => dynamics_count, :dynamics => latest_course_dynamics, :count => dynamics_count}
end
end
#返回数组集合
result.sort! { |order, newer| newer[:update_time] <=> order[:update_time] }
result
end
#计算作业的截止日期,剩余日期
def show_homework_deadline homework
"距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << ""
end
end
end

View File

@ -70,31 +70,41 @@
//解决由于图片加载慢造成div高度不够 以至于展开按钮不显示的bug
$(function(){
function nh_show_btn(){
if($("#contentmessage<%=topic.id %>").height()>182){
$("#project_show_<%= topic.id%>").show();
if($("#project_show_<%= topic.id%>").is(':hidden')){
if($("#contentmessage<%=topic.id %>").height()>182){
$("#project_show_<%= topic.id%>").show();
}
}
}
var div = $("#contentmessage<%=topic.id %>");
var imgs = $('img',div);
var lens = imgs.length;
function nh_load_img_end(){
lens--;
if(lens <= 0){
nh_show_btn();
}
}
if(lens <= 0){
nh_show_btn();
}else{
// lens--;
// if(lens <= 0){
// nh_show_btn();
// }
}
if(lens > 0){
$('img',div).load(function(){
nh_load_img_end();
});
}
nh_show_btn();
// if(lens <= 0){
// nh_show_btn();
// }else{
// $('img',div).load(function(){
// nh_load_img_end();
// });
// }
});
</script>
<div class="project_board_content break_word" id="content_<%=topic.id%>">
<div id="contentmessage<%=topic.id %>" class="upload_img">
<%= topic.content.html_safe %>
<!-- -->
</div>
</div>
@ -157,7 +167,10 @@
<div class="Msg_txt">
<%= link_to_user_header message.author,false,:class => 'fl c_orange ' %>
<br/>
<div class="fl break_word"><%= textAreailizable message,:content,:attachments => message.attachments %></div>
<div class="fl break_word">
<%= textAreailizable message,:content,:attachments => message.attachments %>
<!-- -->
</div>
<input nhname="nh_content_val" value="<%= message.content %>" type="hidden"/>
<br/><div class="cl"></div>
<span class=" c_grey fl"><%= format_time(message.created_on) %></span>

View File

@ -62,26 +62,35 @@
//解决由于图片加载慢造成div高度不够 以至于展开按钮不显示的bug
$(function(){
function nh_show_btn(){
if($("#contentmessage<%=topic.id %>").height()>182){
$("#project_show_<%= topic.id%>").show();
if($("#project_show_<%= topic.id%>").is(':hidden')){
if($("#contentmessage<%=topic.id %>").height()>182){
$("#project_show_<%= topic.id%>").show();
}
}
}
var div = $("#contentmessage<%=topic.id %>");
var imgs = $('img',div);
var lens = imgs.length;
function nh_load_img_end(){
lens--;
if(lens <= 0){
nh_show_btn();
}
}
if(lens <= 0){
nh_show_btn();
}else{
// lens--;
// if(lens <= 0){
// nh_show_btn();
// }
}
if(lens > 0){
$('img',div).load(function(){
nh_load_img_end();
});
}
nh_show_btn();
// if(lens <= 0){
// nh_show_btn();
// }else{
// $('img',div).load(function(){
// nh_load_img_end();
// });
// }
});
</script>
</div>
@ -89,6 +98,7 @@
<div class="project_board_content break_word" id="content_<%=topic.id%>">
<div id="contentmessage<%=topic.id %>" class="upload_img">
<%= topic.content.html_safe %>
<!-- -->
</div>
</div>
<p style="display: none;" id="project_show_<%= topic.id%>">
@ -144,7 +154,10 @@
<div class="Msg_txt">
<%= link_to_user_header message.author,false,:class => 'fl c_orange ' %>
<br/>
<div class="fl break_word"><%= textAreailizable message,:content,:attachments => message.attachments %></div>
<div class="fl break_word">
<%= textAreailizable message,:content,:attachments => message.attachments %>
<!-- -->
</div>
<input nhname="nh_content_val" type="hidden" value="<%= message.content %>"/>
<br/><div class="cl"></div>
<span class=" c_grey fl"><%= format_time(message.created_on) %></span>

View File

@ -3,3 +3,15 @@
<% elsif @course %>
<%= render :partial => 'course_show', locals: {course: @course} %>
<% end %>
<script type="text/javascript">
$(function(){
$("#add_comment_form").submit(function(){
if($("#comment").val() == ''){
alert('请输入评论内容');
return false;
}
$(this)[0].submit();
//return true;
});
})
</script>

View File

@ -36,7 +36,7 @@
<% if @show_all%>
<input type="text" value="<%= @name%>" placeholder="昵称、学号、姓名搜索" class="min_search ml10 fl" onkeypress="SearchByName($(this),'<%= student_work_index_path(:homework => @homework.id)%>',event);">
<a class="student_work_search fl" onclick="SearchByName_1($(this).prev(),'<%= student_work_index_path(:homework => @homework.id)%>');" href="javascript:void(0)">搜索</a>
<%= link_to "缺评情况",student_work_absence_penalty_student_work_index_path(:homework => @homework.id), :class => "student_work_search fl", :target => "_blank" if @is_teacher%>
<%= link_to "缺评情况",student_work_absence_penalty_student_work_index_path(:homework => @homework.id), :class => "student_work_search fl", :target => "_blank" if @is_teacher && @homework.homework_type == 1 && @homework.homework_detail_manual.comment_status != 1 %>
<% end%>
<% if @is_teacher%>
<div class="fr">

View File

@ -1,6 +1,9 @@
<style type="text/css">
p.lablewidth>label{width:190px;}
</style>
<%= labelled_fields_for :pref, @user.pref do |pref_fields| %>
<p><%= pref_fields.check_box :hide_mail %></p>
<p style="width:520px;"><%= pref_fields.time_zone_select :time_zone, nil, :include_blank => true %></p>
<p style="width:477px;"><%= pref_fields.select :comments_sorting, [[l(:label_chronological_order), 'asc'], [l(:label_reverse_chronological_order), 'desc']] %></p>
<p class="lablewidth"><%= pref_fields.check_box :hide_mail %></p>
<p class="lablewidth" style="width:520px;"><%= pref_fields.time_zone_select :time_zone, nil, :include_blank => true %></p>
<p class="lablewidth" style="width:477px;"><%= pref_fields.select :comments_sorting, [[l(:label_chronological_order), 'asc'], [l(:label_reverse_chronological_order), 'desc']] %></p>
<% end %>

View File

@ -10,7 +10,6 @@ class HomeworkCommonTime < ActiveRecord::Migration
end
end
end
puts i.to_s
end
end

View File

@ -721,6 +721,16 @@ ActiveRecord::Schema.define(:version => 20150619060110) do
add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id"
create_table "journal_details_copy", :force => true do |t|
t.integer "journal_id", :default => 0, :null => false
t.string "property", :limit => 30, :default => "", :null => false
t.string "prop_key", :limit => 30, :default => "", :null => false
t.text "old_value"
t.text "value"
end
add_index "journal_details_copy", ["journal_id"], :name => "journal_details_journal_id"
create_table "journal_replies", :id => false, :force => true do |t|
t.integer "journal_id"
t.integer "user_id"

View File

@ -863,6 +863,10 @@ function redo() {
window.location.reload()
}
function encodeHomeworkUrl(url){
var file = encodeURI(url).replace(/\+/g, '%2B');
return '/zipdown/download?file='+file;
}
//// 作业附件删除
$(function(){
@ -880,7 +884,7 @@ $(function(){
}
if(res.length==1){
location.href = '/zipdown/download?file='+res[0].file;return;
location.href = encodeHomeworkUrl(res[0].file);return;
}
document.getElementById('light').style.display='block';
@ -893,7 +897,7 @@ $(function(){
} else {
des = '第'+res[i].index+'个学生的作品下载';
}
$('<li><span class="upload_box_span" >'+(i+1)+'.</span> <a href="/zipdown/download?file='+res[i].file+'">'+des+'</a><span class="c_grey">&nbsp;&nbsp;(共'+res[i].size+'M</span> </li>').appendTo($container);
$('<li><span class="upload_box_span" >'+(i+1)+'.</span> <a href="'+ encodeHomeworkUrl(res[i].file) +'">'+des+'</a><span class="c_grey">&nbsp;&nbsp;(共'+res[i].size+'M</span> </li>').appendTo($container);
}
}
@ -910,7 +914,7 @@ $(function(){
else
{
if(res.length==1){
location.href = '/zipdown/download?file='+res[0].file;return;
location.href = encodeHomeworkUrl(res[0].file);return;
}
document.getElementById('light').style.display='block';
$container = $('#light .upload_box_ul');
@ -922,7 +926,7 @@ $(function(){
} else {
des = '第'+res[i].index+'个学生的作品下载';
}
$('<li><span class="upload_box_span" >'+(i+1)+'.</span> <a href="/zipdown/download?file='+res[i].file+'">'+des+'</a><span class="c_grey">&nbsp;&nbsp;(共'+res[i].size+'M</span> </li>').appendTo($container);
$('<li><span class="upload_box_span" >'+(i+1)+'.</span> <a href="'+ encodeHomeworkUrl(res[i].file) +'">'+des+'</a><span class="c_grey">&nbsp;&nbsp;(共'+res[i].size+'M</span> </li>').appendTo($container);
}
}

View File

@ -439,7 +439,7 @@ a.box_close{background:url(../images/img_floatbox.png) -22px 0 no-repeat;}
/*文本左对齐*/
.tl{text-align: left;}
img{max-width: 100%;}
img,embed{max-width: 100%;}
.attachments {clear: both;}
.is_public_checkbox{margin-left: 15px;margin-right: 10px;}
.author_name{color: #3ca5c6 !important;}