diff --git a/.gitignore b/.gitignore index d53811d1e..8aa87e9f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.swp /.project /.idea /.bundle diff --git a/app/assets/javascripts/apply_project_masters.js b/app/assets/javascripts/apply_project_masters.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/apply_project_masters.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. diff --git a/app/assets/javascripts/no_uses.js b/app/assets/javascripts/no_uses.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/no_uses.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. diff --git a/app/assets/javascripts/open_source_projects.js b/app/assets/javascripts/open_source_projects.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/open_source_projects.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. diff --git a/app/assets/stylesheets/apply_project_masters.css b/app/assets/stylesheets/apply_project_masters.css new file mode 100644 index 000000000..afad32db0 --- /dev/null +++ b/app/assets/stylesheets/apply_project_masters.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/no_uses.css b/app/assets/stylesheets/no_uses.css new file mode 100644 index 000000000..afad32db0 --- /dev/null +++ b/app/assets/stylesheets/no_uses.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/open_source_projects.css b/app/assets/stylesheets/open_source_projects.css new file mode 100644 index 000000000..afad32db0 --- /dev/null +++ b/app/assets/stylesheets/open_source_projects.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/controllers/apply_project_masters_controller.rb b/app/controllers/apply_project_masters_controller.rb new file mode 100644 index 000000000..9e5c52348 --- /dev/null +++ b/app/controllers/apply_project_masters_controller.rb @@ -0,0 +1,114 @@ +class ApplyProjectMastersController < ApplicationController + + before_filter :require_login, :find_apply, :only => [:create, :delete] + + # GET /apply_project_masters + # GET /apply_project_masters.json + def index + @apply_project_masters = ApplyProjectMaster.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @apply_project_masters } + end + end + + # GET /apply_project_masters/1 + # GET /apply_project_masters/1.json + def show + @apply_project_master = ApplyProjectMaster.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @apply_project_master } + end + end + + # GET /apply_project_masters/new + # GET /apply_project_masters/new.json + def new + @apply_project_master = ApplyProjectMaster.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @apply_project_master } + end + end + + # GET /apply_project_masters/1/edit + def edit + @apply_project_master = ApplyProjectMaster.find(params[:id]) + end + + # POST /apply_project_masters + # POST /apply_project_masters.json + def create + # @apply_project_master = ApplyProjectMaster.new(params[:apply_project_master]) +# + # respond_to do |format| + # if @apply_project_master.save + # format.html { redirect_to @apply_project_master, notice: 'Apply project master was successfully created.' } + # format.json { render json: @apply_project_master, status: :created, location: @apply_project_master } + # else + # format.html { render action: "new" } + # format.json { render json: @apply_project_master.errors, status: :unprocessable_entity } + # end + # end + + set_apply(@apply, User.current, true) + + end + + # PUT /apply_project_masters/1 + # PUT /apply_project_masters/1.json + def update + @apply_project_master = ApplyProjectMaster.find(params[:id]) + + respond_to do |format| + if @apply_project_master.update_attributes(params[:apply_project_master]) + format.html { redirect_to @apply_project_master, notice: 'Apply project master was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @apply_project_master.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /apply_project_masters/1 + # DELETE /apply_project_masters/1.json + def destroy + @apply_project_master = ApplyProjectMaster.find(params[:id]) + @apply_project_master.destroy + + respond_to do |format| + format.html { redirect_to apply_project_masters_url } + format.json { head :no_content } + end + end + + def delete + set_apply(@apply, User.current, false) + end + + private + + def find_apply + klass = Object.const_get(params[:object_type].camelcase) rescue nil + if klass && klass.respond_to?('applied_by') + @apply = klass.find_all_by_id(Array.wrap(params[:object_id])) + end + render_404 unless @apply.present? + end + + #flag标注功能,为1时设置‘申请版主’,为0时设置取消 + def set_apply(objects, user, flag) + objects.each do |object| + object.set_apply(user, flag) + end + respond_to do |format| + format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} + format.js { render :partial => 'set_apply', :locals => {:user => user, :objects => objects} } + end + end +end diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb index ea463e121..9e7467bfc 100644 --- a/app/controllers/auto_completes_controller.rb +++ b/app/controllers/auto_completes_controller.rb @@ -30,6 +30,7 @@ class AutoCompletesController < ApplicationController @issues.compact! end render :layout => false + end private diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index f6ad48801..20f0b45c4 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -148,7 +148,8 @@ class MemosController < ApplicationController def find_memo return unless find_forum - @memo = @forum.memos.find(params[:id]) + #@memo = @forum.memos.find(params[:id]) + @memo = Memo.find(params[:id]) rescue ActiveRecord::RecordNotFound render_404 nil diff --git a/app/controllers/no_uses_controller.rb b/app/controllers/no_uses_controller.rb new file mode 100644 index 000000000..f66997107 --- /dev/null +++ b/app/controllers/no_uses_controller.rb @@ -0,0 +1,111 @@ +class NoUsesController < ApplicationController + + before_filter :require_login, :find_no_use, :only => [:create, :delete] + + # GET /no_uses + # GET /no_uses.json + def index + @no_uses = NoUse.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @no_uses } + end + end + + # GET /no_uses/1 + # GET /no_uses/1.json + def show + @no_use = NoUse.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @no_use } + end + end + + # GET /no_uses/new + # GET /no_uses/new.json + def new + @no_use = NoUse.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @no_use } + end + end + + # GET /no_uses/1/edit + def edit + @no_use = NoUse.find(params[:id]) + end + + # POST /no_uses + # POST /no_uses.json + def create + set_no_use(@no_use, User.current, true) + + # respond_to do |format| + # if @no_use.save + # format.html { redirect_to @no_use, notice: 'No use was successfully created.' } + # format.json { render json: @no_use, status: :created, location: @no_use } + # else + # format.html { render action: "new" } + # format.json { render json: @no_use.errors, status: :unprocessable_entity } + # end + # end + end + def delete + set_no_use(@no_use, User.current, false) + end + + # PUT /no_uses/1 + # PUT /no_uses/1.json + def update + @no_use = NoUse.find(params[:id]) + + respond_to do |format| + if @no_use.update_attributes(params[:no_use]) + format.html { redirect_to @no_use, notice: 'No use was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @no_use.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /no_uses/1 + # DELETE /no_uses/1.json + def destroy + # @no_use = NoUse.find(params[:id]) + # @no_use.destroy + + set_no_use(@no_use, User.current, false) + + # respond_to do |format| + # format.html { redirect_to no_uses_url } + # format.json { head :no_content } + # end + end + private + + def find_no_use + klass = Object.const_get(params[:object_type].camelcase) rescue nil + if klass && klass.respond_to?('no_use_for') + @no_use = klass.find_all_by_id(Array.wrap(params[:object_id])) + end + render_404 unless @no_use.present? + end + + #flag标注功能,为1时设置‘没有帮助’,为0时设置取消 + def set_no_use(objects, user, flag) + objects.each do |object| + object.set_no_use(user, flag) + end + respond_to do |format| + format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} + format.js { render :partial => 'set_no_use', :locals => {:user => user, :objects => objects} } + end + end +end diff --git a/app/controllers/open_source_projects_controller.rb b/app/controllers/open_source_projects_controller.rb new file mode 100644 index 000000000..4feca7b27 --- /dev/null +++ b/app/controllers/open_source_projects_controller.rb @@ -0,0 +1,190 @@ +class OpenSourceProjectsController < ApplicationController + + before_filter :find_osp, :only => [:master_apply, :accept_master_apply, :refuse_master_apply] + before_filter :require_master, :only => [:master_apply, :accept_master_apply, :refuse_master_apply] + + helper :sort + include SortHelper + helper :apply_project_masters + include ApplyProjectMastersHelper + helper :no_uses + include NoUsesHelper + # GET /open_source_projects + # GET /open_source_projects.json + def index + @app_dir = params[:app_dir] + @language = params[:language] + @created_at = params[:created_at] + per_page_option = 10 + + @open_source_projects = OpenSourceProject.filter(@app_dir, @language, @created_at) + @open_source_projects = @open_source_projects.like(params[:name]) if params[:name].present? + + @os_project_count = @open_source_projects.count + @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page'] + + @open_source_projects = @open_source_projects.offset(@os_project_pages.offset).limit(@os_project_pages.per_page) + + # @open_source_projects = OpenSourceProject.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @open_source_projects } + end + end + + def master_apply + @apply = @open_source_project.apply_tips + @applicants = @open_source_project.applicants + + respond_to do |format| + format.html { + render :layout => "base_opensource_p" + } + format.json { render json: @open_source_project } + end + end + + # GET /open_source_projects/1 + # GET /open_source_projects/1.json + def show + @open_source_project = OpenSourceProject.find(params[:id]) + + sort_init 'updated_at', 'desc' + sort_update 'created_at' => "#{RelativeMemo.table_name}.created_at", + 'replies' => "#{RelativeMemo.table_name}.replies_count", + 'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)" + + @memo = RelativeMemo.new(:open_source_project => @open_source_project) + @topic_count = @open_source_project.topics.count + @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @memos = @open_source_project.topics. + reorder("#{RelativeMemo.table_name}.sticky DESC"). + includes(:last_reply). + limit(@topic_pages.per_page). + offset(@topic_pages.offset). + order(sort_clause). + all + + respond_to do |format| + format.html { + render :layout => "base_opensource_p" + } + format.json { render json: @open_source_project } + end + end + + def search + + end + + # GET /open_source_projects/new + # GET /open_source_projects/new.json + def new + @open_source_project = OpenSourceProject.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @open_source_project } + end + end + + # GET /open_source_projects/1/edit + def edit + @open_source_project = OpenSourceProject.find(params[:id]) + end + + # POST /open_source_projects + # POST /open_source_projects.json + def create + @open_source_project = OpenSourceProject.new(params[:open_source_project]) + + respond_to do |format| + if @open_source_project.save + format.html { redirect_to @open_source_project, notice: 'Open source project was successfully created.' } + format.json { render json: @open_source_project, status: :created, location: @open_source_project } + else + format.html { render action: "new" } + format.json { render json: @open_source_project.errors, status: :unprocessable_entity } + end + end + end + + # PUT /open_source_projects/1 + # PUT /open_source_projects/1.json + def update + @open_source_project = OpenSourceProject.find(params[:id]) + + respond_to do |format| + if @open_source_project.update_attributes(params[:open_source_project]) + format.html { redirect_to @open_source_project, notice: 'Open source project was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @open_source_project.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /open_source_projects/1 + # DELETE /open_source_projects/1.json + def destroy + @open_source_project = OpenSourceProject.find(params[:id]) + @open_source_project.destroy + + respond_to do |format| + format.html { redirect_to open_source_projects_url } + format.json { head :no_content } + end + end + + def remove_condition + @app_dir = params[:app_dir] + @language = params[:language] + @created_at = params[:created_at] + redirect_to open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => @created_at, :name => params[:name]) + end + + def search + # per_page_option = 10 +# + # @open_source_projects = OpenSourceProject.filter(@app_dir, @language, @created_at) + # @open_source_projects = @open_source_projects.like(params[:name]) if params[:name].present? +# + # @os_project_count = @open_source_projects.count + # @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page'] +# + # @open_source_projects = @open_source_projects.offset(@os_project_pages.offset).limit(@os_project_pages.per_page) + + redirect_to open_source_projects_path(:name => params[:name]) + + end + + def refuse_master_apply + @apply = ApplyProjectMaster.where("user_id = ? and apply_id = ? and apply_type = 'OpenSourceProject'", params[:user_id], @open_source_project.id) + @apply.first.destory + + redirect_to master_apply_open_source_project_path + end + + def accept_master_apply + @apply = ApplyProjectMaster.where("user_id = ? and apply_id = ? and apply_type = 'OpenSourceProject'", params[:user_id], @open_source_project.id) + if @apply.count == 1 + @apply.first.update_attributes(:status => 2) + end + + redirect_to master_apply_open_source_project_path + end + + + private + + def require_master + render_403 unless @open_source_project.admin?(User.current) + end + + def find_osp + @open_source_project = OpenSourceProject.find(params[:id]) + render_404 unless @open_source_project.present? + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 1fbe6acaa..d26cf698e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -138,6 +138,17 @@ class ProjectsController < ApplicationController @project_count = @projects_all.count @project_pages = Paginator.new @project_count, per_page_option, params['page'] +#gcm activity count + + @project_activity_count=Hash.new + + @projects_all.each do |project| + @project_activity_count[project.id]=0 + end + + @project_activity_count=get_project_activity @projects_all,@project_activity_count + +#gcm end case params[:project_sort_type] when '0' @@ -149,6 +160,14 @@ class ProjectsController < ApplicationController when '2' @projects = @projects_all.order("watchers_count desc") @s_type = 2 + + #gcm + when '3' + #@projects=desc_sort_course_by_avtivity(@project_activity_count_array,@project_all_array) + @projects=handle_project @projects_all,@project_activity_count + @s_type = 3 + @projects = @projects[@project_pages.offset, @project_pages.per_page] + else @projects = @projects = @projects_all.order("grade desc") @s_type = 1 @@ -193,122 +212,16 @@ class ProjectsController < ApplicationController @project_count = @projects_all.count @project_pages = Paginator.new @project_count, per_page_option, params['page'] -#gcm activity count + #gcm activity count @project_activity_count=Hash.new - + #count initialize @projects_all.each do |project| @project_activity_count[project.id]=0 end - @project_ids=@project_activity_count.keys() - - days = Setting.activity_days_default.to_i - date_to ||= Date.today + 1 - date_from = date_to - days-1.years -#approach 1 -=begin - - @projects_all.each do |project| - #issue_count - issues=Issue.where("project_id=?",project.id) - issue_count=0 - issues.each do |issue| - issue_count+=issue.journals.count - end - - #repository_count - repositories=Repository.where("project_id=?",project.id) - repository_count=0 - repositories.each do |repository| - repository_count+=repository.changesets.count - end - - #news_count - news_count=News.where("project_id=?",project.id).count - #document_count - document_count=Document.where("project_id=?",project.id).count - #file_count - file_count=Attachment.where("container_type='Project' AND container_id=?",project.id).count - - #message_count - boards=Board.where("project_id=?",project.id) - message_count=0 - boards.each do |board| - message_count+=board.messages.count - end - - #time_entry_count - time_entry_count=TimeEntry.where("project_id=?",project.id).count - - #sum - @project_activity_count[project.id.to_s]=issue_count+repository_count+news_count+document_count+file_count+message_count+time_entry_count - - end -=end -#gcm - -#gcm approach 2 - - #issue_count - Issue.where(project_id: @project_ids).where("updated_on>?",date_from).each do |issue| -# @project_activity_count[issue.project_id.to_s]+=1 - @project_activity_count[issue.project_id]+=issue.journals.where("created_on>?",date_from).count - end - - #repository_count - Repository.where(project_id: @project_ids).each do |repository| -# @project_activity_count[repository.project_id.to_s]+=1 - @project_activity_count[repository.project_id]+=repository.changesets.where("committed_on>?",date_from).count - end - - - #news_count - News.where(project_id: @project_ids).where("created_on>?",date_from).each do |news| - @project_activity_count[news.project_id]+=1 - end - - #document_count - Document.where(project_id: @project_ids).where("created_on>?",date_from).each do |document| - @project_activity_count[document.project_id]+=1 - end - - #file_count - Attachment.where(container_id: @project_ids).where("container_type='Project' AND created_on>?",date_from).each do |attachment| - @project_activity_count[attachment.container_id]+=1 - end - - #message_count - Board.where(project_id: @project_ids).each do |board| -# @project_activity_count[board.project_id]+=1 - @project_activity_count[board.project_id]+=board.messages.where("updated_on>?",date_from).count - end - - #time_entry_count - TimeEntry.where(project_id: @project_ids).where("updated_on>?",date_from).each do |timeentry| - @project_activity_count[timeentry.project_id]+=1 - end - - #feedbackc_count - JournalsForMessage.where(jour_id: @project_ids).each do |jourformess| - @project_activity_count[jourformess.jour_id]+=1 - end - - #@project_activity_count!=0 - @project_all_array=[] - i=0; - @projects_all.each do |project| - id=project.id - @project_all_array[i]=project - if @project_activity_count[id]==0 - @project_activity_count[id]=1 - end - i=i+1 - end - - @project_activity_count_array=@project_activity_count.values() - -#gcm end + #@project_activity_count=get_project_activity @projects_all,@project_activity_count + #gcm end case params[:project_sort_type] @@ -316,26 +229,48 @@ class ProjectsController < ApplicationController @projects = @projects_all.order("created_on desc") @s_type = 0 @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + when '1' @projects = @projects_all.order("course_ac_para desc") @s_type = 1 @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + when '2' @projects = @projects_all.order("watchers_count desc") @s_type = 2 @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + #gcm when '3' - @projects=desc_sort_course_by_avtivity(@project_ids,@project_activity_count_array,@project_all_array) + + #gcm + @project_activity_count=get_project_activity @projects_all,@project_activity_count + #gcmend + + @projects=handle_project @projects_all,@project_activity_count @s_type = 3 @projects = @projects[@project_pages.offset, @project_pages.per_page] - #gcmend - else @s_type = 0 @projects = @projects_all.order("created_on desc") @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + end respond_to do |format| @@ -354,17 +289,76 @@ class ProjectsController < ApplicationController end end +#gcm def search #modified by nie project_type = params[:project_type].to_i projects_all = (project_type.eql? Project::ProjectType_course) ? Project.course_entities : Project.project_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'] - @offset ||= @project_pages.offset - @projects = @projects.visible.offset(@offset).limit(@limit).all + @projects_all = @projects.visible.like(params[:name]) if params[:name].present? + + @project_count = @projects_all.count + @project_pages = Paginator.new @project_count, per_page_option, params['page'] + + #gcm activity count + + @project_activity_count=Hash.new + # count initialize + @projects_all.each do |project| + @project_activity_count[project.id]=0 + end + + #@project_activity_count=get_project_activity @projects_all,@project_activity_count + + #gcm end + + + case params[:project_sort_type] + when '0' + @projects = @projects_all.order("created_on desc") + @s_type = 0 + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + when '1' + @projects = @projects_all.order("course_ac_para desc") + @s_type = 1 + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + when '2' + @projects = @projects_all.order("watchers_count desc") + @s_type = 2 + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + when '3' + #@projects=desc_sort_course_by_avtivity(@project_activity_count_array,@project_all_array) + @project_activity_count=get_project_activity @projects_all,@project_activity_count_array #gcm + @projects=handle_project @projects_all,@project_activity_count + @s_type = 3 + @projects = @projects[@project_pages.offset, @project_pages.per_page] + + else + @s_type = 0 + @projects = @projects_all.order("created_on desc") + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + end + respond_to do |format| format.html { render :layout => 'base' @@ -384,6 +378,38 @@ class ProjectsController < ApplicationController } end end +#gcmend + + # def search + # #modified by nie + # project_type = params[:project_type].to_i + # projects_all = (project_type.eql? Project::ProjectType_course) ? Project.course_entities : Project.project_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'] + # @offset ||= @project_pages.offset + # @projects = @projects.visible.offset(@offset).limit(@limit).all + # respond_to do |format| + # format.html { + # render :layout => 'base' + # scope = Project + # unless params[:closed] + # scope = scope.active + # end + # } + # format.api { + # # @offset, @limit = api_offset_and_limit + # # @project_count = Project.visible.count + # # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all + # } + # format.atom { + # 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 # added by fq def new_join @@ -1026,7 +1052,93 @@ class ProjectsController < ApplicationController end end - def desc_sort_course_by_avtivity(ids,activity_count,projects) + + + #gcm + def get_project_activity projects,activities + @project_ids=activities.keys() + + days = Setting.activity_days_default.to_i + date_to ||= Date.today + 1 + date_from = date_to - days-1.years + + #issue_count + Issue.where(project_id: @project_ids).where("updated_on>?",date_from).each do |issue| +# activities[issue.project_id.to_s]+=1 + activities[issue.project_id]+=issue.journals.where("created_on>?",date_from).count + end + + #repository_count + Repository.where(project_id: @project_ids).each do |repository| +# activities[repository.project_id.to_s]+=1 + activities[repository.project_id]+=repository.changesets.where("committed_on>?",date_from).count + end + + + #news_count + News.where(project_id: @project_ids).where("created_on>?",date_from).each do |news| + activities[news.project_id]+=1 + end + + #document_count + Document.where(project_id: @project_ids).where("created_on>?",date_from).each do |document| + activities[document.project_id]+=1 + end + + #file_count + Attachment.where(container_id: @project_ids, container_type: Project).where("created_on>?",date_from).each do |attachment| + activities[attachment.container_id]+=1 + end + + #message_count + Board.where(project_id: @project_ids).each do |board| +# activities[board.project_id]+=1 + activities[board.project_id]+=board.messages.where("updated_on>?",date_from).count + end + + #time_entry_count + TimeEntry.where(project_id: @project_ids).where("updated_on>?",date_from).each do |timeentry| + activities[timeentry.project_id]+=1 + end + + #feedbackc_count + JournalsForMessage.where(jour_id: @project_ids, jour_type: Project).each do |jourformess| + activities[jourformess.jour_id]+=1 + end + + #activities!=0 + i=0; + projects.each do |project| + id=project.id + if activities[id]==0 + activities[id]=1 + end + end + + return activities + end + #gcmend + + #gcm + def handle_project projects,activities + project_activity_count_array=activities.values() + + project_array=[] + i=0; + projects.each do |project| + project_array[i]=project + i=i+1 + end + + projects=desc_sort_course_by_avtivity(project_activity_count_array,project_array) + + return projects + end + #gcmend + + + #gcm + def desc_sort_course_by_avtivity(activity_count,projects) return projects if activity_count.size<2 (activity_count.size-2).downto(0) do |i| (0..i).each do |j| @@ -1037,20 +1149,7 @@ class ProjectsController < ApplicationController end end return projects - - - - # len=activity_count.length - # for i in 0...(len-1) do - # for j in 0...(len-i-1) do - # if activity_count[j]>activity_count[j+1] do - # count_temp=activity_count[j] - - # activity_count[j]=activity_count[j+1] - # activity_count[j+1]=count_temp - # end - # end - # end -#desc_sort_course_by_avtivity(@project_ids,@project_activity_count_array,@projects_all) end + #gcmend + end diff --git a/app/controllers/relative_memos_controller.rb b/app/controllers/relative_memos_controller.rb new file mode 100644 index 000000000..f8741365b --- /dev/null +++ b/app/controllers/relative_memos_controller.rb @@ -0,0 +1,161 @@ +class RelativeMemosController < ApplicationController + + helper :sort + include SortHelper + helper :apply_project_masters + include ApplyProjectMastersHelper + helper :no_uses + include NoUsesHelper + + before_filter :find_memo, :except => [:new, :create] + before_filter :find_osp, :only => [:create] + before_filter :require_login, :only => [:new, :create] + + layout 'base_opensource_p' + + # GET /open_source_projects + # GET /open_source_projects.json + def index + # per_page_option = 10 +# + # @open_source_projects = OpenSourceProject.all +# + # @os_project_count = @open_source_projects.count + # @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page'] +# + # @open_source_projects = OpenSourceProject.all +# + # respond_to do |format| + # format.html # index.html.erb + # format.json { render json: @open_source_projects } + # end + end + + # GET /open_source_projects/1 + # GET /open_source_projects/1.json + REPLIES_PER_PAGE = 10 unless const_defined?(:REPLIES_PER_PAGE) + def show + pre_count = REPLIES_PER_PAGE + + @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示 + @memo.update_column(:viewed_count_local, (@memo.viewed_count_local.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("#{RelativeMemo.table_name}.created_at ASC"). + limit(@reply_pages.per_page). + offset(@reply_pages.offset). + all + + @mome_new = RelativeMemo.new + + + # @memo = Memo.find_by_id(params[:id]) + # @forum = Forum.find(params[:forum_id]) + # @replies = @memo.replies + # @mome_new = Memo.new + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @memo } + end + end + + + # GET /open_source_projects/new + # GET /open_source_projects/new.json + def new + @open_source_project = OpenSourceProject.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @open_source_project } + end + end + + # GET /open_source_projects/1/edit + def edit + @open_source_project = OpenSourceProject.find(params[:id]) + end + + # POST /open_source_projects + # POST /open_source_projects.json + def create + @memo = RelativeMemo.new(params[:relative_memo]) + # @memo.url = "http://forge.trustie.net/open_source_projects" + @memo.osp_id = params[:open_source_project_id] + @memo.author_id = User.current.id + + @memo.save_attachments(params[:attachments] || (params[:relative_memo] && params[:relative_memo][:uploads])) + + respond_to do |format| + if @memo.save + format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } + format.json { render json: @memo, status: :created, location: @memo } + 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_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } + format.json { render json: @memo.errors, status: :unprocessable_entity } + end + end + end + + # PUT /open_source_projects/1 + # PUT /open_source_projects/1.json + def update + @open_source_project = OpenSourceProject.find(params[:id]) + + respond_to do |format| + if @open_source_project.update_attributes(params[:open_source_project]) + format.html { redirect_to @open_source_project, notice: 'Open source project was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @open_source_project.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /open_source_projects/1 + # DELETE /open_source_projects/1.json + def destroy + @open_source_project = OpenSourceProject.find(params[:id]) + @open_source_project.destroy + + respond_to do |format| + format.html { redirect_to open_source_projects_url } + format.json { head :no_content } + end + end + + private + + def find_memo + return unless find_osp + @memo = @open_source_project.relative_memos.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + nil + end + + def find_osp + @open_source_project = OpenSourceProject.find(params[:open_source_project_id]) + rescue ActiveRecord::RecordNotFound + render_404 + nil + end + + def back_memo_url + open_source_project_relative_memo_path(@open_source_project, (@memo.parent_id.nil? ? @memo : @memo.parent_id)) + end +end diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 5ba6d836b..5b405a27a 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -32,6 +32,19 @@ class SchoolController < ApplicationController def index end + + def get_province + @provinces = School.find_by_sql("select distinct province from schools") + + options = "" + + @provinces.each do |p| + options << "" + end + + render :text => options + + end def get_options @school = School.where("province = ?", params[:province]) diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index 281f6216d..3aba819e0 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -56,8 +56,10 @@ class SoftapplicationsController < ApplicationController @stars_status_map = Hash.new(0.0) stars_status.each do |star_status| + percent = percent_of(star_status.scount, stars_reates_count).to_f + percent_m = format("%.2f", percent) @stars_status_map["star#{star_status.stars.to_i}".to_sym] = - percent_of(star_status.scount, stars_reates_count).to_s + "%" + percent_m.to_s + "%" end @jours = @softapplication.journals_for_messages.order('created_on DESC') @image_results = [] diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 18cfcb3f3..84c3aff0f 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -16,6 +16,7 @@ class TagsController < ApplicationController helper :projects include TagsHelper helper :tags + include OpenSourceProjectsHelper before_filter :require_admin,:only => [:delete,:show_all] @@ -58,7 +59,7 @@ class TagsController < ApplicationController end @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,@contests_tags_num, - @forum_tags_num, @attachments_tags_num = get_tags_size + @forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size # 获取搜索结果 @obj,@obj_pages,@results_count,@users_results, @@ -67,7 +68,8 @@ class TagsController < ApplicationController @bids_results, @forums_results, @attachments_results, - @contests_tags = refresh_results(@obj_id,@obj_flag,@selected_tags) + @contests_tags, + @open_source_projects_results = refresh_results(@obj_id,@obj_flag,@selected_tags) # 这里是做tag推荐用的, 用来生产推荐的tags unless @obj.nil? @@ -182,6 +184,7 @@ class TagsController < ApplicationController @contests_results = nil @forums_results = nil attachments_results = nil + @open_source_projects_results = nil @obj_pages = nil @obj = nil @result = nil @@ -213,10 +216,13 @@ class TagsController < ApplicationController when '7' @obj = Contest.find_by_id(obj_id) @obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags)) + when '8' + @obj = OpenSourceProject.find_by_id(obj_id) + @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags)) else @obj = nil end - return [@obj, + return [@obj, @obj_pages, @results_count, @users_results, @@ -225,7 +231,8 @@ class TagsController < ApplicationController @bids_results, @forums_results, attachments_results, - @contests_results] + @contests_results, + @open_source_projects_results] end def for_pagination(results) @@ -245,8 +252,9 @@ class TagsController < ApplicationController @bids_tags_num = Bid.tag_counts.size forum_tags_num = Forum.tag_counts.size attachment_tags_num = Attachment.tag_counts.size + @open_source_projects_num = OpenSourceProject.tag_counts.size @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 + return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num, @open_source_projects_num end # 通过数字 来转换出对象的类型 @@ -269,6 +277,8 @@ class TagsController < ApplicationController return 'Attachment' when '7' return 'Contest' + when '8' + return 'OpenSourceProject' else render_error :message => e.message return diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5d59a44fc..d4248e3cc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -658,6 +658,8 @@ class UsersController < ApplicationController @obj = Attachment.find_by_id(@obj_id) when '7' then @obj = Contest.find_by_id(@obj_id) + when '8' + @obj = OpenSourceProject.find_by_id(@obj_id) else @obj = nil end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 859b19655..aeacae866 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -442,6 +442,10 @@ module ApplicationHelper def authoring(created, author, options={}) l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe end + + def added_time(created) + l(:label_added_time, :age => time_tag(created)).html_safe + end #huang def betweentime(enddate) diff --git a/app/helpers/apply_project_masters_helper.rb b/app/helpers/apply_project_masters_helper.rb new file mode 100644 index 000000000..565f8ea04 --- /dev/null +++ b/app/helpers/apply_project_masters_helper.rb @@ -0,0 +1,31 @@ +module ApplyProjectMastersHelper + def apply_super_user(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + applied = objects.any? {|object| object.applied_by?(user)} + allowed = objects.any? {|object| object.allowed?(user)} + # @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Bid))) + # css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) : + # ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s) + + css = apply_css(objects) << options[0].to_s + + text = applied ? (allowed ? l(:you_are_master) : l(:cancel_apply)) : l(:apply_master) + + url = apply_project_masters_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = applied ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method, :class => css + end + + def apply_css(objects) + objects = Array.wrap(objects) + id = (objects.size == 1 ? objects.first.id : 'bulk') + "#{objects.first.class.to_s.underscore}-#{id}-watcher" + end + +end diff --git a/app/helpers/no_uses_helper.rb b/app/helpers/no_uses_helper.rb new file mode 100644 index 000000000..2baaf23b6 --- /dev/null +++ b/app/helpers/no_uses_helper.rb @@ -0,0 +1,28 @@ +module NoUsesHelper + def no_use_link(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + clicked = objects.any? {|object| object.no_use_for?(user)} + # @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Bid))) + css = no_use_css(objects) << options[0].to_s + # ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s) + + text = clicked ? l(:cancel_no_use) : l(:no_use) + + url = no_uses_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = clicked ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method, :class => css + #, :class => css + end + + def no_use_css(objects) + objects = Array.wrap(objects) + id = (objects.size == 1 ? objects.first.id : 'bulk') + "#{objects.first.class.to_s.underscore}-#{id}-watcher" + end +end diff --git a/app/helpers/open_source_projects_helper.rb b/app/helpers/open_source_projects_helper.rb new file mode 100644 index 000000000..f758580d9 --- /dev/null +++ b/app/helpers/open_source_projects_helper.rb @@ -0,0 +1,37 @@ +module OpenSourceProjectsHelper + def show_condition(app_dir, language, created_at, name) + s=''.html_safe + unless app_dir.nil? + s_temp = content_tag('a', app_dir) + temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :language => language, :created_at => created_at, :name => name} + temp = content_tag('span', temp, :class => 'del') + s_temp << temp + s_temp = content_tag('span', s_temp, :class => 'tag_show') + s << content_tag('div', s_temp, :id => 'tag') + + end + unless language.nil? + s_temp = content_tag('a', language) + temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :app_dir => app_dir, :created_at => created_at, :name => name} + temp = content_tag('span', temp, :class => 'del') + s_temp << temp + s_temp = content_tag('span', s_temp, :class => 'tag_show') + s << content_tag('div', s_temp, :id => 'tag') + end + unless created_at.nil? + s_temp = content_tag('a', created_at) + temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :app_dir => app_dir, :language => language, :name => name} + temp = content_tag('span', temp, :class => 'del') + s_temp << temp + s_temp = content_tag('span', s_temp, :class => 'tag_show') + s << content_tag('div', s_temp, :id => 'tag') + end + s = content_tag('div', s, :id => 'tags_show') + s = content_tag('div', s, :id => 'tags') + s = content_tag('div', s, :class => 'user_tags') + end + + def get_open_source_projects_by_tag(tag_name) + OpenSourceProject.tagged_with(tag_name).order('created_at desc') + end +end diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 43ee05db8..d9ab8730a 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -297,6 +297,14 @@ module UserScoreHelper return (commit_count + issue_details_count) end + + + def calculate_attachments(user) + attachments = Attachment.where("container_type IS NOT NULL AND container_type <> 'Issue' AND author_id = ?", user.id).count + + return attachments + + end def calculate_user_score(user) collaboration = calculate_collaboration_count(user) diff --git a/app/models/apply_project_master.rb b/app/models/apply_project_master.rb new file mode 100644 index 000000000..13bd2f372 --- /dev/null +++ b/app/models/apply_project_master.rb @@ -0,0 +1,16 @@ +class ApplyProjectMaster < ActiveRecord::Base + # attr_accessible :title, :body + # status 1是申请者,2是版主 + belongs_to :apply, :polymorphic => true + belongs_to :user + + validates_presence_of :user + validates_uniqueness_of :user_id, :scope => [:apply_type, :apply_id] + validate :validate_user + + protected + + def validate_user + errors.add :user_id, :invalid unless user.nil? || user.active? + end +end diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index 5b818cc28..f428c5d81 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -52,7 +52,12 @@ class IssueQuery < Query def initialize(attributes=nil, *args) super attributes - self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} } +# self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} } + + #gcm + self.filters ||= { 'subject' => {:operator => "~" , :values => [""] } } + #gcmend + end # Returns true if the query is visible to +user+ or the current user. diff --git a/app/models/no_use.rb b/app/models/no_use.rb new file mode 100644 index 000000000..a46e519e8 --- /dev/null +++ b/app/models/no_use.rb @@ -0,0 +1,15 @@ +class NoUse < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :no_use, :polymorphic => true + belongs_to :user + + validates_presence_of :user + validates_uniqueness_of :user_id, :scope => [:no_use_type, :no_use_id] + validate :validate_user + + protected + + def validate_user + errors.add :user_id, :invalid unless user.nil? || user.active? + end +end diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb new file mode 100644 index 000000000..e526dc921 --- /dev/null +++ b/app/models/open_source_project.rb @@ -0,0 +1,134 @@ +class OpenSourceProject < ActiveRecord::Base + attr_accessible :name + + include Redmine::SafeAttributes + has_many :applies, :class_name => "ApplyProjectMaster", :as => :apply, :dependent => :delete_all + has_many :topics, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :conditions => "#{RelativeMemo.table_name}.parent_id IS NULL", :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy + has_many :relative_memos, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :dependent => :destroy + has_many :tags, :through => :project_tags, :class_name => 'Tag' + has_many :project_tags, :class_name => 'ProjectTags' + has_many :masters, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 2" + has_many :admin, :through => :masters, :class_name => 'User' + has_many :apply_tips, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 1" + has_many :applicants, :class_name => 'User', :through => :apply_tips, :source => :user + + validates_uniqueness_of :name + + acts_as_taggable + + scope :applied_by, lambda { |user_id| + { :include => :apply_project_master, + :conditions => ["#{ApplyProjectMaster.table_name}.user_id = ?", user_id] + } + } + scope :like, lambda {|arg| + if arg.blank? + where(nil) + else + pattern = "%#{arg.to_s.strip.downcase}%" + where("LOWER(name) LIKE :p OR LOWER(description) LIKE :p ", :p => pattern) + end + } + def filter(app_dir, language, created_at) + filter_app_dir(app_dir).filter_language(language).filter_time(created_at) + end + + def self.filter(app_dir, language, created_at) + self.filter_app_dir(app_dir).filter_language(language).filter_time(created_at) + end + + scope :filter_app_dir, lambda {|args| + nil + } + + scope :filter_language, lambda {|*arg| + if arg[0].nil? + where(nil) + else + tagged_with(arg).order('updated_at desc') + end + } + + scope :filter_time, lambda {|args| + where("YEAR(#{OpenSourceProject.table_name}.created_at) = ?", args) unless args.nil? + } + + # def filter_app_dir(app_dir) + # nil + # end + # + # def self.filter_app_dir(app_dir) + # nil + # end + # + # def filter_language(language) + # nil + # end + # + # def self.filter_language(language) + # nil + # end + # + # def filter_time(created_at) + # nil + # end + # + # def self.filter_time(created_at) + # nil + # end + + def short_description(length = 255) + description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + end + + def applied_by?(user) + self.applies.each do |apply| + if apply.user_id == user.id + return true + end + end + false + end + + def allowed?(user) + self.applies.each do |apply| + if apply.user_id == user.id and apply.status == 2 + return true + end + end + false + end + + def set_apply(user, flag=true) + flag ? set_filter(user) : remove_filter(user) + end + + def set_filter(user) + self.applies << ApplyProjectMaster.new(:user => user, :status => 1) + end + + def remove_filter(user) + return nil unless user && user.is_a?(User) + ApplyProjectMaster.delete_all "apply_type = '#{self.class}' AND apply_id = #{self.id} AND user_id = #{user.id}" + end + + def admin?(user) + if user.admin? or ApplyProjectMaster.find(:all, :conditions => ["user_id = ? and apply_type = 'OpenSourceProject' and apply_id = ? and status = ?", user.id, self.id, 2]).present? + return true + else + return false + end + end + + def reset_counters! + self.class.reset_counters!(id) + end + + def self.reset_counters!(id) + osp_id = id.to_i + update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NULL)," + + " memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," + + " last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})", + ["id = ?", osp_id]) + end +end diff --git a/app/models/query.rb b/app/models/query.rb index db6ca07a5..550047c57 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -233,7 +233,13 @@ class Query < ActiveRecord::Base # filter requires one or more values (values_for(field) and !values_for(field).first.blank?) or # filter doesn't require any value - ["o", "c", "!*", "*", "t", "ld", "w", "lw", "l2w", "m", "lm", "y"].include? operator_for(field) + ["o", "c", "!*", "*", "t", "ld", "w", "lw", "l2w", "m", "lm", "y"].include? operator_for(field) or + + #gcm + #subject could be null + (field.eql?"subject") + #gcmend + end if filters end diff --git a/app/models/relative_memo.rb b/app/models/relative_memo.rb new file mode 100644 index 000000000..24504241e --- /dev/null +++ b/app/models/relative_memo.rb @@ -0,0 +1,185 @@ +class RelativeMemo < ActiveRecord::Base + # attr_accessible :title, :body + include Redmine::SafeAttributes + belongs_to :open_source_project, :class_name => "OpenSourceProject", :foreign_key => 'osp_id' + belongs_to :author, :class_name => "User", :foreign_key => 'author_id' + + has_many :tags, :through => :project_tags, :class_name => 'Tag' + has_many :project_tags, :class_name => 'ProjectTags' + + has_many :no_uses, :as => :no_use, :dependent => :delete_all + + acts_as_taggable + acts_as_attachable + + validates_presence_of :osp_id, :subject + #validates :content, presence: true + # validates_length_of :subject, maximum: 50 + #validates_length_of :content, maximum: 3072 + validate :cannot_reply_to_locked_topic, :on => :create + validates_uniqueness_of :osp_id, :scope => [:subject, :content] + + acts_as_tree :counter_cache => :replies_count, :order => "#{RelativeMemo.table_name}.created_at ASC" + acts_as_attachable + belongs_to :last_reply, :class_name => 'RelativeMemo', :foreign_key => 'last_reply_id' + # acts_as_searchable :column => ['subject', 'content'], + # #: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, + # # :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}"})} + # acts_as_activity_provider :author_key => :author_id, + # :func => 'memos', + # :timestamp => 'created_at' + + # :find_options => {:type => 'memos'} + # acts_as_watchable + + safe_attributes "author_id", + "subject", + "content", + "osp_id", + "last_memo_id", + "lock", + "sticky", + "parent_id", + "replies_count", + "is_quote" + + after_create :add_author_as_watcher, :reset_counters! + # after_update :update_memos_forum + after_destroy :reset_counters! + # after_create :send_notification + # after_save :plusParentAndForum + # after_destroy :minusParentAndForum + + # scope :visible, lambda { |*args| + # includes(:forum => ).where() + # } + + def cannot_reply_to_locked_topic + errors.add :base, l(:label_memo_locked) if root.locked? && self != root + end + + # def update_memos_forum + # if forum_id_changed? + # Message.update_all({:board_id => board_id}, ["id = ? OR parent_id = ?", root.id, root.id ]) + # Forum.reset_counters!(forum_id_was) + # Forum.reset_counters!(forum_id) + # end + # end + + + scope :no_use_for, lambda { |user_id| + { :include => :no_uses, + :conditions => ["#{NoUse.table_name}.user_id = ?", user_id] } + } + + def no_use_for?(user) + self.no_uses.each do |no_use| + if no_use.user_id == user.id + return true + end + end + false + end + + def set_no_use(user, flag=true) + flag ? set_filter(user) : remove_filter(user) + end + + def set_filter(user) + self.no_uses << NoUse.new(:user => user) + end + + def remove_filter(user) + return nil unless user && user.is_a?(User) + NoUse.delete_all "no_use_type = '#{self.class}' AND no_use_id = #{self.id} AND user_id = #{user.id}" + end + + def reset_counters! + if parent && parent.id + RelativeMemo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id}) + parent.update_attribute(:updated_at, Time.now) + end + # forum.reset_counters! + end + + def sticky? + sticky == 1 + end + + def replies + RelativeMemo.where("parent_id = ?", id) + end + + def locked? + self.lock + end + + def editable_by? user + # user && user.logged? || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)) + user.admin? + end + + # def destroyable_by? user + # (user && user.logged? && (Forum.find(self.forum_id).creator_id == user.id) ) || user.admin? + # #self.author == user || user.admin? + # end + + def deleted_attach_able_by? user + (user && user.logged? && (self.author == user) ) || user.admin? + end + + private + + def add_author_as_watcher + Watcher.create(:watchable => self.root, :user => author) + end + + def send_notification + if Setting.notified_events.include?('message_posted') + Mailer.message_posted(self).deliver + end + end + + # def plusParentAndForum + # @forum = Forum.find(self.forum_id) + # @forum.memo_count = @forum.memo_count.to_int + 1 + # @forum.last_memo_id = self.id + # if self.parent_id + # @parent_memo = Memo.find_by_id(self.parent_id) + # @parent_memo.last_reply_id = self + # @parent_memo.replies_count = @parent_memo.replies_count.to_int + 1 + # @parent_memo.save + # else + # @forum.topic_count = @forum.topic_count.to_int + 1 + # end + # @forum.save + # end + + # def minusParentAndForum + # @forum = Forum.find(self.forum_id) + # @forum.memo_count = @forum.memo_count.to_int - 1 + # @forum.memo_count = 0 if @forum.memo_count.to_int < 0 + # # @forum.last_memo_id = Memo.reorder('created_at ASC').find_all_by_forum_id(self.forum_id).last.id + # if self.parent_id + # @parent_memo = Memo.find_by_id(self.parent_id) + # # @parent_memo.last_reply_id = Memo.reorder('created_at ASC').find_all_by_parent_id(self.parent_id).last.id + # @parent_memo.replies_count = @parent_memo.replies_count.to_int - 1 + # @parent_memo.replies_count = 0 if @parent_memo.replies_count.to_int < 0 + # @parent_memo.save + # else + # @forum.topic_count = @forum.topic_count.to_int - 1 + # @forum.topic_count = 0 if @forum.topic_count.to_int < 0 + # end + # @forum.save + # end +end + diff --git a/app/views/apply_project_masters/_form.html.erb b/app/views/apply_project_masters/_form.html.erb new file mode 100644 index 000000000..f817c1bcf --- /dev/null +++ b/app/views/apply_project_masters/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@apply_project_master) do |f| %> + <% if @apply_project_master.errors.any? %> +
+

<%= pluralize(@apply_project_master.errors.count, "error") %> prohibited this apply_project_master from being saved:

+ + +
+ <% end %> + +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/apply_project_masters/_set_apply.js.erb b/app/views/apply_project_masters/_set_apply.js.erb new file mode 100644 index 000000000..2c2075743 --- /dev/null +++ b/app/views/apply_project_masters/_set_apply.js.erb @@ -0,0 +1,2 @@ +<% selector = ".#{apply_css(objects)}" %> +$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript apply_super_user(objects, user) %>")}); diff --git a/app/views/apply_project_masters/edit.html.erb b/app/views/apply_project_masters/edit.html.erb new file mode 100644 index 000000000..47d85b99c --- /dev/null +++ b/app/views/apply_project_masters/edit.html.erb @@ -0,0 +1,6 @@ +

Editing apply_project_master

+ +<%= render 'form' %> + +<%= link_to 'Show', @apply_project_master %> | +<%= link_to 'Back', apply_project_masters_path %> diff --git a/app/views/apply_project_masters/index.html.erb b/app/views/apply_project_masters/index.html.erb new file mode 100644 index 000000000..16023cd83 --- /dev/null +++ b/app/views/apply_project_masters/index.html.erb @@ -0,0 +1,21 @@ +

Listing apply_project_masters

+ + + + + + + + +<% @apply_project_masters.each do |apply_project_master| %> + + + + + +<% end %> +
<%= link_to 'Show', apply_project_master %><%= link_to 'Edit', edit_apply_project_master_path(apply_project_master) %><%= link_to 'Destroy', apply_project_master, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Apply project master', new_apply_project_master_path %> diff --git a/app/views/apply_project_masters/new.html.erb b/app/views/apply_project_masters/new.html.erb new file mode 100644 index 000000000..7cdcac28b --- /dev/null +++ b/app/views/apply_project_masters/new.html.erb @@ -0,0 +1,5 @@ +

New apply_project_master

+ +<%= render 'form' %> + +<%= link_to 'Back', apply_project_masters_path %> diff --git a/app/views/apply_project_masters/show.html.erb b/app/views/apply_project_masters/show.html.erb new file mode 100644 index 000000000..a7edc11ff --- /dev/null +++ b/app/views/apply_project_masters/show.html.erb @@ -0,0 +1,5 @@ +

<%= notice %>

+ + +<%= link_to 'Edit', edit_apply_project_master_path(@apply_project_master) %> | +<%= link_to 'Back', apply_project_masters_path %> diff --git a/app/views/auto_completes/issues.html.erb b/app/views/auto_completes/issues.html.erb index e292bbaeb..b097eaff4 100644 --- a/app/views/auto_completes/issues.html.erb +++ b/app/views/auto_completes/issues.html.erb @@ -3,5 +3,5 @@ 'label' => "#{issue.tracker} ##{issue.id}: #{truncate issue.subject.to_s, :length => 60}", 'value' => issue.id } - }.to_json + }.to_json %> diff --git a/app/views/forums/_show_topics.html.erb b/app/views/forums/_show_topics.html.erb index 7f8017897..057d6a258 100644 --- a/app/views/forums/_show_topics.html.erb +++ b/app/views/forums/_show_topics.html.erb @@ -5,7 +5,7 @@ <% if memos.any? %> <% memos.each do |topic| %> - +
<%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) %>
<%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%> diff --git a/app/views/issues/_form.html.erb b/app/views/issues/_form.html.erb index 0e3cee1ff..8f9554107 100644 --- a/app/views/issues/_form.html.erb +++ b/app/views/issues/_form.html.erb @@ -14,7 +14,8 @@ <% if @issue.safe_attribute? 'tracker_id' %>

<%= f.select :tracker_id, @issue.project.trackers.collect {|t| [t.name, t.id]}, {:required => true}, - :onchange => "updateIssueFrom('#{escape_javascript project_issue_form_path(@project, :id => @issue, :format => 'js')}')" %>

+ :onchange => "updateIssueFrom('#{escape_javascript project_issue_form_path(@project, :id => @issue, :format => 'js')}')" %>

+ <% end %> diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index 9df56ee2f..ee7bcecf0 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -11,16 +11,16 @@ <%= link_to "国防科学技术大学并行与分布处理国家重点实验室","http://www.nudt.edu.cn/ArticleShow.asp?ID=47",:target=>"_blank"%><%= link_to "计算机科学与技术系", "http://www.nudt.edu.cn/ArticleShow.asp?ID=41", :target => "_blank" %>版权@2007~2014 - <%= link_to "联系我们","http://forge.trustie.net/projects/2/member",:target=>"_blank"%> - <%= link_to "湘ICP备09019772","http://www.miibeian.gov.cn/"%> + <%= link_to "联系我们","http://forge.trustie.net/projects/2/member", :target=>"_blank" %> + <%= link_to "湘ICP备09019772","http://www.miibeian.gov.cn/", :target => "_blank" %>

diff --git a/app/views/layouts/_base_softapplication_index_top_content.html.erb b/app/views/layouts/_base_softapplication_index_top_content.html.erb index 0a41036f1..93b177b99 100644 --- a/app/views/layouts/_base_softapplication_index_top_content.html.erb +++ b/app/views/layouts/_base_softapplication_index_top_content.html.erb @@ -3,7 +3,7 @@ -
创新竞赛社区 <%= l(:label_user_location) %> : +