2014-09-15 10:58:14 +08:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class WelcomeController < ApplicationController
|
2015-05-27 17:40:18 +08:00
|
|
|
# layout "base_welcome"
|
2014-09-15 10:58:14 +08:00
|
|
|
include ApplicationHelper
|
|
|
|
include WelcomeHelper
|
|
|
|
helper :project_score
|
2015-05-28 15:14:38 +08:00
|
|
|
caches_action :robots, :course, :contest, expires_in: 2.hours, layout: false
|
2015-03-18 09:25:26 +08:00
|
|
|
#before_filter :find_first_page, :only => [:index]
|
2014-09-15 10:58:14 +08:00
|
|
|
# before_filter :fake, :only => [:index, :course]
|
|
|
|
before_filter :entry_select, :only => [:index]
|
|
|
|
|
|
|
|
def index
|
2015-02-03 11:24:46 +08:00
|
|
|
# 企业版定制: params[:project]为传过来的参数
|
2015-08-29 15:25:58 +08:00
|
|
|
redirect_to signin_path
|
|
|
|
return
|
2015-05-28 15:14:38 +08:00
|
|
|
unless params[:organization].nil?
|
|
|
|
@organization = Organization.find params[:organization]
|
|
|
|
# @organization_projects = Project.joins(:project_status).joins("LEFT JOIN project_scores ON projects.id = project_scores.project_id").where("projects.organization_id = ?", @organization.id).order("score DESC").limit(10).all
|
|
|
|
@organization_projects = @organization.projects.visible.joins("LEFT JOIN project_scores ON projects.id = project_scores.project_id").order("project_scores.score DESC").limit(10).all
|
|
|
|
@part_projects = @organization_projects.count < 9 ? find_miracle_project( 9 - @organization_projects.count, 3,"score desc") : []
|
|
|
|
# @cur_projects = Project.find(params[:organization])
|
|
|
|
# @organization = @cur_projects.enterprise_name
|
|
|
|
# @organization_projects = (current_user.admin? || User.current.member_of?(@cur_projects)) ? Project.where("enterprise_name =? ", @organization) : Project.all_public.where("enterprise_name =? ", @organization)
|
|
|
|
# @e_count = @organization_projects.count
|
|
|
|
# @part_projects = []
|
|
|
|
# # 取十个
|
|
|
|
# @organization_projects.each do |obj|
|
|
|
|
# break if(@organization_projects[10] == obj)
|
|
|
|
# @part_projects << Project.visible.find_by_id("#{obj.id}") unless obj.id.nil?
|
|
|
|
# end
|
|
|
|
# # 不够十个的用最火项目替代
|
|
|
|
# @e_count < 9 ? @part_projects = find_miracle_project( 9 - @e_count, 3,"score desc") : @part_projects
|
|
|
|
# # 配置文件首页定制
|
|
|
|
@enterprise_page = FirstPage.find_by_page_type('enterprise')
|
|
|
|
if @enterprise_page.nil?
|
|
|
|
@enterprise_page = FirstPage.new
|
|
|
|
@enterprise_page.page_type = 'enterprise'
|
|
|
|
end
|
|
|
|
# 主页配置部分结束
|
2015-01-31 17:14:01 +08:00
|
|
|
end
|
2015-05-28 15:14:38 +08:00
|
|
|
# end 企业版定制结束
|
2015-03-05 10:40:10 +08:00
|
|
|
|
2015-05-28 15:14:38 +08:00
|
|
|
if @first_page.nil? || @first_page.sort_type.nil?
|
|
|
|
@projects = find_miracle_project(10, 3,"score desc")
|
|
|
|
else
|
|
|
|
case @first_page.sort_type
|
|
|
|
when 0
|
|
|
|
@my_projects = find_my_projects
|
|
|
|
@other_projects = @my_projects.count < 9 ? find_miracle_project( 9 - @my_projects.count, 3,"score desc") : []
|
|
|
|
@projects = find_miracle_project(10, 3,"created_on desc")
|
|
|
|
#@projects = @projects_all.order("created_on desc")
|
|
|
|
when 1
|
|
|
|
@my_projects = find_my_projects
|
|
|
|
@other_projects = @my_projects.count < 9 ? find_miracle_project( 9 - @my_projects.count, 3,"score desc") : []
|
|
|
|
@projects = find_miracle_project(10, 3,"score desc")
|
|
|
|
#@projects = @projects_all.order("grade desc")
|
|
|
|
when 2
|
|
|
|
@my_projects = find_my_projects
|
|
|
|
@other_projects = @my_projects.count < 9 ? find_miracle_project( 9 - @my_projects.count, 3,"score desc") : []
|
|
|
|
@projects = find_miracle_project(10, 3,"watchers_count desc")
|
|
|
|
#@projects = @projects_all.order("watchers_count desc")
|
2014-09-15 10:58:14 +08:00
|
|
|
|
2015-05-28 15:14:38 +08:00
|
|
|
#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]
|
2014-09-15 10:58:14 +08:00
|
|
|
|
2015-05-28 15:14:38 +08:00
|
|
|
else
|
|
|
|
@projects = @projects_all.order("score desc")
|
|
|
|
end
|
2014-09-15 10:58:14 +08:00
|
|
|
end
|
2015-05-28 15:14:38 +08:00
|
|
|
|
2015-03-05 10:40:10 +08:00
|
|
|
rescue Exception => e
|
|
|
|
render_404
|
2014-09-15 10:58:14 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def robots
|
|
|
|
@projects = Project.all_public.active
|
|
|
|
render :layout => false, :content_type => 'text/plain'
|
|
|
|
end
|
2015-08-29 19:15:06 +08:00
|
|
|
|
2014-09-15 10:58:14 +08:00
|
|
|
def course
|
2015-08-29 19:03:36 +08:00
|
|
|
redirect_to signin_path
|
|
|
|
return
|
2015-08-29 19:15:06 +08:00
|
|
|
#
|
|
|
|
# @course_page = FirstPage.find_by_page_type('course')
|
|
|
|
# @school_id = params[:school_id] || User.current.user_extensions.school.try(:id) || 117
|
|
|
|
# @logoLink ||= logolink()
|
2014-09-15 10:58:14 +08:00
|
|
|
end
|
2015-01-04 13:28:33 +08:00
|
|
|
|
|
|
|
def logolink()
|
|
|
|
@course_page = FirstPage.find_by_page_type('course')
|
|
|
|
logo = get_avatar?(@course_page)
|
2014-09-15 10:58:14 +08:00
|
|
|
id = params[:school_id]
|
|
|
|
logo_link = ""
|
|
|
|
if id.nil? && (User.current.user_extensions.nil? || User.current.user_extensions.school.nil?)
|
|
|
|
if logo
|
|
|
|
logo_link = url_to_avatar(@course_page)
|
|
|
|
else
|
|
|
|
logo_link = '/images/transparent.png'
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
if id == "0"
|
|
|
|
if logo
|
|
|
|
logo_link = url_to_avatar(@course_page)
|
|
|
|
else
|
|
|
|
logo_link = '/images/transparent.png'
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if id.nil?
|
|
|
|
if School.find(User.current.user_extensions.school.id).logo_link.nil?
|
|
|
|
logo_link = '/images/transparent.png'
|
|
|
|
else
|
|
|
|
logo_link = School.find(User.current.user_extensions.school.id).logo_link
|
|
|
|
end
|
|
|
|
else
|
|
|
|
logo_link = School.find(id).logo_link
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return logo_link
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def contest
|
2015-08-29 19:03:36 +08:00
|
|
|
redirect_to signin_path
|
|
|
|
return
|
|
|
|
|
2015-08-29 19:15:06 +08:00
|
|
|
# @contest_page = FirstPage.find_by_page_type('contest')
|
|
|
|
# @contest_notifications = Contestnotification.order("created_at desc").limit(5)
|
2014-09-15 10:58:14 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def search
|
2015-11-26 09:57:53 +08:00
|
|
|
@name = params[:q]
|
|
|
|
@search_type = params[:search_type]
|
|
|
|
case params[:search_type]
|
|
|
|
when 'all'
|
|
|
|
@alls = Elasticsearch::Model.search({
|
|
|
|
query: {
|
|
|
|
multi_match: {
|
|
|
|
query: @name,
|
|
|
|
type:"most_fields",
|
2015-11-26 16:43:10 +08:00
|
|
|
operator: "or",
|
2015-12-07 14:31:05 +08:00
|
|
|
fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5']
|
2015-11-26 09:57:53 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
highlight: {
|
|
|
|
pre_tags: ['<span class="c_red">'],
|
|
|
|
post_tags: ['</span>'],
|
|
|
|
fields: {
|
|
|
|
login: {},
|
|
|
|
firstname: {},
|
|
|
|
lastname: {},
|
|
|
|
name:{},
|
|
|
|
description:{},
|
2015-12-07 14:31:05 +08:00
|
|
|
filename:{},
|
|
|
|
subject:{},
|
|
|
|
content:{}
|
2015-11-26 09:57:53 +08:00
|
|
|
}
|
|
|
|
}
|
2015-12-07 14:31:05 +08:00
|
|
|
},[User,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results
|
2015-11-26 09:57:53 +08:00
|
|
|
when 'user'
|
|
|
|
@users = User.search(@name).page(params[:page] || 1).per(20)
|
|
|
|
when 'project'
|
|
|
|
@projects = Project.search(@name).page(params[:page] || 1).per(20).results
|
|
|
|
when 'course'
|
|
|
|
@courses = Course.search(@name).page(params[:page] || 1).per(20).results
|
|
|
|
when 'attachment'
|
|
|
|
@attachments = Attachment.search(@name).page(params[:page] || 1).per(20).results
|
2015-12-07 14:31:05 +08:00
|
|
|
when 'memo'
|
|
|
|
@memos = Memo.search(@name).page(params[:page] || 1).per(20).results
|
2015-11-26 09:57:53 +08:00
|
|
|
else
|
|
|
|
@alls = Elasticsearch::Model.search({
|
|
|
|
query: {
|
|
|
|
multi_match: {
|
|
|
|
query: @name,
|
|
|
|
type:"most_fields",
|
2015-11-26 16:43:10 +08:00
|
|
|
operator: "or",
|
2015-12-07 14:31:05 +08:00
|
|
|
fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5']
|
2015-11-26 09:57:53 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
highlight: {
|
|
|
|
pre_tags: ['<span class="c_red">'],
|
|
|
|
post_tags: ['</span>'],
|
|
|
|
fields: {
|
|
|
|
login: {},
|
|
|
|
firstname: {},
|
|
|
|
lastname: {},
|
|
|
|
name:{},
|
|
|
|
description:{},
|
2015-12-07 14:31:05 +08:00
|
|
|
filename:{},
|
|
|
|
subject:{},
|
|
|
|
content:{}
|
2015-11-26 09:57:53 +08:00
|
|
|
}
|
|
|
|
}
|
2015-12-07 14:31:05 +08:00
|
|
|
},[User,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results
|
2014-09-15 10:58:14 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-11-26 09:57:53 +08:00
|
|
|
@users_count = User.search(@name).results.total
|
|
|
|
|
|
|
|
@course_count = Course.search(@name).results.total
|
|
|
|
@attach_count = Attachment.search(@name).results.total
|
|
|
|
@project_count = Project.search(@name).results.total
|
2015-12-07 14:31:05 +08:00
|
|
|
@memo_count = Memo.search(@name).results.total
|
2015-11-26 09:57:53 +08:00
|
|
|
@total_count = Elasticsearch::Model.search({
|
|
|
|
query: {
|
|
|
|
multi_match: {
|
|
|
|
query: @name,
|
|
|
|
type:"most_fields",
|
2015-11-26 16:43:10 +08:00
|
|
|
operator: "or",
|
2015-12-07 14:31:05 +08:00
|
|
|
fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5']
|
2015-11-26 09:57:53 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
highlight: {
|
|
|
|
pre_tags: ['<span class="c_red">'],
|
|
|
|
post_tags: ['</span>'],
|
|
|
|
fields: {
|
|
|
|
login: {},
|
|
|
|
firstname: {},
|
|
|
|
lastname: {},
|
|
|
|
name:{},
|
|
|
|
description:{},
|
2015-12-07 14:31:05 +08:00
|
|
|
filename:{},
|
|
|
|
subject:{},
|
|
|
|
content:{}
|
2015-11-26 09:57:53 +08:00
|
|
|
}
|
|
|
|
}
|
2015-12-07 14:31:05 +08:00
|
|
|
},[User,Course,Attachment,Project,Memo] ).results.total
|
2015-11-26 09:57:53 +08:00
|
|
|
# search_type = params[:search_type].to_sym unless search_condition.blank?
|
|
|
|
# search_by = params[:search_by]
|
|
|
|
#
|
|
|
|
# if search_type.nil? && params[:contests_search] && params[:name] != ""
|
|
|
|
# search_type = :contests
|
|
|
|
# search_condition = params[:name]
|
|
|
|
# end
|
|
|
|
|
2014-09-15 10:58:14 +08:00
|
|
|
respond_to do |format|
|
2015-11-26 09:57:53 +08:00
|
|
|
format.js
|
|
|
|
format.html{ render :layout=>'users_base'}
|
2014-09-15 10:58:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
# 判断网站的入口,是课程 course 则跳过index去渲染 course 方法
|
|
|
|
def entry_select
|
2015-08-29 19:15:06 +08:00
|
|
|
# url = request.original_url.gsub('/','')
|
|
|
|
# if url.include?(Setting.url_course.gsub('/',''))
|
|
|
|
# if @first_page.show_course == 1
|
|
|
|
# course
|
|
|
|
# render :course
|
|
|
|
# else
|
|
|
|
# render_404
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# return 0
|
|
|
|
# elsif url.include?(Setting.url_contest.gsub('/',''))
|
|
|
|
# if @first_page.show_contest == 1
|
|
|
|
# contest
|
|
|
|
# render :contest
|
|
|
|
# else
|
|
|
|
# render_404
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# return 0
|
|
|
|
# elsif url.include?(Setting.url_user.gsub('/',''))
|
|
|
|
# #redirect_to(:controller => "users", :action => "index")
|
|
|
|
# end
|
2014-09-15 10:58:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# def render(*args)
|
|
|
|
# _fake if @fake_filter
|
|
|
|
# super
|
|
|
|
# end
|
|
|
|
|
|
|
|
# private
|
|
|
|
|
|
|
|
# def fake
|
|
|
|
# @fake_filter = true
|
|
|
|
# end
|
|
|
|
|
|
|
|
# # 骗子方法
|
|
|
|
# def _fake
|
|
|
|
# instance_variables.map { |variable|
|
|
|
|
# if variable.to_s =~ /Count$/
|
|
|
|
# self.instance_variable_set(variable.to_sym,
|
|
|
|
# ("1" + (self.instance_variable_get(variable.to_sym).to_s)).to_i)
|
|
|
|
# end
|
|
|
|
# }
|
|
|
|
# end
|
|
|
|
|
|
|
|
end
|