Filters
This commit is contained in:
parent
d1af465d2b
commit
e0d4e46c7c
|
|
@ -0,0 +1,23 @@
|
|||
$(function () {
|
||||
$('.select2').select2();
|
||||
$("input[data-bootstrap-switch]").each(function(){
|
||||
$(this).bootstrapSwitch();
|
||||
})
|
||||
$( "#search_input" ).on('input', function() {
|
||||
if ($( "#search_input" ).val().length > 2 || $( "#search_input" ).val().length == 0) {
|
||||
$('#search').val($( "#search_input" ).val());
|
||||
$('#submit_form_btn').click();
|
||||
}
|
||||
});
|
||||
});
|
||||
function formSubmit() {
|
||||
$('#submit_form_btn').click();
|
||||
return false;
|
||||
}
|
||||
function formSubmitText(element) {
|
||||
alert(this);
|
||||
if ($(element).val().length > 2 || $(element).val().length == 0) {
|
||||
//$('#submit_form_btn').click();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -10,6 +10,12 @@ class HomeController < ApplicationController
|
|||
.point_desc.end_date_asc.page(params[:page])
|
||||
end
|
||||
|
||||
def search
|
||||
prepare_filters
|
||||
@dotations = Dotation.search_with_filters(build_filter_hash).public_dot
|
||||
.point_desc.end_date_asc.page(params[:page])
|
||||
end
|
||||
|
||||
def contact; end
|
||||
|
||||
def show
|
||||
|
|
@ -20,8 +26,20 @@ class HomeController < ApplicationController
|
|||
private
|
||||
|
||||
def prepare_filters
|
||||
@company_size_chk = params[:company_size] || []
|
||||
@company_activity_chk = params[:company_activity] || []
|
||||
@project_chk = params[:project] || []
|
||||
@company_sizes = CompanySize.all
|
||||
@company_activities = CompanyActivity.all
|
||||
@projects = Project.all
|
||||
end
|
||||
|
||||
def build_filter_hash
|
||||
{
|
||||
search: params[:search], company_sizes: @company_size_chk,
|
||||
company_activities: @company_activity_chk, projects: @project_chk,
|
||||
localization: params[:localization], ammount_chk: params[:ammount_chk],
|
||||
ammount_price: params[:ammount_price]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class CompanyActivity < ApplicationRecord
|
|||
# == Validations ==========================================================
|
||||
validates :name, presence: true
|
||||
# == Scopes ===============================================================
|
||||
|
||||
scope :by_ids, ->(val) { where(id: val) }
|
||||
# == Callbacks ============================================================
|
||||
|
||||
# == Class Methods ========================================================
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class CompanySize < ApplicationRecord
|
|||
# == Validations ==========================================================
|
||||
validates :name, presence: true
|
||||
# == Scopes ===============================================================
|
||||
|
||||
scope :by_ids, ->(val) { where(id: val) }
|
||||
# == Callbacks ============================================================
|
||||
|
||||
# == Class Methods ========================================================
|
||||
|
|
|
|||
|
|
@ -3,7 +3,17 @@
|
|||
# Dotations
|
||||
class Dotation < ApplicationRecord
|
||||
# == Constants ============================================================
|
||||
AMMOUNT_ON_PROJECT = [
|
||||
[0, 'poniżej 100 tyś zł', 0, 99_999],
|
||||
[1, '100 tyś do 1 mln zł', 100_000, 999_999],
|
||||
[2, '1 mln do 10 mln zł', 1_000_000, 10_000_000],
|
||||
[3, 'powyżej 10 mln zł', 10_000_000, 999_999_999_999_999]
|
||||
|
||||
].freeze
|
||||
AMMOUNT_ON_PROJECT_HASH = {
|
||||
'' => '', 'poniżej 100 tyś zł' => 0, '100 tyś do 1 mln zł' => 1,
|
||||
'1 mln do 10 mln zł' => 2, 'powyżej 10 mln zł' => 3
|
||||
}.freeze
|
||||
# == Attributes ===========================================================
|
||||
|
||||
# == Extensions ===========================================================
|
||||
|
|
@ -29,15 +39,55 @@ class Dotation < ApplicationRecord
|
|||
value: "%#{search_value}%")
|
||||
end)
|
||||
scope :extra_search, (lambda do |search_value|
|
||||
where('name LIKE :value OR formal_name LIKE :value',
|
||||
where('dotations.name LIKE :value OR dotations.formal_name LIKE :value OR '\
|
||||
'dotations.full_descr LIKE'\
|
||||
' :value OR dotations.positioning_text LIKE :value',
|
||||
value: "%#{search_value}%")
|
||||
end)
|
||||
scope :by_localization, (lambda do |search_value|
|
||||
where('dotations.localization LIKE :value', value: "%#{search_value}%")
|
||||
end)
|
||||
scope :by_prize, (lambda do |val_from, val_to|
|
||||
where('dotations.max_amount > :val_f AND dotations.max_amount < :val_t',
|
||||
val_f: val_from, val_t: val_to)
|
||||
end)
|
||||
scope :by_comp_size, (lambda do |val|
|
||||
joins(:company_sizes).merge(CompanySize.by_ids(val)).distinct
|
||||
end)
|
||||
scope :by_comp_active, (lambda do |val|
|
||||
joins(:company_activities).merge(CompanyActivity.by_ids(val)).distinct
|
||||
end)
|
||||
scope :by_projects, (lambda do |val|
|
||||
joins(:projects).merge(Project.by_ids(val)).distinct
|
||||
end)
|
||||
scope :min_prize, ->(val) { where('dotations.min_amount < ?', val) }
|
||||
scope :point_desc, -> { order(points: :desc) }
|
||||
scope :end_date_asc, -> { order(end_date: :asc) }
|
||||
scope :public_dot, -> { where(active: true) }
|
||||
# == Callbacks ============================================================
|
||||
|
||||
# == Class Methods ========================================================
|
||||
|
||||
def self.search_with_filters(filters)
|
||||
ret = Dotation.extra_search(filters[:search])
|
||||
ret = ret.by_localization(filters[:localization]) if filters[:localization]
|
||||
# ammount
|
||||
if filters[:ammount_chk].blank? && !filters[:ammount_price].blank?
|
||||
ret = ret.min_prize(filters[:ammount_price])
|
||||
elsif !filters[:ammount_chk].blank?
|
||||
ret =
|
||||
ret.by_prize(
|
||||
Dotation::AMMOUNT_ON_PROJECT[filters[:ammount_chk].to_i][2],
|
||||
Dotation::AMMOUNT_ON_PROJECT[filters[:ammount_chk].to_i][3]
|
||||
)
|
||||
end
|
||||
unless filters[:company_sizes].blank?
|
||||
ret = ret.by_comp_size(filters[:company_sizes])
|
||||
end
|
||||
unless filters[:company_activities].blank?
|
||||
ret = ret.by_comp_active(filters[:company_activities])
|
||||
end
|
||||
ret = ret.by_projects(filters[:projects]) unless filters[:projects].blank?
|
||||
ret
|
||||
end
|
||||
# == Instance Methods =====================================================
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Project < ApplicationRecord
|
|||
# == Validations ==========================================================
|
||||
validates :name, presence: true
|
||||
# == Scopes ===============================================================
|
||||
|
||||
scope :by_ids, ->(val) { where(id: val) }
|
||||
# == Callbacks ============================================================
|
||||
|
||||
# == Class Methods ========================================================
|
||||
|
|
|
|||
|
|
@ -1,16 +1,26 @@
|
|||
<% if @dotations.blank? %>
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><i class="fas fa-bullhorn"></i> Uwagi</h3>
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<%= render 'filter_form' %>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-info alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<h5><i class="icon fas fa-info"></i> Informacja</h5>
|
||||
Brak danych do wyświetlenia
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><i class="fas fa-bullhorn"></i> Uwagi</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-info alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<h5><i class="icon fas fa-info"></i> Informacja</h5>
|
||||
Brak danych do wyświetlenia
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% else %>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
<% if params[:search] %>
|
||||
|
||||
|
||||
<%= form_tag(home_search_path, method: :get, remote: true, id: 'filter_form') do %>
|
||||
<div class="card card-success card-outline">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title" style="font-size: 1.5rem;"><strong>Filtry</strong></h3>
|
||||
<h3 class="card-title" style="font-size: 1.5rem;"><strong>Aktywne filtry</strong></h3>
|
||||
<div class="card-tools">
|
||||
<h3><span class="badge badge-info"><%= @dotations.count %></span></h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
|
@ -12,6 +11,7 @@
|
|||
<div class="col-md-12">
|
||||
<p><strong>Wyszukiwana fraza:</strong><br />
|
||||
<%= params[:search] %></p>
|
||||
<%= hidden_field_tag :search, params[:search] %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
<div class="form-group">
|
||||
<% @company_sizes.each do |company_size| %>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox">
|
||||
<%= check_box_tag("company_size[]", company_size.id, @company_size_chk.include?(company_size.id.to_s) , class: 'form-check-input', onchange: "formSubmit()") %>
|
||||
<label class="form-check-label" data-toggle="tooltip" data-placement="top" title="<%= company_size.description %>"><%= company_size.name %></label>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
@ -41,19 +41,19 @@
|
|||
<div class="card card-primary">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title w-100">
|
||||
<a class="d-block w-100" data-toggle="collapse" href="#collapseTwo">
|
||||
<a class="d-block w-100" data-toggle="collapse" href="#collapseTwo" aria-expanded="true">
|
||||
Dominująca działalność firmy
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseTwo" class="collapse" data-parent="#accordion">
|
||||
<div id="collapseTwo" class="collapse show" data-parent="#accordion">
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<% @company_activities.each do |company_activity| %>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox">
|
||||
<label class="form-check-label" data-toggle="tooltip" data-placement="top" title="<%= company_activity.description %>"><%= company_activity.name %></label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<%= check_box_tag("company_activity[]", company_activity.id, @company_activity_chk.include?(company_activity.id.to_s) , class: 'form-check-input', onchange: "formSubmit()") %>
|
||||
<label class="form-check-label" data-toggle="tooltip" data-placement="top" title="<%= company_activity.description %>"><%= company_activity.name %></label>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -62,27 +62,74 @@
|
|||
<div class="card card-primary">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title w-100">
|
||||
<a class="d-block w-100" data-toggle="collapse" href="#collapseThree">
|
||||
<a class="d-block w-100" data-toggle="collapse" href="#collapseThree" aria-expanded="true">
|
||||
Rodzaj przedsięwzięcia
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseThree" class="collapse" data-parent="#accordion">
|
||||
<div id="collapseThree" class="collapse show" data-parent="#accordion">
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<% @projects.each do |project| %>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox">
|
||||
<label class="form-check-label" data-toggle="tooltip" data-placement="top" title="<%= project.description %>"><%= project.name %></label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<%= check_box_tag("project[]", project.id, @project_chk.include?(project.id.to_s) , class: 'form-check-input', onchange: "formSubmit()") %>
|
||||
<label class="form-check-label" data-toggle="tooltip" data-placement="top" title="<%= project.description %>"><%= project.name %></label>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card card-primary">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title w-100">
|
||||
<a class="d-block w-100 collapsed" data-toggle="collapse" href="#collapseFour" aria-expanded="true">
|
||||
Lokalizacja
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseFour" class="collapse show" data-parent="#accordion" style="">
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label for="localization">Lokalizacja projektu</label>
|
||||
<%= text_field_tag(:localization, params[:localization], class: 'form-control', placeholder: 'Wpisz tu lokalizację') %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card card-primary">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title w-100">
|
||||
<a class="d-block w-100 collapsed" data-toggle="collapse" href="#collapseFive" aria-expanded="true">
|
||||
Wartość przedsięwzięcia
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseFive" class="collapse show" data-parent="#accordion" style="">
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label for="ammount_price">Minimalna wartość</label>
|
||||
<%= number_field_tag(:ammount_price, params[:ammount_price], class: 'form-control', placeholder: 'Wpisz tu wartość') %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="ammount_price">lub wybierz z listy</label>
|
||||
<%= select_tag "ammount_chk", options_for_select(Dotation::AMMOUNT_ON_PROJECT_HASH, params[:ammount_chk]), class: 'form-control', onchange: "formSubmit()" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<button type="submit" class="btn btn-block btn-outline-info" id="submit_form_btn">
|
||||
<i class="fas fa-bullhorn"></i> Zastosuj filtry
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<button type="button" class="btn btn-block btn-outline-success" data-toggle="modal" data-target="#modal-lg">
|
||||
|
|
|
|||
|
|
@ -17,16 +17,14 @@
|
|||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-8 offset-md-2">
|
||||
<%= form_tag(home_index_path, method: :get, remote: true) do %>
|
||||
<div class="input-group">
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control form-control-lg', placeholder: 'Wpisz wyszukiwaną frazę') %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control form-control-lg', placeholder: 'Wpisz wyszukiwaną frazę', id: 'search_input') %>
|
||||
<div class="input-group-append">
|
||||
<button type="submit" class="btn btn-lg btn-default">
|
||||
<i class="fa fa-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
$('#search_result').html("<%= escape_javascript(render partial: 'dotations') %>");
|
||||
reloadFunctionsOnAjax();
|
||||
|
|
@ -41,6 +41,9 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
<%= javascript_include_tag 'jquery.min', 'bootstrap.bundle.min', 'bs-custom-file-input.min', 'moment-with-locales.min', 'select2.full.min', 'tempusdominus-bootstrap-4.min', 'adminlte.min', 'bootstrap-switch.min', 'forms' %>
|
||||
<%= javascript_include_tag 'jquery.min', 'bootstrap.bundle.min', 'bs-custom-file-input.min', 'moment-with-locales.min', 'select2.full.min', 'tempusdominus-bootstrap-4.min', 'adminlte.min', 'bootstrap-switch.min', 'form_calendar' %>
|
||||
<script type="text/javascript">
|
||||
<%= yield :scripts %>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ Rails.application.routes.draw do
|
|||
|
||||
get 'kontakt' => 'home#contact'
|
||||
get 'dotacja/:id' => 'home#show'
|
||||
get 'home/search'
|
||||
post 'home/search'
|
||||
resources :home, only: %i[index show]
|
||||
devise_for :users
|
||||
resources :company_sizes
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ class CreateDotations < ActiveRecord::Migration[5.2]
|
|||
t.string :formal_name
|
||||
t.date :date_from
|
||||
t.date :date_to
|
||||
t.integer :min_amount
|
||||
t.bigint :min_amount
|
||||
t.integer :min_amount_curr_id, default: 1
|
||||
t.integer :max_amount
|
||||
t.bigint :max_amount
|
||||
t.integer :max_amount_curr_id, default: 1
|
||||
t.integer :max_percent
|
||||
t.text :localization
|
||||
|
|
|
|||
Loading…
Reference in New Issue