Skip to content

Commit ee692be

Browse files
Move abort results to ticket
1 parent 91aae28 commit ee692be

File tree

10 files changed

+87
-32
lines changed

10 files changed

+87
-32
lines changed

app/controllers/admin_controller.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ def check_competition_results
3636
@competition = competition_from_params
3737
end
3838

39-
def clear_results_submission
40-
# Just clear the "results_submitted_at" field to let the Delegate submit
41-
# the results again. We don't actually want to clear InboxResult and InboxPerson.
42-
@competition = competition_from_params
43-
44-
if @competition.results_submitted? && !@competition.results_posted?
45-
@competition.update(results_submitted_at: nil)
46-
flash[:success] = "Results submission cleared."
47-
else
48-
flash[:danger] = "Could not clear the results submission. Maybe results are already posted, or there is no submission."
49-
end
50-
redirect_to competition_admin_upload_results_edit_path
51-
end
52-
5339
# The order of this array has to follow the steps in which results have to be imported.
5440
RESULTS_POSTING_STEPS = %i[inbox_result inbox_person].freeze
5541

app/controllers/results_submission_controller.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,24 @@ def create
172172

173173
return render status: :unprocessable_entity, json: { error: "Submitted results contain errors." } if results_validator.any_errors?
174174

175-
return render status: :unprocessable_entity, json: { error: "There is already a ticket associated, please contact WRT to update this." } if competition.result_ticket.present?
175+
if competition.tickets_competition_result.present? && !competition.tickets_competition_result.aborted?
176+
return render status: :unprocessable_entity, json: {
177+
error: "There is already a ticket associated with this, hence the results can be submitted only if the ticket is in abort state.",
178+
}
179+
end
176180

177181
CompetitionsMailer.results_submitted(competition, results_validator, message, current_user).deliver_now
178182

179183
ActiveRecord::Base.transaction do
180184
competition.touch(:results_submitted_at)
181-
TicketsCompetitionResult.create_ticket!(competition, message, current_user)
185+
if competition.tickets_competition_result.present?
186+
competition.tickets_competition_result.update!(
187+
status: TicketsCompetitionResult.statuses[:submitted],
188+
delegate_message: message,
189+
)
190+
else
191+
TicketsCompetitionResult.create_ticket!(competition, message, current_user)
192+
end
182193
end
183194

184195
render status: :ok, json: { success: true }

app/models/tickets_competition_result.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class TicketsCompetitionResult < ApplicationRecord
55

66
enum :status, {
77
submitted: "submitted",
8+
aborted: "aborted",
89
locked_for_posting: "locked_for_posting",
910
warnings_verified: "warnings_verified",
1011
merged_inbox_results: "merged_inbox_results",

app/views/admin/new_results.html.erb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
<% provide(:title, "Upload results") %>
22
<%= render layout: 'competitions/nav' do %>
33
<h1><%= yield(:title) %></h1>
4-
<% if @competition.results_submitted? && !@competition.results_posted? %>
5-
<%= alert :info, note: true do %>
6-
It looks like the results have been submitted by the Delegate but not posted yet.
7-
If you want to let the Delegate submit the results again you can
8-
<%= link_to("clear the results submission",
9-
competition_clear_results_submission_path(@competition),
10-
method: :post, class: "btn btn-primary") %>
11-
<% end %>
12-
<% end %>
134
<p>
145
Import the results JSON for this competition.
156
The server will check for any error compared to the declared rounds, cutoffs, and time limits.

app/views/results_submission/new.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
resultsSubmitted: @competition.results_submitted?,
99
hasTemporaryResults: @competition.inbox_results.present?,
1010
canSubmitResults: @current_user.can_submit_competition_results?(@competition),
11+
resultProcessAborted: @competition.tickets_competition_result&.aborted?,
1112
}) %>
1213
<% end %>

app/webpacker/components/CompetitionResultSubmission/index.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ export default function Wrapper(
2323

2424
function CompetitionResultSubmission(
2525
{
26-
competitionId, resultsSubmitted, hasTemporaryResults, canSubmitResults,
26+
competitionId, resultsSubmitted, hasTemporaryResults, canSubmitResults, resultProcessAborted,
2727
},
2828
) {
29-
if (resultsSubmitted) {
30-
<Message positive>
31-
The results have already been submitted. If you have any more questions or
32-
comments please reply to the email sent with the first results submission.
33-
</Message>;
29+
if (resultsSubmitted && !resultProcessAborted) {
30+
return (
31+
<Message positive>
32+
The results have already been submitted. If you have any more questions or
33+
comments please reply to the email sent with the first results submission.
34+
</Message>
35+
);
3436
}
3537

3638
return (
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import { Header, List, Segment } from 'semantic-ui-react';
3+
import AbortProcess from './MiscActions/AbortProcess';
4+
5+
export default function MiscActions({ ticketDetails, updateStatus }) {
6+
return (
7+
<Segment>
8+
<Header>Misc Actions</Header>
9+
<List>
10+
<List.Item>
11+
<AbortProcess
12+
ticketDetails={ticketDetails}
13+
updateStatus={updateStatus}
14+
/>
15+
</List.Item>
16+
</List>
17+
</Segment>
18+
);
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { useState } from 'react';
2+
import { Button, Confirm, Popup } from 'semantic-ui-react';
3+
import { ticketsCompetitionResultStatuses } from '../../../../../lib/wca-data.js.erb';
4+
5+
export default function AbortProcess({ ticketDetails, updateStatus }) {
6+
const { ticket: { metadata: { status } } } = ticketDetails;
7+
const [confirmAbort, setConfirmAbort] = useState();
8+
9+
// Result Process can be aborted before the inbox results are merged.
10+
const canAbort = [
11+
ticketsCompetitionResultStatuses.submitted,
12+
ticketsCompetitionResultStatuses.locked_for_posting,
13+
ticketsCompetitionResultStatuses.warnings_verified,
14+
].includes(status);
15+
16+
return (
17+
<>
18+
<Popup
19+
trigger={(
20+
<div>
21+
{/* Button wrapped in a div because disabled button does not fire mouse events */}
22+
<Button
23+
disabled={!canAbort}
24+
onClick={() => setConfirmAbort(true)}
25+
>
26+
Abort Process
27+
</Button>
28+
</div>
29+
)}
30+
content={canAbort ? 'Allow Delegate to resubmit results.' : 'Cannot abort at this stage.'}
31+
/>
32+
<Confirm
33+
open={confirmAbort}
34+
onCancel={() => setConfirmAbort(false)}
35+
onConfirm={() => updateStatus(ticketsCompetitionResultStatuses.aborted)}
36+
content="Are you sure you want to abort the process and allow Delegates to resubmit results?"
37+
/>
38+
</>
39+
);
40+
}

app/webpacker/components/Tickets/TicketWorkbenches/CompetitionResultActionerView/index.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import TimelineView from './TimelineView';
55
import MergeInboxResults from './MergeInboxResults';
66
import CreateWcaIds from './CreateWcaIds';
77
import FinalSteps from './FinalSteps';
8+
import MiscActions from './MiscActions';
89

910
export default function CompetitionResultActionerView({ ticketDetails, updateStatus }) {
1011
const { ticket: { metadata: { status } } } = ticketDetails;
@@ -17,6 +18,10 @@ export default function CompetitionResultActionerView({ ticketDetails, updateSta
1718
ticketDetails={ticketDetails}
1819
updateStatus={updateStatus}
1920
/>
21+
<MiscActions
22+
ticketDetails={ticketDetails}
23+
updateStatus={updateStatus}
24+
/>
2025
</>
2126
);
2227
}

config/routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
# WRT views and action
126126
get '/admin/upload-results' => "admin#new_results", as: :admin_upload_results_edit
127127
get '/admin/check-existing-results' => "admin#check_competition_results", as: :admin_check_existing_results
128-
post '/admin/clear-submission' => "admin#clear_results_submission", as: :clear_results_submission
129128
get '/admin/import-results' => 'admin#import_results', as: :admin_import_results
130129
get '/admin/result-inbox-steps' => 'admin#result_inbox_steps', as: :admin_result_inbox_steps
131130
post '/admin/import-inbox-results' => 'admin#import_inbox_results', as: :admin_import_inbox_results

0 commit comments

Comments
 (0)