修改了搜索功能,并能对搜索进行过滤
This commit is contained in:
parent
8600265f00
commit
28b10ed3fd
|
@ -18,6 +18,7 @@ class OpenSourceProjectsController < ApplicationController
|
|||
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']
|
||||
|
@ -65,17 +66,6 @@ class OpenSourceProjectsController < ApplicationController
|
|||
order(sort_clause).
|
||||
all
|
||||
|
||||
|
||||
|
||||
# @offset, @limit = api_offset_and_limit({:limit => 10})
|
||||
# @forum = Forum.find(params[:id])
|
||||
# @memos_all = @forum.topics
|
||||
# @topic_count = @memos_all.count
|
||||
# @topic_pages = Paginator.new @topic_count, @limit, params['page']
|
||||
|
||||
# @offset ||= @topic_pages.offset
|
||||
# @memos = @memos_all.offset(@offset).limit(@limit).all
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => "base_opensource_p"
|
||||
|
@ -148,6 +138,28 @@ class OpenSourceProjectsController < ApplicationController
|
|||
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
|
||||
|
||||
private
|
||||
|
||||
def require_master
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
module OpenSourceProjectsHelper
|
||||
def render_opensource_project(os_projects)
|
||||
s=''.html_safe
|
||||
s << "<ul class='projects'>\n"
|
||||
os_projects.each do |project|
|
||||
s << "<li class='project-table'><div class='#{classes}'>"
|
||||
s << "div class='root'"
|
||||
|
||||
s << "</div>\n"
|
||||
s << "</li>\n"
|
||||
end
|
||||
s << "</ul>"
|
||||
end
|
||||
|
||||
def show_condition(app_dir, language, created_at)
|
||||
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 => "tags", :action => "remove_tag"}, :remote => true
|
||||
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')
|
||||
|
@ -25,7 +12,7 @@ module OpenSourceProjectsHelper
|
|||
end
|
||||
unless language.nil?
|
||||
s_temp = content_tag('a', language)
|
||||
temp = link_to 'x', {:controller => "tags", :action => "remove_tag"}, :remote => true
|
||||
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')
|
||||
|
@ -33,7 +20,7 @@ module OpenSourceProjectsHelper
|
|||
end
|
||||
unless created_at.nil?
|
||||
s_temp = content_tag('a', created_at)
|
||||
temp = link_to 'x', {:controller => "tags", :action => "remove_tag"}, :remote => true
|
||||
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')
|
||||
|
@ -42,5 +29,4 @@ module OpenSourceProjectsHelper
|
|||
s = content_tag('div', s, :id => 'tags')
|
||||
# s = content_tag('div', s, :class => 'tags')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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
|
||||
|
@ -11,28 +11,36 @@ class OpenSourceProject < ActiveRecord::Base
|
|||
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
|
||||
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
scope :applied_by, lambda { |user_id|
|
||||
{ :include => :apply_project_master,
|
||||
:conditions => ["#{ApplyProjectMaster.table_name}.user_id = ?", user_id] }
|
||||
}
|
||||
|
||||
: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)
|
||||
|
@ -40,88 +48,87 @@ class OpenSourceProject < ActiveRecord::Base
|
|||
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
|
||||
# nil
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def self.filter_app_dir(app_dir)
|
||||
# nil
|
||||
# nil
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def filter_language(language)
|
||||
# nil
|
||||
# nil
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def self.filter_language(language)
|
||||
# nil
|
||||
# nil
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def filter_time(created_at)
|
||||
# nil
|
||||
# nil
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def self.filter_time(created_at)
|
||||
# nil
|
||||
# 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
|
||||
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
|
||||
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
|
||||
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
|
||||
end
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
<td rowspan="2" >
|
||||
<div class="project-search" style="float: right">
|
||||
<%= text_field_tag 'name', params[:name], :size => 30 %>
|
||||
<%= hidden_field_tag 'project_type', params[:project_type] %>
|
||||
<%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
|
||||
</div></td>
|
||||
</tr>
|
||||
|
@ -144,9 +143,8 @@ li {
|
|||
<li class="has-arrow">查找条件><span class="nav-topbar-arror"></span>
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<span class="topbar-search J_TopbarSearch">
|
||||
<%= show_condition(@app_dir, @language, @created_at) %>
|
||||
<%= show_condition(@app_dir, @language, @created_at, params[:name]) %>
|
||||
</span>
|
||||
</li>
|
||||
<li>共 <span class="h"><%= @os_project_count %></span> 个开源项目</li>
|
||||
|
@ -160,24 +158,24 @@ li {
|
|||
<div class="nav-category-group type-line" data-group="type-line">
|
||||
<div class="nav-category ">
|
||||
<h4 title="网络类型">应用方向<span>:</span></h4>
|
||||
<%= link_to "操作系统相关", open_source_projects_path(:app_dir => "操作系统相关", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "管理和监控", open_source_projects_path(:app_dir => "管理和监控", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "游戏/娱乐", open_source_projects_path(:app_dir => "游戏/娱乐", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "应用工具", open_source_projects_path(:app_dir => "应用工具", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "数据库相关", open_source_projects_path(:app_dir => "数据库相关", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "服务器软件", open_source_projects_path(:app_dir => "服务器软件", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "网站系统", open_source_projects_path(:app_dir => "网站系统", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "插件和扩展", open_source_projects_path(:app_dir => "插件和扩展", :language => @language, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "操作系统相关", open_source_projects_path(:app_dir => "操作系统相关", :language => @language, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "管理和监控", open_source_projects_path(:app_dir => "管理和监控", :language => @language, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "游戏/娱乐", open_source_projects_path(:app_dir => "游戏/娱乐", :language => @language, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "应用工具", open_source_projects_path(:app_dir => "应用工具", :language => @language, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "数据库相关", open_source_projects_path(:app_dir => "数据库相关", :language => @language, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "服务器软件", open_source_projects_path(:app_dir => "服务器软件", :language => @language, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "网站系统", open_source_projects_path(:app_dir => "网站系统", :language => @language, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "插件和扩展", open_source_projects_path(:app_dir => "插件和扩展", :language => @language, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<span class="arrow arrow-bottom"></span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="nav-category ">
|
||||
<h4 title="网络类型">开发语言<span>:</span></h4>
|
||||
<%= link_to "JAVA", open_source_projects_path(:language => "JAVA", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "C++", open_source_projects_path(:language => "c++", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "C", open_source_projects_path(:language => "c", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "C#", open_source_projects_path(:language => "c#", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "ruby", open_source_projects_path(:language => "ruby", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
<%= link_to "JAVA", open_source_projects_path(:language => "JAVA", :app_dir => @app_dir, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "C++", open_source_projects_path(:language => "c++", :app_dir => @app_dir, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "C", open_source_projects_path(:language => "c", :app_dir => @app_dir, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "C#", open_source_projects_path(:language => "c#", :app_dir => @app_dir, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "ruby", open_source_projects_path(:language => "ruby", :app_dir => @app_dir, :created_at => @created_at, :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%#= link_to "其他", open_source_projects_path(:language => "其他", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %>
|
||||
|
||||
<span class="arrow arrow-bottom"></span>
|
||||
|
@ -185,12 +183,12 @@ li {
|
|||
</div>
|
||||
<div class="nav-category ">
|
||||
<h4 title="网络类型">创立时间<span>:</span></h4>
|
||||
<%= link_to "2014", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2014"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2013", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2013"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2012", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2012"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2011", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2011"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2010", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2010"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "更早", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "更早"), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2014", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2014", :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2013", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2013", :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2012", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2012", :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2011", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2011", :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "2010", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "2010", :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
<%= link_to "更早", open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => "更早", :name => params[:name]), :class => "nav-more J_More show" %>
|
||||
|
||||
<span class="arrow arrow-bottom"></span>
|
||||
</a>
|
||||
|
|
|
@ -28,6 +28,7 @@ RedmineApp::Application.routes.draw do
|
|||
resources :open_source_projects do
|
||||
collection do
|
||||
match 'search', via: [:get, :post]
|
||||
match 'remove_condition', via: [:get, :post]
|
||||
end
|
||||
resources :relative_memos
|
||||
member do
|
||||
|
|
Loading…
Reference in New Issue