2014-03-29 10:57:36 +08:00
|
|
|
class OpenSourceProjectsController < ApplicationController
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-22 10:16:50 +08:00
|
|
|
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]
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-03 14:41:04 +08:00
|
|
|
helper :sort
|
|
|
|
include SortHelper
|
2014-04-03 20:47:09 +08:00
|
|
|
helper :apply_project_masters
|
|
|
|
include ApplyProjectMastersHelper
|
|
|
|
helper :no_uses
|
|
|
|
include NoUsesHelper
|
2014-03-29 10:57:36 +08:00
|
|
|
# GET /open_source_projects
|
|
|
|
# GET /open_source_projects.json
|
|
|
|
def index
|
2014-05-29 20:48:51 +08:00
|
|
|
|
2014-04-06 22:12:16 +08:00
|
|
|
@app_dir = params[:app_dir]
|
|
|
|
@language = params[:language]
|
|
|
|
@created_at = params[:created_at]
|
2014-03-29 10:57:36 +08:00
|
|
|
per_page_option = 10
|
|
|
|
|
2014-04-08 09:02:12 +08:00
|
|
|
@open_source_projects = OpenSourceProject.filter(@app_dir, @language, @created_at)
|
2014-04-22 08:21:35 +08:00
|
|
|
@open_source_projects = @open_source_projects.like(params[:name]) if params[:name].present?
|
2014-03-29 10:57:36 +08:00
|
|
|
|
|
|
|
@os_project_count = @open_source_projects.count
|
|
|
|
@os_project_pages = Paginator.new @os_project_count, per_page_option, params['page']
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-08 09:02:12 +08:00
|
|
|
@open_source_projects = @open_source_projects.offset(@os_project_pages.offset).limit(@os_project_pages.per_page)
|
2014-05-29 20:48:51 +08:00
|
|
|
|
|
|
|
@bugs = BugToOsp.order('created_at desc').limit(8)
|
2014-03-29 10:57:36 +08:00
|
|
|
|
2014-04-08 09:02:12 +08:00
|
|
|
# @open_source_projects = OpenSourceProject.all
|
2014-03-29 10:57:36 +08:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
|
|
|
format.json { render json: @open_source_projects }
|
|
|
|
end
|
|
|
|
end
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-06 22:12:16 +08:00
|
|
|
def master_apply
|
|
|
|
@apply = @open_source_project.apply_tips
|
|
|
|
@applicants = @open_source_project.applicants
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-06 22:12:16 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => "base_opensource_p"
|
|
|
|
}
|
|
|
|
format.json { render json: @open_source_project }
|
|
|
|
end
|
|
|
|
end
|
2014-03-29 10:57:36 +08:00
|
|
|
|
|
|
|
# GET /open_source_projects/1
|
|
|
|
# GET /open_source_projects/1.json
|
|
|
|
def show
|
|
|
|
@open_source_project = OpenSourceProject.find(params[:id])
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-03 14:41:04 +08:00
|
|
|
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
|
2014-05-14 12:03:50 +08:00
|
|
|
@topic_pages = Paginator.new @topic_count, 10, params['page']
|
2014-04-03 14:41:04 +08:00
|
|
|
@memos = @open_source_project.topics.
|
|
|
|
reorder("#{RelativeMemo.table_name}.sticky DESC").
|
|
|
|
includes(:last_reply).
|
|
|
|
limit(@topic_pages.per_page).
|
|
|
|
offset(@topic_pages.offset).
|
2014-05-27 09:01:36 +08:00
|
|
|
order(sort_clause).
|
2014-04-03 14:41:04 +08:00
|
|
|
all
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-05-22 17:04:45 +08:00
|
|
|
@bugs = @open_source_project.bugs.limit(6)
|
2014-04-03 14:41:04 +08:00
|
|
|
|
2014-03-29 10:57:36 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => "base_opensource_p"
|
|
|
|
}
|
|
|
|
format.json { render json: @open_source_project }
|
|
|
|
end
|
|
|
|
end
|
2014-05-29 21:42:56 +08:00
|
|
|
|
|
|
|
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
|
2014-05-14 12:03:50 +08:00
|
|
|
|
2014-05-27 09:01:36 +08:00
|
|
|
def search
|
2014-05-14 12:03:50 +08:00
|
|
|
|
2014-03-29 10:57:36 +08:00
|
|
|
end
|
|
|
|
|
2014-05-27 09:01:36 +08:00
|
|
|
def showbug
|
|
|
|
@open_source_project = OpenSourceProject.find(params[:id])
|
2014-05-14 12:03:50 +08:00
|
|
|
|
2014-05-27 09:01:36 +08:00
|
|
|
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)"
|
2014-05-14 12:03:50 +08:00
|
|
|
|
2014-05-27 09:01:36 +08:00
|
|
|
@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
|
|
|
|
|
|
|
|
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",
|
2014-05-14 12:03:50 +08:00
|
|
|
'replies' => "#{RelativeMemo.table_name}.replies_count",
|
|
|
|
'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)"
|
|
|
|
|
2014-05-27 09:01:36 +08:00
|
|
|
@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.
|
2014-05-14 12:03:50 +08:00
|
|
|
reorder("#{RelativeMemo.table_name}.sticky DESC").
|
|
|
|
includes(:last_reply).
|
|
|
|
limit(@topic_pages.per_page).
|
|
|
|
offset(@topic_pages.offset).
|
|
|
|
order(sort_clause).
|
|
|
|
all
|
|
|
|
|
2014-05-27 09:01:36 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => "base_opensource_p"
|
|
|
|
}
|
|
|
|
format.json { render json: @open_source_project }
|
|
|
|
end
|
2014-05-14 12:03:50 +08:00
|
|
|
end
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-03-29 10:57:36 +08:00
|
|
|
# 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
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-22 08:21:35 +08:00
|
|
|
def remove_condition
|
|
|
|
@app_dir = params[:app_dir]
|
|
|
|
@language = params[:language]
|
|
|
|
@created_at = params[:created_at]
|
2014-10-15 09:54:54 +08:00
|
|
|
redirect_to open_source_projects_url(:app_dir => @app_dir, :language => @language, :created_at => @created_at, :name => params[:name])
|
2014-04-22 08:21:35 +08:00
|
|
|
end
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-22 08:21:35 +08:00
|
|
|
def search
|
2014-04-22 10:16:50 +08:00
|
|
|
# per_page_option = 10
|
2014-05-27 09:01:36 +08:00
|
|
|
#
|
2014-04-22 10:16:50 +08:00
|
|
|
# @open_source_projects = OpenSourceProject.filter(@app_dir, @language, @created_at)
|
|
|
|
# @open_source_projects = @open_source_projects.like(params[:name]) if params[:name].present?
|
2014-05-27 09:01:36 +08:00
|
|
|
#
|
2014-04-22 10:16:50 +08:00
|
|
|
# @os_project_count = @open_source_projects.count
|
|
|
|
# @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page']
|
2014-05-27 09:01:36 +08:00
|
|
|
#
|
2014-04-22 10:16:50 +08:00
|
|
|
# @open_source_projects = @open_source_projects.offset(@os_project_pages.offset).limit(@os_project_pages.per_page)
|
2014-04-22 08:21:35 +08:00
|
|
|
|
2014-10-15 09:54:54 +08:00
|
|
|
redirect_to open_source_projects_url(:name => params[:name])
|
2014-04-22 08:21:35 +08:00
|
|
|
|
|
|
|
end
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-22 10:16:50 +08:00
|
|
|
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
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-10-15 09:54:54 +08:00
|
|
|
redirect_to master_apply_open_source_project_url
|
2014-04-22 10:16:50 +08:00
|
|
|
end
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-22 10:16:50 +08:00
|
|
|
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
|
2014-05-27 09:01:36 +08:00
|
|
|
@apply.first.update_attributes(:status => 2)
|
2014-04-22 10:16:50 +08:00
|
|
|
end
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-10-15 09:54:54 +08:00
|
|
|
redirect_to master_apply_open_source_project_url
|
2014-04-22 10:16:50 +08:00
|
|
|
end
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-06 22:12:16 +08:00
|
|
|
private
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-06 22:12:16 +08:00
|
|
|
def require_master
|
|
|
|
render_403 unless @open_source_project.admin?(User.current)
|
|
|
|
end
|
2014-05-27 09:01:36 +08:00
|
|
|
|
2014-04-06 22:12:16 +08:00
|
|
|
def find_osp
|
|
|
|
@open_source_project = OpenSourceProject.find(params[:id])
|
|
|
|
render_404 unless @open_source_project.present?
|
|
|
|
end
|
2014-03-29 10:57:36 +08:00
|
|
|
end
|