Merge branch 'szzh' into gitlab_guange

Conflicts:
	Gemfile
	app/models/user.rb
	db/schema.rb
	lib/trustie.rb

解决冲突
tmp
huang 10 years ago
commit 7c1bb8b9ed

@ -6,6 +6,7 @@ unless RUBY_PLATFORM =~ /w32/
gem 'iconv'
end
gem 'grack', path:'./lib/grack'
gem 'gitlab', path: 'lib/gitlab-cli'
gem 'rest-client'
gem "mysql2", "= 0.3.18"
@ -42,6 +43,9 @@ group :development, :test do
gem 'pry-byebug'
end
gem 'pry-stack_explorer'
if RUBY_PLATFORM =~ /darwin/
gem 'puma'
end
end
gem 'rspec-rails', '~> 3.0'

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

@ -0,0 +1,3 @@
// Place all the styles related to the SystemMessages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

@ -25,21 +25,33 @@ class AccountController < ApplicationController
# Login request and validation
def login
if request.get?
@login = params[:login] || true
if User.current.logged?
redirect_to home_url
redirect_to user_path(User.current)
else
render :layout => 'login'
end
else
authenticate_user
end
end
# 服务协议
def agreement
render :layout => 'static_base'
end
def about_us
render :layout => 'static_base'
end
# Log out current user and redirect to welcome page
def logout
if User.current.anonymous?
redirect_to home_url
redirect_to signin_path
elsif request.post?
logout_user
redirect_to home_url
redirect_to signin_path
end
# display the logout form
end
@ -50,16 +62,16 @@ class AccountController < ApplicationController
# Lets user choose a new password
def lost_password
(redirect_to(home_url); return) unless Setting.lost_password?
(redirect_to(signin_path); return) unless Setting.lost_password?
if params[:token]
@token = Token.find_token("recovery", params[:token].to_s)
if @token.nil? || @token.expired?
redirect_to home_url
redirect_to signin_path
return
end
@user = @token.user
unless @user && @user.active?
redirect_to home_url
redirect_to signin_path
return
end
if request.post?
@ -79,6 +91,7 @@ class AccountController < ApplicationController
# user not found or not active
unless user && user.active?
flash.now[:error] = l(:notice_account_unknown_email)
render :layout => 'static_base'
return
end
# user cannot change its password
@ -91,16 +104,17 @@ class AccountController < ApplicationController
if token.save
Mailer.run.lost_password(token)
flash[:notice] = l(:notice_account_lost_email_sent)
redirect_to signin_url
redirect_to lost_password_path
return
end
end
render :layout => 'static_base'
end
end
# User self-registration
def register
(redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration]
(redirect_to(signin_path); return) unless Setting.self_registration? || session[:auth_source_registration]
if request.get?
session[:auth_source_registration] = nil
@user = User.new(:language => current_language.to_s)
@ -128,10 +142,12 @@ class AccountController < ApplicationController
end
when '3'
#register_automatically(@user)
unless @user.new_record?
if !@user.new_record?
self.logged_user = @user
flash[:notice] = l(:notice_account_activated)
redirect_to my_account_url
else
redirect_to signin_path
end
else
#register_manually_by_administrator(@user)
@ -175,11 +191,11 @@ class AccountController < ApplicationController
# Token based account activation
def activate
(redirect_to(home_url); return) unless Setting.self_registration? && params[:token].present?
(redirect_to(signin_path); return) unless Setting.self_registration? && params[:token].present?
token = Token.find_token('register', params[:token].to_s)
(redirect_to(home_url); return) unless token and !token.expired?
(redirect_to(signin_path); return) unless token and !token.expired?
user = token.user
(redirect_to(home_url); return) unless user.registered?
(redirect_to(signin_path); return) unless user.registered?
user.activate
if user.save
token.destroy
@ -266,7 +282,7 @@ class AccountController < ApplicationController
user = User.find_or_initialize_by_identity_url(identity_url)
if user.new_record?
# Self-registration off
(redirect_to(home_url); return) unless Setting.self_registration?
(redirect_to(signin_path); return) unless Setting.self_registration?
# Create on the fly
user.login = registration['nickname'] unless registration['nickname'].nil?
@ -353,12 +369,15 @@ class AccountController < ApplicationController
def invalid_credentials
logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
flash.now[:error] = l(:notice_account_invalid_creditentials)
flash[:error] = l(:notice_account_invalid_creditentials)
# render :layout => 'login'
redirect_to signin_path(:login=>true)
end
def invalid_credentials_new
logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
flash.now[:error] = l(:notice_account_invalid_creditentials_new)
flash[:error] = l(:notice_account_invalid_creditentials_new)
render signin_path(:login=>true)
end
# Register a user for email activation.

@ -79,6 +79,11 @@ class AdminController < ApplicationController
end
end
# 系统消息
def messages
@admin_messages = SystemMessage.new
end
def plugins
@plugins = Redmine::Plugin.all
end
@ -395,4 +400,78 @@ class AdminController < ApplicationController
end
#留言列表
def leave_messages
@jour = JournalsForMessage.find_by_sql("SELECT * FROM journals_for_messages AS j1
WHERE j1.jour_type IN ('Course','Principal') AND (j1.m_parent_id IS NULL OR (j1.m_parent_id IN (SELECT id FROM journals_for_messages WHERE jour_type IN ('Course','Principal')))) order by created_on desc")
@jour = paginateHelper @jour,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.html
end
end
#帖子
def messages_list
@memo = Memo.reorder("created_at desc")
@memo = paginateHelper @memo,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.html
end
end
#课程讨论区的帖子
def course_messages
@course_ms=Message.joins("join boards on messages.board_id=boards.id where boards.course_id is not NULL").reorder('created_on desc')
@course_ms = paginateHelper @course_ms,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.html
end
end
#项目讨论区的帖子
def project_messages
@project_ms=Message.joins("join boards on messages.board_id=boards.id where boards.project_id != -1").reorder('created_on desc')
@project_ms = paginateHelper @project_ms,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.html
end
end
#通知
def notices
@news = News.where('course_id is not NULL').order('created_on desc')
@news = paginateHelper @news,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.html
end
end
#最近登录用户列表
def latest_login_users
scope = User.order('last_login_on desc')
scope = scope.where("last_login_on>= '#{params[:startdate]} 00:00:00'") if params[:startdate].present?
scope =scope.where("last_login_on <= '#{params[:enddate]} 23:59:59'") if params[:enddate].present?
@user = scope
@user = paginateHelper @user,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.html
end
end
#作业
def homework
@homework = HomeworkCommon.order('end_time desc')
@homework = paginateHelper @homework,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.html
end
end
end

@ -557,12 +557,13 @@ class ApplicationController < ActionController::Base
end
def redirect_back_or_default(default, options={})
back_url = params[:back_url].to_s
back_url = '' #params[:back_url].to_s
if back_url.present?
begin
uri = URI.parse(back_url)
# do not redirect user to another host or to the login or register page
if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
back_url = back_url.gsub(%r{\/users\/(\d+)},"/users/"+default.id.to_s) if default.is_a?(:User)
redirect_to(back_url)
return
end

@ -68,6 +68,28 @@ class BoardsController < ApplicationController
end
def show
# 讨论区消息状态更新(已读和未读)
if @project
query_forge_messages = @board.messages
query_forge_messages.each do |query_forge_message|
query = query_forge_message.forge_messages
query.each do |forge_message|
if User.current.id == forge_message.user_id
forge_message.update_attributes(:viewed => true)
end
end
end
elsif @course
query_course_messages = @board.messages
query_course_messages.each do |query_course_message|
query = query_course_message.course_messages
query.each do |course_message|
if User.current.id == course_message.user_id
course_message.update_attributes(:viewed => true)
end
end
end
end
respond_to do |format|
format.js
format.html {
@ -79,8 +101,9 @@ class BoardsController < ApplicationController
@topic_count = @board ? @board.topics.count : 0
if @project
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
#现在发布帖子的时候置顶功能已经没有了。所以取消这个置顶排序 #{Message.table_name}.sticky DESC,
@topics = @board.topics.
reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc").
reorder("#{Message.table_name}.created_on desc").
includes(:last_reply).
limit(@topic_pages.per_page).
offset(@topic_pages.offset).

@ -34,25 +34,42 @@ class CommentsController < ApplicationController
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,@comment.id,OwnerTypeHelper::COMMENT
end
# 与我相关动态的记录add start
if( @comment.id && @news.course )
if(@news.author_id != User.current.id)
notify = ActivityNotify.new()
notify.activity_container_id = @news.course.id
notify.activity_container_type = 'Course'
notify.activity_id = @comment.id
notify.activity_type = 'Comment'
notify.notify_to = @news.author_id
notify.is_read = 0
notify.save()
# # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add start
# if( @comment.id && @news.course )
# if(@news.author_id != User.current.id)
# notify = ActivityNotify.new()
# notify.activity_container_id = @news.course.id
# notify.activity_container_type = 'Course'
# notify.activity_id = @comment.id
# notify.activity_type = 'Comment'
# notify.notify_to = @news.author_id
# notify.is_read = 0
# notify.save()
# end
# end
# # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add end
flash[:notice] = l(:label_comment_added)
course_activity = CourseActivity.where("course_act_type='News' and course_act_id =#{@news.id}").first
if course_activity
course_activity.updated_at = Time.now
course_activity.save
end
user_activity = UserActivity.where("act_type='News' and act_id =#{@news.id}").first
if user_activity
user_activity.updated_at = Time.now
user_activity.save
end
# 与我相关动态的记录add end
flash[:notice] = l(:label_comment_added)
end
if params[:user_activity_id]
@user_activity_id = params[:user_activity_id]
respond_to do |format|
format.js
end
else
redirect_to news_url(@news)
end
end
def destroy
@news.comments.find(params[:comment_id]).destroy

@ -8,7 +8,7 @@ class CoursesController < ApplicationController
helper :attachments
helper :activity_notifys
before_filter :auth_login1, :only => [:show, :feedback]
before_filter :auth_login1, :only => [:show, :course_activity, :feedback]
menu_item :overview
menu_item :feedback, :only => :feedback
menu_item :homework, :only => :homework
@ -39,9 +39,14 @@ class CoursesController < ApplicationController
else
@state = 5 #未登录
end
# if @state == 1 || @state == 3
# respond_to course_path(course.id)
# else
respond_to do |format|
format.js { render :partial => 'set_join', :locals => {:user => user, :course => course, :object_id => params[:object_id]} }
end
#end
rescue Exception => e
@state = 4 #已经加入了课程
respond_to do |format|
@ -101,74 +106,18 @@ class CoursesController < ApplicationController
# 课程搜索
# add by nwb
def search
courses_all = Course.all_course
name = params[:name]
if name.blank?
@courses = []
@courses_all = []
@course_count = 0
@course_pages = Paginator.new @course_count, per_page_option, params['page']
else
@courses = courses_all.visible
if params[:name].present?
@courses_all = @courses.like(params[:name])
if params[:name].empty?
courses = Course.visible
@courses = paginateHelper courses,10
else
@courses_all = @courses;
end
@course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page']
# 课程的动态数
@course_activity_count=Hash.new
@courses_all.each do |course|
@course_activity_count[course.id]=0
courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'")
@courses = paginateHelper courses,10
end
case params[:course_sort_type]
when '0'
@courses = @courses_all.order("created_at desc")
@s_type = 0
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses,@course_activity_count
when '1'
@courses = @courses_all.order("course_ac_para desc")
@s_type = 1
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses,@course_activity_count
when '2'
@courses = @courses_all.order("watchers_count desc")
@s_type = 2
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses,@course_activity_count
when '3'
@course_activity_count=get_course_activity @courses_all,@course_activity_count_array
@courses=handle_course @courses_all,@course_activity_count
@s_type = 3
@courses = @courses[@course_pages.offset, @course_pages.per_page]
else
@s_type = 0
@courses = @courses_all.order("created_at desc")
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses,@course_activity_count
end
end
@name = params[:name]
@type = 'courses'
respond_to do |format|
format.html {
render :layout => 'course_base'
scope = Course
unless params[:closed]
scope = scope.active
end
}
format.atom {
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
@ -519,6 +468,7 @@ class CoursesController < ApplicationController
end
def new
if User.current.login?
@course_type = params[:course_type] ||= params[:course]
@issue_custom_fields = IssueCustomField.sorted.all
@trackers = Tracker.sorted.all
@ -526,6 +476,9 @@ class CoursesController < ApplicationController
@course.safe_attributes = params[:course]
# month = Time.now.month
render :layout => 'new_base'
else
redirect_to signin_url
end
end
def desc_sort_course_by_avtivity(activity_count, courses)
@ -657,94 +610,37 @@ class CoursesController < ApplicationController
end
end
def show
if params[:jump] && redirect_to_course_menu_item(@course, params[:jump])
return
end
@users_by_role = @course.users_by_role
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
end
@key = User.current.rss_key
#新增内容
@days = Setting.activity_days_default.to_i
if params[:from]
begin; @date_to = params[:from].to_date + 1; rescue; end
end
has = {
"show_course_files" => true,
"show_course_news" => true,
"show_course_messages" => true,
#"show_course_journals_for_messages" => true,
# "show_bids" => true,
# "show_homeworks" => true,
"show_polls" => true
}
@date_to ||= Date.today + 1
@date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
if @author.nil?
# 显示老师和助教的活动
# @authors = searchTeacherAndAssistant(@course)
@authors = course_all_member(@course)
events = []
key = "course_events_#{@course.id}".to_sym
if Rails.env.production? && Setting.course_cahce_enabled?
events = Rails.cache.read(key) || []
end
if events.empty?
@authors.each do |author|
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
:with_subprojects => false,
:author => author.user)
@activity.scope_select {|t| has["show_#{t}"]}
# modify by nwb
# 添加私密性判断
if User.current.member_of_course?(@course)|| User.current.admin?
events += @activity.events(@days, @course.created_at)
else
events += @activity.events(@days, @course.created_at, :is_public => 1)
end
end
Rails.cache.write(key, events) if Rails.env.production? && Setting.course_cahce_enabled?
end
else
# @author = @course.teacher
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
:with_subprojects => false,
:author => @author)
@activity.scope_select {|t| has["show_#{t}"]}
# modify by nwb
# 添加私密性判断
if User.current.member_of_course?(@course)|| User.current.admin?
events = @activity.events(@days, @course.created_at)
else
events = @activity.events(@days, @course.created_at, :is_public => 1)
end
def course_activity
redirect_to course_url(@course, type: params[:type], page: params[:page])
end
# 无新动态时,显示老动态
if events.count == 0
if User.current.member_of_course?(@course)|| User.current.admin?
events = @activity.events
def show
course_activities = @course.course_activities
@canShowRealName = User.current.member_of_course? @course
@page = params[:page] ? params[:page].to_i + 1 : 0
if params[:type].present?
case params[:type]
when "homework"
@course_activities = course_activities.where("course_act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10)
when "news"
@course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10)
when "message"
@course_activities = course_activities.where("course_act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10)
when "poll"
@course_activities = course_activities.where("course_act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10)
when "attachment"
@course_activities = course_activities.where("course_act_type = 'Attachment'").order('updated_at desc').limit(10).offset(@page * 10)
when "journalsForMessage"
@course_activities = course_activities.where("course_act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10)
else
events = @activity.events(:is_public => 1)
@course_activities = course_activities.order('updated_at desc').limit(10).offset(@page * 10)
end
else
@course_activities = course_activities.order('updated_at desc').limit(10).offset(@page * 10)
end
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
end
sorted_events = sort_activity_events_course(events)
events = paginateHelper sorted_events,10
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
# documents
@type = params[:type]
respond_to do |format|
format.js
format.html{render :layout => 'base_courses'}
format.api
end
@ -761,6 +657,11 @@ 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
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
page = params[:page]
# Find the page of the requested reply

@ -134,8 +134,12 @@ class FilesController < ApplicationController
if sort == ""
sort = "created_on DESC"
end
if keywords != "%%"
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").
reorder(sort)
else
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' "). reorder(sort)
end
#resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC")
end
@ -176,12 +180,6 @@ class FilesController < ApplicationController
def index
@flag = params[:flag] || false
#sort_init 'filename', 'asc'
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
'filename' => "#{Attachment.table_name}.filename",
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
sort = ""
@sort = ""
@order = ""
@ -553,7 +551,7 @@ class FilesController < ApplicationController
q = "%#{@q.strip}%"
@result = find_course_attache q,@course,sort
@result = visable_attachemnts @result
@result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)}
@result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank?
@searched_attach = paginateHelper @result,10
@tag_list = get_course_tag_list @course

@ -7,7 +7,7 @@ class ForumsController < ApplicationController
before_filter :find_forum_if_available
before_filter :authenticate_user_edit, :only => [:edit, :update]
before_filter :authenticate_user_destroy, :only => [:destroy]
before_filter :require_login, :only => [:new, :create]
before_filter :require_login, :only => [:new, :create,:destroy,:update,:edit]
helper :sort
include SortHelper
@ -97,7 +97,24 @@ class ForumsController < ApplicationController
def index
@offset, @limit = api_offset_and_limit({:limit => 10})
@forums_all = Forum.reorder("sticky DESC")
if(params[:reorder_complex])
@type="reorder_complex"
@str=params[:reorder_complex]
@forums_all = Forum.reorder("topic_count #{params[:reorder_complex]},updated_at #{params[:reorder_complex]}")
elsif(params[:reorder_popu])
@type="reorder_popu"
@str=params[:reorder_popu]
@forums_all = Forum.reorder("topic_count #{params[:reorder_popu]}")
elsif(params[:reorder_time])
@type="reorder_time"
@str=params[:reorder_time]
@forums_all = Forum.reorder("updated_at #{params[:reorder_time]}")
else
params[:reorder_complex] = "desc"
@type="reorder_complex"
@str=params[:reorder_complex]
@forums_all = Forum.reorder("topic_count desc,updated_at desc")
end
@forums_count = @forums_all.count
@forums_pages = Paginator.new @forums_count, @limit, params['page']
@ -106,6 +123,7 @@ class ForumsController < ApplicationController
#@forums = Forum.all
respond_to do |format|
format.html # index.html.erb
format.js
format.json { render json: @forums }
end
end
@ -113,11 +131,25 @@ class ForumsController < ApplicationController
# GET /forums/1
# GET /forums/1.json
def show
sort_init 'updated_at', 'desc'
sort_update 'created_at' => "#{Memo.table_name}.created_at",
'replies' => "#{Memo.table_name}.replies_count",
'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
# sort_init 'updated_at', 'desc'
# sort_update 'created_at' => "#{Memo.table_name}.created_at",
# 'replies' => "#{Memo.table_name}.replies_count",
# 'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
order = ""
@order_str = ""
if(params[:reorder_complex])
order = " last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}"
@order_str = "reorder_complex="+params[:reorder_complex]
elsif(params[:reorder_popu])
order = "replies_count #{params[:reorder_popu]}"
@order_str = "reorder_popu="+params[:reorder_popu]
elsif(params[:reorder_time])
order = "#{Memo.table_name}.updated_at #{params[:reorder_time]}"
@order_str = "reorder_time="+params[:reorder_time]
else
order = "last_replies_memos.created_at desc, #{Memo.table_name}.created_at desc"
@order_str = "reorder_complex=desc"
end
@memo = Memo.new(:forum => @forum)
@topic_count = @forum.topics.count
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
@ -126,19 +158,15 @@ class ForumsController < ApplicationController
includes(:last_reply).
limit(@topic_pages.per_page).
offset(@topic_pages.offset).
order(sort_clause).
reorder(order).
preload(:author, {:last_reply => :author}).
all
@memos
# @offset, @limit = api_offset_and_limit({:limit => 10})
# @forum = Forum.find(params[:id])
# @memos_all = @forum.topics
# @topic_count = @memos_all.count
# @topic_pages = Paginator.new @topic_count, @limit, params['page']
# @offset ||= @topic_pages.offset
# @memos = @memos_all.offset(@offset).limit(@limit).all
@my_topic_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is not null").count
@errors = params[:errors]
respond_to do |format|
format.js
format.html {
render :layout => 'base_forums'
}# show.html.erb
@ -172,20 +200,23 @@ class ForumsController < ApplicationController
# Author lizanle
# Description after save后需要进行资源记录的更新
# owner_type = 2 对应的是 forum
@save_flag=true
if params[:asset_id]
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids ,@forum.id,OwnerTypeHelper::FORUM
end
#end
respond_to do |format|
format.js
format.html { redirect_to @forum, notice: l(:label_forum_create_succ) }
format.json { render json: @forum, status: :created, location: @forum }
end
else
@save_flag=false
respond_to do |format|
flash.now[:error] = "#{l :label_forum_create_fail}: #{@forum.errors.full_messages[0]}"
format.js
format.html { render action: "new" }
format.json { render json: @forum.errors, status: :unprocessable_entity }
end
@ -199,10 +230,12 @@ class ForumsController < ApplicationController
respond_to do |format|
if @forum.update_attributes(params[:forum])
format.js {render :text=> true}
format.html { redirect_to @forum, notice: l(:label_forum_update_succ) }
format.json { head :no_content }
else
flash.now[:error] = "#{l :label_forum_update_fail}: #{@forum.errors.full_messages[0]}"
format.js { render :text=> false}
format.html { render action: "edit" }
format.json { render json: @forum.errors, status: :unprocessable_entity }
end
@ -261,6 +294,52 @@ class ForumsController < ApplicationController
end
end
#检查forum的名字
def check_forum_name
forum_name_exist = true
if params[:forum_id]
forum_name_exist = Forum.where("name = '#{params[:forum_name]}' and id != #{params[:forum_id]}").count >= 1 ? true : false
else
forum_name_exist = Forum.where("name = '#{params[:forum_name]}' ").count >= 1 ? true : false
end
render :text => forum_name_exist
end
#添加论坛tag
def add_forum_tag
@forum = Forum.find(params[:id])
unless @forum.nil?
@forum.tag_list.add(params[:tag_str].split(','))
@forum.save
end
respond_to do |format|
format.js {render :delete_forum_tag}
end
end
#删除forum的tag
def delete_forum_tag
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(params[:tag_name])).id
#forum的taggable_type = 5
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,params[:id],'Forum')
unless @taggings.nil?
@taggings.delete
end
# 是否还有其他记录 引用了 tag_id
@tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id)
# 如果taggings表中记录已经不存在 那么检查tags表 作删除动作
if @tagging.nil?
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
@tag.delete unless @tag.nil?
end
@forum = Forum.find(params[:id])
respond_to do |format|
format.js
end
end
private
def find_forum_if_available

@ -1,12 +0,0 @@
#added by baiyu
class GitUsageController < ApplicationController
layout "new_base"
def ch_usage
end
def en_usage
end
end
#end

File diff suppressed because it is too large Load Diff

@ -20,11 +20,11 @@ class IssuesController < ApplicationController
default_search_scope :issues
before_filter :authorize1, :only => [:show]
before_filter :find_issue, :only => [:show, :edit, :update]
before_filter :find_issue, :only => [:show, :edit, :update,:add_journal]
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
before_filter :find_project, :only => [:new, :create, :update_form]
#before_filter :authorize, :except => [:index, :show]
before_filter :authorize, :except => [:index]
before_filter :authorize, :except => [:index,:add_journal]
before_filter :find_optional_project, :only => [:index]
before_filter :check_for_default_issue_status, :only => [:new, :create]
@ -112,7 +112,19 @@ class IssuesController < ApplicationController
end
def show
# 当前用户查看指派给他的缺陷消息,则设置消息为已读
query = ForgeMessage.where("forge_message_type =? and user_id =? and forge_message_id =?", "Issue", User.current, @issue).first
query.update_attribute(:viewed, true) unless query.nil?
# 缺陷状态更新
query_journals = @issue.journals
query_journals.each do |query_journal|
query_journal.forge_messages.each do |f|
if User.current.id == f.user_id
f.update_attributes(:viewed => true)
end
end
end
# end
@journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
@journals.each_with_index {|j,i| j.indice = i+1}
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
@ -207,7 +219,6 @@ class IssuesController < ApplicationController
end
if saved
#修改界面增加跟踪者
watcherlist = @issue.watcher_users
select_users = []
@ -237,9 +248,7 @@ class IssuesController < ApplicationController
JournalReply.add_reply(@issue.current_journal.id, reply_id, User.current.id)
end
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
respond_to do |format|
format.html { redirect_to issue_url(@issue.id) }
format.api { render_api_ok }
end
@ -371,6 +380,23 @@ class IssuesController < ApplicationController
end
end
def add_journal
if User.current.logged?
jour = Journal.new
jour.user_id = User.current.id
jour.notes = params[:notes]
jour.journalized = @issue
jour.save
user_activity = UserActivity.where("act_type='Issue' and act_id =#{@issue.id}").first
user_activity.updated_at = jour.created_on
user_activity.save
@user_activity_id = params[:user_activity_id]
respond_to do |format|
format.js
end
end
end
private
def find_project

@ -36,8 +36,7 @@ class JournalsController < ApplicationController
sort_update(@query.sortable_columns)
if @query.valid?
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
:limit => 25)
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", :limit => 25)
end
@title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
render :layout => false, :content_type => 'application/atom+xml'
@ -72,9 +71,9 @@ class JournalsController < ApplicationController
end
# Replaces pre blocks with [...]
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
@content = "> #{ll(Setting.default_language, :text_user_wrote, user)}\n> "
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
# @content = "<blockquote style='word-break: break-all;word-wrap: break-word;'>" << @content
@content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n"
@content << text.gsub(/(\r?\n|\r\n?)/, "\n ") + "\n"
@content = "<blockquote style='padding-left:0px;margin-left:0px;'>" << @content << "</blockquote>\n\n<br/>"
@id = user.id
rescue ActiveRecord::RecordNotFound
render_404

@ -11,7 +11,7 @@ class MemosController < ApplicationController
include AttachmentsHelper
include ApplicationHelper
layout 'base_memos'
# layout 'base_memos'
def quote
@subject = @memo.subject
@ -77,46 +77,36 @@ class MemosController < ApplicationController
format.json { render json: @memo, status: :created, location: @memo }
else
flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
# back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id)
pre_count = REPLIES_PER_PAGE
format.js
format.html { redirect_to( forum_path(Forum.find(params[:forum_id]),:errors=>@memo.errors.full_messages[0])) }
format.json { render json: @memo.errors, status: :unprocessable_entity }
#end
@memo_new = @memo.dup
@memo = @memo.root # 取出楼主防止输入帖子id让回复作为主贴显示
unless @memo.new_record?
@memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
end
end
end
REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE)
def show
page = params[:page]
if params[:r] && page.nil?
offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
page = 1 + offset / pre_count
else
# 更新贴吧帖子留言对应的memo_messages的viewed字段
unless @memo.children.blank?
@memo.children.each do |child|
child.memo_messages.each do |memo_message|
if User.current.id == memo_message.user_id
memo_message.update_attributes(:viewed => true)
end
end
@reply_count = @memo.children.count
@reply_pages = Paginator.new @reply_count, pre_count, page
@replies = @memo.children.
includes(:author, :attachments).
reorder("#{Memo.table_name}.created_at DESC").
limit(@reply_pages.per_page).
offset(@reply_pages.offset).
all
if @memo.new_record?
format.html { render :new,:layout=>'base'}
else
format.html { render action: :show }
format.json { render json: @memo.errors, status: :unprocessable_entity }
end
end
query_memo_messages = @memo.memo_messages
query_memo_messages.each do |query_memo_message|
if User.current.id == query_memo_message.user_id
query_memo_message.update_attributes(:viewed => true)
end
end
REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE)
def show
pre_count = REPLIES_PER_PAGE
@memo = @memo.root # 取出楼主防止输入帖子id让回复作为主贴显示
@memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
@ -138,21 +128,27 @@ class MemosController < ApplicationController
@memo_new = Memo.new
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
# @memo = Memo.find_by_id(params[:id])
# @forum = Forum.find(params[:forum_id])
# @replies = @memo.replies
# @mome_new = Memo.new
respond_to do |format|
format.html # show.html.erb
format.html {render :layout=> 'base_forums'}#:layout=> 'base_forums',
format.json { render json: @memo }
format.xml { render xml: @memo }
end
end
def edit
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
@replying = false
respond_to do |format|
format.html {render :layout=>'base_forums'}
end
end
def update
@ -160,7 +156,8 @@ class MemosController < ApplicationController
if( #@memo.update_column(:subject, params[:memo][:subject]) &&
@memo.update_column(:content, params[:memo][:content]) &&
@memo.update_column(:sticky, params[:memo][:sticky]) &&
@memo.update_column(:lock, params[:memo][:lock]))
@memo.update_column(:lock, params[:memo][:lock]) &&
@memo.update_column(:subject,params[:memo][:subject]))
@memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
@memo.save
# @memo.root.update_attribute(:updated_at, @memo.updated_at)
@ -211,7 +208,7 @@ class MemosController < ApplicationController
end
def back_memo_url
forum_memo_path(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))
forum_memo_path(@forum, (@memo.root.nil? ? @memo : @memo.root))
end
def back_memo_or_forum_url

@ -89,6 +89,7 @@ class MessagesController < ApplicationController
# Create a new topic
def new
if User.current.logged?
@message = Message.new
@message.author = User.current
@message.board = @board
@ -101,28 +102,6 @@ class MessagesController < ApplicationController
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE
end
# 与我相关动态的记录add start
if(@board && @board.course) #项目的先不管
teachers = searchTeacherAndAssistant(@board.course)
for teacher in teachers
if(teacher.user_id != User.current.id)
notify = ActivityNotify.new()
if(@board.course)
notify.activity_container_id = @board.course_id
notify.activity_container_type = 'Course'
else
notify.activity_container_id = @board.project_id
notify.activity_container_type = 'Project'
end
notify.activity_id = @message.id
notify.activity_type = 'Message'
notify.notify_to = teacher.user_id
notify.is_read = 0
notify.save()
end
end
end
# 与我相关动态的记录add end
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
render_attachment_warning_if_needed(@message)
@ -156,6 +135,9 @@ class MessagesController < ApplicationController
}
end
end
else
redirect_to signin_path
end
end
# Reply to a topic
@ -177,7 +159,19 @@ class MessagesController < ApplicationController
@reply.board = @board
@reply.safe_attributes = params[:reply]
@reply.content = @quote + @reply.content
@reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject]
# @reply.reply_id = params[:id]
@topic.children << @reply
course_activity = CourseActivity.where("course_act_type='Message' and course_act_id =#{@topic.id}").first
if course_activity
course_activity.updated_at = Time.now
course_activity.save
end
user_activity = UserActivity.where("act_type='Message' and act_id =#{@topic.id}").first
if user_activity
user_activity.updated_at = Time.now
user_activity.save
end
#@topic.update_attribute(:updated_on, Time.now)
if !@reply.new_record?
if params[:asset_id]
@ -185,41 +179,18 @@ class MessagesController < ApplicationController
update_kindeditor_assets_owner ids,@reply.id,OwnerTypeHelper::MESSAGE
end
# 与我相关动态的记录add start
if(@board && @board.course) #项目的先不管
notifyto_arr = {}
notifyto_arr[@topic.author_id] = @topic.author_id
if( params[:parent_topic] != nil && params[:parent_topic] != '')
parent_topic = Message.find(params[:parent_topic])
notifyto_arr[parent_topic.author_id] = parent_topic.author_id
end
notifyto_arr.each do |k,user_id|
if(user_id != User.current.id)
notify = ActivityNotify.new()
if(@board.course)
notify.activity_container_id = @board.course_id
notify.activity_container_type = 'Course'
else
notify.activity_container_id = @board.project_id
notify.activity_container_type = 'Project'
end
notify.activity_id = @reply.id
notify.activity_type = 'Message'
notify.notify_to = user_id
notify.is_read = 0
notify.save()
end
end
end
# 与我相关动态的记录add end
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
attachments = Attachment.attach_files(@reply, params[:attachments])
render_attachment_warning_if_needed(@reply)
else
#render file: 'messages#show', layout: 'base_courses'
end
if params[:is_board]
if params[:user_activity_id]
@user_activity_id = params[:user_activity_id]
respond_to do |format|
format.js
end
elsif params[:is_board]
if @project
redirect_to project_boards_path(@project)
elsif @course

@ -137,7 +137,7 @@ class MyController < ApplicationController
@se.identity = params[:identity].to_i if params[:identity]
@se.technical_title = params[:technical_title] if params[:technical_title]
@se.student_id = params[:no] if params[:no]
@se.brief_introduction = params[:brief_introduction]
# @se.brief_introduction = params[:brief_introduction]
@se.description = params[:description]
if @user.save && @se.save
@ -157,7 +157,7 @@ class MyController < ApplicationController
File.delete(diskfile1) if File.exist?(diskfile1)
end
render :layout=>'base_users_new'
render :layout=>'new_base_user'
end
# Destroys user's account
@ -174,7 +174,7 @@ class MyController < ApplicationController
logout_user
flash.now[:notice] = l(:notice_account_deleted)
end
redirect_to home_url
redirect_to signin_path
end
end

@ -72,7 +72,7 @@ class NewsController < ApplicationController
@news_count = scope.count
@q = params[:subject]
if params[:subject].nil?
if params[:subject].nil? || params[:subject].blank?
scope_order = scope.all(:include => [:author, :course],
:order => "#{News.table_name}.created_on DESC")
else
@ -99,6 +99,33 @@ class NewsController < ApplicationController
end
def show
# 更新news对应的forge_messages的消息viewed字段
if @project
query_message_news = @news.forge_messages
else
query_message_news = @news.course_messages
end
query_message_news.each do |query|
if User.current.id == query.user_id
query.update_attributes(:viewed => true)
end
end
# 更新项目新闻的评阅的消息viewed字段
current_message_comments = @news.comments
current_message_comments.each do |current_message_comment|
if @project
query_message_comment = current_message_comment.forge_messages
else
query_message_comment = current_message_comment.course_messages
end
query_message_comment.each do |query|
if User.current.id == query.user_id
query.update_attributes(:viewed => true)
end
end
end
# end
cs = CoursesService.new
result = cs.show_course_news params,User.current
@news = result[:news]
@ -148,19 +175,19 @@ class NewsController < ApplicationController
update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS
end
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add start
teachers = searchTeacherAndAssistant(@course)
for teacher in teachers
if(teacher.user_id != User.current.id)
notify = ActivityNotify.new()
notify.activity_container_id = @course.id
notify.activity_container_type = 'Course'
notify.activity_id = @news.id
notify.activity_type = 'News'
notify.notify_to = teacher.user_id
notify.is_read = 0
notify.save()
end
end
# teachers = searchTeacherAndAssistant(@course)
# for teacher in teachers
# if(teacher.user_id != User.current.id)
# notify = ActivityNotify.new()
# notify.activity_container_id = @course.id
# notify.activity_container_type = 'Course'
# notify.activity_id = @news.id
# notify.activity_type = 'News'
# notify.notify_to = teacher.user_id
# notify.is_read = 0
# notify.save()
# end
# end
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add end
render_attachment_warning_if_needed(@news)
flash[:notice] = l(:notice_successful_create)

@ -1,3 +1,4 @@
#encoding utf-8
class PollController < ApplicationController
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:republish_poll,:poll_result,:close_poll,:export_poll]
before_filter :find_container, :only => [:new,:create, :index]
@ -27,6 +28,13 @@ class PollController < ApplicationController
render_403
return
end
# 问卷消息状态更新
query_course_poll = @poll.course_messages
query_course_poll.each do |query|
if User.current.id == query.user_id
query.update_attributes(:viewed => true)
end
end
#已提交问卷的用户不能再访问该界面
if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?)
redirect_to poll_index_url(:polls_type => "Course", :polls_group_id => @course.id)
@ -410,6 +418,70 @@ class PollController < ApplicationController
end
end
# 将其他地方的问卷导出来
def other_poll
# 查作者是我,或者作者是当前课程的老师,且不在当前课程内的问卷 进行导入
tea_ids = '('
tea_ids << Course.find(params[:polls_group_id]).tea_id.to_s << ','<< User.current.id.to_s << ')'
@polls = Poll.where("user_id in #{tea_ids} and polls_type = 'course' and polls_group_id != #{params[:polls_group_id]}")
@polls_group_id = params[:polls_group_id]
respond_to do |format|
format.js
end
end
# 将问卷导入本课程
def import_other_poll
course_id = params[:course_id]
@course = Course.find(course_id)
params[:polls].each_with_index do |p,i|
poll = Poll.find(p)
option = {
:polls_name => poll.polls_name || l(:label_poll_new),
:polls_type => 'Course',
:polls_group_id => course_id,
:polls_status => 1,
:user_id => User.current.id,
:published_at => Time.now,
:closed_at => Time.now,
:show_result => 1,
:polls_description => poll.polls_description
}
@poll = Poll.create option
poll.poll_questions.each do | q|
#question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
option = {
:is_necessary => q[:is_necessary],
:question_title => q[:question_title],
:question_type => q[:question_type] || 1,
:question_number => q[:question_number]
}
@poll_questions = @poll.poll_questions.new option
for i in 1..q.poll_answers.count
answer = q.poll_answers[i-1].nil? ? l(:label_new_answer) : q.poll_answers[i-1][:answer_text]
question_option = {
:answer_position => i,
:answer_text => answer
}
@poll_questions.poll_answers.new question_option
end
end
@poll.save
end
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
if @is_teacher
polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}")
else
polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2")
end
@polls = paginateHelper polls,20 #分页
respond_to do |format|
format.js
end
end
private
def find_poll_and_course
@poll = Poll.find params[:id]

File diff suppressed because it is too large Load Diff

@ -207,7 +207,7 @@ class SoftapplicationsController < ApplicationController
@softapplication.destroy
respond_to do |format|
format.html { redirect_to home_url }
format.html { redirect_to signin_path }
format.json { head :no_content }
end
end

File diff suppressed because it is too large Load Diff

@ -0,0 +1,95 @@
class SystemMessagesController < ApplicationController
# before_filter :message_author, :only => [:show]
#
# def message_author
# if(!User.current.logged? && !token.nil?)
#
# User.current =try_to_autologin1
# end
# if @system_messages
# render_403 :message => :notice_not_authorized_message
# else
# deny_access
# end
# end
def index
@system_messages = SystemMessage.all
end
# def show
# @system_messages = SystemMessage.find(params[:id])
# end
# GET /products/new
# def new
# @product = Product.new
# end
# GET /products/1/edit
# def edit
# end
# POST /products
# POST /products.json
def create
unless User.current.admin?
render_403
return
end
@system_messages = SystemMessage.new
@system_messages.description = params[:system_message][:description]
@system_messages.subject = params[:system_message][:subject]
@system_messages.user_id = User.current.id
respond_to do |format|
if @system_messages.save
format.html {redirect_to user_system_messages_path(User.current)}
flash[:notice] = l(:notice_successful_message)
else
if params[:system_messages][:description].empty?
flash[:error] = l(:label_content_blank_fail)
else
flash[:error] = l(:label_admin_message_fail)
end
format.html {redirect_to admin_messages_path}
end
end
end
# PATCH/PUT /products/1
# PATCH/PUT /products/1.json
# def update
# respond_to do |format|
# if @product.update(product_params)
# format.html { redirect_to @product, notice: 'Product was successfully updated.' }
# format.json { render :show, status: :ok, location: @product }
# else
# format.html { render :edit }
# format.json { render json: @product.errors, status: :unprocessable_entity }
# end
# end
# end
# DELETE /products/1
# DELETE /products/1.json
# def destroy
# @system_messages.destroy
# respond_to do |format|
# format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
# format.json { head :no_content }
# end
# end
# private
# # Use callbacks to share common setup or constraints between actions.
# def set_product
# @product = Product.find(params[:id])
# end
#
# # Never trust parameters from the scary internet, only allow the white list through.
# def message_params
# params.require(:admin_system_messages).permit(:content)
# end
end

@ -15,6 +15,7 @@ class TagsController < ApplicationController
include ContestsHelper
include ActsAsTaggableOn::TagsHelper
include TagsHelper
include FilesHelper
helper :projects
helper :courses
helper :tags
@ -230,6 +231,103 @@ class TagsController < ApplicationController
end
end
#更新某个tag名称
def update_tag_name
@tag_name = params[:tagName]
@rename_tag_name = params[:renameName]
@taggable_id = params[:taggableId]
@taggable_type = numbers_to_object_type(params[:taggableType])
@course_id = params[:courseId]
@rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank?
@obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank?
if @taggable_id.blank? #如果没有传tag_id那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。
if @course_id
course = Course.find @course_id
if course
course.attachments.each do |attachment|
taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class)
if taggings
taggings.delete
attachment.tag_list.add(@rename_tag_name.split(","))
attachment.save
end
end
end
end
else
if(@rename_tag.nil?) #这次命名的是新的tag
# 是否还有其他记录 引用了 tag_id
@tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}")
# 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字
if @tagging.count == 1
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
@tag.update_attributes({:name=>@rename_tag_name})
else #如果tagging表中的记录大于1那么就要新增tag记录
unless @obj.nil?
@obj.tag_list.add(@rename_tag_name.split(","))
@obj.save
end
#删除原来的对应的taggings的记录
unless @taggings.nil?
@taggings.delete
end
end
else #这是已有的tag
# 更改taggings记录里的tag_id
unless @taggings.nil?
@taggings.update_attributes({:tag_id=>@rename_tag.id})
end
end
end
@obj_flag = params[:taggableType]
if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course)
@course = @obj.container
@tag_list = @tag_list = get_course_tag_list @course
elsif @course_id
@course = Course.find(@course_id)
@tag_list = get_course_tag_list @course
#这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。
@flag = params[:flag] || false
sort = ""
@sort = ""
@order = ""
@is_remote = false
@isproject = false
sort = "#{Attachment.table_name}.created_on desc"
@containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
show_attachments @containers
elsif @obj && @obj_flag == '5'
@forum = @obj
end
respond_to do |format|
format.js
end
end
def show_attachments obj
@attachments = []
obj.each do |container|
@attachments += container.attachments
end
@all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments)
@limit = 10
@feedback_count = @all_attachments.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
#@curse_attachments_all = @all_attachments[@offset, @limit]
@obj_attachments = paginateHelper @all_attachments,10
end
def tag_save
@select_tag_name = params[:tag_for_save][:tag_name]
@tags = params[:tag_for_save][:name]

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save