Skip to content

Commit

Permalink
Merge branch 'main' into nimmo-view-component
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Jan 19, 2024
2 parents 1458edf + a803d4a commit fb0606a
Show file tree
Hide file tree
Showing 60 changed files with 569 additions and 300 deletions.
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ group :rails do
gem("railties", "~> 7.1.2")
end

# fix for unicorn 6.1.0 not being able to deal with current rack 3 yet
# delete when unicorn updated to 7
gem("rack", "~>2")
# gem irb now depends on psych, but version 5 will not bundle currently
gem("psych", "~> 4")
# importmap for js module handling
Expand All @@ -48,8 +51,12 @@ gem("requestjs-rails")
gem("turbo-rails")
# redis for combining actioncable broadcasts with turbo_stream
# gem("redis", "~> 4.0")
# dalli to run the memcached server
gem("dalli", "~> 3.2")
# Compile SCSS for stylesheets
gem("sassc-rails")
# add locale to cache key
gem("cache_with_locale")

# Fix a version problem betw stimulus and sprockets. (not sprockets-rails)
# Delete this dependency declaration if the issue gets resolved:
Expand Down
78 changes: 43 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,48 @@ GEM
remote: https://rubygems.org/
specs:
RedCloth (4.3.3)
actioncable (7.1.2)
actionpack (= 7.1.2)
activesupport (= 7.1.2)
actioncable (7.1.3)
actionpack (= 7.1.3)
activesupport (= 7.1.3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailer (7.1.2)
actionpack (= 7.1.2)
actionview (= 7.1.2)
activejob (= 7.1.2)
activesupport (= 7.1.2)
actionmailer (7.1.3)
actionpack (= 7.1.3)
actionview (= 7.1.3)
activejob (= 7.1.3)
activesupport (= 7.1.3)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.2)
actionpack (7.1.2)
actionview (= 7.1.2)
activesupport (= 7.1.2)
actionpack (7.1.3)
actionview (= 7.1.3)
activesupport (= 7.1.3)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview (7.1.2)
activesupport (= 7.1.2)
actionview (7.1.3)
activesupport (= 7.1.3)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (7.1.2)
activesupport (= 7.1.2)
activejob (7.1.3)
activesupport (= 7.1.3)
globalid (>= 0.3.6)
activemodel (7.1.2)
activesupport (= 7.1.2)
activerecord (7.1.2)
activemodel (= 7.1.2)
activesupport (= 7.1.2)
activemodel (7.1.3)
activesupport (= 7.1.3)
activerecord (7.1.3)
activemodel (= 7.1.3)
activesupport (= 7.1.3)
timeout (>= 0.4.0)
activesupport (7.1.2)
activesupport (7.1.3)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
Expand Down Expand Up @@ -82,9 +82,13 @@ GEM
racc
browser (5.3.1)
builder (3.2.4)
bullet (7.1.5)
bullet (7.1.6)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
cache_with_locale (0.0.3)
actionview
activesupport
railties
capybara (3.39.2)
addressable
matrix
Expand All @@ -94,14 +98,15 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.2.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crack (0.4.5)
rexml
crass (1.0.6)
cuprite (0.15)
capybara (~> 3.0)
ferrum (~> 0.14.0)
dalli (3.2.6)
database_cleaner-active_record (2.1.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
Expand Down Expand Up @@ -187,21 +192,21 @@ GEM
nokogiri (1.16.0-x86_64-linux)
racc (~> 1.4)
parallel (1.24.0)
parser (3.3.0.2)
parser (3.3.0.4)
ast (~> 2.4.1)
racc
psych (4.0.6)
stringio
public_suffix (5.0.4)
racc (1.7.3)
rack (3.0.8)
rack-session (2.0.0)
rack (>= 3.0.0)
rack (2.2.8)
rack-session (1.0.2)
rack (< 3)
rack-test (2.1.0)
rack (>= 1.3)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rackup (1.0.0)
rack (< 3)
webrick
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
Expand All @@ -213,9 +218,9 @@ GEM
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.1.2)
actionpack (= 7.1.2)
activesupport (= 7.1.2)
railties (7.1.3)
actionpack (= 7.1.3)
activesupport (= 7.1.3)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
Expand All @@ -234,11 +239,11 @@ GEM
railties (>= 6.1.0)
rexml (3.2.6)
rtf (0.3.3)
rubocop (1.59.0)
rubocop (1.60.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
Expand Down Expand Up @@ -358,8 +363,10 @@ DEPENDENCIES
browser
bullet
bundler
cache_with_locale
capybara (~> 3.37, >= 3.37.1)
cuprite
dalli (~> 3.2)
database_cleaner-active_record
date (>= 3.2.1)
debug (>= 1.0.0)
Expand All @@ -382,6 +389,7 @@ DEPENDENCIES
newrelic_rpm
nokogiri (>= 1.13.10)
psych (~> 4)
rack (~> 2)
rails-controller-testing
rails-html-sanitizer (>= 1.4.4)
railties (~> 7.1.2)
Expand Down
6 changes: 5 additions & 1 deletion app/assets/stylesheets/mo/_matrix_box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
.matrix-box {

.panel {
min-height: 200px;
// min-height: 200px;
margin-bottom: $grid-gutter-width;

.thumbnail-container {
min-height: 30px;
}
}

.panel-sizing {
min-height: 180px;
}

// for when the whole panel section is a link, or has a stretched link
// rule necessary when the "link" is a checkbox <label>, not an <a>.
// e.g. "Mark as reviewed"
Expand Down
8 changes: 8 additions & 0 deletions app/assets/stylesheets/mo/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@
margin-left: 10px !important;
}

.ml-1 {
margin-left: 0.25rem !important;
}

.ml-2 {
margin-left: 0.5rem !important;
}

.ml-3 {
margin-left: 1rem !important;
}
Expand Down
31 changes: 19 additions & 12 deletions app/controllers/observations/namings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Controller for handling the naming of observations
# rubocop:disable Metrics/ClassLength

module Observations
class NamingsController < ApplicationController
class NamingsController < ApplicationController # rubocop:disable Metrics/ClassLength
before_action :login_required
before_action :pass_query_params

Expand Down Expand Up @@ -37,7 +37,7 @@ def create
save_changes
respond_to_successful_create
else # If anything failed reload the form.
flash_object_errors(@naming) if name_missing?
flash_naming_errors
add_reasons(params.dig(:naming, :reasons))
respond_to_form_errors
end
Expand Down Expand Up @@ -99,6 +99,8 @@ def destroy
end
end

#########

private

def init_ivars
Expand Down Expand Up @@ -257,16 +259,22 @@ def respond_to_successful_create
end
end

def name_missing?
if @name && @what.match(/\S/)
false
else
@naming.errors.add(:name,
:form_observations_there_is_a_problem_with_name.t)
true
def flash_naming_errors
if @what.blank?
flash_error(:form_naming_what_missing.t)
elsif name_missing?
flash_object_errors(@naming)
end
end

def name_missing?
return false if @name && @what.present?

@naming.errors.
add(:name, :form_observations_there_is_a_problem_with_name.t)
true
end

def respond_to_form_errors
redo_action = case action_name
when "create"
Expand Down Expand Up @@ -308,7 +316,7 @@ def validate_name
success = resolve_name(params.dig(:naming, :name).to_s,
params[:approved_name],
params.dig(:chosen_name, :name_id).to_s)
flash_object_errors(@naming) if name_missing?
flash_naming_errors
success
end

Expand Down Expand Up @@ -408,4 +416,3 @@ def destroy_if_we_can(naming)
end
end
end
# rubocop:enable Metrics/ClassLength
24 changes: 14 additions & 10 deletions app/controllers/observations_controller/validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,30 @@ def validate_params(params)
end

def validate_name(params)
given_name = params.dig(:naming, :name).to_s
chosen_name = params.dig(:chosen_name, :name_id).to_s
@resolver = Naming::NameResolver.new(
given_name, params[:approved_name], chosen_name
)
# NOTE: views could be refactored to access properties of the @resolver,
# e.g. `@resolver.valid_names`, instead of these ivars.
# All but success, @what, @name are only used by form_name_feedback.
(success, @what, @name, @names, @valid_names,
@parent_deprecated, @suggest_corrections) = @resolver.ivar_array
@parent_deprecated, @suggest_corrections) = resolve_name_ivars(params)
if @name
@naming.name = @name
else
elsif !success
@naming.errors.add(:name,
:form_observations_there_is_a_problem_with_name.t)
flash_object_errors(@naming)
end
success
end

def resolve_name_ivars(params)
given_name = params.dig(:naming, :name).to_s
chosen_name = params.dig(:chosen_name, :name_id).to_s
@resolver = Naming::NameResolver.new(
given_name, params[:approved_name], chosen_name
)
# NOTE: views could be refactored to access properties of the @resolver,
# e.g. `@resolver.valid_names`, instead of these ivars.
# All but success, @what, @name are only used by form_name_feedback.
@resolver.ivar_array
end

def validate_place_name(params)
success = true
@place_name = @observation.place_name
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def image_ivars
def set_ivars_for_show
@where = @project&.place_name || ""
@canonical_url = "#{MO.http_domain}/projects/#{@project.id}"
@is_member = @project.is_member?(@user)
@is_member = @project.member?(@user)
@is_admin = @project.is_admin?(@user)
@drafts = NameDescription.joins(:admin_groups).
where("name_description_admins.user_group_id":
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ def flash_notices_html
class: class_names("alert mt-3", alert_class))
end

# Returns a string that indicates the current user/logged_in/admin status.
# Used as a simple cache key for templates that may have three
# possible versions of cached HTML
def user_status_string
if in_admin_mode?
"admin_mode"
elsif browser.bot?
"robot"
elsif !@user.nil?
"logged_in"
else
"no_user"
end
end

# ----------------------------------------------------------------------------

# Take URL that got us to this page and add one or more parameters to it.
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/images_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module ImagesHelper
# }
# )
def interactive_image(image, **args)
presenter = ImagePresenter.new(image, args.except(:image))
presenter = ImagePresenter.new(image, args)
set_width = presenter.width.present? ? "width: #{presenter.width}px;" : ""

[
Expand Down Expand Up @@ -124,7 +124,7 @@ def image_exif_link(image_or_image_id, classes)
image_or_image_id
end
modal_link_to("image_exif_#{image_id}", :image_show_exif.t,
exif_image_path(image_id), { class: classes })
exif_image_path(id: image_id), { class: classes })
end

# NOTE: `stretched_link` might be a link to #show_obs or #show_image,
Expand Down
Loading

0 comments on commit fb0606a

Please sign in to comment.