Merge branch 'hjq_new_course' into develop

This commit is contained in:
huang 2015-12-11 11:02:09 +08:00
commit 35c918cb40
16 changed files with 146 additions and 71 deletions

View File

@ -25,6 +25,7 @@ class CoursesController < ApplicationController
before_filter :authorize_course, :only => [:show, :settings, :update, :course]
before_filter :authorize_course_global, :only => [:new,:create]
before_filter :toggleCourse, :only => [:finishcourse, :restartcourse]
before_filter :is_deleted, :only => [:show, :settings]
before_filter :require_login, :only => [:join, :unjoin]
#before_filter :allow_join, :only => [:join]
@ -55,11 +56,11 @@ class CoursesController < ApplicationController
def join
if User.current.logged?
cs = CoursesService.new
@user = User.current
join = cs.join_course params,@user
@state = join[:state]
@course = join[:course]
cs = CoursesService.new
@user = User.current
join = cs.join_course params,@user
@state = join[:state]
@course = join[:course]
# else
# @course = Course.find_by_id params[:object_id]
# CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest')
@ -70,7 +71,7 @@ class CoursesController < ApplicationController
end
@object_id = params[:object_id]
respond_to do |format|
format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} }
format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} }
end
end
@ -98,14 +99,14 @@ class CoursesController < ApplicationController
c = cs.edit_course params,@course,User.current
@course = c[:course]
if @course.errors.full_messages.count <= 0
respond_to do |format|
format.html {
# render :layout => 'base_courses'
flash[:notice] = l(:notice_successful_update)
redirect_to settings_course_url(@course)
}
format.api { render_api_ok }
end
respond_to do |format|
format.html {
# render :layout => 'base_courses'
flash[:notice] = l(:notice_successful_update)
redirect_to settings_course_url(@course)
}
format.api { render_api_ok }
end
else
respond_to do |format|
format.html {
@ -134,8 +135,8 @@ class CoursesController < ApplicationController
courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'").order("time desc, created_at desc")
@courses = paginateHelper courses,10
end
@name = params[:name]
@type = 'courses'
@name = params[:name]
@type = 'courses'
respond_to do |format|
format.html {
render :layout => 'course_base'
@ -427,7 +428,7 @@ class CoursesController < ApplicationController
end
def course
@school_id = params[:school_id]
@school_id = params[:school_id]
per_page_option = 10
if @school_id == "0" or @school_id.nil?
@courses_all = Course.active.visible.
@ -515,8 +516,8 @@ class CoursesController < ApplicationController
def index
if !User.current.admin?
render_404
return
render_404
return
end
@course_type = params[:course_type]
@school_id = params[:school_id]
@ -565,7 +566,7 @@ class CoursesController < ApplicationController
respond_to do |format|
format.html {
render :layout => 'base'
render :layout => 'base'
}
format.atom {
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
@ -581,6 +582,13 @@ class CoursesController < ApplicationController
end
end
def is_deleted
if @course.is_delete == 1 and !User.current.admin?
render_404
return
end
end
def get_courses
@user = User.current
membership = @user.coursememberships.all
@ -634,6 +642,11 @@ class CoursesController < ApplicationController
end
def show
# 被删除的课程只有超级管理员才能看到is_delete为1的时候标记课程被删除
# if @course.is_delete == 1 && !User.current.admin?
# render_403
# return
# end
#更新创建课程消息状态
create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0)
create_course_messages.update_all(:viewed => true)
@ -684,10 +697,10 @@ class CoursesController < ApplicationController
end
def feedback
@course.journals_for_messages.each do |messages|
query = messages.course_messages.where("user_id = ?", User.current.id)
query.update_all(:viewed => true);
end
@course.journals_for_messages.each do |messages|
query = messages.course_messages.where("user_id = ?", User.current.id)
query.update_all(:viewed => true);
end
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
page = params[:page]
@ -738,20 +751,20 @@ class CoursesController < ApplicationController
#从课程创建的老师那里选择课程大纲
def course_outline
@teacher = User.find(@course.tea_id)
@blog_articles = @teacher.blog.articles
@is_in_show_outline_page = params[:is_in_show_outline_page]
respond_to do |format|
format.js
end
@teacher = User.find(@course.tea_id)
@blog_articles = @teacher.blog.articles
@is_in_show_outline_page = params[:is_in_show_outline_page]
respond_to do |format|
format.js
end
end
#根据关键字搜索,查找方法一样的,但返回内容不一样
def search_course_outline
@article_title = params[:title]
@teacher = User.find(@course.tea_id)
@blog_articles = @teacher.blog.articles.like(@article_title)
render :json=>@blog_articles.to_json
@article_title = params[:title]
@teacher = User.find(@course.tea_id)
@blog_articles = @teacher.blog.articles.like(@article_title)
render :json=>@blog_articles.to_json
end
#设置或者更改课程的大纲
@ -771,10 +784,23 @@ class CoursesController < ApplicationController
format.html {render :layout => 'base_courses'}
end
end
#删除课程
#删除课程只是将课程的is_delete状态改为falseis_delete为false状态的课程只有管理员可以看到
def destroy
#删除课程
#删除课程只是将课程的is_deleted状态改为falseis_deleted为false状态的课程只有管理员可以看到
def destroy
@course.update_attributes(:is_delete => true)
@course = nil
redirect_to user_url(User.current)
end
# 恢复已删除的课程
def renew
if User.current.admin?
@course.update_attributes(:is_delete => false)
redirect_to course_path(@course)
else
return 404
end
end
private
@ -797,7 +823,7 @@ class CoursesController < ApplicationController
def can_show_course
@first_page = FirstPage.find_by_page_type('project')
if @first_page.try(:show_course) == 2
render_404
render_404
end
end

View File

@ -75,6 +75,9 @@ class RepositoriesController < ApplicationController
redirect_to repository_url(@repository)
else
g = Gitlab.client
if User.current.gid.nil?
g.sync_user(User.current)
end
gproject = g.fork(@project.gpid, User.current.gid)
if gproject
copy_project(@project, gproject)

View File

@ -20,7 +20,7 @@ class Course < ActiveRecord::Base
end
end
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete
#belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表
@ -86,7 +86,8 @@ class Course < ActiveRecord::Base
'is_public',
'description',
'class_period',
'open_student'
'open_student',
'is_delete'
acts_as_customizable
@ -94,7 +95,7 @@ class Course < ActiveRecord::Base
scope :active, lambda { where(:status => STATUS_ACTIVE) }
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
scope :all_public, lambda { where(:is_public => true) }
scope :visible, lambda {|*args| where(Course.visible_condition(args.shift || User.current, *args)) }
scope :visible, lambda {|*args| where(Course.where("is_delete =?", 0).visible_condition(args.shift || User.current, *args)) }
scope :allowed_to, lambda {|*args|
user = User.current
permission = nil
@ -114,7 +115,7 @@ class Course < ActiveRecord::Base
where(" LOWER(name) LIKE :p ", :p => pattern)
end
}
scope :indexable,lambda { where('is_public = 1') }
scope :indexable,lambda { where('is_public = 1 and is_delete = 0') }
def self.search(query)
__elasticsearch__.search(
{
@ -399,12 +400,12 @@ class Course < ActiveRecord::Base
# __elasticsearch__.delete_document
# end
def create_course_ealasticsearch_index
if self.is_public == 1
if self.is_public == 1 and self.is_delete == 0 #公开 和 没有被删除的课程才被索引
self.__elasticsearch__.index_document
end
end
def update_course_ealasticsearch_index
if self.is_public == 1 #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性
if self.is_public == 1 and self.is_delete == 0 #如果是初次更新成为公开或者恢复被删除的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性
begin
self.__elasticsearch__.update_document
rescue => e

View File

@ -27,14 +27,14 @@
</div>
<% else %>
<div nhname='new_message_' style="display:none;">
<%= form_for('new_form',:url => {:controller => 'words', :action => 'leave_course_message'},:method => "post") do |f|%>
<%= form_for('new_form',:url => {:controller => 'words', :action => 'leave_course_message'}, :html=>{:id => "course_feedback_new"},:method => "post") do |f|%>
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" nhname='new_message_textarea_' name="new_form[course_message]"></textarea>
<p nhname='contentmsg_'></p>
<div nhname='toolbar_container_' style="float:left;padding-top:3px;margin-bottom: 15px;"></div>
<a id="new_message_cancel_btn_" href="javascript:void(0)" class="grey_btn fr mt10">取消</a>
<a id="new_message_submit_btn_" href="javascript:void(0)" class="blue_btn fr ml10 mt10">留言</a>
<% end%>
<a href="javascript:void(0);" class="blue_btn fr ml10 mt10" id="submit_feedback_course" >留言</a>
<% end %>
</div>
<% end %>
</div>
@ -50,7 +50,11 @@
<div style="display:none;"><a href="#" id="nhjump"></a></div>
<script type="text/javascript">
$(function(){
$(function(){
$("#submit_feedback_course").one('click',function() {
$("#course_feedback_new").submit();
});
KindEditor.ready(function(K){
$("a[nhname='reply_btn']").live('click',function(){
var params = {};
@ -83,4 +87,5 @@
});
});
});
</script>

View File

@ -1,6 +1,7 @@
<% @members.each do |member| %>
<li >
<%= link_to_user_header member.principal,true,:class => "w150 c_orange fl" %>
<%#= link_to_user_header member.principal,true,:class => "w150 c_orange fl" %>
<%= link_to "#{member.principal}#{member.principal.show_name}", user_path(member.principal), :class => "w150 c_orange fl" %>
<span class="w150 fl">
<%= zh_course_role(h member.roles.sort.collect(&:to_s).join(', ')) %>
<%= form_for(member, {:as => :membership, :remote => true, :url => membership_path(member),

View File

@ -6,6 +6,7 @@
</span>
<% end %>
</div>
</div>
<% if @subPage_title == l(:label_student_list)%>
<%= render :partial => 'course_student', :locals => {:members => @members} %>
<% else%>

View File

@ -88,6 +88,15 @@
</li>
<% end %>
</ul>
<% if @course.is_delete == 1 %>
<div class="mt30 fr"><img src="/images/pic_del.gif" class="mr5"><%=link_to "恢复该课程", renew_course_path(@course) %></div>
<% else %>
<div class="mt30">
<img src="/images/pic_del.gif" class="mr5"><%=link_to "删除该课程", course_path(@course), :method => :delete, :confirm=>"确认要删除该课程吗?" %>
<span>(友情提示:删除该课程后如果您想恢复该课程,请联系系统管理员!)</span>
</div>
<% end %>
</div>
<div class="hwork_undis" id="tbc_02">

View File

@ -103,17 +103,17 @@
<!--邀请加入-->
<div class="subNavBox">
<% if User.current.member_of?(@project) %>
<div class="subNav currentDd currentDt subNav_jiantou" id="expand_tools_expand_invit" nhtype="toggle4cookie" data-id="expand_invit" data-target="#navContent_invit" data-val="expand">
<%= l(:label_invite)%>
</div>
<ul class="navContent " style="display:block" id="navContent_invit">
<li><%= link_to l(:label_invite_new_user), :controller=>"projects", :action=>"invite_members_by_mail", :id => @project %></li>
<!--<%# if User.current.allowed_to?(:manage_members, @project) %>-->
<%# if User.current.member_of?(@project) %>
<!--<div class="subNav currentDd currentDt subNav_jiantou" id="expand_tools_expand_invit" nhtype="toggle4cookie" data-id="expand_invit" data-target="#navContent_invit" data-val="expand">-->
<!--<%#= l(:label_invite)%>-->
<!--</div>-->
<!--<ul class="navContent " style="display:block" id="navContent_invit">-->
<!--<li><%#= link_to l(:label_invite_new_user), :controller=>"projects", :action=>"invite_members_by_mail", :id => @project %></li>-->
<!--&lt;!&ndash;<%# if User.current.allowed_to?(:manage_members, @project) %>&ndash;&gt;-->
<!--<li><%#= link_to l(:label_invite_trustie_user), :controller=>"projects", :action=>"invite_members", :id => @project %></li>-->
<!--<%# end %>-->
</ul>
<% end %><!--end-->
<!--</ul>-->
<%# end %><!--end-->
<!--menu 左侧工具栏 -->
<%#--project_new_type: 1为开发组2为科研组3为朋友圈子--%>

View File

@ -147,7 +147,7 @@
<% end%>
<% end%>
</div>
<% courses = @user.courses.visible.select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5)%>
<% courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5)%>
<div class="homepageLeftMenuCourses <%= courses.empty? ? 'none' : ''%>" id="homepageLeftMenuCourses">
<ul>
<%= render :partial => 'layouts/user_courses', :locals => {:courses => courses,:user => @user, :page => 0} %>

View File

@ -29,7 +29,8 @@
<p nhname="contentmsg"></p>
<div class="fl mt10" style="padding-top:5px;" nhname="toolbar_container"></div>
<%#= submit_tag l(:button_leave_meassge), :name => nil , :class => "blue_btn fr mt10 mb10" %>
<%= link_to l(:button_leave_meassge), "javascript:void(0)", :onclick => 'submitProjectFeedback();', :onmouseover => 'submitFocus(this);', :class => 'blue_btn fr mt10 mb10' %>
<a href="javascript:void(0);" class="blue_btn fr ml10 mt10" id="submit_feedback_project" >留言</a>
<%#= link_to l(:button_leave_meassge), "javascript:void(0)", :onclick => 'submitProjectFeedback();', :onmouseover => 'submitFocus(this);', :class => 'blue_btn fr mt10 mb10' %>
<% end %>
<% end %>
@ -43,6 +44,9 @@
<div style="display:none;"><a href="#" id="nhjump"></a></div>
<script type="text/javascript">
$(function(){
$("#submit_feedback_project").one('click',function() {
$("#project_feedback_form").submit();
});
function init_editor(params){
params.textarea.removeAttr('placeholder');

View File

@ -25,8 +25,8 @@
<textarea id="copy_rep_content" class="cloneUrl mt5 fl" type="input" ><%=@repository.type.to_s=="Repository::Gitlab" ? @repos_url.to_s.lstrip : @repository.url %></textarea>
<a href="javascript:void(0);" class="clone_btn mt5" onclick="jsCopy()"><span class="vl_copy" title="点击复制版本库地址"></span></a>
<div class="fl mt5 ml15"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_zip"></span>ZIP</a> </div>
<!--<div class="fr mt5"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_fork"></span>Fork</a> <span href="javascript:void(0);" class="vl_btn_2 fb">0</span> </div>-->
<% unless User.current.id == @project.user_id %>
<%# 针对公开项目:用户必须创建了项目,否则用户无法同步 %>
<% if User.current.id != @project.user_id %>
<div class="fr mt5"><%= link_to "<span class='vl_fork'></span>".html_safe+"Fork", {:controller => 'repositories', :action => 'forked'}, :class=>"vl_btn"%>
<span href="javascript:void(0);" class="vl_btn_2 fb"><%= @project.forked_count.to_i %></span>
</div>

View File

@ -19,12 +19,12 @@
<div class="message_box mb10" id="users_setting">
<div nhname='new_message' style="display:none;">
<%= form_for('new_form',:url => leave_user_message_path(@user.id),:method => "post") do |f|%>
<%= form_for('new_form',:url => leave_user_message_path(@user.id), :html =>{:id => "user_feedback_new"}, :method => "post") do |f|%>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='new_message_textarea' name="new_form[user_message]"></textarea>
<p nhname='contentmsg'></p>
<div nhname='toolbar_container' style="float:left;padding-top:3px;"></div>
<a id="new_message_cancel_btn" href="javascript:void(0)" class="grey_n_btn fr " style="margin-top:6px;">取消</a>
<a id="new_message_submit_btn" href="javascript:void(0)" class="blue_n_btn fr mr5 " style="margin-top:6px;">留言</a>
<a href="javascript:void(0);" class="blue_n_btn fr mr5" id="submit_feedback_user" style="margin-top:6px;" >留言</a>
<% end%>
</div>
<div class="cl"></div>
@ -44,3 +44,12 @@
<div class="cl"></div>
</div><!--message_box end-->
</div>
<script type="text/javascript">
$(function(){
$("#submit_feedback_user").one('click',function() {
$("#submit_feedback_user").submit();
});
});
</script>

View File

@ -890,6 +890,7 @@ RedmineApp::Application.routes.draw do
get 'member_score', :to => 'courses#member_score'
post 'finishcourse'
post 'restartcourse'
match "renew", :to => 'courses#renew', :via => [:post, :get], :as =>'renew'
match "searchmembers", :controller => 'courses', :action => 'searchmembers', :via => [:post,:get]
match "searchgroupmembers", :via => [:post, :get]
match 'member_score_sort', :via => [:get]

View File

@ -0,0 +1,5 @@
class AddIsDeleteToCourses < ActiveRecord::Migration
def change
add_column :courses, :is_delete, :integer, :default => 0
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20151204062220) do
ActiveRecord::Schema.define(:version => 20151210110210) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -459,6 +459,7 @@ ActiveRecord::Schema.define(:version => 20151204062220) do
t.integer "open_student", :default => 0
t.integer "outline", :default => 0
t.integer "publish_resource", :default => 0
t.integer "is_delete"
end
create_table "custom_fields", :force => true do |t|
@ -969,6 +970,7 @@ ActiveRecord::Schema.define(:version => 20151204062220) do
t.integer "course_group_id", :default => 0
end
add_index "members", ["course_id"], :name => "index_members_on_course_id"
add_index "members", ["project_id"], :name => "index_members_on_project_id"
add_index "members", ["user_id", "project_id", "course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true
add_index "members", ["user_id"], :name => "index_members_on_user_id"
@ -1149,6 +1151,7 @@ ActiveRecord::Schema.define(:version => 20151204062220) do
t.datetime "updated_at", :null => false
t.boolean "locked", :default => false
t.integer "sticky", :default => 0
t.integer "org_subfield_id"
end
create_table "org_member_roles", :force => true do |t|
@ -1175,6 +1178,7 @@ ActiveRecord::Schema.define(:version => 20151204062220) do
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "field_type"
end
create_table "organizations", :force => true do |t|
@ -1525,7 +1529,6 @@ ActiveRecord::Schema.define(:version => 20151204062220) do
end
add_index "student_works", ["homework_common_id", "user_id"], :name => "index_student_works_on_homework_common_id_and_user_id"
add_index "student_works", ["homework_common_id"], :name => "index"
create_table "student_works_evaluation_distributions", :force => true do |t|
t.integer "student_work_id"

View File

@ -1363,3 +1363,10 @@ $(function(){
personalized_init();
});
function submit_course_feedback() {
var flag = false;
if(flag == false){
$("#course_feedback_new").submit();
var flag = true
}
}