You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.4 KiB
95 lines
2.4 KiB
class SubjectIndexesController < ApplicationController |
|
include JurisprudenceSearch |
|
|
|
load_and_authorize_resource :subject_index, class: "Cdao::Subject", except: %i[search] |
|
|
|
def index; end |
|
|
|
def new; end |
|
|
|
def edit; end |
|
|
|
def doctrines |
|
@doctrines = @subject_index.doctrines |
|
end |
|
|
|
def show |
|
@doctrines = @subject_index.doctrines |
|
end |
|
|
|
def search |
|
@search = search_subject(search_params) |
|
@subjects = @search.results |
|
|
|
respond_to do |format| |
|
format.html |
|
end |
|
end |
|
|
|
def create |
|
respond_to do |format| |
|
if @subject_index.save |
|
format.html { redirect_to subject_index_path(@subject_index), notice: "Subject Index was successfully created." } |
|
else |
|
format.html { render :new } |
|
end |
|
end |
|
end |
|
|
|
def update |
|
respond_to do |format| |
|
if @subject_index.update(resource_params) |
|
format.html { redirect_to subject_index_path(@subject_index), notice: "Subject Index was successfully updated." } |
|
else |
|
format.html { render :edit } |
|
end |
|
end |
|
end |
|
|
|
def destroy |
|
respond_to do |format| |
|
if @subject_index.destroy |
|
format.html { redirect_to subject_indexes_path, notice: "Subject Index was successfully destroyed." } |
|
else |
|
format.html { redirect_to subject_index_path(@subject_index), alert: @subject_index.errors.full_messages } |
|
end |
|
end |
|
end |
|
|
|
private |
|
def search_subject(args) |
|
Cdao::Subject.search do |
|
if args[:q].present? |
|
fulltext args[:q], fields: %i[name], query_phrase_slop: 0, minimum_match: 1 do |
|
%i[name code series_no].each { |field| highlight field, max_snippets: 3, fragment_size: 100 } |
|
end |
|
end |
|
|
|
if args[:name].present? |
|
fulltext args[:q], fields: %i[name], query_phrase_slop: 0, minimum_match: 1 do |
|
highlight :name, max_snippets: 3, fragment_size: 100 |
|
end |
|
end |
|
|
|
if args[:parent_id].present? |
|
with :parent_id, args[:parent_id].to_i |
|
else |
|
with :parent_id, nil |
|
end |
|
|
|
without(:id).any_of(args[:exclude_ids]) if args[:exclude_ids].present? |
|
|
|
order_by :name, :asc |
|
|
|
paginate page: args[:page] || 1, per_page: args[:per_page] || 20 |
|
end |
|
end |
|
|
|
def resource_params |
|
params.permit(:name, :parent_id, library_ids: []) |
|
end |
|
|
|
def search_params |
|
params.permit(:name, :parent_id, :state, doctrine_ids: [], exclude_ids: []) |
|
end |
|
end
|
|
|