Skip to content
Merged
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
5 changes: 4 additions & 1 deletion client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import lesson from "src/entities/lesson";
import studentKlass from "src/entities/student-klass";
import student from "src/entities/student";
import teacher from "src/entities/teacher";
import transportation from 'src/entities/transportation';
import studentKlassesReport from "src/entities/student-klasses-report";
import reportMonth from "src/entities/report-month";
import teacherReportStatus from "src/entities/teacher-report-status";
Expand Down Expand Up @@ -64,7 +65,7 @@ import paymentTrack from '@shared/components/common-entities/payment-track';
import yemotCall from '@shared/components/common-entities/yemot-call';

import { isShowUsersData, isEditPagesData, isEditPaymentTracksData, isAdmin } from "@shared/utils/permissionsUtil";
import { isLessonSignature, isOnlyInLessonReport, isTeacherView } from 'src/utils/appPermissions';
import { isLessonSignature, isOnlyInLessonReport, isTeacherView, isTransportation } from 'src/utils/appPermissions';
import YemotSimulator from "@shared/components/views/YemotSimulator";
import { RegisterPage } from '@shared/components/layout/RegisterPage';
import { LoginPage } from '@shared/components/layout/LoginPage';
Expand Down Expand Up @@ -104,6 +105,7 @@ import PermContactCalendarIcon from '@mui/icons-material/PermContactCalendar';
import MonetizationOnIcon from '@mui/icons-material/MonetizationOn';
import LocalAtmIcon from '@mui/icons-material/LocalAtm';
import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings';
import DirectionsBusIcon from '@mui/icons-material/DirectionsBus';

const i18nProvider = getI18nProvider(domainTranslations);

Expand Down Expand Up @@ -156,6 +158,7 @@ const App = () => (
<Route path="student-attendance" element={<StudentAttendanceList />} />
</Resource>
<Resource name="student_klass" {...studentKlass} options={{ menuGroup: 'data' }} icon={WorkspacesIcon} />
{(isTransportation(permissions) || isAdmin(permissions)) && <Resource name="transportation" {...transportation} options={{ menuGroup: 'data' }} icon={DirectionsBusIcon} />}
<Resource name="att_report_with_report_month" {...attReportWithReportMonth} options={{ menuGroup: 'data' }} icon={ViewListIcon} />
<Resource name="grade" {...grade} options={{ menuGroup: 'data' }} icon={GradingIcon} />
<Resource name="known_absence" {...knownAbsence} options={{ menuGroup: 'data' }} icon={PlaylistRemoveIcon} />
Expand Down
9 changes: 9 additions & 0 deletions client/src/domainTranslations.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ export default {
displayName: 'שם לתעודה'
}
},
transportation: {
name: 'הסעה |||| הסעות',
fields: {
...generalResourceFieldsTranslation,
key: 'שילוט',
departureTime: 'שעת יציאה',
description: 'תיאור נסיעה',
}
},
text: {
name: 'הודעה |||| הודעות - טבלת אדמין',
fields: {
Expand Down
93 changes: 93 additions & 0 deletions client/src/entities/transportation.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {
DateField,
DateTimeInput,
ReferenceField,
required,
TextField,
TextInput,
NumberInput,
maxLength,
SelectField,
} 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";
import CommonTimeInput from "@shared/components/fields/CommonTimeInput";

const filters = [
...commonAdminFilters,
<CommonAutocompleteInput source="year" choices={yearChoices} alwaysOn />,
<TextInput source="key:$cont" label="שילוט" />,
<TextInput source="description:$cont" label="תיאור" />,
];

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="key" />
<TextField source="departureTime" />
<TextField source="description" />
<SelectField source="year" choices={yearChoices} />
{isAdmin && <DateField showDate showTime source="createdAt" />}
{isAdmin && <DateField showDate showTime source="updatedAt" />}
</CommonDatagrid>
);
};

const Inputs = ({ isCreate, isAdmin }) => {
const unique = useUnique();
return (
<>
{!isCreate && isAdmin && <TextInput source="id" disabled />}
{isAdmin && (
<CommonReferenceInput
source="userId"
reference="user"
validate={required()}
/>
)}

<NumberInput source="key" validate={[required(), unique()]} />
<CommonTimeInput source="departureTime" validate={[required()]} />
<CommonAutocompleteInput
source="year"
choices={yearChoices}
validate={required()}
defaultValue={defaultYearFilter.year}
/>

<TextInput source="description" multiline validate={maxLength(1000)} />

{!isCreate && isAdmin && <DateTimeInput source="createdAt" disabled />}
{!isCreate && isAdmin && <DateTimeInput source="updatedAt" disabled />}
</>
);
};

const Representation = 'key';

const importer = {
fields: ["key", "departureTime", "description"],
};

const entity = {
Datagrid,
Inputs,
Representation,
filters,
filterDefaultValues,
importer,
};

export default getResourceComponents(entity);
4 changes: 4 additions & 0 deletions client/src/utils/appPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const appPermissions = {
lessonSignature: 'lessonSignature',
approvedAbsencesBulk: 'approvedAbsencesBulk',
teacherView: 'teacherView',
transportation: 'transportation',
};

export const isScannerUpload = (permissions) => hasPermissionLogic(permissions, appPermissions.scannerUpload);
Expand Down Expand Up @@ -39,3 +40,6 @@ export const useIsApprovedAbsencesBulk = () => useHasPermission(appPermissions.a
export const isTeacherView = (permissions) => hasPermissionLogic(permissions, appPermissions.teacherView);
export const useIsTeacherView = () => useHasPermission(appPermissions.teacherView);

export const isTransportation = (permissions) => hasPermissionLogic(permissions, appPermissions.transportation);
export const useIsTransportation = () => useHasPermission(appPermissions.transportation);

73 changes: 73 additions & 0 deletions server/src/db/entities/Transportation.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
Column,
CreateDateColumn,
Entity,
Index,
JoinColumn,
PrimaryGeneratedColumn,
UpdateDateColumn,
BeforeInsert,
BeforeUpdate,
} from 'typeorm';
import { IHasUserId } from '@shared/base-entity/interface';
import { User } from 'src/db/entities/User.entity';
import { IsOptional } 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";

@Index('transportations_users_idx', ['userId'], {})
@Index(['userId', 'key', 'year'], { unique: true })
@Entity('transportations')
export class Transportation implements IHasUserId {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

כדאי להוסיף פה fill default year

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ואז יצירת הסעה חדשה לא יצטרכו להכניס שנה?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

כן, וגם יהיה אפשר להוריד את זה מהמערך של הimporter, תראי איך זה בטבלאות אחרות

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

בשביל שזה יעבוד צריך לשים מעל זה @beforeCreate @beforeUpdate

@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;

@IsOptional({ groups: [CrudValidationGroups.UPDATE] })
@NumberType
@IsNumber({ maxDecimalPlaces: 0 }, { always: true })
@IsUniqueCombination(['userId', 'year'], [Transportation, User], {
always: true,
})
@IsNotEmpty({ groups: [CrudValidationGroups.CREATE] })
@Column('int', { name: 'key' })
key: number;

@IsOptional({ groups: [CrudValidationGroups.UPDATE] })
@StringType
@MaxLength(500, { always: true })
@IsNotEmpty({ groups: [CrudValidationGroups.CREATE] })
@IsOptional({ always: true })
@StringType
@MaxLength(255, { always: true })
@Column('varchar', { name: 'departure_time', nullable: true, length: 255 })
departureTime: string | null;

@IsOptional({ always: true })
@StringType
@MaxLength(1000, { always: true })
@Column('varchar', { name: 'description', nullable: true, length: 1000 })
description: string | null;

@CreateDateColumn({ name: 'created_at', type: 'timestamp' })
createdAt: Date;

@UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
updatedAt: Date;

@JoinColumn([{ name: 'user_id', referencedColumnName: 'id' }])
user: User;
}
9 changes: 5 additions & 4 deletions server/src/db/entities/User.entity.ts

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

השינוי הזה לא באמת נצרך

Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import { Teacher } from "src/db/entities/Teacher.entity";
export class User extends BaseUser {
// @OneToMany(() => Grade, (grades) => grades.user)
grades: Grade[];

// @OneToMany(() => KlassType, (klassTypes) => klassTypes.user)
klassTypes: KlassType[];

// @OneToMany(() => KnownAbsence, (knownAbsences) => knownAbsences.user)
knownAbsences: KnownAbsence[];

// @OneToMany(() => Student, (students) => students.user)
students: Student[];

// @OneToMany(() => Teacher, (teachers) => teachers.user)
teachers: Teacher[];

}
2 changes: 2 additions & 0 deletions server/src/entities.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { StudentSpeciality } from "./db/view-entities/StudentSpeciality.entity";
import { AttendanceName } from "./db/entities/AttendanceName.entity";
import reportGroupConfig from "./entity-modules/report-group.config";
import reportGroupSessionConfig from "./entity-modules/report-group-session.config";
import transportationConfig from './entity-modules/transportation.config';

@Module({
imports: [
Expand Down Expand Up @@ -86,6 +87,7 @@ import reportGroupSessionConfig from "./entity-modules/report-group-session.conf
BaseEntityModule.register({ entity: GradeEffectByUser }),
BaseEntityModule.register({ entity: AbsCountEffectByUser }),
BaseEntityModule.register({ entity: LessonKlassName }),
BaseEntityModule.register(transportationConfig),
]
})
export class EntitiesModule { }
21 changes: 21 additions & 0 deletions server/src/entity-modules/transportation.config.ts
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 { Transportation } from 'src/db/entities/Transportation.entity';

function getConfig(): BaseEntityModuleOptions {
return {
entity: Transportation,
exporter: {
getExportHeaders(): IHeader[] {
return [
{ value: 'key', label: 'שילוט' },
{ value: 'year', label: 'שנה' },
{ value: 'departureTime', label: 'שעת יציאה' },
{ value: 'description', label: 'תיאור נסיעה' },
];
},
},
};
}

export default getConfig();