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

Started adding auto complete to contributors #1994

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,52 @@ table.dataTable {
.user-edit-long-field {
width: 400px;
}

.hidden-element {
display: none;
}

/* These are the styles used by the jQuery autocomplete plug-in */
.autocomplete-suggestions {
border: 1px solid #999;
background: #FFF;
overflow: auto;
}

.autocomplete-suggestion {
padding: 2px 5px;
white-space: nowrap;
overflow: hidden;
}

.autocomplete-selected {
background: #F0F0F0;
}

.autocomplete-suggestions strong {
font-weight: normal;
color: #3399FF;
}

.autocomplete-group {
padding: 2px 5px;
}

.autocomplete-group strong {
display: block;
border-bottom: 1px solid #000;
}

/*
* Adds the arrow to the autocomplete textbox.
* Notice that since CSS does not allow ::after on HTML <input> we apply this style to an HTML <span>.
* See https://stackoverflow.com/questions/2587669/can-i-use-a-before-or-after-pseudo-element-on-an-input-field
*/
.autocomplete-arrow::after {
content: "▾";
margin-left: -20px;
}

.autocomplete-error {
color: var(--Secondary-Red-Dark, #b00002);
}
9 changes: 9 additions & 0 deletions app/controllers/researchers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
class ResearchersController < ApplicationController
before_action :authenticate_user!

def ajax_list
researchers = { suggestions: Researcher.all_researchers}
render json: researchers.to_json
end
end
24 changes: 24 additions & 0 deletions app/models/researcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true
class Researcher < ApplicationRecord
def self.new_researcher(first_name, last_name, orcid, netid)
researcher = Researcher.where(netid: netid).first
if researcher == nil
researcher = Researcher.new
researcher.netid = netid
end
researcher.first_name = first_name
researcher.last_name = last_name
researcher.orcid = orcid
researcher.save!
return researcher
end

def self.all_researchers
researchers = []
Researcher.all.each do |researcher|
display_value = "#{researcher.first_name} #{researcher.last_name} (#{researcher.netid})"
researchers << {value: display_value, data: researcher.netid}
end
return researchers
end
end
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<!-- Provides https://jqueryui.com/sortable/ and /autocomplete/-->
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>

<!-- Load our local Autocomplete plug-in which is a copy of https://github.com/devbridge/jQuery-Autocomplete -->
<script src="<%= root_path + 'jquery.autocomplete.js' %>"></script>

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<%= favicon_link_tag asset_path('favicon.png') %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/works/_funder_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@
</tfoot>
</table>
</div>


26 changes: 24 additions & 2 deletions app/views/works/_required_creators_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
<tr class="creators-table-row">
<td>
<span class="hidden given-name-required-message"><i class="bi bi-exclamation-diamond-fill required-field"></i>&nbsp;Must provide a given name</span>
<input name="creators[][given_name]" value="<%= creator&.given_name %>" class="given-entry-creator" />
<input id="creator-row-givenname" name="creators[][given_name]" value="<%= creator&.given_name %>" class="given-entry-creator" />
</td>
<td class="creators-table-row-family-name">
<span class="hidden family-name-required-message"><i class="bi bi-exclamation-diamond-fill required-field"></i>&nbsp;Must provide a family name</span>
<input name="creators[][family_name]" value="<%= creator&.family_name %>" class="family-entry-creator" />
<input id="creator-row-familyname" name="creators[][family_name]" value="<%= creator&.family_name %>" class="family-entry-creator" />
</td>
<td>
<input name="creators[][orcid]" value="<%= creator&.orcid %>" class="orcid-entry-creator" placeholder="0000-0000-0000-0000" />
Expand Down Expand Up @@ -77,3 +77,25 @@
</table>
</div>

<script>
// debugger;
// Documentation: https://github.com/devbridge/jQuery-Autocomplete
$('#creator-row-givenname').devbridgeAutocomplete({
serviceUrl: '<%= researchers_ajax_list_url %>',
onSelect: function (suggestion) {
$("#creator-row-familyname").val(suggestion.data);
}
});

// Settings that we use in TigerData
// $(elementId).autocomplete({
// minChars: 1,
// autoSelectFirst: true,
// showNoSuggestionNotice: true,
// noSuggestionNotice: "No results found",
// lookup: data,
// onSelect: function (suggestion) {
// $(elementId).val(suggestion.data);
// }
// });
</script>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
get "/collections/:id", to: redirect("/groups/%{id}"), as: :collections
get "/reports/dataset-list", to: "reports#dataset_list", as: :reports_dataset_list

# researchers
get "/researchers/ajax-list", to: "researchers#ajax_list", as: :researchers_ajax_list

# Anything still unmatched by the end of the routes file should go to the not_found page
# match '*a', to: redirect('/404'), via: :get

Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20241202152610_create_researchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateResearchers < ActiveRecord::Migration[6.1]
def change
create_table :researchers do |t|
t.string "first_name", null: false
t.string "last_name", null: false
t.string "orcid", null: false
t.string "affiliation", null: true
t.string "affiliation_ror", null: true
t.string "netid", null: true

t.timestamps
end
end
end
13 changes: 12 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions lib/tasks/researchers.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true
namespace :researchers do
desc "Creates default researchers"
task create_default_researchers: :environment do
User.all.each do |user|
if user.orcid != nil
Researcher.new_researcher(user.given_name, user.family_name, user.orcid, user.uid)
end
end
end
end
Loading