@ -1,8 +1,8 @@
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
@ -12,6 +12,7 @@ class OpenSourceProjectsController < ApplicationController
# GET /open_source_projects
# GET /open_source_projects.json
def index
@app_dir = params [ :app_dir ]
@language = params [ :language ]
@created_at = params [ :created_at ]
@ -22,8 +23,10 @@ class OpenSourceProjectsController < ApplicationController
@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 )
@bugs = BugToOsp . order ( 'created_at desc' ) . limit ( 8 )
# @open_source_projects = OpenSourceProject.all
@ -32,11 +35,11 @@ class OpenSourceProjectsController < ApplicationController
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 "
@ -49,7 +52,7 @@ class OpenSourceProjectsController < ApplicationController
# 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 " ,
@ -63,9 +66,9 @@ class OpenSourceProjectsController < ApplicationController
includes ( :last_reply ) .
limit ( @topic_pages . per_page ) .
offset ( @topic_pages . offset ) .
order ( sort_clause ) .
order ( sort_clause ) .
all
@bugs = @open_source_project . bugs . limit ( 6 )
respond_to do | format |
@ -75,26 +78,64 @@ class OpenSourceProjectsController < ApplicationController
format . json { render json : @open_source_project }
end
end
def allbug
@bugs = BugToOsp . visible
@bug_count = @bugs . count
@bug_pages = Paginator . new @bug_count , per_page_option , params [ 'page' ]
@bugs = @bugs . includes ( :bug ) . reorder ( " #{ RelativeMemo . table_name } .created_at DESC " ) . limit ( @bug_pages . per_page ) . offset ( @bug_pages . offset ) . all
respond_to do | format |
format . html
format . json { render json : @open_source_project }
end
end
def search
def search
end
def showbug
@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) "
# added by yiang 暴力添加,请绕道
def showmemo
@open_source_project = OpenSourceProject . find ( params [ :id ] )
@memo = RelativeMemo . new ( :open_source_project = > @open_source_project )
@topic_count = @open_source_project . bugs . count
@topic_pages = Paginator . new @topic_count , per_page_option , params [ 'page' ]
@memos = @open_source_project . bugs .
reorder ( " #{ RelativeMemo . table_name } .sticky DESC " ) .
includes ( :last_reply ) .
limit ( @topic_pages . per_page ) .
offset ( @topic_pages . offset ) .
order ( sort_clause ) .
all
sort_init 'updated_at' , 'desc'
sort_update 'created_at' = > " #{ RelativeMemo . table_name } .created_at " ,
respond_to do | format |
format . html {
render :layout = > " base_opensource_p "
}
format . json { render json : @open_source_project }
end
end
# added by yiang 暴力添加,请绕道
def showmemo
@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 .
@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 ) .
@ -102,13 +143,14 @@ def showmemo
order ( sort_clause ) .
all
respond_to do | format |
format . html {
render :layout = > " base_opensource_p "
}
format . json { render json : @open_source_project }
respond_to do | format |
format . html {
render :layout = > " base_opensource_p "
}
format . json { render json : @open_source_project }
end
end
end
# GET /open_source_projects/new
# GET /open_source_projects/new.json
def new
@ -168,52 +210,51 @@ end
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 )
@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?