diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 80fcaba..42d88d9 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,11 +15,11 @@ //= require turbolinks function reloadFunctionsOnAjax() { $(".tooltip").tooltip("hide"); - //$('.popover').popover('hide'); + $('.popover').popover('hide'); // Reload tootltips $('[data-toggle="tooltip"]').tooltip({ trigger : 'hover' }) // Reload popovers - //$('[data-toggle="popover"]').popover() + $('[data-toggle="popover"]').popover() } diff --git a/app/assets/stylesheets/main.css b/app/assets/stylesheets/main.css index 80c89e7..db2f474 100644 --- a/app/assets/stylesheets/main.css +++ b/app/assets/stylesheets/main.css @@ -109,3 +109,9 @@ .text-navy-new:hover { color: #0a3a7e; } + +.dictionary-word { + text-decoration: underline; + -webkit-text-decoration-color: blue; /* Safari */ + text-decoration-color: blue; +} diff --git a/app/controllers/dictionaries_controller.rb b/app/controllers/dictionaries_controller.rb new file mode 100644 index 0000000..057b1f4 --- /dev/null +++ b/app/controllers/dictionaries_controller.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +# Dictionary class +class DictionariesController < ApplicationController + before_action :authenticate_user! + include ApplicationHelper + before_action :check_access + before_action :set_dictionary, only: %i[show edit update destroy] + + def check_access + redirect_to not_found unless role?('dictionaries') + end + + # GET /tags or /tags.json + def index + @dictionaries = Dictionary.all + end + + # GET /tags/1 or /tags/1.json + def show; end + + # GET /tags/new + def new + @dictionary = Dictionary.new + end + + # GET /tags/1/edit + def edit; end + + # POST /tags or /tags.json + def create + @dictionary = Dictionary.new(dictionary_params) + + respond_to do |format| + if @dictionary.save + format.html { redirect_to dictionaries_url, notice: 'Utworzono pomyślnie.' } + format.json { render :show, status: :created, location: @dictionary } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @dictionary.errors, status: :unprocessable_entity } + end + end + end + + def update + respond_to do |format| + if @dictionary.update(dictionary_params) + format.html { redirect_to dictionaries_url, notice: 'Zaktualizowano pomyślnie.' } + format.json { render :show, status: :ok, location: @dictionary } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @dictionary.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @dictionary.destroy + + respond_to do |format| + format.html { redirect_to dictionaries_url, notice: 'Usunięto pomyślnie.' } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_dictionary + @dictionary = Dictionary.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def dictionary_params + params.require(:dictionary).permit(:shortcut, :name, :description) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a4fcad2..9c8f08f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -13,6 +13,7 @@ module ApplicationHelper ret += menu_item('far fa-circle', 'Przedsięwzięcia', '/projects', 'projects') if role?('projects') 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-user', 'Użytkownicy', '/settings/users', 'users') if admin? ret diff --git a/app/models/dictionary.rb b/app/models/dictionary.rb new file mode 100644 index 0000000..92fdb94 --- /dev/null +++ b/app/models/dictionary.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# Model Dictionary +class Dictionary < ApplicationRecord + # == Constants ============================================================ + + # == Attributes =========================================================== + + # == Extensions =========================================================== + + # == Relationships ======================================================== + + # == Validations ========================================================== + validates :name, presence: true, length: { maximum: 255 } + validates :shortcut, presence: true, length: { maximum: 50 } + validates :description, presence: true, length: { maximum: 1000 } + # == Scopes =============================================================== + scope :by_short, ->(val) { where(shortcut: val) } + # == Callbacks ============================================================ + + # == Class Methods ======================================================== + def self.ret_all_to_tinymce + ret = '' + Dictionary.all.each do |dict| + ret += dict.ret_a_tinymce_element + end + ret.chomp + end + + # == Instance Methods ===================================================== + def ret_a_tag + "#{name}" + end + + def ret_a_tinymce_element + "{type: 'menuitem',text: '#{name}',onAction: function ()"\ + " {editor.insertContent(' #{shortcut}');}}," + end +end diff --git a/app/models/dotation.rb b/app/models/dotation.rb index 6473094..e79cfe5 100644 --- a/app/models/dotation.rb +++ b/app/models/dotation.rb @@ -152,6 +152,19 @@ class Dotation < ApplicationRecord friendly_id end + def replace_dictionary(text, form) + ret = text + dictionaries = Dictionary.all + dictionaries.each do |dictionary| + if form == 'pdf' + ret = ret.gsub(dictionary.shortcut, dictionary.name) + elsif form == 'html' + ret = ret.gsub(dictionary.shortcut, dictionary.ret_a_tag) + end + end + ret + end + def replace_video require 'nokogiri' ret = full_descr diff --git a/app/views/dictionaries/_form.html.erb b/app/views/dictionaries/_form.html.erb new file mode 100644 index 0000000..7834f88 --- /dev/null +++ b/app/views/dictionaries/_form.html.erb @@ -0,0 +1,20 @@ +<%= form_with(model: dictionary, local: true) do |form| %> +<%= render '/shared/errors_list', error_object: dictionary %> +
+ <%= form.label :shortcut %> + <%= form.text_field :shortcut, class: 'form-control', placeholder: 'Wprowadź skrót' %> +
+
+ <%= form.label :name %> + <%= form.text_field :name, class: 'form-control', placeholder: 'Wprowadź nazwę' %> +
+
+ <%= form.label :description %> + <%= form.text_area :description, class: 'form-control', placeholder: 'Wprowadź opis' %> +
+ + +<% end %> diff --git a/app/views/dictionaries/_list.html.erb b/app/views/dictionaries/_list.html.erb new file mode 100644 index 0000000..05ce702 --- /dev/null +++ b/app/views/dictionaries/_list.html.erb @@ -0,0 +1,31 @@ +<% if @dictionaries.blank? %> +
+
Informacja
+ Brak elementów na liście +
+<% else %> + + + + + + + + + + + + <% @dictionaries.each do |dictionary| %> + + + + + + <% end %> + +
NazwaOpisAkcje
<%= dictionary.name %><%= dictionary.description %> + <%= link_to raw(' Edycja'), edit_dictionary_path(dictionary), class: 'btn-sm btn-info' %> + <%= link_to raw(' Usuń'), dictionary, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %> +
+ +<% end %> diff --git a/app/views/dictionaries/edit.html.erb b/app/views/dictionaries/edit.html.erb new file mode 100644 index 0000000..a3552e9 --- /dev/null +++ b/app/views/dictionaries/edit.html.erb @@ -0,0 +1,30 @@ +
+
+
+
+

Słownik

+
+
+
+
+
+ +
+
+
+
+
+
+

Edycja pojęcia

+
+ +
+

<%= notice %>

+ <%= render 'form', dictionary: @dictionary %> + +
+
+
+
+
+
diff --git a/app/views/dictionaries/index.html.erb b/app/views/dictionaries/index.html.erb new file mode 100644 index 0000000..b95f11c --- /dev/null +++ b/app/views/dictionaries/index.html.erb @@ -0,0 +1,33 @@ +
+
+
+
+

Słownik pojęć

+
+
+
+
+
+ +
+
+
+
+
+
+

Słownik pojęć

+
+ <%= link_to raw(''), new_dictionary_path %> + +
+
+ +
+

<%= notice %>

+ <%= render partial: 'list' %> +
+
+
+
+
+
diff --git a/app/views/dictionaries/new.html.erb b/app/views/dictionaries/new.html.erb new file mode 100644 index 0000000..42c5b77 --- /dev/null +++ b/app/views/dictionaries/new.html.erb @@ -0,0 +1,35 @@ + +
+
+
+
+

Słownik

+
+ +
+ +
+ +
+ +
+ +
+
+
+
+
+
+

Nowe pojęcie

+
+ +
+

<%= notice %>

+ <%= render 'form', dictionary: @dictionary %> + +
+
+
+
+
+
diff --git a/app/views/grants/_form.html.erb b/app/views/grants/_form.html.erb index 57af479..5877d87 100644 --- a/app/views/grants/_form.html.erb +++ b/app/views/grants/_form.html.erb @@ -264,7 +264,7 @@ 'insertdatetime', 'media', 'table', 'code', 'wordcount' ], toolbar: 'undo redo | blocks | ' + - 'bold italic backcolor | alignleft aligncenter ' + + 'bold italic backcolor | customDictionary | alignleft aligncenter ' + 'alignright alignjustify | bullist numlist outdent indent | ' + 'removeformat link image media | table tableinsertdialog tablecellprops tableprops advtablerownumbering', /* enable title field in the Image dialog*/ @@ -276,6 +276,17 @@ images_upload_url: 'postAcceptor.php', here we add custom filepicker only to Image dialog */ + setup: function (editor) { + editor.ui.registry.addMenuButton('customDictionary', { + icon: 'user', + tooltip: 'Pojęcie słownikowe', + fetch: function (callback) { + var items = [<%= raw Dictionary.ret_all_to_tinymce %>]; + callback(items); + } + + }); + }, file_picker_types: 'image', /* and here's our custom image picker*/ file_picker_callback: (cb, value, meta) => { diff --git a/app/views/grants/_list.html.erb b/app/views/grants/_list.html.erb index 503fe56..6524c9d 100644 --- a/app/views/grants/_list.html.erb +++ b/app/views/grants/_list.html.erb @@ -34,7 +34,7 @@ <%= render 'activate', dotation: dotation %> - <%= link_to raw(' Pokaż'), edit_grant_path(dotation), class: 'btn-sm btn-info' %> + <%= link_to raw(' Pokaż'), grant_path(dotation), class: 'btn-sm btn-info' %> <%= link_to raw(' Usuń'), grant_path(dotation), class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %> diff --git a/app/views/grants/_show.html.erb b/app/views/grants/_show.html.erb index 2b3828b..ba4d53b 100644 --- a/app/views/grants/_show.html.erb +++ b/app/views/grants/_show.html.erb @@ -115,7 +115,7 @@
- <%= raw @dotation.full_descr %> + <%= raw @dotation.replace_dictionary(@dotation.full_descr, 'html') %>

diff --git a/app/views/home/_show.html.erb b/app/views/home/_show.html.erb index 15f6aeb..342e90d 100644 --- a/app/views/home/_show.html.erb +++ b/app/views/home/_show.html.erb @@ -89,7 +89,7 @@

Szczegółowy opis dotacji

- <%= raw @dotation.full_descr %> + <%= raw @dotation.replace_dictionary(@dotation.full_descr, 'html') %>
diff --git a/app/views/home/_show.pdf.erb b/app/views/home/_show.pdf.erb index 83156af..6449bd2 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_video %> + <%= raw dotation.replace_dictionary(dotation.replace_video, 'pdf') %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ac9cddb..657aa7d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -107,5 +107,8 @@ + diff --git a/config/locales/pl/models/dictionary.yml b/config/locales/pl/models/dictionary.yml new file mode 100644 index 0000000..a6b6b27 --- /dev/null +++ b/config/locales/pl/models/dictionary.yml @@ -0,0 +1,22 @@ +pl: + activerecord: + models: + tag: Słownik + attributes: + dictionary: + name: "Nazwa" + description: "Opis" + shortcut: "Skrót" + errors: + models: + dictionary: + attributes: + name: + blank: nie może być pusta + too_long: jest za długa (max 255 znaków) + description: + blank: nie może być pusty + too_long: jest za długi (max 1000 znaków) + shortcut: + 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 c3bf422..952c900 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,7 @@ Rails.application.routes.draw do resources :projects resources :partners resources :experts + resources :dictionaries get 'grants/activate' post 'grants/activate' resources :grants diff --git a/db/migrate/20220629060749_create_dictionaries.rb b/db/migrate/20220629060749_create_dictionaries.rb new file mode 100644 index 0000000..517da07 --- /dev/null +++ b/db/migrate/20220629060749_create_dictionaries.rb @@ -0,0 +1,11 @@ +class CreateDictionaries < ActiveRecord::Migration[5.2] + def change + create_table :dictionaries do |t| + t.string :shortcut + t.string :name + t.longtext :description + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 1b5f84a..0c9124d 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_28_085754) do +ActiveRecord::Schema.define(version: 2022_06_29_060749) do create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "name", null: false @@ -83,6 +83,14 @@ ActiveRecord::Schema.define(version: 2022_06_28_085754) do t.datetime "updated_at", null: false end + create_table "dictionaries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| + t.string "shortcut" + t.string "name" + t.text "description", limit: 4294967295 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "dotations", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "slug" t.string "name" diff --git a/test/fixtures/dictionaries.yml b/test/fixtures/dictionaries.yml new file mode 100644 index 0000000..4073986 --- /dev/null +++ b/test/fixtures/dictionaries.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + shortcut: MyString + name: MyString + description: + +two: + shortcut: MyString + name: MyString + description: diff --git a/test/models/dictionary_test.rb b/test/models/dictionary_test.rb new file mode 100644 index 0000000..ec4b5b2 --- /dev/null +++ b/test/models/dictionary_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class DictionaryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end