-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from ladesa-ro/refactor/use-form-context-ever…
…ywhere feat: turma: split serie and turma and make it work propertly; enhancements in the ui-autocomplete-api component
- Loading branch information
Showing
13 changed files
with
307 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ export type TurmaFormOutput = { | |
ambientePadraoAula: { id: string } | null; | ||
|
||
periodo: string; | ||
|
||
_?: any; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
components/Section/Turmas/Form/Fields/Periodo/Bruto/Bruto.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script setup lang="ts"> | ||
import { useField } from 'vee-validate'; | ||
defineProps({ | ||
disabled: { | ||
type: Boolean, | ||
required: false, | ||
}, | ||
isLoading: { | ||
type: Boolean, | ||
required: false, | ||
}, | ||
}); | ||
const { value: modoPeriodo } = useField('_.modoPeriodo'); | ||
onMounted(() => { | ||
modoPeriodo.value = 'periodo'; | ||
}); | ||
</script> | ||
|
||
<template> | ||
<VVTextField | ||
type="text" | ||
name="periodo" | ||
label="Período" | ||
:disabled="isLoading || disabled" | ||
placeholder="1° Período, 2° Período, 3° Período..." | ||
v-bind="$attrs" | ||
/> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
components/Section/Turmas/Form/Fields/Periodo/SerieLetra/SerieLetra.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<script setup lang="ts"> | ||
import { useField } from 'vee-validate'; | ||
import { useSplittedSerieLetra } from './composables/useSplittedSerieLetra'; | ||
type Props = { | ||
disabled?: boolean; | ||
isLoading?: boolean; | ||
} | ||
defineProps<Props>(); | ||
const { value: formPeriodo } = useField<string>('periodo'); | ||
const { value: formSerie } = useField<string>('_.serie'); | ||
const { value: formLetra } = useField<string>('_.letra'); | ||
const { serie, letra } = useSplittedSerieLetra(formPeriodo); | ||
watch( | ||
[serie, letra], | ||
([serie, letra]) => { | ||
formSerie.value = serie; | ||
formLetra.value = letra; | ||
}, | ||
{ immediate: true } | ||
); | ||
const { value: modoPeriodo } = useField('_.modoPeriodo'); | ||
onMounted(() => { | ||
requestIdleCallback(() => { | ||
modoPeriodo.value = 'serie-letra'; | ||
}); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div class="grid grid-cols-[2fr,1fr] gap-4"> | ||
<VVTextField | ||
type="text" | ||
name="_.serie" | ||
:disabled="isLoading || disabled" | ||
v-model="serie" | ||
label="Série" | ||
placeholder="1°, 2°, 3°..." | ||
/> | ||
|
||
<VVTextField | ||
type="text" | ||
name="_.letra" | ||
:disabled="isLoading || disabled" | ||
label="Letra" | ||
v-model="letra" | ||
placeholder="A, B, C..." | ||
/> | ||
</div> | ||
</template> |
83 changes: 83 additions & 0 deletions
83
...onents/Section/Turmas/Form/Fields/Periodo/SerieLetra/composables/useSplittedSerieLetra.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
export const splitPeriodo = (periodo: string) => { | ||
const [serie, letra] = periodo.split(' '); | ||
|
||
return { | ||
serie, | ||
letra, | ||
}; | ||
}; | ||
|
||
export const joinPeriodo = (serie: string, letra: string) => { | ||
return `${serie.replace(/ /g, '')} ${letra.replace(/ /g, '')}`; | ||
}; | ||
|
||
const getModifiedSplitted = ( | ||
currentPeriodo: string, | ||
newSerie: string | null, | ||
newLetra: string | null | ||
) => { | ||
const currentSplitted = splitPeriodo(currentPeriodo); | ||
|
||
return { | ||
serie: newSerie !== null ? newSerie : currentSplitted.serie, | ||
letra: newLetra !== null ? newLetra : currentSplitted.letra, | ||
}; | ||
}; | ||
|
||
const getModifiedCombined = ( | ||
currentPeriodo: string, | ||
newSerie: string | null, | ||
newLetra: string | null | ||
) => { | ||
const { serie, letra } = getModifiedSplitted( | ||
currentPeriodo, | ||
newSerie, | ||
newLetra | ||
); | ||
|
||
return joinPeriodo(serie, letra); | ||
}; | ||
|
||
export const useSplittedSerieLetra = (periodo: Ref<string>) => { | ||
const splittedSerieLetra = computed(() => splitPeriodo(periodo.value)); | ||
|
||
const modify = (serie: string | null, letra: string | null) => { | ||
periodo.value = getModifiedCombined(unref(periodo), serie, letra); | ||
}; | ||
|
||
const modifySerie = (serie: string) => { | ||
return modify(serie, null); | ||
}; | ||
|
||
const modifyLetra = (letra: string) => { | ||
return modify(null, letra); | ||
}; | ||
|
||
const serie = computed({ | ||
get: () => { | ||
return unref(splittedSerieLetra).serie; | ||
}, | ||
|
||
set: (value) => { | ||
modifySerie(value); | ||
}, | ||
}); | ||
|
||
const letra = computed({ | ||
get: () => { | ||
return unref(splittedSerieLetra).letra; | ||
}, | ||
set: (value) => { | ||
modifyLetra(value); | ||
}, | ||
}); | ||
|
||
return { | ||
serie, | ||
letra, | ||
modify, | ||
modifyLetra, | ||
modifySerie, | ||
splittedSerieLetra, | ||
}; | ||
}; |
Oops, something went wrong.