forked from bofh/fetsite
search function
This commit is contained in:
@@ -11,4 +11,19 @@ class HomeController < ApplicationController
|
|||||||
def linksnotimplemented
|
def linksnotimplemented
|
||||||
render 'links_notimplemented'
|
render 'links_notimplemented'
|
||||||
end
|
end
|
||||||
|
def search
|
||||||
|
unless params['query'].nil? || params['query'].empty?
|
||||||
|
@neuigkeiten=Neuigkeit.search(params['query'])
|
||||||
|
@fetprofiles = Fetprofile.search(params['query'])
|
||||||
|
@themen=Thema.search(params['query'])
|
||||||
|
else
|
||||||
|
@neuigkeiten=[]
|
||||||
|
@fetprofiles=[]
|
||||||
|
@themen=[]
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ validates :desc, :presence=>true
|
|||||||
validates :nachname, length:{minimum: 3},:presence=>true
|
validates :nachname, length:{minimum: 3},:presence=>true
|
||||||
validates :vorname, length:{minimum: 3},:presence=>true
|
validates :vorname, length:{minimum: 3},:presence=>true
|
||||||
has_many :users
|
has_many :users
|
||||||
|
scope :search, ->(query) {where("nachname like ? or vorname like ? or short like ?", "%#{query}%", "%#{query}%", "%#{query}%")}
|
||||||
|
|
||||||
accepts_nested_attributes_for :memberships, :reject_if=>lambda{|a| a[:typ].blank?|| a[:start].blank? ||a[:gremium_id].blank?}, :allow_destroy=>true
|
accepts_nested_attributes_for :memberships, :reject_if=>lambda{|a| a[:typ].blank?|| a[:start].blank? ||a[:gremium_id].blank?}, :allow_destroy=>true
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,10 @@ class Neuigkeit < ActiveRecord::Base
|
|||||||
has_many :calentries, as: :object
|
has_many :calentries, as: :object
|
||||||
mount_uploader :picture, PictureUploader
|
mount_uploader :picture, PictureUploader
|
||||||
scope :published, -> {where("datum <= ? AND datum IS NOT NULL", Time.now.to_date).order(:datum).reverse_order}
|
scope :published, -> {where("datum <= ? AND datum IS NOT NULL", Time.now.to_date).order(:datum).reverse_order}
|
||||||
scope :recent, -> { published.where("updated_at >= ? ",Time.now - 7.days)}
|
scope :recent, -> { published.order(:datum).reverse_order.limit(15)}
|
||||||
scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)}
|
scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)}
|
||||||
scope :public, ->{includes(:rubrik).where("rubriken.public"=>:true)}
|
scope :public, ->{includes(:rubrik).where("rubriken.public"=>:true)}
|
||||||
|
scope :search, ->(query) {where("text like ? or title like ?", "%#{query}%", "%#{query}%")}
|
||||||
accepts_nested_attributes_for :calentries, :allow_destroy=>true , :reject_if=> lambda{|a| a[:start].blank?}
|
accepts_nested_attributes_for :calentries, :allow_destroy=>true , :reject_if=> lambda{|a| a[:start].blank?}
|
||||||
before_validation :sanitize
|
before_validation :sanitize
|
||||||
def datum_nilsave
|
def datum_nilsave
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class Thema < ActiveRecord::Base
|
|||||||
has_one :gremium
|
has_one :gremium
|
||||||
validates :themengruppe, :presence => true
|
validates :themengruppe, :presence => true
|
||||||
validates :title, :presence => true
|
validates :title, :presence => true
|
||||||
|
scope :search, ->(query) {where("text like ? or title like ?", "%#{query}%", "%#{query}%")}
|
||||||
|
|
||||||
translates :title,:text, :versioning =>true, :fallbacks_for_empty_translations => true
|
translates :title,:text, :versioning =>true, :fallbacks_for_empty_translations => true
|
||||||
end
|
end
|
||||||
|
|||||||
18
app/views/fetprofiles/_compact.html.erb
Normal file
18
app/views/fetprofiles/_compact.html.erb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<div class="media">
|
||||||
|
|
||||||
|
<span class="pull-left">
|
||||||
|
<%= image_tag fetprofile.picture.portrait.url %>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div class="media-body">
|
||||||
|
<h2><%= fetprofile.name %></h2>
|
||||||
|
|
||||||
|
<p><%= fetprofile.fetmail %></p>
|
||||||
|
<% if false %>
|
||||||
|
<p><%= fetprofile.desc %></p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -1,12 +1,4 @@
|
|||||||
|
|
||||||
<div class="media">
|
<%= link_to fetprofile, {class: :linkbox} do %>
|
||||||
<div class="pull-left">
|
<%= render :partial=>"fetprofiles/compact", :locals=>{:fetprofile=>fetprofile} %>
|
||||||
<%= image_tag fetprofile.picture.portrait.url %>
|
<% end %>
|
||||||
</div>
|
|
||||||
<div class="media-body">
|
|
||||||
|
|
||||||
<h2><%= link_to fetprofile.name, fetprofile %></h2>
|
|
||||||
<p><%= fetprofile.fetmail %></p>
|
|
||||||
<p><%= fetprofile.desc.split(" ")[1..20].join(" ") %></p>
|
|
||||||
<p><%= fetprofile.active %> </p>
|
|
||||||
</div>
|
|
||||||
|
|||||||
37
app/views/home/_search_results.html.erb
Normal file
37
app/views/home/_search_results.html.erb
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
<% unless @neuigkeiten.empty? %>
|
||||||
|
<h2>Neuigkeiten</h2>
|
||||||
|
<% end %>
|
||||||
|
<% @neuigkeiten.each do |neuigkeit| %>
|
||||||
|
<ul class="unstyled linkbox-list" style="max-width:70em">
|
||||||
|
<li>
|
||||||
|
<%= render neuigkeit %>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% unless @fetprofiles.empty? %>
|
||||||
|
<h2>Mitarbeiter</h2>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% @fetprofiles.each do |fetprofile| %>
|
||||||
|
<ul class="unstyled linkbox-list" style="max-width:70em">
|
||||||
|
<li>
|
||||||
|
<%= render fetprofile %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% unless @fetprofiles.empty? %>
|
||||||
|
<h2>Themen</h2>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% @themen.each do |thema| %>
|
||||||
|
<ul class="unstyled linkbox-list" style="max-width:70em">
|
||||||
|
<li><%= link_to thema, {:class=>"linkbox"} do %>
|
||||||
|
<%= render :partial=>"themen/small", :object=>thema %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
17
app/views/home/search.html.erb
Normal file
17
app/views/home/search.html.erb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<div class="content-wrap content-column">
|
||||||
|
<%= semantic_form_for :search,:remote=>true, :url=>search_home_index_path, :html=>{:id=>"search_form", :method=>'get'} do |f| %>
|
||||||
|
<%= f.input :query, :input_html => { :name => 'query' } %>
|
||||||
|
<% end %>
|
||||||
|
<script>
|
||||||
|
$( document ).ready(function() {
|
||||||
|
$("#search_query").bind("keyup", function(event){
|
||||||
|
$("#search_form").submit();
|
||||||
|
});
|
||||||
|
$("#search_query").value="df"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<div id="searchresults">
|
||||||
|
<%= render :partial=>"home/search_results" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
1
app/views/home/search.js.erb
Normal file
1
app/views/home/search.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$("#searchresults").html("<%=escape_javascript( render :partial=>'home/search_results' )%>")
|
||||||
25
app/views/neuigkeiten/_compact.html.erb
Normal file
25
app/views/neuigkeiten/_compact.html.erb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
<div class="media">
|
||||||
|
<div class="pull-left" href="#">
|
||||||
|
<p><br><%= image_tag neuigkeit.picture.thumb.url unless neuigkeit.picture.url.nil? %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="media-body">
|
||||||
|
<div>
|
||||||
|
<small><%= neuigkeit.rubrik.name %></small>
|
||||||
|
<small class="pull-right"> <%= "am "+ I18n.l(neuigkeit.try(:datum).try(:to_date)) unless neuigkeit.try(:datum).try(:to_date).nil? %></small>
|
||||||
|
</div>
|
||||||
|
<h1>
|
||||||
|
<%= neuigkeit.title%>
|
||||||
|
</h1>
|
||||||
|
<%= raw(neuigkeit.text_first_words) unless neuigkeit.text.nil?%>
|
||||||
|
</div>
|
||||||
|
<% if neuigkeit.has_calentries? %>
|
||||||
|
<div class="pull-right" href="#">
|
||||||
|
<%= image_tag("/iconnavy/time.png") %>
|
||||||
|
|
||||||
|
<%= neuigkeit.calentries.first.text %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -1,28 +1,4 @@
|
|||||||
|
|
||||||
<%= link_to [neuigkeit.rubrik,neuigkeit], {class: :linkbox} do %>
|
<%= link_to [neuigkeit.rubrik,neuigkeit], {class: :linkbox} do %>
|
||||||
<div class="media">
|
<%= render :partial=>"neuigkeiten/compact",:locals=> {:neuigkeit=> neuigkeit} %>
|
||||||
<div class="pull-left" href="#">
|
|
||||||
<p><br><%= image_tag neuigkeit.picture.thumb.url unless neuigkeit.picture.url.nil? %>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="media-body">
|
|
||||||
<div>
|
|
||||||
<small><%= neuigkeit.rubrik.name %></small>
|
|
||||||
<small class="pull-right"> <%= "am "+ I18n.l(neuigkeit.try(:datum).try(:to_date)) unless neuigkeit.try(:datum).try(:to_date).nil? %></small>
|
|
||||||
</div>
|
|
||||||
<h1>
|
|
||||||
<%= neuigkeit.title%>
|
|
||||||
</h1>
|
|
||||||
<%= raw(neuigkeit.text_first_words) unless neuigkeit.text.nil?%>
|
|
||||||
</div>
|
|
||||||
<% if neuigkeit.has_calentries? %>
|
|
||||||
<div class="pull-right" href="#">
|
|
||||||
<%= image_tag("/iconnavy/time.png") %>
|
|
||||||
|
|
||||||
<%= neuigkeit.calentries.first.text %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user