Skip to content

Commit

Permalink
Merge pull request #1759 from MushroomObserver/nimmo-election-naming
Browse files Browse the repository at this point in the history
`NamingConsensus`
  • Loading branch information
nimmolo authored Jan 5, 2024
2 parents 95a62cc + 80c5574 commit 8015bb9
Show file tree
Hide file tree
Showing 38 changed files with 999 additions and 954 deletions.
3 changes: 2 additions & 1 deletion app/classes/api2/observation_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def create_naming(obs)
end
end
naming.save!
obs.change_vote(naming, @vote, user)
consensus = ::Observation::NamingConsensus.new(obs)
consensus.change_vote(naming, @vote, user)
end

def create_specimen_records(obs)
Expand Down
96 changes: 0 additions & 96 deletions app/classes/naming_params.rb

This file was deleted.

14 changes: 9 additions & 5 deletions app/controllers/observations/identify_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@ def region_filter(term)
# show_selected_results(query)
# end

# TODO: Allow show_index_of_objects to `render` rather than `redirect`,
# or better yet `respond_to do |format|` and write index.js.erb templates
# to just render the #results div.
def show_selected_results(query)
args = {
matrix: true,
include: [:location, :user, :rss_log, { name: :synonym },
{ namings: :name }, observation_matrix_box_image_includes]
include: observation_identify_index_includes
}

show_index_of_objects(query, args)
end

def observation_identify_index_includes
[observation_matrix_box_image_includes,
:location,
{ name: :synonym },
{ namings: [:name, :votes] },
:rss_log, :user]
end
end
end
23 changes: 15 additions & 8 deletions app/controllers/observations/namings/votes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ class VotesController < ApplicationController
# Index breakdown of votes for a given naming.
# Linked from: observations/show
# Displayed on show obs via popup for JS users.
# Has its own route for non-js.
# Inputs: params[:id] (naming)
# Outputs: @naming
# Has its own route for non-js access and testing.
# Inputs: params[:naming_id], [:observation_id]
# Outputs: @naming, @consensus
def index
pass_query_params
@naming = find_or_goto_index(Naming, params[:naming_id].to_s)
obs = Observation.naming_includes.find(params[:observation_id])
@consensus = Observation::NamingConsensus.new(obs)

respond_to do |format|
format.turbo_stream do
Textile.register_name(@naming.name)
Expand All @@ -22,7 +25,8 @@ def index
render(partial: "shared/modal",
locals: {
identifier: identifier, title: title, subtitle: subtitle,
body: "observations/namings/votes/table", naming: @naming
body: "observations/namings/votes/table", naming: @naming,
consensus: @consensus
})
end
format.html
Expand Down Expand Up @@ -68,9 +72,8 @@ def create_or_update_vote
value = Vote.validate_value(value_str)
raise("Bad value.") unless value

# N+1: Take the whole vote object and send it to change vote?
# Or how about returning obs.reload from observation.change_vote
observation.change_vote(@naming, value, @user) # 2nd load (obs.reload)
@consensus = ::Observation::NamingConsensus.new(observation)
@consensus.change_vote(@naming, value, @user) # 2nd load (namings.reload)
@observation = load_observation_naming_includes # 3rd load
respond_to_new_votes
end
Expand All @@ -87,8 +90,12 @@ def respond_to_new_votes
render(partial: "observations/namings/update_matrix_box",
locals: { obs: @observation })
else
obs = Observation.naming_includes.find(@observation.id)
owner_name = @consensus.owner_preference

render(partial: "observations/namings/update_observation",
locals: { obs: @observation })
locals: { obs: obs, consensus: @consensus,
owner_name: owner_name })
end
return
end
Expand Down
Loading

0 comments on commit 8015bb9

Please sign in to comment.