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 switching user data entry to use autocomplete #1035

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ node_modules
# Do not check aterm.jar into the repo
aterm.jar

public
public
doc

# Ignore test created to not get accidentally added to commit
project_create_8.txt

# Ignore .yardoc
.yardoc/
.yardoc/

# Ignore rspec report
/spec/fixtures/failed_tests.txt
27 changes: 2 additions & 25 deletions app/assets/stylesheets/_settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -238,37 +238,14 @@
margin-bottom: 10px;
}

.custom_error {
display: none;

.error_message {
color: var(--Secondary-Red-Dark, #b00002);
margin-top: 2px;

/* Body XS */
font-family: "Libre Franklin";
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: 21px; /* 150% */
}
}

input:valid {
input[type=text]:valid {
background-color: rgb(255, 255, 255);
}

input:invalid {
input[type=text]:invalid {
outline-color: red;
}

// write css so that the text displayed on invalid input is red and appears to the right of the div instead of below it
span {
color: red;
display: inline;
margin-left: 10px;
}

h2 {
// Headings for roles and description
text-decoration: underline;
Expand Down
48 changes: 48 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,51 @@ body {
}
}

.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);
}
24 changes: 24 additions & 0 deletions app/helpers/project_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,28 @@ def pre_populate_data_sponsor
@project.metadata[:data_sponsor]
end
end

# Returns a string with JSON representation of a list of users
# The JSON can be used to feed the jQuery Autocomplete plug-in
# rubocop:disable Rails/OutputSafety
def user_list_json(users)
json_elements = users.map do |user|
"{ data: '#{user.uid}', value: '#{user.display_name_safe} (#{user.uid})' }"
end

json_elements.join(",").html_safe
end
# rubocop:enable Rails/OutputSafety

def sponsor_list_json
user_list_json(User.sponsor_users)
end

def manager_list_json
user_list_json(User.manager_users)
end

def all_users_list_json
user_list_json(User.all)
end
end
3 changes: 0 additions & 3 deletions app/javascript/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import * as bootstrap from 'bootstrap';
import '../channels';

import { setTargetHtml } from './helper';
import UserDatalist from './user_datalist';
import { displayMediafluxVersion } from './mediafluxVersion';
import { showCreateScript } from './atermScripts';

Expand Down Expand Up @@ -245,8 +244,6 @@ function initPage() {
$('#test-jquery').click((event) => {
setTargetHtml(event, 'jQuery works!');
});
const datalist = new UserDatalist();
datalist.setupDatalistValidity();
initDataUsers();
initListContentsModal();
showMoreLessContent();
Expand Down
56 changes: 0 additions & 56 deletions app/javascript/entrypoints/user_datalist.js

This file was deleted.

29 changes: 12 additions & 17 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,22 @@ def self.from_cas(access_token)
user
end

def self.all_users
User.all.map(&:uid)
end

# Users that can be project sponsors
def self.sponsor_users
Copy link
Member Author

Choose a reason for hiding this comment

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

self.sponsor_users and self.manager_users below now returns a list of User objects (rather than just their uids) so that we can display both the user name and their netid

users = if Rails.env.development? || Rails.env.staging?
User.where(eligible_sponsor: true).or(User.where(superuser: true))
else
User.where(eligible_sponsor: true)
end
users.map(&:uid)
if Rails.env.development? || Rails.env.staging?
User.where(eligible_sponsor: true).or(User.where(superuser: true))
else
User.where(eligible_sponsor: true)
end
end

# All users who are eligible to be Data Managers
# Users that can be data managers
def self.manager_users
users = if Rails.env.development? || Rails.env.staging?
User.where(eligible_manager: true).or(User.where(superuser: true))
else
User.where(eligible_manager: true)
end
users.map(&:uid)
if Rails.env.development? || Rails.env.staging?
User.where(eligible_manager: true).or(User.where(superuser: true))
else
User.where(eligible_manager: true)
end
end

def clear_mediaflux_session(session)
Expand Down
11 changes: 2 additions & 9 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@
<%= vite_javascript_tag 'application' %>
<script src="//code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>

<!--
If using a TypeScript entrypoint file:
vite_typescript_tag 'application'

If using a .jsx or .tsx entrypoint, add the extension:
vite_javascript_tag 'application.jsx'

Visit the guide for more information: https://vite-ruby.netlify.app/guide/rails
-->
<!-- 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>

<% if Rails.env.development? || Rails.env.staging? %>
<%= render 'shared/plausible_dev_staging' %>
Expand Down
3 changes: 1 addition & 2 deletions app/views/projects/_approve_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<%= render 'form_errors' %>
<%= render 'data_list' %>

<div class="container">
<div class="field">
<label for="project_directory" class="form-label">Confirm Project Directory</label>
<input class="form-directory" type="text" name="project_directory_prefix" required value="<%= @project.project_directory_parent_path %>"></input> /
<input class="form-directory-confirm" type="text" name="project_directory" required value=<%= "#{@project.project_directory_short}"%>></input>
<input class="form-directory-confirm" type="text" name="project_directory" required value=<%= "#{@project.project_directory_short}"%>></input>
</div>
<div class="field">
<label for="storage_capacity" class="form-label">Confirm Storage Capacity</label>
Expand Down
17 changes: 0 additions & 17 deletions app/views/projects/_data_list.html.erb

This file was deleted.

Loading