Skip to content

Commit

Permalink
Added the ability to delete external assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
allomanta committed Oct 15, 2024
1 parent 08b48da commit 5db01bf
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 18 deletions.
10 changes: 10 additions & 0 deletions IguideME.Web/Controllers/Apps/TileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,16 @@ public ActionResult PatchAssignment([FromBody] AppAssignment assignment)
return Ok();
}

[Authorize(Policy = "IsInstructor")]
[HttpDelete]
[Route("/external-assignments/{assignmentID}")]
public ActionResult DeleteAssignment(int assignmentID)
{
int courseID = this.GetCourseID();
_databaseManager.DeleteExternalAssignment(assignmentID, courseID);
return Ok();
}

[Authorize(Policy = "IsInstructor")]
[HttpPatch]
[Route("/external-assignments/{assignmentID}/title")]
Expand Down
4 changes: 4 additions & 0 deletions IguideME.Web/Frontend/src/api/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ export async function patchExternalAssignment(assignment: Assignment): Promise<v
export async function patchExternalAssignmentTitle({ id, title }: { id: number; title: string }): Promise<void> {
return await apiClient.patch(`external-assignments/${id}/title`, { title });
}

export async function deleteExternalAssignment({assignmentID}: {assignmentID: number}): Promise<void> {
return await apiClient.delete(`external-assignments/${assignmentID}`);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getStudentsByCourse } from '@/api/courses';
import { getExternalAssignments, patchExternalAssignmentTitle, postExternalAssignment } from '@/api/entries';
import { getExternalAssignments, patchExternalAssignmentTitle, postExternalAssignment, deleteExternalAssignment } from '@/api/entries';
import AdminTitle from '@/components/atoms/admin-titles/admin-titles';
import UploadManager from '@/components/crystals/upload-manager/upload-manager';
import QueryError from '@/components/particles/QueryError';
Expand All @@ -13,6 +13,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { Button, Input, Tooltip } from 'antd';
import { useState, type FC, type ReactElement } from 'react';
import AssignmentSettingsForm from './assignment-settings-form';
import Swal from 'sweetalert2';

const DataWizard: FC = (): ReactElement => {
return (
Expand Down Expand Up @@ -107,16 +108,23 @@ const ViewExternalAssignment: FC<ViewExternalAssignmentProps> = ({ assignment, s
const [uploadMenuOpen, setUploadMenuOpen] = useState<boolean>(false);

const queryClient = useQueryClient();
const { mutate } = useMutation({
const { mutate: patchExternalAssignment } = useMutation({
mutationFn: patchExternalAssignmentTitle,
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ['external-assignments'] });
},
});

const { mutate: deleteExternalAss } = useMutation({
mutationFn: deleteExternalAssignment,
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ['external-assignments'] });
},
});

return (
<div className='border-border0 bg-surface2 rounded-md border border-solid px-8 py-4'>
<div className='mb-5 flex items-center justify-between'>
<div className='mb-5 flex items-center justify-between flex-wrap'>
<button
onClick={() => {
setEditing(true);
Expand All @@ -136,7 +144,7 @@ const ViewExternalAssignment: FC<ViewExternalAssignmentProps> = ({ assignment, s
}}
onKeyDown={(e) => {
if (e.key !== 'Enter') return;
mutate({
patchExternalAssignment({
id: assignment.id,
title,
});
Expand All @@ -152,14 +160,36 @@ const ViewExternalAssignment: FC<ViewExternalAssignmentProps> = ({ assignment, s
}
</button>
{!uploadMenuOpen && (
<Button
className='custom-default-button ml-auto'
onClick={() => {
setUploadMenuOpen(true);
}}
>
New Upload
</Button>
<div className='ml-auto flex justify-center items-center gap-2 flex-wrap'>
<Button
className='custom-default-button'
onClick={() => {
setUploadMenuOpen(true);
}}
>
New Upload
</Button>
<Button
className='custom-danger-button'
onClick={() => {
void Swal.fire({
title: 'Warning: This will permanently delete the tile!',
icon: 'warning',
focusCancel: true,
showCancelButton: true,
confirmButtonText: 'Delete',
cancelButtonText: 'Cancel',
customClass: {},
}).then((result) => {
if (result.isConfirmed) {
deleteExternalAss({assignmentID: assignment.id});
}
});
}}
>
Delete External Assignment
</Button>
</div>
)}
</div>
{uploadMenuOpen && (
Expand Down
11 changes: 9 additions & 2 deletions IguideME.Web/Services/Constants/DatabaseQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,15 @@ ORDER BY `sync_id`
`grading_type`=@gradingType
WHERE `assignments`.`assignment_id`=@ID
AND `assignments`.`course_id`=@courseID
;";

;";

public const string DELETE_EXTERNAL_ASSIGNMENT =
@"DELETE FROM `assignments`
WHERE `assignments`.`assignment_id`=@ID
AND `assignments`.`course_id`=@courseID
AND `assignments`.`published`=2
;";

public const string UPDATE_EXTERNAL_ASSIGNMENT_TITLE =
@"UPDATE `assignments`
SET `title`=@title
Expand Down
17 changes: 13 additions & 4 deletions IguideME.Web/Services/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public void RegisterUser(User user)
);
}

public List<AppAssignment> GetExternalAssignments(int courseID)
public List<AppAssignment> GetExternalAssignments(int courseID)
{
List<AppAssignment> assignments = new();

Expand Down Expand Up @@ -633,7 +633,7 @@ public int RegisterExternalAssignment(AppAssignment assignment)
);

return assignment_id;
}
}

public void UpdateExternalAssignment(AppAssignment assignment)
{
Expand All @@ -645,7 +645,16 @@ public void UpdateExternalAssignment(AppAssignment assignment)
new SQLiteParameter("maxGrade", assignment.MaxGrade),
new SQLiteParameter("gradingType", assignment.GradingType)
);
}
}

public void DeleteExternalAssignment(int assignmentID, int courseID)
{
int assignment_id = IDNonQuery(
DatabaseQueries.DELETE_EXTERNAL_ASSIGNMENT,
new SQLiteParameter("ID", assignmentID),
new SQLiteParameter("courseID", courseID)
);
}

public void UpdateExternalAssignmentTitle(int assignmentID, int courseID, string title)
{
Expand Down Expand Up @@ -2764,7 +2773,7 @@ public void CreateLayoutTileGroup(int courseID, string title, int position)
// if (cols.Count < 1) return;

NonQuery(
DatabaseQueries.REGISTER_TILE_GROUP,
DatabaseQueries.REGISTER_TILE_GROUP,
// new SQLiteParameter("columnID", cols[0].ID),
new SQLiteParameter("title", title),
new SQLiteParameter("order", position),
Expand Down

0 comments on commit 5db01bf

Please sign in to comment.