Skip to content

Commit

Permalink
merged 20241126-maintenance-release into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Jan 7, 2025
2 parents 646848c + 5f3634a commit e52f6a3
Show file tree
Hide file tree
Showing 40 changed files with 287 additions and 156 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ public/assets/
yarn.lock
*.log
.bundle
<<<<<<< HEAD
*.env
!.env
*.sql
*.sql.gz
log/*
=======
*.sql.gz
*.sql
>>>>>>> origin/20241126-maintenance-release
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

source 'http://rubygems.org'
ruby '3.1.4'
ruby '3.1.4'

## RAILS and related ##
gem 'rails', '~> 7.0.0'
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ There are 3 containers created: **web**, **db** and **mailcatcher**

# Access the front end web app in DEVELOPMENT

By default, the application will listen on port 3006 and runs with RAILS_ENV=development.
By default, the application will listen on port 3006 and runs with RAILS_ENV=development.

To access the application in Chrome browser, you will need to add the ModHeader extension to your Chrome browser.

Once the extension has been activated, you can add the following header to the site http://localhost:3006/. This will enable you to login as **manager** user.
Once the extension has been activated, you can add the following header to the site http://localhost:3006/. This will enable you to login as **manager** user.

Header: PYORK_USER
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/bib_finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function searchRecords() {

$("#item_publisher").val(my_record.publisher);
$("#item_isbn").val(my_record.isbn);

$("#item_other_isbn_issn").val(my_record.other_isbn_issn);
$("#item_callnumber").val(my_record.callnumber);
$("#item_edition").val(my_record.edition);
$("#item_publication_date").val(my_record.publish_date);
Expand Down
41 changes: 25 additions & 16 deletions app/assets/javascripts/request_history.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
$(document).ready(function() {
$(".request_history table .comment").click(function() {
//alert($(this).parent().next().prop("class"));
$(this).parent().next().toggleClass('hide');
});



$("#note-textarea").bind('keyup', function(){
checkCount();
$(document).on("click", ".request_history table .comment", function() {
$(this).parent().next().toggleClass('hide');
});

$(document).on('keyup', '[id^="note-textarea_"]', function () {
updateCharacterCount($(this));
});


$('#history_popup').on('shown.bs.modal', function (e) {
Expand All @@ -18,16 +15,28 @@ $(document).ready(function() {
$( "#request_history_log" ).load( data_url);
} );

$(document).on('shown.bs.modal', '[id^="item_history_popup_"]', function () {
var $modal = $(this);
var itemId = $modal.attr('id').split('_').pop();
var dataUrl = $modal.find("#request_history_log_" + itemId).data("url");

if (dataUrl) {
$modal.find("#request_history_log_" + itemId).load(dataUrl);
}
});

});

/* Checks the count of the note text area and changes color to red if limit hit */
function checkCount(){
var textAreaValue = $("#note-textarea").val();
$('.remaining').html(textAreaValue.length);
function updateCharacterCount($textArea) {
var textAreaValue = $textArea.val();
var itemId = $textArea.attr('id').split('_').pop();
var remainingCounter = $textArea.closest('.modal').find('.remaining');

remainingCounter.text(textAreaValue.length);

if (textAreaValue.length > 255) {
$('.remaining').addClass("red");
}
else {
$('.remaining').removeClass("red");
remainingCounter.addClass("red");
} else {
remainingCounter.removeClass("red");
}
}
8 changes: 4 additions & 4 deletions app/assets/stylesheets/controllers/items.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ form {

a.change-item-status {
&.item_ready {
color: #006600;
border: 1px solid #006600;
color: #32cd32;
border: 1px solid #32cd32;
}

&.item_not_ready {
Expand All @@ -45,7 +45,7 @@ form {

&.item_ready:hover,
&.item_ready:focus {
color: green;
color: #32cd32;
}


Expand All @@ -54,7 +54,7 @@ form {
span.item-status {
&.item_ready {
color: white;
background: green;
background: #32cd32;
}
}

Expand Down
1 change: 1 addition & 0 deletions app/controllers/acquisition_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def change_status

def send_to_acquisitions
@acquisition_request.audit_comment = "Sent email to #{params[:which].humanize}. CC: #{current_user.email}"
@acquisition_request.acquisition_notes = params[:acquisition_notes]
@acquisition_request.save(validate: false)

@acquisition_request.email_to(params[:which], current_user)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index
end

## location, nil is all locations
location_id = params[:location] || nil
location_id = params[:location] || 'all'

if location_id.nil?
## home location
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create

respond_to do |format|
if @item.save
@request.update(status: Request::OPEN)
@request.reload
RequestMailer.new_item_notification(@request, @item).deliver_later

format.html { redirect_to [@request, @item], notice: 'Item was successfully created.' }
Expand Down Expand Up @@ -78,6 +78,7 @@ def update
def destroy
@item.audit_comment = "Item #{@item.title} removed from request"
@item.destroy
@request.reload
respond_to do |format|
format.html { redirect_to @request }
format.js
Expand Down Expand Up @@ -123,7 +124,7 @@ def set_item

# Never trust parameters from the scary internet, only allow the white list through.
def item_params
item_attributes = %i[id title author description callnumber isbn publication_date edition publisher loan_period provided_by_requestor
item_attributes = %i[id title author description callnumber isbn other_isbn_issn publication_date edition publisher loan_period provided_by_requestor
metadata_source metadata_source_id _destroy request_id item_type copyright_options other_copyright_options url format map_index_num
page_number physical_copy_required journal_title issue volume ils_barcode]

Expand Down
43 changes: 33 additions & 10 deletions app/controllers/request_history_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,64 @@ class RequestHistoryController < ApplicationController
authorize_resource User
# skip_authorization_check

def index
@audits = @request.audits | @request.associated_audits # | @request.course.audits
@audits.sort! { |a, b| a.created_at <=> b.created_at }
def index
associated_audits = @request.associated_audits.where.not(associated_type: 'item')

@audits_grouped = @audits.reverse.group_by { |a| a.created_at.at_beginning_of_day }
request_audits = @request.audits.where(auditable_type: 'Request', associated_id: nil, associated_type: nil)

@audits = (associated_audits + request_audits).sort_by(&:created_at)

@audits_grouped = @audits.reverse.group_by { |audit| audit.created_at.at_beginning_of_day }

@users = User.all
@locations = Location.active

render partial: 'history_log', layout: false if request.xhr?
end

def item_history
item_id = params[:item_id]
@audits = @request.audits.where(associated_type: 'item', associated_id: item_id.to_i).order(created_at: :desc)

@audits_grouped = @audits.reverse.group_by { |a| a.created_at.at_beginning_of_day }

@users = User.all
@locations = Location.active

render partial: 'history_log', layout: false if request.xhr?
end



def create
# @aud = Audited::Adapters::ActiveRecord::Audit.new
@item_id = params[:item_id]
@aud = Audited::Audit.new
@aud.action = 'note'
@aud.user = current_user
@aud.auditable = @request
@aud.audited_changes = 'Note Added'
@aud.comment = params[:audit_comment]

if @item_id.present?
@aud.associated_id = @item_id
@aud.associated_type = "item"
end


respond_to do |format|
redirect_path = @item_id.present? ? item_history_request_path(@request, item_id: @item_id) : history_request_path(@request)
if @aud.comment.blank?
format.html { redirect_to history_request_path(@request), alert: 'Note is blank. Nothing updated' }
format.html { redirect_to redirect_path, alert: 'Note is blank. Nothing updated' }
format.js
elsif @aud.comment.length > 255
format.html { redirect_to history_request_path(@request), alert: 'Note is more than 255 characters!' }
format.html { redirect_to redirect_path, alert: 'Note is more than 255 characters!' }
format.js
elsif @aud.save
format.html { redirect_to history_request_path(@request), notice: 'Note saved' }
format.html { redirect_to redirect_path, notice: 'Note saved' }
format.js
else
format.html do
redirect_to history_request_path(@request), alert: 'Note not saved. Please contact application administrator'
end
format.html { redirect_to redirect_path, alert: 'Note not saved. Please contact application administrator' }
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/request_wizard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RequestWizardController < ApplicationController

def step_one
if current_user.valid?
@request = Request.new
@request = Request.new(status: Request::INCOMPLETE)
@request.course = Course.new
@request.requester = current_user
else
Expand Down Expand Up @@ -35,7 +35,7 @@ def save
end
else
@old_request = get_request_duplicated
if @old_request.course.created_by_id == current_user.id
if !@old_request.nil? && @old_request.course.created_by_id == current_user.id
redirect_to new_request_step_two_path(@old_request), notice: 'Proceeding to Step 2.'
elsif !@request.save
render action: 'step_one'
Expand All @@ -48,7 +48,7 @@ def step_two
end

def finish
if @request.items.size.positive?
if @request.items.where.not(status: 'deleted').exists?
@request.audit_comment = 'Request Step Two Completed'
@request.status = Request::OPEN
@request.requested_date = Date.today.to_date
Expand All @@ -62,7 +62,7 @@ def finish

else
redirect_to new_request_step_two_path(@request),
alert: 'You must add at least one item for this request to be submitted!'
alert: 'You must add at least one active item for this request to be submitted!'
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/items_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def format(field, simple_format = false)

def show_field?(item, field, &block)
field_map = {
Item::TYPE_BOOK => %w[title author callnumber isbn publisher publication_date edition
Item::TYPE_BOOK => %w[title author callnumber isbn other_isbn_issn publisher publication_date edition
provided_by loan_period physical_copy_required],
Item::TYPE_EBOOK => %w[title author callnumber isbn publisher publication_date edition
provided_by url],
Expand Down
2 changes: 1 addition & 1 deletion app/models/acquisition_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AcquisitionRequest < ApplicationRecord

## VALIDATIONS
validates_presence_of :item, :requested_by, :location ## default basic validation
validates_presence_of :acquired_by, :acquired_at, :acquisition_source_type, :acquisition_source_name, if: lambda {
validates_presence_of :acquired_by, :acquired_at, if: lambda {
status == STATUS_ACQUIRED
}
validates_presence_of :cancelled_by, :cancelled_at, :cancellation_reason, if: lambda {
Expand Down
10 changes: 7 additions & 3 deletions app/models/bib_result.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class BibResult
attr_accessor :title, :author, :isbn_issn, :callnumber, :publication_date, :publisher, :edition,
attr_accessor :title, :author, :isbn_issn, :other_isbn_issn, :callnumber, :publication_date, :publisher, :edition,
:item_type, :format, :map_index_num, :journal_title, :volume, :page_number,
:issue, :ils_barcode, :ils_id, :description, :main_location, :url, :rtype,
:catalogue_record, :source, :language, :subject
Expand Down Expand Up @@ -65,10 +65,13 @@ def from_primo(record)
rescue StandardError
'n/a'
end
self.isbn_issn = get_value record[:pnx]['addata']['isbn']
self.isbn_issn = get_value(record[:pnx]['addata']['isbn']&.first || '').tr('^A-Za-z0-9', '')
self.other_isbn_issn = (record[:pnx]['addata']['isbn']&.drop(1) || []).map { |isbn| get_value(isbn).tr('^A-Za-z0-9', '') }.join(',')

## journals
self.isbn_issn = get_value record[:pnx]['addata']['issn'] if isbn_issn.blank?
self.isbn_issn = get_value(record[:pnx]['addata']['issn']&.first || '').tr('^A-Za-z0-9', '') if isbn_issn.blank?
self.other_isbn_issn = (record[:pnx]['addata']['issn']&.drop(1) || []).map { |issn| get_value(issn).tr('^A-Za-z0-9', '') }.join(',') if isbn_issn.blank?

self.journal_title = get_value record[:pnx]['addata']['jtitle']
self.volume = get_value record[:pnx]['addata']['volume']
self.issue = get_value record[:pnx]['addata']['issue']
Expand Down Expand Up @@ -111,6 +114,7 @@ def to_json(*_args)
{ title: title,
author: author,
isbn_issn: isbn_issn,
other_isbn_issn: other_isbn_issn,
callnumber: callnumber,
publication_date: publication_date,
publisher: publisher,
Expand Down
1 change: 1 addition & 0 deletions app/models/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Request < ApplicationRecord

## VALIDATIONS

validates :course, presence: { message: 'Cannot be empty' }
# :requester_id, :course_id, :item_id ,:assigned_to_id, :department_id,
validates_presence_of :reserve_start_date, :reserve_location_id, :course, :reserve_end_date,
message: 'Cannot be empty'
Expand Down
2 changes: 1 addition & 1 deletion app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Setting < RailsSettings::Base

## Request Related Defaults
field :request_expiry_notice_interval, default: (ENV['request_expiry_notice_interval'] || 2.weeks)
field :request_archive_all_after, default: (ENV['request_archive_all_after'] || 60.days)
field :request_archive_all_after, default: (ENV['request_archive_all_after'] || 60)
field :request_archive_all_user_id, default: (ENV['request_archive_all_user_id'] || 0)
field :request_archive_all_allow, default: (ENV['request_archive_all_allow'] || false)
field :request_remove_incomplete_allow, default: (ENV['request_remove_incomplete_allow'] || false)
Expand Down
2 changes: 1 addition & 1 deletion app/views/acquisition_requests/_new_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<%= f.button :submit, class: "btn btn-success", value: "Request Acquisition" %>
<%= f.button :submit, class: "btn btn-success", value: "Create Acquisition Request" %>
</div>
<% end %>

Expand Down
11 changes: 9 additions & 2 deletions app/views/acquisition_requests/_send_email_choice.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<% if can? :send_to_acquisitions, @acquisition_request %>
<hr/>
<p>Send Acquisition Email To:</p>
<%= form_tag send_to_acquisitions_acquisition_request_path(@acquisition_request), method: :post do |f| %>
<select name="which" class="form-control">
<option value="<%= AcquisitionRequest::EMAIL_TO_BOOKSTORE %>">Bookstore</option>
<%# <option value="<%= AcquisitionRequest::EMAIL_TO_BOOKSTORE %>">Bookstore</option> %>
<option value="<%= AcquisitionRequest::EMAIL_TO_ACQUISITIONS %>">Acquisitions Department</option>
<% if @acquisition_request.location.acquisitions_email.blank? %>
<option disabled>-- No Acquistion Email Set For This Location --</option>
Expand All @@ -12,6 +11,14 @@
<% end %>
</select>

<br>

<div class="form-group">
<label for="acquisition_notes">Notes</label>
<textarea name="acquisition_notes" id="acquisition_notes" class="form-control"><%= @acquisition_request.acquisition_notes %></textarea>
<small class="form-text text-muted">This note will be sent along with the acquisition email.</small>
</div>

<%= submit_tag 'Send Request Details', data: { confirm: "Are you sure? "}, class: "btn btn-sm btn-primary", style: "margin-top: 10px;" %>
<% end %>

Expand Down
Loading

0 comments on commit e52f6a3

Please sign in to comment.