Edycja pojęcia
+<%= notice %>
+ <%= render 'form', dictionary: @dictionary %> + +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 %> +
| Nazwa | +Opis | +Akcje | +
|---|---|---|
| <%= 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?' } %> + | +
<%= notice %>
+ <%= render 'form', dictionary: @dictionary %> + +<%= notice %>
+ <%= render partial: 'list' %> +<%= notice %>
+ <%= render 'form', dictionary: @dictionary %> + +