Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

228 nuxt edit modal does not work #288

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ frontend/.env
/docs/.vitepress/cache/
/docs/.vitepress/dist/
/docs/node_modules
/backend/docker

# User-specific stuff
.idea
40 changes: 20 additions & 20 deletions backend/src/DataFixtures/BookFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ class BookFixture extends Fixture implements DependentFixtureInterface
*/
public function load(ObjectManager $manager): void
{
for ($i = 0; $i < 50; $i++) {
$book = new Book();
$book->setTitle('The Lord of the Rings: Part ' . $i);
$book->setShortTitle('LOTR: Part ' . $i);
$book->setPublisher($this->getReference("publisher " . $i));
$book->setDescription('The sun shines and birds are chirping outside... ' . $i);
$book->setOrderNumber(random_int(1000, 9999999));
$book->setYear($this->getReference('year ' . $i));
$book->setSubject($this->getReference('subject ' . $i));
$book->setEbook(true);
$book->setEbookPlus(false);
$book->setSchoolForm(9999);
$book->setBookPrice(50);
$book->setGrade($i);
$manager->persist($book);

$this->addReference('book ' . $i, $book);
}

$manager->flush();
// for ($i = 0; $i < 50; $i++) {
// $book = new Book();
// $book->setTitle('The Lord of the Rings: Part ' . $i);
// $book->setShortTitle('LOTR: Part ' . $i);
// $book->setPublisher($this->getReference("publisher " . $i));
// $book->setDescription('The sun shines and birds are chirping outside... ' . $i);
// $book->setOrderNumber(random_int(1000, 9999999));
// $book->setYear($this->getReference('year ' . $i));
// $book->setSubject($this->getReference('subject ' . $i));
// $book->setEbook(true);
// $book->setEbookPlus(false);
// $book->setSchoolForm(9999);
// $book->setBookPrice(50);
// $book->setGrade($i);
// $manager->persist($book);
//
// $this->addReference('book ' . $i, $book);
// }
//
// $manager->flush();
}


Expand Down
28 changes: 14 additions & 14 deletions backend/src/DataFixtures/BookOrderFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class BookOrderFixture extends Fixture implements DependentFixtureInterface
{
public function load(ObjectManager $manager): void
{
for ($i = 0; $i < 50; $i++) {
$bookOrder = new BookOrder();
$bookOrder->setBook($this->getReference('book ' . $i));
$bookOrder->setSchoolClass($this->getReference('schoolClass ' . $i));
$bookOrder->setYear($this->getReference('year ' . $i));
$bookOrder->setCount(10);
$bookOrder->setCreationUser('User ' . $i);
$bookOrder->setLastUser('User ' . $i);
$bookOrder->setTeacherCopy(true);
$manager->persist($bookOrder);
$this->addReference('bookOrder ' . $i, $bookOrder);
}

$manager->flush();
// for ($i = 0; $i < 50; $i++) {
// $bookOrder = new BookOrder();
// $bookOrder->setBook($this->getReference('book ' . $i));
// $bookOrder->setSchoolClass($this->getReference('schoolClass ' . $i));
// $bookOrder->setYear($this->getReference('year ' . $i));
// $bookOrder->setCount(10);
// $bookOrder->setCreationUser('User ' . $i);
// $bookOrder->setLastUser('User ' . $i);
// $bookOrder->setTeacherCopy(true);
// $manager->persist($bookOrder);
// $this->addReference('bookOrder ' . $i, $bookOrder);
// }
//
// $manager->flush();
}

public function getDependencies()
Expand Down
1 change: 1 addition & 0 deletions backend/src/Service/BookOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Service;

use App\Entity\Book;
use App\Entity\BookOrder;
use App\Repository\BookOrderRepository;
use Doctrine\ORM\EntityManagerInterface;
Expand Down
108 changes: 108 additions & 0 deletions frontend/components/forms/BookOrderForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<script setup lang="ts">
import { z } from "zod"

const schema = z.object({
schoolClass: z.object({
id: z.number(),
name: z.string(),
grade: z.number(),
students: z.number(),
repetents: z.number(),
budget: z.number(),
usedBudget: z.number(),
}),
repetents: z.string(),
teacherCopy: z.boolean(),
})

const { schoolClasses, fetchSchoolClasses } = useSchoolClasses()
await fetchSchoolClasses()

let repententOptions: { label: string; value: number }[] = []

const { locale, t } = useI18n()
watch(
locale,
() => {
repententOptions = [
{ label: t("bookList.createOrder.repetents.with"), value: 1 },
{ label: t("bookList.createOrder.repetents.without"), value: 2 },
{ label: t("bookList.createOrder.repetents.only"), value: 3 },
]
},
{ immediate: true },
)

const emit = defineEmits<{
"update:modelValue": [newState: typeof state]
}>()

type BookFormState = {
schoolClass: undefined
repetents: undefined
teacherCopy: undefined
}
const state = defineModel<BookFormState>()

watch(
state,
(newState) => {
const result = schema.safeParse(state)

if (!result.success) {
displayFailureNotification(
t("notification.failure"),
t("classes.updateClass.failureDescription"),
)
console.error(result.error.errors)
return
}
emit("update:modelValue", newState)
},
{ deep: true },
)
</script>

<template>
<slot name="header" />
<UForm :schema="schema" :state="state" class="space-y-4">
<UFormGroup
:label="$t('bookList.createOrder.class.title')"
name="schoolClass"
>
<USelectMenu
v-model="state.schoolClass"
:placeholder="$t('bookList.createOrder.class.placeholder')"
:options="schoolClasses"
option-attribute="name"
searchable
/>
</UFormGroup>

<UFormGroup
:label="$t('bookList.createOrder.repetents.title')"
name="repetents"
>
<USelectMenu
v-model="state.repetents"
:placeholder="$t('bookList.createOrder.repetents.placeholder')"
:options="repententOptions"
option-attribute="label"
value-attribute="label"
/>
</UFormGroup>

<UFormGroup
:label="$t('bookList.createOrder.teacherCopy')"
name="teacherCopy"
>
<UCheckbox
v-model="state.teacherCopy"
class="mt-2"
color="blue"
:label="$t('bookList.createOrder.includeTeacherCopy')"
:help="$t('bookList.createOrder.includeDescription')"
/>
</UFormGroup>
</UForm>
</template>
2 changes: 1 addition & 1 deletion frontend/components/modal/BookOrderEditModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const isVisible = props.isVisible
<p
class="text-base font-semibold leading-6 text-red-600 dark:text-white"
>
Editing "{{ bookOrder.bookId }}"
Editing "{{ bookOrder.book }}"
</p>
<UButton
color="gray"
Expand Down
6 changes: 2 additions & 4 deletions frontend/composables/useSchoolClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ export default function useSchoolClasses() {
if (schoolClasses.value.length) return

try {
const { data: classes } = useFetch<APIResponseArray<SchoolClass>>(
const { data: classes } = await useFetch<APIResponseArray<SchoolClass>>(
"/schoolClasses",
{
baseURL: config.public.baseURL,
pick: ["data"],
},
)

// watch(classes, () => {
// schoolClasses.value = classes.value.data
// })
schoolClasses.value = classes.value?.data ?? []
} catch (error) {
schoolClasses.value = []
return error
Expand Down
4 changes: 3 additions & 1 deletion frontend/locales/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
"failureDescription": "Beim Bestellen des Buches ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut."
},
"updateOrder": {
"title": "Buch bearbeiten",
"title": "Bearbeiten des Buches",
"book": "Buch",
"class": "Klasse",
"successDescription": "Das Buch wurde erfolgreich bearbeitet.",
"failureDescription": "Beim Aktualisieren des Buches ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut."
}
Expand Down
16 changes: 14 additions & 2 deletions frontend/locales/en-US.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"error": {
"title": "An Error occurred",
"home": "Go home"
"home": "Go home",
"generic": {
"title": "An error occurred",
"description": "Something went wrong. Please try again."
}
},
"info": {
"couldNotFetch": "Couldn't fetch",
Expand Down Expand Up @@ -82,7 +86,9 @@
"failureDescription": "An error occurred while creating the order. Please try again."
},
"updateOrder": {
"title": "Update Book",
"title": "Editing book order for",
"book": "Book",
"class": "Class",
"successDescription": "The book was successfully updated.",
"failureDescription": "An error occurred while updating the book. Please try again."
}
Expand All @@ -99,6 +105,12 @@
"ebook": "E-book",
"price": "Price"
},
"bookOrder": {
"count": "Count",
"totalPrice": "Total Price",
"repetents": "Repetents",
"lastUser": "Last User"
},
"classes": {
"title": "Class Management",
"subtitle": "Manage your school classes",
Expand Down
Loading
Loading