-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
obs unit selector for sample form #2020
use objects_input, grouped by study
- Loading branch information
Showing
4 changed files
with
32 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ObservationUnitsHelper | ||
|
||
def observation_unit_selector(name, selected = nil, opts = {}) | ||
opts[:data] ||= {} | ||
opts[:multiple] = false | ||
grouped_options = grouped_observation_unit_options | ||
opts[:select_options] = grouped_options_for_select(grouped_options, selected) | ||
|
||
objects_input(name, [selected&.id], opts) | ||
end | ||
|
||
private | ||
|
||
def grouped_observation_unit_options | ||
obs_units = authorised_assets(ObservationUnit, nil, :edit) | ||
grouped = obs_units.group_by(&:study) | ||
grouped.keys.collect do |study| | ||
title = study&.can_view? ? study.title : "Hidden #{t('study')}" | ||
[title, grouped[study].collect{|obs_unit| [obs_unit.title, obs_unit.id]}] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= folding_panel(t('observation_unit'), resource.observation_unit.present?) do %> | ||
<%= observation_unit_selector('sample[observation_unit_id]', resource.observation_unit) %> | ||
<% 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