diff --git a/backend/sql/course.migration.sql b/backend/sql/course.migration.sql index 560bcf7..776e2f9 100644 --- a/backend/sql/course.migration.sql +++ b/backend/sql/course.migration.sql @@ -1,6 +1,6 @@ CREATE TABLE course ( course_id INTEGER PRIMARY KEY AUTO_INCREMENT, - course_name VARCHAR(50) NOT NULL, + course_name VARCHAR(75) NOT NULL, course_display_name VARCHAR(100) NOT NULL, course_days_amount INTEGER NOT NULL, course_has_custom_label BOOLEAN NOT NULL diff --git a/backend/sql/person.migration.sql b/backend/sql/person.migration.sql index f58a641..70732ed 100644 --- a/backend/sql/person.migration.sql +++ b/backend/sql/person.migration.sql @@ -2,7 +2,7 @@ CREATE TABLE person ( person_id INTEGER PRIMARY KEY AUTO_INCREMENT, - person_dni VARCHAR(8) NOT NULL, + person_dni VARCHAR(20) NOT NULL, person_names VARCHAR(100) NOT NULL, person_paternal_surname VARCHAR(50) NOT NULL, person_maternal_surname VARCHAR(50) NOT NULL diff --git a/frontend/src/certs/NewRegister/ManualRegistration.tsx b/frontend/src/certs/NewRegister/ManualRegistration.tsx index 469ba80..28a31cc 100644 --- a/frontend/src/certs/NewRegister/ManualRegistration.tsx +++ b/frontend/src/certs/NewRegister/ManualRegistration.tsx @@ -43,8 +43,6 @@ export function ManualRegistration(props: {personId: number | null, onAdd: (v: [ setCount((x) => x + 1); }; - console.log(`Person ID: ${props.personId}`); - return ( <>
diff --git a/frontend/src/certs/NewRegister/RegisterPresets.tsx b/frontend/src/certs/NewRegister/RegisterPresets.tsx index 74a0037..f5c5568 100644 --- a/frontend/src/certs/NewRegister/RegisterPresets.tsx +++ b/frontend/src/certs/NewRegister/RegisterPresets.tsx @@ -1,20 +1,107 @@ +import { Accessor, For, createSignal } from "solid-js"; import { Chip } from "../../components/Chip"; +import { getCourseMemo } from "../../utils/allCourses"; +import { Course } from "../../types/Course"; -export function RegisterPresets() { +type PresetName = "None" | "2 Matpel" | "3 Matpel" | "4 Escolta" | "MD, 2 Matpel" | "3 4x4" | "2 4x4"; + +function genPresets(): {[k: string]: Array>} { + return { + "2 Matpel": [ + getCourseMemo("Matpel 2"), + getCourseMemo("Matpel 1"), + ], + "3 Matpel": [ + getCourseMemo("Matpel 3"), + getCourseMemo("Matpel 2"), + getCourseMemo("Matpel 1"), + ], + "4 Escolta": [ + getCourseMemo("Sup. Escolta"), + getCourseMemo("Matpel 3"), + getCourseMemo("Matpel 2"), + getCourseMemo("Matpel 1"), + ], + "MD, 2 Matpel": [ + getCourseMemo("Matpel 2"), + getCourseMemo("Matpel 1"), + getCourseMemo("Manejo Defensivo"), + ], + "3 4x4": [ + getCourseMemo("4x4"), + getCourseMemo("Mecanica Basica"), + getCourseMemo("Manejo Defensivo"), + ], + "2 4x4": [ + getCourseMemo("4x4"), + getCourseMemo("Manejo Defensivo"), + ], + }; +} + +export function RegisterPresets(props: {disableCreation: boolean, onAdd: (v: [number, string]) => void}) { let datePicker: HTMLInputElement | undefined; + const [selectedPreset, setSelectedPreset] = createSignal("None"); + const [error, setError] = createSignal(""); + const presets = genPresets(); + + const add = () => { + if (datePicker === undefined) { + return; + } + const date = datePicker.value; + const preset = selectedPreset(); + + if (date === "") { + setError("Selecciona una fecha"); + setTimeout(() => setError(""), 5000); + return; + } + if (preset === "None") { + setError("Selecciona un preset"); + setTimeout(() => setError(""), 5000); + return; + } + + const presetIds = presets[preset]; + const currentDate = new Date(date); + for (const courseMemo of presetIds) { + // Get course and course duration from the memo + const course = courseMemo(); + if (course === null) { + setError(`Un curso no existe. Error fatal. (${preset})`); + return; + } + + const courseId = course.course_id; + const courseDuration = course.course_days_amount; + const dateYYYYMMDD = currentDate.toISOString().split("T")[0]; + + // Add + props.onAdd([courseId, dateYYYYMMDD]); + + // Substract current date for the next course + currentDate.setDate(currentDate.getDate() - courseDuration); + } + + setSelectedPreset("None"); + }; return ( <>
-

Las fechas se colocan automáticamente según la duración del curso.

+

Las fechas se colocan automáticamente según la duración del curso y su jeraquía.


- - - - - - + + {(key) => ( + setSelectedPreset(key as PresetName)} + text={key} + /> + )} +
@@ -28,13 +115,22 @@ export function RegisterPresets() {
- +
+ + +

+ {error()}  +

+
); } diff --git a/frontend/src/certs/NewRegister/RegisterPreview.tsx b/frontend/src/certs/NewRegister/RegisterPreview.tsx index c32066d..2085325 100644 --- a/frontend/src/certs/NewRegister/RegisterPreview.tsx +++ b/frontend/src/certs/NewRegister/RegisterPreview.tsx @@ -21,7 +21,7 @@ export function RegisterPreview(props: {selections: Array<[number, string]>, per const result = await createRegisters(registers); if (result === null) { - console.log("Success"); + console.log("Create register: success"); } else { console.log(`error. ${result}`); } @@ -54,7 +54,7 @@ export function RegisterPreview(props: {selections: Array<[number, string]>, per function Register(props: {courseId: number, date: string, onDelete: (v: number) => void}) { const courseName = () => { const courses = allCourses(); - return courses.find((course) => course.course_id === props.courseId)?.course_name ?? "!"; + return courses.find((course) => course.course_id === props.courseId)?.course_name ?? `Curso invalido! (${props.courseId})`; }; return ( diff --git a/frontend/src/certs/NewRegister/SearchableSelect.tsx b/frontend/src/certs/NewRegister/SearchableSelect.tsx index 621a888..6bfdac5 100644 --- a/frontend/src/certs/NewRegister/SearchableSelect.tsx +++ b/frontend/src/certs/NewRegister/SearchableSelect.tsx @@ -30,8 +30,9 @@ export function SearchableSelect(props: { }); createEffect(() => { - // Makes reactivity happen - console.log(props.count); + // Makes reactivity happen, don't remove + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const _count = props.count; setFilter(""); setSelected(null); diff --git a/frontend/src/certs/NewRegister/index.tsx b/frontend/src/certs/NewRegister/index.tsx index d99cb71..2d81ac5 100644 --- a/frontend/src/certs/NewRegister/index.tsx +++ b/frontend/src/certs/NewRegister/index.tsx @@ -12,7 +12,7 @@ export function NewRegister(props: { personId: number | null, onSuccess: () => void, }) { - const [active, setActive] = createSignal("Manual"); + const [active, setActive] = createSignal("Presets"); const [selections, setSelections] = createSignal>([]); const onRegister = () => { @@ -29,7 +29,10 @@ export function NewRegister(props: {
- + setSelections((x) => [...x, v])} + disableCreation={props.personId === null} + /> setCount((x) => x + 1)} /> diff --git a/frontend/src/components/Chip.tsx b/frontend/src/components/Chip.tsx index 3aa48d5..e55f487 100644 --- a/frontend/src/components/Chip.tsx +++ b/frontend/src/components/Chip.tsx @@ -1,7 +1,18 @@ -export function Chip(props: {text: string}) { +export function Chip(props: {text: string, selected: boolean, select: () => void}) { + const selectedClasses = () => { + if (props.selected) { + return "bg-c-surface-variant text-c-on-surface-variant shadow"; + } else { + return ""; + } + }; + return ( -
{props.text}
diff --git a/frontend/src/utils/allCourses.ts b/frontend/src/utils/allCourses.ts index f88b4bf..7397973 100644 --- a/frontend/src/utils/allCourses.ts +++ b/frontend/src/utils/allCourses.ts @@ -1,4 +1,4 @@ -import { createSignal } from "solid-js"; +import { Accessor, createMemo, createSignal } from "solid-js"; import { Course } from "../types/Course"; type CourseMap = {[k: number]: Course}; @@ -17,8 +17,17 @@ export const [courseMap, setCourseMap] = createSignal({}); for (const course of data) { map[course.course_id] = course; } - console.log("course map", map); setCourseMap(map); }); })(); +export function getCourseMemo(name: string): Accessor { + return createMemo(() => { + const course = allCourses().find((course) => course.course_name === name); + if (course) { + return course; + } + return null; + }); +} +