Browse Source

Merge pull request #117 from lexintegritastech/enhance-ui-for-doctrines-modal-form

Enhance UI for `doctrines#modal_form`
pull/119/head
Alexander D. Bondoc 4 years ago committed by GitHub
parent
commit
9e9c6c5ea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
  2. 72
      app/javascript/controllers/doctrines_controller.js
  3. 9
      app/models/cdao/document.rb
  4. 16
      app/reflexes/doctrines_reflex.rb
  5. 73
      app/views/shared/_annotation_modal_form.html.erb

2
app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb

@ -85,7 +85,7 @@
<div class="row-flex">
<div class="annot-header"> <h5> Annotations </h5> </div>
<div class="" id="annotationsIndexView">
<% annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime("%Y-%m-%d")] }.each do |annotation| %>
<% doctrine.annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime("%Y-%m-%d")] }.each do |annotation| %>
<% document_title = annotation.document.short_title || annotation.document.title %>
<% date_or_year = annotation.document.docdate.present? ? annotation.document.docdate.strftime("%B %d, %Y") : annotation.document.year %>
<% annotated_documents_title = [] %>

72
app/javascript/controllers/doctrines_controller.js

@ -49,9 +49,9 @@ export default class extends ApplicationController {
}
save () {
var $modal = $("#doctrineModal"), document_id = this.document_idTarget.value, doctrine_id = this.doctrine_idTarget.value
var params = { subject_ids: $modal.find("select[name='subject_ids[]']").val(), headnote: this.headnoteTarget.value,
content: this.contentTarget.value }
var $this = this, $modal = $("#doctrineModal"), document_id = $this.document_idTarget.value, doctrine_id = $this.doctrine_idTarget.value
var params = { subject_ids: $modal.find("select[name='subject_ids[]']").val(), headnote: $this.headnoteTarget.value,
content: $this.contentTarget.value }
if (!params.subject_ids.length) {
@ -73,28 +73,36 @@ export default class extends ApplicationController {
type: 'PUT',
data: params,
success: function() {
$(".btn-close-x").trigger("click")
$('.toast').addClass('bg-success').show()
$( ".toast-body" ).html( "<span><b>Submitted Successfully</b></span>" ),
$(".btn-close-x").trigger("click");
$('.toast').addClass('bg-success').show();
$( ".toast-body" ).html( "<span><b>Submitted Successfully</b></span>" );
location.pathname = "/documents/" + document_id + "/doctrines/" + doctrine_id
},
error: function() {
$(".btn-close-x").trigger("click"),
$('.toast').addClass('bg-danger').show(),
$( ".toast-body" ).html( "<span><b>Unexpected Error Problem Occurred</b></span>" )
$(".btn-close-x").trigger("click");
$('.toast').addClass('bg-danger').show();
$( ".toast-body" ).html( "<span><b>Unexpected Error Problem Occurred</b></span>" );
}
})
} else {
$.post("/api/doctrines", $.extend({ jurisprudence_ids: [document_id] }, params), function(data, status) {
if(status === 'success') {
$('.toast').addClass('bg-success').show();
$( ".toast-body" ).html( "<span><b>Submitted Successfully</b></span>" );
const contrim_alert = confirm("Do you want to create an Annotation?")
if (contrim_alert) {
$this.stimulate("DoctrinesReflex#render_annotation_modal_form", document_id, data.id)
$('.toast').fadeOut(5000)
} else {
$(".btn-close-x").trigger("click")
$('.toast').addClass('bg-success').show()
$( ".toast-body" ).html( "<span><b>Submitted Successfully</b></span>" ),
location.pathname = "/documents/" + document_id + "/doctrines/" + data.id
}else {
$(".btn-close-x").trigger("click"),
$('.toast').addClass('bg-danger').show(),
$( ".toast-body" ).html( "<span><b>Unexpected Error Problem Occurred</b></span>" )
}
} else {
$(".btn-close-x").trigger("click");
$('.toast').addClass('bg-danger').show();
$( ".toast-body" ).html( "<span><b>Unexpected Error Problem Occurred</b></span>" );
}
})
}
@ -111,11 +119,43 @@ export default class extends ApplicationController {
url: "/api/doctrines/" + doctrine_id,
type: 'DELETE',
success: function() {
$('.toast').addClass('bg-danger').show();
$( ".toast-body" ).html( "<span><b>Deleted Successfully</b></span>" );
location.pathname = "/documents/" + document_id
},
error: function () {
$('.toast').addClass('bg-danger').show();
$( ".toast-body" ).html( "<span><b>Unexpected Error Problem Occurred</b></span>" );
}
})
}
}
saveAnnotation () {
var $modal = $("#doctrineModal")
const params = { doctrine_id: $modal.find("#doctrine_id").val(), document_id: $modal.find("#document_id").val(),
document_ids: $modal.find("#document_ids").val().split(","), content: $modal.find("#document_title").val(),
phil_rep: $modal.find("#phil_rep").val(), editor_notes: $modal.find("#editor_notes").val(),
annomark_ids: $modal.find("select[name='annomark_ids[]']").val() }
$.post("/api/doctrines/" + params.doctrine_id + "/annotations", params, function (result, status) {
if(status === "success") {
$(".btn-close-x").trigger("click");
$('.toast').addClass('bg-success').show();
$( ".toast-body" ).html( "<span><b>Submitted Successfully</b></span>" );
location.pathname = "/documents/" + $modal.find("#current_document_id").val() + "/doctrines/" + params.doctrine_id
} else {
$(".btn-close-x").trigger("click")
$('.toast').addClass('bg-danger').show()
$( ".toast-body" ).html( "<span><b>Deleted Successfully</b></span>" );
$( ".toast-body" ).html( "<span><b>Unexpected Error Problem Occurred</b></span>" )
}
})
}
closeDoctrineAnnotationModalForm () {
var $current_document_id = $("#doctrineModal").find("#current_document_id").val()
var $doctrine_id = $("#doctrineModal").find("#doctrine_id").val()
$(".btn-close-x").trigger("click");
location.pathname = "/documents/" + $current_document_id + "/doctrines/" + $doctrine_id
}
}

9
app/models/cdao/document.rb

@ -14,6 +14,15 @@ class Cdao::Document < Cdao::Base
(reference_number.presence || "").gsub(/<!--\d+-->/, "")
end
def doc_date_display
doc_date.present? ? doc_date.strftime("%B %d, %Y") : year
end
def display_text
title_display = short_title || title
[title_display, clean_reference_number, doc_date_display].join(", ")
end
def libraries
Cdao::DocumentLibrary.where(library_product_type: doc_type, library_product_id: doc_id).map(&:library)
end

16
app/reflexes/doctrines_reflex.rb

@ -0,0 +1,16 @@
# frozen_string_literal: true
class DoctrinesReflex < ApplicationReflex
include DoctrineSearch
def render_document_doctrines_index(search_params)
search = doctrine_search(search_params)
morph "#doctrinesIndexView", render(partial: "/shared/document_doctrines_index", locals: { doctrines: search.results, current_user: current_user, opts: { document_id: search_params[:jurisprudence_id], current_page: search_params[:page] } })
end
def render_annotation_modal_form(document_id, doctrine_id)
jurisprudence = Cdao::Jurisprudence.find(document_id)
document = Cdao::Document.where(reference_number: jurisprudence.reference_number).first
morph "#doctrineModal", render(partial: "/shared/annotation_modal_form", locals: { document: document, doctrine_id: doctrine_id, jurisprudence: jurisprudence })
end
end

73
app/views/shared/_annotation_modal_form.html.erb

@ -1 +1,72 @@
<%= render AnnotationMarksModalFormComponent.new(current_user: current_user, opts: { is_show: true }) %>
<div class="modal-dialog modal-lg modal-dialog-scrollable" data-controller="doctrines selectize">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"> New Annotation </h5>
<button type="button" class="btn-close-x" data-bs-dismiss="modal" aria-label="Close">x</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :annotation_marks %> </strong>
<%= hidden_field_tag :doctrine_id, doctrine_id %>
<%= hidden_field_tag :current_document_id, jurisprudence.id %>
<%= hidden_field_tag :document_id, document.id %>
<%= hidden_field_tag :document_ids, nil %>
<%= select_tag "annomark_ids[]", options_from_collection_for_select(Annomark.all.order(name: :asc), :id, :name),
class: "form-control default-selectize ps-0", multiple: true, prompt: "Please select" %>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :document_title %> </strong>
<%= text_area_tag :document_title, document.display_text, class: "form-control selected-citing-docs" %>
</div>
</div>
<div id="annotatedDocumentsSearchResults">
<div class="row">
<div class="col-sm-10 p-2">
<%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number, Title or Short Title", data: { target: "annotations.q" } %>
</div>
<div class="col-sm-1 p-2">
<button type="button" class="btn btn-success" data-action="click->annotations#searchDocuments"> Search </button>
</div>
</div>
<div class="row tab">
<table class="table table-striped table-hover mb-0" style="width: 98%; margin: 0 auto;">
<thead>
<th class="bg-light"> Reference No. </th>
<th class="bg-light"> Title </th>
<th class="bg-light"> Date </th>
<th class="bg-light"> </th>
</thead>
</table>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :phil_rep %> </strong>
<%= text_field_tag :phil_rep, document.phil_rep, class: "form-control" %>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :editor_notes %> </strong>
<%= rich_text_area_tag :editor_notes, nil, placeholder: "Editor Notes" %>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-action="click->doctrines#saveAnnotation"> Save </button>
<button type="button" class="btn btn-danger"
data-document-id="<%= document.id %>" data-doctrine-id="<%= doctrine_id %>"
data-action="click->doctrines#closeDoctrineAnnotationModalForm">Close</button>
</div>
</div>
</div>

Loading…
Cancel
Save