Merge branch 'cxt_course' into develop

Conflicts:
	db/schema.rb
This commit is contained in:
cxt 2016-04-29 15:58:05 +08:00
commit 341927506a
17 changed files with 243 additions and 24 deletions

View File

@ -288,6 +288,27 @@ class UsersController < ApplicationController
end
end
#处理引用作业的请求
#status 1 同意 2 拒绝
def dealwith_apply_homework
@msg = CourseMessage.find(params[:msg_id])
case params[:agree]
when 'Y'
ah = ApplyHomework.where("user_id = ? and homework_common_id = ?",@msg.apply_user_id, @msg.course_message_id)
unless ah.empty?
ah.first.update_column('status', 2)
CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>5,:apply_result=>1)
@msg.update_attributes(:apply_result=>1,:viewed=>1)
end
when 'N'
CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>5,:apply_result=>2)
@msg.update_attributes(:apply_result=>2,:viewed=>1)
end
respond_to do |format|
format.js
end
end
# added by bai
def show_score
@ -372,13 +393,38 @@ class UsersController < ApplicationController
end
# end
#申请引用非公开作业
def apply_for_homework
if User.current.logged?
homework = HomeworkCommon.find params[:homework_id]
unless homework.nil?
ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework_id].to_i)
if ah.empty?
ApplyHomework.create(:user_id => params[:id].to_i, :homework_common_id => params[:homework_id].to_i, :status => 1)
Mailer.run.apply_for_homework_request(homework, User.current)
CourseMessage.create(:user_id => homework.user_id, :course_id => homework.course.id, :viewed => false,:course_message_id=>params[:homework_id].to_i,:course_message_type=>'HomeworkCommon',:status=>5,:apply_user_id=>params[:id].to_i)
@state = 2
@ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", params[:id].to_i, params[:homework_id].to_i).first
@homework = homework
else
@state = 3
end
end
else
@state = 1
end
respond_to do |format|
format.js
end
end
#用户作业列表
def user_homeworks
@order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
@user = User.current
@r_sort = @b_sort == "desc" ? "asc" : "desc"
if(params[:type].blank? || params[:type] == "1") #公共题库
visible_course = Course.where("is_public = 1 && is_delete = 0")
if(params[:type].blank? || params[:type] == "1") #题库
visible_course = Course.where("is_delete = 0")
visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
elsif params[:type] == "2" #我的题库
@ -424,6 +470,14 @@ class UsersController < ApplicationController
def choose_user_course
homework = HomeworkCommon.find params[:send_id].to_i
if homework.course.is_public == 0 && homework.user_id != User.current.id
ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:send_id].to_i)
if ah.empty?
@status = 2
elsif ah.first.status == 1
@status = 1
end
end
if !params[:search].nil?
search = "%#{params[:search].to_s.strip.downcase}%"
@course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id} and #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)}
@ -528,12 +582,18 @@ class UsersController < ApplicationController
@order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
@r_sort = @b_sort == "desc" ? "asc" : "desc"
@user = User.current
if(params[:type].blank? || params[:type] == "1") #公共题库
visible_course = Course.where("is_public = 1 && is_delete = 0")
if(params[:type].blank? || params[:type] == "1") #题库
visible_course = Course.where("is_delete = 0")
visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
elsif params[:type] == "2" #我的题库
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
elsif params[:type] == "3" #申请题库
#apply_homeworks = ApplyHomework.where("user_id = ?",@user.id)
#homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")"
#@homeworks = HomeworkCommon.where("id in #{homework_ids}")
sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN apply_homeworks as ah ON homework_commons.id = ah.homework_common_id where ah.user_id = #{@user.id} order by ah.created_at desc"
@homeworks = HomeworkCommon.find_by_sql(sql)
end
if params[:property] && params[:property] == "1"
@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}")
@ -571,8 +631,8 @@ class UsersController < ApplicationController
@user = User.current
search = params[:name].to_s.strip.downcase
type_ids = params[:property]=="" || params[:property].nil? ? "(1, 2, 3)" : "(" + params[:property] + ")"
if(params[:type].blank? || params[:type] == "1") #全部
visible_course = Course.where("is_public = 1 && is_delete = 0")
if(params[:type].blank? || params[:type] == "1") #全部
visible_course = Course.where("is_delete = 0")
visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
all_homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'")
all_user_ids = all_homeworks.map{|hw| hw.user_id}
@ -586,7 +646,7 @@ class UsersController < ApplicationController
else
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}")
end
elsif params[:type] == "2" #课程资源
elsif params[:type] == "2" #我的题库
if @order == "course_name"
sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
@homeworks = HomeworkCommon.find_by_sql(sql)
@ -595,6 +655,17 @@ class UsersController < ApplicationController
else
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}")
end
elsif params[:type] == "3" #申请题库
apply_homeworks = ApplyHomework.where("user_id = ?",@user.id)
homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")"
if @order == "course_name"
sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.id in #{homework_ids} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
@homeworks = HomeworkCommon.find_by_sql(sql)
elsif @order == "user_name"
@homeworks = HomeworkCommon.where("homework_commons.id in #{homework_ids} and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
else
@homeworks = HomeworkCommon.where("id in #{homework_ids} and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}")
end
end
=begin
if params[:property] && params[:property] == "1"

View File

@ -0,0 +1,6 @@
class ApplyHomework < ActiveRecord::Base
#status1. 待审核 2.审核通过
belongs_to :user
belongs_to :homework_common
attr_accessible :status, :user_id, :homework_common_id
end

View File

@ -1,8 +1,9 @@
class CourseMessage < ActiveRecord::Base
# status说明 status在课程不同的类型区分不同的功能 status = 9 作品的提交记录
# HomeworkCommonstatus
# nil发布了作业 1作业截止时间到了提醒2:开启匿评; 3关闭匿评 4匿评开始失败
attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status
# nil发布了作业 1作业截止时间到了提醒2:开启匿评; 3关闭匿评 4匿评开始失败 5申请引用作业
# apply_user_id: 申请者的用户id
attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status, :apply_user_id, :apply_result
# 多态 虚拟关联
belongs_to :course_message ,:polymorphic => true

View File

@ -1041,7 +1041,13 @@ class Mailer < ActionMailer::Base
:subject => @subject
end
def apply_for_homework_request(homework, user)
@receive = User.find(homework.user_id)
@user = user
@subject = "#{@user.show_name} #{l(:label_apply_for_homework)} #{homework.name} "
mail :to => @receive.mail,
:subject => @subject
end
private

View File

@ -19,7 +19,9 @@
<input type="radio" name="checkMenu" class="mr5 subject-name-middle" value="<%= homework.id%>"/>
<span title="<%= homework.name%>" class="subject-name-middle subject-name-hidden"><%= homework.name%></span>
</label>
<img src="/images/locked.png" width="16" height="16" alt="私有" title="私有" class="subject-name-middle" />
<% if homework.course.is_public == 0 %>
<img src="/images/locked.png" width="16" height="16" alt="私有" title="私有" class="subject-name-middle" />
<% end %>
</li>
<li class="subject-list-from fl hidden"><span title="<%=homework.course.name %>(<%=current_time_and_term(homework.course) %>)"><%=homework.course.name %>(<%=current_time_and_term_short(homework.course) %>)</span></li>
<li class="subject-list-type fl">
@ -35,7 +37,20 @@
<li class="subject-list-publisher fl hidden"><%= homework.user.show_name %></li>
<li class="subject-list-count fl" id="subject_count_homework_<%=homework.id %>"><%= homework.quotes %></li>
<li class="fl subject-list-date"><%=format_date homework.publish_time %></li>
<li class="fl subject-list-option"><a href="javascript:void(0);">提交申请</a></li>
<% if homework.course.is_public == 0 && homework.user_id != User.current.id %>
<li class="fl subject-list-option" id="homework_apply_status_<%=homework.id %>">
<% ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, homework.id).first %>
<% if ah.nil? %>
<%= link_to("提交申请", apply_for_homework_user_path(User.current.id,:homework_id => homework.id), :remote => true) %>
<% elsif ah.status == 1 %>
待审核
<% elsif ah.status == 2 %>
可引用
<% end %>
</li>
<% else %>
<li class="fl subject-list-option" id="homework_apply_status_<%=homework.id %>"><a href="javascript:void(0);">--</a></li>
<% end %>
</ul>
<% end %>
</div>

View File

@ -229,7 +229,36 @@
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>
<% if ma.course_message_type == "HomeworkCommon" && ma.status == 5 %>
<ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><div class="navHomepageLogo fl"><%= image_tag("/images/trustie_logo1.png", width: "30px", height: "30px", class: "mt3") %></div></a></li>
<li class="homepageNewsPubType fl">
<span class="newsBlue homepageNewsPublisher">系统提示</span>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">您有了新的引用作业申请:</span>
</li>
<li class="homepageHomeworkContent fl"><a href="javascript:void(0);" class="newsGrey">
<span title="<%=User.find(ma.apply_user_id).show_name+"申请引用作业\""+"#{HomeworkCommon.find(ma.course_message_id).name}"+"\"" %>" class ='#{ma.viewed==0 ? "newsBlack" : "newsGrey"}'><%=User.find(ma.apply_user_id).show_name+"申请引用作业\""+"#{HomeworkCommon.find(ma.course_message_id).name}"+"\"" %></span>
<!--:onmouseover => "message_titile_show($(this),event)",-->
<!--:onmouseout => "message_titile_hide($(this))" %>-->
</a>
</li>
<li class="homepageHomeworkContentWarn fl">
<span id="deal_info_<%=ma.id%>">
<% if ma.apply_result == 0 || ma.apply_result.nil?%>
<%= link_to '同意',dealwith_apply_homework_user_path(User.current,:agree=>'Y',:msg_id=>ma.id),:remote=>'true'%>
|
<%= link_to '拒绝',dealwith_apply_homework_user_path(User.current,:agree=>'N',:msg_id=>ma.id),:remote=>'true'%>
<% elsif ma.apply_result == 1%> <!-- 同意 -->
您已经同意了该申请
<% elsif ma.apply_result == 2%> <!-- 拒绝 -->
您已经拒绝了该申请
<%end %>
</span>
</li>
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>
<% if ma.course_message_type == "Poll" %>
<ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %></a></li>

View File

@ -0,0 +1,8 @@
<% if @state == 1 %>
alert("您还未登录");
<% elsif @state == 2 %>
alert("申请成功,请等待审核");
$("#homework_apply_status_<%=@homework.id %>").html("待审核");
<% elsif @state == 3 %>
alert("您已经发送过申请了,请耐心等待");
<% end %>

View File

@ -1,11 +1,17 @@
<% if params[:is_observe].nil? %>
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/send_homework_to_course', :locals => {:courses => @course, :user => @user, :send_id => @send_id}) %>');
showModal('ajax-modal', '452px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 435px;' class='resourceClose'></a>");
$('#ajax-modal').parent().css("top","50%").css("left","50%");
$('#ajax-modal').parent().addClass("popbox").addClass("resourceUploadPopup");
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
<% if @status == 1 %>
alert("您的申请尚未通过审核,暂时不可发送至课程");
<% elsif @status == 2 %>
alert("该作业是私有的,请先提交申请并通过审核后再发送");
<% else %>
$("#send_homework_to_course_form").html("<%= escape_javascript(render :partial => 'users/send_homework_to_course_form', :locals => {:courses => @course, :user => @user, :send_id => @send_id}) %>");
<% if params[:is_observe].nil? %>
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/send_homework_to_course', :locals => {:courses => @course, :user => @user, :send_id => @send_id}) %>');
showModal('ajax-modal', '452px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 435px;' class='resourceClose'></a>");
$('#ajax-modal').parent().css("top","50%").css("left","50%");
$('#ajax-modal').parent().addClass("popbox").addClass("resourceUploadPopup");
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
<% else %>
$("#send_homework_to_course_form").html("<%= escape_javascript(render :partial => 'users/send_homework_to_course_form', :locals => {:courses => @course, :user => @user, :send_id => @send_id}) %>");
<% end %>
<% end %>

View File

@ -0,0 +1,11 @@
$("#deal_info_<%=@msg.id%>").html(
<% if @msg.apply_result == 0 || @msg.apply_result.nil?%>
<%= link_to '同意',dealwith_apply_request_user_path(User.current,:agree=>'Y',:msg_id=>@msg.id),:remote=>'true'%>
'|'
<%= link_to '拒绝',dealwith_apply_request_user_path(User.current,:agree=>'N',:msg_id=>@msg.id),:remote=>'true'%>
<% elsif @msg.apply_result == 1%>
'您已经同意了该申请'
<% elsif @msg.apply_result == 2%>
'您已经拒绝了该申请'
<%end %>
);

View File

@ -36,13 +36,13 @@
<div class="resource-wrapper">
<ul class="resource-banner">
<li class="fl resource-switch">
<a href="<%= user_homework_type_user_path(@user,:is_import => 0) %>" id="public_homeworks_choose" class="resource-tab resource-tab-active" data-remote="true">公共题库</a>
<a href="<%= user_homework_type_user_path(@user,:is_import => 0) %>" id="public_homeworks_choose" class="resource-tab resource-tab-active" data-remote="true">题库</a>
</li>
<li class="fl resource-switch">
<a href="<%= user_homework_type_user_path(@user,:type=>'2',:is_import => 0) %>" id="user_homeworks_choose" class="resource-tab" data-remote="true">我的题库</a>
</li>
<li class="fl resource-switch">
<a href="javascript:void(0);" class="resource-tab" data-remote="true">申请题库</a>
<a href="<%= user_homework_type_user_path(@user,:type=>'3',:is_import => 0) %>" id="apply_homeworks_choose" class="resource-tab" data-remote="true">申请题库</a>
</li>
<li class="fl w680 border-bottom h34">&nbsp;</li>
<li class="fr resource-banner-li border-bottom h34">

View File

@ -28,6 +28,7 @@ zh:
label_course_file: 资源库
label_upload_files: 上传资源
label_apply_join_course: 申请加入课程
label_apply_for_homework: 申请引用作业
#
# 课程托管平台主页
#

View File

@ -521,6 +521,7 @@ RedmineApp::Application.routes.draw do
match 'user_project_activities', :to => 'users#user_project_activities', :via => :get
match 'user_feedback4show', :to => 'users#user_feedback4show', :via => :get
match 'user_visitorlist', :to => 'users#user_visitorlist', :via => :get
match 'apply_for_homework', :to => 'users#apply_for_homework', :via => :get
match 'user_homeworks', :to => 'users#user_homeworks', :via => :get
match 'student_homeworks', :to => 'users#student_homeworks', :via => :get
get 'user_import_homeworks'
@ -583,6 +584,7 @@ RedmineApp::Application.routes.draw do
get 'user_ref_resource_search'
post 'import_resources_to_homework'
get 'dealwith_apply_request'
get 'dealwith_apply_homework'
get 'store_selected_resource'
get 'user_organizations'
get 'search_user_orgs'

View File

@ -0,0 +1,13 @@
class CreateApplyHomeworks < ActiveRecord::Migration
def change
create_table :apply_homeworks do |t|
t.integer :status
t.references :user
t.references :homework_common
t.timestamps
end
add_index :apply_homeworks, :user_id
add_index :apply_homeworks, :homework_common_id
end
end

View File

@ -0,0 +1,6 @@
class AddColumnToCourseMessages < ActiveRecord::Migration
def change
add_column :course_messages, :apply_user_id, :integer
add_column :course_messages, :apply_result, :integer
end
end

View File

@ -12,7 +12,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160427075457) do
ActiveRecord::Schema.define(:version => 20160429030819) do
@ -63,6 +63,17 @@ ActiveRecord::Schema.define(:version => 20160419074016) do
t.integer "user_id", :null => false
end
create_table "apply_homeworks", :force => true do |t|
t.integer "status"
t.integer "user_id"
t.integer "homework_common_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "apply_homeworks", ["homework_common_id"], :name => "index_apply_homeworks_on_homework_common_id"
add_index "apply_homeworks", ["user_id"], :name => "index_apply_homeworks_on_user_id"
create_table "apply_project_masters", :force => true do |t|
t.integer "user_id"
t.string "apply_type"
@ -482,6 +493,8 @@ ActiveRecord::Schema.define(:version => 20160419074016) do
t.datetime "updated_at", :null => false
t.string "content"
t.integer "status"
t.integer "apply_user_id"
t.integer "apply_result"
end
add_index "course_messages", ["course_message_type"], :name => "index_course_messages_on_course_message_type"
@ -1100,6 +1113,23 @@ ActiveRecord::Schema.define(:version => 20160419074016) do
t.integer "viewed_count", :default => 0
end
create_table "mess", :id => false, :force => true do |t|
t.string "课程名"
t.integer "课程ID", :default => 0, :null => false
t.string "教师姓", :default => "", :null => false
t.string "教师名", :limit => 30, :default => "", :null => false
t.string "主贴名", :default => "", :null => false
t.integer "主贴或回帖ID", :default => 0, :null => false
t.integer "回帖对应主贴ID"
t.integer "帖子点赞数"
t.integer "主贴回复数", :default => 0, :null => false
t.text "主贴或回帖内容"
t.datetime "发帖时间", :null => false
t.integer "发帖或回帖用户ID", :default => 0, :null => false
t.string "发帖或回帖用户姓", :default => "", :null => false
t.string "发帖或回帖用户名", :limit => 30, :default => "", :null => false
end
create_table "message_alls", :force => true do |t|
t.integer "user_id"
t.integer "message_id"

View File

@ -0,0 +1,9 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :apply_homework do
status 1
user nil
homework_common nil
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ApplyHomework, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end