Skip to content

Commit

Permalink
chore: docker images edit button
Browse files Browse the repository at this point in the history
  • Loading branch information
bsilkyn committed Apr 29, 2024
1 parent 33fe3bc commit 0d7b11c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
6 changes: 3 additions & 3 deletions backend/api/views/docker_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def search(self, request: Request) -> Response:
return self.get_paginated_response(serializer.data)


@action(detail=True, permission_classes=[IsAdminUser])
def patch_public(self, request: Request, *_) -> Response:
@action(detail=True, methods=['PATCH'], url_path='public', permission_classes=[IsAdminUser])
def patch_public(self, request: Request, **_) -> Response:
docker_image = self.get_object()
serializer = DockerImageSerializer(docker_image, data=request.data, partial=True)

if serializer.is_valid:
if serializer.is_valid():
serializer.save()

return Response(serializer.data)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/services/docker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function useDockerImages(): DockerImagesState {

async function patchDockerImage(dockerData: DockerImage): Promise<void> {
const endpoint = endpoints.dockerImages.patch.replace('{id}', dockerData.id);
await patch(endpoint, {public: dockerData.public }, response);
await patch(endpoint, {public: dockerData.public}, response);
}

async function createDockerImage(dockerData: DockerImage, file: File): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/config/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const endpoints = {
dockerImages: {
index: '/api/docker-images/',
search: '/api/docker-images/search/',
patch: 'api/docker-images/{id}/',
patch: '/api/docker-images/{id}/public/',
},
students: {
index: '/api/students/',
Expand Down
20 changes: 9 additions & 11 deletions frontend/src/views/admin/DockerImagesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@ const publicOptions = ref<{ value: any, label: string }[]>([
]);
const showSafetyGuard = ref<boolean>(false);
const changePublicStatus = async (dockerData: DockerImage): Promise<void> => {
showSafetyGuard.value = false;
await patchDockerImage(dockerData);
};
const toggleSafetyGuard = (data: any): void => {
editItem.value.public = data.public;
editItem.value.id = data.id;
showSafetyGuard.value = true;
console.log(data);
}
console.log(editItem.value);
};
const changePublicStatus = async (dockerData: DockerImage): Promise<void> => {
showSafetyGuard.value = false;
await patchDockerImage(dockerData);
};
const upload = async (event: FileUploadUploaderEvent): Promise<void> => {
const files: File[] = event.files as File[];
await createDockerImage(addItem.value, files[0]);
Expand Down Expand Up @@ -120,7 +118,7 @@ const upload = async (event: FileUploadUploaderEvent): Promise<void> => {
<SelectButton
class="mb-3 gap-3"
v-model="data.public"
@click="toggleSafetyGuard"
@click="() => toggleSafetyGuard(data)"
:options="publicOptions"
option-value="value"
option-label="label"/>
Expand Down Expand Up @@ -149,9 +147,9 @@ const upload = async (event: FileUploadUploaderEvent): Promise<void> => {
</div>
</Body>
</AdminLayout>
<Dialog v-model:visible="showSafetyGuard" :style="{ width: '26rem' }">
<Dialog v-model:visible="showSafetyGuard" :style="{ width: '15rem' }">
<h3>Are you sure?</h3>
<div class="p-d-flex p-jc-end">
<div class="flex justify-content-between">
<Button label="No" @click="showSafetyGuard = false" />
<Button label="Yes" @click="() => changePublicStatus(editItem)" />
</div>
Expand Down

0 comments on commit 0d7b11c

Please sign in to comment.