Repository navigation
add event types table and link to known absences #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4f7076d
add event types table and link to known absences
yael-miller 6b81835
add absence types and quotas logic with dynamic labels
yael-miller 21c9a82
Rename Event entity to AbsenceType
yael-miller dc4ee0b
rename variables
yael-miller 151ec23
absence_type
yael-miller 97f51f8
migration: create AbsenceType and rename permission to absenceType
yael-miller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,87 @@ | ||
| import { | ||
| DateField, | ||
| DateTimeInput, | ||
| ReferenceField, | ||
| required, | ||
| TextField, | ||
| TextInput, | ||
| NumberInput, | ||
| maxLength, | ||
| SelectField, | ||
| ArrayInput, | ||
| SimpleFormIterator, | ||
| } from "react-admin"; | ||
| import { CommonDatagrid } from "@shared/components/crudContainers/CommonList"; | ||
| import { getResourceComponents } from "@shared/components/crudContainers/CommonEntity"; | ||
| import CommonReferenceInput from "@shared/components/fields/CommonReferenceInput"; | ||
| import { useUnique } from "@shared/utils/useUnique"; | ||
| import { commonAdminFilters } from "@shared/components/fields/PermissionFilter"; | ||
| import { defaultYearFilter, yearChoices } from "@shared/utils/yearFilter"; | ||
| import CommonAutocompleteInput from "@shared/components/fields/CommonAutocompleteInput"; | ||
|
|
||
| const filters = [ | ||
| ...commonAdminFilters, | ||
| <CommonAutocompleteInput source="year" choices={yearChoices} alwaysOn />, | ||
| <TextInput source="name:$cont" />, | ||
| ]; | ||
|
|
||
| const filterDefaultValues = { | ||
| year: defaultYearFilter.year, | ||
| }; | ||
|
|
||
| const Datagrid = ({ isAdmin, children, ...props }) => { | ||
| return ( | ||
| <CommonDatagrid {...props}> | ||
| {children} | ||
| {isAdmin && <TextField source="id" />} | ||
| {isAdmin && <ReferenceField source="userId" reference="user" />} | ||
|
|
||
| <TextField source="name" /> | ||
| <TextField source="quota" /> | ||
| <SelectField source="year" choices={yearChoices} /> | ||
|
|
||
| <TextField source="requiredLabels"/> | ||
|
|
||
| {isAdmin && <DateField source="createdAt" disabled />} | ||
| {isAdmin && <DateField source="updatedAt" disabled />} | ||
| </CommonDatagrid> | ||
| ); | ||
| }; | ||
|
|
||
| const Inputs = ({ isCreate, isAdmin }) => { | ||
| const unique = useUnique(); | ||
| return ( | ||
| <> | ||
| {!isCreate && isAdmin && <TextInput source="id" disabled />} | ||
| {isAdmin && ( <CommonReferenceInput source="userId" reference="user" validate={required()}/> )} | ||
| <TextInput source="name" validate={[required(), maxLength(100)]}/> | ||
| <NumberInput source="quota" step={1} validate={[required()]} /> | ||
| <CommonAutocompleteInput source="year" choices={yearChoices} validate={required()} defaultValue={defaultYearFilter.year} /> | ||
| <ArrayInput source="requiredLabels"> | ||
| <SimpleFormIterator> | ||
| <TextInput fullWidth /> | ||
| </SimpleFormIterator> | ||
| </ArrayInput> | ||
|
|
||
| {!isCreate && isAdmin && <DateTimeInput source="createdAt" disabled />} | ||
| {!isCreate && isAdmin && <DateTimeInput source="updatedAt" disabled />} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| const Representation = 'name'; | ||
|
|
||
| const importer = { | ||
| fields: ["name", "quota", "requiredLabels", "year"], | ||
| }; | ||
|
|
||
| const entity = { | ||
| Datagrid, | ||
| Inputs, | ||
| Representation, | ||
| filters, | ||
| filterDefaultValues, | ||
| importer, | ||
| }; | ||
|
|
||
| export default getResourceComponents(entity); |
This file contains hidden or 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 hidden or 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 hidden or 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,67 @@ | ||
| import { | ||
| Column, | ||
| Entity, | ||
| Index, | ||
| JoinColumn, | ||
| PrimaryGeneratedColumn, | ||
| BeforeInsert, | ||
| BeforeUpdate, | ||
| } from 'typeorm'; | ||
| import { IHasUserId } from '@shared/base-entity/interface'; | ||
| import { User } from 'src/db/entities/User.entity'; | ||
| import { IsOptional, Min } from 'class-validator'; | ||
| import { CrudValidationGroups } from '@dataui/crud'; | ||
| import { IsNotEmpty, IsUniqueCombination, MaxLength, IsNumber } from '@shared/utils/validation/class-validator-he'; | ||
| import { StringType, NumberType } from '@shared/utils/entity/class-transformer'; | ||
| import { fillDefaultYearValue } from "@shared/utils/entity/year.util"; | ||
| import { CreatedAtColumn, UpdatedAtColumn } from '@shared/utils/entity/column-types.util'; | ||
|
|
||
| @Index('absenceTypes_users_idx', ['userId'], {}) | ||
| @Index(['userId', 'name', 'year'], { unique: true }) | ||
| @Entity('absenceTypes') | ||
| export class AbsenceType implements IHasUserId { | ||
| @BeforeInsert() | ||
| @BeforeUpdate() | ||
| async fillFields() { | ||
| fillDefaultYearValue(this); | ||
| } | ||
|
|
||
| @PrimaryGeneratedColumn({ type: 'int', name: 'id' }) | ||
| id: number; | ||
|
|
||
| @Column('int', { name: 'user_id' }) | ||
| userId: number; | ||
|
|
||
| @Column({ nullable: true }) | ||
| year: number; | ||
|
|
||
| @IsNotEmpty({ groups: [CrudValidationGroups.CREATE] }) | ||
| @StringType | ||
| @MaxLength(100, { always: true }) | ||
| @Column('varchar', { name: 'name', length: 100 }) | ||
| name: string; | ||
|
|
||
| @IsNumber({ maxDecimalPlaces: 1 }, { always: true }) | ||
| @IsNotEmpty({ groups: [CrudValidationGroups.CREATE] }) | ||
| @Min(0, { always: true }) | ||
| @NumberType | ||
| @Column('decimal', { name: 'quota', precision: 5, scale: 1 }) | ||
| quota: number; | ||
|
|
||
| @IsOptional({ always: true }) | ||
| @Column({ | ||
| type: 'simple-array', | ||
| name: 'required_labels', | ||
| nullable: true, | ||
| }) | ||
| requiredLabels: string[] | null; | ||
|
|
||
| @CreatedAtColumn() | ||
| createdAt: Date; | ||
|
|
||
| @UpdatedAtColumn() | ||
| updatedAt: Date; | ||
|
|
||
| @JoinColumn([{ name: 'user_id', referencedColumnName: 'id' }]) | ||
| user: User; | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| import { BaseEntityModuleOptions } from '@shared/base-entity/interface'; | ||
| import { IHeader } from '@shared/utils/exporter/types'; | ||
| import { AbsenceType } from 'src/db/entities/AbsenceType.entity'; | ||
|
|
||
| function getConfig(): BaseEntityModuleOptions { | ||
| return { | ||
| entity: AbsenceType, | ||
| exporter: { | ||
| getExportHeaders(): IHeader[] { | ||
| return [ | ||
| { value: 'name', label: 'סוג חיסור' }, | ||
| { value: 'year', label: 'שנה' }, | ||
| { value: 'quota', label: 'מכסה שנתית' }, | ||
| { value: 'requiredLabels', label: 'שדות חובה לדיווח' }, | ||
| ]; | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| export default getConfig(); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.