Skip to content

Commit

Permalink
Advanced search - except author type
Browse files Browse the repository at this point in the history
  • Loading branch information
Ana06 authored and voodoorai2000 committed Jan 13, 2016
1 parent 15ce538 commit 4d3e3f2
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/assets/stylesheets/participation.scss
Expand Up @@ -1030,4 +1030,11 @@
.content {
height: rem-calc(60);
}
}
}
.advanced-search-title{
cursor:pointer; cursor: hand
}

.blue{
color: $brand;
}
32 changes: 32 additions & 0 deletions app/controllers/concerns/commentable_actions.rb
Expand Up @@ -4,6 +4,26 @@ module CommentableActions

def index
@resources = @search_terms.present? ? resource_model.search(@search_terms) : resource_model.all
if @params_author
author = User.where(username: @params_author)
@resources = author.count > 0 ? @resources.where(author_id: author.first.id) : resource_model.none
end
if @params_date
case @params_date
when '1'
min_date_time = DateTime.now -24.hour
when '2'
min_date_time = DateTime.now - 7.day
when '3'
min_date_time = DateTime.now - 30.day
when '4'
min_date_time = DateTime.now - 365.day
when '5'
@resources = @resources.where('created_at <= ?', @params_date_max) if @params_date_max
min_date_time = @params_date_min
end
@resources = @resources.where('created_at >= ?', min_date_time) if min_date_time
end
@resources = @resources.tagged_with(@tag_filter) if @tag_filter
@resources = @resources.page(params[:page]).for_render.send("sort_by_#{@current_order}")
index_customization if index_customization.present?
Expand Down Expand Up @@ -81,6 +101,18 @@ def parse_search_terms
@search_terms = params[:search] if params[:search].present?
end

def parse_advanced_search_terms
search = params[:advanced_search]
if search
@params_author = search[:author] if search[:author].present?
@params_author_type = search[:author_type] if search[:author_type].present?
@params_date = search[:date] if search[:date].present?
@params_date_min = search[:date_min] if (@params_date == '5') && search[:date_min].present?
@params_date_max = search[:date_max] if (@params_date == '5') && search[:date_max].present?
@advanced_search_present = true if params[:commit] || @params_author || @params_author_type || @params_date
end
end

def set_search_order
if params[:search].present? && params[:order].blank?
params[:order] = 'relevance'
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/proposals_controller.rb
Expand Up @@ -3,6 +3,7 @@ class ProposalsController < ApplicationController
include FlagActions

before_action :parse_search_terms, only: :index
before_action :parse_advanced_search_terms, only: :index
before_action :parse_tag_filter, only: :index
before_action :set_search_order, only: :index
before_action :authenticate_user!, except: [:index, :show]
Expand All @@ -14,7 +15,7 @@ class ProposalsController < ApplicationController
respond_to :html, :js

def index_customization
@featured_proposals = Proposal.all.sort_by_confidence_score.limit(3) if (@search_terms.blank? && @tag_filter.blank?)
@featured_proposals = Proposal.all.sort_by_confidence_score.limit(3) if (!@advanced_search_present && @search_terms.blank? && @tag_filter.blank?)
if @featured_proposals.present?
set_featured_proposal_votes(@featured_proposals)
@resources = @resources.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id))
Expand Down Expand Up @@ -44,4 +45,5 @@ def resource_model
def set_featured_proposal_votes(proposals)
@featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {}
end

end
32 changes: 30 additions & 2 deletions app/views/proposals/index.html.erb
Expand Up @@ -11,10 +11,12 @@

<div class="filters">
<div class="small-12 medium-7 left">
<% if @search_terms %>
<% if @search_terms || @advanced_search_present %>
<h2 class="margin-top">
<%= page_entries_info @proposals %>
<%= t("proposals.index.search_results", count: @proposals.size, search_term: @search_terms) %>
<% if !@advanced_search_present %>
<%= t("proposals.index.search_results", count: @proposals.size, search_term: @search_terms) %>
<% end %>
</h2>
<% elsif @tag_filter %>
<h2 class="margin-top">
Expand All @@ -24,6 +26,32 @@
<% end %>
</div>

<% if @tag_filter || @search_terms || @advanced_search_present %>
<div class="small-12 medium-5 margin-top margin-top inline-block proposals-order">
<h6 class="inline-block">
<%= t("proposals.index.select_order") %>
</h6>
<%= render 'shared/order_selector', i18n_namespace: "proposals.index" %>
</div>
<% else %>
<div class="small-12 inline-block">
<h2 class="inline-block">
<%= t("proposals.index.select_order_long") %>
</h2>
<%= render 'shared/order_selector', i18n_namespace: "proposals.index" %>
</div>
<% end %>

<div class="small-12 medium-12 advanced-search row">
<%= render "shared/advanced_search",
search_path: proposals_path(page: 1),
i18n_namespace: "proposals.index.search_form" %>
</div>

<div class="show-for-small-only">
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button radius expand' %>
</div>

<% if @featured_proposals.present? %>
<div id="featured-proposals" class="row featured-proposals-container">
<div class="small-12 medium-3 column">
Expand Down
93 changes: 93 additions & 0 deletions app/views/shared/_advanced_search.html.erb
@@ -0,0 +1,93 @@
<% # Params:
#
# i18n_namespace: for example "proposals.index.search_form"
# search_path: for example proposals_path
%>

<div class="small-12 medium-12 columns">
<h4 class='advanced-search-title'>Búsqueda avanzada</h4>
</div>

<%= form_tag search_path, method: :get do %>
<div id='advanced-search'>

<div class="small-12 medium-12 advanced-search columns">
<h5 class='search-option inline-block'>Con el texto</h5>
<%= text_field_tag "search", @search_terms, placeholder: "Escribe el texto" %>
</div>

<div class="small-12 medium-6 advanced-search columns">
<h5 class='search-option inline-block'>Por nombre de autor</h5>
<%= text_field_tag "advanced_search[author]", @params_author, placeholder: "Escribe el nombre del autor" %>
</div>

<div class="small-12 medium-6 advanced-search columns">
<h5 class='search-option'>Por categoría de autor</h5>
<%= select_tag('advanced_search[author_type]', options_for_select([['Concejal', 1], ['Cargo directivo', 2]], @params_author_type), include_blank: 'Elige una categoría') %>
<%# text_field_tag "advanced_search[author_type]", @params_author_type, placeholder: "Escribe la categoría" %>
</div>

<div class="small-12 advanced-search columns">
<h5 class='search-option'>Por fecha</h5>
<%= select_tag('advanced_search[date]', options_for_select([['Últimas 24 horas', 1], ['Última semana', 2], ['Últimos 30 días', 3],['Último año', 4], ['Personalizada', 5]], @params_date), include_blank: 'Elige una fecha') %>
<div class='customized-date inline-block'>
&nbsp;&nbsp;Desde:
<div class='inline-block'>
<%= date_field 'advanced_search', 'date_min', max:Date.today, value: @params_date_min %>
</div>
&nbsp;&nbsp;Hasta:
<div class='inline-block'>
<%= date_field 'advanced_search', 'date_max', max:Date.today, value: @params_date_max %>
</div>
</div>
</div>


<div class="small-6 medium-3 offset advanced-search columns">
<%= submit_tag 'Buscar', class: 'button postfix' %>
</div>

</div>

<% end %>

<hr>

<script type="text/javascript">

//open advantage options menu

var open = <%= raw @advanced_search_present.to_json.html_safe %>;

if(!open) $('#advanced-search').hide();

$('.advanced-search-title').on({
click: function(){
$('#advanced-search').slideToggle();
},
mouseenter: function(){
$(this).addClass('blue');
},
mouseleave: function(){
$(this).removeClass('blue');
}
});

//hide customized-date if it is not selected

if($('#advanced_search_date').val() != 5){
$('.customized-date').hide();
}

$('#advanced_search_date').on('change',function(e){
var next = $(e.target).next();
if($(this).val() == 5){
next.show();
}
else{
next.hide();
}

});

</script>

0 comments on commit 4d3e3f2

Please sign in to comment.