diff --git a/app/components/sidenav_component/sidenav_component.html.erb b/app/components/sidenav_component/sidenav_component.html.erb
index a4e0444..cb79ba3 100644
--- a/app/components/sidenav_component/sidenav_component.html.erb
+++ b/app/components/sidenav_component/sidenav_component.html.erb
@@ -16,7 +16,7 @@
diff --git a/app/controllers/case_doctrines_controller.rb b/app/controllers/case_doctrines_controller.rb
deleted file mode 100644
index 5b04f2b..0000000
--- a/app/controllers/case_doctrines_controller.rb
+++ /dev/null
@@ -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
diff --git a/app/controllers/doctrine/annotations_controller.rb b/app/controllers/doctrine/annotations_controller.rb
new file mode 100644
index 0000000..5b9135d
--- /dev/null
+++ b/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
diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb
index 0b13bc8..c4f6ff8 100644
--- a/app/controllers/documents_controller.rb
+++ b/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
diff --git a/app/controllers/jurisprudence/doctrines_controller.rb b/app/controllers/jurisprudence/doctrines_controller.rb
new file mode 100644
index 0000000..dc5de6a
--- /dev/null
+++ b/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
diff --git a/app/models/doctrine.rb b/app/models/doctrine.rb
index 35c5b9b..3b7a7c0 100644
--- a/app/models/doctrine.rb
+++ b/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
@@ -25,9 +28,9 @@ class Doctrine < ApplicationRecord
def subject_ids=(ids)
ids.each do |subject_id|
record = DoctrineSubject.find_or_initialize_by(doctrine_id: self.id, subject_id: subject_id)
-
+
next if record.persisted?
-
+
record.save
end
diff --git a/config/routes.rb b/config/routes.rb
index e40ae0c..772fc8f 100644
--- a/config/routes.rb
+++ b/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