Skip to content

Commit d648d17

Browse files
authored
Started switching user data entry to use autocomplete (#1035)
* Started switching user data entry to use autocomplete * Cleaning up... * Include our local copy of the jQuery autocomplete plugin: * Removed reference to deleted code * Ignore rspec report * Fixed test logic * Tweaking the autocomplete validation * Tweak validation code * Fix errors in project_spec validation * Found the magic incantation to trigger focusout and the validation. Still need to fix a few more broken test * Fixed tests * Rubocop nitpicking * Adjusted the validation (since it got messed up during the branch merge) * Fixed another test that I messed up in the branch merge * Fixed another git merge issue * Fixed broken tests * Simplify a couple of tests
1 parent 81c95c4 commit d648d17

File tree

20 files changed

+1403
-703
lines changed

20 files changed

+1403
-703
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ node_modules
6565
# Do not check aterm.jar into the repo
6666
aterm.jar
6767

68-
public
68+
public
6969
doc
7070

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

7474
# Ignore .yardoc
75-
.yardoc/
75+
.yardoc/
76+
77+
# Ignore rspec report
78+
/spec/fixtures/failed_tests.txt

app/assets/stylesheets/_settings.scss

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -238,37 +238,14 @@
238238
margin-bottom: 10px;
239239
}
240240

241-
.custom_error {
242-
display: none;
243-
244-
.error_message {
245-
color: var(--Secondary-Red-Dark, #b00002);
246-
margin-top: 2px;
247-
248-
/* Body XS */
249-
font-family: "Libre Franklin";
250-
font-size: 14px;
251-
font-style: normal;
252-
font-weight: 400;
253-
line-height: 21px; /* 150% */
254-
}
255-
}
256-
257-
input:valid {
241+
input[type=text]:valid {
258242
background-color: rgb(255, 255, 255);
259243
}
260244

261-
input:invalid {
245+
input[type=text]:invalid {
262246
outline-color: red;
263247
}
264248

265-
// write css so that the text displayed on invalid input is red and appears to the right of the div instead of below it
266-
span {
267-
color: red;
268-
display: inline;
269-
margin-left: 10px;
270-
}
271-
272249
h2 {
273250
// Headings for roles and description
274251
text-decoration: underline;

app/assets/stylesheets/application.scss

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,51 @@ body {
3535
}
3636
}
3737

38+
.hidden-element {
39+
display: none;
40+
}
41+
42+
/* These are the styles used by the jQuery autocomplete plug-in */
43+
.autocomplete-suggestions {
44+
border: 1px solid #999;
45+
background: #FFF;
46+
overflow: auto;
47+
}
48+
49+
.autocomplete-suggestion {
50+
padding: 2px 5px;
51+
white-space: nowrap;
52+
overflow: hidden;
53+
}
54+
55+
.autocomplete-selected {
56+
background: #F0F0F0;
57+
}
58+
59+
.autocomplete-suggestions strong {
60+
font-weight: normal;
61+
color: #3399FF;
62+
}
63+
64+
.autocomplete-group {
65+
padding: 2px 5px;
66+
}
67+
68+
.autocomplete-group strong {
69+
display: block;
70+
border-bottom: 1px solid #000;
71+
}
72+
73+
/*
74+
* Adds the arrow to the autocomplete textbox.
75+
* Notice that since CSS does not allow ::after on HTML <input> we apply this style to an HTML <span>.
76+
* See https://stackoverflow.com/questions/2587669/can-i-use-a-before-or-after-pseudo-element-on-an-input-field
77+
*/
78+
.autocomplete-arrow::after {
79+
content: "";
80+
margin-left: -20px;
81+
}
82+
83+
.autocomplete-error {
84+
color: var(--Secondary-Red-Dark, #b00002);
85+
}

app/helpers/project_helper.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,28 @@ def pre_populate_data_sponsor
1010
@project.metadata[:data_sponsor]
1111
end
1212
end
13+
14+
# Returns a string with JSON representation of a list of users
15+
# The JSON can be used to feed the jQuery Autocomplete plug-in
16+
# rubocop:disable Rails/OutputSafety
17+
def user_list_json(users)
18+
json_elements = users.map do |user|
19+
"{ data: '#{user.uid}', value: '#{user.display_name_safe} (#{user.uid})' }"
20+
end
21+
22+
json_elements.join(",").html_safe
23+
end
24+
# rubocop:enable Rails/OutputSafety
25+
26+
def sponsor_list_json
27+
user_list_json(User.sponsor_users)
28+
end
29+
30+
def manager_list_json
31+
user_list_json(User.manager_users)
32+
end
33+
34+
def all_users_list_json
35+
user_list_json(User.all)
36+
end
1337
end

app/javascript/entrypoints/application.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import * as bootstrap from 'bootstrap';
1616
import '../channels';
1717

1818
import { setTargetHtml } from './helper';
19-
import UserDatalist from './user_datalist';
2019
import { displayMediafluxVersion } from './mediafluxVersion';
2120
import { showCreateScript } from './atermScripts';
2221

@@ -245,8 +244,6 @@ function initPage() {
245244
$('#test-jquery').click((event) => {
246245
setTargetHtml(event, 'jQuery works!');
247246
});
248-
const datalist = new UserDatalist();
249-
datalist.setupDatalistValidity();
250247
initDataUsers();
251248
initListContentsModal();
252249
showMoreLessContent();

app/javascript/entrypoints/user_datalist.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

app/models/user.rb

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,22 @@ def self.from_cas(access_token)
1919
user
2020
end
2121

22-
def self.all_users
23-
User.all.map(&:uid)
24-
end
25-
22+
# Users that can be project sponsors
2623
def self.sponsor_users
27-
users = if Rails.env.development? || Rails.env.staging?
28-
User.where(eligible_sponsor: true).or(User.where(superuser: true))
29-
else
30-
User.where(eligible_sponsor: true)
31-
end
32-
users.map(&:uid)
24+
if Rails.env.development? || Rails.env.staging?
25+
User.where(eligible_sponsor: true).or(User.where(superuser: true))
26+
else
27+
User.where(eligible_sponsor: true)
28+
end
3329
end
3430

35-
# All users who are eligible to be Data Managers
31+
# Users that can be data managers
3632
def self.manager_users
37-
users = if Rails.env.development? || Rails.env.staging?
38-
User.where(eligible_manager: true).or(User.where(superuser: true))
39-
else
40-
User.where(eligible_manager: true)
41-
end
42-
users.map(&:uid)
33+
if Rails.env.development? || Rails.env.staging?
34+
User.where(eligible_manager: true).or(User.where(superuser: true))
35+
else
36+
User.where(eligible_manager: true)
37+
end
4338
end
4439

4540
def clear_mediaflux_session(session)

app/views/layouts/application.html.erb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,8 @@
1616
<%= vite_javascript_tag 'application' %>
1717
<script src="//code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
1818

19-
<!--
20-
If using a TypeScript entrypoint file:
21-
vite_typescript_tag 'application'
22-
23-
If using a .jsx or .tsx entrypoint, add the extension:
24-
vite_javascript_tag 'application.jsx'
25-
26-
Visit the guide for more information: https://vite-ruby.netlify.app/guide/rails
27-
-->
19+
<!-- Load our local Autocomplete plug-in which is a copy of https://github.com/devbridge/jQuery-Autocomplete -->
20+
<script src="<%= root_path + 'jquery.autocomplete.js' %>"></script>
2821

2922
<% if Rails.env.development? || Rails.env.staging? %>
3023
<%= render 'shared/plausible_dev_staging' %>

app/views/projects/_approve_form.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<%= render 'form_errors' %>
2-
<%= render 'data_list' %>
32

43
<div class="container">
54
<div class="field">
65
<label for="project_directory" class="form-label">Confirm Project Directory</label>
76
<input class="form-directory" type="text" name="project_directory_prefix" required value="<%= @project.project_directory_parent_path %>"></input> /
8-
<input class="form-directory-confirm" type="text" name="project_directory" required value=<%= "#{@project.project_directory_short}"%>></input>
7+
<input class="form-directory-confirm" type="text" name="project_directory" required value=<%= "#{@project.project_directory_short}"%>></input>
98
</div>
109
<div class="field">
1110
<label for="storage_capacity" class="form-label">Confirm Storage Capacity</label>

app/views/projects/_data_list.html.erb

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)