Skip to content

Commit 6ea22f0

Browse files
author
John Pinto
committed
Feature that re-designs Plan creation page to enforce template access
rules and simplify UI. Co-authored-by: don-stuckey [email protected] This feature was contributed to DMPonline by @don-stuckey
1 parent f7bcd33 commit 6ea22f0

File tree

4 files changed

+254
-148
lines changed

4 files changed

+254
-148
lines changed
Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
11
@use '../variables/colours' as *;
22

3-
.form-control {
4-
border: 0px;
5-
}
63

7-
.form-control input, .form-control textarea, .form-control select{
8-
border: 2px solid $color-border-light;
4+
5+
.form-control input,
6+
.form-control textarea,
7+
.form-control select {
8+
border: 2px solid $color-border-light;
99
}
1010

1111
.form-check {
12-
padding-left: 0rem;
12+
padding-left: 0rem;
1313
}
1414

15-
.form-inline{
16-
margin-bottom: 5px;
15+
.form-inline {
16+
margin-bottom: 5px;
1717
}
1818

1919
.form-check-label {
20-
padding-left: 5px;
20+
padding-left: 5px;
21+
}
22+
23+
// Added for new plan create page app/views/plans/new.html.erb
24+
.roadmap-form {
25+
margin-bottom: 1rem;
26+
27+
legend {
28+
padding-inline: 2px;
29+
float: none;
30+
width: auto;
31+
padding: 0.5rem;
32+
font-size: 1rem;
33+
background-color: $color-primary-background;
34+
color: $color-primary-text;
35+
}
36+
37+
fieldset {
38+
border: 2px solid #555555;
39+
padding: 1rem;
40+
margin-bottom: 1rem;
41+
}
42+
43+
.form-row {
44+
margin-bottom: 1rem;
45+
}
46+
47+
.form-row:last-child {
48+
margin-bottom: 0;
49+
}
50+
51+
.form-check .form-check-input {
52+
float: left;
53+
margin-left: 0.5rem;
54+
}
2155
}

app/controllers/plans_controller.rb

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,43 @@ def index
2929
# rubocop:enable Metrics/AbcSize
3030

3131
# GET /plans/new
32-
# rubocop:disable Metrics/AbcSize
32+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
3333
def new
3434
@plan = Plan.new
3535
authorize @plan
3636

37-
# Get all of the available funders and non-funder orgs
38-
@funders = Org.funder
39-
.includes(identifiers: :identifier_scheme)
40-
.joins(:templates)
41-
.where(templates: { published: true }).uniq.sort_by(&:name)
42-
@orgs = (Org.includes(identifiers: :identifier_scheme).organisation +
43-
Org.includes(identifiers: :identifier_scheme).institution +
44-
Org.includes(identifiers: :identifier_scheme).default_orgs)
45-
@orgs = @orgs.flatten.uniq.sort_by(&:name)
46-
47-
@plan.org_id = current_user.org&.id
37+
# get funder templates
38+
funder_templates = Template.published
39+
.joins(:org)
40+
.merge(Org.funder)
41+
.distinct
42+
43+
# get global templates
44+
global_templates = Template.published
45+
.where(is_default: true)
46+
.distinct
47+
48+
# get templates of user's org
49+
user_org_templates = Template.published
50+
.where(org: current_user.org)
51+
.distinct
52+
53+
# create templates-grouped hash
54+
@templates_grouped = {
55+
_("Your Organisation's Templates:") => user_org_templates.map do |t|
56+
[t.title, t.id]
57+
end,
58+
_('Global Templates:') => global_templates.map do |t|
59+
[t.title, t.id]
60+
end,
61+
_('Funder Templates:') => funder_templates.map do |t|
62+
[t.title, t.id]
63+
end
64+
}.reject { |_, val| val.empty? }
4865

49-
# TODO: is this still used? We cannot switch this to use the :plan_params
50-
# strong params because any calls that do not include `plan` in the
51-
# query string will fail
52-
flash[:notice] = "#{_('This is a')} <strong>#{_('test plan')}</strong>" if params.key?(:test)
53-
@is_test = params[:test] ||= false
5466
respond_to :html
5567
end
56-
# rubocop:enable Metrics/AbcSize
68+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
5769

5870
# POST /plans
5971
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength

app/views/plans/new.html.erb

Lines changed: 83 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,90 @@
1-
<% title _('Create a new plan') %>
2-
<% required_project_title_tooltip = _('This field is required.') %>
3-
<% project_title_tooltip = _('If applying for funding, state the project title exactly as in the proposal.') %>
4-
<% required_research_org_tooltip = _('You must select a research organisation from the list or click the checkbox.') %>
5-
<% research_org_tooltip = _('Please select a valid research organisation from the list.') %>
6-
<% required_primary_funding_tooltip = _('You must select a funder from the list or click the checkbox.') %>
7-
<% primary_funding_tooltip = _('Please select a valid funding organisation from the list.') %>
8-
9-
<div class="row">
10-
<div class="col-md-12">
11-
<h1><%= _('Create a new plan') %></h1>
12-
13-
<p class="start-indent">
14-
<%= _("Before you get started, we need some information about your research project to set you up with the best DMP template for your needs.") %>
15-
</p>
1+
<form action="<%= plans_path %>" method="post" class="roadmap-form">
2+
<div class="row form-row">
3+
<div class="col-12">
4+
<h1><%= _('Create a new plan') %></h1>
5+
<p>
6+
<%= _("Before you get started, we need some information about your research project to set you up with the best DMP template for your needs.") %>
7+
</p>
8+
</div>
169
</div>
17-
</div>
18-
19-
<div class="row">
20-
<div class="col-md-12">
21-
<%= form_for Plan.new, url: plans_path do |f| %>
22-
<!-- Plan name section -->
23-
<h2 id="project-title"><span class="red" title="<%= required_project_title_tooltip %>">*<em class="sr-only"><%= required_project_title_tooltip %></em> </span><%= _('What research project are you planning?') %></h2>
24-
<div class="row">
25-
<div class="form-control mb-3 col-md-8">
26-
<%= f.text_field(:title, class: 'form-control', 'aria-labelledby': 'project-title', 'aria-required': 'true', 'aria-label': 'project-title',
27-
'data-toggle': 'tooltip',
28-
'data-placement': 'bottom',
29-
spellcheck: true,
30-
title: project_title_tooltip ) %>
31-
</div>
32-
<div class="form-control mb-3 col-md-6">
33-
<div class="checkbox">
34-
<%= label_tag(:is_test) do %>
35-
<%= check_box_tag(:is_test, "1", false) %>
36-
<%= _('mock project for testing, practice, or educational purposes') %>
37-
<% end %>
38-
</div>
39-
</div>
10+
<fieldset>
11+
<div class="row form-row">
12+
<div class="col-12">
13+
<!-- Rails form authenticity token -->
14+
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
15+
<label for="plan_title" id="project-title" class="form-label">
16+
<%= _('Enter project title') %>
17+
</label>
18+
<input type="text"
19+
id="plan_title"
20+
name="plan[title]"
21+
class="form-control"
22+
required
23+
aria-labelledby="project-title"
24+
aria-required="true"
25+
aria-label="project-title"
26+
data-toggle="tooltip"
27+
data-placement="bottom"
28+
spellcheck="true">
4029
</div>
41-
42-
<!-- Organisation selection -->
43-
<h2 id="research-org">
44-
<span class="red" title="<%= required_research_org_tooltip %>">*<em class="sr-only"><%= required_research_org_tooltip %></em> </span>
45-
<%= _('Select the primary research organisation') %>
46-
</h2>
47-
<div id="research-org-controls" class="row">
48-
<div class="form-control mb-3 col-md-6">
49-
<em class="sr-only"><%= research_org_tooltip %></em>
50-
<% dflt = @orgs.include?(current_user.org) ? current_user.org : nil %>
51-
<%= f.fields_for :org, @plan.org do |org_fields| %>
52-
<%= render partial: "shared/org_selectors/local_only",
53-
locals: {
54-
form: org_fields,
55-
id_field: :id,
56-
default_org: dflt,
57-
orgs: @orgs,
58-
required: false
59-
} %>
60-
<% end %>
61-
</div>
62-
<div class="col-md-3 text-center"><strong>- <%= _('or') %> -</strong></div>
63-
<div class="form-control mb-3 col-md-3">
64-
<div class="form-check">
65-
<% primary_research_org_message = _('No research organisation associated with this plan or my research organisation is not listed') %>
66-
<%= label_tag(:plan_no_org) do %>
67-
<%= check_box_tag(:plan_no_org, "0", false, class: "toggle-autocomplete") %>
68-
<%= primary_research_org_message %>
69-
<% end %>
70-
</div>
30+
</div>
31+
<div class="row form-row">
32+
<div class="col-12">
33+
<div class="form-check">
34+
<input type="checkbox"
35+
class="form-check-input"
36+
id="is_test"
37+
value="1">
38+
<label class="form-check-label" for="is_test">
39+
<%= _('Mock project for testing, practice, or educational purposes') %>
40+
</label>
7141
</div>
72-
</div>
73-
74-
<!-- Funder selection -->
75-
<h2 id="funder-org"><span class="red" title="<%= required_primary_funding_tooltip %>">* <em class="sr-only"><%= required_primary_funding_tooltip %></em> </span><%= _('Select the primary funding organisation') %></h2>
76-
<div id="funder-org-controls" class="row">
77-
<div class="form-control mb-3 col-md-6">
78-
<em class="sr-only"><%= primary_funding_tooltip %></em>
79-
<%= f.fields_for :funder, @plan.funder = Org.new do |funder_fields| %>
80-
<%= render partial: "shared/org_selectors/local_only",
81-
locals: {
82-
form: funder_fields,
83-
id_field: :id,
84-
label: _("Funder"),
85-
default_org: nil,
86-
orgs: @funders,
87-
required: false
88-
} %>
89-
<% end %>
90-
</div>
91-
<div class="col-md-3 text-center"><strong>- <%= _('or') %> -</strong></div>
92-
<div class="form-control mb-3 col-md-3">
93-
<div class="form-check">
94-
<% primary_funding_message = _('No funder associated with this plan or my funder is not listed') %>
95-
<%= label_tag(:plan_no_funder) do %>
96-
<%= check_box_tag(:plan_no_funder, "0", false, class: "toggle-autocomplete") %>
97-
<%= primary_funding_message %>
42+
</div>
43+
</div>
44+
</fieldset>
45+
<fieldset class="form-group">
46+
<legend>
47+
<%= _('Select a DMP template') %>
48+
</legend>
49+
<div class="row form-row">
50+
<div class="col-12">
51+
<% @templates_grouped.each do |group_label, group_templates| %>
52+
<div class="mb-3">
53+
<div class="form-label fw-bold">
54+
<%= group_label %>
55+
</div>
56+
<% group_templates.each do |template_title, template_id| %>
57+
<div class="form-check">
58+
<input
59+
class="form-check-input"
60+
type="radio"
61+
id="template_<%= template_id %>"
62+
name="plan[template_id]"
63+
value="<%= template_id %>"
64+
required
65+
aria-labelledby="template_<%= template_id %>"
66+
>
67+
<label
68+
class="form-check-label fw-normal"
69+
id="template_<%= template_id %>"
70+
for="template_<%= template_id %>"
71+
>
72+
<%= template_title %>
73+
</label>
74+
</div>
9875
<% end %>
9976
</div>
100-
</div>
101-
</div>
77+
<% end %>
10278

103-
<!-- Template selection -->
104-
<div id="available-templates" style="visibility: none;">
105-
<%= hidden_field_tag 'template-option-target', template_options_path %>
106-
<h2 id="template-selection"><%= _('Which DMP template would you like to use?') %></h2>
107-
<div class="form-control mb-3 row">
108-
<div class="col-md-6">
109-
<%= select_tag(:plan_template_id, "<option value=\"\">#{_('Please select a template')}</option>", name: 'plan[template_id]',
110-
class: 'form-select', 'aria-labelledby': 'template-selection') %>
111-
</div>
112-
<div class="col-md-6">
113-
<span id="multiple-templates">
114-
<%= _('We found multiple DMP templates corresponding to your funder.') %>
115-
</span>
116-
</div>
117-
</div>
118-
</div>
119-
120-
<%= f.hidden_field(:visibility, value: @is_test ? 'is_test' : Rails.configuration.x.plans.default_visibility) %>
121-
<%= f.button(_('Create plan'), class: "btn btn-primary", type: "submit") %>
122-
<%= link_to _('Cancel'), plans_path, class: 'btn btn-secondary' %>
123-
<% end %>
79+
</div>
80+
</div>
81+
</fieldset>
82+
<div class="row form-row">
83+
<div class="col-12">
84+
<button type="submit" class="btn btn-primary">
85+
<%= _('Create') %>
86+
</button>
87+
<%= link_to _('Cancel'), plans_path, class: 'btn btn-secondary' %>
88+
</div>
12489
</div>
125-
</div>
90+
</form>

0 commit comments

Comments
 (0)