Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAW - Another PermissibleValue method #1003

Merged
merged 4 commits into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/models/permissible_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ def self.get_value_list(category)
PermissibleValue.where(category: category).pluck(:value)
end

# Get a hash of PermissibleValue keys as they keys and values as values
def self.get_hash(category)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between this method and the one below? They do the same thing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#get_hash uses the standard format { key => value } but #get_value_key_hash uses a { value => key } format

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, and I was confused because they looked so similar.

Hash[PermissibleValue.where(category: category).pluck(:key, :value)]
end

# Get a hash of PermissibleValue values as the keys and keys as values
def self.get_value_key_hash(category)
def self.get_inverted_hash(category)
Hash[PermissibleValue.where(category: category).pluck(:value, :key)]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
%li
= PermissibleValue.get_value('funding_source', excluded_funding_source.funding_source)
%span.ui-icon.ui-icon-close.remove_funding_source{:funding_source_id => excluded_funding_source.id}
= select_tag 'funding_source', options_for_select(PermissibleValue.get_value_key_hash('funding_source')), :prompt => '--- Select ---', :class => 'new_excluded_funding_source', :style => 'width:325px;'
= select_tag 'funding_source', options_for_select(PermissibleValue.get_inverted_hash('funding_source')), :prompt => '--- Select ---', :class => 'new_excluded_funding_source', :style => 'width:325px;'
%a.add_new_excluded_funding_source.btn{:org_id => entity.id, :org_type => entity.class}
= t("cm_shared.labels.exclude_button")
%br
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/protocols/form/_project_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
title: t(:protocols)[:tooltips][:funding_source]
.col-lg-10
= form.select :funding_source,
options_for_select(PermissibleValue.get_value_key_hash('funding_source'), protocol.funding_source),
options_for_select(PermissibleValue.get_inverted_hash('funding_source'), protocol.funding_source),
{ include_blank: t(:protocols)[:prompts][:source] },
class: 'selectpicker'

Expand All @@ -72,7 +72,7 @@
title: t(:protocols)[:tooltips][:potential_funding_source]
.col-lg-10
= form.select :potential_funding_source,
options_for_select(PermissibleValue.get_value_key_hash('potential_funding_source'), protocol.potential_funding_source),
options_for_select(PermissibleValue.get_inverted_hash('potential_funding_source'), protocol.potential_funding_source),
{ include_blank: t(:protocols)[:prompts][:potential_source] },
class: 'selectpicker'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
title: t(:protocols)[:tooltips][:funding_source]
.col-lg-10
= form.select :funding_source,
options_for_select(PermissibleValue.get_value_key_hash('funding_source'), protocol.funding_source),
options_for_select(PermissibleValue.get_inverted_hash('funding_source'), protocol.funding_source),
{ include_blank: t(:protocols)[:prompts][:source] },
class: 'selectpicker'

Expand All @@ -89,7 +89,7 @@
title: t(:protocols)[:tooltips][:potential_funding_source]
.col-lg-10
= form.select :potential_funding_source,
options_for_select(PermissibleValue.get_value_key_hash('potential_funding_source'), protocol.potential_funding_source),
options_for_select(PermissibleValue.get_inverted_hash('potential_funding_source'), protocol.potential_funding_source),
{ include_blank: t(:protocols)[:prompts][:potential_source] },
class: 'selectpicker'

Expand Down
4 changes: 2 additions & 2 deletions app/views/protocols/form/_project_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
title: t(:protocols)[:tooltips][:funding_source]
.col-lg-10
= form.select :funding_source,
options_for_select(PermissibleValue.get_value_key_hash('funding_source'), protocol.funding_source),
options_for_select(PermissibleValue.get_inverted_hash('funding_source'), protocol.funding_source),
{ include_blank: t(:protocols)[:prompts][:source] },
class: 'selectpicker'

Expand All @@ -72,7 +72,7 @@
title: t(:protocols)[:tooltips][:potential_funding_source]
.col-lg-10
= form.select :potential_funding_source,
options_for_select(PermissibleValue.get_value_key_hash('potential_funding_source'), protocol.potential_funding_source),
options_for_select(PermissibleValue.get_inverted_hash('potential_funding_source'), protocol.potential_funding_source),
{ include_blank: t(:protocols)[:prompts][:potential_source] },
class: 'selectpicker'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
title: t(:protocols)[:tooltips][:funding_source]
.col-lg-10
= form.select :funding_source,
options_for_select(PermissibleValue.get_value_key_hash('funding_source'), protocol.funding_source),
options_for_select(PermissibleValue.get_inverted_hash('funding_source'), protocol.funding_source),
{ include_blank: t(:protocols)[:prompts][:source] },
class: 'selectpicker'

Expand All @@ -85,7 +85,7 @@
title: t(:protocols)[:tooltips][:potential_funding_source]
.col-lg-10
= form.select :potential_funding_source,
options_for_select(PermissibleValue.get_value_key_hash('potential_funding_source'), protocol.potential_funding_source),
options_for_select(PermissibleValue.get_inverted_hash('potential_funding_source'), protocol.potential_funding_source),
{ include_blank: t(:protocols)[:prompts][:potential_source] },
class: 'selectpicker'

Expand Down