Browse Source

Minor UI Updates

pull/55/head
alexdbondoc17 4 years ago
parent
commit
d90f3446fd
  1. 4
      app/components/document_advanced_search_component.rb
  2. 5
      app/components/document_advanced_search_component/document_advanced_search_component.html.erb
  3. 12
      app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb
  4. 8
      app/components/reports_search_results_component/reports_search_results_component.html.erb
  5. 2
      app/javascript/controllers/application_controller.js
  6. 148
      app/javascript/controllers/document_controller.js
  7. 2
      app/javascript/controllers/subjects_controller.js
  8. 25
      app/javascript/packs/application.js
  9. 145
      app/javascript/packs/application/footnotes.js
  10. 2
      app/javascript/src/application.scss
  11. 4
      app/views/reports/index.html.erb
  12. 4
      package.json
  13. 33
      yarn.lock

4
app/components/document_advanced_search_component.rb

@ -4,4 +4,8 @@ class DocumentAdvancedSearchComponent < BaseComponent
def initialize(current_user:, opts: {})
@opts = opts
end
def years
(1901..Time.zone.today.year).entries.reverse
end
end

5
app/components/document_advanced_search_component/document_advanced_search_component.html.erb

@ -13,6 +13,11 @@
<%= text_field_tag :title, params[:short_title], class: "form-control" %>
</div>
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label text-white">Year</label>
<%= select_tag :year, options_for_select(years, params[:year]), class: "form-select" %>
</div>
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label text-white">Citation Finder</label>
<%= text_field_tag :citation_finder, params[:citation_finder], class: "form-control" %>

12
app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb

@ -1,4 +1,5 @@
<div class="row-flex m-3 mt-0 doctrine-content-body clickable-link" href="<%= jurisprudence.present? ? document_doctrine_path(jurisprudence.id, id) : doctrine_path(id)%>">
<% if opts[:is_doctrines_index].blank? %>
<% if opts[:is_subjects_index].blank? %>
<% if opts[:is_doctrines_index].present? && opts[:subject_ids].reject(&:blank?).present? %>
<h5 style="color: darkred;"> <%= subjects.where(id: opts[:subject_ids].map(&:to_i)).map(&:lineage_name).join(" ") %> </h5>
@ -10,18 +11,19 @@
<h5> (No Subjects Provided) </h5>
<% end %>
<% end %>
<% end %>
<div class="container-sm <%= opts[:is_subjects_index].present? ? 'm-0 ps-0' : '' %>">
<p class="mb-0"> <%= raw content.html_safe %> </p>
<div class="container-sm ms-3">
<% annotations.each do |annotation| %>
<div class="container-fluid p-0">
<% if opts[:is_doctrines_index].present? %>
<% document_title = annotation.doctrine.document.short_title || annotation.doctrine.document.title %>
<% date_or_year = annotation.doctrine.document.docdate.present? ? annotation.doctrine.document.docdate.to_date.strftime("%B %d, %Y") : annotation.document.year %>
<span> <%= [document_title, annotation.document.reference_number, date_or_year].join(", ") %> </span>
<% document_title = jurisprudence.short_title || jurisprudence.title %>
<% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime("%B %d, %Y") : jurisprudence.year %>
<h5 style="color: darkred;"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5>
<% end %>
<% annotations.each do |annotation| %>
<p class="mb-0 ms-3">
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>

8
app/components/reports_search_results_component/reports_search_results_component.html.erb

@ -4,11 +4,11 @@
<div class="container-fluid p-0">
<% annotations.each do |annotation| %>
<% document_title = annotation.document.short_title || annotation.document.title %>
<% date_or_year = annotation.document.docdate.present? ? annotation.document.docdate : annotation.document.year %>
<h5 style="color: darkred;"> <%= [document_title, annotation.document.reference_number, date_or_year].join(", ") %> </h5>
<% document_title = jurisprudence.short_title || jurisprudence.title %>
<% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.strftime : jurisprudence.year %>
<h5 style="color: darkred;"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5>
<% annotations.each do |annotation| %>
<p class="mb-0 ms-5">
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>

2
app/javascript/controllers/application_controller.js

@ -5,8 +5,10 @@ import { end } from '@popperjs/core'
require("selectize/dist/js/selectize.min");
require("selectize/dist/css/selectize");
require("bootstrap/dist/js/bootstrap")
import Selectize from "selectize";
import Bootstrap from 'bootstrap';
/* This is your ApplicationController.
* All StimulusReflex controllers should inherit from this class.

148
app/javascript/controllers/document_controller.js

@ -4,154 +4,6 @@ export default class extends ApplicationController {
connect () {
super.connect()
$.fn.footnotes = function () {
var a, b, c;
a = $(this), b = a.find('a[href^="#footnote"]')
c = a.find('p>span, p>a[href^="#fn"]>span').filter(function() {
return ($(this).css('color') == 'rgb(255, 0, 0)')
})
b.each(function(){
var $this = $(this);
if($this.anchor_check()) {
if(!$this.parent('span.footnote-x').length) {
// Wrap the anchor with 'footnote-x'
$this.wrap('<span class="footnote-x"></span>')
}
}
})
// Append index to every anchor
b = a.find('span.footnote-x a[href^="#footnote"]')
b.each(function() {
var $this = $(this);
var $matches = $($this.prop("tagName") + '#' + $this.attr("id") + ':not([data-index])')
var index = 0;
$matches.each(function(){
$(this).attr('id', $(this).attr('id') + '_' + index)
$(this).attr('name', $(this).attr('name') + '_' + index)
$(this).attr('href', $(this).attr('href') + '_' + index)
$(this).attr('data-index', index)
index = index + 1;
})
})
c.each(function(){
var $this = $(this)
$this.footnote_check()
})
c = a.find('a[href^="#fn"]')
c.each(function() {
var $this = $(this);
var $matches = $($this.prop("tagName") + '#' + $this.attr("id") + ':not([data-index])')
var index = 0;
$matches.each(function(){
var self, parent
self = $(this), parent = self.parent()
self.closest('p').find('#cdasiatab').detach()
self.attr('id', self.attr('id') + '_' + index)
self.attr('name', self.attr('name') + '_' + index)
self.attr('href', self.attr('href') + '_' + index)
self.attr('data-index', index)
parent.is('a') ? parent.replaceWith(self) : parent.closest('a').replaceWith(parent) // Remove parent its parent 'a' tag
index = index + 1;
})
})
}
$.fn.anchor_check = function () {
var a, b, c, d;
a = $(this), b = a.attr('href'), c = $.trim(a.text())
if (!$.isNumeric($.trim(c)) && c != '*' && c != 'n') { return false }
if($.trim(b) && a.is('[href^="#footnote"]')){
// Check whether href, name and text is valid
var a_href_id = a.attr('href').substring(9) // Get only the value after '#footnote'
var a_name_id = a.attr('name') ? a.attr('name').substring(2) : a_href_id // Get only the value after 'fn' if name attr is present if not return a_href_id
var a_id = a.attr('id') ? a.attr('id').substring(2) : ''
if(a_href_id != a_name_id || a_href_id != c || a_id != c || a_name_id != c){
a.attr('href', '#footnote' + c), a.attr('id', 'fn' + c), a.attr('name', 'fn' + c)
}
} else {
// If anchor to footnote is invalid by href=#footnote*** or no href
// the text inside the 'a' tag will use as a reference
a.attr('href', '#footnote' + c), a.attr('id', 'fn' + c), a.attr('name', 'fn' + c)
}
return true;
}
$.fn.footnote_check = function () {
var a, b, c, d;
a = $(this), d = null
if (a.find('a:not([href^="#footnote"])').size()) {
a.find('a').each(function(){
b = $.trim($(this).text()), c = b.match(/([\*]{1,3}|[\d]{1,3})/)
if (c!= null) {
c = c[0]
d = $(document.createElement('a'))
d.text(b), d.attr('href', '#fn' + c), d.attr('id', 'footnote' + c), d.attr('name', 'footnote' + c), d.addClass('m-r-lg'), d.css('color', 'red')
a.html(''), a.append(d)
return true;
}
})
if (d=null) {
return false
}
} else if (!a.find('a').size()) {
b = $.trim(a.text()), c = b.match(/([\*]{1,3}|[\d]{1,3})/)
if(c!= null){
c = c[0]
d = $(document.createElement('a'))
d.text(b), d.attr('href', '#fn' + c), d.attr('id', 'footnote' + c), d.attr('name', 'footnote' + c), d.addClass('m-r-lg'), d.css('color', 'red')
a.html(''), a.append(d)
}else{
return false
}
}
return true
}
$.fn.footnote = function () {
var a = $(this)
var b, c, d;
b = $(a.attr('href'))
if (b.length<=0 && a.data('index')>0) {
var a_id = a.attr('id').substring(0, a.attr('id').indexOf('_'))
var a_like = $('a[href^="#footnote"][id^="' + a_id + '"]')
var a_found = false;
a_like.each(function() {
if(!a_found){ b = $($(this).attr('href')) }
a_found = b.length > 0
})
}
if (b.length>0) {
c = b.closest('p')
d = c.footnote_text(b.parent('span') || b), d = d.substring(0,499) + (d.length > 500 ? '...' : '')
a.attr('data-original-title', d), a.attr('data-toggle', 'tooltip')
a.tooltip({title: d}), a.tooltip('show')
}
return a
}
$.fn.footnote_text = function (except) {
var a = '';
$(this).children().not(except).each(function() {
// Check first if the current select element not equal to except
var self = $(this)
a += self.text()
})
return a;
}
}
search () {

2
app/javascript/controllers/subjects_controller.js

@ -5,7 +5,7 @@ export default class extends ApplicationController {
}
loadSubjectsAccordion () {
var $this = this, params = { per_page: 200 }, parent_id = $this.element.dataset["subjectParentId"],
var $this = this, params = { per_page: 10000 }, parent_id = $this.element.dataset["subjectParentId"],
opts = { parent_accordion_id: $this.element.dataset["accordionId"], accordionTarget: $this.element.dataset["accordionTarget"],
accordionFor: $this.element.dataset["accordionFor"] }

25
app/javascript/packs/application.js

@ -19,6 +19,7 @@ import "chosen-js";
import 'trix/dist/trix.css';
import 'trix/dist/trix.js';
import "cable_ready";
import "flatpickr/dist/flatpickr";
window.jQuery = $;
window.$ = $;
@ -50,7 +51,31 @@ $(document).on("ready turbolinks:load", function () {
window.open($href);
}
})
var default_config = { altFormat: "m/d/Y", altInput: true, enableTime: false, dateFormat: "Y-m-d", isMobile: true };
$('.default-flatpickr').flatpickr(default_config);
if ($.fn.footnotes) {
$('#documentTabContent').footnotes()
}
$(document).on('click', 'a[href="#footnotes"]', function(event){
event.preventDefault();
$(this).each(function(){
var a, b, c, d;
a = $(this), b = a.attr('href'), c = a.text(), d = '#footnote' + c
a.attr('href', d), a.attr('id', 'fn' + c)
a.trigger('click')
})
}).on('click', 'a[href^="#footnote"], a[href^="#fn"]', function(event){
var a, b;
a = $(this), b = $(a.attr('href'))
if(b.length<=0)return
event.preventDefault()
$(document).wrap('<span class="footnote-x"></span>')
})
});
import "channels"
import "controllers"
import "./application/footnotes"

145
app/javascript/packs/application/footnotes.js

@ -0,0 +1,145 @@
(function ($) {
'use strict';
$.fn.footnotes = function () {
var a, b, c;
a = $(this), b = a.find('a[href^="#footnote"]')
c = a.find('p>span, p>a[href^="#fn"]>span').filter(function() {
return ($(this).css('color') == 'rgb(255, 0, 0)')
})
b.each(function(){
var $this = $(this);
console.log($this)
if($this.anchor_check()){
if(!$this.parent('span.footnote-x').length){
// Wrap the anchor with 'footnote-x'
$this.wrap('<span class="footnote-x"></span>')
}
}
})
// Append index to every anchor
b = a.find('span.footnote-x a[href^="#footnote"]')
b.each(function(){
var $this = $(this);
var $matches = $($this.prop("tagName") + '#' + $this.attr("id") + ':not([data-index])')
var index = 0;
$matches.each(function(){
$(this).attr('id', $(this).attr('id') + '_' + index)
$(this).attr('name', $(this).attr('name') + '_' + index)
$(this).attr('href', $(this).attr('href') + '_' + index)
$(this).attr('data-index', index)
index = index + 1;
})
})
c.each(function(){
var $this = $(this)
$this.footnote_check()
})
c = a.find('a[href^="#fn"]')
c.each(function(){
var $this = $(this);
var $matches = $($this.prop("tagName") + '#' + $this.attr("id") + ':not([data-index])')
var index = 0;
$matches.each(function(){
var self, parent
self = $(this), parent = self.parent()
self.closest('p').find('#cdasiatab').detach()
self.attr('id', self.attr('id') + '_' + index)
self.attr('name', self.attr('name') + '_' + index)
self.attr('href', self.attr('href') + '_' + index)
self.attr('data-index', index)
parent.is('a') ? parent.replaceWith(self) : parent.closest('a').replaceWith(parent) // Remove parent its parent 'a' tag
index = index + 1;
})
})
}
$.fn.anchor_check = function () {
var a, b, c, d;
a = $(this), b = a.attr('href'), c = $.trim(a.text())
if(!$.isNumeric($.trim(c)) && c != '*' && c != 'n'){return false}
if($.trim(b) && a.is('[href^="#footnote"]')){
// Check whether href, name and text is valid
var a_href_id = a.attr('href').substring(9) // Get only the value after '#footnote'
var a_name_id = a.attr('name') ? a.attr('name').substring(2) : a_href_id // Get only the value after 'fn' if name attr is present if not return a_href_id
var a_id = a.attr('id') ? a.attr('id').substring(2) : ''
if(a_href_id != a_name_id || a_href_id != c || a_id != c || a_name_id != c){
a.attr('href', '#footnote' + c), a.attr('id', 'fn' + c), a.attr('name', 'fn' + c)
}
}else{
// If anchor to footnote is invalid by href=#footnote*** or no href
// the text inside the 'a' tag will use as a reference
a.attr('href', '#footnote' + c), a.attr('id', 'fn' + c), a.attr('name', 'fn' + c)
}
return true;
}
$.fn.footnote_check = function () {
var a, b, c, d;
a = $(this), d = null
if(a.find('a:not([href^="#footnote"])').length){
a.find('a').each(function(){
b = $.trim($(this).text()), c = b.match(/([\*]{1,3}|[\d]{1,3})/)
if(c!= null){
c = c[0]
d = $(document.createElement('a'))
d.text(b), d.attr('href', '#fn' + c), d.attr('id', 'footnote' + c), d.attr('name', 'footnote' + c), d.addClass('m-r-lg'), d.css('color', 'red')
a.html(''), a.append(d)
return true;
}
})
if(d=null){
return false
}
}else if(!a.find('a').length){
b = $.trim(a.text()), c = b.match(/([\*]{1,3}|[\d]{1,3})/)
if(c!= null){
c = c[0]
d = $(document.createElement('a'))
d.text(b), d.attr('href', '#fn' + c), d.attr('id', 'footnote' + c), d.attr('name', 'footnote' + c), d.addClass('m-r-lg'), d.css('color', 'red')
a.html(''), a.append(d)
}else{
return false
}
}
return true
}
$.fn.footnote = function () {
var a = $(this)
// Validation of footnote
var b, c, d;
b = $(a.attr('href'))
if(b.length<=0 && a.data('index')>0){
var a_id = a.attr('id').substring(0, a.attr('id').indexOf('_'))
var a_like = $('a[href^="#footnote"][id^="' + a_id + '"]')
var a_found = false;
a_like.each(function(){
if(!a_found){b = $($(this).attr('href'))}
a_found = b.length>0
})
}
if(b.length>0){
c = b.closest('p')
d = c.footnote_text(b.parent('span') || b), d = d.substring(0,499) + (d.length > 500 ? '...' : '')
a.attr('data-original-title', d), a.attr('data-toggle', 'tooltip')
a.tooltip({title: d}), a.tooltip('show')
}else{
// typeof a._errorReport === "function" && a._errorReport({
// type: 'footnote',
// details: 'Footnote not found @ ' + a.attr('href')
// })
}
return a
}
$.fn.footnote_text = function (except) {
var a = '';
$(this).children().not(except).each(function(){
// Check first if the current select element not equal to except
var self = $(this)
a += self.text()
})
return a;
}
$(document).on('mouseover mouseenter focus', 'a[href^="#footnote"]', function(event){
event.preventDefault()
$(this).footnote()
})
}(jQuery))

2
app/javascript/src/application.scss

@ -1,4 +1,6 @@
@import "~bootstrap/scss/bootstrap";
@import '~flatpickr/dist/flatpickr.min';
@import '~flatpickr/dist/themes/airbnb';
@import "./application/sidenav";
@import "./application/sessions";
@import "./application/pagination";

4
app/views/reports/index.html.erb

@ -10,6 +10,10 @@
<label for="exampleFormControlInput1" class="form-label text-white"> Subjects </label>
<select class="form-control subject-ids-selectize p-0" name="subject_ids[]" id="subject_ids_" multiple="true"> </select>
</div>
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label text-white"> Date Created At </label>
<%= text_field_tag :created_at, params[:created_at], class: "default-flatpickr" %>
</div>
<hr class="simple">
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label text-white"> Users </label>

4
package.json

@ -16,11 +16,7 @@
"jquery": "^3.6.0",
"moment": "^2.29.1",
"popper.js": "^1.16.1",
"select2": "^4.1.0-rc.0",
"select2-bootstrap-5-theme": "^1.2.0",
"select2-bootstrap-theme": "^0.1.0-beta.10",
"selectize": "^0.12.6",
"selectize.js": "^0.12.12",
"stimulus": "^3.0.1",
"stimulus_reflex": "3.4.1",
"trix": "^2.0.0-alpha.0",

33
yarn.lock generated

@ -1542,7 +1542,7 @@ boolbase@^1.0.0, boolbase@~1.0.0:
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
integrity sha1-aN/1++YMUes3cl6p4+0xDcwed24=
bootstrap@^5.0.2, bootstrap@^5.1.3:
bootstrap@^5.1.3:
version "5.1.3"
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-5.1.3.tgz#ba081b0c130f810fa70900acbc1c6d3c28fa8f34"
integrity sha512-fcQztozJ8jToQWXxVuEyXWW+dSo8AiXWKwiSSrKWsRB/Qt+Ewwza+JWoLKiTuQLaEPhdNAJ7+Dosc9DOIqNy7Q==
@ -3892,11 +3892,6 @@ jest-worker@^26.5.0:
merge-stream "^2.0.0"
supports-color "^7.0.0"
jquery@^1.7.0:
version "1.12.4"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-1.12.4.tgz#01e1dfba290fe73deba77ceeacb0f9ba2fec9e0c"
integrity sha1-AeHfuikP5z3rp3zurLD5ui/sngw=
jquery@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.0.tgz#c72a09f15c1bdce142f49dbf1170bdf8adac2470"
@ -6017,32 +6012,6 @@ select-hose@^2.0.0:
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
integrity sha1-Yl2GWPhlr0Psliv8N2o3NZpJlMo=
select2-bootstrap-5-theme@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/select2-bootstrap-5-theme/-/select2-bootstrap-5-theme-1.2.0.tgz#36282520c7a88b89818350217600f3440dab718e"
integrity sha512-ia8yvInGTU9XntLQM1+ByGNA+nY2LPqgdB4XA/D766gihZjRpPJlum2eXbg/ur4q+H5hAnoCkY5TcFcX3DseKg==
dependencies:
bootstrap "^5.0.2"
select2-bootstrap-theme@^0.1.0-beta.10:
version "0.1.0-beta.10"
resolved "https://registry.yarnpkg.com/select2-bootstrap-theme/-/select2-bootstrap-theme-0.1.0-beta.10.tgz#b9426ecfc03bf4a235e76a132377574310469ac0"
integrity sha1-uUJuz8A79KI152oTI3dXQxBGmsA=
select2@^4.1.0-rc.0:
version "4.1.0-rc.0"
resolved "https://registry.yarnpkg.com/select2/-/select2-4.1.0-rc.0.tgz#ba3cd3901dda0155e1c0219ab41b74ba51ea22d8"
integrity sha512-Hr9TdhyHCZUtwznEH2CBf7967mEM0idtJ5nMtjvk3Up5tPukOLXbHUNmh10oRfeNIhj+3GD3niu+g6sVK+gK0A==
selectize.js@^0.12.12:
version "0.12.12"
resolved "https://registry.yarnpkg.com/selectize.js/-/selectize.js-0.12.12.tgz#67321487881a81506abe388b2995d3af3ad6edcd"
integrity sha1-ZzIUh4gagVBqvjiLKZXTrzrW7c0=
dependencies:
jquery "^1.7.0"
microplugin "0.0.3"
sifter "^0.5.1"
selectize@^0.12.6:
version "0.12.6"
resolved "https://registry.yarnpkg.com/selectize/-/selectize-0.12.6.tgz#c2cf08cbaa4cb06c5e99bb452919d71b080690d6"

Loading…
Cancel
Save