added locations
This commit is contained in:
parent
09fb6af0a2
commit
134661dcd8
|
|
@ -96,6 +96,7 @@ class GrantsController < ApplicationController
|
|||
@experts = Expert.all
|
||||
@expenses = Expense.all
|
||||
@partners = Partner.all
|
||||
@locations = Location.where.not(id: 1)
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
|
|
@ -112,6 +113,6 @@ class GrantsController < ApplicationController
|
|||
:start_date_month, :end_date_month, :ann_date_month,
|
||||
:start_date_always, :end_date_always, :ann_date_always,
|
||||
project_ids: [], tag_ids: [], company_activity_ids: [],
|
||||
company_size_ids: [], expense_ids: [])
|
||||
company_size_ids: [], expense_ids: [], location_ids: [])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -170,19 +170,20 @@ class HomeController < ApplicationController
|
|||
@company_size_chk = params[:company_size] || []
|
||||
@company_activity_chk = params[:company_activity] || []
|
||||
@project_chk = params[:project] || []
|
||||
@location_chk = params[:location] || []
|
||||
@company_sizes = CompanySize.all
|
||||
@company_activities = CompanyActivity.all
|
||||
@projects = Project.all
|
||||
@locations = Location.where.not(id: 1)
|
||||
end
|
||||
|
||||
def pdf_header
|
||||
|
||||
end
|
||||
def pdf_header; end
|
||||
|
||||
def build_filter_hash
|
||||
{
|
||||
search: params[:search], company_sizes: @company_size_chk,
|
||||
company_activities: @company_activity_chk, projects: @project_chk,
|
||||
locations: @location_chk,
|
||||
localization: params[:localization], ammount_chk: params[:ammount_chk],
|
||||
ammount_price: params[:ammount_price]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Test controller only admin access
|
||||
class TestController < ApplicationController
|
||||
def add_locations
|
||||
return unless Location.all.blank?
|
||||
|
||||
Location.create(parent_id: nil, name: 'Cała polska')
|
||||
Location.create(parent_id: 1, name: 'dolnośląskie')
|
||||
Location.create(parent_id: 1, name: 'kujawsko-pomorskie')
|
||||
Location.create(parent_id: 1, name: 'lubelskie')
|
||||
Location.create(parent_id: 1, name: 'lubuskie')
|
||||
Location.create(parent_id: 1, name: 'łódzkie')
|
||||
Location.create(parent_id: 1, name: 'małopolskie')
|
||||
Location.create(parent_id: 1, name: 'mazowieckie')
|
||||
Location.create(parent_id: 1, name: 'opolskie')
|
||||
Location.create(parent_id: 1, name: 'podkarpackie')
|
||||
Location.create(parent_id: 1, name: 'podlaskie')
|
||||
Location.create(parent_id: 1, name: 'pomorskie')
|
||||
Location.create(parent_id: 1, name: 'śląskie')
|
||||
Location.create(parent_id: 1, name: 'świętokrzyskie')
|
||||
Location.create(parent_id: 1, name: 'warmińsko-mazurskie')
|
||||
Location.create(parent_id: 1, name: 'wielkopolskie')
|
||||
Location.create(parent_id: 1, name: 'zachodniopomorskie')
|
||||
end
|
||||
end
|
||||
|
|
@ -36,6 +36,7 @@ class Dotation < ApplicationRecord
|
|||
has_and_belongs_to_many :company_sizes
|
||||
has_and_belongs_to_many :projects
|
||||
has_and_belongs_to_many :tags
|
||||
has_and_belongs_to_many :locations
|
||||
has_and_belongs_to_many :company_activities
|
||||
# == Validations ==========================================================
|
||||
validates :name, presence: true, length: { maximum: 255 }
|
||||
|
|
@ -61,6 +62,9 @@ class Dotation < ApplicationRecord
|
|||
scope :by_comp_size, (lambda do |val|
|
||||
joins(:company_sizes).merge(CompanySize.by_ids(val)).distinct
|
||||
end)
|
||||
scope :by_locations, (lambda do |val|
|
||||
joins(:locations).merge(Location.by_ids(val)).distinct
|
||||
end)
|
||||
scope :by_comp_active, (lambda do |val|
|
||||
joins(:company_activities).merge(CompanyActivity.by_ids(val)).distinct
|
||||
end)
|
||||
|
|
@ -92,6 +96,9 @@ class Dotation < ApplicationRecord
|
|||
unless filters[:company_sizes].blank?
|
||||
ret = ret.by_comp_size(filters[:company_sizes])
|
||||
end
|
||||
unless filters[:locations].blank?
|
||||
ret = ret.by_locations(filters[:locations])
|
||||
end
|
||||
unless filters[:company_activities].blank?
|
||||
ret = ret.by_comp_active(filters[:company_activities])
|
||||
end
|
||||
|
|
@ -178,4 +185,18 @@ class Dotation < ApplicationRecord
|
|||
end
|
||||
doc
|
||||
end
|
||||
|
||||
def location_to_text
|
||||
ret = ''
|
||||
if locations.size == 16
|
||||
ret = 'Cała polska'
|
||||
else
|
||||
l_size = locations.size
|
||||
locations.each_with_index do |loca, index|
|
||||
ret += loca.name
|
||||
ret += ', ' if l_size > index + 1
|
||||
end
|
||||
end
|
||||
ret
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Location < ApplicationRecord
|
||||
# == Constants ============================================================
|
||||
|
||||
# == Attributes ===========================================================
|
||||
|
||||
# == Extensions ===========================================================
|
||||
|
||||
# == Relationships ========================================================
|
||||
has_and_belongs_to_many :dotations
|
||||
# == Validations ==========================================================
|
||||
|
||||
# == Scopes ===============================================================
|
||||
scope :by_ids, ->(val) { where(id: val) }
|
||||
# == Callbacks ============================================================
|
||||
|
||||
# == Class Methods ========================================================
|
||||
|
||||
# == Instance Methods =====================================================
|
||||
end
|
||||
|
|
@ -115,7 +115,13 @@
|
|||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<%= form.label :localization %>
|
||||
<%= form.text_field :localization, class: 'form-control', placeholder: 'Wprowadź region' %>
|
||||
<%= form.text_field :localization, class: 'form-control', placeholder: 'Opisowa lokalizacja' %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="form-group">
|
||||
<%= form.label :locations %>
|
||||
<%= form.select(:location_ids, @locations.collect {|p| [ p.name, p.id ] }, { include_blank: false }, { class: 'form-control duallistbox', multiple: true } ) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -77,6 +77,27 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card card-secondary">
|
||||
<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">
|
||||
<% @locations.each do |location| %>
|
||||
<div class="form-check">
|
||||
<%= check_box_tag("location[]", location.id, @location_chk.include?(location.id.to_s) , class: 'form-check-input', onchange: "formSubmit()") %>
|
||||
<label class="form-check-label"><%= location.name %></label>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%#
|
||||
<div class="card card-primary">
|
||||
<div class="card-header">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
<h1>Test#add_locations</h1>
|
||||
<p>Find me in app/views/test/add_locations.html.erb</p>
|
||||
|
|
@ -21,6 +21,7 @@ pl:
|
|||
max_percent: Maksymalny poziom dofinansowania
|
||||
company_activities: Dominująca działalność firmy
|
||||
company_sizes: Wielkość firmy
|
||||
locations: Województwa
|
||||
projects: Rodzaj przedsięwzięcia
|
||||
expert: Ekspert
|
||||
expert_id: Ekspert
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
Rails.application.routes.draw do
|
||||
get 'test/add_locations'
|
||||
get 'dashboard/index'
|
||||
get 'zrezygnuj' => 'email_filter#unsubscribe'
|
||||
get 'email_filter/unsubscribe'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
class CreateLocations < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :locations do |t|
|
||||
t.bigint :parent_id
|
||||
t.string :name
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
class CreateJoinTableDotationLocation < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_join_table :dotations, :locations do |t|
|
||||
# t.index [:dotation_id, :location_id]
|
||||
# t.index [:location_id, :dotation_id]
|
||||
end
|
||||
end
|
||||
end
|
||||
14
db/schema.rb
14
db/schema.rb
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_07_31_134927) do
|
||||
ActiveRecord::Schema.define(version: 2022_08_30_110315) do
|
||||
|
||||
create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
|
|
@ -152,6 +152,11 @@ ActiveRecord::Schema.define(version: 2022_07_31_134927) do
|
|||
t.index ["dotation_id", "expense_id"], name: "dot_expind"
|
||||
end
|
||||
|
||||
create_table "dotations_locations", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.bigint "dotation_id", null: false
|
||||
t.bigint "location_id", null: false
|
||||
end
|
||||
|
||||
create_table "dotations_projects", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.bigint "dotation_id", null: false
|
||||
t.bigint "project_id", null: false
|
||||
|
|
@ -212,6 +217,13 @@ ActiveRecord::Schema.define(version: 2022_07_31_134927) do
|
|||
t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id"
|
||||
end
|
||||
|
||||
create_table "locations", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.bigint "parent_id"
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "partners", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.text "description"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
parent_id:
|
||||
name: MyString
|
||||
|
||||
two:
|
||||
parent_id:
|
||||
name: MyString
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class LocationTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Loading…
Reference in New Issue