Skip to content

Commit f52be0f

Browse files
Fix: prompt SCC Members to select an organization before adding to queue (#356)
* Fix: prompt SCC Members to select an organization before adding to queue * Remove business logic from controller * fix: remove unnecessary quote from en.yml * fix: attribute prerequisites and more standard use of present? --------- Co-authored-by: Tomas Goncalves <43731728+Runner-dev@users.noreply.github.com> Co-authored-by: Katie Zhang <mengyua3@andrew.cmu.edu>
1 parent fdf4db1 commit f52be0f

File tree

4 files changed

+83
-81
lines changed

4 files changed

+83
-81
lines changed

app/controllers/organization_timeline_entries_controller.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ def create
3232
redirect_to params[:url], notice: "Added to structural queue!"
3333
elsif @organization_timeline_entry.entry_type == 'electrical'
3434
redirect_to params[:url], notice: "Added to electrical queue!"
35-
else
35+
else
3636
redirect_to params[:url], notice: "Started downtime!"
3737
end
3838
else
39-
flash.now[:alert] = t('.alert')
40-
render :new, status: :unprocessable_entity
39+
redirect_to params[:url], alert: t(".alert")
4140
end
4241
end
4342

app/models/organization_timeline_entry.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class OrganizationTimelineEntry < ApplicationRecord
1414
scope :current, -> { where(ended_at: nil) }
1515
scope :active, -> { where(active: true) }
1616
scope :inactive, -> { where(active: false) }
17-
scope :today, -> { where("started_at >= ? AND started_at <= ?", Time.zone.now.beginning_of_day, Time.zone.now.end_of_day)}
17+
scope :today, -> { where("started_at >= ? AND started_at <= ?", Time.zone.now.beginning_of_day, Time.zone.now.end_of_day)}
1818

1919
def duration
2020
return ended_at.to_i - started_at.to_i if ended_at.present?
@@ -24,7 +24,7 @@ def duration
2424

2525
def already_in_queue?
2626
%w[structural electrical].include?(entry_type) &&
27-
!organization.organization_timeline_entries.current.send(entry_type).empty?
27+
organization&.organization_timeline_entries&.current&.send(entry_type)&.present?
2828
end
2929

3030
# notifcations

app/views/organization_timeline_entries/_queue_sidebar.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h1>Add to Queue</h1>
22
<%= form_with model: OrganizationTimelineEntry.new do |f| %>
33
<% if can?(:create, OrganizationTimelineEntry.new) %>
4-
<%= f.collection_select :organization_id, Organization.all.ordered_by_name, :id, :name %>
4+
<%= f.collection_select :organization_id, Organization.all.ordered_by_name, :id, :name, prompt: true %>
55
<% else %>
66
<%= f.collection_select :organization_id, Current.user.organizations, :id, :name %>
77
<% end %>

config/locales/en.yml

Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -32,137 +32,140 @@
3232
en:
3333
unauthorized:
3434
manage:
35-
all: 'Not authorized to %{action} %{subject}.'
35+
all: Not authorized to %{action} %{subject}.
3636
new:
37-
faq: 'Not authorized to add %{action} %{subject}.'
37+
faq: Not authorized to add %{action} %{subject}.
3838

3939
time:
4040
formats:
41-
timestamp: '%Y-%m-%d %H:%M (%a)'
41+
timestamp: %Y-%m-%d %H:%M (%a)
4242

4343
# Controllers
4444
faq:
4545
index:
46-
new: 'Add Question to FAQ'
47-
edit: 'Edit This FAQ'
48-
destroy: 'Delete This FAQ'
49-
confirm: 'Are you sure?'
46+
new: Add Question to FAQ
47+
edit: Edit This FAQ
48+
destroy: Delete This FAQ
49+
confirm: Are you sure?
5050
new:
51-
heading: 'Create New FAQ'
51+
heading: Create New FAQ
5252
edit:
53-
heading: 'Edit FAQ'
53+
heading: Edit FAQ
5454
create:
55-
alert: 'Could not create FAQ. Please correct the issues below.'
56-
notice: 'FAQ "%{name}" created successfully.'
55+
alert: Could not create FAQ. Please correct the issues below.
56+
notice: FAQ %{name} created successfully.
5757
update:
58-
alert: 'Could not update FAQ. Please correct the issues below.'
59-
notice: 'FAQ "%{name}" updated successfully.'
58+
alert: Could not update FAQ. Please correct the issues below.
59+
notice: FAQ %{name} updated successfully.
6060
destroy:
61-
alert: 'Problem deleting FAQ "%{name}"'
62-
notice: 'FAQ "%{name}" deleted successfully.'
61+
alert: Problem deleting FAQ %{name}
62+
notice: FAQ %{name} deleted successfully.
6363
form:
64-
cancel: 'Cancel'
64+
cancel: Cancel
6565
participants:
6666
safety_briefings:
6767
update:
68-
alert: 'Problem: %{errors}'
68+
alert: Problem: %{errors}
6969
waivers:
7070
form:
71-
cancel: 'Cancel'
71+
cancel: Cancel
7272
update:
73-
alert: 'Could not accept waiver. Please correct the issues below.'
74-
notice: 'Waiver for %{name} submitted.'
73+
alert: Could not accept waiver. Please correct the issues below.
74+
notice: Waiver for %{name} submitted.
7575
sessions:
7676
create:
77-
alert: 'User could not be found. %{message}'
78-
help_link: 'Get help'
77+
alert: User could not be found. %{message}
78+
help_link: Get help
7979
destroy:
80-
notice: 'User logged out.'
80+
notice: User logged out.
8181
welcome:
82-
html: '<h1>Welcome, %{name}!</h1>'
82+
html: <h1>Welcome, %{name}!</h1>
83+
organization_timeline_entries:
84+
create:
85+
alert: Failed to save organization timeline entry
8386

8487
# Views: Form helpers
8588
helpers:
8689
label:
8790
faq:
88-
question: 'Question text'
89-
answer: 'Answer to the question'
90-
organization_category: 'Show this question to'
91+
question: Question text
92+
answer: Answer to the question
93+
organization_category: Show this question to
9194
submit:
92-
create: 'Create New %{model}'
93-
update: 'Confirm Changes to %{model}'
95+
create: Create New %{model}
96+
update: Confirm Changes to %{model}
9497

9598
# Models
9699
activerecord:
97100
models:
98-
faq: 'Question'
101+
faq: Question
99102
attributes:
100103
participant:
101-
safety_briefing_expected_end_at: 'Safety briefing completion time'
104+
safety_briefing_expected_end_at: Safety briefing completion time
102105
errors:
103106
models:
104107
participant:
105108
attributes:
106109
safety_briefing_expected_end_at:
107-
less_than: 'too soon. Now watch it again from the beginning.'
110+
less_than: too soon. Now watch it again from the beginning.
108111
name_confirmation:
109-
confirmation: "doesn't match name above"
112+
confirmation: doesn't match name above
110113
# OLD
111114
attributes_OLD:
112115
shift:
113-
required_number_of_participants: '# of People'
114-
shift_participants: 'Participants'
115-
shift_type: 'Type'
116+
required_number_of_participants: # of People
117+
shift_participants: Participants
118+
shift_type: Type
116119
charge:
117-
charge_type: 'Type'
118-
issuing_participant: 'Issued By'
119-
receiving_participant: 'Issued To'
120-
charged_at: 'Time'
121-
is_approved: 'Approved?'
120+
charge_type: Type
121+
issuing_participant: Issued By
122+
receiving_participant: Issued To
123+
charged_at: Time
124+
is_approved: Approved?
122125
organization:
123-
organization_category: 'Division'
126+
organization_category: Division
124127
helpers_OLD:
125-
actions: 'Actions'
128+
actions: Actions
126129
links:
127-
add: 'Add'
128-
edit: 'Edit'
129-
new: 'New'
130-
update: 'Update'
131-
show: 'Show'
132-
destroy: 'Delete'
133-
back: 'Back'
134-
cancel: 'Cancel'
135-
checkout: 'Check-Out'
136-
checkin: 'Check-In'
137-
add_to_cart: 'Add to Cart'
138-
remove_from_cart: 'Remove from Cart'
139-
complete: 'Complete'
140-
confirm: 'Are you sure?'
141-
new_item: 'New Store Item'
142-
new_charge: 'New Charge'
143-
new_task: 'New Task'
144-
new_shift_participant: 'Clock In'
130+
add: Add
131+
edit: Edit
132+
new: New
133+
update: Update
134+
show: Show
135+
destroy: Delete
136+
back: Back
137+
cancel: Cancel
138+
checkout: Check-Out
139+
checkin: Check-In
140+
add_to_cart: Add to Cart
141+
remove_from_cart: Remove from Cart
142+
complete: Complete
143+
confirm: Are you sure?
144+
new_item: New Store Item
145+
new_charge: New Charge
146+
new_task: New Task
147+
new_shift_participant: Clock In
145148
errors:
146149
messages:
147-
tool_already_checked_out: 'The Tool you selected is already checked out. Please return it before continuing.'
148-
tool_already_checked_in: 'The Tool you selected is already checked in.'
149-
tool_does_not_exist: 'The Tool barcode you entered is not registered with the system. Please register it if desired.'
150-
tool_is_not_hardhat: 'This page can only be used to checkout/checkin hardhats.'
151-
participant_does_not_exist: 'The Participant or ID card you selected is invalid. Please try again or contact an admin if you think this message is in error'
152-
organization_does_not_exist: 'The Organization you selected does not exist.'
150+
tool_already_checked_out: The Tool you selected is already checked out. Please return it before continuing.
151+
tool_already_checked_in: The Tool you selected is already checked in.
152+
tool_does_not_exist: The Tool barcode you entered is not registered with the system. Please register it if desired.
153+
tool_is_not_hardhat: This page can only be used to checkout/checkin hardhats.
154+
participant_does_not_exist: The Participant or ID card you selected is invalid. Please try again or contact an admin if you think this message is in error
155+
organization_does_not_exist: The Organization you selected does not exist.
153156
will_paginate:
154-
previous_label: '«'
155-
next_label: '»'
157+
previous_label: «
158+
next_label: »
156159
flash:
157160
actions:
158161
create:
159-
notice: '{resource_name} was successfully created'
162+
notice: {resource_name} was successfully created
160163
update:
161-
notice: '{resource_name} was successfully updated'
164+
notice: {resource_name} was successfully updated
162165
destroy:
163-
notice: '{resource_name} was successfully deleted'
164-
alert: '{resource_name} could not be deleted'
166+
notice: {resource_name} was successfully deleted
167+
alert: {resource_name} could not be deleted
165168
charges:
166169
approve:
167-
notice: 'Charge was successfully approved/un-approved'
168-
alert: 'Charge could not be approved/un-approved'
170+
notice: Charge was successfully approved/un-approved
171+
alert: Charge could not be approved/un-approved

0 commit comments

Comments
 (0)