-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
607 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,3 +93,7 @@ ul.tight-list { | |
font-size: 13px; | ||
font-weight: bold; | ||
} | ||
|
||
.btn-constraint-warning { | ||
color: black; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
# Show and remove non-compliant Observations from a Project | ||
module Projects | ||
# Actions | ||
# ------- | ||
# edit (get) | ||
# update (patch) | ||
# | ||
class ViolationsController < ApplicationController | ||
before_action :login_required | ||
before_action :pass_query_params | ||
|
||
def update | ||
unless (@project = find_or_goto_index(Project, params[:project_id])) | ||
return | ||
end | ||
|
||
params[:project]&.each do |key, value| | ||
next unless key =~ /|remove_\d+$/ && value == "1" | ||
|
||
obs_id = key.sub("remove_", "") | ||
remove_observation_if_permitted(obs_id) | ||
end | ||
|
||
redirect_with_query(project_path(@project)) | ||
end | ||
|
||
######### | ||
|
||
private | ||
|
||
def default_index_subaction | ||
list_all | ||
end | ||
|
||
def list_all | ||
return unless find_project! | ||
|
||
@violations = @project.violations | ||
end | ||
|
||
def find_project! | ||
@project = find_or_goto_index(Project, params[:project_id]) | ||
end | ||
|
||
def remove_observation_if_permitted(obs_id) | ||
return unless (obs = Observation.safe_find(obs_id)) | ||
return unless @project.observations.include?(obs) | ||
|
||
permitted_removers = @project.admin_group_user_ids + [obs.user_id] | ||
return unless permitted_removers.include?(User.current.id) | ||
|
||
@project.remove_observations([obs]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# frozen_string_literal: true | ||
|
||
# View Helpers for Projects, Project Violations | ||
module ProjectsHelper | ||
def violation_table_headers(project) | ||
[ | ||
nil, # column for checkbox | ||
"#{:CONSTRAINTS.l}:", | ||
"#{:DATES.l}: #{project.date_range}", | ||
"Lat: #{project.location.north} to #{project.location.south}", | ||
"Lon: #{project.location.west} to #{project.location.east} ", | ||
location_link(project.location.display_name, project.location, | ||
nil, false), | ||
nil # column for observation.user | ||
] | ||
end | ||
|
||
def violation_table_rows(form:, project:, violations:) | ||
violations.each_with_object([]) do |obs, rows| | ||
rows << [ | ||
violation_checkbox(form: form, project: project, obs: obs), | ||
link_to_object(obs, obs.text_name) + " (#{obs.id})", | ||
styled_obs_when(project, obs), | ||
styled_obs_lat(project, obs), | ||
styled_obs_long(project, obs), | ||
styled_obs_where(project, obs), | ||
user_link(obs.user) | ||
] | ||
end | ||
end | ||
|
||
def violations_help_text(project) | ||
:form_violations_help.l if project.violations_removable_by_current_user? | ||
end | ||
|
||
def violations_submit_text(project) | ||
if project.violations_removable_by_current_user? | ||
:form_violations_remove_selected.l | ||
else | ||
:form_violations_show_project.l | ||
end | ||
end | ||
|
||
######### | ||
|
||
private | ||
|
||
def violation_checkbox(form:, project:, obs:) | ||
if violation_checkbox_viewers(project, obs).include?(User.current.id) | ||
form.check_box("remove_#{obs.id}") | ||
end | ||
end | ||
|
||
def violation_checkbox_viewers(project, obs) | ||
project.admin_group_user_ids + [obs.user_id] | ||
end | ||
|
||
def styled_obs_when(project, obs) | ||
if project.violates_date_range?(obs) | ||
tag.span(obs.when, class: "violation-highlight") | ||
else | ||
obs.when | ||
end | ||
end | ||
|
||
def styled_obs_lat(project, obs) | ||
return "" if obs.lat.blank? | ||
|
||
displayed_coord = | ||
coord_or_hidden(obs: obs, project: project, coord: obs.lat) | ||
return displayed_coord if project.location.contains_lat?(obs.lat) | ||
|
||
tag.span(displayed_coord, class: "violation-highlight") | ||
end | ||
|
||
def styled_obs_long(project, obs) | ||
return "" if obs.long.blank? | ||
|
||
displayed_coord = | ||
coord_or_hidden(obs: obs, project: project, coord: obs.long) | ||
|
||
return displayed_coord if project.location.contains_long?(obs.long) | ||
|
||
tag.span(displayed_coord, class: "violation-highlight") | ||
end | ||
|
||
def coord_or_hidden(obs:, project:, coord:) | ||
if !obs.gps_hidden? || | ||
User.current == obs.user || | ||
project.trusted_by?(User.current) && project.admin?(User.current) | ||
coord | ||
else | ||
:hidden.l | ||
end | ||
end | ||
|
||
def styled_obs_where(project, obs) | ||
if obs.lat.present? || # If lat/lon present, ignore Location for compliance | ||
project.location.found_here?(obs) | ||
location_link(obs.place_name, obs.location, nil, false) | ||
else | ||
tag.span(location_link(obs.place_name, obs.location, nil, false), | ||
class: "violation-highlight") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.