Skip to content

Commit

Permalink
Merge pull request #1321 from jonkerz/3.7.11.1-grab-bag
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkerz committed Jul 23, 2021
2 parents 608bdc2 + c93f7ac commit d65e762
Show file tree
Hide file tree
Showing 45 changed files with 80 additions and 111 deletions.
11 changes: 1 addition & 10 deletions app/assets/javascripts/all_pages/global.coffee
Expand Up @@ -12,21 +12,12 @@ $ ->
# To make ".disabled" link be unclickable.
$('body').on 'click', 'a.disabled', (event) -> event.preventDefault()

# Something seems to override this method when
# it's named "enable" - it doesn't get called.
$.fn.undisable = -> @.removeClass('ui-state-disabled').removeAttr('disabled')
$.fn.disable = -> @.addClass('ui-state-disabled').attr('disabled', 'true')

# Like above, but without jQuery UI classes.
$.fn.enableButton = -> @removeClass "disabled"
$.fn.disableButton = -> @addClass "disabled"

AntCat.notifySuccess = (content, autoHide = true) -> $.notify content, className: "success", autoHide: autoHide
AntCat.notifyError = (content, autoHide = true) -> $.notify content, autoHide: autoHide

# Used by `ApplicationHelper#inline_expandable`.
enableInlineExpansions = ->
$(".expandable").on "click", (event) ->
$(".expandable").on "click", (_event) ->
$(this).find(".show-when-expanded, .hide-when-expanded").toggle()

AntCat.escapeRegExp = (string) ->
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/controllers/authors/merges.coffee
Expand Up @@ -6,4 +6,4 @@ setupAuthorAutocomplete = ->
autoFocus: true
minLength: 1
source: '/authors/autocomplete'
select: (event, ui) -> $("#author_to_merge_id").val ui.item.author_id
select: (_event, ui) -> $("#author_to_merge_id").val(ui.item.author_id)
4 changes: 2 additions & 2 deletions app/assets/javascripts/controllers/references/form.coffee
Expand Up @@ -19,7 +19,7 @@ setupAdvancedAuthorAutocomplete = ->
$('#reference_author_names_string').autocomplete
autoFocus: true
minLength: 1
source: (request, response) ->
source: (_request, response) ->
selectionStart = AntCat.getInputSelection(@element.get(0), true)
searchTerm = extractAuthorSearchTerm(@element.val(), selectionStart)
if searchTerm.length >= 1
Expand All @@ -28,7 +28,7 @@ setupAdvancedAuthorAutocomplete = ->
response []
return
focus: -> false
select: (event, ui) ->
select: (_event, ui) ->
$this = $(this)
selectionStart = AntCat.getInputSelection($this.get(0), true)
value_and_position = insertAuthor(@value, selectionStart, ui.item.value)
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/globals/create_copy_buttons.js
Expand Up @@ -2,7 +2,7 @@
// It will remain horrible for some time since it's used both in Sprockets JS and Vue.
// And it's ES5.

$(function () {
$(function() {
window.AntCat.CreateCopyButtons(document);
});

Expand All @@ -11,8 +11,8 @@ window.AntCat.CreateCopyButtons = function(element) {
return;
}

element.querySelectorAll('[data-copy-to-clipboard]').forEach(function (item) {
item.addEventListener('click', function (event) {
element.querySelectorAll('[data-copy-to-clipboard]').forEach(function(item) {
item.addEventListener('click', function(event) {
event.preventDefault()
var stringToCopy = item.getAttribute('data-copy-to-clipboard');
CopyToClipboard(stringToCopy);
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/revision_comparer.coffee
Expand Up @@ -43,7 +43,7 @@ unavailable_DIFF_WITH_ID_radios = ->
# All right-mosts radios ("SELECTED_ID") above the checked "DIFF_WITH_ID",
# ie those having a lower value, should be hidden.
unavailable_SELECTED_ID_radios = ->
DIFF_WITH_ID_value = parseInt $("#{DIFF_WITH_ID}:checked").prop("value")
DIFF_WITH_ID_value = parseInt $("#{DIFF_WITH_ID}:checked").prop("value")

$ jQuery.grep $(SELECTED_ID), (v) ->
return false if v.value == "" # HACK: Same as above.
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/fireworks.css
Expand Up @@ -83,7 +83,7 @@ $box-shadow2: ();
}
}

@include keyframes(gravity) {
@include keyframes(gravity) {
to {
@include transform(translateY(200px));
opacity: 0;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Expand Up @@ -14,7 +14,7 @@ def index
end

def create
@comment = Comment.build_comment commentable, current_user, body: comment_params[:body]
@comment = Comment.build_comment(commentable, current_user, body: comment_params[:body])

if @comment.save
@comment.create_activity Activity::CREATE, current_user
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/database_scripts_controller.rb
Expand Up @@ -26,7 +26,7 @@ def show

@database_script = find_database_script
@decorated_database_script = @database_script.decorate
@rendered, @render_duration = timed_render
@rendered, @render_duration = timed_render @database_script
end

private
Expand Down Expand Up @@ -58,9 +58,9 @@ def check_if_empty?
end

# TODO: Probably move from controller and wrap in a renderer.
def timed_render
def timed_render database_script
start = Time.current
rendered = DatabaseScripts::Render.new(@database_script, render_options).call
rendered = DatabaseScripts::Render.new(database_script, render_options).call
render_duration = Time.current - start

[rendered, render_duration]
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/feedbacks_controller.rb
Expand Up @@ -12,7 +12,7 @@ def index

def show
@feedback = find_feedback
@new_comment = Comment.build_comment @feedback, current_user
@new_comment = Comment.build_comment(@feedback, current_user)
end

def new
Expand All @@ -29,7 +29,7 @@ def create

@feedback.ip = request.remote_ip

if rate_throttle?
if rate_throttle?(@feedback.ip)
@feedback.errors.add :base, <<~MSG
You have already posted a couple of feedbacks in the last few minutes. Thanks for that!
Please wait for a few minutes while we are trying to figure out if you are a bot...
Expand Down Expand Up @@ -106,8 +106,8 @@ def feedback_params
params.require(:feedback).permit(:comment, :name, :email, :user, :page)
end

def rate_throttle?
def rate_throttle? remote_ip
return if current_user
Feedback.submitted_by_ip(@feedback.ip).recent.count >= 5
Feedback.submitted_by_ip(remote_ip).recent.count >= 5
end
end
2 changes: 1 addition & 1 deletion app/controllers/issues_controller.rb
Expand Up @@ -11,7 +11,7 @@ def index

def show
@issue = find_issue
@new_comment = Comment.build_comment @issue, current_user
@new_comment = Comment.build_comment(@issue, current_user)
end

def new
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/site_notices_controller.rb
Expand Up @@ -12,7 +12,7 @@ def index

def show
@site_notice = find_site_notice
@new_comment = Comment.build_comment @site_notice, current_user
@new_comment = Comment.build_comment(@site_notice, current_user)
end

def new
Expand Down
22 changes: 11 additions & 11 deletions app/controllers/taxa/create_combinations_controller.rb
Expand Up @@ -12,25 +12,25 @@ def new
def show
@taxon = find_taxon
@new_parent = find_new_parent
@target_name = find_target_name
@target_name = build_target_name(@new_parent)

redirect_to({ action: :new }, alert: "Target must be specified.") unless @new_parent
end

def create
@taxon = find_taxon
@new_parent = find_new_parent
@target_name = find_target_name
@target_name = build_target_name(@new_parent)

operation = ::Operations::CreateNewCombination.new(
current_taxon: @taxon,
new_genus: @new_parent,
target_name_string: target_name_string
target_name_string: target_name_string(@new_parent)
).tap { |object| object.extend RunInTransaction }.run

if operation.success?
new_combination = operation.results.new_combination
create_activity new_combination
create_activity new_combination, @taxon
redirect_to catalog_path(new_combination), notice: "Successfully created new combination."
else
flash.now[:alert] = operation.context.errors.to_sentence
Expand All @@ -48,18 +48,18 @@ def find_new_parent
Taxon.find_by(id: params[:new_parent_id])
end

def target_name_string
return unless @new_parent
"#{@new_parent.name.name} #{params[:species_epithet]}"
def target_name_string new_parent
return unless new_parent
"#{new_parent.name.name} #{params[:species_epithet]}"
end

def find_target_name
Names::BuildNameFromString[target_name_string]
def build_target_name new_parent
Names::BuildNameFromString[target_name_string(new_parent)]
end

def create_activity new_combination
def create_activity new_combination, taxon
new_combination.create_activity Activity::CREATE_NEW_COMBINATION, current_user,
parameters: { previous_combination_id: @taxon.id }
parameters: { previous_combination_id: taxon.id }
end
end
end
Expand Up @@ -20,7 +20,7 @@ def create
return
end

obsolete_combination = create_obsolete_combination
obsolete_combination = Taxa::Operations::CreateObsoleteCombination[@taxon, @obsolete_genus]

if obsolete_combination.persisted?
create_activity obsolete_combination
Expand All @@ -45,10 +45,6 @@ def valid_parent_ranks
[Rank::GENUS]
end

def create_obsolete_combination
Taxa::Operations::CreateObsoleteCombination[@taxon, @obsolete_genus]
end

def create_activity obsolete_combination
obsolete_combination.create_activity Activity::CREATE_OBSOLETE_COMBINATION, current_user
end
Expand Down
20 changes: 8 additions & 12 deletions app/controllers/taxa/force_parent_changes_controller.rb
Expand Up @@ -6,12 +6,12 @@ class ForceParentChangesController < ApplicationController

def show
@taxon = find_taxon
@valid_parent_ranks = valid_parent_ranks
@valid_parent_ranks = valid_parent_ranks @taxon
end

def create
@taxon = find_taxon
@valid_parent_ranks = valid_parent_ranks
@valid_parent_ranks = valid_parent_ranks @taxon
@new_parent = find_new_parent

if @new_parent.nil? && !@taxon.is_a?(Genus)
Expand All @@ -20,8 +20,8 @@ def create
return
end

if update_parent_and_save
create_activity
if Taxa::Operations::ForceParentChange[@taxon, @new_parent]
create_activity @taxon
redirect_to catalog_path(@taxon), notice: "Successfully changed the parent."
else
flash.now[:alert] = "Something went wrong... ?"
Expand All @@ -42,8 +42,8 @@ def find_taxon
Taxon.find(params[:taxa_id])
end

def valid_parent_ranks
case @taxon
def valid_parent_ranks taxon
case taxon
when ::Tribe then [Rank::SUBFAMILY]
when ::Genus then [Rank::FAMILY, Rank::SUBFAMILY, Rank::TRIBE]
when ::Subgenus then [Rank::GENUS]
Expand All @@ -56,12 +56,8 @@ def find_new_parent
Taxon.find_by(id: params[:new_parent_id])
end

def update_parent_and_save
Taxa::Operations::ForceParentChange[@taxon, @new_parent]
end

def create_activity
@taxon.create_activity Activity::FORCE_PARENT_CHANGE, current_user
def create_activity taxon
taxon.create_activity Activity::FORCE_PARENT_CHANGE, current_user
end
end
end
Expand Up @@ -124,7 +124,6 @@ def first_pass_endings
end

# These can only be applied once the above endings have been assigned.
# TODO: Move non-conflicting ending to the first pass.
def second_pass_endings
{
feminine: %w[a e opsis lepis],
Expand Down
Expand Up @@ -37,7 +37,7 @@ def render
end <<
as_table do |t|
t.caption "Subgenera without subfamily"
t.header 'Species', 'Status', 'Subfamily of genus', 'Created at'
t.header 'Subgenus', 'Status', 'Subfamily of genus', 'Created at'

t.rows(subgenera_without_subfamily) do |taxon|
[
Expand All @@ -50,7 +50,7 @@ def render
end <<
as_table do |t|
t.caption "Genera without tribe"
t.header 'species', 'Status', 'Subfamily', 'Created at'
t.header 'Genus', 'Status', 'Subfamily', 'Created at'

t.rows(genera_without_tribe) do |taxon|
[
Expand Down
Expand Up @@ -37,15 +37,7 @@ def render
tags: [references, pdfs, slow-render]

description: >
Once confirmed, the plan is to upload all externally hosted documents to S3, where
all other references are hosted (TODO: write script).


This list does not take into account `ReferenceDocument`s with both a `url` and
a `file_file_name` (URLs are ignored for documents with both).


Issues: %github387, %github324, %github371
To be uploaded by script.

related_scripts:
- ProtonymReferencesWithoutPdfs
Expand Down
2 changes: 0 additions & 2 deletions app/decorators/activity_decorator.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

# TODO: Cleanup.

class ActivityDecorator < Draper::Decorator
# Don't show user who created other users' accounts.
HIDE_USER_FOR_TRACKABLE_TYPES = ['User']
Expand Down
2 changes: 1 addition & 1 deletion app/exporters/exporters/antweb/history/history_items.rb
Expand Up @@ -26,7 +26,7 @@ def history_presenter
end

def history_content
tag.div do
tag.div do
string = ''.html_safe

history_presenter.grouped_items.each do |grouped_item|
Expand Down
2 changes: 0 additions & 2 deletions app/injectable_formatters/catalog_formatter.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

# TODO: Cleanup methods/names.

module CatalogFormatter
extend ActionView::Helpers::OutputSafetyHelper # For `#safe_join`.

Expand Down
6 changes: 3 additions & 3 deletions app/javascript/packs/utils/keysToCamel.js
@@ -1,14 +1,14 @@
const toCamel = (s) => s.replace(/([-_][a-z])/ig, ($1) => $1.toUpperCase().replace('-', '').replace('_', ''))

const isArray = function (a) {
const isArray = function(a) {
return Array.isArray(a)
}

const isObject = function (o) {
const isObject = function(o) {
return o === Object(o) && !isArray(o) && typeof o !== 'function'
}

const keysToCamel = function (o) {
const keysToCamel = function(o) {
if (isObject(o)) {
const n = {}

Expand Down
5 changes: 1 addition & 4 deletions app/models/author_name.rb
Expand Up @@ -15,22 +15,19 @@ class AuthorName < ApplicationRecord

validates :name, presence: true, length: { minimum: NAME_MIN_LENGTH }, uniqueness: { case_sensitive: true },
format: { with: VALID_CHARACTERS_REGEX, message: "contains unsupported characters" }
# TODO: Remove `on: :create` (or just squish the string) once records have been fixed.
validates :name, format: { without: / /, message: "cannot contain consecutive spaces" }, on: :create
validates :name, format: { without: / /, message: "cannot contain consecutive spaces" }
validates :name, format: { without: /,[^ ]/, message: "cannot contain commas not followed by a space" }
validate :validate_commas_and_suffixes, if: -> { name.present? }
after_update :invalidate_reference_caches

has_paper_trail
trackable

# TODO: Store in db?
def last_name
last, _ = name_parts
last
end

# TODO: Store in db?
def first_name_and_initials
_, first = name_parts
first
Expand Down

0 comments on commit d65e762

Please sign in to comment.