This commit is contained in:
Your Name 2019-01-25 09:44:12 +08:00
commit 1f35bc49d2
411 changed files with 54585 additions and 45892 deletions

View File

@ -35,7 +35,7 @@ module Mobile
def authenticate!
begin
raise('Unauthorized. 用户认证失败.') unless current_user
# current_user = User.find(2) if current_user.blank?
rescue Exception => e
return {:status => -2, :message => 'Unauthorized. 用户认证失败.'}
end
@ -68,13 +68,16 @@ module Mobile
# 本地调试找不到用户信息
if Rails.env.development? && session[:user_id].blank?
session[:user_id] = 12 #116
# session[:user_id] = 12 #116
end
if session[:user_id].blank?
session[:user_id] = 2
end
Rails.logger.info("####### session user_id is #{session[:user_id]}")
if session[:user_id]
user = (User.active.find(session[:user_id]) rescue nil)
user = (User.find(session[:user_id]) rescue nil)
return user if user
end
nil

View File

@ -7,6 +7,15 @@ module Mobile
resources :memos do
desc "讨论区的footer"
get :footer do
tel = PublicProperty.where(:property => "Tel").first.try(:value)
email = PublicProperty.where(:property => "Email").first.try(:value)
addr = PublicProperty.where(:property => "Address").first.try(:value)
copyright = PublicProperty.where(:property => "Copyright").first.try(:value)
{tel:tel, email:email, addr:addr, copyright:copyright}
end
desc "新建帖子"
get 'new' do
MemosService.new.new current_user, session
@ -17,8 +26,8 @@ module Mobile
requires :memo, type: Hash do
requires :subject, type: String, desc: "帖子名"
requires :content, type: String, desc: "帖子内容"
requires :forum_id, type: Integer, desc: "帖子类型"
end
requires :forum_id, type: Array, desc: "帖子类型"
end
post 'create' do
MemosService.new.create params, current_user
@ -123,7 +132,6 @@ module Mobile
MemosService.new.more_reply params, current_user
end
end
end
end
end

View File

@ -101,7 +101,7 @@ class AccountController < ApplicationController
end
def help
@index = params[:index].to_i == 0 ? 1 : params[:index].to_i
@index = params[:index].to_i == 0 ? 4 : params[:index].to_i
if @index == 6 && !User.current.logged?
redirect_to signin_path
return
@ -385,13 +385,6 @@ class AccountController < ApplicationController
@pref = @user.pref
@se = @user.extensions
# 已授权的用户修改单位名称,需要重新授权
if @se.school_id != params[:occupation].to_i && @user.certification == 1
@user.certification = 0
apply_user = ApplyAction.where(:user_id => @user.id, :container_type => "TrialAuthorization")
apply_user.update_all(:status => 2) unless apply_user.blank?
end
@user.lastname = params[:lastname]
@user.firstname = ""
@user.show_realname = params[:hide_realname] ? 0 : 1
@ -422,35 +415,10 @@ class AccountController < ApplicationController
reward_grade(@user, @user.id, 'Account', 500)
if @user.certification != 1
school_ids = School.where(:auto_users_trial => 1).map(&:id)
# 授权单位中的老师、学生自动授权,且创建试用授权记录
if (@se.identity == 0 || (@se.identity == 1 && !@se.student_id.blank?)) && !@se.school.nil? && school_ids.include?(@se.school_id)
@user.update_attributes(:certification => 1)
apply_action = ApplyAction.where(:user_id => @user.id, :container_type => "TrialAuthorization", :status => 0).first
if apply_action.present?
apply_action.update_attributes(:status => 1, :noticed => 1)
else
ApplyAction.create(:user_id => @user.id, :container_type => "TrialAuthorization", :status => 1, :noticed => 1)
end
# 授权的教师加入示例课堂
join_ex_course(@user) if @se.identity == 0
end
end
@user.pref.save
set_language_if_valid @user.language
flash[:notice] = l(:notice_account_updated)
first_update = Grade.where(:user_id => @user.id, :container_id => @user.id, :container_type => 'Account').first
if @user.certification == 1 || (Time.now.to_i - first_update.created_at.to_i) < 86400
if @user.certification != 1 && !@user.user_day_certifications.first.present? # 更新字段是为了在user页面弹框提示
@user.update_attributes(:certification => 3)
UserDayCertification.create(:user_id => @user.id, :status => 1)
end
redirect_to user_path(@user)
else
redirect_to my_account_url
end
redirect_to user_path(@user)
return
else
@user.login = lg

View File

@ -17,7 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AdminController < ApplicationController
layout 'forge'
layout 'forge'
# menu_item :projects, :only => :projects
# menu_item :plugins, :only => :plugins
# menu_item :info, :only => :info

View File

@ -239,6 +239,7 @@ class ApplicationController < ActionController::Base
end
def require_login
logger.info("#########################")
if !User.current.logged?
# Extract only the basic url parameters on non-GET requests
if request.get?
@ -304,6 +305,7 @@ class ApplicationController < ActionController::Base
end
end
end
def auth_login1(token = params[:token])
Rails.logger.info("##auth_login1 start")
if(!User.current.logged? && !token.nil?)
@ -311,12 +313,15 @@ class ApplicationController < ActionController::Base
User.current =try_to_autologin1
end
end
def authorize_allowed(ctrl = params[:controller], action = params[:action], global = false)
#modify by NWB
if @project
if ctrl == "repositories" && action == "show" && @project.hidden_repo
Rails.logger.info("authorize_allowed start")
allowed = User.current.admin? || (User.current.member_of?(@project) && !(role_of_members_in_project(@project.id, User.current.id) == "Reporter"))
else
Rails.logger.info("authorize_allowed start2")
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
end
elsif @course
@ -559,7 +564,7 @@ class ApplicationController < ActionController::Base
return
end
@project = nil
render_error({:message => :notice_not_authorized, :status => 403}.merge(options),'common/403')
render_error({:message => :notice_not_authorized, :status => 403, :layout => "forge"}.merge(options),'common/403')
#render :template => 'common/403'
return false
end
@ -569,7 +574,7 @@ class ApplicationController < ActionController::Base
redirect_to signin_url
return
end
render_error({:message => :notice_file_not_found, :status => 404}.merge(options),'common/404')
render_error({:message => :notice_file_not_found, :status => 404, :layout => "forge"}.merge(options),'common/404')
#render :template => 'common/404'
return false
end
@ -619,7 +624,7 @@ class ApplicationController < ActionController::Base
#
# @return [boolean, string] name of the layout to use or false for no layout
def use_layout
request.xhr? ? false : 'users_base'
request.xhr? ? false : 'forge'
end
def invalid_authenticity_token

View File

@ -83,8 +83,6 @@ class AppliedProjectController < ApplicationController
@project.managers.each do |mem|
Tiding.create(:user_id => mem.user_id, :trigger_user_id => User.current.id, :container_id => @project.id, :container_type => 'ReporterJoinProject', :belong_container_id => @project.id, :belong_container_type => "Project", :tiding_type => "System")
end
# ps = ProjectsService.new
# ps.send_wechat_join_project_notice User.current,@project,5,0
else
@flag = 4
role = params[:member] == "member_manager" ? 3 : (params[:member] == "member_developer" ? 4 :5)

View File

@ -17,6 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AttachmentsController < ApplicationController
skip_before_filter :session_expiration, :only => [:download]
layout "users_base"
before_filter :verify_authenticity_token, only: [:upload]
@ -26,7 +27,7 @@ class AttachmentsController < ApplicationController
before_filter :delete_authorize, :only => [:destroy]
before_filter :authorize_global, :only => [:upload]
#before_filter :authorize_attachment_download1, :only => [:download]
before_filter :has_login
before_filter :has_login, :except => [:download, :direct_download]
#before_filter :login_without_softapplication, only: [:download]
accept_api_auth :show, :download, :upload
require 'iconv'
@ -185,8 +186,8 @@ class AttachmentsController < ApplicationController
def download
# modify by nwb
# 下载添加权限设置
candown = attachment_candown @attachment
candown = (@attachment.container_type == 'Memo' ? true : attachment_candown(@attachment))
logger.info("################下载权限: #{candown}")
if candown || User.current.admin? || User.current.id == @attachment.author_id
if stale?(:etag => @attachment.digest)
if params[:preview] == 'true'
@ -213,8 +214,7 @@ class AttachmentsController < ApplicationController
else
render_403 :message => :notice_not_authorized
end
rescue => e
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
end
#更新资源文件类型
@ -327,7 +327,6 @@ class AttachmentsController < ApplicationController
render :nothing => true, :status => 406
return
end
@attachment = Attachment.new(:file => request.raw_post)
@attachment.author = User.current
if !params[:project].nil?
@ -350,17 +349,11 @@ class AttachmentsController < ApplicationController
end
def upload_memo_heads
logger.debug "upload_memo_heads"
@attachment = Attachment.new(:file => request.raw_post)
@attachment = Attachment.new(:file => params[:file])
@attachment.author = User.current
if params[:container_type].present?
@attachment.container_type = params[:container_type]
@attachment.container_id = params[:container_id]
end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
@attachment.filename = params[:file].original_filename.presence || Redmine::Utils.random_hex(16)
saved = @attachment.save!
saved
render json: {
success: saved ? 1 : 0, # | 1, // 0 表示上传失败1 表示上传成功
message: "上传信息:#{ @attachment.errors.full_messages.join(',') }",
@ -370,8 +363,8 @@ class AttachmentsController < ApplicationController
end
def upload_with_markdown
logger.debug "upload_with_markdown"
@attachment = Attachment.new(:file => params["editormd-image-file"])
@attachment.author = User.current
# 如果其它类型的条用md必须传类型elsif判断
if params[:container_type].present?
@ -432,9 +425,6 @@ class AttachmentsController < ApplicationController
@course.course_groups.each do |group|
att_group_setting = @old_attachment.attachment_group_settings.where(:course_group_id => group.id).first
unless att_group_setting
att_group_setting = AttachmentGroupSetting.create(:attachment_id => @old_attachment.id, :course_group_id => group.id, :course_id => @course.id, :publish_time => @old_attachment.publish_time)
end
end
@old_attachment.attachment_group_settings.joins(:course_group).reorder("course_groups.name asc").each_with_index do |setting, index|
if params[:attachment_publish_time][index] && params[:attachment_publish_time][index] != ""
@ -497,59 +487,15 @@ class AttachmentsController < ApplicationController
if @attachment.container.respond_to?(:init_journal)
@attachment.container.init_journal(User.current)
end
if @attachment.container
if @attachment.container_type == "Issue"
@attachment.destroy
else
@attachment.container.attachments.delete(@attachment)
end
else
@attachment.delete
end
@attachment.destroy
end
respond_to do |format|
if !@attachment.container.nil? &&
(@attachment.container.is_a?(Course) || ((@attachment.container.has_attribute?(:course) || @attachment.container.has_attribute?(:course_id) ) &&
@attachment.container.course ) || ((@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) &&
@attachment.container.board && @attachment.container.board.course ) || @attachment.container.is_a?(StudentWorksScore) || @attachment.container.is_a?(HomeworkCommon) ||
@attachment.container.is_a?(StudentWork))
if @attachment.container.is_a?(News)
format.html { redirect_to_referer_or news_path(@attachment.container) }
elsif @attachment.container.is_a?(StudentWorksScore)
@is_destroy = true unless params[:attachment_id] #根据ID删除页面对应的数据js刷新页面
format.js
elsif @attachment.container.is_a?(HomeworkCommon)
@is_destroy = true unless params[:attachment_id] #根据ID删除页面对应的数据js刷新页面
format.js
elsif @attachment.container.is_a?(StudentWork)
@is_destroy = true unless params[:attachment_id] #根据ID删除页面对应的数据js刷新页面
format.js
elsif @attachment.container.is_a?(Message)
format.html { redirect_to_referer_or new_board_message_path(@attachment.container) }
elsif @course.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
else
format.html { redirect_to_referer_or course_path(@course) }
end
elsif !@attachment.container.nil? && @attachment.container.is_a?(Softapplication)
format.html { redirect_to_referer_or softapplications_path(@attachment.container) }
elsif !@attachment.container.nil? && @attachment.container.is_a?(Bid)
format.html { redirect_to_referer_or respond_path(@attachment.container) }
elsif !@attachment.container.nil? && @attachment.container.is_a?(PhoneAppVersion)
format.html { redirect_to_referer_or mobile_version_path }
elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgSubfield)
format.html {redirect_to_referer_or org_subfield_files_path(@attachment.container)}
elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgDocumentComment)
format.html {redirect_to_referer_or org_document_comment_path(@attachment.container)}
if @project.nil?
format.html { redirect_to_referer_or forum_path(@attachment.container) }
else
if @project.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
else
format.html { redirect_to_referer_or project_path(@project) }
end
format.html { redirect_to_referer_or project_path(@project) }
end
format.js
end
end
@ -688,26 +634,14 @@ class AttachmentsController < ApplicationController
# Show 404 if the filename in the url is wrong
# modify by nwb
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
if @attachment.container_type == 'Course'
@course = @attachment.course
elsif !@attachment.container.nil? && (@attachment.container.has_attribute?(:course) || @attachment.container.has_attribute?(:course_id)) && @attachment.container.course
@course = @attachment.container.course
elsif !@attachment.container.nil? && ((@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
@attachment.container.board.course)
@course = @attachment.container.board.course
elsif !@attachment.container.nil? && ((@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
@attachment.container.board.contest)
@contest = @attachment.container.board.contest
elsif @attachment.container_type == 'Shixun'
@shixun
elsif @attachment.container_type == 'Inform'
@inform = @attachment.container
elsif @attachment.container_type == 'Challenge'
@challenge = @attachment.container
if @attachment.container_type == 'Memo'
@memo = @attachment.container
elsif @attachment.container_type == 'IssueImage'
@project = Issue.find(@attachment.container_id).project
elsif @attachment.container_type == 'ProjectImage'
@project = Project.find(@attachment.container_id)
else
unless @attachment.container_type == 'Syllabus' || @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' || @attachment.container_type == 'Work'|| @attachment.container_type == 'ContestantWork'|| @attachment.container_type == 'Contest' || @attachment.container_type == 'HomeworkBank'
@project = @attachment.project
end
@project = @attachment.project
end
rescue ActiveRecord::RecordNotFound
render_404

View File

@ -0,0 +1,709 @@
#encoding: utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AttachmentsController < ApplicationController
skip_before_filter :session_expiration, :only => [:download]
layout "users_base"
before_filter :verify_authenticity_token, only: [:upload]
before_filter :find_project, :only => [:show, :download, :thumbnail, :destroy]#, :except => [:upload, :autocomplete]
before_filter :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young
before_filter :delete_authorize, :only => [:destroy]
before_filter :authorize_global, :only => [:upload]
#before_filter :authorize_attachment_download1, :only => [:download]
before_filter :has_login, :except => [:download, :direct_download]
#before_filter :login_without_softapplication, only: [:download]
accept_api_auth :show, :download, :upload
require 'iconv'
include AttachmentsHelper
include ApplicationHelper
def show
respond_to do |format|
format.html {
if @attachment.is_diff?
@diff = File.new(@attachment.diskfile, "rb").read
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
# Save diff type as user preference
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
User.current.pref[:diff_type] = @diff_type
User.current.preference.save
end
render :action => 'diff'
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
@content = File.new(@attachment.diskfile, "rb").read
# 编码为非 UTF-8先进行间接转码
# 部分unicode编码不直接支持转为 UTF-8
# modify by nwb
if @content.encoding.name != 'UTF-8'
@content = @content.force_encoding('GBK')
@content = @content.encode('UTF-8')
end
render :action => 'file'
else
download
end
}
format.api
end
rescue Encoding::InvalidByteSequenceError => e
render :action => 'file'
end
def pdf?(file)
file.downcase.end_with?(".pdf")
end
def get_image_type
image = Attachment.find(params[:id])
image_type = image.content_type.split("/")[1]
render :json => {type: image_type}
end
def direct_download
@attachment.increment_download
file_type = detect_content_type(@attachment)
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
:type => file_type,
:disposition => 'attachment' #inline can open in browser
end
def direct_download_resource
@resource = ResourceBank.find(params[:id])
storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files")
file = File.join(storage_path, @resource.disk_directory.to_s, @resource.disk_filename.to_s)
send_file file, :filename => filename_for_content_disposition(@resource.filename),
:type => detect_content_type(@resource),
:disposition => 'attachment' #inline can open in browser
@resource.increment!(:downloads)
end
def download_resource
@resource = ResourceBank.find(params[:id])
candown = resource_bank_candown @resource, params[:type]
if candown
if stale?(:etag => @resource.digest)
if params[:preview] == 'true'
storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files")
convered_file = File.join(storage_path, @resource.disk_directory.to_s, @resource.disk_filename.to_s)
#如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
unless pdf?(convered_file)
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
unless File.exist?(convered_file)
office = Trustie::Utils::Office.new(File.join(storage_path, @resource.disk_directory.to_s, @resource.disk_filename.to_s))
office.conver(convered_file)
end
end
if File.exist?(convered_file) && pdf?(convered_file)
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
else
direct_download_resource
end
else
# 记录用户行为
record_user_actions(params[:id])
# 直接下载历史版本
direct_download_resource
end
end
else
render_403 :message => :notice_not_authorized
end
rescue => e
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
end
def direct_download_history
@attachment_history = AttachmentHistory.find(params[:id])
@attachment_history.increment_download
send_file @attachment_history.diskfile_history, :filename => filename_for_content_disposition(@attachment_history.filename),
:type => detect_content_type(@attachment_history),
:disposition => 'attachment' #inline can open in browser
end
def download_history
@attachment_history = AttachmentHistory.find(params[:id])
candown = attachment_history_candown @attachment_history
if candown || User.current.admin? || User.current.id == @attachment_history.author_id
if stale?(:etag => @attachment_history.digest)
if params[:preview] == 'true'
convered_file = @attachment_history.diskfile_history
#如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
unless pdf?(convered_file)
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
unless File.exist?(convered_file)
office = Trustie::Utils::Office.new(@attachment_history.diskfile)
office.conver(convered_file)
end
end
if File.exist?(convered_file) && pdf?(convered_file)
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
else
direct_download_history
end
else
# 记录用户行为
record_user_actions(params[:id])
# 直接下载历史版本
direct_download_history
end
end
else
render_403 :message => :notice_not_authorized
end
rescue => e
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
end
def record_user_actions id
if params[:action] == "download_history"
UserActions.create(:action_id => id, :action_type => "AttachmentHistory", :user_id => User.current.id) unless id.nil?
elsif params[:action] == "download"
UserActions.create(:action_id => id, :action_type => "Attachment", :user_id => User.current.id) unless id.nil?
elsif params[:action] == "download_resource"
UserActions.create(:action_id => id, :action_type => "ResourceBank", :user_id => User.current.id) unless id.nil?
end
end
def download
# modify by nwb
# 下载添加权限设置
candown = (@attachment.container_type == 'Memo' ? true : attachment_candown(@attachment))
logger.info("################下载权限: #{candown}")
if candown || User.current.admin? || User.current.id == @attachment.author_id
if stale?(:etag => @attachment.digest)
if params[:preview] == 'true'
convered_file = @attachment.diskfile
#如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
unless pdf?(convered_file)
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
unless File.exist?(convered_file)
office = Trustie::Utils::Office.new(@attachment.diskfile)
office.conver(convered_file)
end
end
if File.exist?(convered_file) && pdf?(convered_file)
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
else
direct_download
end
else
# 记录用户行为
record_user_actions(params[:id])
direct_download
end
end
else
render_403 :message => :notice_not_authorized
end
end
#更新资源文件类型
def updateType
@attachment = Attachment.find(params[:attachmentid])
if @attachment != nil
@attachment.attachtype = params[:newtype]
@attachment.save
render :text =>'success'
else
render :text=>'error'
end
end
# 更新文件密级
def updateFileDense
@attachment = Attachment.find(params[:attachmentid])
if @attachment != nil
filedense = params[:newtype].to_s
# d = Iconv.conv("unicodebig","utf-8",filedense)
if filedense == "%E5%85%AC%E5%BC%80" #l(:field_is_public)
@attachment.is_public = 1
else
@attachment.is_public = 0
end
@attachment.save
@newfiledense = filedense
end
respond_to do |format|
format.js
end
end
def update_file_dense
@attachment = Attachment.find(params[:attachmentid])
if @attachment != nil
filedense = params[:newtype].to_s
if filedense == "1"
@attachment.is_public = 1
else
@attachment.is_public = 0
end
@attachment.save
@newfiledense = filedense
end
if @attachment.container_type == "Project" || @attachment.container_type == "Course"
tip_attachment_update
end
respond_to do |format|
format.js
end
end
def tip_attachment_update
if params[:course_id]
@tip_all_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id])
@tip_all_public_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id], :is_public => 1)
@tip_all_private_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id], :is_public => 0)
@course = Course.find(params[:course_id])
elsif params[:project_id]
@tip_all_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id])
@tip_all_public_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id], :is_public => 1)
@tip_all_private_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id], :is_public => 0)
@project = Project.find(params[:project_id])
end
@tag_name = params[:tag_name]
@other = params[:other]
unless @tag_name.blank?
if @other
if @project
@tip_all_attachments = @tip_all_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
@tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
@tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
elsif @course
@tip_all_attachments = @tip_all_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') }
@tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') }
@tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') }
end
else
@tip_all_attachments = @tip_all_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)}
@tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)}
@tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)}
end
end
@tip_all_attachments = @tip_all_attachments.count
@tip_all_public_attachments = @tip_all_public_attachments.count
@tip_all_private_attachments = @tip_all_private_attachments.count
end
def thumbnail
if @attachment.thumbnailable? && thumbnail = @attachment.thumbnail(:size => params[:size])
if stale?(:etag => thumbnail)
send_file thumbnail,
:filename => filename_for_content_disposition(@attachment.filename),
:type => detect_content_type(@attachment),
:disposition => 'inline'
end
else
# No thumbnail for the attachment or thumbnail could not be created
render :nothing => true, :status => 404
end
end
def upload
# Make sure that API users get used to set this content type
# as it won't trigger Rails' automatic parsing of the request body for parameters
unless request.content_type == 'application/octet-stream'
render :nothing => true, :status => 406
return
end
@attachment = Attachment.new(:file => request.raw_post)
@attachment.author = User.current
if !params[:project].nil?
@attachment.container_type = 'Project'
@attachment.container_id = params[:project].split("?")[0]
end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
saved = @attachment.save
respond_to do |format|
format.js
format.api {
if saved
render :action => 'upload', :status => :created
else
render_validation_errors(@attachment)
end
}
end
end
def upload_memo_heads
@attachment = Attachment.new(:file => params[:file])
@attachment.author = User.current
@attachment.filename = params[:file].original_filename.presence || Redmine::Utils.random_hex(16)
saved = @attachment.save!
saved
render json: {
success: saved ? 1 : 0, # | 1, // 0 表示上传失败1 表示上传成功
message: "上传信息:#{ @attachment.errors.full_messages.join(',') }",
url: download_attachment_path(@attachment.id), # 上传成功时才返回
attachment_id: @attachment.id
}
end
def upload_with_markdown
@attachment = Attachment.new(:file => params["editormd-image-file"])
@attachment.author = User.current
# 如果其它类型的条用md必须传类型elsif判断
if params[:container_type].present?
@attachment.container_type = params[:container_type]
@attachment.container_id = params[:container_id]
end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
saved = @attachment.save!
saved
render json: {
success: saved ? 1 : 0, # | 1, // 0 表示上传失败1 表示上传成功
message: "上传失败:#{ @attachment.errors.full_messages.join(',') }",
url: download_attachment_path(@attachment.id) # 上传成功时才返回
}
end
def upload_attachment_version
@flag = false
@course = Course.find params[:course_id]
@old_attachment = Attachment.find params[:old_attachment_id]
if params[:attachments]
Attachment.transaction do
#取出当前上传的文件
@attachment = Attachment.find(params[:attachments].first[1][:attachment_id])
#将需要修改的记录保存到历史记录
@history = AttachmentHistory.new
@history.attributes = @old_attachment.attributes.dup.except("id", "resource_bank_id")
@history.attachment_id = params[:old_attachment_id]
#需要更新版本号,需要拿到原来该文件最大的历史版本号
@old_history = @old_attachment.attachment_histories.reorder('version desc').first
@history.version = @old_history.nil? ? 1 : @old_history.version + 1
@history.save #历史记录保存完毕
#将最新保存的记录 数据替换到 需要修改的文件记录
@old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes",'is_publish','publish_time')
@status = @old_attachment.is_publish
@old_attachment.save
#删除当前记录
@attachment.delete
@flag = true
end
end
# 如果附件描述被修改,则保存
if params[:description] && params[:description].strip() != "" && params[:description] != @old_attachment.description
@old_attachment.description = params[:description]
@flag = true
end
if !params[:unified_setting] && params[:attachment_publish_time] && @course.course_groups.count > 1
@old_attachment.unified_setting = 0
min_publish_time = @old_attachment.publish_time ? (format_time @old_attachment.publish_time).to_s : (format_time @old_attachment.created_on).to_s
params[:attachment_publish_time].each do |publish_time|
if publish_time != "" && publish_time < min_publish_time
min_publish_time = publish_time
end
end
@old_attachment.is_publish = min_publish_time > (format_time Time.now).to_s ? 0 : 1
@old_attachment.publish_time = min_publish_time > (format_time @old_attachment.created_on).to_s ? min_publish_time : @old_attachment.created_on
@course.course_groups.each do |group|
att_group_setting = @old_attachment.attachment_group_settings.where(:course_group_id => group.id).first
end
@old_attachment.attachment_group_settings.joins(:course_group).reorder("course_groups.name asc").each_with_index do |setting, index|
if params[:attachment_publish_time][index] && params[:attachment_publish_time][index] != ""
setting.update_column(:publish_time, params[:attachment_publish_time][index])
end
end
@flag = true
elsif params[:publish_time] && params[:publish_time] != ""
@old_attachment.publish_time = params[:publish_time]
@old_attachment.is_publish = 0
@old_attachment.unified_setting = 1
@old_attachment.attachment_group_settings.destroy_all
@flag = true
end
if @old_attachment.is_public == 0 && params[:is_public]
@old_attachment.is_public = 1
@flag = true
end
# tip_attachment_update
@old_attachment.save
respond_to do |format|
format.js
end
end
def update_attachment_publish_time
@attachment = Attachment.find params[:id]
@status = params[:status].to_i
if @status == 0
@attachment.update_attributes(:is_publish => 1, :publish_time => Time.now)
end
end
# prams[:type] => history 历史版本
def destroy
if params[:type] == "history"
begin
AttachmentHistory.find(params[:history_id]).destroy
@attachment = Attachment.find(params[:id])
@is_history = true
@is_history_destroy = false
@attachment_histories = @attachment.attachment_histories
rescue Exception => e
puts e
end
elsif params[:type] == "history_delete"
begin
AttachmentHistory.find(params[:history_id]).destroy
@attachment = Attachment.find(params[:id])
@is_history_delete = true
@is_history_destroy = false
@attachment_histories = @attachment.attachment_histories
@attachment_histories_count = @attachment_histories.count
rescue Exception => e
puts e
end
else
@history = params[:history]
if @attachment.container.respond_to?(:init_journal)
@attachment.container.init_journal(User.current)
end
<<<<<<< Temporary merge branch 1
@attachment.delete
=======
@attachment.destroy
>>>>>>> Temporary merge branch 2
end
respond_to do |format|
if @project.nil?
format.html { redirect_to_referer_or forum_path(@attachment.container) }
else
format.html { redirect_to_referer_or project_path(@project) }
end
format.js
end
end
def autocomplete
# modify by nwb
if params[:project_id]
@project = Project.find_by_id(params[:project_id])
elsif params[:course_id]
@course = Course.find_by_id(params[:course_id])
end
respond_to do |format|
format.js
end
end
def add_exist_file_to_project
classname = params[:class_name]
class_id = params[:class_id]
attachments = params[:attachment][:attach]
obj = Object.const_get(classname).find_by_id(class_id)
attachments.collect do |attach_id|
ori = Attachment.find_by_id(attach_id)
next if ori.blank?
attach_copied_obj = ori.copy
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
attach_copied_obj.container = obj
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 1
end
@obj = obj
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:error_attachment_empty)
respond_to do |format|
format.js
end
end
def add_exist_file_to_projects
file = Attachment.find(params[:file_id])
projects = params[:projects][:project]
@message = ""
projects.each do |project|
c = Project.find(project);
if project_contains_attachment?(c,file)
if @message && @message == ""
@message += l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
else
@message += "<br/>" + l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
end
end
attach_copied_obj = file.copy
attach_copied_obj.tag_list.add(file.tag_list) # tag关联
attach_copied_obj.container = c
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
@obj = c
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
update_quotes attach_copied_obj
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:label_project_empty_select)
respond_to do |format|
format.js
end
end
def update_quotes attachment
if attachment.copy_from
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
else
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}")
end
attachment.quotes = get_qute_number attachment
attachment.save
attachments.each do |att|
att.quotes = attachment.quotes
att.save
end
end
#找到文件的所有的历史版本
def attachment_versions
@history = params[:history]
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
respond_to do |format|
format.js
end
end
def attachment_versions_delete
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
@attachment_histories_count = @attachment_histories.count
respond_to do |format|
format.js
end
end
#找到文件的所有的历史版本及当前版本
def attachment_history_download
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
respond_to do |format|
format.js
end
end
private
def find_project
@attachment = Attachment.find(params[:id])
# Show 404 if the filename in the url is wrong
# modify by nwb
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
if @attachment.container_type == 'Memo'
@memo = @attachment.container
<<<<<<< Temporary merge branch 1
else
=======
elsif @attachment.container_type == 'IssueImage'
@project = Issue.find(@attachment.container_id).project
elsif @attachment.container_type == 'ProjectImage'
@project = Project.find(@attachment.container_id)
else
>>>>>>> Temporary merge branch 2
@project = @attachment.project
end
rescue ActiveRecord::RecordNotFound
render_404
end
# Checks that the file exists and is readable
def file_readable
if @attachment.readable?
true
else
logger.error "Cannot send attachment, #{@attachment.diskfile} does not exist or is unreadable."
render_404
end
end
def read_authorize
if @attachment.container_type == "HomeworkAttach" || @attachment.container_type == 'Bid'
true
#User.current.allowed_to?(:view_homework_attaches, @attachment.project) ? true : deny_access
else
@attachment.visible? ? true : deny_access
end
end
def delete_authorize
@attachment.deletable? ? true : deny_access
end
def detect_content_type(attachment)
content_type = attachment.content_type
if content_type.blank?
content_type = Redmine::MimeType.of(attachment.filename)
end
content_type.to_s
end
def login_without_softapplication
referer = request.headers['Referer']
require_login unless referer =~ /softapplication/ || @attachment.container_type == "Memo"
end
def renderTag
@attachmentNew = Attachment.find(params[:attchmentId])
respond_to do |format|
format.js
end
end
def has_login
unless (@attachment && @attachment.container_type == "Organization").nil?
unless (@attachment && @attachment.container_type == "PhoneAppVersion").nil?
render_403 if (!User.current.logged? && !(params[:type] && params[:type] == "wechat")) && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download)
end
end
end
end

View File

@ -0,0 +1,700 @@
#encoding: utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AttachmentsController < ApplicationController
skip_before_filter :session_expiration, :only => [:download]
layout "users_base"
before_filter :verify_authenticity_token, only: [:upload]
before_filter :find_project, :only => [:show, :download, :thumbnail, :destroy]#, :except => [:upload, :autocomplete]
before_filter :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young
before_filter :delete_authorize, :only => [:destroy]
before_filter :authorize_global, :only => [:upload]
#before_filter :authorize_attachment_download1, :only => [:download]
before_filter :has_login, :except => [:download, :direct_download]
#before_filter :login_without_softapplication, only: [:download]
accept_api_auth :show, :download, :upload
require 'iconv'
include AttachmentsHelper
include ApplicationHelper
def show
respond_to do |format|
format.html {
if @attachment.is_diff?
@diff = File.new(@attachment.diskfile, "rb").read
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
# Save diff type as user preference
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
User.current.pref[:diff_type] = @diff_type
User.current.preference.save
end
render :action => 'diff'
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
@content = File.new(@attachment.diskfile, "rb").read
# 编码为非 UTF-8先进行间接转码
# 部分unicode编码不直接支持转为 UTF-8
# modify by nwb
if @content.encoding.name != 'UTF-8'
@content = @content.force_encoding('GBK')
@content = @content.encode('UTF-8')
end
render :action => 'file'
else
download
end
}
format.api
end
rescue Encoding::InvalidByteSequenceError => e
render :action => 'file'
end
def pdf?(file)
file.downcase.end_with?(".pdf")
end
def get_image_type
image = Attachment.find(params[:id])
image_type = image.content_type.split("/")[1]
render :json => {type: image_type}
end
def direct_download
@attachment.increment_download
file_type = detect_content_type(@attachment)
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
:type => file_type,
:disposition => 'attachment' #inline can open in browser
end
def direct_download_resource
@resource = ResourceBank.find(params[:id])
storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files")
file = File.join(storage_path, @resource.disk_directory.to_s, @resource.disk_filename.to_s)
send_file file, :filename => filename_for_content_disposition(@resource.filename),
:type => detect_content_type(@resource),
:disposition => 'attachment' #inline can open in browser
@resource.increment!(:downloads)
end
def download_resource
@resource = ResourceBank.find(params[:id])
candown = resource_bank_candown @resource, params[:type]
if candown
if stale?(:etag => @resource.digest)
if params[:preview] == 'true'
storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files")
convered_file = File.join(storage_path, @resource.disk_directory.to_s, @resource.disk_filename.to_s)
#如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
unless pdf?(convered_file)
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
unless File.exist?(convered_file)
office = Trustie::Utils::Office.new(File.join(storage_path, @resource.disk_directory.to_s, @resource.disk_filename.to_s))
office.conver(convered_file)
end
end
if File.exist?(convered_file) && pdf?(convered_file)
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
else
direct_download_resource
end
else
# 记录用户行为
record_user_actions(params[:id])
# 直接下载历史版本
direct_download_resource
end
end
else
render_403 :message => :notice_not_authorized
end
rescue => e
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
end
def direct_download_history
@attachment_history = AttachmentHistory.find(params[:id])
@attachment_history.increment_download
send_file @attachment_history.diskfile_history, :filename => filename_for_content_disposition(@attachment_history.filename),
:type => detect_content_type(@attachment_history),
:disposition => 'attachment' #inline can open in browser
end
def download_history
@attachment_history = AttachmentHistory.find(params[:id])
candown = attachment_history_candown @attachment_history
if candown || User.current.admin? || User.current.id == @attachment_history.author_id
if stale?(:etag => @attachment_history.digest)
if params[:preview] == 'true'
convered_file = @attachment_history.diskfile_history
#如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
unless pdf?(convered_file)
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
unless File.exist?(convered_file)
office = Trustie::Utils::Office.new(@attachment_history.diskfile)
office.conver(convered_file)
end
end
if File.exist?(convered_file) && pdf?(convered_file)
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
else
direct_download_history
end
else
# 记录用户行为
record_user_actions(params[:id])
# 直接下载历史版本
direct_download_history
end
end
else
render_403 :message => :notice_not_authorized
end
rescue => e
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
end
def record_user_actions id
if params[:action] == "download_history"
UserActions.create(:action_id => id, :action_type => "AttachmentHistory", :user_id => User.current.id) unless id.nil?
elsif params[:action] == "download"
UserActions.create(:action_id => id, :action_type => "Attachment", :user_id => User.current.id) unless id.nil?
elsif params[:action] == "download_resource"
UserActions.create(:action_id => id, :action_type => "ResourceBank", :user_id => User.current.id) unless id.nil?
end
end
def download
# modify by nwb
# 下载添加权限设置
candown = (@attachment.container_type == 'Memo' ? true : attachment_candown(@attachment))
logger.info("################下载权限: #{candown}")
if candown || User.current.admin? || User.current.id == @attachment.author_id
if stale?(:etag => @attachment.digest)
if params[:preview] == 'true'
convered_file = @attachment.diskfile
#如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
unless pdf?(convered_file)
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
unless File.exist?(convered_file)
office = Trustie::Utils::Office.new(@attachment.diskfile)
office.conver(convered_file)
end
end
if File.exist?(convered_file) && pdf?(convered_file)
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
else
direct_download
end
else
# 记录用户行为
record_user_actions(params[:id])
direct_download
end
end
else
render_403 :message => :notice_not_authorized
end
end
#更新资源文件类型
def updateType
@attachment = Attachment.find(params[:attachmentid])
if @attachment != nil
@attachment.attachtype = params[:newtype]
@attachment.save
render :text =>'success'
else
render :text=>'error'
end
end
# 更新文件密级
def updateFileDense
@attachment = Attachment.find(params[:attachmentid])
if @attachment != nil
filedense = params[:newtype].to_s
# d = Iconv.conv("unicodebig","utf-8",filedense)
if filedense == "%E5%85%AC%E5%BC%80" #l(:field_is_public)
@attachment.is_public = 1
else
@attachment.is_public = 0
end
@attachment.save
@newfiledense = filedense
end
respond_to do |format|
format.js
end
end
def update_file_dense
@attachment = Attachment.find(params[:attachmentid])
if @attachment != nil
filedense = params[:newtype].to_s
if filedense == "1"
@attachment.is_public = 1
else
@attachment.is_public = 0
end
@attachment.save
@newfiledense = filedense
end
if @attachment.container_type == "Project" || @attachment.container_type == "Course"
tip_attachment_update
end
respond_to do |format|
format.js
end
end
def tip_attachment_update
if params[:course_id]
@tip_all_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id])
@tip_all_public_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id], :is_public => 1)
@tip_all_private_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id], :is_public => 0)
@course = Course.find(params[:course_id])
elsif params[:project_id]
@tip_all_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id])
@tip_all_public_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id], :is_public => 1)
@tip_all_private_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id], :is_public => 0)
@project = Project.find(params[:project_id])
end
@tag_name = params[:tag_name]
@other = params[:other]
unless @tag_name.blank?
if @other
if @project
@tip_all_attachments = @tip_all_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
@tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
@tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
elsif @course
@tip_all_attachments = @tip_all_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') }
@tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') }
@tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') }
end
else
@tip_all_attachments = @tip_all_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)}
@tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)}
@tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)}
end
end
@tip_all_attachments = @tip_all_attachments.count
@tip_all_public_attachments = @tip_all_public_attachments.count
@tip_all_private_attachments = @tip_all_private_attachments.count
end
def thumbnail
if @attachment.thumbnailable? && thumbnail = @attachment.thumbnail(:size => params[:size])
if stale?(:etag => thumbnail)
send_file thumbnail,
:filename => filename_for_content_disposition(@attachment.filename),
:type => detect_content_type(@attachment),
:disposition => 'inline'
end
else
# No thumbnail for the attachment or thumbnail could not be created
render :nothing => true, :status => 404
end
end
def upload
# Make sure that API users get used to set this content type
# as it won't trigger Rails' automatic parsing of the request body for parameters
unless request.content_type == 'application/octet-stream'
render :nothing => true, :status => 406
return
end
@attachment = Attachment.new(:file => request.raw_post)
@attachment.author = User.current
if !params[:project].nil?
@attachment.container_type = 'Project'
@attachment.container_id = params[:project].split("?")[0]
end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
saved = @attachment.save
respond_to do |format|
format.js
format.api {
if saved
render :action => 'upload', :status => :created
else
render_validation_errors(@attachment)
end
}
end
end
def upload_memo_heads
@attachment = Attachment.new(:file => params[:file])
@attachment.author = User.current
@attachment.filename = params[:file].original_filename.presence || Redmine::Utils.random_hex(16)
saved = @attachment.save!
saved
render json: {
success: saved ? 1 : 0, # | 1, // 0 表示上传失败1 表示上传成功
message: "上传信息:#{ @attachment.errors.full_messages.join(',') }",
url: download_attachment_path(@attachment.id), # 上传成功时才返回
attachment_id: @attachment.id
}
end
def upload_with_markdown
@attachment = Attachment.new(:file => params["editormd-image-file"])
@attachment.author = User.current
# 如果其它类型的条用md必须传类型elsif判断
if params[:container_type].present?
@attachment.container_type = params[:container_type]
@attachment.container_id = params[:container_id]
end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
saved = @attachment.save!
saved
render json: {
success: saved ? 1 : 0, # | 1, // 0 表示上传失败1 表示上传成功
message: "上传失败:#{ @attachment.errors.full_messages.join(',') }",
url: download_attachment_path(@attachment.id) # 上传成功时才返回
}
end
def upload_attachment_version
@flag = false
@course = Course.find params[:course_id]
@old_attachment = Attachment.find params[:old_attachment_id]
if params[:attachments]
Attachment.transaction do
#取出当前上传的文件
@attachment = Attachment.find(params[:attachments].first[1][:attachment_id])
#将需要修改的记录保存到历史记录
@history = AttachmentHistory.new
@history.attributes = @old_attachment.attributes.dup.except("id", "resource_bank_id")
@history.attachment_id = params[:old_attachment_id]
#需要更新版本号,需要拿到原来该文件最大的历史版本号
@old_history = @old_attachment.attachment_histories.reorder('version desc').first
@history.version = @old_history.nil? ? 1 : @old_history.version + 1
@history.save #历史记录保存完毕
#将最新保存的记录 数据替换到 需要修改的文件记录
@old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes",'is_publish','publish_time')
@status = @old_attachment.is_publish
@old_attachment.save
#删除当前记录
@attachment.delete
@flag = true
end
end
# 如果附件描述被修改,则保存
if params[:description] && params[:description].strip() != "" && params[:description] != @old_attachment.description
@old_attachment.description = params[:description]
@flag = true
end
if !params[:unified_setting] && params[:attachment_publish_time] && @course.course_groups.count > 1
@old_attachment.unified_setting = 0
min_publish_time = @old_attachment.publish_time ? (format_time @old_attachment.publish_time).to_s : (format_time @old_attachment.created_on).to_s
params[:attachment_publish_time].each do |publish_time|
if publish_time != "" && publish_time < min_publish_time
min_publish_time = publish_time
end
end
@old_attachment.is_publish = min_publish_time > (format_time Time.now).to_s ? 0 : 1
@old_attachment.publish_time = min_publish_time > (format_time @old_attachment.created_on).to_s ? min_publish_time : @old_attachment.created_on
@course.course_groups.each do |group|
att_group_setting = @old_attachment.attachment_group_settings.where(:course_group_id => group.id).first
end
@old_attachment.attachment_group_settings.joins(:course_group).reorder("course_groups.name asc").each_with_index do |setting, index|
if params[:attachment_publish_time][index] && params[:attachment_publish_time][index] != ""
setting.update_column(:publish_time, params[:attachment_publish_time][index])
end
end
@flag = true
elsif params[:publish_time] && params[:publish_time] != ""
@old_attachment.publish_time = params[:publish_time]
@old_attachment.is_publish = 0
@old_attachment.unified_setting = 1
@old_attachment.attachment_group_settings.destroy_all
@flag = true
end
if @old_attachment.is_public == 0 && params[:is_public]
@old_attachment.is_public = 1
@flag = true
end
# tip_attachment_update
@old_attachment.save
respond_to do |format|
format.js
end
end
def update_attachment_publish_time
@attachment = Attachment.find params[:id]
@status = params[:status].to_i
if @status == 0
@attachment.update_attributes(:is_publish => 1, :publish_time => Time.now)
end
end
# prams[:type] => history 历史版本
def destroy
if params[:type] == "history"
begin
AttachmentHistory.find(params[:history_id]).destroy
@attachment = Attachment.find(params[:id])
@is_history = true
@is_history_destroy = false
@attachment_histories = @attachment.attachment_histories
rescue Exception => e
puts e
end
elsif params[:type] == "history_delete"
begin
AttachmentHistory.find(params[:history_id]).destroy
@attachment = Attachment.find(params[:id])
@is_history_delete = true
@is_history_destroy = false
@attachment_histories = @attachment.attachment_histories
@attachment_histories_count = @attachment_histories.count
rescue Exception => e
puts e
end
else
@history = params[:history]
if @attachment.container.respond_to?(:init_journal)
@attachment.container.init_journal(User.current)
end
@attachment.destroy
end
respond_to do |format|
if @project.nil?
format.html { redirect_to_referer_or forum_path(@attachment.container) }
else
format.html { redirect_to_referer_or project_path(@project) }
end
format.js
end
end
def autocomplete
# modify by nwb
if params[:project_id]
@project = Project.find_by_id(params[:project_id])
elsif params[:course_id]
@course = Course.find_by_id(params[:course_id])
end
respond_to do |format|
format.js
end
end
def add_exist_file_to_project
classname = params[:class_name]
class_id = params[:class_id]
attachments = params[:attachment][:attach]
obj = Object.const_get(classname).find_by_id(class_id)
attachments.collect do |attach_id|
ori = Attachment.find_by_id(attach_id)
next if ori.blank?
attach_copied_obj = ori.copy
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
attach_copied_obj.container = obj
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 1
end
@obj = obj
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:error_attachment_empty)
respond_to do |format|
format.js
end
end
def add_exist_file_to_projects
file = Attachment.find(params[:file_id])
projects = params[:projects][:project]
@message = ""
projects.each do |project|
c = Project.find(project);
if project_contains_attachment?(c,file)
if @message && @message == ""
@message += l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
else
@message += "<br/>" + l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
end
end
attach_copied_obj = file.copy
attach_copied_obj.tag_list.add(file.tag_list) # tag关联
attach_copied_obj.container = c
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
@obj = c
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
update_quotes attach_copied_obj
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:label_project_empty_select)
respond_to do |format|
format.js
end
end
def update_quotes attachment
if attachment.copy_from
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
else
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}")
end
attachment.quotes = get_qute_number attachment
attachment.save
attachments.each do |att|
att.quotes = attachment.quotes
att.save
end
end
#找到文件的所有的历史版本
def attachment_versions
@history = params[:history]
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
respond_to do |format|
format.js
end
end
def attachment_versions_delete
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
@attachment_histories_count = @attachment_histories.count
respond_to do |format|
format.js
end
end
#找到文件的所有的历史版本及当前版本
def attachment_history_download
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
respond_to do |format|
format.js
end
end
private
def find_project
@attachment = Attachment.find(params[:id])
# Show 404 if the filename in the url is wrong
# modify by nwb
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
if @attachment.container_type == 'Memo'
@memo = @attachment.container
elsif @attachment.container_type == 'IssueImage'
@project = Issue.find(@attachment.container_id).project
elsif @attachment.container_type == 'ProjectImage'
@project = Project.find(@attachment.container_id)
else
@project = @attachment.project
end
rescue ActiveRecord::RecordNotFound
render_404
end
# Checks that the file exists and is readable
def file_readable
if @attachment.readable?
true
else
logger.error "Cannot send attachment, #{@attachment.diskfile} does not exist or is unreadable."
render_404
end
end
def read_authorize
if @attachment.container_type == "HomeworkAttach" || @attachment.container_type == 'Bid'
true
#User.current.allowed_to?(:view_homework_attaches, @attachment.project) ? true : deny_access
else
@attachment.visible? ? true : deny_access
end
end
def delete_authorize
@attachment.deletable? ? true : deny_access
end
def detect_content_type(attachment)
content_type = attachment.content_type
if content_type.blank?
content_type = Redmine::MimeType.of(attachment.filename)
end
content_type.to_s
end
def login_without_softapplication
referer = request.headers['Referer']
require_login unless referer =~ /softapplication/ || @attachment.container_type == "Memo"
end
def renderTag
@attachmentNew = Attachment.find(params[:attchmentId])
respond_to do |format|
format.js
end
end
def has_login
unless (@attachment && @attachment.container_type == "Organization").nil?
unless (@attachment && @attachment.container_type == "PhoneAppVersion").nil?
render_403 if (!User.current.logged? && !(params[:type] && params[:type] == "wechat")) && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download)
end
end
end
end

View File

@ -0,0 +1,697 @@
#encoding: utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AttachmentsController < ApplicationController
layout "users_base"
before_filter :verify_authenticity_token, only: [:upload]
before_filter :find_project, :only => [:show, :download, :thumbnail, :destroy]#, :except => [:upload, :autocomplete]
before_filter :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young
before_filter :delete_authorize, :only => [:destroy]
before_filter :authorize_global, :only => [:upload]
#before_filter :authorize_attachment_download1, :only => [:download]
before_filter :has_login
#before_filter :login_without_softapplication, only: [:download]
accept_api_auth :show, :download, :upload
require 'iconv'
include AttachmentsHelper
include ApplicationHelper
def show
respond_to do |format|
format.html {
if @attachment.is_diff?
@diff = File.new(@attachment.diskfile, "rb").read
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
# Save diff type as user preference
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
User.current.pref[:diff_type] = @diff_type
User.current.preference.save
end
render :action => 'diff'
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
@content = File.new(@attachment.diskfile, "rb").read
# 编码为非 UTF-8先进行间接转码
# 部分unicode编码不直接支持转为 UTF-8
# modify by nwb
if @content.encoding.name != 'UTF-8'
@content = @content.force_encoding('GBK')
@content = @content.encode('UTF-8')
end
render :action => 'file'
else
download
end
}
format.api
end
rescue Encoding::InvalidByteSequenceError => e
render :action => 'file'
end
def pdf?(file)
file.downcase.end_with?(".pdf")
end
def get_image_type
image = Attachment.find(params[:id])
image_type = image.content_type.split("/")[1]
render :json => {type: image_type}
end
def direct_download
@attachment.increment_download
file_type = detect_content_type(@attachment)
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
:type => file_type,
:disposition => 'attachment' #inline can open in browser
end
def direct_download_resource
@resource = ResourceBank.find(params[:id])
storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files")
file = File.join(storage_path, @resource.disk_directory.to_s, @resource.disk_filename.to_s)
send_file file, :filename => filename_for_content_disposition(@resource.filename),
:type => detect_content_type(@resource),
:disposition => 'attachment' #inline can open in browser
@resource.increment!(:downloads)
end
def download_resource
@resource = ResourceBank.find(params[:id])
candown = resource_bank_candown @resource, params[:type]
if candown
if stale?(:etag => @resource.digest)
if params[:preview] == 'true'
storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files")
convered_file = File.join(storage_path, @resource.disk_directory.to_s, @resource.disk_filename.to_s)
#如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
unless pdf?(convered_file)
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
unless File.exist?(convered_file)
office = Trustie::Utils::Office.new(File.join(storage_path, @resource.disk_directory.to_s, @resource.disk_filename.to_s))
office.conver(convered_file)
end
end
if File.exist?(convered_file) && pdf?(convered_file)
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
else
direct_download_resource
end
else
# 记录用户行为
record_user_actions(params[:id])
# 直接下载历史版本
direct_download_resource
end
end
else
render_403 :message => :notice_not_authorized
end
rescue => e
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
end
def direct_download_history
@attachment_history = AttachmentHistory.find(params[:id])
@attachment_history.increment_download
send_file @attachment_history.diskfile_history, :filename => filename_for_content_disposition(@attachment_history.filename),
:type => detect_content_type(@attachment_history),
:disposition => 'attachment' #inline can open in browser
end
def download_history
@attachment_history = AttachmentHistory.find(params[:id])
candown = attachment_history_candown @attachment_history
if candown || User.current.admin? || User.current.id == @attachment_history.author_id
if stale?(:etag => @attachment_history.digest)
if params[:preview] == 'true'
convered_file = @attachment_history.diskfile_history
#如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
unless pdf?(convered_file)
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
unless File.exist?(convered_file)
office = Trustie::Utils::Office.new(@attachment_history.diskfile)
office.conver(convered_file)
end
end
if File.exist?(convered_file) && pdf?(convered_file)
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
else
direct_download_history
end
else
# 记录用户行为
record_user_actions(params[:id])
# 直接下载历史版本
direct_download_history
end
end
else
render_403 :message => :notice_not_authorized
end
rescue => e
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
end
def record_user_actions id
if params[:action] == "download_history"
UserActions.create(:action_id => id, :action_type => "AttachmentHistory", :user_id => User.current.id) unless id.nil?
elsif params[:action] == "download"
UserActions.create(:action_id => id, :action_type => "Attachment", :user_id => User.current.id) unless id.nil?
elsif params[:action] == "download_resource"
UserActions.create(:action_id => id, :action_type => "ResourceBank", :user_id => User.current.id) unless id.nil?
end
end
def download
# modify by nwb
# 下载添加权限设置
candown = attachment_candown @attachment
if candown || User.current.admin? || User.current.id == @attachment.author_id
if stale?(:etag => @attachment.digest)
if params[:preview] == 'true'
convered_file = @attachment.diskfile
#如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
unless pdf?(convered_file)
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
unless File.exist?(convered_file)
office = Trustie::Utils::Office.new(@attachment.diskfile)
office.conver(convered_file)
end
end
if File.exist?(convered_file) && pdf?(convered_file)
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
else
direct_download
end
else
# 记录用户行为
record_user_actions(params[:id])
direct_download
end
end
else
render_403 :message => :notice_not_authorized
end
rescue => e
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
end
#更新资源文件类型
def updateType
@attachment = Attachment.find(params[:attachmentid])
if @attachment != nil
@attachment.attachtype = params[:newtype]
@attachment.save
render :text =>'success'
else
render :text=>'error'
end
end
# 更新文件密级
def updateFileDense
@attachment = Attachment.find(params[:attachmentid])
if @attachment != nil
filedense = params[:newtype].to_s
# d = Iconv.conv("unicodebig","utf-8",filedense)
if filedense == "%E5%85%AC%E5%BC%80" #l(:field_is_public)
@attachment.is_public = 1
else
@attachment.is_public = 0
end
@attachment.save
@newfiledense = filedense
end
respond_to do |format|
format.js
end
end
def update_file_dense
@attachment = Attachment.find(params[:attachmentid])
if @attachment != nil
filedense = params[:newtype].to_s
if filedense == "1"
@attachment.is_public = 1
else
@attachment.is_public = 0
end
@attachment.save
@newfiledense = filedense
end
if @attachment.container_type == "Project" || @attachment.container_type == "Course"
tip_attachment_update
end
respond_to do |format|
format.js
end
end
def tip_attachment_update
if params[:course_id]
@tip_all_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id])
@tip_all_public_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id], :is_public => 1)
@tip_all_private_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id], :is_public => 0)
@course = Course.find(params[:course_id])
elsif params[:project_id]
@tip_all_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id])
@tip_all_public_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id], :is_public => 1)
@tip_all_private_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id], :is_public => 0)
@project = Project.find(params[:project_id])
end
@tag_name = params[:tag_name]
@other = params[:other]
unless @tag_name.blank?
if @other
if @project
@tip_all_attachments = @tip_all_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
@tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
@tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
elsif @course
@tip_all_attachments = @tip_all_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') }
@tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') }
@tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') }
end
else
@tip_all_attachments = @tip_all_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)}
@tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)}
@tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)}
end
end
@tip_all_attachments = @tip_all_attachments.count
@tip_all_public_attachments = @tip_all_public_attachments.count
@tip_all_private_attachments = @tip_all_private_attachments.count
end
def thumbnail
if @attachment.thumbnailable? && thumbnail = @attachment.thumbnail(:size => params[:size])
if stale?(:etag => thumbnail)
send_file thumbnail,
:filename => filename_for_content_disposition(@attachment.filename),
:type => detect_content_type(@attachment),
:disposition => 'inline'
end
else
# No thumbnail for the attachment or thumbnail could not be created
render :nothing => true, :status => 404
end
end
def upload
# Make sure that API users get used to set this content type
# as it won't trigger Rails' automatic parsing of the request body for parameters
unless request.content_type == 'application/octet-stream'
render :nothing => true, :status => 406
return
end
@attachment = Attachment.new(:file => request.raw_post)
@attachment.author = User.current
if !params[:project].nil?
@attachment.container_type = 'Project'
@attachment.container_id = params[:project].split("?")[0]
end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
saved = @attachment.save
respond_to do |format|
format.js
format.api {
if saved
render :action => 'upload', :status => :created
else
render_validation_errors(@attachment)
end
}
end
end
def upload_memo_heads
@attachment = Attachment.new(:file => params[:file])
@attachment.author = User.current
@attachment.filename = params[:file].original_filename.presence || Redmine::Utils.random_hex(16)
saved = @attachment.save!
saved
render json: {
success: saved ? 1 : 0, # | 1, // 0 表示上传失败1 表示上传成功
message: "上传信息:#{ @attachment.errors.full_messages.join(',') }",
url: download_attachment_path(@attachment.id), # 上传成功时才返回
attachment_id: @attachment.id
}
end
def upload_with_markdown
@attachment = Attachment.new(:file => params["editormd-image-file"])
@attachment.author = User.current
# 如果其它类型的条用md必须传类型elsif判断
if params[:container_type].present?
@attachment.container_type = params[:container_type]
@attachment.container_id = params[:container_id]
end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
saved = @attachment.save!
saved
render json: {
success: saved ? 1 : 0, # | 1, // 0 表示上传失败1 表示上传成功
message: "上传失败:#{ @attachment.errors.full_messages.join(',') }",
url: download_attachment_path(@attachment.id) # 上传成功时才返回
}
end
def upload_attachment_version
@flag = false
@course = Course.find params[:course_id]
@old_attachment = Attachment.find params[:old_attachment_id]
if params[:attachments]
Attachment.transaction do
#取出当前上传的文件
@attachment = Attachment.find(params[:attachments].first[1][:attachment_id])
#将需要修改的记录保存到历史记录
@history = AttachmentHistory.new
@history.attributes = @old_attachment.attributes.dup.except("id", "resource_bank_id")
@history.attachment_id = params[:old_attachment_id]
#需要更新版本号,需要拿到原来该文件最大的历史版本号
@old_history = @old_attachment.attachment_histories.reorder('version desc').first
@history.version = @old_history.nil? ? 1 : @old_history.version + 1
@history.save #历史记录保存完毕
#将最新保存的记录 数据替换到 需要修改的文件记录
@old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes",'is_publish','publish_time')
@status = @old_attachment.is_publish
@old_attachment.save
#删除当前记录
@attachment.delete
@flag = true
end
end
# 如果附件描述被修改,则保存
if params[:description] && params[:description].strip() != "" && params[:description] != @old_attachment.description
@old_attachment.description = params[:description]
@flag = true
end
if !params[:unified_setting] && params[:attachment_publish_time] && @course.course_groups.count > 1
@old_attachment.unified_setting = 0
min_publish_time = @old_attachment.publish_time ? (format_time @old_attachment.publish_time).to_s : (format_time @old_attachment.created_on).to_s
params[:attachment_publish_time].each do |publish_time|
if publish_time != "" && publish_time < min_publish_time
min_publish_time = publish_time
end
end
@old_attachment.is_publish = min_publish_time > (format_time Time.now).to_s ? 0 : 1
@old_attachment.publish_time = min_publish_time > (format_time @old_attachment.created_on).to_s ? min_publish_time : @old_attachment.created_on
@course.course_groups.each do |group|
att_group_setting = @old_attachment.attachment_group_settings.where(:course_group_id => group.id).first
end
@old_attachment.attachment_group_settings.joins(:course_group).reorder("course_groups.name asc").each_with_index do |setting, index|
if params[:attachment_publish_time][index] && params[:attachment_publish_time][index] != ""
setting.update_column(:publish_time, params[:attachment_publish_time][index])
end
end
@flag = true
elsif params[:publish_time] && params[:publish_time] != ""
@old_attachment.publish_time = params[:publish_time]
@old_attachment.is_publish = 0
@old_attachment.unified_setting = 1
@old_attachment.attachment_group_settings.destroy_all
@flag = true
end
if @old_attachment.is_public == 0 && params[:is_public]
@old_attachment.is_public = 1
@flag = true
end
# tip_attachment_update
@old_attachment.save
respond_to do |format|
format.js
end
end
def update_attachment_publish_time
@attachment = Attachment.find params[:id]
@status = params[:status].to_i
if @status == 0
@attachment.update_attributes(:is_publish => 1, :publish_time => Time.now)
end
end
# prams[:type] => history 历史版本
def destroy
if params[:type] == "history"
begin
AttachmentHistory.find(params[:history_id]).destroy
@attachment = Attachment.find(params[:id])
@is_history = true
@is_history_destroy = false
@attachment_histories = @attachment.attachment_histories
rescue Exception => e
puts e
end
elsif params[:type] == "history_delete"
begin
AttachmentHistory.find(params[:history_id]).destroy
@attachment = Attachment.find(params[:id])
@is_history_delete = true
@is_history_destroy = false
@attachment_histories = @attachment.attachment_histories
@attachment_histories_count = @attachment_histories.count
rescue Exception => e
puts e
end
else
@history = params[:history]
if @attachment.container.respond_to?(:init_journal)
@attachment.container.init_journal(User.current)
end
@attachment.delete
end
respond_to do |format|
if @project.nil?
format.html { redirect_to_referer_or forum_path(@attachment.container) }
else
format.html { redirect_to_referer_or project_path(@project) }
end
format.js
end
end
def autocomplete
# modify by nwb
if params[:project_id]
@project = Project.find_by_id(params[:project_id])
elsif params[:course_id]
@course = Course.find_by_id(params[:course_id])
end
respond_to do |format|
format.js
end
end
def add_exist_file_to_project
classname = params[:class_name]
class_id = params[:class_id]
attachments = params[:attachment][:attach]
obj = Object.const_get(classname).find_by_id(class_id)
attachments.collect do |attach_id|
ori = Attachment.find_by_id(attach_id)
next if ori.blank?
attach_copied_obj = ori.copy
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
attach_copied_obj.container = obj
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 1
end
@obj = obj
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:error_attachment_empty)
respond_to do |format|
format.js
end
end
def add_exist_file_to_projects
file = Attachment.find(params[:file_id])
projects = params[:projects][:project]
@message = ""
projects.each do |project|
c = Project.find(project);
if project_contains_attachment?(c,file)
if @message && @message == ""
@message += l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
else
@message += "<br/>" + l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
end
end
attach_copied_obj = file.copy
attach_copied_obj.tag_list.add(file.tag_list) # tag关联
attach_copied_obj.container = c
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
@obj = c
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
update_quotes attach_copied_obj
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:label_project_empty_select)
respond_to do |format|
format.js
end
end
def update_quotes attachment
if attachment.copy_from
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
else
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}")
end
attachment.quotes = get_qute_number attachment
attachment.save
attachments.each do |att|
att.quotes = attachment.quotes
att.save
end
end
#找到文件的所有的历史版本
def attachment_versions
@history = params[:history]
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
respond_to do |format|
format.js
end
end
def attachment_versions_delete
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
@attachment_histories_count = @attachment_histories.count
respond_to do |format|
format.js
end
end
#找到文件的所有的历史版本及当前版本
def attachment_history_download
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
respond_to do |format|
format.js
end
end
private
def find_project
@attachment = Attachment.find(params[:id])
# Show 404 if the filename in the url is wrong
# modify by nwb
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
if @attachment.container_type == 'Memo'
@memo = @attachment.container
else
@project = @attachment.project
end
rescue ActiveRecord::RecordNotFound
render_404
end
# Checks that the file exists and is readable
def file_readable
if @attachment.readable?
true
else
logger.error "Cannot send attachment, #{@attachment.diskfile} does not exist or is unreadable."
render_404
end
end
def read_authorize
if @attachment.container_type == "HomeworkAttach" || @attachment.container_type == 'Bid'
true
#User.current.allowed_to?(:view_homework_attaches, @attachment.project) ? true : deny_access
else
@attachment.visible? ? true : deny_access
end
end
def delete_authorize
@attachment.deletable? ? true : deny_access
end
def detect_content_type(attachment)
content_type = attachment.content_type
if content_type.blank?
content_type = Redmine::MimeType.of(attachment.filename)
end
content_type.to_s
end
def login_without_softapplication
referer = request.headers['Referer']
require_login unless referer =~ /softapplication/ || @attachment.container_type == "Memo"
end
def renderTag
@attachmentNew = Attachment.find(params[:attchmentId])
respond_to do |format|
format.js
end
end
def has_login
unless (@attachment && @attachment.container_type == "Organization").nil?
unless (@attachment && @attachment.container_type == "PhoneAppVersion").nil?
render_403 if (!User.current.logged? && !(params[:type] && params[:type] == "wechat")) && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download)
end
end
end
end

View File

@ -56,7 +56,6 @@ class AvatarController < ApplicationController
@status = 1
@msg = l(:error_upload_avatar_to_large, :max_size => number_to_human_size(Setting.upload_avatar_max_size.to_i))
elsif Trustie::Utils::Image.new(@temp_file).image?
diskfile=disk_filename(@source_type,@source_id)
if @source_type == 'UserAuthentication'
diskfile = disk_auth_filename('UserAuthentication', @source_id, @auth_type)
diskfile1 = diskfile + 'temp'
@ -69,8 +68,15 @@ class AvatarController < ApplicationController
elsif @source_type == "Platform"
diskfile = disk_auth_filename(@source_type, @auth_type, "")
@urlfile='/' << File.join("images","avatars", avatar_directory(@source_type),auth_filename(@auth_type,''))
elsif @source_type == 'Forgelogo'
diskfile = disk_logo_filename(@source_type)
@urlfile='/' << File.join("images","trustieForge", "Forgelogo")
elsif @source_type == 'Loginlogo'
diskfile = disk_logo_filename(@source_type)
@urlfile='/' << File.join("images","trustieForge", "Loginlogo")
else
@urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file))
diskfile = disk_filename_avatar(@source_type,@source_id)
@urlfile='/' << File.join("images","avatars",avatar_directory(@source_type), avatar_filename(@source_id,@image_file))
end
# 用户头像上传时进行特别处理
@ -99,7 +105,7 @@ class AvatarController < ApplicationController
end
end
if @source_type == 'User' || @source_type == 'UserAuthentication' || @source_type == 'edu_coop' || @source_type == 'com_coop' || @source_type == 'Platform' || @source_type == 'Shixun' || @source_type == 'Subject'
if @source_type == 'User' || @source_type == 'UserAuthentication' || @source_type == 'edu_coop' || @source_type == 'com_coop' || @source_type == 'Platform' || @source_type == 'Forgelogo' || @source_type == 'Loginlogo' || @source_type == 'Advertisement'
else
Trustie::Utils::Image.new(diskfile,true).compress(300)

View File

@ -1,7 +1,8 @@
# encoding=utf-8
class CategoriesController < ApplicationController
# before_filter :render_react
before_filter :require_login
before_filter :require_login, :except => [:all]
skip_before_filter :session_expiration, :only => [:all]
include ApplicationHelper
# 所有类型,通过参数过滤

View File

@ -53,7 +53,6 @@ class CommentsController < ApplicationController
# end
# # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add end
#flash[:notice] = l(:label_comment_added)
update_user_activity(@news.class,@news.id)
end
if params[:user_activity_id]
@ -92,7 +91,6 @@ class CommentsController < ApplicationController
new_comment = @news.comments.build(:author_id => User.current.id, :reply_id => params[:id], :comments => params[:content], :parent_id => comment.id)
@user_activity_id = params[:user_activity_id]
if new_comment.save
update_user_activity(@news.class,@news.id)
if @user_activity_id
respond_to do |format|
format.js

View File

@ -50,7 +50,7 @@ class FilesController < ApplicationController
def searchone4reload
attachment = Attachment.find_by_id(params[:fileid])
respond_to do |format|
format.html{render :layout => nil,:locals=>{:file=>attachment,:course=>@course}}
format.html{render :layout => nil,:locals=>{:file=>attachment}}
end
end
@ -58,7 +58,6 @@ class FilesController < ApplicationController
@file = Attachment.find params[:id]
@attachment = @file
@attachment_histories = @file.attachment_histories
@course = Course.find params[:course_id]
respond_to do |format|
format.js
end
@ -78,7 +77,6 @@ class FilesController < ApplicationController
end
sort = "#{@sort} #{@order}"
end
# show_attachments [@course]
begin
q = "%#{params[:name].strip}%"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
@ -144,13 +142,6 @@ class FilesController < ApplicationController
@order = ""
@is_remote = false
if params[:project_id]
# 更新资源申请消息为已读
# ar_ids = ApplyResource.where("user_id =? and container_id =? and container_type =?", User.current.id, params[:project_id].to_i, "Project").map{|ar| ar.id}
# cms = CourseMessage.where("course_message_type =? and user_id =? and course_message_id in (#{ar_ids.empty? ? '0': ar_ids.join(',')})", "ApplyResource", User.current.id)
# cms.each do |cm|
# cm.update_column(:viewed, true)
# end
# over
@page = params[:page] ? params[:page].to_i + 1 : 2
@container_type = 0
if params[:sort]
@ -241,7 +232,6 @@ class FilesController < ApplicationController
@course_tag = @project.project_type
if @project.project_type == 1
@left_nav_type = 5
render :layout => 'base_courses'
end
end

View File

@ -1,7 +1,8 @@
# encoding=utf-8
# For react
class ForumsController < ApplicationController
before_filter :require_login
before_filter :require_login, :only => [:new, :edit]
skip_before_filter :session_expiration, :only => [:index, :show]
include ApplicationHelper

View File

@ -299,10 +299,6 @@ class IssuesController < ApplicationController
issue_title = params[:issue][:subject]
priority_id = params[:issue][:priority_id]
ps = ProjectsService.new
if senduser.id != User.current.id
ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id
end
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
respond_to do |format|
format.html {
@ -583,7 +579,6 @@ class IssuesController < ApplicationController
jour.journalized = @issue
jour.save_attachments(params[:attachments])
jour.save
update_user_activity(@issue.class,@issue.id)
update_forge_activity(@issue.class,@issue.id)
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@user_activity_id = params[:user_activity_id]
@ -644,7 +639,6 @@ class IssuesController < ApplicationController
# new_jour = @issue.journals.build(:user_id => User.current.id, :reply_id => params[:journal_id], :notes => params[:content], :parent_id => jour.id)
@user_activity_id = params[:user_activity_id]
if new_jour.save
update_user_activity(@issue.class,@issue.id)
update_forge_activity(@issue.class,@issue.id)
respond_to do |format|
if params[:is_issue_show]
@ -665,11 +659,8 @@ class IssuesController < ApplicationController
@is_project = params[:is_project]
@issue = Issue.find(params[:id])
begin
forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id])
forge_acts.destroy_all unless forge_acts.empty?
at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id])
at_message.destroy_all unless at_message.empty?
Journal.delete(params[:journal_id])
journal = Journal.where(:id => params[:journal_id]).first
journal.destroy if journal.present?
rescue Exception => e
puts e
end
@ -953,8 +944,6 @@ class IssuesController < ApplicationController
issue_id = @issue.id
issue_title = params[:issue][:subject]
priority_id = params[:issue][:priority_id]
ps = ProjectsService.new
ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id
end
end

View File

@ -123,10 +123,16 @@ class ManagementsController < ApplicationController
end
end
def memo_homepage_show
memo = Memo.find params[:id]
memo.update_column(:homepage_show, params[:homepage])
render :json => {status: 1, message: "设置成功!"}
end
# 贴吧类型
def forum_list
@menu_type = 12
@sub_type = 7
@sub_type = 2
@forums = Forum.select([:id, :name, :sticky]).all
@page = (params['page'] || 1).to_i
@forums_count = @forums.count
@ -229,6 +235,118 @@ class ManagementsController < ApplicationController
end
end
# 公共属性
def navigationbar
@menu_type = 12
@sub_type = 1
@tel = PublicProperty.where(:property => "Tel").first
@email = PublicProperty.where(:property => "Email").first
@addr = PublicProperty.where(:property => "Address").first
@copyright = PublicProperty.where(:property => "Copyright").first
end
# 更新公共属性
def update_public_property
if params[:Tel]
tel = PublicProperty.where(:property => "Tel").first || PublicProperty.new(:property => "Tel")
tel.value = params[:Tel].strip
tel.save!
end
if params[:Email]
email = PublicProperty.where(:property => "Email").first || PublicProperty.new(:property => "Email")
email.value = params[:Email].strip
email.save!
end
if params[:Address]
addr = PublicProperty.where(:property => "Address").first || PublicProperty.new(:property => "Address")
addr.value = params[:Address].strip
addr.save!
end
if params[:Copyright]
copyright = PublicProperty.where(:property => "Copyright").first || PublicProperty.new(:property => "Copyright")
copyright.value = params[:Copyright].strip
copyright.save!
end
redirect_to navigationbar_managements_path
end
# 广告列表
def ads_list
@menu_type = 12
@sub_type = 3
@ads = Advertisement.order("updated_at desc")
respond_to do |format|
format.js
format.html
end
end
# 删除广告
def delete_ads
@ads = Advertisement.find params[:ad]
@ads.destroy
end
# 新增门户广告
def add_homepage_ads
Advertisement.create!(:link_to => params[:link_to], :position => params[:position])
redirect_to ads_list_managements_path
end
# 发布广告
def publish_ads
ad = Advertisement.find params[:ad]
if ad.link_to && ad.position
ad.update_attribute(:status, 1)
@result = 1
else
@result = 0
end
end
# 添加广告链接、投放位置
def add_info_for_ads
ad = Advertisement.find params[:ad]
params[:link_to] && ad.update_attribute(:link_to, params[:link_to])
params[:position] && ad.update_attribute(:position, params[:position])
render :json => {:success => 1}
end
# 项目列表 + 搜索
def projects_list
@menu_type = 1
name = params[:name]
homepage = params[:homepage]
x_sort = params[:sort] || "desc"
sql =
if name.present?
homepage.present? ? "name like '%#{name.strip}%' and homepage_show = #{homepage}" : "name like '%#{name.strip}%' "
elsif homepage.present?
"homepage_show = #{homepage}"
end
@projects = Project.where("#{sql}").order("created_on #{x_sort}")
@page = (params['page'] || 1).to_i
@projects_count = @projects.count
@limit = 20
@is_remote = true
@projects_pages = Paginator.new @projects_count, @limit, params['page'] || 1
@offset ||= @projects_pages.offset
@projects = paginateHelper @projects, @limit
respond_to do |format|
format.js
format.html
end
end
# 项目首页展示
# params: id-项目ID homepage: true显示false取消显示
def project_homepage_show
project = Project.find params[:id]
project.update_column(:homepage_show, params[:homepage])
render :json => {status: 1, message: "设置成功!"}
end
# 单位部门列表
def departments
@menu_type = 6

View File

@ -85,8 +85,6 @@ class MembersController < ApplicationController
# 添加成功后,申请人收到消息
# AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_type => "AppliedProject", :applied_id => @applied_project.id ,
# :status => 6, :viewed => false, :applied_user_id => User.current.id, :role => @applied_project.role, :project_id => @applied_project.project_id)
# ps = ProjectsService.new
# ps.send_wechat_join_project_notice user,project,ap_role,0
# 添加成功后,批准人收到消息
# AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => @applied_project.id ,
# :status => 7, :viewed => true, :applied_user_id => @applied_message.applied_user_id, :role => @applied_project.role, :project_id => @applied_project.project_id)
@ -135,7 +133,6 @@ class MembersController < ApplicationController
# ps = ProjectsService.new
# user = User.find(@applied_message.applied_user_id)
# ap_role = @applied_project.try(:role)
# ps.send_wechat_join_project_notice user,project,ap_role,1
# applied_project.delete
Tiding.where(:trigger_user_id => @applied_message.applied_user_id, :container_id => @applied_message.project_id, :container_type => 'JoinProject', :status => 0).update_all(:status => 1)
@ -177,21 +174,22 @@ class MembersController < ApplicationController
if @project
project_info = []
if params[:membership]
if params[:member_user_ids]
if params[:membership][:user_ids]
ActiveRecord::Base.transaction do
begin
# attrs = params[:membership].dup
user_ids = params[:member_user_ids].split(",")
attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
user_grades << UserGrade.new(:user_id => user_id, :project_id => @project.id)
#给新成员发送加入项目的消息发送者id放在ForgeMessage的forge_message_id字段中
#forge_message_type设置为JoinProject
Tiding.create(:user_id => user_id, :trigger_user_id => User.current.id, :container_id => @project.id, :container_type => 'ManagerJoinProject', :belong_container_id => @project.id, :belong_container_type => "Project", :tiding_type => "System", :extra => params[:membership][:role_ids][0])
# forge_join = ForgeMessage.new(:user_id =>user_id, :forge_message_id=>User.current.id,:project_id => @project.id,:forge_message_type=>"JoinProject", :viewed => false)
# forge_join.save
## added by nie
Tiding.create(:user_id => user_id, :trigger_user_id => User.current.id, :container_id => @project.id, :container_type => 'ManagerJoinProject', :belong_container_id => @project.id, :belong_container_type => "Project", :tiding_type => "System", :extra => params[:membership][:role_ids][0])
if (params[:membership][:role_ids])
role = Role.find(params[:membership][:role_ids][0])
project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) if role.allowed_to?(:is_manager)
@ -245,7 +243,7 @@ class MembersController < ApplicationController
@succes_message = "添加成功"
end
respond_to do |format|
format.html { redirect_to project_member_path(@project) }
format.html { redirect_to_settings_in_projects }
format.js
format.api {
@member = members.first
@ -259,6 +257,7 @@ class MembersController < ApplicationController
end
end # end of if @project
end # end of params[:refusal_button]
end

View File

@ -173,7 +173,6 @@ class MessagesController < ApplicationController
# @reply.reply_id = params[:id]
end
update_user_activity(@topic.class,@topic.id)
update_forge_activity(@topic.class,@topic.id)
if @project && !params[:user_activity_id]

View File

@ -17,7 +17,7 @@
class MyController < ApplicationController
include ApplicationHelper
layout "users_base"
layout "forge"
skip_before_filter :check_authentication, :only => [:account]
before_filter :auth_login1, :only => [:account]
before_filter :require_login, except: [:change_mail_notification]

View File

@ -20,37 +20,37 @@
# Description 封装代码,简化代码,格式化代码,
class ProjectsController < ApplicationController
layout 'base_projects'
before_filter :authorize1, :only => [:show]
# menu_item :overview, :only => :show
# menu_item :roadmap, :only => :roadmap
# menu_item :settings, :only => :settings
# menu_item :homework, :only => [:homework, :new_homework]
# menu_item :feedback, :only => :feedback
# menu_item :share, :only => :share
skip_before_filter :verify_authenticity_token, :only => [:training_task_status]
skip_before_filter :check_if_login_required, :only => [:training_task_status]
before_filter :check_authentication
before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,
:view_homework_attaches,:join_project, :project_home, :training_execute, :training_task_status]
before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course]
before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches]
before_filter :require_admin, :only => [ :copy, :unarchive, :calendar]
before_filter :require_admin_or_manager, :only => [ :destroy]
before_filter :file
# before_filter :authorize1, :only => [:show]
# # menu_item :overview, :only => :show
# # menu_item :roadmap, :only => :roadmap
# # menu_item :settings, :only => :settings
# # menu_item :homework, :only => [:homework, :new_homework]
# # menu_item :feedback, :only => :feedback
# # menu_item :share, :only => :share
# skip_before_filter :verify_authenticity_token, :only => [:training_task_status]
# skip_before_filter :check_if_login_required, :only => [:training_task_status]
# before_filter :check_authentication
before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course,
:join_project, :project_home]
# before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,
# :view_homework_attaches,:course]
# before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches]
# before_filter :require_admin, :only => [ :copy, :unarchive, :calendar]
# before_filter :require_admin_or_manager, :only => [ :destroy]
# 除非项目内人员,不可查看成员, TODO: 完了写报表里去
# before_filter :memberAccess, only: :member
# accept_rss_auth :index
accept_api_auth :index, :show, :create, :update, :destroy
after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
if controller.request.post?
controller.send :expire_action, :controller => 'welcome', :action => 'robots'
end
end
# # accept_rss_auth :index
# accept_api_auth :index, :show, :create, :update, :destroy
#
# after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
# if controller.request.post?
# controller.send :expire_action, :controller => 'welcome', :action => 'robots'
# end
# end
before_filter :import_base, :only => [:import_project, :check_clone, :check_push]
helper :sort
include SortHelper
@ -74,6 +74,12 @@ class ProjectsController < ApplicationController
### added by william
include ActsAsTaggableOn::TagsHelper
include ApplicationHelper
require 'fileutils'
skip_before_filter :check_authentication, :only => [:index]
skip_before_filter :session_expiration, :only => [:index]
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
# 仅仅为了转换Gitlab地址
def project_home
@ -119,33 +125,55 @@ class ProjectsController < ApplicationController
def index
@user = User.current
@select = params[:select].nil? ? '' : params[:select]
# if params[:order].present?
# @order = params[:order]
# order_str = params[:order] == "members_count" ? "c.members_count" : "c.created_at"
# else
# @order = "members_count"
# order_str = "c.members_count"
# end
@hidden = params[:hidden] ? params[:hidden].to_i : 0
@select = params[:select]
@language = params[:language]
@s_order = params[:order] ? params[:order] : "created_on"
@all_projects_count = Project.all.count
@public_projects_count = Project.all_public.count
@private_projects_count = @all_projects_count - @public_projects_count
# join users 是为了过滤掉用户为nil的项目
if @select == "private"
@projects = Project.find_by_sql("SELECT p.*, COUNT(m.id) member_count FROM projects p, members m, users u WHERE u.id = p.user_id and m.`project_id`=p.id AND p.is_public = 0 GROUP BY p.`id` order by member_count desc")
if @language
@projects = Project.find_by_sql("SELECT p.*, COUNT(m.id) member_count FROM projects p, members m, users u
WHERE u.id = p.user_id and m.`project_id`=p.id AND p.is_public = false AND p.language = '#{@language}'
GROUP BY p.`id` order by #{@s_order} desc")
else
@projects = Project.find_by_sql("SELECT p.*, COUNT(m.id) member_count FROM projects p, members m, users u
WHERE u.id = p.user_id and m.`project_id`=p.id AND p.is_public = false
GROUP BY p.`id` order by #{@s_order} desc")
end
@language_list = Project.find_by_sql("select language, count(*) cnt from projects where is_public = false group by language")
elsif @select == "public"
@projects = Project.find_by_sql("SELECT p.*, COUNT(m.id) member_count FROM projects p, members m, users u WHERE u.id = p.user_id and m.`project_id`=p.id AND p.is_public = 1 GROUP BY p.`id` order by member_count desc")
if @language
@projects = Project.find_by_sql("SELECT p.*, COUNT(m.id) member_count FROM projects p, members m, users u
WHERE u.id = p.user_id and m.`project_id`=p.id AND p.is_public = true AND p.language = '#{@language}'
GROUP BY p.`id` order by #{@s_order} desc")
else
@projects = Project.find_by_sql("SELECT p.*, COUNT(m.id) member_count FROM projects p, members m, users u
WHERE u.id = p.user_id and m.`project_id`=p.id AND p.is_public = true
GROUP BY p.`id` order by #{@s_order} desc")
end
@language_list = Project.find_by_sql("select language, count(*) cnt from projects where is_public = true group by language")
else
@projects = Project.find_by_sql("SELECT p.*, COUNT(m.id) member_count FROM projects p, members m, users u WHERE u.id = p.user_id and m.`project_id`=p.id GROUP BY p.`id` order by member_count desc")
if @language
@projects = Project.find_by_sql("SELECT p.*, COUNT(m.id) member_count FROM projects p, members m, users u
WHERE u.id = p.user_id and m.`project_id`=p.id and p.language = '#{@language}' GROUP BY p.`id` order by #{@s_order} desc")
else
@projects = Project.find_by_sql("SELECT p.*, COUNT(m.id) member_count FROM projects p, members m, users u
WHERE u.id = p.user_id and m.`project_id`=p.id GROUP BY p.`id` order by #{@s_order} desc")
end
@language_list = Project.find_by_sql("select language, count(*) cnt from projects group by language")
end
@projects = paginateHelper @projects, 16
@projects = paginateHelper @projects, 10
respond_to do |format|
format.js
format.html { render :layout => "forge" }
end
end
def courserender_404
end
@ -180,7 +208,7 @@ class ProjectsController < ApplicationController
projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
}
end
end
end
# Time 2015-01-29 16:13:20
@ -213,12 +241,12 @@ class ProjectsController < ApplicationController
reply_user_id = params[:reference_user_id]
reply_id = params[:reference_message_id]
content = params[:project_respond]
options = {:user_id => author_id,
:m_parent_id => parent_id,
:m_reply_id => reply_id,
:reply_id => reply_user_id,
:notes => content,
:is_readed => false}
options = {:user_id => author_id,
:m_parent_id => parent_id,
:m_reply_id => reply_id,
:reply_id => reply_user_id,
:notes => content,
:is_readed => false}
@jfm = Project.add_new_jour(nil, nil, project_id, options)
@save_succ = @jfm.errors.empty?
@ -241,12 +269,115 @@ class ProjectsController < ApplicationController
redirect_to signin_url
end
end
# 如果image_url不存在
# status --> 1: 需要克隆2需要push更新
def import_project
image_url = @project.image_url
render_403 if image_url.blank? || !(User.current.admin? || User.current.member_of?(@project))
unless (image_url.include?(".git") && (image_url.include?("http://") || image_url.include?("https://")))
render :json => {status: -1, message: "您输入的镜像仓库地址不合法。示例地址https://github.com/facebook/react.git"}
return
end
# 镜像仓库名
repo_name = @repository.try(:identifier)
# 如果仓库名存在并且不等于镜像仓库
if repo_name && @image_repo_name != repo_name
render :json => {status: -1, message: "系统检测到项目本身仓库和您设置的镜像仓库不一致,您可以删除项目仓库后再进行同步"}
return
end
# 同一个用户在不同的项目中不能使用同一个镜像地址
image_url_count = Project.where(:user_id => User.current.id, :image_url => image_url).count
if image_url_count > 1
render :json => {status: -1, message: "您已经在其它项目中使用过该镜像地址"}
return
end
# 如果不存在用户工作空间目录
unless File.directory?(@path)
FileUtils.mkdir_p(@path)
end
# status --> 2表示进入check_clone步骤
render :json => {:status => 0}
end
# 检测克隆是否完成
# push时间执行完异步取获取结果
# status --> 0正常完成克隆1克隆未完成
def check_clone
ActiveRecord::Base.transaction do
begin
logger.info("Dir is exist? --> #{Dir.exist?("#{@path}/#{@image_repo_name}")}")
g = Gitlab.client
# 有些仓库没有master分支
if @repository && g.project(@project.gpid) && Dir.exist?("#{@path}/#{@image_repo_name}") &&
(system("cd #{@path}/#{@image_repo_name} && git pull origin master") || system("cd #{@path}/#{@image_repo_name} && git pull"))
# 说明仓库已经克隆过只需push更新即可
render :json => {:status => 0}
else
# 以前没有克隆过的,则需要建立版本库并且克隆代码
g = Gitlab.client
s = Trustie::Gitlab::Sync.new
if @repository.nil?
@repository = Repository.create(:project_id => @project.id, :identifier => @image_repo_name) # 创建版本库
@repository.type ="Repository::Gitlab"
@repository.save
end
logger.info("############repository: #{@repository}")
gitlab_project = s.create_project(@project, @repository)
logger.info("############gitlab_project: #{gitlab_project}")
raise "### sync failed" if gitlab_project.try(:id).blank?
g.add_team_member(gitlab_project.id, 6, 40) # 40代表角色master
# 返回结果说明仓库正常,克隆步骤已完成
logger.info("###Dir is not exist path is: #{@path}/#{@image_repo_name}")
if Dir.exist?("#{@path}/#{@image_repo_name}")
system("rm -rf #{@path}/#{@image_repo_name}")
end
logger.info("### clone_and_push: image_url is #{@project.image_url}")
shell = system("cd #{@path} && git clone #{@project.image_url}")
if shell
render :json => {:status => 0, :message => "代码克隆完成"}
else
raise("代码克隆失败")
end
end
rescue Exception => e
g.delete_project(gitlab_project.id) if gitlab_project.try(:id)
@repository.delete if @repository
logger.info("import_project #{e.message}")
render :json => {:status => -1, :message => "版本库克隆异常,请稍后重试"}
raise ActiveRecord::Rollback
end
end
end
# push操作
# original_gitlab_url: forge版本库地址带用户名和密码的
# image_url: 镜像仓库地址,需要从远程镜像仓库克隆
# status --> 0正常提交1异常需要重试前端设置最多重试三次
def check_push
shell1 = system("cd #{@path}/#{@image_repo_name} && git pull origin master")
logger.info("shell1 is #{shell1}")
# 如果远程的remote_origin存在的话则不需要重新设置
shell2 = system("cd #{@path}/#{@image_repo_name} && git remote add remote_origin #{@gitlab_url}")
logger.info("shell2 is #{shell2}")
shell = system("cd #{@path}/#{@image_repo_name} && git push remote_origin master")
if shell
render :json => {:status => 0, :url => "#{Redmine::Configuration['host_address']}/projects/#{@project.id}/repository/#{@repository.try(:identifier)}",
:message => "代码同步完成"}
else
render :json => {:status => -1, :message => "代码同步异常,请稍后重试"}
end
end
def share
@shares = @project.shares.reverse
@base_courses_tag = @project.project_type
respond_to do |format|
format.html{render :layout => 'base_courses' if @base_courses_tag==1}
format.html{render :layout => 'base_courses' if @base_courses_tag == 1}
format.api
end
end
@ -258,54 +389,55 @@ class ProjectsController < ApplicationController
redirect_to signin_url
return
end
@issue_custom_fields = IssueCustomField.sorted.all
@trackers = Tracker.sorted.all
@project = Project.new
@project.safe_attributes = params[:project]
@project.user_id = User.current.id
params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0
if validate_parent_id && @project.save!
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
# Add current user as a project member if he is not admin
#unless User.current.admin?
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => User.current, :roles => [r])
# project's score
if ProjectScore.where("project_id=?", @project.id).first.nil?
ProjectScore.create(:project_id => @project.id, :score => false)
end
# end
project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id)
user_grades = UserGrade.create(:user_id => User.current.id, :project_id => @project.id)
Rails.logger.debug "UserGrade created: #{user_grades.to_json}"
#if params[:project][:is_public] == '1'
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0)
Rails.logger.debug "ProjectStatus created: #{project_status.to_json}"
#end
@project.members << m
@project.project_infos << project_info
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_create)
if params[:continue]
attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}
redirect_to new_project_url(attrs, :course => '0')
else
redirect_to settings_project_url(@project)
ActiveRecord::Base.transaction do
begin
# 创建项目
@project = Project.new
@project.safe_attributes = params[:project]
@project.user_id = User.current.id
params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0
if @project.save!
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => User.current, :roles => [r])
if ProjectScore.where("project_id=?", @project.id).first.nil?
ProjectScore.create(:project_id => @project.id, :score => 0)
end
}
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
format.js
end
else
respond_to do |format|
format.html { render :action => 'new', :layout => 'new_base'}#Added by young
format.api { render_validation_errors(@project) }
@project.members << m
identifier = generate_identifier
logger.info("project rep_identifier is #{identifier}")
repository = Repository.new
repository.type = 'Repository::Gitlab'
repository.identifier = identifier
repository.url = identifier
repository.project_id = @project.id
repository.save!
s = Trustie::Gitlab::Sync.new
gproject = s.create_project(@project, repository)
raise "版本库创建失败" if gproject.try(:id).blank?
@project.update_column(:rep_identifier, identifier)
flash[:notice] = l(:notice_successful_create)
redirect_to settings_project_url(@project)
end
rescue Exception => e
logger.error("failed: create repository #{e.message}")
flash[:notice] = "项目创建失败,请稍后重试"
redirect_to new_project_path
raise ActiveRecord::Rollback
end
end
end
# 随机生成唯一标识
def generate_identifier
code = "p" + DCODES.sample(8).join
return generate_identifier if Project.where(rep_identifier: code).present?
code
end
def copy
@issue_custom_fields = IssueCustomField.sorted.all
@trackers = Tracker.sorted.all
@ -331,9 +463,9 @@ class ProjectsController < ApplicationController
end
end
rescue ActiveRecord::RecordNotFound
# source_project not found
# source_project not found
render_404
end
end
# Time 2015-01-29 10:42:00
# Author lizanle
@ -429,7 +561,7 @@ class ProjectsController < ApplicationController
errors.each do |error|
# 版本库路径为空的错误信息不予提示
if(error!=l(:label_repository_path_not_null))
html << error << ";"
html << error << ";"
end
end
if params[:repository] == "pswd_is_null"
@ -437,25 +569,6 @@ class ProjectsController < ApplicationController
end
flash.now[:error] = html if !html.to_s.blank?
end
# for设置默认分支
@gitlab_repository = Repository.where(:project_id => @project, :type => "Repository::Gitlab").first
unless @gitlab_repository.nil?
gitlab_address = Redmine::Configuration['gitlab_address']
creator = @project.owner.try(:login)
@repos_url = gitlab_address+"/" + creator + "/" + @gitlab_repository.identifier+"."+"git"
end
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
@repository = Repository.factory(scm)
@repository.is_default = @project.repository.nil?
@repository.project = @project
@gitlab_rep = Repository.where(:type => "Repository::Gitlab", :project_id => @project).first
unless @project.gpid.nil?
g = Gitlab.client
@gitlab_branches = g.branches(@project.gpid)
@branch_names = @gitlab_branches.map{|b| b.name}
@gitlab_default_branch = g.project(@project.gpid).default_branch
end
end
# 项目邀请用户加入实现过程
@ -488,7 +601,7 @@ class ProjectsController < ApplicationController
flash[:notice] = l(:notice_email_sent, :value => email)
end
# 邮箱地址已被注册
# 邮箱地址已被注册
elsif !User.find_by_mail(params[:mail].to_s).nil?
user = User.find_by_mail(params[:mail].to_s)
if !user.member_of?(@project)
@ -698,9 +811,9 @@ class ProjectsController < ApplicationController
def sort_project_members project, members
#userGrade = UserGrade.where(:project_id => project.id)
users = UserGrade.where(:project_id => project.id).
order('grade DESC').
joins("LEFT JOIN users ON users.id = user_grades.id").
select("DISTINCT user_grades.user_id")
order('grade DESC').
joins("LEFT JOIN users ON users.id = user_grades.id").
select("DISTINCT user_grades.user_id")
memberlist = []
users.each do |user|
members.each do |member|
@ -751,8 +864,7 @@ class ProjectsController < ApplicationController
end
def update
@project.safe_attributes = params[:project]
@project.organization_id = params[:organization_id]
@project.update_attributes(params[:project])
params[:project][:is_public] == "on" ? @project.is_public = 1 : @project.is_public = 0
params[:project][:hidden_repo] == "on" ? @project.hidden_repo = 1 : @project.hidden_repo = 0
# 更新公开私有时同步gitlab公开私有
@ -814,8 +926,8 @@ class ProjectsController < ApplicationController
begin
g = Gitlab.client
g.delete_project(@project.gpid)
rescue Exception => e
puts e
rescue Exception => e
puts e
end
# 删除Trustie版本库记录
repoisitory = Repository.where(:project_id => @project.id, :type => GITLABTYPE).first
@ -1018,7 +1130,6 @@ class ProjectsController < ApplicationController
jour.notes = content
jour.journalized = @training_task
jour.save
update_user_activity(@training_task.class, @training_task.id)
update_forge_activity(@training_task.class, @training_task.id)
end
@ -1123,11 +1234,11 @@ class ProjectsController < ApplicationController
# Delete @project
def destroy
ActiveRecord::Base.transaction do
g = Gitlab.client
g.delete_project(@project.gpid)
#g = Gitlab.client
#g.delete_project(@project.gpid)
# 删除Trustie版本库记录
repoisitory = Repository.where(:project_id => @project.id, :type => GITLABTYPE).first
repoisitory.delete
repoisitory.delete if repoisitory.present?
@project.update_column(:gpid, nil)
@project.update_column(:forked_from_project_id, nil)
@project_to_destroy = @project
@ -1136,6 +1247,8 @@ class ProjectsController < ApplicationController
respond_to do |format|
if params[:type] == "project"
format.html{redirect_to user_path(User.current)}
elsif params[:type] == "management"
format.js{redirect_to projects_list_managements_path}
else
format.html{redirect_to admin_projects_url(:status => params[:status])}
end
@ -1179,29 +1292,29 @@ class ProjectsController < ApplicationController
format.js
end
end
def issue_score_index
respond_to do |format|
format.js
end
respond_to do |format|
format.js
end
end
def news_score_index
end
def file_score_index
end
def code_submit_score_index
end
def projects_topic_score_index
end
# end
# end
# 最好通过用户与项目的权限解决这种事情。还没写
def finishcourse
@ -1275,6 +1388,14 @@ class ProjectsController < ApplicationController
end
private
def import_base
@image_repo_name = @project.image_url.split("/").last.split(".").first
@repository = @project.repository
@login = @project.owner.login
@path = "#{Redmine::Configuration['repository_path']}/#{@login}"
@gitlab_url = "http://p83921064:xinhu1ji2qu3@117.50.12.128:7889/#{@login}/#{@image_repo_name}.git"
end
def memberAccess
# 如果是私有项目,项目成员不对外公开,公开项目成员列表对外公开。
@ -1298,7 +1419,7 @@ class ProjectsController < ApplicationController
parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
unless @project.allowed_parents.include?(parent)
@project.errors.add :parent_id, :invalid
return false
return false
end
end
true

View File

@ -39,12 +39,6 @@ class RepositoriesController < ApplicationController
before_filter :find_project_repository, :except => [:commits, :shixun_show, :new, :create, :newcreate, :edit, :update, :destroy, :committers,
:newrepo, :to_gitlab, :forked, :export_rep_static, :training_project_extend, :shixun_entry, :shixun_commit_diff]
# 实训项目新增
before_filter :find_project_and_repository, :only => [:commits, :shixun_show, :shixun_entry, :shixun_commit_diff]
# 连接gitlab
# before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff]
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
# before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff]
before_filter :authorize_visible , :except => [:shixun_show, :newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :shixun_commit_diff]
@ -62,7 +56,13 @@ class RepositoriesController < ApplicationController
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
def new
@project_menu_type = 5
logger.info("#########new start #{User.current.login}")
logger.info("#########1new star11 #{@project.repositories.count == 0}")
logger.info("#########1new start12#{User.current.admin?}")
logger.info("#########1new start23 #{User.current.manager_of_project?(@project.id)}")
if @project.repositories.count == 0
logger.info("########ddd#new start #{User.current.login}")
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
@repository = Repository.factory(scm)
@repository.is_default = @project.repository.nil?
@ -75,6 +75,7 @@ class RepositoriesController < ApplicationController
render :layout => 'base_projects'
end
else
logger.info("#########new start #{User.current.login}")
render_403
end
@ -340,54 +341,26 @@ class RepositoriesController < ApplicationController
render :action => 'show', :layout => 'base_projects'
end
HOOK_TEMPLATE = %Q{#!/bin/sh
exec sh -c '
function update()
{
CMD_PATH=`dirname $0`;
cd $CMD_PATH;
PY_PATH=$PWD/../../git_refresh_changes.py;
[[ -s "$PY_PATH" ]] && $(which python) $PY_PATH $PWD;
cd -;
}
git update-server-info
update
'
}
def create
# 判断版本库创建者是否有同名版本库,避免版本库路径一致问题
unless is_sigle_identifier?(@project.user_id, params[:repository].first[1])
flash[:notice] = l(:project_gitlab_create_double_message)
redirect_to new_project_repository_path(@project)
else
attrs = pickup_extra_info
@repository = Repository.factory('Git')
@repository.safe_attributes = params[:repository]
if attrs[:attrs_extra].keys.any?
@repository.merge_extra_info(attrs[:attrs_extra])
end
@repository.project = @project
@repository.type = 'Repository::Gitlab'
@repository.identifier = @repository.identifier.downcase
@repository.url = @repository.identifier
ActiveRecord::Base.transaction do
begin
if request.post? && @repository.save!
s = Trustie::Gitlab::Sync.new
s.create_project(@project, @repository)
raise "sync failed" if @project.gpid.blank?
redirect_to(:controller => 'repositories', :action => 'show', :id => @project, :repository_id => gitlab_repository(@project).try(:identifier))
else
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
end
rescue Exception => e
logger.info("create repository #{e.message}")
@repo_error= "666"
redirect_to settings_project_url(@project, :tab => 'repositories', :create_error => "版本库创建失败,用户名或版本库名中不允许包含特殊字符")
raise ActiveRecord::Rollback
logger.info("################{params[:repository][:identifier]}")
ActiveRecord::Base.transaction do
begin
@repository = Repository.new(:project_id => @project.id, :identifier => params[:repository][:identifier])
@repository.type = 'Repository::Gitlab'
if request.post? && @repository.save!
s = Trustie::Gitlab::Sync.new
gproject = s.create_project(@project, @repository)
raise "sync failed" if @project.gpid.blank?
Gitlab.client.add_team_member(gproject.id, 6, 40) # 40代表角色master
redirect_to(:controller => 'repositories', :action => 'show', :id => @project, :repository_id => gitlab_repository(@project).try(:identifier))
else
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
end
# rescue Exception => e
# logger.error("create repository #{e.message}")
# @repo_error= "666"
# redirect_to settings_project_url(@project, :tab => 'repositories', :create_error => "版本库创建失败,用户名或版本库名中不允许包含特殊字符")
# raise ActiveRecord::Rollback
end
end
end
@ -480,10 +453,10 @@ update
end
def destroy
DestroyRepositoryTask.new.destroy(User.current.id, @repository.id)
@repository.hidden = true
@repository.save
redirect_to settings_project_url(@project, :tab => 'repositories')
# DestroyRepositoryTask.new.destroy(User.current.id, @repository.id)
# @repository.hidden = true
# @repository.save
# redirect_to settings_project_url(@project, :tab => 'repositories')
end
def to_gitlab
@ -631,6 +604,7 @@ update
g = Gitlab.client
limit = 10
# 每次页面的换回值从1开始,但是gitlab的页面查询是从0开始,所以先改变page的类型减一在改回来
@env = @env ? @env : "master"
@commits = g.commits(@project.gpid, page:(params[:page].to_i - 1).to_s, ref_name:@rev)
@commits_count = params[:commit_count].nil? ? @g.user_static(@project.gpid, :rev => @rev).count : params[:commit_count].to_i
@commits_pages = Paginator.new @commits_count, limit, params[:page]
@ -931,15 +905,16 @@ update
end
def authorize_visible
allowed = authorize_allowed(params[:controller], params[:action], global = false)
if allowed || User.current.admin? || (@project.hidden_repo && User.current.member_of?(@project) && !role_of_members_in_project(@project.id, User.current.id) == "Reporter")
if !@project.is_public? || @project.hidden_repo
(User.current.member_of?(@project) || User.current.admin?) ? true : render_403
else
true
end
if User.current.member_of?(@project) || User.current.admin?
true
else
if @project && @project.archived?
render_403 :message => :notice_not_authorized_archived_project
else
deny_access
end
(!@project.hidden_repo && !@project.archived?) ? true : render_403
end
end
@ -978,12 +953,11 @@ update
end
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
REP_TYPE = "Repository::Gitlab"
# 获取项目、版本库、路劲、默认分支
def find_project_repository
@project = Project.find(params[:id])
@repository = Repository.where(:type => REP_TYPE, :project_id => @project).first
@repository = Repository.where(:project_id => @project).first
(render_404; return false) unless (@repository || @project.gpid)
@path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s
@g = Gitlab.client

View File

@ -199,7 +199,6 @@ class TrainingTasksController < ApplicationController
jour.journalized = @training_task
jour.save_attachments(params[:attachments])
jour.save
update_user_activity(@training_task.class, @training_task.id)
update_forge_activity(@training_task.class, @training_task.id)
# @allowed_statuses = @training_task.new_statuses_allowed_to(User.current)
@user_activity_id = params[:user_activity_id]
@ -260,7 +259,6 @@ class TrainingTasksController < ApplicationController
# new_jour = @issue.journals.build(:user_id => User.current.id, :reply_id => params[:journal_id], :notes => params[:content], :parent_id => jour.id)
@user_activity_id = params[:user_activity_id]
if new_jour.save
update_user_activity(@training_task.class, @training_task.id)
update_forge_activity(@training_task.class, @training_task.id)
respond_to do |format|
if params[:is_issue_show]

View File

@ -239,7 +239,7 @@ class UsersController < ApplicationController
if User.current == @user || User.current.admin?
@onclick_time = User.current.onclick_time.onclick_time
User.current.onclick_time.update_attribute(:onclick_time, Time.now)
@tids = @user.tidings
@tids = @user.tidings.where(:tiding_type => ["project", "Apply", "System", "Comment", "Mentioned", "Praise", "Fan"])
if params[:type]
case params[:type]
when "project"
@ -322,7 +322,7 @@ class UsersController < ApplicationController
@new_mess_count = 0
@messages = PrivateMessage.find_by_sql("SELECT ui.* FROM (SELECT * FROM private_messages WHERE STATUS != 2 AND user_id = #{@user.id} ORDER BY id DESC) ui GROUP BY ui.target_id ORDER BY ui.send_time DESC")
respond_to do |format|
format.html{ render :layout => "base_edu_user" }
format.html{ render :layout => "forge" }
end
else
render_404
@ -471,14 +471,6 @@ class UsersController < ApplicationController
@is_project = params[:is_project]
case params[:type]
when 'HomeworkCommon', 'Work'
@reply = JournalsForMessage.find params[:reply_id]
@type = params[:type]
if params[:user_activity_id]
@user_activity_id = params[:user_activity_id]
else
@user_activity_id = -1
end
when 'JournalsForMessage'
@reply = JournalsForMessage.find params[:reply_id]
@user_activity_id = params[:user_activity_id]
@ -504,19 +496,11 @@ class UsersController < ApplicationController
@user_activity_id = params[:user_activity_id]
@activity_id = params[:activity_id]
@type = 'Training_task'
when 'Syllabus'
@reply = JournalsForMessage.find params[:reply_id]
@type = 'Syllabus'
when 'Memo'
@reply = Memo.find params[:reply_id]
@user_activity_id = params[:user_activity_id]
@activity_id = params[:activity_id]
@type = 'Memo'
when 'Challenge'
@reply = Discuss.find params[:reply_id]
@user_activity_id = params[:user_activity_id]
@activity_id = params[:activity_id]
@type = 'Challenge'
end
respond_to do |format|
format.js
@ -636,9 +620,7 @@ class UsersController < ApplicationController
return
end
update_user_activity(@root.class.to_s,@root.id)
update_forge_activity(@root.class.to_s,@root.id)
update_principal_activity(@root.class.to_s,@root.id)
respond_to do |format|
format.js
end
@ -1029,11 +1011,6 @@ class UsersController < ApplicationController
end
def show_new_score
render :layout => 'users_base'
end
# end
##added by fq
def watch_bids
# cond = 'bids.reward_type <> 1'
@ -1496,7 +1473,6 @@ class UsersController < ApplicationController
student_work.save
send_message_to_teacher(student_work)
homework.update_column(:updated_at, Time.now)
update_user_activity(homework.class,homework.id)
flash[:notice] = l(:notice_successful_create)
redirect_to student_work_index_url(:homework => params[:homework], :tab => 2)
@ -1826,72 +1802,6 @@ class UsersController < ApplicationController
end
#end
def index
@status = params[:status] || 1
sort_init 'login', 'asc'
sort_update %w(login firstname lastname mail admin created_on last_login_on)
case params[:format]
when 'xml', 'json'
@offset, @limit = api_offset_and_limit({:limit => 15})
else
@limit = 15
end
# retrieve all users
# 先内连一下statuses 保证排序之后数量一致
scope = User.visible.
joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id")
# unknow
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
# pagination
@user_count = scope.count
@user_pages = Paginator.new @user_count, @limit, params['page']
# users classify
case params[:user_sort_type]
when '0'
# 创建时间排序
@s_type = 0
@users = scope.reorder('users.created_on DESC')
when '1'
# 活跃度排序, 就是所谓的得分情况
@s_type = 1
@users = scope.
joins("LEFT JOIN option_numbers ON users.id = option_numbers.user_id and option_numbers.score_type = 1").
reorder('option_numbers.total_score DESC')
when '2'
# 粉丝数排序
@s_type = 2
@users = scope.
#joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id").
reorder('user_statuses.watchers_count DESC')
else
# 默认活跃度排序
@s_type = 1
@users = scope.
joins("LEFT JOIN option_numbers ON users.id = option_numbers.user_id and option_numbers.score_type = 1").
reorder('option_numbers.total_score DESC')
end
# limit and offset
@users = @users.limit(@user_pages.per_page).offset(@user_pages.offset)
@user_base_tag = params[:id] ? 'base_users':'users_base'
respond_to do |format|
format.html {
@groups = Group.all.sort
User.current.admin? ? (render :layout => @user_base_tag) : (render_404)
}
format.api
end
end
def search
sort_init 'login', 'asc'
sort_update %w(login firstname lastname mail admin created_on last_login_on)
@ -3789,7 +3699,7 @@ class UsersController < ApplicationController
@user_fanlist_count = fan_query.count
@user_fanlist = fan_query.order("#{Watcher.table_name}.id desc")
respond_to do |format|
format.html {render :layout => 'base_edu_user'}
format.html {render :layout => 'forge'}
end
end
@ -4504,10 +4414,6 @@ class UsersController < ApplicationController
def all_journals
if params[:type].present?
case params[:type]
when 'OrgDocumentComment'
@user_activity_id = params[:div_id].to_i if params[:div_id]
@type = 'OrgDocumentComment'
@journals = OrgDocumentComment.where("root_id = #{params[:id].to_i}").reorder("created_at desc")
when 'Message','is_project_message'
@type = 'Message'
@user_activity_id = params[:div_id].to_i if params[:div_id]
@ -4517,23 +4423,18 @@ class UsersController < ApplicationController
@journals = obj.comments.reorder("created_on desc")
@type = 'News'
@user_activity_id = params[:div_id].to_i if params[:div_id]
when 'Syllabus'
obj = Syllabus.where('id = ?', params[:id].to_i).first
@journals = obj.journals_for_messages.reorder("created_on desc")
@type = 'Syllabus'
@user_activity_id = params[:div_id].to_i if params[:div_id]
when 'JournalsForMessage'
@journals = JournalsForMessage.where("root_id = #{params[:id].to_i}").reorder("created_on desc")
@type = 'JournalsForMessage'
@user_activity_id = params[:div_id].to_i if params[:div_id]
when 'Issue'
obj = Issue.where('id = ?', params[:id].to_i).first
@journals = obj.journals.reorder("created_on desc")
@journals = obj.journals.includes(:user, :details).where(:parent_id => nil).reorder("created_on desc")
@type = 'Issue'
@user_activity_id = params[:div_id].to_i if params[:div_id]
when 'is_project_issue'
@activity = Issue.where('id = ?', params[:id].to_i).first
@journals = @activity.journals.reorder("created_on desc")
@journals = @activity.journals.includes(:user, :details).where(:parent_id => nil).reorder("created_on desc")
@user_activity_id = params[:div_id].to_i if params[:div_id]
@user_activity = ForgeActivity.where(params[:div_id].to_i).first if params[:div_id]
when 'is_project_training_task'
@ -4543,7 +4444,7 @@ class UsersController < ApplicationController
@user_activity = ForgeActivity.where(params[:div_id].to_i).first if params[:div_id]
end
end
@journals = get_no_children_comments_all @journals
# @journals = get_no_children_comments_all @journals
end
def homepage

View File

@ -22,15 +22,104 @@ class WelcomeController < ApplicationController
include WelcomeHelper
helper :project_score
caches_action :robots, :course, :contest, expires_in: 2.hours, layout: false
#before_filter :find_first_page, :only => [:index]
# before_filter :fake, :only => [:index, :course]
before_filter :entry_select, :only => [:index]
skip_before_filter :check_authentication, :only => [:index]
skip_before_filter :check_authentication, :only => [:index, :about, :service, :join, :contact]
skip_before_filter :session_expiration, :only => [:index, :about, :service, :join, :contact]
def index
# 左侧导航栏
@left_forum = Forum.order("sticky asc").limit(5)
# 中间栏memos
m_ids = MemoForum.where(:forum_id => @left_forum.map(&:id)).pluck(:memo_id)
@top_memos = Memo.where(:root_id => nil, :id => m_ids, :homepage_show => true).order("published_at desc").limit(1)
@botton_memos = Memo.where(:root_id => nil, :id => m_ids, :homepage_show => false).order("published_at desc").limit(7)
# 右侧通知通告
@notification_forum = Forum.order("sticky asc").offset(5).first
if @notification_forum.present?
memo_ids = MemoForum.where(:forum_id => @notification_forum.id).pluck(:memo_id)
@notification_memos = Memo.where(:id => memo_ids, :root_id => nil).order("published_at desc").limit(5)
end
# 右侧出版物
@publication_forum = Forum.order("sticky asc").offset(6).first
if @publication_forum.present?
memo_ids = MemoForum.where(:forum_id => @publication_forum.id).pluck(:memo_id)
@publication_memos = Memo.where(:id =>memo_ids, :root_id => nil).order("published_at desc").limit(3)
end
# 右侧最新招聘
@employment_forum = Forum.order("sticky asc").offset(7).first
if @employment_forum.present?
memo_ids = MemoForum.where(:forum_id => @employment_forum.id).pluck(:memo_id)
@employment_memos = Memo.where(:id => memo_ids, :root_id => nil).order("published_at desc").limit(6)
end
# 广告
@ad_1 = Advertisement.where(:position => 1).first
render :layout => 'forge'
end
# 关于我们
def about
render :layout => 'forge'
end
# 联盟服务
def service
render :layout => 'forge'
end
# 加入联盟
def join
render :layout => 'forge'
end
# 联系我们
def contact
render :layout => 'forge'
end
def get_homepage_info
forum_id = params[:type]
if forum_id.to_i == -1
@top_memos = Project.order("created_on desc").limit(1)
@botton_memos = Project.order("created_on desc").offset(1).limit(6)
elsif forum_id
memo_ids = MemoForum.where(:forum_id => forum_id).pluck(:memo_id)
@top_memos = Memo.where(:root_id => nil, :id => memo_ids).order("published_at desc").limit(1)
@botton_memos = Memo.where(:root_id => nil, :id => memo_ids).order("published_at desc").offset(1).limit(6)
else
left_forum = Forum.order("sticky asc").limit(5)
memo_ids = MemoForum.where(:forum_id => left_forum.map(&:id)).pluck(:memo_id)
@top_memos = Memo.where(:root_id => nil, :id => memo_ids, :homepage_show => true).order("published_at desc").limit(1)
@botton_memos = Memo.where(:root_id => nil, :id => memo_ids, :homepage_show => false).order("published_at desc").limit(7)
end
respond_to do |format|
format.js
end
end
# 首页滚动时,加载数据
# params :type -2表示推荐 -1 表示开源项目 其他表示forum_id
def get_scroll_data
forum_id = params[:type].to_i
page = params[:page].to_i
@botton_memos =
if forum_id == -1
Project.order("created_on desc").offset(8*page).limit(8)
elsif forum_id == -2
left_forum = Forum.order("sticky asc").limit(5)
memo_ids = MemoForum.where(:forum_id => left_forum.map(&:id)).pluck(:memo_id)
Memo.where(:root_id => nil, :id => memo_ids).order("created_at desc").offset(8*page).limit(8)
elsif forum_id
memo_ids = MemoForum.where(:forum_id => forum_id).pluck(:memo_id)
Memo.where(:root_id => nil, :id => memo_ids).order("created_at desc").offset(8*page).limit(8)
end
respond_to do |format|
format.js
end
end
def robots
@projects = Project.all_public.active
render :layout => false, :content_type => 'text/plain'

View File

@ -60,9 +60,7 @@ class WordsController < ApplicationController
@jfm = add_reply_adapter(@activity, options)
@save_succ = true if @jfm.errors.empty?
if @save_succ
update_user_activity('JournalsForMessage',@activity.id)
update_forge_activity('JournalsForMessage',@activity.id)
update_principal_activity('JournalsForMessage',@activity.id)
@activity.update_attribute(:updated_on,Time.now)
end
respond_to do |format|
@ -349,7 +347,6 @@ class WordsController < ApplicationController
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
end
@homework.update_column('updated_at', Time.now)
update_user_activity(@homework.class,@homework.id)
respond_to do |format|
format.js{
@user_activity_id = params[:user_activity_id].to_i
@ -381,7 +378,6 @@ class WordsController < ApplicationController
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
end
@homework.update_column('updated_at', Time.now)
update_user_activity(@homework.class,@homework.id)
respond_to do |format|
format.js{
@user_activity_id = params[:user_activity_id].to_i
@ -411,7 +407,6 @@ class WordsController < ApplicationController
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
end
@contestwork.update_column('updated_at', Time.now)
update_user_activity(@contestwork.class,@contestwork.id)
respond_to do |format|
format.js{
@user_activity_id = params[:user_activity_id].to_i
@ -443,7 +438,6 @@ class WordsController < ApplicationController
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
end
@contestwork.update_column('updated_at', Time.now)
update_user_activity(@contestwork.class,@contestwork.id)
respond_to do |format|
format.js{
@user_activity_id = params[:user_activity_id].to_i

View File

@ -178,7 +178,7 @@ module ApiHelper
lastUpdateTime = time.to_i*1000
currentTime = Time.now.to_i*1000
timePassed = currentTime - lastUpdateTime;
timePassed = currentTime - lastUpdateTime
timeIntoFormat = 0
updateAtValue = ""
if timePassed < 0

View File

@ -47,6 +47,60 @@ module ApplicationHelper
end
end
def home_memo_image(memo, default_image, options={})
attach = memo.attachments.where(:memo_image => true).first
if memo.present? && attach.present?
# 首页列表的图片要做宽高比处理
if options[:height] == "120"
"<div style='width:160px;height:120px; position: relative;background: transparent; margin-right: 10px;border: 1px solid #e2e2e2;' ><img src='/attachments/download/#{attach.id}' width='160' height='120' class='#{options[:class]} list_img' id='ttt' style=' ' ><div class='img_mask' style='width: 100%; height: 100%; position: absolute; top: 0px; background: #fafafa; display: block;'></div></div>".html_safe
else
"<img src='/attachments/download/#{attach.id}' width='#{options[:width]}' height='#{options[:height]}' class='#{options[:class]}'>".html_safe
end
else
"<img src='#{default_image}' width='#{options[:width]}' height='#{options[:height]}' class='#{options[:class]}'>".html_safe
end
end
def forum_btn_html memo
forum_name = memo.class.to_s == 'Project' ? ["开源项目"] : memo.forums.map(&:name)
name = ""
forum_name.each do |n|
case n
when '行业新闻'
name += "<span class=\"fl news_tag tag-color-green mr10\">行业新闻</span>"
when '开源项目'
name += "<span class=\"fl news_tag tag-color-orange mr10\">开源项目</span>"
else
name += "<span class=\"fl news_tag tag-color-blue mr10\">#{n}</span>"
end
end
name.html_safe
end
def forum_img_html memo
forum_name = memo.class.to_s == 'Project' ? ["开源项目"] : memo.forums.map(&:name)
case forum_name.first
when '联盟动态'
home_memo_image(memo, "/images/trustieForge/welcomelianmeng.jpg",:width => "160", :height => '120', :class => "mr10")
when '成果展示'
home_memo_image(memo, "/images/trustieForge/welcomechengguo.jpg",:width => "160", :height => '120', :class => "mr10")
when '开源项目'
home_memo_image(memo, "images/trustieForge/welcome/kaiyuan.jpg",:width => "160", :height => '120', :class => "mr10")
when '行业新闻'
home_memo_image(memo, "/images/trustieForge/welcome/xinwen.jpg",:width => "160", :height => '120', :class => "mr10")
when '产业动态'
home_memo_image(memo, "/images/trustieForge/welcome/chanye.jpg",:width => "160", :height => '120', :class => "mr10")
when '会员风采'
home_memo_image(memo, "/images/trustieForge/welcome/huiyuan.jpg",:width => "160", :height => '120', :class => "mr10")
end
end
# 项目语言
def project_languages
["C", "C#", "C++", "Clojure", "CoffeeScript", "CSS", "GO", "Haskell", "HTML", "Java", "Javascript", "Lua", "Matlab",
"Objective-C", "Perl", "PHP", "Python", "R", "Ruby", "Scala", "Shell", "Swift", "TeX"]
end
# welcome首页门户定制
def welcome_forum_sticky sticky, limit
forum = Forum.where(:sticky => sticky).first
@ -56,7 +110,18 @@ module ApplicationHelper
# 处理有置顶的帖子
def welcome_forum sticky, limit
forum = Forum.where(:sticky => sticky).first
memos = forum.memos.where(:parent_id => nil).order("created_at desc").limit(limit)
if forum.present?
memos = forum.memos.where(:parent_id => nil).order("created_at desc").limit(limit)
else
return nil
end
end
# 精彩回复
def wonderful_forum sticky, limit
forum = Forum.where(:sticky => sticky).first
return nil unless forum
memos = forum.memos.where(:parent_id => nil).order("replies_count desc").limit(limit)
end
def container_limit mirror_repositories
@ -106,16 +171,10 @@ module ApplicationHelper
user_e = UserExtensions.where(:user_id => User.current.id).first
if User.current.lastname.blank? || user_e.school_id.blank? || user_e.identity.blank? || User.current.mail.blank?
redirect_to user_info_path()
Rails.logger.info("check_authentication end")
Rails.logger.info("info check_authentication end")
return
elsif User.current.certification != 1
day_cer = UserDayCertification.where(:user_id => User.current.id).last
unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400
redirect_to my_account_path()
Rails.logger.info("check_authentication end")
return
end
end
Rails.logger.info("check_authentication end")
end
def match_specific_symbol(str)
@ -129,19 +188,23 @@ module ApplicationHelper
# 积分表中建立记录行为,有过奖励则不重复奖励
def reward_grade(user, container_id, container_type, score)
=begin
grade = Grade.where(:user_id => user.id, :container_id => container_id, :container_type => container_type).first
if grade.nil?
Grade.create!(:user_id => user.id, :container_id => container_id, :container_type => container_type, :score => score)
user.update_column(:grade, (score.to_i + user.grade.to_i))
end
=end
end
def reward_experience(user, container_id, container_type, score)
=begin
experience = Experience.where(:user_id => user.id, :container_id => container_id, :container_type => container_type).first
if experience.nil?
Experience.create!(:user_id => user.id, :container_id => container_id, :container_type => container_type, :score => score)
user.update_column(:experience, (score.to_i + user.experience.to_i))
end
=end
end
# 平均耗时
@ -394,6 +457,8 @@ module ApplicationHelper
def managements_navigation_bar_show menu_type, sub_type, grandchild_type={}
case menu_type
when 1
"项目列表"
when 2
sub_type == 1 ? "课程列表" : (sub_type == 2? "课堂列表" : "实训作业")
when 3
@ -435,12 +500,9 @@ module ApplicationHelper
"单位部门列表"
end
when 7
sub_type == 1 ? "用户列表" : (sub_type == 2 ? "试用授权列表" : "自动授权列表")
sub_type == 1 ? "用户列表" : (sub_type == 2 ? "职业信息列表" : "自动授权列表")
when 8
sub_type == 1 ? "作业回复" :
(sub_type == 2 ? "实训反馈" :
(sub_type == 3 ? "讨论区" : "课堂讨论区")
)
"讨论区"
when 9
sub_type == 1 ? "实训留言列表" : ""
when 10
@ -457,9 +519,9 @@ module ApplicationHelper
when 11
"工程认证+"
when 12
sub_type == 1 ? "过关任务模板" :
(sub_type == 2 ? "实训简介模板" :
(sub_type == 3 ? "背景知识模板" :
sub_type == 1 ? "公共属性" :
(sub_type == 2 ? "贴吧和门户配置" :
(sub_type == 3 ? "广告列表" :
(sub_type == 4 ? "通用评测模板" :
(sub_type == 5 ? "新课导语模板" :
(sub_type == 6 ? "实训评分设置" : "技术体系")
@ -1111,6 +1173,15 @@ module ApplicationHelper
atts.count > 0 ? true :false
end
#项目动态更新
def update_forge_activity type, id
forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id).first
if forge_activity
forge_activity.updated_at = Time.now
forge_activity.save
end
end
# 必须是项目成员,项目必须提交过代码
def allow_pull_request project
return 0 if project.gpid.nil?
@ -1460,7 +1531,7 @@ module ApplicationHelper
if @project
title << (@project.name.present? ? @project.name : "项目")
elsif params[:controller] == "projects"
title << "项目"
title << "开源项目"
elsif @welcome
title << "创新源于实践"
elsif @course
@ -1529,7 +1600,7 @@ module ApplicationHelper
elsif @syllabus
title << (@syllabus.title.nil? ? "在线课堂" : @syllabus.title)
else
title << (User.current.id == 2 ? "未登录" : User.current.show_name)
title << (User.current.id == 2 ? "可控开源社区" : User.current.show_name)
end
# if first_page.nil? || first_page.web_title.nil?
# title << Setting.app_title unless Setting.app_title == title.last
@ -2501,7 +2572,7 @@ module ApplicationHelper
end
def favicon
"<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />".html_safe
"<link rel='shortcut icon' href='#{image_path('/images/trustieForge/Forgelogo')}' />".html_safe
end
def robot_exclusion_tag
@ -2703,7 +2774,9 @@ module ApplicationHelper
def attachment_candown attachment
candown = false
if attachment.container
if attachment.container_type == 'IssueImage' || attachment.container_type == 'ProjectImage'
candown = true
elsif attachment.container
if attachment.container.class.to_s=="PhoneAppVersion"
candown = true
elsif attachment.container.class.to_s != "HomeworkAttach" && attachment.container.class.to_s != "StudentWork" && attachment.container.class.to_s != "ContestantWork" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project
@ -2716,56 +2789,14 @@ module ApplicationHelper
attachment.container.board.project
project = attachment.container.board.project
candown = User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
elsif (attachment.container.has_attribute?(:course) ||attachment.container.has_attribute?(:course_id) ) && attachment.container.course
course = attachment.container.course
candown = User.current.member_of_course?(course) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2
elsif attachment.container.is_a?(Course)
course = attachment.container
candown= User.current.member_of_course?(course) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2
elsif attachment.container.is_a?(OrgSubfield)
org = attachment.container.organization
candown = User.current.member_of_org?(org) || ((attachment.is_public == 1 || attachment.get_status_by_attach(User.current.id) == 2) && org.allow_guest_download == true)
elsif attachment.container.is_a?(OrgDocumentComment)
org = attachment.container.organization
candown = org.allow_guest_download || User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1)
elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board &&
attachment.container.board.course
course = attachment.container.board.course
candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
elsif attachment.container.class.to_s=="Organization"
candown = true
elsif attachment.container.class.to_s=="HomeworkAttach"
candown = true
elsif attachment.container.class.to_s=="StudentWorksScore"
candown = true
elsif attachment.container.class.to_s=="StudentWork"
candown = true
elsif attachment.container.class.to_s=="Contest"
candown = true
elsif attachment.container.class.to_s=="Work"
candown = true
elsif attachment.container.class.to_s=="ContestantWork"
candown = true
elsif attachment.container.class.to_s=="HomeworkBank"
candown = true
elsif attachment.container.class.to_s=="BlogComment" #博客资源允许下载
candown = true
elsif attachment.container.class.to_s=="Memo" #论坛资源允许下载
candown = true
elsif attachment.container.class.to_s=="Syllabus" #论坛资源允许下载
elsif attachment.container.class.to_s=="Memo" || attachment.container.class.to_s == 'Issue' #论坛资源允许下载
candown = true
elsif attachment.container.class.to_s == "User"
candown = (attachment.is_public == 1 || attachment.is_public == true || attachment.author_id == User.current.id)
elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses
course = attachment.container.courses.first
candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1)
else
candown = (attachment.is_public == 1 || attachment.is_public == true)
end
else
if attachment.container_type == "Shixun" || attachment.container_type == "Inform" || attachment.container_type == "Memo"
candown = true
end
end
candown
end

View File

@ -48,7 +48,11 @@ module AvatarHelper
"#{source_id}#{type}"
end
def disk_filename(source_type,source_id,image_file=nil)
# def disk_filename(source_type,source_id,image_file=nil)
# File.join(storage_path,avatar_directory(source_type),avatar_filename(source_id,image_file))
# end
def disk_filename_avatar(source_type,source_id,image_file=nil)
File.join(storage_path,avatar_directory(source_type),avatar_filename(source_id,image_file))
end
@ -59,6 +63,11 @@ module AvatarHelper
def disk_auth_filename(source_type,source_id,type)
File.join(storage_path,avatar_directory(source_type),auth_filename(source_id,type))
end
def disk_logo_filename(source_type)
file_path = File.join(Rails.root, "public", "images", "trustieForge")
File.join(file_path, "#{source_type}")
end
def file_extension(filename=nil)
$1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
@ -68,7 +77,7 @@ module AvatarHelper
if source.nil?
return File.join(relative_path,'AnonymousUser','0')
end
if source.class && source.id && File.exist?(disk_filename(source.class,source.id))
if source.class && source.id && File.exist?(disk_filename_avatar(source.class,source.id))
avatar_image(source, false)
else
if source.class.to_s == "User"

View File

@ -33,7 +33,7 @@ module MembersHelper
#获取项目可邀请的成员列表
def render_project_members project
if params[:q] && params[:q].lstrip.rstrip != ""
scope = Principal.active.sorted.not_member_of(project).where("mail is not null and mail != ''").like(params[:q])
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
else
scope = []
end
@ -45,6 +45,10 @@ module MembersHelper
s + content_tag('ul', links,:class => 'wlist', :id => "course_member_pagination_links" )
end
def user_url_in_org(user_id)
Setting.protocol + "://" + Setting.host_name + "/users/" + user_id.to_s
end
# add by nwb
# 课程可添加的成员列表
def render_principals_for_new_course_members(course)

View File

@ -0,0 +1,18 @@
# encoding: utf-8
#
# name: 广告名称
# link_to: 广告链接
# position: 投放位置
# status 0未发布, 1已发布
# published_at: 发布时间
class Advertisement < ActiveRecord::Base
# attr_accessible :title, :body
after_create :save_filename
def save_filename
self.update_column(:name, "Advertisement_#{self.id}")
end
end

View File

@ -14,14 +14,6 @@ class AppliedProject < ActiveRecord::Base
def send_appliled_message
self.project.managers.each do |member|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => false, :viewed => false, :applied_user_id => self.user_id, :role => self.role, :project_id => self.project_id)
#----------------微信通知----------------------
# count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count
# if count == 0
# ws = WechatService.new
# ws.project_review_notice member.user_id, "review_project_member", self.project_id, "项目成员审批通知。", self.project.name, self.user.show_name, format_time(Time.now),"点击查看申请详情。",self.user.id
# end
#--------------------------------------------
end
# end
end

View File

@ -113,16 +113,6 @@ class AtMessage < ActiveRecord::Base
count = 0
detail_title = detail_title.gsub(/RE: /, '')
if container_id != 0
count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='#{shield_type}' and shield_id=#{container_id}").count
end
if count == 0 && status == 0
message_title = self.sender.show_name+"@了您"
ws = WechatService.new
ws.at_notice user.id, type, detail_id, message_title, detail_title, format_time(Time.now), detail_content, "点击查看详情。",0
end
end
def subject

View File

@ -30,7 +30,6 @@ class Attachment < ActiveRecord::Base
# end
include UserScoreHelper
has_many :attachment_histories
has_many :attachment_group_settings, :dependent => :destroy
validates :filename, presence: true, length: {maximum: 254}
validates :author, presence: true

View File

@ -20,7 +20,7 @@ class ForgeActivity < ActiveRecord::Base
validates :forge_act_id,presence: true
validates :forge_act_type, presence: true
has_many :user_acts, :class_name => 'UserActivity',:as =>:act
after_create :add_user_activity
# after_create :add_user_activity
before_destroy :destroy_user_activity
# 在个人动态里面增加当前动态

View File

@ -1,9 +1,12 @@
# sticky 表示帖子的位置
class Forum < ActiveRecord::Base
include Redmine::SafeAttributes
include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy
has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy
has_many :memos, :dependent => :destroy, conditions: "parent_id IS NULL"
# has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy
has_many :memo_forums, :dependent => :destroy
has_many :memos, :through => :memo_forums
belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id'
safe_attributes 'name',
'description',

View File

@ -7,7 +7,7 @@ class Grade < ActiveRecord::Base
belongs_to :user
has_many :tidings, :as => :container, :dependent => :destroy
after_create :send_tiding
# after_create :send_tiding
def send_tiding
self.tidings << Tiding.new(:user_id => self.user_id, :trigger_user_id => 0, :parent_container_id => self.container_id, :parent_container_type => self.container_type, :viewed => 0, :tiding_type => "System")
end

View File

@ -17,9 +17,9 @@
class Group < Principal
include Redmine::SafeAttributes
has_and_belongs_to_many :users, :after_add => :user_added,
:after_remove => :user_removed
#
# has_and_belongs_to_many :users, :after_add => :user_added,
# :after_remove => :user_removed
acts_as_customizable

View File

@ -141,7 +141,6 @@ class Issue < ActiveRecord::Base
#动态的更新
def update_activity
update_user_activity(self.class, self.id)
update_forge_activity(self.class, self.id)
end
@ -166,27 +165,7 @@ class Issue < ActiveRecord::Base
unless self.author_id == self.assigned_to_id
self.forge_messages << ForgeMessage.new(:user_id => self.assigned_to_id, :project_id => self.project_id, :viewed => false)
end
# self.project.members.each do |m|
# count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count
# if m.user_id != self.author_id && count == 0
# ws = WechatService.new
# str = " 有新缺陷了: "
# case self.tracker_id
# when 1
# str = " 有新缺陷了: "
# when 2
# str = " 有新功能了: "
# when 3
# str = " 有新支持了: "
# when 4
# str = " 有新任务了: "
# when 5
# str = " 有新周报了: "
# end
# content = strip_html self.project.name + str + self.subject.html_safe, 200
# ws.message_update_template m.user_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on)
# end
# end
if self.tracker_id == 5
self.project.members.each do |m|
if m.roles.first.to_s.include?("Manager") && m.user_id != self.author_id && m.user_id != self.assigned_to_id
@ -1492,8 +1471,10 @@ class Issue < ActiveRecord::Base
@current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => obj.id, :old_value => obj.filename)
@current_journal.save
user_activity = UserActivity.where("act_type='Issue' and act_id =#{@current_journal.journalized_id}").first
user_activity.updated_at = Time.now
user_activity.save
if user_activity
user_activity.updated_at = Time.now
user_activity.save
end
end
end
@ -1601,8 +1582,10 @@ class Issue < ActiveRecord::Base
end
@current_journal.save
user_activity = UserActivity.where("act_type='Issue' and act_id =#{@current_journal.journalized_id}").first
user_activity.updated_at = Time.now
user_activity.save
if user_activity
user_activity.updated_at = Time.now
user_activity.save
end
# reset current journal
init_journal @current_journal.user, @current_journal.notes
end

View File

@ -62,7 +62,7 @@ class Journal < ActiveRecord::Base
# end
#after_destroy :down_user_score
#before_save :be_user_score
after_destroy :down_user_score, :decrease_issues_journal_count
after_destroy :down_user_score
scope :visible, lambda {|*args|
user = args.shift || User.current
@ -244,15 +244,6 @@ class Journal < ActiveRecord::Base
end
# 减少留言数量统计
def decrease_issues_journal_count
unless self.issue.project.nil?
journal_count = self.issue.project.project_score.issue_journal_num - 1
# project = self.issue.project
self.issue.project.project_score.update_attribute(:issue_journal_num, journal_count < 0 ? 0 : journal_count)
end
end
# issue留言总数更新
def add_journals_count
if self.journalized_type == 'Issue'

View File

@ -87,9 +87,7 @@ class JournalsForMessage < ActiveRecord::Base
#动态的更新
def update_activity
update_user_activity(self.class, self.id)
update_forge_activity(self.class, self.id)
update_principal_activity(self.class, self.id)
end
def self.create_by_user? user
if user.anonymous?

View File

@ -8,11 +8,13 @@ class Memo < ActiveRecord::Base
include UserScoreHelper
include ApplicationHelper
include Elasticsearch::Model
belongs_to :forum
has_many :forums, :through => :memo_forums
has_many :memo_forums, :dependent => :destroy
has_many_kindeditor_assets :assets, :dependent => :destroy
has_many :tidings, :as => :container , :dependent => :destroy
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
validates_presence_of :author_id, :forum_id, :subject,:content
validates_presence_of :author_id, :subject,:content
# 若是主题帖,则内容可以是空
#validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? }
validates_length_of :subject, maximum: 50
@ -63,13 +65,13 @@ class Memo < ActiveRecord::Base
# #:include => { :forum => :p}
# #:project_key => "#{Forum.table_name}.project_id"
# :date_column => "#{table_name}.created_at"
acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"},
:datetime => :updated_at,
#acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"},
#:datetime => :updated_at,
# :datetime => :created_at,
:description => :content,
:author => :author,
:type => Proc.new {|o| o.parent_id.nil? ? 'Memo' : 'Reply'},
:url => Proc.new {|o| {:controller => 'memos', :action => 'show', :forum_id => o.forum_id}.merge(o.parent_id.nil? ? {:id => o.id} : {:id => o.parent_id, :r => o.id, :anchor => "reply-#{o.id}"})}
#:description => :content,
#:author => :author,
#:type => Proc.new {|o| o.parent_id.nil? ? 'Memo' : 'Reply'},
#:url => Proc.new {|o| {:controller => 'memos', :action => 'show', :forum_id => o.forum_id}.merge(o.parent_id.nil? ? {:id => o.id} : {:id => o.parent_id, :r => o.id, :anchor => "reply-#{o.id}"})}
acts_as_activity_provider :author_key => :author_id,
:func => 'memos',
:timestamp => 'created_at'
@ -79,7 +81,6 @@ class Memo < ActiveRecord::Base
safe_attributes "author_id",
"subject",
"content",
"forum_id",
"last_memo_id",
"lock",
"sticky",
@ -90,7 +91,7 @@ class Memo < ActiveRecord::Base
# after_create :add_author_as_watcher, :reset_counters!, :send_tiding
after_update
after_destroy :reset_counters!,:delete_kindeditor_assets #,:down_user_score -- 公共区发帖暂不计入得分,
# after_destroy :reset_counters!,:delete_kindeditor_assets #,:down_user_score -- 公共区发帖暂不计入得分,
# after_create :send_notification
# after_save :plusParentAndForum
# after_destroy :minusParentAndForum
@ -103,9 +104,9 @@ class Memo < ActiveRecord::Base
}
scope :visible, lambda{where(hidden: 0)}
scope :field_for_list, lambda{
select([:id, :subject, :author_id, :sticky, :updated_at, :language, :reward, :replies_count, :viewed_count, :forum_id])
select([:id, :subject, :author_id, :sticky, :published_at, :language, :reward, :replies_count, :viewed_count])
}
scope :field_for_recommend, lambda{select([:id, :subject, :language, :forum_id])}
scope :field_for_recommend, lambda{select([:id, :subject])}
scope :user_posts, ->(user_id){where(root_id: nil, author_id: user_id)}
scope :memo_replies, ->(id){where(:root_id => id)}

5
app/models/memo_forum.rb Normal file
View File

@ -0,0 +1,5 @@
class MemoForum < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :memo
belongs_to :forum
end

View File

@ -188,7 +188,6 @@ class Message < ActiveRecord::Base
end
#动态的更新
def update_activity
update_user_activity(self.class, self.id)
update_forge_activity(self.class, self.id)
end

View File

@ -67,7 +67,6 @@ class News < ActiveRecord::Base
#动态的更新
def update_activity
update_user_activity(self.class, self.id)
update_forge_activity(self.class, self.id)
end

View File

@ -43,21 +43,18 @@ class Project < ActiveRecord::Base
end
end
has_many :student_work_projects, :dependent => :destroy
has_many :contestant_work_projects, :dependent => :destroy
has_many :student_works
has_many :time_entry_activities
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'Member'
has_many :member_principals, :class_name => 'Member',
:include => :principal,
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
belongs_to :owner, :class_name => 'User', :foreign_key => :user_id, :dependent => :destroy # 定义一个方法teacher该方法通过tea_id来调用User表
belongs_to :owner, :class_name => 'User', :foreign_key => :user_id
has_many :users, :through => :members
has_many :principals, :through => :member_principals, :source => :principal
has_many :enabled_modules, :dependent => :delete_all
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
has_many :issues, :dependent => :destroy, :include => [:status, :tracker],:order => "issues.id ASC"
has_many :issues, :include => [:status, :tracker],:order => "issues.id ASC"
has_many :training_tasks, :dependent => :destroy, :order => "training_tasks.id ASC"
has_many :issue_changes, :through => :issues, :source => :journals
has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
@ -80,15 +77,13 @@ class Project < ActiveRecord::Base
has_many :shares, :dependent => :destroy
has_many :applied_projects, :dependent => :destroy
has_many :invite_lists, :dependent => :destroy
# has_one :dts
has_many :organizations,:through => :org_projects
# end
#ADDED BY NIE
has_one :project_score, :dependent => :destroy
has_many :project_infos, :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_many :user_grades, :class_name => "UserGrade", :dependent => :destroy
has_many :user_grades, :class_name => "UserGrade"
#end
has_one :wiki, :dependent => :destroy
@ -106,13 +101,11 @@ class Project < ActiveRecord::Base
has_many :tags, :through => :project_tags, :class_name => 'Tag'
has_many :project_tags, :class_name => 'ProjectTags'
# 动态级联删除
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act
#has_many :forge_activities, :class_name => 'ForgeActivity', :as =>:forge_act, :dependent => :destroy
# 关联虚拟表
has_many :forge_messages, :class_name =>'ForgeMessage', :as => :forge_message, :dependent => :destroy
has_many :forge_messages, :class_name =>'ForgeMessage', :as => :forge_message
has_many :org_projects,:dependent => :destroy
has_many :organization,:through => :org_projects
has_many :rep_statics, :class_name => 'RepStatics'
# has_many :journals
@ -231,6 +224,14 @@ class Project < ActiveRecord::Base
(!self.enabled_modules.where("name = 'training_tasks'").empty? && self.training_status == 1) ? true : false
end
def subject
self.name
end
def created_at
self.created_on
end
# 判断项目是否为开启实训的项目eg学生开启实训
def is_child_training_project?
self.training_status == 2 ? true :false
@ -315,6 +316,19 @@ class Project < ActiveRecord::Base
end
end
def get_attachments_count
Attachment.where(:container_type => "Project", :container_id => self.id).count
end
def get_repository_count
rep = Repository.where(:project_id => self.id, :type => "Repository::Gitlab").first
rep ? project_score.changeset_num.to_i : 0
end
def get_pull_request_count
self.gpid.present? ? project_score.pull_request_num : 0
end
def identifier=(identifier)
super unless identifier_frozen?
end
@ -368,36 +382,37 @@ class Project < ActiveRecord::Base
base_statement = "(#{project_statement}) AND (#{base_statement})"
end
if user.admin?
base_statement
else
statement_by_role = {}
unless options[:member]
role = user.logged? ? Role.non_member : Role.anonymous
if role.allowed_to?(permission)
statement_by_role[role] = "#{Project.table_name}.is_public = #{connection.quoted_true}"
end
end
if user.logged?
user.projects_by_role.each do |role, projects|
if role.allowed_to?(permission) && projects.any?
statement_by_role[role] = "#{Project.table_name}.id IN (#{projects.collect(&:id).join(',')})"
end
end
end
if statement_by_role.empty?
"1=0"
else
if block_given?
statement_by_role.each do |role, statement|
if s = yield(role, user)
statement_by_role[role] = "(#{statement} AND (#{s}))"
end
end
end
"((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))"
end
end
base_statement
# if user.admin?
# base_statement
# else
# statement_by_role = {}
# unless options[:member]
# role = user.logged? ? Role.non_member : Role.anonymous
# if role.allowed_to?(permission)
# statement_by_role[role] = "#{Project.table_name}.is_public = #{connection.quoted_true}"
# end
# end
# if user.logged?
# user.projects_by_role.each do |role, projects|
# if role.allowed_to?(permission) && projects.any?
# statement_by_role[role] = "#{Project.table_name}.id IN (#{projects.collect(&:id).join(',')})"
# end
# end
# end
# if statement_by_role.empty?
# "1=0"
# else
# if block_given?
# statement_by_role.each do |role, statement|
# if s = yield(role, user)
# statement_by_role[role] = "(#{statement} AND (#{s}))"
# end
# end
# end
# "((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))"
# end
# end
end
# Returns the Systemwide and project specific activities
@ -846,7 +861,9 @@ class Project < ActiveRecord::Base
'dts_test',
'attachmenttype',
'enterprise_name',
'gpid'
'gpid',
'image_url',
'image_status'

View File

@ -0,0 +1,3 @@
class PublicProperty < ActiveRecord::Base
attr_accessible :property, :value
end

View File

@ -36,17 +36,17 @@ class Repository < ActiveRecord::Base
# has_many :changesets, :dependent => :destroy is too slow for big repositories
before_destroy :clear_changesets
validates_length_of :password, :maximum => 255, :allow_nil => true
validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true
validates_presence_of :identifier#, :unless => Proc.new { |r| r.is_default? || r.set_as_default? }
#validates_length_of :password, :maximum => 255, :allow_nil => true
#validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true
#validates_presence_of :identifier#, :unless => Proc.new { |r| r.is_default? || r.set_as_default? }
#validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true
# 改成同一用户不能有两个相同名字的版本库
# validates_uniqueness_of :identifier, :allow_blank => true
validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph)
#validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph)
# donwcase letters, digits, dashes, underscores but not digits only
validates_format_of :identifier, :with => /^[a-zA-Z0-9_\-]*[a-zA-Z_\-]+[a-zA-Z0-9_\-]*$/, :allow_blank => true
#validates_format_of :identifier, :with => /^[a-zA-Z0-9_\-]*[a-zA-Z_\-]+[a-zA-Z0-9_\-]*$/, :allow_blank => true
# Checks if the SCM is enabled when creating a repository
validate :repo_create_validation, :on => :create
#validate :repo_create_validation, :on => :create
safe_attributes 'identifier',
'login',
@ -107,7 +107,7 @@ class Repository < ActiveRecord::Base
def scm
unless @scm
@scm = self.scm_adapter.new(url, root_url, login, password, path_encoding, project_id, shixun_id, myshixun_id)
@scm = self.scm_adapter.new(url, root_url, login, password, path_encoding, project_id)
if root_url.blank? && @scm.root_url.present?
update_attribute(:root_url, @scm.root_url)
end

View File

@ -925,7 +925,7 @@ class User < Principal
end
def manager_of_memo?(memo)
(User.current.id == memo.author_id || User.current.admin?) ? true : false
((self.id == memo.author_id || self.admin?) && self.logged?) ? true : false
end
def manager_of_project?(project_id)
@ -1051,9 +1051,7 @@ class User < Principal
# authorize if user has at least one role that has this permission
roles = memberships.collect {|m| m.roles}.flatten.uniq
if roles.count == 0
roles = coursememberships.collect {|m| m.roles}.flatten.uniq
end
roles << (self.logged? ? Role.non_member : Role.anonymous)
roles.any? {|role|
role.allowed_to?(action) &&

View File

@ -26,15 +26,20 @@ class MemosService
# attachments 附件
# attachment_id 是帖子的头像
def create params, current_user
return nil if params[:memo][:subject].blank? || params[:memo][:content].blank? || params[:memo][:forum_id].blank?
Rails.logger.info("################{params}")
return nil if params[:memo][:subject].blank? || params[:memo][:content].blank? || params[:forum_id].blank?
memo = Memo.new(params[:memo])
memo.author = current_user
memo.save_attachments(params[:attachments]) if params[:attachments].present?
memo.published_at = Time.now if params[:memo][:published_at].blank?
memo.save!
params[:forum_id].each do |forum_id|
MemoForum.create(:memo_id => memo.id, :forum_id => forum_id)
end
# 为了区分帖子头像改变其类型为MemoIcon
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_column(:container_type, "MemoIcon")
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 0, message: "帖子创建成功!", memo_id: memo.id}
end
@ -50,25 +55,32 @@ class MemosService
def show params, current_user
memo = Memo.find params[:id]
# 消息总数
tidding_count = unviewed_tiddings(current_user)
attachments_list = acttachements_info memo.attachments
tidding_count = current_user ? unviewed_tiddings(current_user) : 0
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id,
:filename => memo_image.filename,
:url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => memo_image.filesize} if memo_image
memo_praise_count = memo.praise_tread.liker.count
user_praise = PraiseTread.where(:praise_tread_object_id => memo.id, :praise_tread_object_type => "Memo",
:user_id => current_user.id, :praise_or_tread => 1).present? ? true : false
:user_id => current_user.try(:id), :praise_or_tread => 1).present? ? true : false
unless memo.children.blank?
memo.children.each do |child|
child.memo_messages.each do |memo_message|
memo_message.update_attributes(:viewed => true) if current_user.id == memo_message.user_id
if current_user
unless memo.children.blank?
memo.children.each do |child|
child.memo_messages.each do |memo_message|
memo_message.update_attributes(:viewed => true) if current_user.id == memo_message.user_id
end
end
end
end
query_memo_messages = memo.memo_messages
unless query_memo_messages
query_memo_messages.each do |query_memo_message|
query_memo_message.update_attributes(:viewed => true) if current_user.id == query_memo_message.user_id
query_memo_messages = memo.memo_messages
unless query_memo_messages
query_memo_messages.each do |query_memo_message|
query_memo_message.update_attributes(:viewed => true) if current_user.id == query_memo_message.user_id
end
end
end
memo.update_column(:viewed_count, memo.viewed_count + 1)
@ -90,13 +102,18 @@ class MemosService
label_id = memo.language.split(";")
tag = Label.where(:id => label_id).pluck(:name)
end
if memo.forums.present?
forum_name = memo.forums.map(&:name)
end
memo = {id: memo.id,
subject: memo.subject,
is_md: is_md,
content: memo.content,
time: memo.created_at,
time: memo.published_at,
tag: tag, # 标签
forum_name: forum_name, #类型
sticky: memo.sticky, # 置顶 1
viewed_count: memo.viewed_count,
replies_count: replies_count,
@ -106,7 +123,7 @@ class MemosService
user_praise: user_praise}
current_user_info = format_for_current_user current_user
# recommend_shixuns: recommends,
{ memo: memo, memo_replies: list, author_info: author_info,
{ memo: memo, memo_replies: list, author_info: author_info, memo_image_info: memo_image_info,
current_user: current_user_info, tidding_count: tidding_count}
end
@ -138,10 +155,22 @@ class MemosService
def edit params, current_user
memo_type = object_to_hash Forum.select([:id, :name])
memo_tag = object_to_hash Label.select([:id, :name])
memo = Memo.select([:id, :subject, :content, :forum_id, :language]).find params[:id]
attachments_list = acttachements_info memo.attachments
memo = Memo.select([:id, :subject, :content, :published_at]).find params[:id]
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id,
:filename => memo_image.filename,
:url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => memo_image.filesize} if memo_image
current_user_info = format_for_current_user current_user
memo.attributes.merge({memo_type: memo_type, memo_tag: memo_tag, current_user: current_user_info, attachments_url: attachments_list})
# forum_id转成字符串数组是因为前端控件处理方便
forum_id = memo.memo_forums.pluck(:forum_id).map(&:to_s)
memo.attributes.merge({memo_type: memo_type,
memo_tag: memo_tag,
current_user: current_user_info,
attachments_url: attachments_list,
memo_image_info: memo_image_info,
forum_id: forum_id})
end
def update params
@ -154,6 +183,16 @@ class MemosService
memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
end
memo.save!
memo.memo_forums.delete_all
params[:forum_id].each do |forum_id|
MemoForum.create(:memo_id => memo.id, :forum_id => forum_id)
end
# 为了区分帖子头像改变其类型为MemoIcon
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 0, message: "帖子更新成功!"}
end
@ -172,26 +211,29 @@ class MemosService
# hot_tags 热门标签
# my_memos_count 我的帖子数
def get_memos_list params, current_user
s_order = params[:order] || "updated_at"
s_order = params[:order] || "published_at"
tidding_count = unviewed_tiddings(current_user) if current_user.present?
page = params[:page].to_i
offset = page * 15
search = params[:search]
forum_id = params[:forum]
sql =
if forum_id
search ? "forum_id = #{forum_id} and root_id is null and subject like '%#{search}%'"
: "forum_id = #{forum_id} and root_id is null"
memo_ids = MemoForum.where(:forum_id => forum_id).pluck(:memo_id)
memo_ids = memo_ids.present? ? memo_ids.join(",") : -1
search ? "id in(#{memo_ids}) and root_id is null and subject like '%#{search}%'"
: "id in(#{memo_ids}) and root_id is null"
elsif search
"root_id is null and subject like '%#{search}%'"
else
"root_id is null"
end
memos = Memo.field_for_list.includes(:praise_tread, :author).where("#{sql}")
memos_count = memos.count # 帖子的总数
memos = memos.order("sticky=1 desc, #{Memo.table_name}.#{s_order} desc").offset(offset).limit(15)
memo_list = memo_data memos
my_memos_count = Memo.user_posts(current_user.id).count
my_memos_count = current_user ? Memo.user_posts(current_user.id).count : 0
# 标签只有forum_id = 5才有
hot_tags = object_to_hash Forum.select([:id, :name])
hot_memos = Memo.field_for_recommend.posts.hot.limit(4)
@ -203,8 +245,8 @@ class MemosService
end
current_user_info = format_for_current_user current_user
{memo_list: memo_list, memo_count: memos_count, hot_memos: hot_memos,
hot_tags: hot_tags, my_memos_count: my_memos_count,
current_user: current_user_info, tidding_count: tidding_count}
hot_tags: hot_tags, my_memos_count: my_memos_count, current_user: current_user_info,
tidding_count: tidding_count}
end
# params
@ -215,7 +257,6 @@ class MemosService
reply = Memo.new
reply.content = params[:content]
reply.author = current_user
reply.forum_id = memo.forum_id
reply.subject = memo.subject
reply.root_id = memo.root_id || memo.id
memo.children << reply
@ -224,15 +265,12 @@ class MemosService
# params:
# order 排序
# forum_id: 3.技术分享; 5操作指南
# sticky: 1 置顶,0 取消置顶
# id 帖子ID
def set_top_or_down params
s_order = params[:order] || "updated_at"
forum_id = params[:forum_id]
sql = forum_id ? "forum_id = #{forum_id} and root_id is null" : "root_id is null"
Memo.find(params[:id]).update_attribute(:sticky, params[:sticky])
memos = Memo.field_for_list.includes(:praise_tread, :author).where("#{sql}").order("sticky=1 desc, #{s_order} desc").limit(15)
memos = Memo.field_for_list.includes(:praise_tread, :author).where(:root_id => nil).order("sticky=1 desc, #{s_order} desc").limit(15)
memo_list = memo_data memos
{status: 0, message: "操作成功!", memo_list: memo_list}
end
@ -270,8 +308,9 @@ class MemosService
memo_list = []
memos.each do |m|
praise_count = m.praise_tread.where(:praise_or_tread => 1).count
forum_name = Forum.find(m.forum_id).name
user_info = {username: m.author.show_name, login: m.author.login, image_url: url_to_avatar(m.author), praise_count: praise_count, forum_name:forum_name}
replies_count = m.all_replies.count
forum_name = m.forums.map(&:name)
user_info = {username: m.author.show_name, login: m.author.login, image_url: url_to_avatar(m.author), praise_count: praise_count, forum_name:forum_name, replies_count: replies_count}
memo_list << m.attributes.dup.merge(user_info)
end
memo_list
@ -305,11 +344,12 @@ class MemosService
# 总赞数
praise_count = memo.praise_tread.liker.count
# 用户是否点赞
user_praise = memo.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false
user_praise = memo.praise_tread.select{|pt| pt.user_id == current_user.try(:id)}.length > 0 ? true : false
permission = current_user ? current_user.manager_of_memo?(memo) : false
# 实训TPM的管理员可以看到隐藏的评论
replies = {:id => memo.id, :content => memo.content, :time => time_from_now(memo.created_at), :user_id => memo.author_id,
:image_url => url_to_avatar(memo.author), :username => memo.author.show_name, :reward => memo.reward, :hidden => memo.hidden,
:permission => current_user.manager_of_memo?(memo), :praise_count => praise_count, :user_praise => user_praise,
:permission => permission, :praise_count => praise_count, :user_praise => user_praise,
:user_login => memo.author.try(:login), :admin => current_user.admin}
# 现在没有二级回复所以查询的时候直接从root_id取
childrens = Memo.where(:parent_id => memo.id).includes(:author).reorder("created_at asc")
@ -317,7 +357,7 @@ class MemosService
childrens.each do |child|
children_list << {:id => child.id, :content => child.content, :time => time_from_now(child.created_at),
:image_url => url_to_avatar(child.author), :username => child.author.show_name, :hidden => child.hidden,
:permission => current_user.manager_of_memo?(memo), :user_login => child.author.try(:login), :user_id => child.author.try(:id)}
:permission => permission, :user_login => child.author.try(:login), :user_id => child.author.try(:id)}
end
list << replies.merge({children: children_list})
end
@ -343,5 +383,4 @@ class MemosService
# str.include?("<p>" || "<div>" || "<span>" || "<img>" || "<strong>") && update_time < "2018-06-23"
update_time < "2018-06-23"
end
end

View File

@ -0,0 +1,406 @@
# encoding=utf-8
class MemosService
include ApplicationHelper
LIMIT = 10
def new current_user, session
csrf_token = session[:_csrf_token] ||= SecureRandom.base64(32)
tidding_count = unviewed_tiddings(current_user)
#reps = Repertoire.field_for_list.order("updated_at asc")
#tag_list = tag_list reps
current_user_info = format_for_current_user current_user
memo_type = object_to_hash Forum.select([:id, :name])
memo_tag = object_to_hash Label.select([:id, :name])
# csrf_token = SecureRandom.base64(32)
{current_user: current_user_info, memo_type: memo_type, memo_tag: memo_tag,
:csrf_token => csrf_token, :tidding_count => tidding_count}
end
# params 直接传params[:memo][:subject]
# subject标题
# content内容
# forum_id 话题类型
# sticky 是否置顶(创建时没入口)
# repertoire_name + language 技术标签
# attachments 附件
# attachment_id 是帖子的头像
def create params, current_user
Rails.logger.info("################{params}")
return nil if params[:memo][:subject].blank? || params[:memo][:content].blank? || params[:forum_id].blank?
memo = Memo.new(params[:memo])
memo.author = current_user
memo.save_attachments(params[:attachments]) if params[:attachments].present?
memo.published_at = Time.now if params[:memo][:published_at].blank?
memo.save!
params[:forum_id].each do |forum_id|
MemoForum.create(:memo_id => memo.id, :forum_id => forum_id)
end
# 为了区分帖子头像改变其类型为MemoIcon
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 0, message: "帖子创建成功!", memo_id: memo.id}
end
# params
# :id 帖子id
# return
# :memo 帖子
# :memo_replies 帖子的回复
# :recommend_shixun 推荐实训
# :admin 当前用户是否是管理员
# :author_info 表示当前帖子用户的信息
def show params, current_user
memo = Memo.find params[:id]
# 消息总数
<<<<<<< Temporary merge branch 1
tidding_count = unviewed_tiddings(current_user)
=======
tidding_count = current_user ? unviewed_tiddings(current_user) : 0
>>>>>>> Temporary merge branch 2
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id,
:filename => memo_image.filename,
:url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => memo_image.filesize} if memo_image
memo_praise_count = memo.praise_tread.liker.count
user_praise = PraiseTread.where(:praise_tread_object_id => memo.id, :praise_tread_object_type => "Memo",
:user_id => current_user.try(:id), :praise_or_tread => 1).present? ? true : false
if current_user
unless memo.children.blank?
memo.children.each do |child|
child.memo_messages.each do |memo_message|
memo_message.update_attributes(:viewed => true) if current_user.id == memo_message.user_id
end
end
end
query_memo_messages = memo.memo_messages
unless query_memo_messages
query_memo_messages.each do |query_memo_message|
query_memo_message.update_attributes(:viewed => true) if current_user.id == query_memo_message.user_id
end
end
end
memo.update_column(:viewed_count, memo.viewed_count + 1)
replies_count = memo.all_replies.count
# 帖子的回复
memos = memo.reply_for_memo.includes(:praise_tread, :author).order("created_at desc").limit(LIMIT)
watched = memo.author.watched_by?(current_user)
list = memo_list memos, current_user
is_md = memo.is_md
author_info = {username: memo.author.show_name,
watched: watched,
image_url: url_to_avatar(memo.author),
identity: memo.author.identity,
login: memo.author.login,
user_id: memo.author.id}
if memo.language.present?
label_id = memo.language.split(";")
tag = Label.where(:id => label_id).pluck(:name)
end
<<<<<<< Temporary merge branch 1
if memo.forum_id.present?
forum_name = Forum.find(memo.forum_id).name
=======
if memo.forums.present?
forum_name = memo.forums.map(&:name)
>>>>>>> Temporary merge branch 2
end
memo = {id: memo.id,
subject: memo.subject,
is_md: is_md,
content: memo.content,
time: memo.published_at,
tag: tag, # 标签
forum_name: forum_name, #类型
sticky: memo.sticky, # 置顶 1
viewed_count: memo.viewed_count,
replies_count: replies_count,
praise_count: memo_praise_count,
reward: memo.reward,
attachment_url: attachments_list,
user_praise: user_praise}
current_user_info = format_for_current_user current_user
# recommend_shixuns: recommends,
{ memo: memo, memo_replies: list, author_info: author_info, memo_image_info: memo_image_info,
current_user: current_user_info, tidding_count: tidding_count}
end
def more_reply params, current_user
page = params[:page].to_i
offset = page * LIMIT
memo_id = params[:id]
# 总数,分页使用
memos_count = Memo.where(:parent_id => memo_id).count
memos = Memo.limit(LIMIT).where(:parent_id => memo_id).includes(:author, :praise_tread).offset(offset)
list = memo_list memos, current_user
return {:memo_replies => list, :memos_count => memos_count}
end
# 隐藏评论功能
def hidden params, current_user
memo = Memo.select([:id, :hidden]).find(params[:id])
if current_user.admin?
if params[:hidden] == "1"
memo.update_attribute(:hidden, true)
elsif params[:hidden] == "0"
memo.update_column("hidden", false)
end
else
raise("你没有权限")
end
end
def edit params, current_user
memo_type = object_to_hash Forum.select([:id, :name])
memo_tag = object_to_hash Label.select([:id, :name])
<<<<<<< Temporary merge branch 1
memo = Memo.select([:id, :subject, :content, :forum_id, :language]).find params[:id]
=======
memo = Memo.select([:id, :subject, :content, :published_at]).find params[:id]
>>>>>>> Temporary merge branch 2
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id,
:filename => memo_image.filename,
:url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => memo_image.filesize} if memo_image
current_user_info = format_for_current_user current_user
<<<<<<< Temporary merge branch 1
memo.attributes.merge({memo_type: memo_type, memo_tag: memo_tag, current_user: current_user_info, attachments_url: attachments_list, memo_image_info: memo_image_info})
=======
# forum_id转成字符串数组是因为前端控件处理方便
forum_id = memo.memo_forums.pluck(:forum_id).map(&:to_s)
memo.attributes.merge({memo_type: memo_type,
memo_tag: memo_tag,
current_user: current_user_info,
attachments_url: attachments_list,
memo_image_info: memo_image_info,
forum_id: forum_id})
>>>>>>> Temporary merge branch 2
end
def update params
memo = Memo.find params[:id]
if(memo.update_attributes(params[:memo]))
# 为了将旧数据的KE转换为MD
if !memo.is_md && params[:content_changed]
memo.update_column(:is_md, true)
end
memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
end
memo.save!
<<<<<<< Temporary merge branch 1
=======
memo.memo_forums.delete_all
params[:forum_id].each do |forum_id|
MemoForum.create(:memo_id => memo.id, :forum_id => forum_id)
end
>>>>>>> Temporary merge branch 2
# 为了区分帖子头像改变其类型为MemoIcon
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 0, message: "帖子更新成功!"}
end
# params
# 排序:order -> 类型字符串replies_count最热 created_at 最新
# 搜索:search -> 类型:字符串;
# 类型:forum -> 类型:整型; 值3 操作指南 5 技术分享
# 用户:user_id -> 搜索那个用户的帖子(目前主要用来显示我的帖子)。
# 标签:language -> 经过base64编码后的热门标签带特殊字符
# return:
# memo_list 列表
# memo_count 帖子的总数
# current_user 用户信息
# hot_memos 热门帖子
# recommend_shixuns 推荐实训
# hot_tags 热门标签
# my_memos_count 我的帖子数
def get_memos_list params, current_user
s_order = params[:order] || "published_at"
tidding_count = unviewed_tiddings(current_user) if current_user.present?
page = params[:page].to_i
offset = page * 15
search = params[:search]
forum_id = params[:forum]
sql =
if forum_id
memo_ids = MemoForum.where(:forum_id => forum_id).pluck(:memo_id)
memo_ids = memo_ids.present? ? memo_ids.join(",") : -1
search ? "id in(#{memo_ids}) and root_id is null and subject like '%#{search}%'"
: "id in(#{memo_ids}) and root_id is null"
elsif search
"root_id is null and subject like '%#{search}%'"
else
"root_id is null"
end
memos = Memo.field_for_list.includes(:praise_tread, :author).where("#{sql}")
memos_count = memos.count # 帖子的总数
memos = memos.order("sticky=1 desc, #{Memo.table_name}.#{s_order} desc").offset(offset).limit(15)
memo_list = memo_data memos
my_memos_count = current_user ? Memo.user_posts(current_user.id).count : 0
# 标签只有forum_id = 5才有
hot_tags = object_to_hash Forum.select([:id, :name])
hot_memos = Memo.field_for_recommend.posts.hot.limit(4)
# 将热门问题添加 回复数
hot_memos =
hot_memos.map do |hm|
replies_count = Memo.where(:root_id => hm.id).count
hm.attributes.dup.merge({replies_count: replies_count})
end
current_user_info = format_for_current_user current_user
{memo_list: memo_list, memo_count: memos_count, hot_memos: hot_memos,
hot_tags: hot_tags, my_memos_count: my_memos_count,
current_user: current_user_info, tidding_count: tidding_count}
end
# params
# parent_id: 给谁的回复id
# content: 回复的内容
def reply params, current_user
memo = Memo.find params[:parent_id]
reply = Memo.new
reply.content = params[:content]
reply.author = current_user
reply.subject = memo.subject
reply.root_id = memo.root_id || memo.id
memo.children << reply
reply
end
# params:
# order 排序
# sticky: 1 置顶,0 取消置顶
# id 帖子ID
def set_top_or_down params
s_order = params[:order] || "updated_at"
Memo.find(params[:id]).update_attribute(:sticky, params[:sticky])
memos = Memo.field_for_list.includes(:praise_tread, :author).where(:root_id => nil).order("sticky=1 desc, #{s_order} desc").limit(15)
memo_list = memo_data memos
{status: 0, message: "操作成功!", memo_list: memo_list}
end
protected
def unviewed_tiddings current_user
new_tidings_count = current_user.tidings.where("created_at > '#{current_user.onclick_time.onclick_time}'").count
new_pri_message_count = current_user.private_messages.where("created_at > '#{current_user.onclick_time.onclick_time}'").count
count = new_tidings_count + new_pri_message_count
return count
end
def find_memo params
if params[:id].blank?
@memo = Memo.new
else
@memo = Memo.find params[:id]
end
end
def format_for_current_user current_user
{username: current_user.show_name, login: current_user.login,
user_id: current_user.id, image_url: url_to_avatar(current_user),
admin: current_user.admin?, is_teacher: current_user.user_extensions.try(:identity) == 0 }
end
# 将数据库对象转换成哈希对象
def object_to_hash objects
objects.map{|o| o.attributes.dup}
end
# 将memos对象添加额外信息
def memo_data memos
memo_list = []
memos.each do |m|
praise_count = m.praise_tread.where(:praise_or_tread => 1).count
replies_count = m.all_replies.count
forum_name = m.forums.map(&:name)
user_info = {username: m.author.show_name, login: m.author.login, image_url: url_to_avatar(m.author), praise_count: praise_count, forum_name:forum_name, replies_count: replies_count}
memo_list << m.attributes.dup.merge(user_info)
end
memo_list
end
# 权限
def permission memo, current_user
if current_user.admin?
1
elsif memo.author_id == current_user.id
2
else
3
end
end
def tag_list reps
rep_list = []
reps.each do |r|
sub_ids = SubRepertoire.where(:repertoire_id => r.id).pluck(:id)
tag = object_to_hash TagRepertoire.where(:sub_repertoire_id => sub_ids).field_for_list.order("name asc")
rep_list << {:rep => r, :tag => tag}
end
return rep_list
end
def memo_list memos, current_user
return nil if memos.blank?
list = [] # 贴子的回复
memos.each do |memo|
# 总赞数
praise_count = memo.praise_tread.liker.count
# 用户是否点赞
user_praise = memo.praise_tread.select{|pt| pt.user_id == current_user.try(:id)}.length > 0 ? true : false
permission = current_user ? current_user.manager_of_memo?(memo) : false
# 实训TPM的管理员可以看到隐藏的评论
replies = {:id => memo.id, :content => memo.content, :time => time_from_now(memo.created_at), :user_id => memo.author_id,
:image_url => url_to_avatar(memo.author), :username => memo.author.show_name, :reward => memo.reward, :hidden => memo.hidden,
:permission => permission, :praise_count => praise_count, :user_praise => user_praise,
:user_login => memo.author.try(:login), :admin => current_user.admin}
# 现在没有二级回复所以查询的时候直接从root_id取
childrens = Memo.where(:parent_id => memo.id).includes(:author).reorder("created_at asc")
children_list = [] # 子回复
childrens.each do |child|
children_list << {:id => child.id, :content => child.content, :time => time_from_now(child.created_at),
:image_url => url_to_avatar(child.author), :username => child.author.show_name, :hidden => child.hidden,
:permission => permission, :user_login => child.author.try(:login), :user_id => child.author.try(:id)}
end
list << replies.merge({children: children_list})
end
list
end
# 帖子附件信息
def acttachements_info attachments
attachments_list = []
if attachments.present?
attachments.each do |attach|
attachments_list << {:id => attach.id,
:filename => attach.filename,
:url => "/attachments/download/" + "#{attach.id}" + "/" + "#{attach.filename}",
:filesize => attach.filesize}
end
end
return attachments_list
end
# 判断编辑器存储的内容是否是html类型的ke目的为了区分ke和markdown
def editor_html update_time
# str.include?("<p>" || "<div>" || "<span>" || "<img>" || "<strong>") && update_time < "2018-06-23"
update_time < "2018-06-23"
end
end

View File

@ -0,0 +1,386 @@
# encoding=utf-8
class MemosService
include ApplicationHelper
LIMIT = 10
def new current_user, session
csrf_token = session[:_csrf_token] ||= SecureRandom.base64(32)
tidding_count = unviewed_tiddings(current_user)
#reps = Repertoire.field_for_list.order("updated_at asc")
#tag_list = tag_list reps
current_user_info = format_for_current_user current_user
memo_type = object_to_hash Forum.select([:id, :name])
memo_tag = object_to_hash Label.select([:id, :name])
# csrf_token = SecureRandom.base64(32)
{current_user: current_user_info, memo_type: memo_type, memo_tag: memo_tag,
:csrf_token => csrf_token, :tidding_count => tidding_count}
end
# params 直接传params[:memo][:subject]
# subject标题
# content内容
# forum_id 话题类型
# sticky 是否置顶(创建时没入口)
# repertoire_name + language 技术标签
# attachments 附件
# attachment_id 是帖子的头像
def create params, current_user
Rails.logger.info("################{params}")
return nil if params[:memo][:subject].blank? || params[:memo][:content].blank? || params[:forum_id].blank?
memo = Memo.new(params[:memo])
memo.author = current_user
memo.save_attachments(params[:attachments]) if params[:attachments].present?
memo.published_at = Time.now if params[:memo][:published_at].blank?
memo.save!
params[:forum_id].each do |forum_id|
MemoForum.create(:memo_id => memo.id, :forum_id => forum_id)
end
# 为了区分帖子头像改变其类型为MemoIcon
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 0, message: "帖子创建成功!", memo_id: memo.id}
end
# params
# :id 帖子id
# return
# :memo 帖子
# :memo_replies 帖子的回复
# :recommend_shixun 推荐实训
# :admin 当前用户是否是管理员
# :author_info 表示当前帖子用户的信息
def show params, current_user
memo = Memo.find params[:id]
# 消息总数
tidding_count = current_user ? unviewed_tiddings(current_user) : 0
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id,
:filename => memo_image.filename,
:url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => memo_image.filesize} if memo_image
memo_praise_count = memo.praise_tread.liker.count
user_praise = PraiseTread.where(:praise_tread_object_id => memo.id, :praise_tread_object_type => "Memo",
:user_id => current_user.try(:id), :praise_or_tread => 1).present? ? true : false
if current_user
unless memo.children.blank?
memo.children.each do |child|
child.memo_messages.each do |memo_message|
memo_message.update_attributes(:viewed => true) if current_user.id == memo_message.user_id
end
end
end
query_memo_messages = memo.memo_messages
unless query_memo_messages
query_memo_messages.each do |query_memo_message|
query_memo_message.update_attributes(:viewed => true) if current_user.id == query_memo_message.user_id
end
end
end
memo.update_column(:viewed_count, memo.viewed_count + 1)
replies_count = memo.all_replies.count
# 帖子的回复
memos = memo.reply_for_memo.includes(:praise_tread, :author).order("created_at desc").limit(LIMIT)
watched = memo.author.watched_by?(current_user)
list = memo_list memos, current_user
is_md = memo.is_md
author_info = {username: memo.author.show_name,
watched: watched,
image_url: url_to_avatar(memo.author),
identity: memo.author.identity,
login: memo.author.login,
user_id: memo.author.id}
if memo.language.present?
label_id = memo.language.split(";")
tag = Label.where(:id => label_id).pluck(:name)
end
if memo.forums.present?
forum_name = memo.forums.map(&:name)
end
memo = {id: memo.id,
subject: memo.subject,
is_md: is_md,
content: memo.content,
time: memo.published_at,
tag: tag, # 标签
forum_name: forum_name, #类型
sticky: memo.sticky, # 置顶 1
viewed_count: memo.viewed_count,
replies_count: replies_count,
praise_count: memo_praise_count,
reward: memo.reward,
attachment_url: attachments_list,
user_praise: user_praise}
current_user_info = format_for_current_user current_user
# recommend_shixuns: recommends,
{ memo: memo, memo_replies: list, author_info: author_info, memo_image_info: memo_image_info,
current_user: current_user_info, tidding_count: tidding_count}
end
def more_reply params, current_user
page = params[:page].to_i
offset = page * LIMIT
memo_id = params[:id]
# 总数,分页使用
memos_count = Memo.where(:parent_id => memo_id).count
memos = Memo.limit(LIMIT).where(:parent_id => memo_id).includes(:author, :praise_tread).offset(offset)
list = memo_list memos, current_user
return {:memo_replies => list, :memos_count => memos_count}
end
# 隐藏评论功能
def hidden params, current_user
memo = Memo.select([:id, :hidden]).find(params[:id])
if current_user.admin?
if params[:hidden] == "1"
memo.update_attribute(:hidden, true)
elsif params[:hidden] == "0"
memo.update_column("hidden", false)
end
else
raise("你没有权限")
end
end
def edit params, current_user
memo_type = object_to_hash Forum.select([:id, :name])
memo_tag = object_to_hash Label.select([:id, :name])
memo = Memo.select([:id, :subject, :content, :published_at]).find params[:id]
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id,
:filename => memo_image.filename,
:url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => memo_image.filesize} if memo_image
current_user_info = format_for_current_user current_user
# forum_id转成字符串数组是因为前端控件处理方便
forum_id = memo.memo_forums.pluck(:forum_id).map(&:to_s)
memo.attributes.merge({memo_type: memo_type,
memo_tag: memo_tag,
current_user: current_user_info,
attachments_url: attachments_list,
memo_image_info: memo_image_info,
forum_id: forum_id})
end
def update params
memo = Memo.find params[:id]
if(memo.update_attributes(params[:memo]))
# 为了将旧数据的KE转换为MD
if !memo.is_md && params[:content_changed]
memo.update_column(:is_md, true)
end
memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
end
memo.save!
memo.memo_forums.delete_all
params[:forum_id].each do |forum_id|
MemoForum.create(:memo_id => memo.id, :forum_id => forum_id)
end
# 为了区分帖子头像改变其类型为MemoIcon
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 0, message: "帖子更新成功!"}
end
# params
# 排序:order -> 类型字符串replies_count最热 created_at 最新
# 搜索:search -> 类型:字符串;
# 类型:forum -> 类型:整型; 值3 操作指南 5 技术分享
# 用户:user_id -> 搜索那个用户的帖子(目前主要用来显示我的帖子)。
# 标签:language -> 经过base64编码后的热门标签带特殊字符
# return:
# memo_list 列表
# memo_count 帖子的总数
# current_user 用户信息
# hot_memos 热门帖子
# recommend_shixuns 推荐实训
# hot_tags 热门标签
# my_memos_count 我的帖子数
def get_memos_list params, current_user
s_order = params[:order] || "published_at"
tidding_count = unviewed_tiddings(current_user) if current_user.present?
page = params[:page].to_i
offset = page * 15
search = params[:search]
forum_id = params[:forum]
sql =
if forum_id
memo_ids = MemoForum.where(:forum_id => forum_id).pluck(:memo_id)
memo_ids = memo_ids.present? ? memo_ids.join(",") : -1
search ? "id in(#{memo_ids}) and root_id is null and subject like '%#{search}%'"
: "id in(#{memo_ids}) and root_id is null"
elsif search
"root_id is null and subject like '%#{search}%'"
else
"root_id is null"
end
memos = Memo.field_for_list.includes(:praise_tread, :author).where("#{sql}")
memos_count = memos.count # 帖子的总数
memos = memos.order("sticky=1 desc, #{Memo.table_name}.#{s_order} desc").offset(offset).limit(15)
memo_list = memo_data memos
my_memos_count = current_user ? Memo.user_posts(current_user.id).count : 0
# 标签只有forum_id = 5才有
hot_tags = object_to_hash Forum.select([:id, :name])
hot_memos = Memo.field_for_recommend.posts.hot.limit(4)
# 将热门问题添加 回复数
hot_memos =
hot_memos.map do |hm|
replies_count = Memo.where(:root_id => hm.id).count
hm.attributes.dup.merge({replies_count: replies_count})
end
current_user_info = format_for_current_user current_user
{memo_list: memo_list, memo_count: memos_count, hot_memos: hot_memos,
hot_tags: hot_tags, my_memos_count: my_memos_count,
current_user: current_user_info, tidding_count: tidding_count}
end
# params
# parent_id: 给谁的回复id
# content: 回复的内容
def reply params, current_user
memo = Memo.find params[:parent_id]
reply = Memo.new
reply.content = params[:content]
reply.author = current_user
reply.subject = memo.subject
reply.root_id = memo.root_id || memo.id
memo.children << reply
reply
end
# params:
# order 排序
# sticky: 1 置顶,0 取消置顶
# id 帖子ID
def set_top_or_down params
s_order = params[:order] || "updated_at"
Memo.find(params[:id]).update_attribute(:sticky, params[:sticky])
memos = Memo.field_for_list.includes(:praise_tread, :author).where(:root_id => nil).order("sticky=1 desc, #{s_order} desc").limit(15)
memo_list = memo_data memos
{status: 0, message: "操作成功!", memo_list: memo_list}
end
protected
def unviewed_tiddings current_user
new_tidings_count = current_user.tidings.where("created_at > '#{current_user.onclick_time.onclick_time}'").count
new_pri_message_count = current_user.private_messages.where("created_at > '#{current_user.onclick_time.onclick_time}'").count
count = new_tidings_count + new_pri_message_count
return count
end
def find_memo params
if params[:id].blank?
@memo = Memo.new
else
@memo = Memo.find params[:id]
end
end
def format_for_current_user current_user
{username: current_user.show_name, login: current_user.login,
user_id: current_user.id, image_url: url_to_avatar(current_user),
admin: current_user.admin?, is_teacher: current_user.user_extensions.try(:identity) == 0 }
end
# 将数据库对象转换成哈希对象
def object_to_hash objects
objects.map{|o| o.attributes.dup}
end
# 将memos对象添加额外信息
def memo_data memos
memo_list = []
memos.each do |m|
praise_count = m.praise_tread.where(:praise_or_tread => 1).count
replies_count = m.all_replies.count
forum_name = m.forums.map(&:name)
user_info = {username: m.author.show_name, login: m.author.login, image_url: url_to_avatar(m.author), praise_count: praise_count, forum_name:forum_name, replies_count: replies_count}
memo_list << m.attributes.dup.merge(user_info)
end
memo_list
end
# 权限
def permission memo, current_user
if current_user.admin?
1
elsif memo.author_id == current_user.id
2
else
3
end
end
def tag_list reps
rep_list = []
reps.each do |r|
sub_ids = SubRepertoire.where(:repertoire_id => r.id).pluck(:id)
tag = object_to_hash TagRepertoire.where(:sub_repertoire_id => sub_ids).field_for_list.order("name asc")
rep_list << {:rep => r, :tag => tag}
end
return rep_list
end
def memo_list memos, current_user
return nil if memos.blank?
list = [] # 贴子的回复
memos.each do |memo|
# 总赞数
praise_count = memo.praise_tread.liker.count
# 用户是否点赞
user_praise = memo.praise_tread.select{|pt| pt.user_id == current_user.try(:id)}.length > 0 ? true : false
permission = current_user ? current_user.manager_of_memo?(memo) : false
# 实训TPM的管理员可以看到隐藏的评论
replies = {:id => memo.id, :content => memo.content, :time => time_from_now(memo.created_at), :user_id => memo.author_id,
:image_url => url_to_avatar(memo.author), :username => memo.author.show_name, :reward => memo.reward, :hidden => memo.hidden,
:permission => permission, :praise_count => praise_count, :user_praise => user_praise,
:user_login => memo.author.try(:login), :admin => current_user.admin}
# 现在没有二级回复所以查询的时候直接从root_id取
childrens = Memo.where(:parent_id => memo.id).includes(:author).reorder("created_at asc")
children_list = [] # 子回复
childrens.each do |child|
children_list << {:id => child.id, :content => child.content, :time => time_from_now(child.created_at),
:image_url => url_to_avatar(child.author), :username => child.author.show_name, :hidden => child.hidden,
:permission => permission, :user_login => child.author.try(:login), :user_id => child.author.try(:id)}
end
list << replies.merge({children: children_list})
end
list
end
# 帖子附件信息
def acttachements_info attachments
attachments_list = []
if attachments.present?
attachments.each do |attach|
attachments_list << {:id => attach.id,
:filename => attach.filename,
:url => "/attachments/download/" + "#{attach.id}" + "/" + "#{attach.filename}",
:filesize => attach.filesize}
end
end
return attachments_list
end
# 判断编辑器存储的内容是否是html类型的ke目的为了区分ke和markdown
def editor_html update_time
# str.include?("<p>" || "<div>" || "<span>" || "<img>" || "<strong>") && update_time < "2018-06-23"
update_time < "2018-06-23"
end
end

View File

@ -0,0 +1,366 @@
# encoding=utf-8
class MemosService
include ApplicationHelper
LIMIT = 10
def new current_user, session
csrf_token = session[:_csrf_token] ||= SecureRandom.base64(32)
tidding_count = unviewed_tiddings(current_user)
#reps = Repertoire.field_for_list.order("updated_at asc")
#tag_list = tag_list reps
current_user_info = format_for_current_user current_user
memo_type = object_to_hash Forum.select([:id, :name])
memo_tag = object_to_hash Label.select([:id, :name])
# csrf_token = SecureRandom.base64(32)
{current_user: current_user_info, memo_type: memo_type, memo_tag: memo_tag,
:csrf_token => csrf_token, :tidding_count => tidding_count}
end
# params 直接传params[:memo][:subject]
# subject标题
# content内容
# forum_id 话题类型
# sticky 是否置顶(创建时没入口)
# repertoire_name + language 技术标签
# attachments 附件
# attachment_id 是帖子的头像
def create params, current_user
return nil if params[:memo][:subject].blank? || params[:memo][:content].blank? || params[:memo][:forum_id].blank?
memo = Memo.new(params[:memo])
memo.author = current_user
memo.save_attachments(params[:attachments]) if params[:attachments].present?
memo.save!
# 为了区分帖子头像改变其类型为MemoIcon
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 0, message: "帖子创建成功!", memo_id: memo.id}
end
# params
# :id 帖子id
# return
# :memo 帖子
# :memo_replies 帖子的回复
# :recommend_shixun 推荐实训
# :admin 当前用户是否是管理员
# :author_info 表示当前帖子用户的信息
def show params, current_user
memo = Memo.find params[:id]
# 消息总数
tidding_count = unviewed_tiddings(current_user)
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id,
:filename => memo_image.filename,
:url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => memo_image.filesize} if memo_image
memo_praise_count = memo.praise_tread.liker.count
user_praise = PraiseTread.where(:praise_tread_object_id => memo.id, :praise_tread_object_type => "Memo",
:user_id => current_user.id, :praise_or_tread => 1).present? ? true : false
unless memo.children.blank?
memo.children.each do |child|
child.memo_messages.each do |memo_message|
memo_message.update_attributes(:viewed => true) if current_user.id == memo_message.user_id
end
end
end
query_memo_messages = memo.memo_messages
unless query_memo_messages
query_memo_messages.each do |query_memo_message|
query_memo_message.update_attributes(:viewed => true) if current_user.id == query_memo_message.user_id
end
end
memo.update_column(:viewed_count, memo.viewed_count + 1)
replies_count = memo.all_replies.count
# 帖子的回复
memos = memo.reply_for_memo.includes(:praise_tread, :author).order("created_at desc").limit(LIMIT)
watched = memo.author.watched_by?(current_user)
list = memo_list memos, current_user
is_md = memo.is_md
author_info = {username: memo.author.show_name,
watched: watched,
image_url: url_to_avatar(memo.author),
identity: memo.author.identity,
login: memo.author.login,
user_id: memo.author.id}
if memo.language.present?
label_id = memo.language.split(";")
tag = Label.where(:id => label_id).pluck(:name)
end
if memo.forum_id.present?
forum_name = Forum.find(memo.forum_id).name
end
memo = {id: memo.id,
subject: memo.subject,
is_md: is_md,
content: memo.content,
time: memo.created_at,
tag: tag, # 标签
forum_name: forum_name, #类型
sticky: memo.sticky, # 置顶 1
viewed_count: memo.viewed_count,
replies_count: replies_count,
praise_count: memo_praise_count,
reward: memo.reward,
attachment_url: attachments_list,
user_praise: user_praise}
current_user_info = format_for_current_user current_user
# recommend_shixuns: recommends,
{ memo: memo, memo_replies: list, author_info: author_info, memo_image_info: memo_image_info,
current_user: current_user_info, tidding_count: tidding_count}
end
def more_reply params, current_user
page = params[:page].to_i
offset = page * LIMIT
memo_id = params[:id]
# 总数,分页使用
memos_count = Memo.where(:parent_id => memo_id).count
memos = Memo.limit(LIMIT).where(:parent_id => memo_id).includes(:author, :praise_tread).offset(offset)
list = memo_list memos, current_user
return {:memo_replies => list, :memos_count => memos_count}
end
# 隐藏评论功能
def hidden params, current_user
memo = Memo.select([:id, :hidden]).find(params[:id])
if current_user.admin?
if params[:hidden] == "1"
memo.update_attribute(:hidden, true)
elsif params[:hidden] == "0"
memo.update_column("hidden", false)
end
else
raise("你没有权限")
end
end
def edit params, current_user
memo_type = object_to_hash Forum.select([:id, :name])
memo_tag = object_to_hash Label.select([:id, :name])
memo = Memo.select([:id, :subject, :content, :forum_id, :language]).find params[:id]
attachments_list = acttachements_info memo.attachments.where(:memo_image => false)
memo_image = memo.attachments.where(:memo_image => true).first
memo_image_info = {:id => memo_image.id,
:filename => memo_image.filename,
:url => "/attachments/download/" + "#{memo_image.id}" + "/" + "#{memo_image.filename}",
:filesize => memo_image.filesize} if memo_image
current_user_info = format_for_current_user current_user
memo.attributes.merge({memo_type: memo_type, memo_tag: memo_tag, current_user: current_user_info, attachments_url: attachments_list, memo_image_info: memo_image_info})
end
def update params
memo = Memo.find params[:id]
if(memo.update_attributes(params[:memo]))
# 为了将旧数据的KE转换为MD
if !memo.is_md && params[:content_changed]
memo.update_column(:is_md, true)
end
memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
end
memo.save!
# 为了区分帖子头像改变其类型为MemoIcon
if params[:attachment_id]
attachment = Attachment.find(params[:attachment_id])
attachment.update_attributes(:container_id => memo.id, :container_type => "Memo", :memo_image => true)
end
{status: 0, message: "帖子更新成功!"}
end
# params
# 排序:order -> 类型字符串replies_count最热 created_at 最新
# 搜索:search -> 类型:字符串;
# 类型:forum -> 类型:整型; 值3 操作指南 5 技术分享
# 用户:user_id -> 搜索那个用户的帖子(目前主要用来显示我的帖子)。
# 标签:language -> 经过base64编码后的热门标签带特殊字符
# return:
# memo_list 列表
# memo_count 帖子的总数
# current_user 用户信息
# hot_memos 热门帖子
# recommend_shixuns 推荐实训
# hot_tags 热门标签
# my_memos_count 我的帖子数
def get_memos_list params, current_user
s_order = params[:order] || "updated_at"
tidding_count = unviewed_tiddings(current_user) if current_user.present?
page = params[:page].to_i
offset = page * 15
search = params[:search]
forum_id = params[:forum]
sql =
if forum_id
search ? "forum_id = #{forum_id} and root_id is null and subject like '%#{search}%'"
: "forum_id = #{forum_id} and root_id is null"
elsif search
"root_id is null and subject like '%#{search}%'"
end
memos = Memo.field_for_list.includes(:praise_tread, :author).where("#{sql}")
memos_count = memos.count # 帖子的总数
memos = memos.order("sticky=1 desc, #{Memo.table_name}.#{s_order} desc").offset(offset).limit(15)
memo_list = memo_data memos
my_memos_count = Memo.user_posts(current_user.id).count
# 标签只有forum_id = 5才有
hot_tags = object_to_hash Forum.select([:id, :name])
hot_memos = Memo.field_for_recommend.posts.hot.limit(4)
# 将热门问题添加 回复数
hot_memos =
hot_memos.map do |hm|
replies_count = Memo.where(:root_id => hm.id).count
hm.attributes.dup.merge({replies_count: replies_count})
end
current_user_info = format_for_current_user current_user
{memo_list: memo_list, memo_count: memos_count, hot_memos: hot_memos,
hot_tags: hot_tags, my_memos_count: my_memos_count,
current_user: current_user_info, tidding_count: tidding_count}
end
# params
# parent_id: 给谁的回复id
# content: 回复的内容
def reply params, current_user
memo = Memo.find params[:parent_id]
reply = Memo.new
reply.content = params[:content]
reply.author = current_user
reply.forum_id = memo.forum_id
reply.subject = memo.subject
reply.root_id = memo.root_id || memo.id
memo.children << reply
reply
end
# params:
# order 排序
# forum_id: 3.技术分享; 5操作指南
# sticky: 1 置顶,0 取消置顶
# id 帖子ID
def set_top_or_down params
s_order = params[:order] || "updated_at"
forum_id = params[:forum_id]
sql = forum_id ? "forum_id = #{forum_id} and root_id is null" : "root_id is null"
Memo.find(params[:id]).update_attribute(:sticky, params[:sticky])
memos = Memo.field_for_list.includes(:praise_tread, :author).where("#{sql}").order("sticky=1 desc, #{s_order} desc").limit(15)
memo_list = memo_data memos
{status: 0, message: "操作成功!", memo_list: memo_list}
end
protected
def unviewed_tiddings current_user
new_tidings_count = current_user.tidings.where("created_at > '#{current_user.onclick_time.onclick_time}'").count
new_pri_message_count = current_user.private_messages.where("created_at > '#{current_user.onclick_time.onclick_time}'").count
count = new_tidings_count + new_pri_message_count
return count
end
def find_memo params
if params[:id].blank?
@memo = Memo.new
else
@memo = Memo.find params[:id]
end
end
def format_for_current_user current_user
{username: current_user.show_name, login: current_user.login,
user_id: current_user.id, image_url: url_to_avatar(current_user),
admin: current_user.admin?, is_teacher: current_user.user_extensions.try(:identity) == 0 }
end
# 将数据库对象转换成哈希对象
def object_to_hash objects
objects.map{|o| o.attributes.dup}
end
# 将memos对象添加额外信息
def memo_data memos
memo_list = []
memos.each do |m|
praise_count = m.praise_tread.where(:praise_or_tread => 1).count
forum_name = Forum.find(m.forum_id).name
user_info = {username: m.author.show_name, login: m.author.login, image_url: url_to_avatar(m.author), praise_count: praise_count, forum_name:forum_name}
memo_list << m.attributes.dup.merge(user_info)
end
memo_list
end
# 权限
def permission memo, current_user
if current_user.admin?
1
elsif memo.author_id == current_user.id
2
else
3
end
end
def tag_list reps
rep_list = []
reps.each do |r|
sub_ids = SubRepertoire.where(:repertoire_id => r.id).pluck(:id)
tag = object_to_hash TagRepertoire.where(:sub_repertoire_id => sub_ids).field_for_list.order("name asc")
rep_list << {:rep => r, :tag => tag}
end
return rep_list
end
def memo_list memos, current_user
return nil if memos.blank?
list = [] # 贴子的回复
memos.each do |memo|
# 总赞数
praise_count = memo.praise_tread.liker.count
# 用户是否点赞
user_praise = memo.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false
# 实训TPM的管理员可以看到隐藏的评论
replies = {:id => memo.id, :content => memo.content, :time => time_from_now(memo.created_at), :user_id => memo.author_id,
:image_url => url_to_avatar(memo.author), :username => memo.author.show_name, :reward => memo.reward, :hidden => memo.hidden,
:permission => current_user.manager_of_memo?(memo), :praise_count => praise_count, :user_praise => user_praise,
:user_login => memo.author.try(:login), :admin => current_user.admin}
# 现在没有二级回复所以查询的时候直接从root_id取
childrens = Memo.where(:parent_id => memo.id).includes(:author).reorder("created_at asc")
children_list = [] # 子回复
childrens.each do |child|
children_list << {:id => child.id, :content => child.content, :time => time_from_now(child.created_at),
:image_url => url_to_avatar(child.author), :username => child.author.show_name, :hidden => child.hidden,
:permission => current_user.manager_of_memo?(memo), :user_login => child.author.try(:login), :user_id => child.author.try(:id)}
end
list << replies.merge({children: children_list})
end
list
end
# 帖子附件信息
def acttachements_info attachments
attachments_list = []
if attachments.present?
attachments.each do |attach|
attachments_list << {:id => attach.id,
:filename => attach.filename,
:url => "/attachments/download/" + "#{attach.id}" + "/" + "#{attach.filename}",
:filesize => attach.filesize}
end
end
return attachments_list
end
# 判断编辑器存储的内容是否是html类型的ke目的为了区分ke和markdown
def editor_html update_time
# str.include?("<p>" || "<div>" || "<span>" || "<img>" || "<strong>") && update_time < "2018-06-23"
update_time < "2018-06-23"
end
end

View File

@ -22,17 +22,6 @@ class ProjectsService
project
end
def send_wechat_create_project_notice user,project
count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Project' and shield_id=#{project.id}").count
Rails.logger.info "!!!!!!!!!!!!!!!!!!!!!!#{project}"
if count == 0
ws = WechatService.new
title = "恭喜您创建项目成功。"
ws.create_project_notice user.id, "create_project_notice", project.id,title, project.name, format_time(project.created_on),"点击查看项目详情。"
end
end
def createNewProject params,user
status = -1
issue_custom_fields = IssueCustomField.sorted.all
@ -52,7 +41,6 @@ class ProjectsService
# if validate_parent_id && @project.save
if project.save
p = Project.find("#{project.id}")
# send_wechat_create_project_notice user,p
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => user, :roles => [r])
# project's score
@ -117,27 +105,6 @@ class ProjectsService
]
end
#加入项目结果
def send_wechat_join_project_notice user,project,role_id,result
# count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Project' and shield_id=#{project.id}").count
# if count == 0
# result_name = result == 0 ? "已同意" : "已拒绝"
# if result == 0
# title = "恭喜您加入项目成功。"
# remark = "点击查看项目详情。"
# uid = 0
# type = "project"
# else
# title = "很遗憾您未能成功加入项目。"
# remark = "点击查看申请详情。"
# uid = user.id
# type = "review_project_member"
# end
# ws = WechatService.new
# ws.join_project_notice user.id, "project", project.id,title, project.name,result_name, remark,uid
# end
end
def join_project params,current_user
status = -1
project = Project.find_by_invite_code(params[:invite_code]) if params[:invite_code]
@ -171,7 +138,6 @@ class ProjectsService
project.project_infos << project_info
status = 0
send_wechat_join_project_notice current_user,project,5,0
#将之前的申请都改为已拒绝
applied_messages = AppliedMessage.where(:project_id => project.id, :status => true, :applied_user_id=>current_user.id,:applied_type => "AppliedProject")
@ -301,8 +267,6 @@ class ProjectsService
message = "您已同意"+rolename+user.show_name+",加入项目"
send_wechat_join_project_notice user,project,ap_role,0
else
#拒绝
AppliedMessage.create(:user_id => user.id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 4,
@ -313,7 +277,6 @@ class ProjectsService
message = "您已拒绝"+rolename+user.show_name+",加入项目"
send_wechat_join_project_notice user,project,ap_role,1
end
status = 0
@ -331,30 +294,6 @@ class ProjectsService
{:status => status,:message => message}
end
def send_wechat_project_issue_notice user,project,issue_id,issue_title,priority_id
count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Project' and shield_id=#{project.id}").count
if count == 0
title = "您有新的issue需要解决。"
remark = "点击详情查看issue。"
case priority_id
when "1"
priority = ""
when "2"
priority = "正常"
when "3"
priority = ""
when "4"
priority = "紧急"
when "5"
priority = "立刻"
end
ws = WechatService.new
ws.project_issue_notice user.id, "issues", issue_id,title, issue_title,priority, remark
end
end
#删除项目成员
def project_delete_member project,user_id,current_user
if current_user.nil?

View File

@ -1 +1,13 @@
<p class="color-grey-9 copyright_info">Copyright 2007~2018, All Rights Reserved.&nbsp;&nbsp;湘ICP备17009477号&nbsp;&nbsp;&nbsp;&nbsp;Powered by <a href="https://team.trustie.net" class="color-grey-9" target="_blank">Trustie</a> and <a href="https://intellide.trustie.net" target="_blank" class="color-grey-9">IntelliDE</a>.</p>
<p class="mb10 edu-txt-center mt50">
<% unless PublicProperty.where(:property => "Tel").first.try(:value).blank? %>
<span class="mr15"><i class="iconfont icon-weibiaoti- font-16"></i> <%= PublicProperty.where(:property => "Tel").first.try(:value) %></span>
<% end %>
<% unless PublicProperty.where(:property => "Email").first.try(:value).blank? %>
<span class="mr15"><i class="iconfont icon-mail font-16"></i> <%= PublicProperty.where(:property => "Email").first.try(:value) %></span>
<% end %>
<% unless PublicProperty.where(:property => "Address").first.try(:value).blank? %>
<span class="mr15"><i class="iconfont icon-xiazai18 font-16"></i> <%= PublicProperty.where(:property => "Address").first.try(:value) %></span>
<% end %>
</p>
<p class="color-grey-9 edu-txt-center">版权所有:<%= PublicProperty.where(:property => "Copyright").first.try(:value) %>&nbsp;&nbsp;&nbsp;&nbsp;Powerd by <span class="color-grey-71">Trustie</span></p>

View File

@ -20,6 +20,10 @@
</div>
<% end %>
</div>
<p class="color-dark mt120">Copyright 2007~2018, All Rights Reserved.&nbsp;&nbsp;湘ICP备17009477号&nbsp;&nbsp;&nbsp;&nbsp;Powered by <a href="https://team.trustie.net" class="color-dark" target="_blank">Trustie</a> and <a href="https://intellide.trustie.net" target="_blank" class="color-dark">IntelliDE</a>.</p>
</div>
<p class="mb10">
<span class="mr15 colorFFF"><i class="iconfont icon-weibiaoti- font-16"></i>+010-68207906</span>
<span class="mr15 colorFFF"><i class="iconfont icon-mail font-16"></i>liyang@opengcc.org</span>
<span class="mr15 colorFFF"><i class="iconfont icon-xiazai18 font-16"></i> 北京市海淀区万寿路27号</span>
</p>
<p class="colorFFF">版权所有:绿色计算产业联盟&nbsp;&nbsp;&nbsp;&nbsp;京ICP备06019433号-15&nbsp;&nbsp;&nbsp;&nbsp;Powerd by Trustie</p></div>
</div>

View File

@ -45,7 +45,12 @@
</div>
<% end %>
</div>
<p class="color-dark mt120">Copyright 2007~2018, All Rights Reserved.&nbsp;&nbsp;湘ICP备17009477号&nbsp;&nbsp;&nbsp;&nbsp;Powered by <a href="https://team.trustie.net" class="color-dark" target="_blank">Trustie</a> and <a href="https://intellide.trustie.net" target="_blank" class="color-dark">IntelliDE</a>.</p>
<p class="mb10">
<span class="mr15 colorFFF"><i class="iconfont icon-weibiaoti- font-16"></i>+010-68207906</span>
<span class="mr15 colorFFF"><i class="iconfont icon-mail font-16"></i>liyang@opengcc.org</span>
<span class="mr15 colorFFF"><i class="iconfont icon-xiazai18 font-16"></i> 北京市海淀区万寿路27号</span>
</p>
<p class="colorFFF">版权所有:绿色计算产业联盟&nbsp;&nbsp;&nbsp;&nbsp;京ICP备06019433号-15&nbsp;&nbsp;&nbsp;&nbsp;Powerd by Trustie</p>
</div>
</div>

View File

@ -10,12 +10,12 @@
<div class="edu-index-show-con pt30 clearfix mb30" >
<div class="with20 fl">
<ul class="edu-class-leftnav " style="text-align: left">
<li class="<%= @index == 1 ? 'active':'' %>"><a href="<%= help_path(:index => 1) %>" class="ml15">关于我们</a></li>
<li class="<%= @index == 2 ? 'active':'' %>"><a href="<%= help_path(:index => 2) %>" class="ml15">联系我们</a></li>
<li class="<%= @index == 3 ? 'active':'' %>"><a href="<%= help_path(:index => 3) %>" class="ml15">合作伙伴</a></li>
<!--<li class="<%#= @index == 1 ? 'active':'' %>"><a href="<%#= help_path(:index => 1) %>" class="ml15">关于我们</a></li>-->
<!--<li class="<%#= @index == 2 ? 'active':'' %>"><a href="<%#= help_path(:index => 2) %>" class="ml15">联系我们</a></li>-->
<!--<li class="<%#= @index == 3 ? 'active':'' %>"><a href="<%#= help_path(:index => 3) %>" class="ml15">合作伙伴</a></li>-->
<li class="<%= @index == 4 ? 'active':'' %>"><a href="<%= help_path(:index => 4) %>" class="ml15">服务协议</a></li>
<li class="<%= @index == 5 ? 'active':'' %>"><a href="<%= help_path(:index => 5) %>" class="ml15">帮助中心</a></li>
<li class="<%= @index == 6 ? 'active':'' %>"><a href="<%= User.current.logged? ? help_path(:index => 6) : signin_path %>" class="ml15">意见反馈</a></li>
<!--<li class="<%#= @index == 5 ? 'active':'' %>"><a href="<%#= help_path(:index => 5) %>" class="ml15">帮助中心</a></li>-->
<!--<li class="<%#= @index == 6 ? 'active':'' %>"><a href="<%#= User.current.logged? ? help_path(:index => 6) : signin_path %>" class="ml15">意见反馈</a></li>-->
</ul>
</div>
<div class="with80 fl" id = 'right' style="text-align: left">
@ -30,7 +30,7 @@
data: {index: '<%= @index %>'},
type: 'post',
dataType: 'script'
})
});
$(function(){
KindEditor.ready(function(K){
$("#hidden_div_block").each(function(){
@ -50,9 +50,9 @@
});
var title = ["关于我们","联系我们","合作伙伴","服务协议","帮助中心","意见反馈"]
$('.edu-class-leftnav li').on('click',function(){
$(this).siblings().removeClass('active')
var i = $(this).index()
$("title").html(title[i])
$(this).siblings().removeClass('active');
var i = $(this).index();
$("title").html(title[i]);
$(this).addClass('active');
$("a",this)[0].click();

View File

@ -2,7 +2,7 @@
<div class="login_register educontent" id="backImg" >
<div class="pr edu-txt-center height-100 pt110">
<div class="login_reg pr">
<a href="<%= home_path %>" class="logo-redirect"><img src="/images/trustieForge/Forgelogo.png"></a>
<a href="<%= home_path %>" class="logo-redirect"><img src="/images/trustieForge/Loginlogo"></a>
<%= link_to '', home_path, :class => "logo-redirect" %>
<div id="log_reg_content">
<ul class="log_nav clearfix">
@ -82,8 +82,19 @@
</div>-->
</div>
</div>
<p class="color-white mt120">Copyright 2007~2018, All Rights Reserved.&nbsp;&nbsp;湘ICP备17009477号&nbsp;&nbsp;&nbsp;&nbsp;Powered by <a href="https://team.trustie.net" class="color-white" target="_blank">Trustie</a> and <a href="https://intellide.trustie.net" target="_blank" class="color-white" >IntelliDE</a>.</p>
</div>
<p class="mb10">
<% unless PublicProperty.where(:property => "Tel").first.try(:value).blank? %>
<span class="mr15"><i class="iconfont icon-weibiaoti- font-16"></i> <%= PublicProperty.where(:property => "Tel").first.try(:value) %></span>
<% end %>
<% unless PublicProperty.where(:property => "Email").first.try(:value).blank? %>
<span class="mr15"><i class="iconfont icon-mail font-16"></i> <%= PublicProperty.where(:property => "Email").first.try(:value) %></span>
<% end %>
<% unless PublicProperty.where(:property => "Address").first.try(:value).blank? %>
<span class="mr15"><i class="iconfont icon-xiazai18 font-16"></i> <%= PublicProperty.where(:property => "Address").first.try(:value) %></span>
<% end %>
</p>
<p class="colorFFF">版权所有:<%= PublicProperty.where(:property => "Copyright").first.try(:value) %>&nbsp;&nbsp;&nbsp;&nbsp;Powerd by Trustie</p>
</div>
</div>
<script>

View File

@ -29,6 +29,11 @@
<a href="javascript:void(0);" id="lost_psd_next_a" disabled class="mt20 log-botton">下一步</a>
</div>
</div>
<p class="color-dark mt80">Copyright 2007~2018, All Rights Reserved.&nbsp;&nbsp;湘ICP备17009477号&nbsp;&nbsp;&nbsp;&nbsp;Powered by <a href="https://team.trustie.net" class="color-dark" target="_blank">Trustie</a> and <a href="https://intellide.trustie.net" target="_blank" class="color-dark">IntelliDE</a>.</p>
<p class="mb10">
<span class="mr15 colorFFF"><i class="iconfont icon-weibiaoti- font-16"></i>+010-68207906</span>
<span class="mr15 colorFFF"><i class="iconfont icon-mail font-16"></i>liyang@opengcc.org</span>
<span class="mr15 colorFFF"><i class="iconfont icon-xiazai18 font-16"></i> 北京市海淀区万寿路27号</span>
</p>
<p class="colorFFF">版权所有:绿色计算产业联盟&nbsp;&nbsp;&nbsp;&nbsp;京ICP备06019433号-15&nbsp;&nbsp;&nbsp;&nbsp;Powerd by Trustie</p>
</div>
</div>

View File

@ -57,8 +57,12 @@
</div>
</div>
</div>
<p class="edu-txt-center mt20">Copyright 2007~2018, All Rights Reserved. 湘ICP备17009477号</p>
<p class="edu-txt-center">Powered by Trustie and IntelliDE.</p>
<p class="mb10">
<span class="mr15 colorFFF"><i class="iconfont icon-weibiaoti- font-16"></i>+010-68207906</span>
<span class="mr15 colorFFF"><i class="iconfont icon-mail font-16"></i>liyang@opengcc.org</span>
<span class="mr15 colorFFF"><i class="iconfont icon-xiazai18 font-16"></i> 北京市海淀区万寿路27号</span>
</p>
<p class="colorFFF">版权所有:绿色计算产业联盟&nbsp;&nbsp;&nbsp;&nbsp;京ICP备06019433号-15&nbsp;&nbsp;&nbsp;&nbsp;Powerd by Trustie</p>
</div>
</div>

View File

@ -4,7 +4,7 @@
<a href="<%= home_path %>" class="none"><img src="/images/educoder/logo.png" class="fl"/></a>
<span class="fr">已有账号,<a href="<%= signin_path %>" class="color-blue">马上登录</a><em class="vertical-line ml10 mr5"></em><a href="<%= home_path %>" class="color-blue">返回首页</a></span>
</div>
<div class="account_main">
<div class="account_main" style="margin-bottom: 100px;">
<div class="account_title">注册会员</div>
<%= form_for :user, :url => register_path, :method => 'post', :html => { :id => 'main_reg_form' } do |f| %>
<input type="text" name="none_name" id="none_name" style="display: none">
@ -30,7 +30,7 @@
</div>
<div class="clearfix mt10">
<input type="checkbox" class="mr5 magic-checkbox" id="read_and_confirm_1" checked="checked"/>
<label for="read_and_confirm_1" class="fl" style="top:0px">我已阅读并同意<a href="https://www.educoder.net/help?index=4" class="color-blue">服务协议条款</a></label>
<label for="read_and_confirm_1" class="fl" style="top:0px">我已阅读并同意<a href="<%= help_path %>" class="color-blue" target="_blank">服务协议条款</a></label>
<div style="height: 25px;" class="clearfix">
<p class="color-orange edu-txt-left none" id="user_aggre_1_notice"></p>
</div>
@ -42,3 +42,11 @@
<%= render :partial => "account/copyright_info" %>
</div>
</div>
<script>
$(window).load(function(){
if($('#user_phone_num').val().trim() != ""){
$('#user_phone_num').blur();
}
});
</script>

View File

@ -4,11 +4,11 @@
<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<% end %>
<%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
<% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'),
<%# if attachment.is_text? %>
<%#= link_to image_tag('magnifier.png'),
:controller => 'attachments', :action => 'show',
:id => attachment, :filename => attachment.filename %>
<% end %>
<%# end %>
<span title="<%= attachment.description%>">
<%= h(truncate(" - #{attachment.description}", length: 20, omission: '...')) unless attachment.description.blank? %>
</span>

View File

@ -16,13 +16,13 @@
</div>
<% end%>
<% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'),
<%# if attachment.is_text? %>
<%#= link_to image_tag('magnifier.png'),
:controller => 'attachments',
:action => 'show',
:id => attachment,
:filename => attachment.filename%>
<% end %>
<%# end %>
<span title="<%= attachment.description%>">
<%= h(truncate(" - #{attachment.description}", length: options[:length] ? options[:length]:15, omission: '...')) unless attachment.description.blank? %>
</span>

View File

@ -2,7 +2,7 @@
<% if defined?(container) && container && container.saved_attachments %>
<% container.attachments.each_with_index do |attachment, i| %>
<span id="attachments_p<%= i %>" class="attachment">
<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'upload_filename readonly hidden', :readonly => 'readonly', :style=>'border:none; width:460px;') %>
<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'upload_filename readonly hidden ml15', :readonly => 'readonly', :style=>'border:none; width:460px;') %>
<%#= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style => "display: inline-block;") %>
<!--<span class="ispublic-label"><%#= l(:field_is_public) %>:</span>-->
@ -27,7 +27,7 @@
<span class="add_attachment" style="font-weight:normal;">
<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %>
<!--%= link_to image_tag(),"javascript:void(0)", :onclick => "_file.click()"%-->
<%= button_tag "上传附件", :id => "upload_attachments", :type=>"button", :onclick=>"$('#_file').click();",:onmouseover => 'this.focus()',:class => 'sub_btn' %>
<%= button_tag "上传附件", :id => "upload_attachments", :type=>"button", :onclick=>"$('#_file').click();",:onmouseover => 'this.focus()',:class => 'sub_btn ml18' %>
<%= file_field_tag 'attachments[dummy][file]',
:id => '_file',
:class => 'file_selector',

View File

@ -3,16 +3,16 @@
<div title="<%= attachment.filename%>" id = "attachment_" style="max-width: 300px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;float: left;">
<%= link_to_short_attachment attachment, :class => 'link_file', :download => true, :length => 100 -%>
</div>
<% if attachment.is_text? %>
<div style="float: left;">
<%= link_to image_tag('magnifier.png'),
<%# if attachment.is_text? %>
<!--<div style="float: left;">
<%#= link_to image_tag('magnifier.png'),
{:controller => 'attachments',
:action => 'show',
:id => attachment,
:filename => attachment.filename},
:target => "_blank"%>
</div>
<% end %>
</div>-->
<%# end %>
<div class="cl"></div>
<% end %>
</div>

View File

@ -16,13 +16,13 @@
</div>
<% end%>
<% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'),
<%# if attachment.is_text? %>
<%#= link_to image_tag('magnifier.png'),
:controller => 'attachments',
:action => 'show',
:id => attachment,
:filename => attachment.filename%>
<% end %>
<%# end %>
<span title="<%= attachment.description%>">
<%= h(truncate(" - #{attachment.description}", length: options[:length] ? options[:length]:15, omission: '...')) unless attachment.description.blank? %>
</span>

View File

@ -28,8 +28,8 @@
<div class="attachments" style="font-weight:normal;">
<% is_float ||= false %>
<% for attachment in attachments %>
<div style="float:left;">
<p style="height:14px;line-height:12px;width: 100%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
<div class="fl mt3">
<p style="height:18px;line-height:12px;width: 100%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
<% if is_float %>
<div style="max-width:55%;white-space: nowrap; overflow: hidden; text-overflow: ellipsis;float: left;">
<% end %>
@ -52,13 +52,13 @@
</div>
<% end %>
<% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'),
<%# if attachment.is_text? %>
<%#= link_to image_tag('magnifier.png'),
:controller => 'attachments',
:action => 'show',
:id => attachment,
:filename => attachment.filename%>
<% end %>
<%# end %>
</div>
<div style="float:left;max-width:220px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;" title="<%= attachment.description%>">
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
@ -69,7 +69,7 @@
<% if options[:deletable] %>
<% if attachment.container_type == 'Issue' %>
<% if User.current == attachment.author %>
<%= link_to image_tag('delete.png'), attachment_path(attachment),
<%= link_to '<i class="iconfont icon-shanchu font-16 color-grey-8"></i>'.html_safe, attachment_path(attachment),
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,
:class => 'delete',
@ -79,7 +79,7 @@
<% end %>
<% elsif attachment.container_type == 'TrainingTask' %>
<% if User.current == attachment.author %>
<%= link_to image_tag('delete.png'), attachment_path(attachment),
<%= link_to '<i class="iconfont icon-shanchu font-16 color-grey-8"></i>'.html_safe, attachment_path(attachment),
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,
:class => 'delete',
@ -88,7 +88,7 @@
:title => l(:button_delete) %>
<% end %>
<% else %>
<%= link_to image_tag('delete.png'), attachment_path(attachment),
<%= link_to '<i class="iconfont icon-shanchu font-16 color-grey-8"></i>'.html_safe, attachment_path(attachment),
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,
:class => 'delete',
@ -103,7 +103,7 @@
<% end %>
<% if options[:author] %>
<span class="author" title="<%= attachment.author.show_name%>">
<%= link_to h(truncate(attachment.author.show_name, length: 10, omission: '...')), User.current.logged? ? user_path(attachment.author) : signin_url_without_domain, :class => "color-orange03" %>,
<%= link_to h(truncate(attachment.author.show_name, length: 20, omission: '...')), User.current.logged? ? user_path(attachment.author) : signin_url_without_domain, :class => "color-orange03" %>,
<%= format_time(attachment.created_on) %>
</span>
<% end %>

View File

@ -19,7 +19,7 @@
$("#show_img_url").val(<%= "#{@urlfile.to_s}"%>);
<% elsif @source_type == 'Platform' %>
$("#mirror_image_<%= @source_id %>").attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'});
<% elsif @source_type == 'Shixun' || @source_type == 'Subject' %>
<% elsif @source_type == 'Shixun' || @source_type == 'Subject' || @source_type == 'Advertisement' %>
notice_box("上传成功");
$("#object_upload_img_<%= @source_id %>").html("重新上传");
$("#shixun_image_show_<%= @source_id %>").attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'}).show();
@ -27,6 +27,10 @@
var element = $("<a></a>").attr("href", image.attr('src')+".png");
image.wrap(element);
$(image).parent().colorbox({rel: 'nofollow', close: "关闭", returnFocus: false});
<% elsif @source_type == 'Forgelogo' %>
$(".forge_logo").attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'});
<% elsif @source_type == 'Loginlogo' %>
$("#login_logo").attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'});
<% else %>
<% if @source_type=='User' %>
var imgSpan = jQuery('#nh_user_logo');

View File

@ -11,7 +11,11 @@
<img src="/images/warn/pic_403.jpg" >
<p class="font-18 mt40">
您可以稍后尝试&nbsp;<a href="javascript:history.back()" class="color-blue">返回上页</a>,或者&nbsp;
<a href="http://shang.qq.com/wpa/qunwpa?idkey=064e805dac955b8aea158c4b0dd3f033b8841bcee175fd619613f0e4ac4d8151" target="_blank" class="color-blue">QQ反馈>></a>
<% if User.current.logged? %>
<a href="<%= message_detail_user_path(User.current, :user_id => 1) %>" class="color-blue">意见反馈>></a>
<% else %>
<a href="<%= signin_url %>" class="color-blue">意见反馈>></a>
<% end %>
</p>
</div>
</body>

View File

@ -11,7 +11,11 @@
<img src="/images/warn/pic_404.jpg" >
<p class="font-18 mt40">
您可以稍后尝试&nbsp;<a href="javascript:history.back()" class="color-blue">返回上页</a>,或者&nbsp;
<a href="http://shang.qq.com/wpa/qunwpa?idkey=064e805dac955b8aea158c4b0dd3f033b8841bcee175fd619613f0e4ac4d8151" target="_blank" class="color-blue">QQ反馈>></a>
<% if User.current.logged? %>
<a href="<%= message_detail_user_path(User.current, :user_id => 1) %>" class="color-blue">意见反馈>></a>
<% else %>
<a href="<%= signin_url %>" class="color-blue">意见反馈>></a>
<% end %>
</p>
</div>
</body>

View File

@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><title>Educoder</title><script type="text/javascript">window.__isR=!0</script><link rel="stylesheet" href="/react/build/css/css_min_all.css"><link rel="stylesheet" href="//at.alicdn.com/t/font_653600_euyzqz9ex50cnmi.css"><link href="/react/build/./static/css/main.683ad105.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root" class="page -layout-v -fit"></div><div id="picture_display" style="display:none"></div><script type="text/javascript" src="/react/build/js/js_min_all_2.js"></script><script type="text/javascript" src="/assets/kindeditor/kindeditor.js"></script><script type="text/javascript" src="/react/build/js/create_kindeditor.js"></script><script type="text/javascript" src="/react/build/./static/js/main.bea63e8e.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/images/trustieForge/Forgelogo"><title></title><script type="text/javascript">window.__isR=!0</script><link rel="stylesheet" href="/react/build/css/css_min_all.css"><link rel="stylesheet" href="//at.alicdn.com/t/font_653600_euyzqz9ex50cnmi.css"><link href="/react/build/./static/css/main.3e127e7a.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root" class="page -layout-v -fit"></div><div id="picture_display" style="display:none"></div><script type="text/javascript" src="/react/build/js/js_min_all_2.js"></script><script type="text/javascript" src="/assets/kindeditor/kindeditor.js"></script><script type="text/javascript" src="/react/build/js/create_kindeditor.js"></script><script type="text/javascript" src="/react/build/./static/js/main.26dac415.js"></script></body></html>

View File

@ -1,9 +1,5 @@
<p> <!--ondblclick=show_edit_file_description('<%#= file.id %>')-->
<span style="white-space:nowrap;">资源描述:</span><% if file.description.blank? %><!--<span style="color:#C5C5BE; cursor:pointer;" title="双击可编辑">双击添加描述</span>--><% else %><span id="file_description_tip_<%= file.id %>" style="cursor:default;" class="break_word"><%= file.description %></span><% end %>
<%#= file.description.blank? ? "该资源暂无描述" : file.description %>
<% if @course %>
<%= link_to image_tag("../images/signature_edit.png",width:"12px", height: "12px"), setting_course_file_path(@course, file), :remote =>true %><!--, :onclick => "show_edit_file_description("+file.id.to_s+");"-->
<% else %>
<%= link_to image_tag("../images/signature_edit.png",width:"12px", height: "12px"), attachments_versions_path(file), :remote =>true %><!--, :onclick => "show_edit_file_description("+file.id.to_s+");"-->
<% end %>
<%= link_to image_tag("../images/signature_edit.png",width:"12px", height: "12px"), attachments_versions_path(file), :remote =>true %><!--, :onclick => "show_edit_file_description("+file.id.to_s+");"-->
</p>

View File

@ -1,5 +1,5 @@
<span data-containerid="<%= container.id %>">
<% checkBox = (@course.present? && @course.is_public?) ? 'public' : 'private'%>
<% checkBox = 'private'%>
<a class="white-btn orange-btn" onclick="_file<%=container.id %>.click()" onmouseover="this.focus()" style="<%= ie8? ? 'display:none' : ''%>">文件浏览</a>
<!--<button name="button" class="sub_btn" onclick="_file<%#=container.id %>.click()" onmouseover="this.focus()" style="<%#= ie8? ? 'display:none' : ''%>" type="button" >文件浏览</button>-->
<%= file_field_tag 'attachments[dummy][file]',

View File

@ -1,8 +1,8 @@
<script>
$(function(){
$("#RSide").removeAttr("id")
$("#container").css('width',"1000px")
$("#RSide").removeAttr("id");
$("#container").css('width',"1000px");
});
function searchone4reload(fileid){
var url = "<%= searchone4reload_project_files_path(@project)%>";

View File

@ -101,48 +101,6 @@
<%end%>
}
function course_attachmenttypes_searchex(value) {
<% if @course%>
$.ajax({
url: '<%=getattachtype_course_files_path(course_id: @course)%>',
type: "POST",
data: {
type: encodeURIComponent(value),
contentType: $('#attach_sufix_browse').val()
}
}).complete(eval_ajax);
<%end%>
}
function course_attachment_contenttypes_searchex(value) {
<% if @course%>
$.ajax({
url: '<%=getattachtype_course_files_path(course_id: @course)%>',
type: "POST",
data: {
type: $('#attachment_browse').val(),
contentType: encodeURIComponent(value)
}
}).complete(eval_ajax);
<%end%>
}
function course_attachtype_edit(value) {
<% if @course%>
$.ajax({
url: '<%=getattachtype_course_files_path(course_id: @course)%>',
type: "POST",
data: {
type: $('#attachment_browse').val(),
contentType: encodeURIComponent(value)
}
}).complete(eval_ajax);
<%end%>
}
function attachmenttypes_change(id, type) {
<% if @project%>
$.ajax({

View File

@ -15,7 +15,7 @@
<% @groups.each do |group| %>
<tr class="<%= cycle 'odd', 'even' %>">
<td><%= link_to h(group), edit_group_path(group) %></td>
<td align="center"><%= group.users.size %></td>
<td class="buttons"><%= delete_link group %></td>
</tr>
<% end %>

View File

@ -1,3 +1,6 @@
<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %>
<%= javascript_include_tag '/editormd/lib/marked.min.js','/editormd/lib/prettify.min.js','/editormd/lib/raphael.min.js','/editormd/lib/underscore.min.js','/editormd/lib/sequence-diagram.min.js',
'/editormd/lib/flowchart.min.js','/editormd/lib/jquery.flowchart.min.js','/editormd/editormd.js' %>
<div id="issue_detail" style="display: block">
<div class="ping_dispic">
<%= link_to image_tag(url_to_avatar(@issue.author), :width => 46, :height => 46), user_path(@issue.author), :class => "ping_dispic" %>
@ -29,10 +32,13 @@
<div class="cl"></div>
<% if @issue.description? || @issue.attachments.any? -%>
<div class="talk_info mb10 issue_desc ke-block" id="issue_desc_<%= @issue.id %>" style="word-break:break-all;">
<% if @issue.description? %>
<div class="new_li" id="issue_desc_show" style="box-sizing: border-box">
<textarea style="display:none;"><%= @issue.description %></textarea>
</div>
<%# if @issue.description? %>
<%#= link_to l(:button_quote), quoted_issue_path(@issue.id), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %>
<%= textAreailizable @issue, :description, :attachments => @issue.attachments %>
<% end %>
<%#= textAreailizable @issue, :description, :attachments => @issue.attachments %>
<%# end %>
</div>
<% end -%>
@ -49,5 +55,8 @@
$(function(){
showNormalImage('issue_desc_<%= @issue.id %>');
autoUrl('issue_desc_<%= @issue.id %>');
// markdownHtml渲染
editormd_to_html("issue_desc_show");
});
</script>

View File

@ -1,9 +1,11 @@
<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %>
<%= javascript_include_tag '/editormd/editormd' %>
<%= labelled_fields_for :issue, @issue do |f| %>
<ul class="fl pro_new_conbox_left">
<li>
<% if @issue.safe_attribute? 'subject' %>
<label class="label"><span class="c_red f12">*</span>&nbsp;主题&nbsp;&nbsp;:&nbsp;</label>
<%= f.text_field :subject, :style => "font-size:small;width:606px;", :no_label => true %>
<%= f.text_field :subject, :style => "font-size:small;width: 778px;margin-left: 16px;height:35px;", :no_label => true %>
<!--Added by young-->
<%= javascript_tag do %>
observeAutocompleteField('issue_subject',
@ -21,11 +23,9 @@
<% if @issue.safe_attribute? 'description' %>
<label class="label">&nbsp;描述&nbsp;&nbsp;:&nbsp;</label>
<%= f.label_for_field :description, :required => @issue.required_attribute?('description'), :no_label => true, :class => "label" %>
<%#= link_to_function image_tag('edit.png'), '$(this).hide(); $("#issue_description_and_toolbar").show()' unless @issue.new_record? %>
<%#= content_tag 'span', :id => "issue_description_and_toolbar" do %>
<%= f.kindeditor :description,:editor_id => "issue_desc_editor", :width=>'85%', :height =>159, :resizeType => 0, :no_label => true, at_id: @project.id, at_type: @project.class.to_s %>
<%# end %>
<%#= wikitoolbar_for 'issue_description' %>
<div id="issue_description" class="new_li">
<textarea cols="40" name="issue[description]" rows="20" style="display:none"><%= @issue.description %></textarea>
</div>
<% end %>
</li>
@ -164,6 +164,10 @@
</ul>
<% end %>
<script>
var placeholder = "";
var imageUrl = "<%= upload_with_markdown_path(:container_id => @issue.id, :container_type => 'IssueImage') %>";
// 创建editorMd
var description_editormd = create_editorMD("issue_description", '85%', 300, placeholder, imageUrl);
function change_assigned_tip() {
if( document.getElementById('issue_assigned_to_id').options[document.getElementById('issue_assigned_to_id').selectedIndex].value == 0 ){
@ -199,7 +203,7 @@
str += ",";
}
}
issue_desc_editor.sync();
//issue_desc_editor.sync();
$('#commit_ids').val(str);
$('#issue-form').submit();
}

View File

@ -1,5 +1,5 @@
<% if issue.attachments.any? %>
<div class="pro_pic_box mb10">
<div class="ml60 mb10">
<a href="javascript:void(0)" class="link_img fl">
<!--显示附件、图片-->
<%= link_to_attachment_project issue, :thumbnails => true %>

View File

@ -73,9 +73,9 @@
<span class="fl mr5"><%= activity.journals.count %></span>
<% end %>
<div class="undis" style="position: absolute; <%= activity.journals.count > 0 ? 'top:25px;' : 'top:7px' %>">
<%= link_to "", edit_issue_path(activity.id), :class => 'sy_icons_edit fl mt15', :style => "margin-top:25px;", :accesskey => accesskey(:edit) if activity.editable? && User.current.allowed_to?(:edit_issues, activity.project) %>
<%= link_to "", edit_issue_path(activity.id), :class => 'sy_icons_edit fl', :style => "margin-top:25px;", :accesskey => accesskey(:edit) if activity.editable? && User.current.allowed_to?(:edit_issues, activity.project) %>
<% if !defined?(project_id) && !defined?(user_id) %>
<a herf="javascript:void(0)" onclick="delete_confirm_box_3('<%= issue_path(activity.id) %>','你确定删除选中的问题吗?');" class="fl mt8 color-grey-7f font-16 eud-pointer"><i class="fa fa-close"></i></a>
<a herf="javascript:void(0)" onclick="delete_confirm_box_3('<%= issue_path(activity.id) %>','你确定删除选中的问题吗?');" class="fl ml5 mt8 color-grey-7f font-16 eud-pointer"><i class="fa fa-close"></i></a>
<%#= link_to "", issue_path(activity.id), :data => {:confirm => issues_destroy_confirmation_message(activity)}, :method => :delete, :class => 'sy_icons_del fl mt15', :style => "margin-top:25px;" if User.current.allowed_to?(:delete_issues, activity.project) %>
<% elsif defined?(project_id) %>
<%= link_to "", issue_path(activity.id, :page_classify => "project_page", :page_id => project_id), :data => {:confirm => issues_destroy_confirmation_message(activity)}, :method => :delete, :class => 'sy_icons_del fl mt15' if User.current.allowed_to?(:delete_issues, activity.project) %>

View File

@ -1,6 +1,3 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: true, prettify: false, init_activity: false) %>
<% end %>
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");

View File

@ -22,7 +22,6 @@
<%= render :partial => 'issues/detail'%>
</div>
</div>
<!--problem_main end-->
<div style="clear: both;"></div>
<div class="homepagePostReply set_Reply_detail">
@ -53,7 +52,7 @@
<li class="clear">
<span class="pro_new_conbox_leftspan fl">指派给</span>
<span class="pro_new_conbox_rightspan fl ml10">
<a href="<%= @issue.assigned_to_id.nil? ? "javascript:void(0)" : user_path(@issue.assigned_to) %>" class="color-orange05" ><%= @issue.assigned_to ? @issue.assigned_to.show_name : "--" %></a></span>
<a href="<%= @issue.assigned_to_id.nil? ? "javascript:void(0)" : user_path(@issue.assigned_to) %>" class="color-orange05" ><%= @issue.assigned_to ? @issue.assigned_to.show_name : "--" %></a></span>
</li>
<% end %>
<% unless @issue.disabled_core_fields.include?('fixed_version_id') %>

View File

@ -1,37 +1,16 @@
<div class="newFooter edu-txt-center"> <!-- 底部导航栏 -->
<div class="footerUpper">
<div class="edu-txt-left educontent">
<div class="inline">
<ul class="fl footerUl">
<li class="ulMain">资讯社区</li>
<li>行业动态</li>
<li>技术标准</li>
<li>行业报告</li>
<li>产品方案</li>
<li>竞赛培训</li>
</ul>
<ul class="fl footerUl">
<li class="ulMain">开发社区</li>
<li>开源项目</li>
<li>开源资讯</li>
<li>技术问答</li>
</ul>
<ul class="fl footerUl">
<li class="ulMain">开发者云</li>
</ul>
<ul class="fl footerUl">
<li class="ulMain">关于我们</li>
<li>业务概况</li>
<li>联系我们</li>
<li>成员单位</li>
<li>加入联盟</li>
</ul>
<img src="/images/trustieForge/ewm.png" class="fl mr100" width="110px"/>
<img src="/images/trustieForge/Forgelogo.png" class="fl" width="110px"/>
</div>
</div>
</div>
<div class="footerbottom">
<div class="edu-txt-left educontent font-16">CopyRight 2007-2017,国防科技大学湘ICP备09019772</div>
<div class="footerbottom edu-txt-center"><p class="mb10">
<% unless PublicProperty.where(:property => "Tel").first.try(:value).blank? %>
<span class="mr15"><i class="iconfont icon-weibiaoti- font-16"></i> <%= PublicProperty.where(:property => "Tel").first.try(:value) %></span>
<% end %>
<% unless PublicProperty.where(:property => "Email").first.try(:value).blank? %>
<span class="mr15"><i class="iconfont icon-mail font-16"></i> <%= PublicProperty.where(:property => "Email").first.try(:value) %></span>
<% end %>
<% unless PublicProperty.where(:property => "Address").first.try(:value).blank? %>
<span class="mr15"><i class="iconfont icon-xiazai18 font-16"></i> <%= PublicProperty.where(:property => "Address").first.try(:value) %></span>
<% end %>
</p>
<p>版权所有:<%= PublicProperty.where(:property => "Copyright").first.try(:value) %>&nbsp;&nbsp;&nbsp;&nbsp;Powerd by <span class="color-grey-71">Trustie</span></p>
</div>
</div>

View File

@ -1,42 +1,43 @@
<div class="educontent clearfix">
<%= link_to image_tag("/images/trustieForge/Forgelogo.png", alt:"", class:"logoimg"), home_path %>
<div class="clearfix pl40 pr40 df">
<%= link_to image_tag("/images/trustieForge/Forgelogo", alt:"", class:"logoimg forge_logo"), home_path %>
<div class="head-nav pr">
<ul id="header-nav">
<li><%= link_to "首页", home_path %></li>
<!--<li><a href="<%#= welcome_about_path %>">联盟介绍</a></li>
<li><a href="<%#= welcome_service_path %>">联盟服务</a></li>
<li><a href="<%#= welcome_join_path %>">加入联盟</a></li>-->
<li><%= link_to "开源项目", projects_path %></li>
<li><%= link_to "发现", forums_path %></li>
<li><%= link_to "论坛交流", forums_path %></li>
<!--<li><a href="<%#= welcome_contact_path %>">联系我们</a></li>-->
</ul>
</div>
<% if User.current.logged? %>
<div class="fr edu-menu-panel ml15" style="height:60px;">
<%= link_to (image_tag(url_to_avatar(User.current), :width =>"34", :height => "34", :class => "radius mt13", :nhname => "avatar_image", :alt=>"头像", :id => "nh_user_logo")), user_path(User.current),:class => "fl" %>
<ul class="edu-menu-list" style="top:60px;">
<span class="border-Bgrey-eb currentName"><%= User.current.show_name %></span>
<li><%= link_to '我的项目', user_path(User.current) %></li>
<li><%= link_to '我的消息', user_tidings_user_path(User.current) %></li>
<li><%= link_to '账号安全', my_account_path %></li>
<li class="border-Tgrey-eb"><%= link_to '退出', signout_path %></li>
</ul>
</div>
<% else %>
<div class="font-15 fr mt15 ml15">
<%= link_to '登录', signin_path, :class => "mr5 color-dark" %>
<em class="vertical-line"></em>
<%= link_to '注册', user_join_path, :class => "ml5 color-dark" %>
</div>
<% end %>
<div class="fr head-right">
<% if false %>
<div class="posi-search fl mt16 mr20" id="posi-search">
<div class="search-all clearfix">
<div class="fl edu-menu-panel" id="headSearchCondition">
<span class="searchCondition"><font>项目</font><i class="iconfont icon-xiajiantou ml3 font-12"></i></span>
<ul class="edu-menu-list">
<li><a href="javascript:void(0)" data-remote="true">项目</a></li>
<li><a href="javascript:void(0)" data-remote="true">帖子</a></li>
</ul>
<input type="hidden" id="search_type" value="1">
</div>
<input type="text" class="search-input fl" id="search-input" name="search_keyword" placeholder="搜索您想要的"/>
<a href="javascript:void(0)" class="search-icon fl" id="header_keyword_search">
<i class="iconfont icon-sousuo fl"></i>
</a>
</div>
</div>
<% end %>
<% if User.current.logged? %>
<div href="javascript:void(0)" class="fl edu-menu-panel headIcon">
<a href="<%= new_project_path %>"><i class="iconfont icon-xinjian color-grey-8" data-tip-down="新建项目"></i></a>
<i class="iconfont icon-xinjian color-grey-8"></i>
<ul class="edu-menu-list" style="top: 60px;">
<li><a href="<%= new_project_path %>">新建项目</a></li>
<li><a href="<%= new_forum_path %>">新建帖子</a></li>
</ul>
</div>
<div class="fl edu-menu-panel headIcon">
<a href="<%= applied_join_project_path %>" data-remote="true"><i class="iconfont icon-tianjiafangda color-grey-8" data-tip-down="加入项目"></i></a>
@ -58,13 +59,35 @@
</div>
<% else %>
<div href="javascript:void(0)" class="fl edu-menu-panel headIcon">
<a href="<%= signin_path %>"><i class="iconfont icon-xinjian color-grey-8" data-tip-down="新建项目"></i></a>
<i class="iconfont icon-xinjian color-grey-8"></i>
<ul class="edu-menu-list" style="top: 60px;">
<li><a href="<%= new_project_path %>">新建项目</a></li>
<li><a href="<%= new_forum_path %>">新建帖子</a></li>
</ul>
</div>
<div class="fl edu-menu-panel headIcon">
<a href="<%= signin_path %>"><i class="iconfont icon-tianjiafangda color-grey-8" data-tip-down="加入项目"></i></a>
</div>
<% end %>
</div>
<% if User.current.logged? %>
<div class="fr edu-menu-panel ml15" style="height:60px;">
<%= link_to (image_tag(url_to_avatar(User.current), :width =>"34", :height => "34", :class => "radius mt13", :nhname => "avatar_image", :alt=>"头像", :id => "nh_user_logo")), user_path(User.current),:class => "fl" %>
<ul class="edu-menu-list" style="top:60px;">
<span class="border-Bgrey-eb currentName"><%= User.current.show_name %></span>
<li><%= link_to '我的项目', user_path(User.current) %></li>
<li><%= link_to '我的消息', user_tidings_user_path(User.current) %></li>
<li><%= link_to '账号安全', my_account_path %></li>
<li class="border-Tgrey-eb"><%= link_to '退出', signout_path %></li>
</ul>
</div>
<% else %>
<div class="font-15 fr mt15 ml15">
<%= link_to '登录', signin_path, :class => "mr5 color-dark" %>
<em class="vertical-line"></em>
<%= link_to '注册', user_join_path, :class => "ml5 color-dark" %>
</div>
<% end %>
</div>
<script>
@ -73,22 +96,29 @@
document.getElementById('nHeader').style.left=sl+'px';
};
$(function() {
var $active = $("#header-nav").children("li");
<% if params[:controller] == 'welcome' %>
<% if params[:action] == "index" %>
$active.eq(0).addClass("active");
<% elsif params[:action] == 'about' %>
$active.eq(1).addClass("active");
<% elsif params[:action] == 'service' %>
$active.eq(2).addClass("active");
<% elsif params[:action] == 'join' %>
$active.eq(3).addClass("active");
<% elsif params[:action] == 'contact' %>
$active.eq(6).addClass("active");
<% end %>
<% elsif params[:controller] == 'projects' %>
$active.eq(4).addClass("active");
<% elsif params[:controller] == 'forums' %>
$active.eq(5).addClass("active");
<% end %>
// 如果是搜索的进来 保留搜索内容
<% if !@search.blank? && params[:action] == "search_projects" %>
var search = HtmlUtil.htmlDecode("<%= @search %>");
$("input[name='search_keyword']").val(search);
<% end %>
<% if params[:action] == "index" %>
<% case params[:controller] %>
<% when "welcome" %>
$("#header-nav").children("li").eq(0).addClass("active");
<% when "projects" %>
$("#header-nav").children("li").eq(1).addClass("active");
<% when "forums" %>
$("#header-nav").children("li").eq(2).addClass("active");
<% end %>
<% end %>
<%# if !@search.blank? && params[:action] == "search_projects" %>
// var search = HtmlUtil.htmlDecode("<%#= @search %>");
// $("input[name='search_keyword']").val(search);
<%# end %>
<!--<%# if (User.current.certification == 1 || params[:controller] != "welcome") && Time.now < Time.local(2018, 6, 12, 2, 0) && User.current.user_system_notices.where(:notice_type => 2).count == 0 || @noticed_update %>-->
// var htmlvalue = "<%#= escape_javascript(render :partial => 'account/user_update_notice')%>";
@ -97,4 +127,27 @@
<!--<%# end %>-->
});
/*---------------------头部切换搜索条件 begin-------------------------*/
$("#headSearchCondition .edu-menu-list li").click(function(){
var value=$(this).find('a').html().trim();
$("#headSearchCondition").find("font").html(value);
$("#headSearchCondition .edu-menu-list").hide();
switch (value){
case '项目':
$("#search_type").val('1');
break;
case '帖子':
$("#search_type").val('2');
break;
}
});
$("#headSearchCondition").hover(function() {
$("#headSearchCondition .edu-menu-list").show();
},function(){
$("#headSearchCondition .edu-menu-list").hide();
})
/*---------------------头部切换搜索条件 end-------------------------*/
</script>

View File

@ -0,0 +1,71 @@
<% @nav_dispaly_home_path_label = 1
@nav_dispaly_main_course_label = 1
@nav_dispaly_main_project_label = 1
@nav_dispaly_main_contest_label = 1 %>
<% @nav_dispaly_forum_label = 1%>
<!DOCTYPE html>
<html lang="<%= current_language %>">
<head>
<meta charset="utf-8" />
<title><%= h html_title %></title>
<meta name="description" content="<%= Redmine::Info.app_name %>" />
<meta name="keywords" content="issue,bug,tracker" />
<%= csrf_meta_tag %>
<%= favicon %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application','project', 'educoder/edu-main', 'educoder/edu-all', 'css/font-awesome', 'educoder/magic-check', :media => 'all' %>
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
<%= javascript_heads %>
<%= heads_for_theme %>
<%= call_hook :view_layouts_base_html_head %>
<!-- page specific tags -->
<%= yield :header_tags -%>
<!-- MathJax的配置 -->
<script type="text/javascript"
src="/javascripts/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</head>
<body class="<%= h body_css_classes %>">
<div id="wrapper">
<div id="wrapper2">
<div id="wrapper3">
<%= render :partial => 'layouts/header'%>
<div style="margin-top: 10px;">
<div id="main">
<div id="sidebar">
<%= yield :sidebar %>
<%= view_layouts_base_sidebar_hook_response %>
</div>
<div id="content" style="padding-top: 0px;">
<%= render_flash_messages %>
<%= yield %>
<%= call_hook :view_layouts_base_content %>
<div style="clear:both;"></div>
</div>
<%= render :partial => 'layouts/footer'%>
</div>
</div>
</div>
<div id="ajax-indicator" style="display:none;">
<span><%= l(:label_loading) %></span>
</div>
<div id="ajax-modal" style="display:none;"></div>
<div id="footer">
<div class="bgl">
<div class="bgr">
Powered by <%= link_to Redmine::Info.app_name, Redmine::Info.url %> &copy; 2006-2013 Jean-Philippe Lang
</div>
</div>
</div>
</div>
</div>
<%= call_hook :view_layouts_base_body_bottom %>
</body>
</html>
<script>
$("#sidebar ul").css({"marginLeft":"40px","marginTop":"1em","padding":"0"});
$("#sidebar a").css({"color":"#169","fontSize":"12px","lineHeight":"1.5"});
$("#sidebar a").mouseover(function(){$(this).css({"color":"#fff","backgroundColor":"#169"});});
$("#sidebar a").mouseout(function(){$(this).css({"color":"#169","backgroundColor":"#fff"});});
</script>

View File

@ -10,7 +10,7 @@
<%= favicon %>
<%= javascript_heads %>
<%= heads_for_theme %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'css/edu-common', 'css/edu-public', 'css/font-awesome', 'css/edu-popup', 'css/magic-check', "css/edu-admin", "css/moduel", "css/taskstyle",'educoder/edu-main','educoder/edu-all','//at.alicdn.com/t/font_653600_8n6u07l5e2joflxr.css' %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'css/edu-common', 'css/edu-public', 'css/font-awesome', 'css/edu-popup', 'educoder/magic-check', "css/edu-admin", "css/moduel", "css/taskstyle",'educoder/edu-main','educoder/edu-all' %>
<%= javascript_include_tag "edu/application",'edu/base_edu','edu/account', 'baiduTemplate', 'jquery.datetimepicker.js', "edu/management", 'educoder/edu_application' %>
<%= call_hook :view_layouts_base_html_head %>
<%= yield :header_tags -%>
@ -30,36 +30,12 @@
</p>
<ul class="edu-admin-nav clearfix bor-grey-e">
<!--<li class="fl edu-admin-nav-li"><a href="javascript:void(0);" class="edu-admin-nav-a">主页</a></li>-->
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 2 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">课堂+</a>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 1 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">项目</a>
<ul class="edu-admin-nav-inner edu-absolute">
<li><%= link_to "课程列表", classroom_managements_path %></li>
<li><%= link_to "课堂列表", classroom_classment_managements_path %></li>
<li><%= link_to "实训作业", shixun_task_managements_path%></li>
<li><%= link_to "项目列表", projects_list_managements_path %></li>
</ul>
</li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 3 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">精选实训+</a>
<ul class="edu-admin-nav-inner edu-absolute">
<li><%= link_to "实训列表", shixuns_managements_path %></li>
<li><%= link_to "实训配置列表", shixun_setting_list_managements_path %></li>
<li><%= link_to "已发布的实训", publish_shixuns_managements_path %></li>
<li><%= link_to "已关闭的实训", close_shixuns_managements_path %></li>
<li><%= link_to "镜像管理", mirror_repository_managements_path %></li>
<li><%= link_to "学员实训列表",shixun_member_managements_path %></li>
<li><%= link_to "镜像类别图片",mirror_picture_shixuns_managements_path %></li>
<li><%= link_to "TPI实训列表",myshixuns_managements_path %></li>
<li><%= link_to "TPI性能测试结果",mul_test_managements_path %></li>
<!--<li><%#= link_to "镜像类别图片",mirror_picture_shixuns_path %></li>-->
</ul>
</li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 4 %>" style="width: 100px"><a href="javascript:void(0);" class="edu-admin-nav-a" >实训路径+</a>
<ul class="edu-admin-nav-inner edu-absolute">
<li style="width: 100px"><%= link_to "实训路径列表", class_shixuns_managements_path %></li>
<li style="width: 100px"><%= link_to "实训路径配置", subject_setting_list_managements_path %></li>
<li style="width: 100px"><%= link_to "已发布实训路径", class_publish_shixuns_managements_path %></li>
</ul>
</li>
<li class="fl edu-admin-nav-li"><a href="javascript:void(0);" class="edu-admin-nav-a">竞赛+</a></li>
<li class="fl edu-admin-nav-li edu-position"><a href="javascript:void(0);" class="edu-admin-nav-a">单位</a>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 6 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">单位</a>
<ul class="edu-admin-nav-inner edu-absolute">
<li><%= link_to "单位列表", departments_part_managements_path, :class => "edu-admin-nav-a" %></li>
<li><%= link_to "单位部门列表", departments_managements_path %></li>
@ -68,51 +44,51 @@
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 7 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">用户</a>
<ul class="edu-admin-nav-inner edu-absolute">
<li><%= link_to "用户列表", users_managements_path %></li>
<li><%= link_to "试用授权列表", users_trial_managements_path %></li>
<li><%= link_to "自动授权列表", auto_users_trial_managements_path %></li>
<li><%= link_to "职业信息列表", users_trial_managements_path %></li>
<!--<li><%#= link_to "自动授权列表", auto_users_trial_managements_path %></li>-->
</ul>
</li>
<li class="fl edu-admin-nav-li edu-position"><a href="javascript:void(0);" class="edu-admin-nav-a">消息</a>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 8 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">消息</a>
<ul class="edu-admin-nav-inner edu-absolute">
<li><%= link_to "作业回复",leave_message_managements_path %></li>
<li><%= link_to "实训反馈", shixun_feedback_message_managements_path %></li>
<li><%= link_to "讨论区",messages_list_managements_path %></li>
<li><%= link_to "课堂讨论区",course_messages_list_managements_path %></li>
</ul>
</li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 9 %>">
<%= link_to "评测时间",evaluate_records_managements_path, :class => "edu-admin-nav-a" %>
<!--<ul class="edu-admin-nav-inner edu-absolute">-->
<!--<li><%#= link_to "实训留言", shixun_feedback_managements_path %></li>-->
<!--</ul>-->
</li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 10 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">审批</a>
<ul class="edu-admin-nav-inner">
<li><%= link_to "实名认证", :controller => "managements", :action => "identity_authentication" %></li>
<li><%= link_to "职业认证", :controller => "managements", :action => "professional_authentication" %></li>
<li><%= link_to "试用授权", :controller => "managements", :action => "trial_authorization" %></li>
<!--<li><%#= link_to "试用授权", :controller => "managements", :action => "trial_authorization" %></li>-->
<li><%= link_to "部门审批", depart_managements_path %></li>
<li><%= link_to '单位审批', unit_managements_path %></li>
<li><%= link_to '实训发布', shixun_authorization_managements_path %></li>
<li><%= link_to '实训路径发布', subject_authorization_managements_path %></li>
<!--<li><%#= link_to '实训发布', shixun_authorization_managements_path %></li>
<li><%#= link_to '实训路径发布', subject_authorization_managements_path %></li>-->
</ul>
</li>
<li class="fl edu-admin-nav-li"><a href="javascript:void(0);" class="edu-admin-nav-a">工程认证+</a></li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 12 %>"><a href="javascript:void(0);" class="edu-admin-nav-a" style="border-right:none;">其它</a>
<!--<li class="fl edu-admin-nav-li"><a href="javascript:void(0);" class="edu-admin-nav-a">工程认证+</a></li>-->
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 12 %>"><a href="javascript:void(0);" class="edu-admin-nav-a">门户</a>
<ul class="edu-admin-nav-inner">
<li style="width: 120px"><%= link_to "公共属性", navigationbar_managements_path %></li>
<li style="width: 120px"><%= link_to "贴吧和门户配置", forum_list_managements_path %></li>
<li style="width: 120px"><%= link_to "广告列表", ads_list_managements_path %></li>
</ul>
</li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 13 %>"><a href="javascript:void(0);" class="edu-admin-nav-a" style="border-right:none;">其它</a>
<ul class="edu-admin-nav-inner">
<li style="width: 120px"><%= link_to "过关任务模板", editmd_template_managements_path(:samples_type => "taskPass") %></li>
<li style="width: 120px"><%= link_to "实训简介模板", editmd_template_managements_path(:samples_type => "introduction") %></li>
<li style="width: 120px"><%= link_to "背景知识模板", editmd_template_managements_path(:samples_type => "knowledge") %></li>
<li style="width: 120px"><%= link_to "通用评测模板", codemirror_template_managements_path(:samples_type => "script") %></li>
<li style="width: 120px"><%= link_to "新课导语模板", course_guide_template_managements_path(:samples_type => "courseGuide") %></li>
<li style="width: 120px"><%= link_to "实训评分设置", shixun_quality_score_managements_path() %></li>
<li style="width: 120px"><%= link_to "贴吧类型", forum_list_managements_path %></li>
<!--<li style="width: 120px"><%#= link_to "专业列表",profession_managements_path %></li>
<li style="width: 120px"><%#= link_to "实训适用课程列表", applicable_course_managements_path %></li>-->
<!--<li style="width: 120px"><%#= link_to "实训任务模板", task_pass_template2_managements_path %></li>-->
<li style="width: 120px"><%= link_to "技术体系", label_list_managements_path %></li>
<!--<li style="width: 120px"><%#= link_to "过关任务模板", editmd_template_managements_path(:samples_type => "taskPass") %></li>
<li style="width: 120px"><%#= link_to "实训简介模板", editmd_template_managements_path(:samples_type => "introduction") %></li>
<li style="width: 120px"><%#= link_to "背景知识模板", editmd_template_managements_path(:samples_type => "knowledge") %></li>
<li style="width: 120px"><%#= link_to "通用评测模板", codemirror_template_managements_path(:samples_type => "script") %></li>-->
<!--<li style="width: 120px"><%#= link_to "新课导语模板", course_guide_template_managements_path(:samples_type => "courseGuide") %></li>-->
<!--<li style="width: 120px"><%#= link_to "实训评分设置", shixun_quality_score_managements_path() %></li>-->
<!--<li style="width: 120px"><%#= link_to "贴吧类型", forum_list_managements_path %></li>
<li style="width: 120px"><%#= link_to "技术体系", label_list_managements_path %></li>-->
<!--<li style="width: 120px"><a href="javascript:void(0)">联系我们</a></li>-->
<li style="width: 120px"><a href="<%= help_path() %>">服务协议</a></li>
</ul>
</li>
</ul>

View File

@ -11,7 +11,7 @@
<%= heads_for_theme %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/edu-popup','css/edu-common','educoder/edu-main','educoder/edu-all', "css/edu-public",'css/common','css/structure','scm','css/public', 'css/project','css/popup','repository','css/gantt', 'css/calendar', 'css/moduel', 'css/font-awesome', 'css/taskstyle' ,'css/ketang', 'css/magic-check','//at.alicdn.com/t/font_653600_8n6u07l5e2joflxr.css' %>
<%= javascript_include_tag 'educoder/edu_application' %>
<%= call_hook :view_layouts_base_html_head %>
<%#= call_hook :view_layouts_base_html_head %>
<!-- page specific tags -->
<%= yield :header_tags -%>
</head>
@ -30,7 +30,7 @@
<div id="Container">
<%= render_flash_messages %>
<%= yield %>
<%= call_hook :view_layouts_base_content %>
<%#= call_hook :view_layouts_base_content %>
<div style="clear:both;"></div>
</div>
@ -44,7 +44,7 @@
<div id="ajax-indicator" style="display:none;">
<span><%= l(:label_loading) %></span>
</div>
<%= call_hook :view_layouts_base_body_bottom %>
<%#= call_hook :view_layouts_base_body_bottom %>
</div>
</body>
<!-- MathJax的配置 -->

View File

@ -1,55 +0,0 @@
<!DOCTYPE html>
<html lang="<%= current_language %>">
<head>
<meta charset="utf-8" />
<title><%=h html_title %></title>
<meta name="description" content="<%= Redmine::Info.app_name %>" />
<meta name="keywords" content="issue,bug,tracker" />
<%= csrf_meta_tag %>
<%= favicon %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'css/edu-common','educoder/edu-main','educoder/edu-all', "css/edu-public",'application', 'nyan','prettify', 'css/font-awesome', :media => 'all' %>
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
<%= javascript_heads %>
<%= javascript_include_tag "jquery.leanModal.min" ,'prettify','avatars','educoder/edu_application' %>
<%= javascript_include_tag 'seems_rateable/jRating', 'seems_rateable/rateable'%>
<%= heads_for_theme %>
<%= call_hook :view_layouts_base_html_head %>
<!-- page specific tags -->
<%= yield :header_tags -%>
<%= stylesheet_link_tag 'css/common','css/structure','css/public' ,:media => 'all'%>
<!-- MathJax的配置 -->
<script type="text/javascript"
src="/javascripts/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- 配置 在生成的公式图片上去掉Math定义的右键菜单$$ $$ \( \) \[ \] 中的公式给予显示-->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showMathMenu: false,
showMathMenuMSIE: false,
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
</head>
<body onload="prettyPrint();">
<div class="newContainer"> <!-- 页面全部内容 -->
<div class="newHeader">
<div class="cl"></div>
<%= render :partial => "layouts/header" %>
</div>
<div class="newMain clearfix"> <!-- 主提部分 -->
<div class="cl"></div>
<%= render_flash_messages %>
<%= yield %>
<%= call_hook :view_layouts_base_content %>
<div style="clear:both;"></div>
<div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
<div id="ajax-modal" style="display:none;"></div>
</div>
<div class="cl"></div>
<%= render :partial => 'layouts/footer' %>
<div class="cl"></div>
<%= call_hook :view_layouts_base_body_bottom %>
</div>
</body>
</html>

View File

@ -0,0 +1,137 @@
<div class="AdvertisingHeadBox" id="AdvertisingBox">
<div class="AdvertisingHead">
<a href="javascript:void(0)" class="fr user_default_btn edu-blueback-btn ml20 font-18" onClick="addAdvertising()">新增</a>
</div>
<div class="AdvertisingCont">
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed">
<thead>
<tr>
<th>序号</th>
<th>广告图片</th>
<th style="width:400px;">链接</th>
<th style="width:100px;">位置</th>
<th class="eud-pointer">更新时间<i class="fa <%= @sx_order == "desc" ? "fa-long-arrow-down" : "fa-long-arrow-up" %> color-light-green ml5"></i></th>
<th>操作</th>
</tr>
</thead>
<tbody id="tbodyBox">
<% @ads.each_with_index do |ad, index| %>
<tr id="ad_tr_<%= ad.id %>">
<td><%= index + 1 %></td>
<td>
<%= file_field_tag 'avatar[image]',
:id => "upload_img_#{ad.id}",
:style => 'display:none;',
:size => "1",
:multiple => false,
:onchange => 'addInputAvatar(this);',
:data => {
:max_file_size => Setting.authentication_img_max_size.to_i.kilobytes,
:max_file_size_message => l(:error_user_auth_too_big, :max_size => number_to_human_size(Setting.authentication_img_max_size.to_i.kilobytes)),
:max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
:file_type => Redmine::Configuration['pic_types'].to_s,
:type_support_message => l(:error_pic_type),
:upload_path => upload_avatar_path(:format => 'js'),
:description_placeholder => nil ,# l(:label_optional_description)
:source_type => "Advertisement",
:source_id => ad.id,
:is_direct => 1
} %>
<a href="javascript:void(0);" id="object_upload_img_<%= ad.id %>" class="mr10" onclick="$('#upload_img_<%= ad.id %>').click();">
<%= File.exist?(disk_filename_avatar("Advertisement",ad.id)) ? "重新上传" : "上传图片" %>
</a>
<% if File.exist?(disk_filename_avatar("Advertisement",ad.id)) %>
<%= image_tag(url_to_avatar(ad), :class => "w80 h80 ml5 shixun_image_show", :id => "shixun_image_show_#{ad.id}") %>
<% else %>
<img src="" class="w80 h80 ml5 shixun_image_show none" id="shixun_image_show_<%= ad.id %>"/>
<% end %>
</td>
<td>
<input data-type="link_to" name="ad_link_to" data-id="<%= ad.id %>" style="width:350px;" value="<%= ad.link_to %>">
</td>
<td style="width:100px;">
<input data-type="position" name="ad_position" data-id="<%= ad.id %>" style="width:100px; text-align: center;" value="<%= ad.position %>">
</td>
<td class="eud-pointer"><span><%= format_time ad.updated_at %></span></td>
<td>
<% if ad.status != 1 %>
<a href="<%= publish_ads_managements_path(:ad => ad.id) %>" id="publish_ads_<%= ad.id %>" data-remote="true">发布&nbsp;</a>
<% end %>
<a href="javascript:void(0);" onclick="delete_confirm_box_2('<%= delete_ads_managements_path(:ad => ad.id) %>', '是否执行删除操作?')">删除&nbsp;</a>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<%= javascript_include_tag "avatars.js" %>
<script>
$(function(){
var all_images = $(".shixun_image_show");
if (all_images.length>0) {
for (var i=0; i<all_images.length; i++){
if($(all_images[i]).is(":visible")){
var image=$(all_images[i]);
var element = $("<a></a>").attr("href", image.attr('src')+".png");
image.wrap(element);
$(image).parent().colorbox({rel: 'nofollow', close: "关闭", returnFocus: false});
}
}
}
});
$("#AdvertisingBox").on("blur", "input[name='ad_link_to']", function(){
$.post("/managements/add_info_for_ads?ad="+$(this).attr("data-id"),
{"link_to": $(this).val().trim()});
});
$("#AdvertisingBox").on("blur", "input[name='ad_position']", function(){
$.post("/managements/add_info_for_ads?ad="+$(this).attr("data-id"),
{"position": $(this).val().trim()});
});
function addAdvertising(){
if($("#add_new_ad").length == 0){
var html ="<tr id='add_new_ad'>"
+'<td></td>'
+'<td>'
+'<div class="mirror-picture hor-ver-center">'
+'<input type="hidden" value="0"/>'
+'<a href="javascript:void(0);" class="mirror-click hor-ver-center mirror-shade edu-txt-center discuss-lh80 color_white font-14">点击更换</a>'
+'</div>'
+'</td>'
+'<td>'
+'<input style="width:350px;" placeholder="请输入广告链接" id="new_ad_link">'
+'</td>'
+'<td style="width:100px;">'
+'<input style="width:100px;" placeholder="1" id="new_ad_position">'
+'</td>'
+'<td class="eud-pointer">'
+'<span></span>'
+'</td>'
+'<td>'
+'<a href="javascript:void(0);" onclick="submit_new_ad();">保存&nbsp;</a>'
+'<a href="javascript:void(0);" onclick="$("#add_new_ad").remove();">取消&nbsp;</a>'
+'</td>'
+"</tr>";
$("#tbodyBox").append(html);
}
}
function submit_new_ad(){
if ($("#new_ad_link").val().trim() == "") {
$("#new_ad_link").focus();
return;
} else{
$.post("<%= add_homepage_ads_managements_path %>",
{"link_to": $("#new_ad_link").val().trim(), "position": $("#new_ad_position").val().trim()});
}
}
</script>

View File

@ -1,8 +1,5 @@
<div style="width:400px" class="task-popup">
<div class="task-popup-title clearfix ">
<h3 class="fl color-grey mt10 ml5">添加帖子类型</h3>
<a href="javascript:void(0);" class="pop_close"><i class="fa fa-times-circle font-18 link-color-grey fr mt5"></i></a>
</div>
<div class="task-popup-title clearfix ">添加帖子类型</div>
<div class="mt10 ml30">
<span class="fl font-16 color-grey mr10 mt3 ">帖子名称:</span>
<input class="task-height-40 panel-box-sizing fl ml5" type="text" placeholder="请输入帖子名称" style="width: 260px" name="add_department" value="<%= @forum.name %>" />

View File

@ -1,8 +1,5 @@
<div style="width:400px" class="task-popup">
<div class="task-popup-title clearfix ">
<h3 class="fl color-grey mt10 ml5">添加帖子类型</h3>
<a href="javascript:void(0);" class="pop_close"><i class="fa fa-times-circle font-18 link-color-grey fr mt5"></i></a>
</div>
<div class="task-popup-title clearfix ">添加帖子类型</div>
<div class="mt10 ml30">
<span class="fl font-16 color-grey mr10 mt3 ">帖子名称:</span>
<input class="task-height-40 panel-box-sizing fl ml5" type="text" placeholder="请输入帖子名称" style="width: 260px" name="add_department" value="<%= @label.name %>" />

View File

@ -15,7 +15,7 @@
<tr>
<td><%= apply.id %></td>
<td class="edu-txt-left"> <%= apply.name %></td>
<td class="edu-txt-left"> <%= apply.school.name %></td>
<td class="edu-txt-left"> <%= apply.school.try(:name) %></td>
<td><%= apply.user.show_real_name %></td>
<td><%= format_time apply.created_at %></td>
<td class="center">

View File

@ -2,18 +2,17 @@
<thead>
<tr>
<th width="9%">序号</th>
<th width="12%">来源(贴吧ID)</th>
<th width="15%">作者</th>
<th width="18%">时间<i class="fa fa-long-arrow-down %> color-light-green ml5" ></i></th>
<th width="30%" class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">标题</th>
<th>回复数</th>
<th width="5%">首页</th>
</tr>
</thead>
<tbody>
<% @memo.each_with_index do |memo,index| %>
<tr>
<td><%= (@page -1) * @limit +index + 1 %></td>
<td> <%= memo.forum_id %> </td>
<td>
<% if memo.try(:author).try(:realname) == ' '%>
<%= link_to(memo.try(:author), user_path(memo.author)) %>
@ -24,13 +23,21 @@
<td><%= format_time(memo.created_at) %></td>
<td class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
<% if memo.parent_id.nil? || memo.subject.starts_with?('RE:')%>
<%= link_to(memo.subject, forum_memo_path(memo.forum, memo)) %>
<%= link_to(memo.subject, forum_path(memo)) %>
<% else %>
<%= link_to("RE:"+memo.subject, forum_memo_path(memo.forum, memo), :target => "_blank") %>
<%= link_to("RE:"+memo.subject, forum_path(memo), :target => "_blank") %>
<% end %>
</td>
<td>
<%= link_to(memo.replies_count, forum_memo_path(memo.forum, memo)) %>
<%= link_to(memo.replies_count, forum_path(memo)) %>
</td>
<td>
<p class="inline">
<span class="fl">
<input type="checkbox" data-value="<%= memo.id %>" <%= memo.homepage_show ? "checked" : "" %> id="readonly_<%= memo.id %>" class="magic-checkbox">
<label for="readonly_<%= memo.id %>" style="top:-1px">&nbsp;</label>
</span>
</p>
</td>
</tr>
<% end %>
@ -44,3 +51,16 @@
<div class="cl"></div>
</div>
</div>
<script>
$(".magic-checkbox").live("click", function () {
var id = $(this).attr("data-value");
var homepage = $(this).is(":checked") ? 1 : 0;
$.ajax({
url: "<%= memo_homepage_show_managements_path %>",
data: {id: id, homepage: homepage},
success: function (data) {
notice_box(data.message);
}
})
});
</script>

View File

@ -0,0 +1,40 @@
<% @projects.each_with_index do |p, index| %>
<tr>
<td><%= (@page -1) * @limit + index + 1 %></td>
<td><%= p.id %></td>
<td><p class="task-hide" style="max-width: 316px;"><%= p.name %></p></td>
<td><%= p.is_public ? "√" : "" %></td>
<td><%= p.issues.count %></td>
<td><%= p.get_attachments_count %></td>
<td><%= p.get_repository_count %></td>
<td><%= p.get_pull_request_count %></td>
<td><%= p.versions.count %></td>
<td><%= p.member_principals.count %></td>
<td><%= format_time p.created_on %></td>
<td>
<p class="inline">
<span class="fl">
<input type="checkbox" data-value="<%= p.id %>" <%= p.homepage_show ? "checked" : "" %> id="readonly_<%= p.id %>" class="magic-checkbox">
<label for="readonly_<%= p.id %>" style="top:-1px">&nbsp;</label>
</span>
</p>
</td>
<td>
<a href="<%= project_path(p, :type => "management") %>" data-method="delete" data-remote="true">删除</a>
</td>
</tr>
<% end %>
<script>
$(".magic-checkbox").live("click", function () {
var id = $(this).attr("data-value");
var homepage = $(this).is(":checked") ? 1 : 0;
$.ajax({
url: "<%= project_homepage_show_managements_path %>",
data: {id: id, homepage: homepage},
success: function (data) {
notice_box(data.message);
}
})
});
</script>

View File

@ -32,8 +32,8 @@
</td>
<td><%= format_time user.created_on %></td>
<td title="<%= user.last_login_on.blank? ? "--" : (format_time user.last_login_on) %>"><%= user.last_login_on.blank? ? "--" : (format_time user.last_login_on) %></td>
<td><%= link_to user.experience.to_i, user_experience_user_path(user), :target => '_blank' %></td>
<td><%= link_to user.grade.to_i, user_grade_user_path(user), :target => '_blank' %></td>
<td><%= link_to user.experience.to_i, 'javascript:void(0)', :target => '_blank' %></td>
<td><%= link_to user.grade.to_i,'javascript:void(0)', :target => '_blank' %></td>
<td>
<!--<a href="<%#= update_user_status_managements_path(:status => user.status, :page => params[:page]) %>" class="mr10 link-color-blue" id="lock_user"><%#= user.status == 3 ? "解锁" : "锁定" %></a>-->
<%= update_status_link(user) %>

View File

@ -13,9 +13,11 @@
<th>单位</th>
<th>子单位</th>
<th class="eud-pointer">最后登录时间<i class="fa fa-long-arrow-down color-light-green ml5"></i></th>
<% if false %>
<th>试用状态</th>
<th>&nbsp;T&nbsp;</th>
<th>&nbsp;E&nbsp;</th>
<% end %>
</tr>
</thead>
<tbody>
@ -40,6 +42,7 @@
<td ><span class="edu-txt-w140 task-hide2" title="<%= user.try(:user_extensions).try(:school).try(:name) %>"><%= user.try(:user_extensions).try(:school).try(:name).blank? ? "--" : user.try(:user_extensions).try(:school) %></span></td>
<td ><span class="edu-txt-w140 task-hide2"><%= user.try(:user_extensions).department ? user.try(:user_extensions).try(:department).try(:name).to_s : '--' %></span></td>
<td><%= user.last_login_on.blank? ? "--" : (format_time user.last_login_on) %></td>
<% if false %>
<td><%= identity_authentication_status(user) %></td>
<td class="homepage_teacher">
<input type="checkbox" name="homepage_show" value="<%= user.id %>" <%= user.homepage_teacher ? "checked" : "" %> class="ml-3 mr5 magic-checkbox" id="join_teacher_homepage_<%= user.id %>">
@ -49,6 +52,7 @@
<input type="checkbox" name="homepage_show" value="<%= user.id %>" <%= user.homepage_engineer ? "checked" : "" %> class="ml-3 mr5 magic-checkbox" id="join_engineer_homepage_<%= user.id %>">
<label style="top:-14px;" class="ml20" for="join_engineer_homepage_<%= user.id %>"></label>
</td>
<% end %>
</tr>
<% end %>
</tbody>

View File

@ -0,0 +1 @@
<%= render :partial => "advertising_list" %>

View File

@ -0,0 +1 @@
$("#AdvertisingBox").replaceWith("<%= j(render :partial => 'managements/advertising_list') %>")

View File

@ -0,0 +1 @@
$("#ad_tr_<%= @ads.id %>").remove();

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