Skip to content

Commit

Permalink
Add submission cancel feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ram81 committed Jun 6, 2021
1 parent 978367b commit bf4528b
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 2 deletions.
5 changes: 5 additions & 0 deletions apps/jobs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
views.update_submission_started_at,
name="update_submission_started_at",
),
url(
r"^challenge/(?P<challenge_pk>[0-9]+)/submissions/(?P<submission_pk>[0-9]+)/cancel/$",
views.change_submission_status_to_cancel,
name="change_submission_status_to_cancel",
),
]

app_name = "jobs"
43 changes: 43 additions & 0 deletions apps/jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2775,3 +2775,46 @@ def update_submission_started_at(request, submission_pk):
return Response(response_data, status=status.HTTP_200_OK)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


@api_view(["PATCH"])
@throttle_classes([UserRateThrottle])
@permission_classes((permissions.IsAuthenticated, HasVerifiedEmail))
@authentication_classes((JWTAuthentication, ExpiringTokenAuthentication))
def change_submission_status_to_cancel(request, challenge_pk, submission_pk):
"""
API Endpoint for setting submission status to CANCELLED.
"""
print(request.user, challenge_pk)
participant_team_pk = get_participant_team_id_of_user_for_a_challenge(
request.user, challenge_pk
)

try:
participant_team = ParticipantTeam.objects.get(pk=participant_team_pk)
except ParticipantTeam.DoesNotExist:
response_data = {"error": "You haven't participated in the challenge"}
return Response(response_data, status=status.HTTP_403_FORBIDDEN)

try:
submission = Submission.objects.get(
id=submission_pk,
participant_team=participant_team,
)
except Submission.DoesNotExist:
response_data = {"error": "Submission does not exist"}
return Response(response_data, status=status.HTTP_403_FORBIDDEN)

serializer = SubmissionSerializer(
submission,
data={"status": Submission.CANCELLED},
context={"request": request},
partial=True,
)

if serializer.is_valid():
serializer.save()
response_data = serializer.data
return Response(response_data, status=status.HTTP_200_OK)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
37 changes: 36 additions & 1 deletion frontend/src/js/controllers/challengeCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,42 @@
}
};

vm.hideVisibilityDialog = function() {
vm.cancelSubmission = function(submissionId) {
parameters.url = "jobs/challenge/" + vm.challengeId + "/submissions/" + submissionId + "/cancel/";
parameters.method = 'PATCH';
console.log("Cancelling submission: " + vm.submissionId);
parameters.callback = {
onSuccess: function(response) {
var status = response.status;
if (status === 200) {
$mdDialog.hide();
$rootScope.notify("success", "Submission cancelled successfully!");
}
},
onError: function(response) {
$mdDialog.hide();
var error = response.data;
$rootScope.notify("error", error);
}
};

utilities.sendRequest(parameters);
};

vm.showCancelSubmissionDialog = function(submissionId, status) {
if (status != "submitted") {
$rootScope.notify("error", "Only unproccessed submissions can be cancelled");
return;
}
vm.submissionId = submissionId;
$mdDialog.show({
scope: $scope,
preserveScope: true,
templateUrl: 'dist/views/web/challenge/cancel-submission.html'
});
};

vm.hideDialog = function() {
$mdDialog.hide();
};

Expand Down
16 changes: 16 additions & 0 deletions frontend/src/views/web/challenge/cancel-submission.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<section class="text-center rm-overflow-y">
<div class="row">
<div class="col s12 m12">
<div class="update-submission-visibility-card">
<form name="cancelSubmissionForm" ng-submit="challenge.cancelSubmission(challenge.submissionId)">
<div class="pass-title">Are you sure you want to cancel submission?</div>

<ul class="inline-list pointer">
<li><a class="dark-link" type="button" ng-click="challenge.hideDialog()"><strong>Cancel </strong></a></li>
<li><button class="btn ev-btn-dark waves-effect waves-dark grad-btn grad-btn-dark fs-14" type="submit" value="Submit">Submit </button></li>
</ul>
</form>
</div>
</div>
</div>
</section>
3 changes: 3 additions & 0 deletions frontend/src/views/web/challenge/my-submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ <h6>My Participated Team: {{challenge.participated_team_name}}</h6>
<th class="fs-18 w-300" data-field="isBaseline" ng-if="challenge.isChallengeHost">Baseline
</th>
<th class="fs-18 w-300">Edit</th>
<th class="fs-18 w-300">Cancel</th>
</thead>
<tbody>
<tr ng-repeat="key in challenge.submissionResult.results" class="result-val fs-16 w-300">
Expand Down Expand Up @@ -133,6 +134,8 @@ <h6>My Participated Team: {{challenge.participated_team_name}}</h6>
</td>
<td><a class="pointer" ng-click="challenge.showMdDialog($event, key.id)"><i
class="fa fa-pencil" aria-hidden="true"></i></a></td>
<td><a class="times" ng-click="challenge.showCancelSubmissionDialog(key.id, key.status)"><i
class="fa fa-times" aria-hidden="true"></i></a></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="pass-title">Are you sure you want to override your current public submission?</div>

<ul class="inline-list pointer">
<li><a class="dark-link" type="button" ng-click="challenge.hideVisibilityDialog()"><strong>Cancel </strong></a></li>
<li><a class="dark-link" type="button" ng-click="challenge.hideDialog()"><strong>Cancel </strong></a></li>
<li><button class="btn ev-btn-dark waves-effect waves-dark grad-btn grad-btn-dark fs-14" type="submit" value="Submit">Submit </button></li>
</ul>
</form>
Expand Down

0 comments on commit bf4528b

Please sign in to comment.