Skip to content

Commit

Permalink
Season code now maps to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeffer committed Nov 23, 2024
1 parent 4344d9a commit 0c1b260
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,33 @@ import {
import {MyCreate} from '@/components/Admin/custom/MyCreate'
import {MyDateTimeInput} from '@/components/Admin/custom/MyDateTimeInput'

export const SemesterCreate: FC = () => (
<MyCreate>
<SimpleForm>
<ReferenceInput source="competition" reference="competition/competition">
<SelectInput fullWidth validate={required()} />
</ReferenceInput>
<NumberInput source="year" helperText="ročník súťaže, napr. 48" fullWidth validate={required()} />
<NumberInput source="season_code" fullWidth validate={required()} />
<TextInput source="school_year" helperText="napr. 2023/2024" fullWidth />
<MyDateTimeInput source="start" fullWidth validate={required()} />
<MyDateTimeInput source="end" fullWidth validate={required()} />
<TextInput source="additional_name" fullWidth />
{/* nechavam viditelne disabled nech sa rozhodneme, co s tym. BE nam posiela ID,
export const SemesterCreate: FC = () => {
const season_code_strings = [
{id: 0, name: 'Zimný'},
{id: 1, name: 'Letný'},
{id: 2, name: 'Iný'},
]

return (
<MyCreate>
<SimpleForm>
<ReferenceInput source="competition" reference="competition/competition">
<SelectInput fullWidth validate={required()} />
</ReferenceInput>
<NumberInput source="year" helperText="ročník súťaže, napr. 48" fullWidth validate={required()} />
<SelectInput source="season_code" choices={season_code_strings} fullWidth validate={required()} />
<TextInput source="school_year" helperText="napr. 2023/2024" fullWidth />
<MyDateTimeInput source="start" fullWidth validate={required()} />
<MyDateTimeInput source="end" fullWidth validate={required()} />
<TextInput source="additional_name" fullWidth />
{/* nechavam viditelne disabled nech sa rozhodneme, co s tym. BE nam posiela ID,
neviem, ci vieme updatnut cely objekt tym, ze ho pribalim, ako v EventEdit...
uvidime, ci ten field vobec potrebujeme */}
<NumberInput source="registration_link" fullWidth disabled />
<ReferenceArrayInput source="late_tags" reference="competition/late-tag">
<CheckboxGroupInput />
</ReferenceArrayInput>
</SimpleForm>
</MyCreate>
)
<NumberInput source="registration_link" fullWidth disabled />
<ReferenceArrayInput source="late_tags" reference="competition/late-tag">
<CheckboxGroupInput />
</ReferenceArrayInput>
</SimpleForm>
</MyCreate>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,43 @@ import {
import {MyDateTimeInput} from '@/components/Admin/custom/MyDateTimeInput'
import {MyEdit} from '@/components/Admin/custom/MyEdit'

export const SemesterEdit: FC = () => (
<MyEdit
transform={(record) => {
// automaticky sa na BE posiela cely record, ale BE read_only (aj neexistujuce) fieldy ignoruje
// radsej z payloadu odstranime aspon sety
delete record.publication_set
delete record.series_set
return record
}}
>
<TabbedForm>
<FormTab label="general">
<ReferenceInput source="competition" reference="competition/competition">
<SelectInput fullWidth validate={required()} />
</ReferenceInput>
<NumberInput source="year" helperText="ročník súťaže, napr. 48" fullWidth />
<NumberInput source="season_code" fullWidth />
<TextInput source="school_year" helperText="napr. 2023/2024" fullWidth />
<MyDateTimeInput source="start" fullWidth />
<MyDateTimeInput source="end" fullWidth />
<TextInput source="additional_name" fullWidth />
{/* nechavam viditelne disabled nech sa rozhodneme, co s tym. BE nam posiela ID,
neviem, ci vieme updatnut cely objekt tym, ze ho pribalim, ako v EventEdit...
uvidime, ci ten field vobec potrebujeme */}
<NumberInput source="registration_link" fullWidth disabled />
<ReferenceArrayInput source="late_tags" reference="competition/late-tag">
<CheckboxGroupInput />
</ReferenceArrayInput>
</FormTab>
</TabbedForm>
</MyEdit>
)
export const SemesterEdit: FC = () => {
const season_code_strings = [
{id: 0, name: 'Zimný'},
{id: 1, name: 'Letný'},
{id: 2, name: 'Iný'},
]

return (
<MyEdit
transform={(record) => {
// automaticky sa na BE posiela cely record, ale BE read_only (aj neexistujuce) fieldy ignoruje
// radsej z payloadu odstranime aspon sety
delete record.publication_set
delete record.series_set
return record
}}
>
<TabbedForm>
<FormTab label="general">
<ReferenceInput source="competition" reference="competition/competition">
<SelectInput fullWidth validate={required()} />
</ReferenceInput>
<NumberInput source="year" helperText="ročník súťaže, napr. 48" fullWidth />
<SelectInput source="season_code" choices={season_code_strings} fullWidth validate={required()} />
<TextInput source="school_year" helperText="napr. 2023/2024" fullWidth />
<MyDateTimeInput source="start" fullWidth />
<MyDateTimeInput source="end" fullWidth />
<TextInput source="additional_name" fullWidth />
{/* nechavam viditelne disabled nech sa rozhodneme, co s tym. BE nam posiela ID,
neviem, ci vieme updatnut cely objekt tym, ze ho pribalim, ako v EventEdit...
uvidime, ci ten field vobec potrebujeme */}
<NumberInput source="registration_link" fullWidth disabled />
<ReferenceArrayInput source="late_tags" reference="competition/late-tag">
<CheckboxGroupInput />
</ReferenceArrayInput>
</FormTab>
</TabbedForm>
</MyEdit>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,46 @@ import {

import {DateTimeField} from '@/components/Admin/custom/DateTimeField'

export const SemesterList: FC = () => (
<List>
<Datagrid rowClick="show">
<ReferenceField source="competition" reference="competition/competition" link={false} />
<NumberField source="year" />
<NumberField source="season_code" />
<TextField source="school_year" />
<DateTimeField source="start" />
<DateTimeField source="end" />
<BooleanField source="complete" />
<TextField source="additional_name" />
<NumberField source="registration_link" />
<FunctionField<RaRecord>
source="series_set"
label="Series count"
render={(record) => record && <span>{record['series_set'].length}</span>}
/>
<FunctionField<RaRecord>
source="publication_set"
label="Publication count"
render={(record) => record && <span>{record['publication_set'].length}</span>}
/>
<FunctionField<RaRecord>
source="late_tags"
label="Late tags count"
render={(record) => record && <span>{record['late_tags'].length}</span>}
/>
</Datagrid>
</List>
)
export const SemesterList: FC = () => {
const season_code_strings = [
{id: 0, name: 'Zimný'},
{id: 1, name: 'Letný'},
{id: 2, name: 'Iný'},
]

return (
<List>
<Datagrid rowClick="show">
<ReferenceField source="competition" reference="competition/competition" link={false} />
<NumberField source="year" />
<FunctionField
source="season_code"
render={(record) => {
return `${season_code_strings[record.season_code].name ?? ''}`
}}
/>
<TextField source="school_year" />
<DateTimeField source="start" />
<DateTimeField source="end" />
<BooleanField source="complete" />
<TextField source="additional_name" />
<NumberField source="registration_link" />
<FunctionField<RaRecord>
source="series_set"
label="Series count"
render={(record) => record && <span>{record['series_set'].length}</span>}
/>
<FunctionField<RaRecord>
source="publication_set"
label="Publication count"
render={(record) => record && <span>{record['publication_set'].length}</span>}
/>
<FunctionField<RaRecord>
source="late_tags"
label="Late tags count"
render={(record) => record && <span>{record['late_tags'].length}</span>}
/>
</Datagrid>
</List>
)
}
134 changes: 74 additions & 60 deletions src/components/Admin/resources/competition/semester/SemesterShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ArrayField,
BooleanField,
Datagrid,
FunctionField,
NumberField,
ReferenceArrayField,
ReferenceField,
Expand All @@ -16,64 +17,77 @@ import {DateTimeField} from '@/components/Admin/custom/DateTimeField'
import {MyShow} from '@/components/Admin/custom/MyShow'
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField'

export const SemesterShow: FC = () => (
<MyShow>
<TabbedShowLayout>
<Tab label="general">
<SimpleShowLayout>
<ReferenceField source="competition" reference="competition/competition" link="show" />
<NumberField source="year" />
<NumberField source="season_code" />
<TextField source="school_year" />
<DateTimeField source="start" />
<DateTimeField source="end" />
<BooleanField source="complete" />
<TextField source="additional_name" />
<NumberField source="registration_link" />
</SimpleShowLayout>
</Tab>
<Tab label="series">
<SimpleShowLayout>
<ArrayField source="series_set">
<Datagrid rowClick={(id) => `/competition/series/${id}/show`}>
<DateTimeField source="deadline" />
<TextField source="order" />
<ArrayField source="problems">
<Datagrid>
<TruncatedTextField source="text" maxTextWidth={50} />
</Datagrid>
</ArrayField>
</Datagrid>
</ArrayField>
</SimpleShowLayout>
</Tab>
<Tab label="publications">
<SimpleShowLayout>
<ArrayField source="publication_set">
<Datagrid>
<TextField source="name" />
<TextField source="file" />
<ReferenceField source="publication_type" reference="competition/publication-type" link="show">
export const SemesterShow: FC = () => {
const season_code_strings = [
{id: 0, name: 'Zimný'},
{id: 1, name: 'Letný'},
{id: 2, name: 'Iný'},
]

return (
<MyShow>
<TabbedShowLayout>
<Tab label="general">
<SimpleShowLayout>
<ReferenceField source="competition" reference="competition/competition" link="show" />
<NumberField source="year" />
<FunctionField
source="season_code"
render={(record) => {
return `${season_code_strings[record.season_code].name ?? ''}`
}}
/>
<TextField source="school_year" />
<DateTimeField source="start" />
<DateTimeField source="end" />
<BooleanField source="complete" />
<TextField source="additional_name" />
<NumberField source="registration_link" />
</SimpleShowLayout>
</Tab>
<Tab label="series">
<SimpleShowLayout>
<ArrayField source="series_set">
<Datagrid rowClick={(id) => `/competition/series/${id}/show`}>
<DateTimeField source="deadline" />
<TextField source="order" />
<ArrayField source="problems">
<Datagrid>
<TruncatedTextField source="text" maxTextWidth={50} />
</Datagrid>
</ArrayField>
</Datagrid>
</ArrayField>
</SimpleShowLayout>
</Tab>
<Tab label="publications">
<SimpleShowLayout>
<ArrayField source="publication_set">
<Datagrid>
<TextField source="name" />
<TextField source="file" />
<ReferenceField source="publication_type" reference="competition/publication-type" link="show">
<TextField source="name" />
</ReferenceField>
<NumberField source="event" />
<NumberField source="order" />
</Datagrid>
</ArrayField>
</SimpleShowLayout>
</Tab>
<Tab label="late tags">
<SimpleShowLayout>
<ReferenceArrayField source="late_tags" reference="competition/late-tag">
<Datagrid>
<TextField source="name" />
</ReferenceField>
<NumberField source="event" />
<NumberField source="order" />
</Datagrid>
</ArrayField>
</SimpleShowLayout>
</Tab>
<Tab label="late tags">
<SimpleShowLayout>
<ReferenceArrayField source="late_tags" reference="competition/late-tag">
<Datagrid>
<TextField source="name" />
<TextField source="slug" />
<TextField source="upper_bound" />
<BooleanField source="can_resubmit" />
</Datagrid>
</ReferenceArrayField>
</SimpleShowLayout>
</Tab>
</TabbedShowLayout>
</MyShow>
)
<TextField source="slug" />
<TextField source="upper_bound" />
<BooleanField source="can_resubmit" />
</Datagrid>
</ReferenceArrayField>
</SimpleShowLayout>
</Tab>
</TabbedShowLayout>
</MyShow>
)
}

0 comments on commit 0c1b260

Please sign in to comment.