diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index 73176293c..6294c9ca8 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -10,7 +10,7 @@ // 08. Forms // 09. Alerts // 10. User account -// 11. Filters +// 11. Filters & search // 12. Official levels // 13. Pagination // 14. Tables @@ -133,9 +133,14 @@ h6 { .button { font-size: rem-calc(13); + font-family: $font-family-sans-serif !important; padding: rem-calc(15) rem-calc(32); } +.postfix.button { + padding: 0; +} + .clear { clear: both; } @@ -985,7 +990,7 @@ img.initialjs-avatar { top: -9px; } -// 11. Filters +// 11. Filters & search // - - - - - - - - - - - - - - - - - - - - - - - - - .filters { @@ -1018,6 +1023,23 @@ img.initialjs-avatar { } } +.search-results { + @extend .filters; +} + +.search-form { + + h3 { + border-top: 1px solid $votes-border; + display: inline-block; + font-family: $font-family-sans-serif; + font-size: rem-calc(16); + margin: -1px 0 rem-calc(12); + padding-top: rem-calc(6); + text-transform: uppercase; + } +} + // 12. Officials levels // - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 68570dd70..1c5696304 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -1,13 +1,14 @@ class DebatesController < ApplicationController before_action :parse_order, only: :index before_action :parse_tag_filter, only: :index + before_action :parse_search_terms, only: :index before_action :authenticate_user!, except: [:index, :show] load_and_authorize_resource respond_to :html, :js def index - @debates = Debate.all + @debates = @search_terms.present? ? Debate.search(@search_terms) : Debate.all @debates = @debates.tagged_with(@tag_filter) if @tag_filter @debates = @debates.page(params[:page]).for_render.send("sort_by_#{@order}") @tag_cloud = Debate.tag_counts.order(taggings_count: :desc, name: :asc).limit(20) @@ -92,4 +93,8 @@ class DebatesController < ApplicationController end end + def parse_search_terms + @search_terms = params[:search] if params[:search].present? + end + end diff --git a/app/models/debate.rb b/app/models/debate.rb index ed0fc17b8..8471be20d 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -128,6 +128,10 @@ class Debate < ActiveRecord::Base self.hot_score = (age_in_units**3 + weighted_score * 1000).round end + def self.search(terms) + terms.present? ? where("title ILIKE ? OR description ILIKE ?", "%#{terms}%", "%#{terms}%") : none + end + protected def sanitize_description diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index bcd74445c..e23a45f5c 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -3,18 +3,24 @@