diff --git a/app/assets/javascripts/form_calendar.js b/app/assets/javascripts/form_calendar.js
index b2aaea1..2e349ac 100644
--- a/app/assets/javascripts/form_calendar.js
+++ b/app/assets/javascripts/form_calendar.js
@@ -3,10 +3,15 @@ $(function () {
$("input[data-bootstrap-switch]").each(function(){
$(this).bootstrapSwitch();
})
+ var searchTimeout = null;
$( "#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();
+ clearTimeout(searchTimeout);
+ searchTimeout = setTimeout(function() {
+ $('#search').val($( "#search_input" ).val());
+ $('#submit_form_btn').click();
+ }, 400);
+
}
});
});
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 7e9ef87..0315285 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -39,7 +39,9 @@ class HomeController < ApplicationController
@email_message = EmailMessage.new
end
- def statute; end
+ def statute
+ @setting = Setting.first
+ end
def register_contact
@email_message = EmailMessage.new(email_messages_params)
diff --git a/app/controllers/settings/email_messages_controller.rb b/app/controllers/settings/email_messages_controller.rb
new file mode 100644
index 0000000..2749e28
--- /dev/null
+++ b/app/controllers/settings/email_messages_controller.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+# module settings
+module Settings
+ # Users
+ class EmailMessagesController < ApplicationController
+ before_action :authenticate_user!
+ before_action :set_email_message, only: %i[show destroy]
+
+ def index
+ @email_messages = EmailMessage.all
+ end
+
+ def show; end
+
+ def destroy
+ @email_message.destroy
+
+ respond_to do |format|
+ format.html { redirect_to settings_email_messages_url, notice: 'Usunięto pomyślnie.' }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+
+ def set_email_message
+ @email_message = EmailMessage.find(params[:id])
+ end
+ end
+end
diff --git a/app/controllers/settings/filter_for_emails_controller.rb b/app/controllers/settings/filter_for_emails_controller.rb
new file mode 100644
index 0000000..1cce38c
--- /dev/null
+++ b/app/controllers/settings/filter_for_emails_controller.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+# module settings
+module Settings
+ # Users
+ class FilterForEmailsController < ApplicationController
+ before_action :authenticate_user!
+ before_action :set_filter_for_email, only: %i[show destroy]
+
+ def index
+ @filter_for_emails = FilterForEmail.all
+ end
+
+ def show; end
+
+ def destroy
+ @filter_for_email.destroy
+
+ respond_to do |format|
+ format.html { redirect_to settings_filter_for_emails_url, notice: 'Usunięto pomyślnie.' }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+
+ def set_filter_for_email
+ @filter_for_email = FilterForEmail.find(params[:id])
+ end
+ end
+end
diff --git a/app/controllers/settings/settings_controller.rb b/app/controllers/settings/settings_controller.rb
new file mode 100644
index 0000000..e4a54e5
--- /dev/null
+++ b/app/controllers/settings/settings_controller.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+# module settings
+module Settings
+ # Users
+ class SettingsController < ApplicationController
+ before_action :authenticate_user!
+ before_action :set_setting, only: %i[show edit update]
+
+ def index
+ @settings = Setting.all
+ end
+
+ def show; end
+
+ def new
+ @setting = Setting.new
+ end
+
+ def edit; end
+
+ def create
+ @setting = Setting.new(setting_params)
+
+ respond_to do |format|
+ if @setting.save
+ # @user.confirm
+ # @user.save
+ format.html { redirect_to settings_settings_url, notice: 'Utworzono pomyślnie.' }
+ format.json { render :show, status: :created, location: @setting }
+ else
+ format.html { render :new, status: :unprocessable_entity }
+ format.json { render json: @setting.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ def update
+ respond_to do |format|
+ if @setting.update_attributes(setting_params)
+ format.html { redirect_to settings_settings_url, notice: 'Zaktualizowano pomyślnie.' }
+ format.json { render :show, status: :ok, location: @setting }
+ else
+ format.html { render :edit, status: :unprocessable_entity }
+ format.json { render json: @setting.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ private
+
+ # Use callbacks to share common setup or constraints between actions.
+ def set_setting
+ @setting = Setting.first
+ end
+
+ # Only allow a list of trusted parameters through.
+ def setting_params
+ params.require(:setting).permit(:disclaimer_clause, :privacy_policy,
+ :statute)
+ end
+ end
+end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 9c8f08f..3e1f2b0 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -14,6 +14,9 @@ module ApplicationHelper
ret += menu_item('far fa-circle', 'Eksperci', '/experts', 'experts') if role?('experts')
ret += menu_item('far fa-circle', 'Partnerzy', '/partners', 'partners') if role?('partners')
ret += menu_item('far fa-circle', 'Słownik', '/dictionaries', 'dictionaries') if role?('dictionaries')
+ ret += menu_item('far fa-circle', 'Kontakty od klientów', '/settings/email_messages', 'email_messages') if admin?
+ ret += menu_item('far fa-circle', 'Filtry klientów', '/settings/filter_for_emails', 'filter_for_emails') if admin?
+ ret += menu_item('far fa-circle', 'Ustawienia', '/settings/settings', 'settings/settings') if admin?
ret += menu_item('far fa-user', 'Użytkownicy', '/settings/users', 'users') if admin?
ret
diff --git a/app/models/setting.rb b/app/models/setting.rb
new file mode 100644
index 0000000..794034a
--- /dev/null
+++ b/app/models/setting.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+# Settings
+class Setting < ApplicationRecord
+ # == Constants ============================================================
+
+ # == Attributes ===========================================================
+
+ # == Extensions ===========================================================
+
+ # == Relationships ========================================================
+
+ # == Validations ==========================================================
+
+ # == Scopes ===============================================================
+
+ # == Callbacks ============================================================
+
+ # == Class Methods ========================================================
+
+ # == Instance Methods =====================================================
+ def updated
+ user = User.where('id = ?', updated_by).first
+ if user.blank?
+ 'Brak'
+ else
+ user.email
+ end
+ end
+end
diff --git a/app/views/home/_dotations.html.erb b/app/views/home/_dotations.html.erb
index 9cb4574..1b2ca49 100644
--- a/app/views/home/_dotations.html.erb
+++ b/app/views/home/_dotations.html.erb
@@ -36,6 +36,12 @@
<% @dotations.each do |dotation| %>
<%= render 'dotation_card', dotation: dotation %>
<% end %>
+
+
+ <%= link_to raw(' Zapisz wyniki jako PDF'), "/zestawienie_dotacji/plik.pdf", class: 'btn btn-navy btn-block' %>
+
+
+
<% end %>
<%= paginate @dotations, params: {controller: :home, action: :index}, theme: 'twitter-bootstrap-4' %>
diff --git a/app/views/home/_filter_form.html.erb b/app/views/home/_filter_form.html.erb
index fca067d..ebda1e5 100644
--- a/app/views/home/_filter_form.html.erb
+++ b/app/views/home/_filter_form.html.erb
@@ -4,14 +4,6 @@
Użyj filtrów, aby szybko odnaleźć interesującą Cię dotację
- <% unless params[:search].blank? %>
-
-
- <%= link_to raw(' Zapisz jako PDF'), "/zestawienie_dotacji/plik.pdf", class: 'btn btn-navy btn-block' %>
-
-
-
- <% end %>
Wyszukiwana fraza:
diff --git a/app/views/home/_show.pdf.erb b/app/views/home/_show.pdf.erb
index 6449bd2..4d8c182 100644
--- a/app/views/home/_show.pdf.erb
+++ b/app/views/home/_show.pdf.erb
@@ -74,7 +74,7 @@
Szczegółowy opis dotacji
- <%= raw dotation.replace_dictionary(dotation.replace_video, 'pdf') %>
+ <%= raw dotation.replace_dictionary(dotation.replace_video.to_s, 'pdf') %>
diff --git a/app/views/home/statute.html.erb b/app/views/home/statute.html.erb
index 3bcf3d4..c9895bc 100644
--- a/app/views/home/statute.html.erb
+++ b/app/views/home/statute.html.erb
@@ -28,7 +28,8 @@
- <%= render '/home/statutes/statut' %>
+ <%= raw @setting.statute %>
+ <%# render '/home/statutes/statut' %>
@@ -44,7 +45,8 @@
- <%= render '/home/statutes/privacy' %>
+ <%= raw @setting.privacy_policy %>
+ <%# render '/home/statutes/privacy' %>
@@ -56,7 +58,8 @@
- <%= render '/shared/disclaimer' %>
+ <%= raw @setting.disclaimer_clause %>
+ <%# render '/shared/disclaimer' %>
diff --git a/app/views/settings/email_messages/_list.html.erb b/app/views/settings/email_messages/_list.html.erb
new file mode 100644
index 0000000..c16b30c
--- /dev/null
+++ b/app/views/settings/email_messages/_list.html.erb
@@ -0,0 +1,34 @@
+<% if @email_messages.blank? %>
+
+
Informacja
+ Brak elementów na liście
+
+<% else %>
+
+
+
+
+ | E-mail |
+ Temat |
+ Wiadomość |
+ Utworzono |
+ Akcje |
+
+
+
+
+ <% @email_messages.each do |email_message| %>
+
+ | <%= email_message.email %> |
+ <%= email_message.subject %> |
+ <%= email_message.message %> |
+ <%= email_message.created_at.strftime("%Y-%m-%d %H:%M:%S") unless email_message.created_at.blank? %> |
+
+ <%= link_to raw(' Usuń'), "/settings/email_messages/#{email_message.id}", class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %>
+ |
+
+ <% end %>
+
+
+
+<% end %>
diff --git a/app/views/settings/email_messages/index.html.erb b/app/views/settings/email_messages/index.html.erb
new file mode 100644
index 0000000..4ac6724
--- /dev/null
+++ b/app/views/settings/email_messages/index.html.erb
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
<%= notice %>
+ <%= render partial: 'list' %>
+
+
+
+
+
+
diff --git a/app/views/settings/filter_for_emails/_list.html.erb b/app/views/settings/filter_for_emails/_list.html.erb
new file mode 100644
index 0000000..9da366e
--- /dev/null
+++ b/app/views/settings/filter_for_emails/_list.html.erb
@@ -0,0 +1,30 @@
+<% if @filter_for_emails.blank? %>
+
+
Informacja
+ Brak elementów na liście
+
+<% else %>
+
+
+
+
+ | E-mail |
+ Utworzono |
+ Akcje |
+
+
+
+
+ <% @filter_for_emails.each do |filter_for_email| %>
+
+ | <%= filter_for_email.email %> |
+ <%= filter_for_email.created_at.strftime("%Y-%m-%d %H:%M:%S") unless filter_for_email.created_at.blank? %> |
+
+ <%= link_to raw(' Usuń'), "/settings/filter_for_emails/#{filter_for_email.id}", class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %>
+ |
+
+ <% end %>
+
+
+
+<% end %>
diff --git a/app/views/settings/filter_for_emails/index.html.erb b/app/views/settings/filter_for_emails/index.html.erb
new file mode 100644
index 0000000..4dc9a4a
--- /dev/null
+++ b/app/views/settings/filter_for_emails/index.html.erb
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
<%= notice %>
+ <%= render partial: 'list' %>
+
+
+
+
+
+
diff --git a/app/views/settings/settings/_form.html.erb b/app/views/settings/settings/_form.html.erb
new file mode 100644
index 0000000..9d955ab
--- /dev/null
+++ b/app/views/settings/settings/_form.html.erb
@@ -0,0 +1,77 @@
+<%= render '/shared/errors_list', error_object: setting %>
+
+
+
+ <%= form.label :disclaimer_clause %>
+ <%= form.text_area :disclaimer_clause, class: 'form-control', placeholder: 'Klauzula o wyłączeniu odpowiedzialności' %>
+
+
+ <%= form.label :privacy_policy %>
+ <%= form.text_area :privacy_policy, class: 'form-control', placeholder: 'Polityka prywatności' %>
+
+
+ <%= form.label :statute %>
+ <%= form.text_area :statute, class: 'form-control', placeholder: 'Regulamin' %>
+
+
+
+
+
+
diff --git a/app/views/settings/settings/_list.html.erb b/app/views/settings/settings/_list.html.erb
new file mode 100644
index 0000000..2190141
--- /dev/null
+++ b/app/views/settings/settings/_list.html.erb
@@ -0,0 +1,28 @@
+<% if @settings.blank? %>
+
+
Informacja
+ Brak elementów na liście
+
+<% else %>
+
+
+
+
+ |
+ Modyfikował |
+ Ostatnia zmiana |
+
+
+
+
+ <% @settings.each do |setting| %>
+
+ | <%= link_to 'Ustawienia', edit_settings_setting_path(setting) %> |
+ <%= setting.updated %> |
+ <%= setting.updated_at.strftime("%Y-%m-%d %H:%M:%S") unless setting.updated_at.blank? %> |
+
+ <% end %>
+
+
+
+<% end %>
diff --git a/app/views/settings/settings/edit.html.erb b/app/views/settings/settings/edit.html.erb
new file mode 100644
index 0000000..95f2da1
--- /dev/null
+++ b/app/views/settings/settings/edit.html.erb
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
<%= notice %>
+ <%= form_with(model: @setting, url: settings_setting_path(@setting), method: :patch, local: true) do |form| %>
+ <%= render 'form', setting: @setting, form: form %>
+ <% end %>
+
+
+
+
+
+
diff --git a/app/views/settings/settings/index.html.erb b/app/views/settings/settings/index.html.erb
new file mode 100644
index 0000000..ac0107b
--- /dev/null
+++ b/app/views/settings/settings/index.html.erb
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
<%= notice %>
+ <%= render partial: 'list' %>
+
+
+
+
+
+
diff --git a/app/views/settings/settings/new.html.erb b/app/views/settings/settings/new.html.erb
new file mode 100644
index 0000000..1002fb8
--- /dev/null
+++ b/app/views/settings/settings/new.html.erb
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
<%= notice %>
+ <%= form_with(scope: @user, url: settings_users_path, local: true) do |form| %>
+ <%= render 'form', user: @user, form: form %>
+ <% end %>
+
+
+
+
+
+
+
diff --git a/config/locales/pl/models/filter_for_email.yml b/config/locales/pl/models/filter_for_email.yml
new file mode 100644
index 0000000..521d85f
--- /dev/null
+++ b/config/locales/pl/models/filter_for_email.yml
@@ -0,0 +1,22 @@
+pl:
+ activerecord:
+ models:
+ tag: Ustawienia
+ attributes:
+ filter_for_email:
+ disclaimer_clause: "Klauzula o wyłączeniu odpowiedzialności"
+ privacy_policy: "Polityka prywatności"
+ statute: "Regulamin"
+ errors:
+ models:
+ filter_for_email:
+ attributes:
+ disclaimer_clause:
+ blank: nie może być pusta
+ too_long: jest za długa (max 255 znaków)
+ privacy_policy:
+ blank: nie może być pusty
+ too_long: jest za długi (max 1000 znaków)
+ statute:
+ blank: nie może być pusty
+ too_long: jest za długi (max 50 znaków)
diff --git a/config/locales/pl/models/setting.yml b/config/locales/pl/models/setting.yml
new file mode 100644
index 0000000..14041e3
--- /dev/null
+++ b/config/locales/pl/models/setting.yml
@@ -0,0 +1,22 @@
+pl:
+ activerecord:
+ models:
+ tag: Ustawienia
+ attributes:
+ setting:
+ disclaimer_clause: "Klauzula o wyłączeniu odpowiedzialności"
+ privacy_policy: "Polityka prywatności"
+ statute: "Regulamin"
+ errors:
+ models:
+ setting:
+ attributes:
+ disclaimer_clause:
+ blank: nie może być pusta
+ too_long: jest za długa (max 255 znaków)
+ privacy_policy:
+ blank: nie może być pusty
+ too_long: jest za długi (max 1000 znaków)
+ statute:
+ blank: nie może być pusty
+ too_long: jest za długi (max 50 znaków)
diff --git a/config/routes.rb b/config/routes.rb
index 952c900..8c7e9ef 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
+ get 'dashboard/index'
get 'zrezygnuj' => 'email_filter#unsubscribe'
get 'email_filter/unsubscribe'
get 'kontakt' => 'home#contact'
@@ -22,6 +23,7 @@ Rails.application.routes.draw do
resources :company_activities
post 'projects/chg_prio'
resources :projects
+ resources :dashboard
resources :partners
resources :experts
resources :dictionaries
@@ -30,6 +32,9 @@ Rails.application.routes.draw do
resources :grants
namespace :settings do
resources :users
+ resources :settings
+ resources :email_messages
+ resources :filter_for_emails
end
get 'welcome/index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
diff --git a/db/migrate/20220731134927_create_settings.rb b/db/migrate/20220731134927_create_settings.rb
new file mode 100644
index 0000000..6936b23
--- /dev/null
+++ b/db/migrate/20220731134927_create_settings.rb
@@ -0,0 +1,12 @@
+class CreateSettings < ActiveRecord::Migration[5.2]
+ def change
+ create_table :settings do |t|
+ t.longtext :disclaimer_clause
+ t.longtext :privacy_policy
+ t.longtext :statute
+ t.bigint :updated_by
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 0c9124d..02ebd8b 100644
--- a/db/schema.rb
+++ b/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_06_29_060749) do
+ActiveRecord::Schema.define(version: 2022_07_31_134927) do
create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", null: false
@@ -253,6 +253,15 @@ ActiveRecord::Schema.define(version: 2022_06_29_060749) do
t.datetime "updated_at", null: false
end
+ create_table "settings", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
+ t.text "disclaimer_clause", limit: 4294967295
+ t.text "privacy_policy", limit: 4294967295
+ t.text "statute", limit: 4294967295
+ t.bigint "updated_by"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
create_table "tags", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.string "description"
diff --git a/test/fixtures/settings.yml b/test/fixtures/settings.yml
new file mode 100644
index 0000000..989b4f7
--- /dev/null
+++ b/test/fixtures/settings.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ disclaimer_clause:
+ privacy_policy:
+ statute:
+ updated_by:
+
+two:
+ disclaimer_clause:
+ privacy_policy:
+ statute:
+ updated_by:
diff --git a/test/models/setting_test.rb b/test/models/setting_test.rb
new file mode 100644
index 0000000..2d91c71
--- /dev/null
+++ b/test/models/setting_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class SettingTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end