Browse Source

Updates for doctrines and annotations

pull/6/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
3872a0695f
  1. 2
      app/components/sidenav_component/sidenav_component.html.erb
  2. 17
      app/controllers/case_doctrines_controller.rb
  3. 54
      app/controllers/doctrine/annotations_controller.rb
  4. 5
      app/controllers/documents_controller.rb
  5. 40
      app/controllers/jurisprudence/doctrines_controller.rb
  6. 3
      app/models/doctrine.rb
  7. 13
      config/routes.rb

2
app/components/sidenav_component/sidenav_component.html.erb

@ -16,7 +16,7 @@
<div class="accordion-item">
<h5 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#mainDoctrinesSubMenu">
<%= link_to "Doctrines", case_doctrines_path, class: "accordion-link text-dark" %>
<%= link_to "Doctrines", "#", class: "accordion-link text-dark" %>
</button>
</h5>

17
app/controllers/case_doctrines_controller.rb

@ -1,17 +0,0 @@
# frozen_string_literal: true
class CaseDoctrinesController < ApplicationController
def index; end
def new; end
def edit; end
def show; end
def create; end
def update; end
def destroy; end
end

54
app/controllers/doctrine/annotations_controller.rb

@ -0,0 +1,54 @@
class Doctrine::AnnotationsController < ApplicationController
load_and_authorize_resource :doctrine, class: "Doctrine"
load_and_authorize_resource :annotation, class: "Annotation", through: :doctrine
def create
attrs = resource_params.to_unsafe_h
document_id = attrs.delete(:document_id)
@annotation = Annotation.new(attrs)
if document_id.present?
@annotation.document = Cdao::Jurisprudence.find(attrs.delete(:document_id))
end
respond_to do |format|
if @annotation.save
format.html { redirect_to document_path(@doctrine.document) , notice: "Doctrine Annotation was successfully created." }
else
format.html { redirect_to document_path(@doctrine.document) }
end
end
end
def update
attrs = resource_params.to_unsafe_h
document_id = attrs.delete(:document_id)
attrs[:document] = Cdao::Jurisprudence.find(document_id) if document_id.present?
respond_to do |format|
if @annotation.update(attrs)
format.html { redirect_to document_path(@doctrine.document), notice: "Doctrine Annotation was successfully updated." }
else
format.html { redirect_to document_path(@doctrine.document) }
end
end
end
def destroy
respond_to do |format|
if @annotation.destroy
format.html { redirect_to subject_indexes_path, notice: "Doctrine Annotation was successfully destroyed." }
else
format.html { redirect_to document_path(@doctrine.document), alert: @annotation.errors.full_messages }
end
end
end
private
def resource_params
params.permit(:document_id, :annomark_id, :phil_rep, :editor_notes, :rank)
end
end

5
app/controllers/documents_controller.rb

@ -20,13 +20,14 @@ class DocumentsController < ApplicationController
@jurisprudences = search.results
respond_to do |format|
format.html
end
end
def show; end
def show
@doctrines = @document.doctrines
end
private
def search_params

40
app/controllers/jurisprudence/doctrines_controller.rb

@ -0,0 +1,40 @@
class Jurisprudence::DoctrinesController < ApplicationController
load_and_authorize_resource :jurisprudence, class: "Cdao::Jurisprudence"
load_and_authorize_resource :doctrine, class: "Doctrine", through: :jurisprudence
def create
respond_to do |format|
if @doctrine.save
format.html { redirect_to document_path(@jurisprudence), notice: "Doctrine was successfully created." }
else
format.html { redirect_to document_path(@jurisprudence) }
end
end
end
def update
respond_to do |format|
if @doctrine.update(resource_params)
format.html { redirect_to document_path(@jurisprudence), notice: "Doctrine was successfully updated." }
else
format.html { redirect_to document_path(@jurisprudence) }
end
end
end
def destroy
respond_to do |format|
if @doctrine.destroy
format.html { redirect_to subject_indexes_path, notice: "Doctrine was successfully destroyed." }
else
format.html { redirect_to document_path(@jurisprudence), alert: @doctrine.errors.full_messages }
end
end
end
private
def resource_params
params.permit(:content, subject_ids: [])
end
end

3
app/models/doctrine.rb

@ -1,6 +1,9 @@
class Doctrine < ApplicationRecord
belongs_to :document, polymorphic: true, optional: false
has_many :doctrine_subjects, dependent: :destroy
has_many :subjects, through: :doctrine_subjects
has_many :annotations, dependent: :destroy
validates :content, presence: true

13
config/routes.rb

@ -3,7 +3,18 @@ Rails.application.routes.draw do
root to: "home#index"
resources :case_doctrines, only: %i[index]
resources :doctrines, only: [] do
scope module: :doctrine do
resources :annotations, only: %i[create update destroy]
end
end
resources :jurisprudences, only: [] do
scope module: :jurisprudence do
resources :doctrines, only: %i[create update destroy]
end
end
resources :documents, only: %i[index show]
resources :decisions, only: %i[index show]
resources :subject_indexes

Loading…
Cancel
Save