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

Adds support for communities and subcommunities #1235

Merged
merged 5 commits into from Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
44 changes: 44 additions & 0 deletions app/models/group.rb
Expand Up @@ -153,4 +153,48 @@ def delete_permission(current_user, removed_user)
errors.add(:delete_permission, "Unauthorized")
end
end

Copy link
Member Author

Choose a reason for hiding this comment

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

Eventually we might want to make communities and subcommunities configurable somehow, but for now we are just trying to see if this new design works for PPPL.

def communities
values = []
if code == "PPPL"
values << "Princeton Plasma Physics Laboratory"
else
values << "Princeton Neuroscience Institute"
values << "Department of Geosciences"
values << "Mechanical and Aerospace Engineering"
values << "Astrophysical Sciences"
values << "Civil and Environmental Engineering"
values << "Chemical and Biological Engineering"
values << "Digital Humanities"
values << "Music and Arts"
values << "Princeton School of Public and International Affairs"
end
values
end

# rubocop:disable Metrics/MethodLength
def subcommunities
values = []
if code == "PPPL"
values << "Spherical Torus"
values << "Advanced Projects"
values << "ITER and Tokamaks"
values << "Theory"
values << "NSTX-U"
values << "NSTX"
values << "Plasma Science & Technology"
values << "Theory and Computation"
values << "Stellarators"
values << "PPPL Collaborations"
values << "MAST-U"
values << "Other Projects"
values << "System Studies"
end
values
end
# rubocop:enable Metrics/MethodLength

def default_community
return communities.first if code == "PPPL"
end
end
8 changes: 7 additions & 1 deletion app/models/pdc_metadata/resource.rb
Expand Up @@ -7,10 +7,11 @@ def self.fuzzy_match(obj, value)
obj.key.to_s == value or obj.value.casecmp(value).zero?
end

# rubocop:disable Metrics/ClassLength
class Resource
attr_accessor :creators, :titles, :publisher, :publication_year, :resource_type, :resource_type_general,
:description, :doi, :ark, :rights, :version_number, :collection_tags, :keywords, :related_objects,
:funders, :organizational_contributors, :domains, :migrated
:funders, :organizational_contributors, :domains, :migrated, :communities, :subcommunities

# rubocop:disable Metrics/MethodLength
def initialize(doi: nil, title: nil, resource_type: nil, resource_type_general: nil, creators: [], description: nil)
Expand All @@ -33,6 +34,8 @@ def initialize(doi: nil, title: nil, resource_type: nil, resource_type_general:
@organizational_contributors = []
@funders = []
@domains = []
@communities = []
@subcommunities = []
@migrated = false
end
# rubocop:enable Metrics/MethodLength
Expand Down Expand Up @@ -136,6 +139,8 @@ def set_curator_controlled_metadata(resource, hash)

def set_additional_metadata(resource, hash)
resource.keywords = hash["keywords"] || []
resource.communities = hash["communities"] || []
resource.subcommunities = hash["subcommunities"] || []
end

def set_titles(resource, hash)
Expand Down Expand Up @@ -196,4 +201,5 @@ def set_funders(resource, hash)
end
end
end
# rubocop:enable Metrics/ClassLength
end
8 changes: 7 additions & 1 deletion app/services/form_to_resource_service.rb
Expand Up @@ -15,8 +15,8 @@ def convert(params, work)
resource.publication_year = params["publication_year"] if params["publication_year"].present?
resource.rights = PDCMetadata::Rights.find(params["rights_identifier"])
resource.keywords = (params["keywords"] || "").split(",").map(&:strip)
resource.domains = params["domains"] || []

add_additional_metadata(params, resource)
add_curator_controlled(params, resource)
add_titles(params, resource)
add_related_objects(params, resource)
Expand All @@ -40,6 +40,12 @@ def reset_resource_to_work(work)
resource
end

def add_additional_metadata(params, resource)
resource.domains = params["domains"] || []
resource.communities = params["communities"] || []
resource.subcommunities = params["subcommunities"] || []
end

def add_curator_controlled(params, resource)
resource.doi = params["doi"] if params["doi"].present?
resource.ark = params["ark"] if params["ark"].present?
Expand Down
2 changes: 2 additions & 0 deletions app/views/works/_additional_form.html.erb
Expand Up @@ -23,3 +23,5 @@
<%= render(partial: 'works/organizational_contributors_table') %>

<%= render(partial: 'works/domains') %>

<%= render(partial: 'works/communities') %>
46 changes: 46 additions & 0 deletions app/views/works/_communities.html.erb
@@ -0,0 +1,46 @@
<div class="section-title">
<% if @work.group.communities.count == 1 %>
<!-- Special case for PPPL that has a single community -->
<details>
<summary>Community</summary>
The community for this dataset.
</details>
<select id="communities" name="communities[]" class="form-select" >
<option selected><%= @work.group.communities.first %></option>
</select>
<% else %>
<details>
<summary>Communities</summary>
Select one or more communities for this dataset.
</details>
<select id="communities" name="communities[]" class="form-select" multiple >
<% @work.group.communities.each do |community| %>
<% if @work.resource.communities.include?(community) %>
<option selected><%= community %></option>
<% else %>
<option><%= community %></option>
<% end %>
<% end %>
</select>
<% end %>

<% if @work.group.subcommunities.count > 0 %>
<br/>
<!-- Display subcommunities only for those groups that have them. -->
<details>
<summary>Subcommunities</summary>
Select one or more subcommunities for this dataset.
</details>

<select id="subcommunities" name="subcommunities[]" class="form-select" multiple >
<% @work.group.subcommunities.each do |subcommunity| %>
<% if @work.resource.subcommunities.include?(subcommunity) %>
<option selected><%= subcommunity %></option>
<% else %>
<option><%= subcommunity %></option>
<% end %>
<% end %>
</select>
<% end %>
</div>

14 changes: 14 additions & 0 deletions app/views/works/show.html.erb
Expand Up @@ -231,6 +231,20 @@
<dt><%= t("work.group") %></dt>
<dd><%= @work.group.title %></dd>

<% if @work.resource.communities.count > 0 %>
<dt>Communities</dt>
<% @work.resource.communities.each do |community| %>
<dd><%= community %></dd>
<% end %>

<% if @work.resource.subcommunities.count > 0 %>
<dt>Subcommunities</dt>
<% @work.resource.subcommunities.each do |subcommunity| %>
<dd><%= subcommunity %></dd>
<% end %>
<% end %>
<% end %>

<% if @work.resource.funders.count > 0 %>
<dt>Funders</dt>
<% @work.resource.funders.each do |funder| %>
Expand Down
2 changes: 2 additions & 0 deletions spec/models/pdc_metadata/resource_spec.rb
Expand Up @@ -162,6 +162,8 @@
"award_uri" => nil
}],
"domains" => ["Humanities"],
"communities" => [],
"subcommunities" => [],
"migrated" => true
}
end
Expand Down
4 changes: 4 additions & 0 deletions spec/models/work_spec.rb
Expand Up @@ -58,6 +58,8 @@
"contributors" => [],
"funders" => [],
"domains" => [],
"communities" => [],
"subcommunities" => [],
"migrated" => false
},
"files" => [],
Expand Down Expand Up @@ -894,6 +896,8 @@
}
],
"domains":[],
"communities":[],
"subcommunities":[],
"migrated": false
}'
end
Expand Down
4 changes: 3 additions & 1 deletion spec/services/resource_compare_service_spec.rb
Expand Up @@ -70,7 +70,9 @@
individual_contributors: [],
organizational_contributors: [],
creators: [],
domains: ["Humanities"]
domains: ["Humanities"],
communities: [],
subcommunities: []
}
expected_diff = {
doi: [{ action: :changed, from: "10.34770/pe9w-x904", to: "" }],
Expand Down