redmine_glossary/app/controllers/glossary_terms_controller.rb

76 lines
2.0 KiB
Ruby
Raw Normal View History

class GlossaryTermsController < ApplicationController
2018-05-05 15:59:12 +02:00
before_action :find_term_from_id, only: [:show, :edit, :update, :destroy]
before_action :find_project_by_project_id, :authorize, except: [:preview]
before_action :find_attachments, only: [:preview]
def index
2018-05-13 00:48:03 +02:00
@glossary_terms = GlossaryTerm.where(project_id: @project.id)
2018-06-05 18:21:17 +02:00
if not params[:index].nil?
@glossary_terms = @glossary_terms.search_by_name(params[:index])
elsif not params[:index_rubi].nil?
@glossary_terms = @glossary_terms.search_by_rubi(params[:index_rubi])
end
@grouping = params[:grouping] unless params[:grouping].nil?
end
2018-05-04 02:40:20 +02:00
2018-05-05 04:15:27 +02:00
def new
@term = GlossaryTerm.new
end
2018-05-04 02:40:20 +02:00
def create
term = GlossaryTerm.new(glossary_term_params)
2018-05-13 00:48:03 +02:00
term.project = @project
term.save_attachments params[:attachments]
if term.save
render_attachment_warning_if_needed term
redirect_to [@project, term], notice: l(:notice_successful_create)
end
end
2018-05-05 14:04:21 +02:00
def edit
end
def update
@term.attributes = glossary_term_params
@term.save_attachments params[:attachments]
2018-05-05 14:04:21 +02:00
if @term.save
render_attachment_warning_if_needed @term
redirect_to [@project, @term], notice: l(:notice_successful_update)
2018-05-05 14:04:21 +02:00
end
rescue ActiveRecord::StaleObjectError
flash.now[:error] = l(:notice_locking_conflict)
end
2018-05-05 15:59:12 +02:00
def destroy
@term.destroy
redirect_to project_glossary_terms_path(@project)
2018-05-05 15:59:12 +02:00
end
def preview
term = GlossaryTerm.find_by_id(params[:id])
if term
@attachments += term.attachments
@previewed = term
end
@text = params[:glossary_term][:description]
render partial: 'common/preview'
end
2018-05-04 02:40:20 +02:00
# Find the term whose id is the :id parameter
def find_term_from_id
@term = GlossaryTerm.find(params[:id])
2018-05-04 03:08:14 +02:00
rescue ActiveRecord::RecordNotFound
render_404
2018-05-04 02:40:20 +02:00
end
private
def glossary_term_params
params.require(:glossary_term).permit(
2018-05-24 01:26:17 +02:00
:name, :description, :category_id,
:name_en, :rubi, :abbr_whole, :datatype, :codename
)
end
end