user score merge

exceptionHandle
baiyu 11 years ago
commit f0b497e455

1
.gitignore vendored

@ -1,4 +1,5 @@
/.project
/.idea
/.bundle
/config/database.yml

@ -1,5 +1,11 @@
source 'https://rubygems.org'
unless RUBY_PLATFORM =~ /w32/
# unix-like only
gem 'iconv'
gem 'rubyzip'
gem 'zip-zip'
end
gem "rails", "3.2.13"
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

@ -150,6 +150,7 @@ class AttachmentsController < ApplicationController
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
@ -174,7 +175,7 @@ private
@attachment = Attachment.find(params[:id])
# Show 404 if the filename in the url is wrong
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo'
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication'
@project = @attachment.project
end
rescue ActiveRecord::RecordNotFound

@ -472,22 +472,22 @@ class BidsController < ApplicationController
# added by bai type ==1 需求type==2 竞赛, type==3 作业
if @bid.reward_type == 1
flash[:notice] = l(:label_bidding_succeed)
flash.now[:notice] = l(:label_bidding_succeed)
elsif @bid.reward_type == 2
flash[:notice] = l(:label_bidding_contest_succeed)
flash.now[:notice] = l(:label_bidding_contest_succeed)
else @bid.reward_type == 3
flash[:notice] = l(:label_bidding_homework_succeed)
flash.now[:notice] = l(:label_bidding_homework_succeed)
end
# end
end
else
if @bid.reward_type == 3
flash[:error] = l(:label_bidding_homework_fail)
flash.now[:error] = l(:label_bidding_homework_fail)
else
flash[:error] = l(:label_bidding_fail)
flash.now[:error] = l(:label_bidding_fail)
end
end
@bidding_project = @bid.biding_projects

File diff suppressed because it is too large Load Diff

@ -33,8 +33,8 @@ class FilesController < ApplicationController
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [ Project.includes(:attachments).reorder("attachments.created_on DESC").find(@project.id)] #modify by Long Jun
@containers += @project.versions.includes(:attachments).reorder("created_on DESC").all.sort
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
if @project.project_type == 1
render :layout => 'base_courses'

@ -11,6 +11,42 @@ class ForumsController < ApplicationController
include SortHelper
PageLimit = 20
def create_memo
@memo = Memo.new(params[:memo])
@memo.forum_id = @forum.id
@memo.author_id = User.current.id
@memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
respond_to do |format|
if @memo.save
format.html { redirect_to (forum_memo_path(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))), notice: "#{l :label_memo_create_succ}" }
format.json { render json: @memo, status: :created, location: @memo }
else
sort_init 'updated_at', 'desc'
sort_update 'created_at' => "#{Memo.table_name}.created_at",
'replies' => "#{Memo.table_name}.replies_count",
'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
@topic_count = @forum.topics.count
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
@memos = @forum.topics.
reorder("#{Memo.table_name}.sticky DESC").
includes(:last_reply).
limit(@topic_pages.per_page).
offset(@topic_pages.offset).
order(sort_clause).
preload(:author, {:last_reply => :author}).
all
flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
# back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id)
format.html { render action: :show, layout: 'base_forums' }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
format.json { render json: @memo.errors, status: :unprocessable_entity }
end
end
end
def index
@offset, @limit = api_offset_and_limit({:limit => 10})

@ -47,7 +47,30 @@ class MemosController < ApplicationController
else
flash[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
# back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id)
format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
pre_count = REPLIES_PER_PAGE
@memo_new = @memo.dup
@memo = @memo.root # 取出楼主防止输入帖子id让回复作为主贴显示
@memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
page = params[:page]
if params[:r] && page.nil?
offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
page = 1 + offset / pre_count
else
end
@reply_count = @memo.children.count
@reply_pages = Paginator.new @reply_count, pre_count, page
@replies = @memo.children.
includes(:author, :attachments).
reorder("#{Memo.table_name}.created_at ASC").
limit(@reply_pages.per_page).
offset(@reply_pages.offset).
all
format.html { render action: :show }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
# format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
format.json { render json: @memo.errors, status: :unprocessable_entity }
end
end
@ -76,7 +99,7 @@ class MemosController < ApplicationController
offset(@reply_pages.offset).
all
@mome_new = Memo.new
@memo_new = Memo.new
# @memo = Memo.find_by_id(params[:id])

@ -87,7 +87,7 @@ class MyController < ApplicationController
se = UserExtensions.new
se.user_id = @user.id
if params[:occupation]
se.occupation = params[:occupation]
se.school_id = params[:occupation]
end
se.gender = params[:gender]
@ -109,7 +109,7 @@ class MyController < ApplicationController
else
se = @user.user_extensions
if params[:occupation]
se.occupation = params[:occupation]
se.school_id = params[:occupation]
end
se.gender = params[:gender]

@ -69,6 +69,8 @@ class PraiseTreadController < ApplicationController
@obj = Project.find_by_id(id)
when 'Bid'
@obj = Bid.find_by_id(id)
when 'Contest'
@obj = Contest.find_by_id(id)
end
return @obj
end

@ -68,6 +68,8 @@ class ProjectsController < ApplicationController
helper :bids
include BidsHelper
helper :contests
include ContestsHelper
helper :sort
include SortHelper
helper :custom_fields
@ -218,8 +220,10 @@ class ProjectsController < ApplicationController
def search
#modified by nie
@projects = Project.visible
@projects = @projects.visible.where('project_type = ?', params[:project_type]).like(params[:name]) if params[:name].present?
project_type = params[:project_type]
projects_all = (project_type.eql? Project::ProjectType_project) ? Project.project_entities : Project.course_entities
@projects = projects_all.visible
@projects = @projects.visible.like(params[:name]) if params[:name].present?
@offset, @limit = api_offset_and_limit({:limit => 10})
@project_count = @projects.visible.count
@project_pages = Paginator.new @project_count, @limit, params['page']
@ -346,7 +350,7 @@ class ProjectsController < ApplicationController
end
def new
@project_type = params[:project_type]
@project_type = params[:project_type] ||= params[:course]
@issue_custom_fields = IssueCustomField.sorted.all
@trackers = Tracker.sorted.all
@ -360,9 +364,9 @@ class ProjectsController < ApplicationController
@course_tag = params[:course]
@course = Course.new
@course.safe_attributes = params[:course]
else
render_404
return -1
else # default Project
@project = Project.new
@project.safe_attributes = params[:project]
end
render :layout => 'base'
end
@ -388,7 +392,7 @@ class ProjectsController < ApplicationController
# added by bai
@course.term = params[:term]
@course.time = params[:time]
@course.school_id = params[:school]
@course.school_id = params[:occupation]
@course.setup_time = params[:setup_time]
@course.endup_time = params[:endup_time]
@course.class_period = params[:class_period]
@ -567,6 +571,7 @@ class ProjectsController < ApplicationController
"show_messages" => true,
"show_news" => true,
"show_bids" => true,
"show_contests" => true,
"show_journals_for_messages" => true
}
@date_to ||= Date.today + 1
@ -849,8 +854,7 @@ class ProjectsController < ApplicationController
def select_project_layout
project = Project.find_by_id(params[:id])
project ||= @project
project ||= @course
project ||= @project ||= @course ||= params[:course] ||= params[:project_type]
(project.try(:project_type) == Project::ProjectType_project) ? 'base_projects' : 'base_courses'
end

@ -1,2 +1,15 @@
class SchoolController < ApplicationController
def get_options
@school = School.where("province = ?", params[:province])
p = params[:province]
##@school = School.all
options = ""
@school.each do |s|
options << "<option value=#{s.id}>#{s.name}</option>"
end
render :text => options
end
end

@ -0,0 +1,194 @@
class SoftapplicationsController < ApplicationController
# GET /softapplications
# GET /softapplications.json
def index
@softapplications = Softapplication.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @softapplications }
end
end
# GET /softapplications/1
# GET /softapplications/1.json
def show
@softapplication = Softapplication.find(params[:id])
@jours = @softapplication.journals_for_messages.order('created_on DESC')
@image_results = []
@softapplication.attachments.each do |f|
f.image? ? @image_results << f : @image_results
end
@app_items = []
@softapplication.attachments.each do |f|
f.pack? ? @app_items << f : @app_items
end
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@state = false
respond_to do |format|
format.html # show.html.erb
format.json { render json: @softapplication }
end
end
# GET /softapplications/new
# GET /softapplications/new.json
def new
@softapplication = Softapplication.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @softapplication }
end
end
# GET /softapplications/1/edit
def edit
@softapplication = Softapplication.find(params[:id])
end
# POST /softapplications
# POST /softapplications.json
def create
@softapplication = Softapplication.new(params[:softapplication])
@softapplication.user = User.current
@softapplication.save_attachments(params[:attachments])
respond_to do |format|
if @softapplication.save
format.html { redirect_to @softapplication, notice: 'Softapplication was successfully created.' }
format.json { render json: @softapplication, status: :created, location: @softapplication }
else
format.html { render action: "new" }
format.json { render json: @softapplication.errors, status: :unprocessable_entity }
end
end
end
# PUT /softapplications/1
# PUT /softapplications/1.json
def update
@softapplication = Softapplication.find(params[:id])
respond_to do |format|
if @softapplication.update_attributes(params[:softapplication])
format.html { redirect_to @softapplication, notice: 'Softapplication was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @softapplication.errors, status: :unprocessable_entity }
end
end
end
def add_attach
@softapplication = Softapplication.find(params[:id])
@softapplication.save_attachments(params[:attachments])
end
# DELETE /softapplications/1
# DELETE /softapplications/1.json
def destroy
@softapplication = Softapplication.find(params[:id])
@softapplication.destroy
respond_to do |format|
format.html { redirect_to softapplications_url }
format.json { head :no_content }
end
end
#应用评价涉及到的方法
def new_message
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
if @jour
user = @jour.user
text = @jour.notes
else
user = @softapplication.user
text = @softapplication.description
end
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
@content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> "
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
@id = user.id
rescue ActiveRecord::RecordNotFound
render_404
end
#新建评价
def create_message
if params[:softapplication_message][:message].size>0
if params[:reference_content]
message = params[:softapplication_message][:message] + "\n" + params[:reference_content]
else
message = params[:softapplication_message][:message]
end
refer_user_id = params[:softapplication_message][:reference_user_id].to_i
@softapplication = Softapplication.find(params[:id])
@softapplication.add_jour(User.current, message, refer_user_id)
end
@user = @softapplication.user
@jours = @softapplication.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
#@softapplication.set_commit(@feedback_count)
respond_to do |format|
format.js
end
end
##删除评价
def destroy_message
@user = @softapplication.user
if User.current.admin? || User.current.id == @user.id
JournalsForMessage.delete_message(params[:object_id])
end
@jours = @softapplication.journals_for_messages.reverse
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@softapplication.set_commit(@feedback_count)
respond_to do |format|
format.js
end
end
#
def more
@jour = @softapplication.journals_for_messages
@jour.each_with_index {|j,i| j.indice = i+1}
@state = true
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
end
end
#
def back
@jour = @softapplication.journals_for_messages
@jour.each_with_index {|j,i| j.indice = i+1}
@state = false
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
end
end
end

@ -11,6 +11,7 @@ class TagsController < ApplicationController
include BidsHelper
include ForumsHelper
include AttachmentsHelper
include ContestsHelper
include ActsAsTaggableOn::TagsHelper
helper :projects
include TagsHelper
@ -30,7 +31,7 @@ class TagsController < ApplicationController
# 最后是2个过滤何种数据显示结果的控制参数params[:obj_id],params[:object_falg]
# 0代表删除tag 1代表增加tag
def index
@obj_id = params[:obj_id]
@obj_flag = params[:object_flag]
@ -44,28 +45,29 @@ class TagsController < ApplicationController
@tag = params[:tag]
@selected_tags = params[:current_selected_tags]
@selected_tags = @selected_tags.nil? ? Array.new : @selected_tags
case @do_what
when '0' then
@selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop
@selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop
when '1' then
# 判断是否已存在该tag 主要用来处理分页的情况
unless @selected_tags.include? @tag
@selected_tags << @tag
end
# 判断是否已存在该tag 主要用来处理分页的情况
unless @selected_tags.include? @tag
@selected_tags << @tag
end
end
end
@users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,
@users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,@contests_tags_num,
@forum_tags_num, @attachments_tags_num = get_tags_size
# 获取搜索结果
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@issues_results,
@bids_results,
@forums_results,
@attachments_results = refresh_results(@obj_id,@obj_flag,@selected_tags)
@attachments_results,
@contests_tags = refresh_results(@obj_id,@obj_flag,@selected_tags)
# 这里是做tag推荐用的 用来生产推荐的tags
unless @obj.nil?
@ -74,13 +76,13 @@ class TagsController < ApplicationController
# @selected_tags.each do |i|
# @tags.delete(i)
# end
@related_tags = @tags
@related_tags = @tags
else
return
end
end
# 增加已选的tag
def add_tag
@tag = params[:tag]
@ -90,11 +92,13 @@ class TagsController < ApplicationController
$related_tags.delete(@tag)
# 获取搜索结果
@obj,@obj_pages,@users_results,
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@issues_results,
@bids_results,
@forums_results = refresh_results(@obj_id,@show_flag)
@forums_results,
@attachments_results,
@contests_results = refresh_results(@obj_id,@show_flag)
end
# 删除已选tag
@ -110,13 +114,15 @@ class TagsController < ApplicationController
@projects_results,
@issues_results,
@bids_results,
@forums_results = refresh_results(@obj_id,@show_flag)
@forums_results,
@attachments_results,
@contests_results = refresh_results(@obj_id,@show_flag)
end
def show_all
@tags = ActsAsTaggableOn::Tag.find(:all)
@tags = ActsAsTaggableOn::Tag.find(:all)
end
# 完全从数据库删除tag
# 这种删除方式是针对 印有该 tag所有对象来做删除的
# 这样是从整个系统数据库中把该tag删除了
@ -148,24 +154,24 @@ class TagsController < ApplicationController
# if can_remove_tag?(User.current,@taggable_id,@taggable_type)
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type)
unless @taggings.nil?
@taggings.delete
end
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type)
unless @taggings.nil?
@taggings.delete
end
# 是否还有其他记录 引用了 tag_id
@tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id)
@tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id)
# 如果taggings表中记录已经不存在 那么检查tags表 作删除动作
if @tagging.nil?
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
@tag.delete unless @tag.nil?
end
if @tagging.nil?
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
@tag.delete unless @tag.nil?
end
# end
end
end
private
private
# 这里用来刷新搜索结果的区域
# 函数的返回值 前2字段用来处理获取其他tag和分页 另外4个返回值为过滤结果
def refresh_results(obj_id,obj_flag,selected_tags)
@ -173,11 +179,13 @@ private
@projects_results = nil
@issues_results = nil
@bids_results = nil
@contests_results = nil
@forums_results = nil
attachments_results = nil
@obj_pages = nil
@obj = nil
@result = nil
# 这里为了提高系统的响应速度 把搜索结果放到case中去了
case obj_flag
when '1' then
@ -197,11 +205,27 @@ private
@obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags))
when '6'
@obj = Attachment.find_by_id(obj_id)
@obj_pages, attachments_results, @results_count = for_pagination(get_attachments_by_tag(selected_tags))
# modifed by Long Jun
# this is used to find the attachments that came from the same project and tagged with the same tag.
@result = get_attachments_by_project_tag(selected_tags, @obj)
@obj_pages, attachments_results, @results_count = for_pagination(@result)
when '7'
@obj = Contest.find_by_id(obj_id)
@obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags))
else
@obj = nil
@obj = nil
end
return @obj,@obj_pages,@results_count,@users_results,@projects_results,@issues_results,@bids_results,@forums_results, attachments_results
return [@obj,
@obj_pages,
@results_count,
@users_results,
@projects_results,
@issues_results,
@bids_results,
@forums_results,
attachments_results,
@contests_results]
end
def for_pagination(results)
@ -221,7 +245,8 @@ private
@bids_tags_num = Bid.tag_counts.size
forum_tags_num = Forum.tag_counts.size
attachment_tags_num = Attachment.tag_counts.size
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num
@contests_tags_num = Contest.tag_counts.size
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num
end
# 通过数字 来转换出对象的类型
@ -242,6 +267,8 @@ private
return 'Forum'
when '6'
return 'Attachment'
when '7'
return 'Contest'
else
render_error :message => e.message
return

@ -1,160 +1,56 @@
class TestController < ApplicationController
before_filter :find_user, :only => [:new, :create, :destroy]
def index
# @users = User.where('status = ?', 1)
# for user in @users
# if user.user_extensions.nil?
# UserExtensions.create(:user_id => user.id)
# end
# end
# @message = Message.all
# @message.each do |m|
# Activity.create(:act_id => m.id, :act_type => 'Message', :user_id => m.author_id)
# end
# activity = Message.all
# activity += News.all
# activity += Journal.all
# activity += Issue.all
# activity += Bid.all
# @activity = activity.sort {|x,y| x.created_on <=> y.created_on}
# @activity.each do |act|
# if act.instance_of?(Bid)
# act.acts << Activity.new(:user_id => act.author_id)
# elsif act.instance_of?(News)
# act.acts << Activity.new(:user_id => act.author_id)
# elsif act.instance_of?(Message)
# act.acts << Activity.new(:user_id => act.author_id)
# elsif act.instance_of?(Journal)
# act.acts << Activity.new(:user_id => act.user_id)
# elsif act.instance_of?(Issue)
# act.acts << Activity.new(:user_id => act.author_id)
# elsif act.instance_of?(Changeset)
# act.acts << Activity.new(:user_id => act.user_id)
# end
# end
#@watchers_of_projects = WatchersOfProjects.new
#@watchers_of_projects.user_id = 1
#@watchers_of_projects.project_id = 1
#@watchers_of_projects.save
#测试user表与watch_project表之间的关联是否成功
#@user = User.find(params[:id])
#@watch_table = @user.watch_projects.to_a.first
#@watch = WatchProject.find(1)
#@watcher = @watch.user
#测试通过watch_project表使user表可以访问project表
#@watch_project = @user.projects
#watch_project_path(@watch)
#@project = Project.find(11)
#project_path(@project)
#@member = @project.users
#@watched = @project.watch_projects
#@issue = Issue.find(6)
#user_path(@user)
#issue_path(@issue)
#@watcher2=WatchProject.where("#{WatchProject.table_name}.project_id = ?" , temp)
#测试where语句
#temp = 1
#@watcher2=WatchProject.where(:project_id => temp).to_a
#测试新建记录
#@watch_new = WatchProject.new
#@watch_new.user_id = 4
#@watch_new.project_id = 1
#@watch_new.save
#@id = params[:id]
#测试添加关注项目功能
#WatchersOfProjects.watch(3,10)
#Project.find(50)
#测试统计关注该项目的用户数
#@count = WatchersOfProjects.watcher_count(@watch_project.to_a.first)
#测试取消关注功能
#WatchersOfProjects.watch_cancle(10,35)
#测试关注用户功能
#测试关注功能
#WatchersOfUser.watch_user(7,7)
#测试取消关注功能
#WatchersOfUser.cancel_watching_user(1,2)
#测试查找关注的人功能
#@user = WatchersOfUser.find_users(1)
#测试查找被关注的人功能
#@user = WatchersOfUser.find_watchers(10)
#测试用户留言功能
#测试留言功能
# MessagesForUser.leave_message(User.current.id, 6, 'test')
#测试查找留言功能
#@message_table = MessagesForUser.find_message(3)
#测试查找留言用户功能
#@messager=@message_table.first.find_messager
#测试需求
#测试新建需求
#bids = Bid.creat_bids(10000, '2013.7.25', 'test', 'sfsadgfag')
#测试修改需求
#bids.update_bids(10, '2014.7.222', 'asdf')
#测试删除需求
# bids = Bid.where('id = ?', 5)
# bids.each do |bid|
# bid.delete_bids
# end
def zip
homeworks_attach_path = []
homework_id = params[:homework_id]
bid = Bid.find_by_id(homework_id)
bid.homeworks.each do |homeattach|
homeattach.attachments.each do |attach|
length = attach.storage_path.length
homeworks_attach_path << attach.diskfile.to_s.slice((length+1)..-1)
end
end
# ##########留言功能 message by fq
# def new
# end
#
# def create
#
# if params[:user_search].size>0
# unless params[:user_id].nil?
# message = params[:user_search]
# MessagesForUser.leave_message(User.current.id, params[:user_id], message)
# @message = MessagesForUser.find_message(@user.id)
# end
# end
#
# respond_to do |format|
# # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
# format.js
# #format.api { render_api_ok }
# end
# end
#
# def destroy
# MessagesForUser.delete_message(params[:object_id])
# @message = MessagesForUser.find_message(@user.id)
# respond_to do |format|
# format.html { redirect_to :back }
# format.js
# #format.api { render_api_ok }
# end
# end
@paths = homeworks_attach_path
zipfile = ziping homeworks_attach_path
send_file zipfile, :filename => bid.name,
:type => detect_content_type(zipfile)
rescue Errno::ENOENT => e
logger.error "[Errno::ENOENT] ===> #{e}"
end
def courselist
@courses = Project.course_entities
end
def ziping files_path
ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
folder = "#{Rails.root}/files"
input_filename = files_path
zipfile_name = "#{Rails.root}/tmp/archiveZip/archive_#{Time.now.to_i}.zip"
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
input_filename.each do |filename|
zipfile.add(ic.iconv(filename_to_real(File.basename(filename))), folder + '/' + filename)
end
zipfile.get_output_stream("ReadMe"){ |os|
os.write "Homeworks"
}
end
zipfile_name
end
def detect_content_type(name)
content_type = Redmine::MimeType.of(name)
content_type.to_s
end
# private
#
# def find_user
# if params[:user_id]
# @user = User.find(params[:user_id])
# end
# rescue
# render_404
# end
#######end of message
def filename_to_real name
attach = Attachment.find_by_disk_filename(name)
attach.filename
end
end

@ -23,19 +23,20 @@ class UsersController < ApplicationController
menu_item :user_homework, :only => :user_homeworks
menu_item :user_project, :only => [:user_projects, :watch_projects]
menu_item :requirement_focus, :only => :watch_bids
menu_item :requirement_focus, :only => :watch_contests
menu_item :user_newfeedback, :only => :user_newfeedback
#Ended by young
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info,
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
#edit has been deleted by huang, 2013-9-23
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
:watch_bids, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save
@ -116,6 +117,28 @@ class UsersController < ApplicationController
format.api
end
end
#new add by linchun
def watch_contests
@bids = Contest.watched_by(@user)
@offset, @limit = api_offset_and_limit({:limit => 10})
@contest_count = @contests.count
@contest_pages = Paginator.new @contest_count, @limit, params['page']
@offset ||= @contest_pages.reverse_offset
unless @offset == 0
@contest = @contests.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
@contest = @contests.offset(@offset).limit(limit).all.reverse
end
respond_to do |format|
format.html {
render :layout => 'base_users'
}
format.api
end
end
# added by fq
def user_activities
@ -633,6 +656,8 @@ class UsersController < ApplicationController
@obj = Forum.find_by_id(@obj_id)
when '6'
@obj = Attachment.find_by_id(@obj_id)
when '7' then
@obj = Contest.find_by_id(@obj_id)
else
@obj = nil
end

@ -27,6 +27,7 @@ class WelcomeController < ApplicationController
@projectHidenCount = @projectCount - @projectPublicCount
@developerCount = User.developer.count
@allUsercount = User.count
end
def robots
@ -80,7 +81,7 @@ class WelcomeController < ApplicationController
def entry_select_contest
if request.original_url.match(/contest\.trustie\.net/)
contest
render :contest, layout: false
render :contest
return 0
end
end

@ -190,6 +190,10 @@ class WordsController < ApplicationController
obj = User.find_by_id(obj_id)
elsif ( referer.match(/bids/) || referer.match(/calls/) )
obj = Bid.find_by_id(obj_id)
elsif ( referer.match(/contests/) || referer.match(/contests/) ) #new added
obj = Contest.find_by_id(obj_id)
elsif ( referer.match(/softapplications/) || referer.match(/softapplications/) ) #new added
obj = Softapplication.find_by_id(obj_id)
else
raise 'create reply obj unknow type.'
end
@ -204,6 +208,10 @@ class WordsController < ApplicationController
Project.add_new_jour(nil, nil, obj.id, options)
elsif obj.kind_of? Bid
obj.add_jour(nil, nil, nil, options)
elsif obj.kind_of? Contest
obj.add_jour(nil, nil, obj.id, options) #new added
elsif obj.kind_of? Softapplication
obj.add_jour(nil, nil, obj.id, options) #new added
else
raise 'create reply obj unknow type.'
end

@ -0,0 +1,115 @@
class ZipdownController < ApplicationController
SAVE_FOLDER = "#{Rails.root}/files"
OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip"
def assort
obj_class = params[:obj_class]
obj_id = params[:obj_id]
obj = obj_class.constantize.find(obj_id)
zipfile = nil
case obj.class.to_s.to_sym
when :Bid
zipfile = zip_bid obj
else
logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!"
end
send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile
#rescue NameError, ActiveRecord::RecordNotFound => e
#logger.error "[ZipDown] ===> #{e}"
#@error = e
end
private
def zip_bid(bid)
# Todo: User Access Controll
homeattaches = bid.homeworks
# 得到每一个人所有文件打包的zip文件
# 并将每一个人的zip打包为一个并返回路径
user_zip_paths = homeattaches.map do |homeattach|
zip_homework_by_user homeattach
end
zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER
#@paths = homeworks_attach_path
#zipfile = ziping homeworks_attach_path
#send_file zipfile, :filename => bid.name,
# :type => detect_content_type(zipfile)
#rescue Errno::ENOENT => e
# logger.error "[Errno::ENOENT] ===> #{e}"
# @error = e
end
def zip_homework_by_user(homeattach)
homeworks_attach_path = []
# 需要将所有homework.attachments遍历加入zip
# 并且返回zip路径
user_attaches_paths = homeattach.attachments.each do |attach|
#length = attach.storage_path.length
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
end
zipping "#{Time.now.to_i}_#{homeattach.user.name.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
end
def zipping(zip_name_refer, files_paths, output_path, is_attachment=false)
# 输入待打包的文件列表已经打包文件定位到ouput_path
ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
input_filename = files_paths
rename_zipfile = zip_name_refer ||= "archive_#{Time.now.to_i}.zip"
zipfile_name = "#{output_path}/#{rename_zipfile}"
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
input_filename.each do |filename|
rename_file = Time.now.to_i.to_s+ ic.iconv( (File.basename(filename)) ).to_s
rename_file = ic.iconv( filename_to_real( File.basename(filename))).to_s if is_attachment
zipfile.add(rename_file, filename)
end
zipfile.get_output_stream('ReadMe') do |os|
os.write 'Homeworks'
end
end
zipfile_name
rescue Errno => e
logger.error "[zipdown#zipping] ===> #{e}"
@error = e
end
#def ziping files_path
# ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
# folder = SaveFolder
# input_filename = files_path
# zipfile_name = "#{OutputFolder}/archive_#{Time.now.to_i}.zip"
#
# Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
# Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
# input_filename.each do |filename|
# zipfile.add(ic.iconv(filename_to_real(File.basename(filename))), folder + '/' + filename)
# end
# zipfile.get_output_stream("ReadMe") { |os|
# os.write "Homeworks"
# }
# end
# zipfile_name
#rescue Errno => e
# logger.error "[zipdown#zipping] ===> #{e}"
# @error = e
#end
def detect_content_type(name)
content_type = Redmine::MimeType.of(name)
content_type.to_s
end
def filename_to_real(name)
attach = Attachment.find_by_disk_filename(name)
attach.filename
end
end

@ -24,10 +24,10 @@ module ActivitiesHelper
events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event|
if group_events = events_by_group.delete(event.event_group)
group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i|
sorted_events << [e, i > 0]
sorted_events << [e, i > 0] unless e.event_description.nil?
end
end
end
sorted_events
sorted_events
end
end

@ -111,6 +111,14 @@ module ApplicationHelper
link_to text, url, html_options
end
def link_to_attachment_img(attachment, options={})
text = options.delete(:text) || attachment.filename
route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
html_options = options.slice!(:only_path)
url = send(route_method, attachment, attachment.filename, options)
image_tag url, html_options
end
# Generates a link to a SCM revision
# Options:
# * :text - Link text (default to the formatted revision)
@ -1402,6 +1410,71 @@ module ApplicationHelper
end
html.html_safe
end
#display contest project
def show_more_contest_project?(contest)
if contest.projects.where('is_public = 1').count > 12
return true
else
return false
end
end
def show_more_contest_softapplication?(contest)
if contest.softapplications.where('is_public = 1').count > 12
return true
else
return false
end
end
def show_contest_project(bid)
html = ''
if contest.projects.where('is_public = 1').count == 0
html << (content_tag "p", l(:label_no_bid_project), :class => "font_lighter")
else
contest.projects.where('is_public = 1').take(12).each do |project|
html << (link_to image_tag(url_to_avatar(project), :class => "avatar", :title => project.name), project_path(project), :class => "avatar")
end
end
html.html_safe
end
def show_contest_project(contest)
html = ''
if contest.projects.where('is_public = 1').count == 0
html << (content_tag "p", l(:label_no_bid_project), :class => "font_lighter")
else
contest.projects.where('is_public = 1').take(12).each do |project|
html << (link_to image_tag(url_to_avatar(project), :class => "avatar", :title => project.name), project_path(project), :class => "avatar")
end
end
html.html_safe
end
def show_contest_softapplication(contest)
html = ''
if contest.softapplications.where('is_public = 1').count == 0
html << (content_tag "p", l(:label_no_contest_softapplication), :class => "font_lighter")
else
contest.softapplications.where('is_public = 1').take(12).each do |softapplication|
html << (link_to image_tag(url_to_avatar(project), :class => "avatar", :title => project.name), project_path(project), :class => "avatar")
end
end
html.html_safe
end
def show_contest_fans_picture(obj)
html = ''
if obj.watcher_users.count == 0
html << (content_tag "span", l(:label_project_no_follow))
else
obj.watcher_users.take(12).each do |user|
html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => user.name)
end
end
html.html_safe
end
#display fans picture
def show_more_fans?(obj)
@ -1494,13 +1567,14 @@ module ApplicationHelper
home_link = link_to l(:field_homepage), {:controller => 'welcome', :action => 'index'}
main_course_link = link_to l(:label_course_practice), {:controller => 'welcome', :action => 'index', :host => Setting.course_domain}
main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain}
main_contest_link = link_to l(:label_contest_innovate), {:controller => 'welcome', :action => 'index', :host => Setting.contest_domain}
course_all_course_link = link_to l(:label_course_all), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain}
course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher', :host => Setting.course_domain}
courses_link = link_to l(:label_course_practice), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain}
projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}
users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain}
contest_link = link_to l(:label_contest_innovate), {:controller => 'bids', :action => 'contest', :project_type => 1 , :host => Setting.contest_domain}
contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'}
bids_link = link_to l(:label_requirement_enterprise), {:controller => 'bids', :action => 'index'}
forum_link = link_to l(:label_project_module_forums), {:controller => "forums", :action => "index"}
stores_link = link_to l(:label_stores_index), {:controller => 'stores', :action=> 'index'}
@ -1513,6 +1587,7 @@ module ApplicationHelper
nav_list.push(main_project_link) if @nav_dispaly_main_project_label
nav_list.push(main_course_link) if @nav_dispaly_main_course_label
nav_list.push(main_contest_link) if @nav_dispaly_main_contest_label
nav_list.push(courses_link) if @nav_dispaly_course_label
nav_list.push(projects_link) if @nav_dispaly_project_label
@ -1528,5 +1603,9 @@ module ApplicationHelper
end
content_tag :ul, content_li.html_safe
end
def current_user
User.current
end
end

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

Loading…
Cancel
Save