diff --git a/src/components/schedule/table/table.component.ts b/src/components/schedule/table/table.component.ts index f1df375..162fbff 100644 --- a/src/components/schedule/table/table.component.ts +++ b/src/components/schedule/table/table.component.ts @@ -31,7 +31,9 @@ interface Dictionary { }) export class TableComponent implements OnChanges { + private isDisciplineWithWeeks: boolean = false; protected tableDataSource: MatTableDataSource = new MatTableDataSource([]); + private backupDisciplines: string[] = []; protected daysOfWeek: string[] = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота']; protected displayedColumns: string[] = ['pairNumber']; protected dataSource: ScheduleResponse[] = []; @@ -41,6 +43,11 @@ export class TableComponent implements OnChanges { @Input() startWeek!: Date; @Input() isLoad: boolean = false; + @Input() set disciplineWithWeeks(value: boolean) { + this.isDisciplineWithWeeks = value; + this.convertData(); + } + @Input() set data(schedule: ScheduleResponse[]) { this.dataSource = schedule; this.convertData(); @@ -68,17 +75,35 @@ export class TableComponent implements OnChanges { }; for (let k: number = 1; k < 7; k++) { - convertedData.data[k.toString()] = this.dataSource.filter(x => + let filteredData = this.dataSource.filter(x => x.pairNumber === i && x.dayOfWeek === k && - x.isEven === (this.currentWeek % 2 === 0) && - ( - x.isExcludedWeeks === undefined || - x.weeks === undefined || + x.isEven === (this.currentWeek % 2 === 0) + ); + + if (!this.isDisciplineWithWeeks) + filteredData = filteredData.filter(x => + x.isExcludedWeeks == undefined || + x.weeks == undefined || (x.isExcludedWeeks && (!x.weeks.includes(this.currentWeek))) || (!x.isExcludedWeeks && (x.weeks.includes(this.currentWeek))) - ) - ); + ); + + filteredData.forEach(x => { + if (this.isDisciplineWithWeeks) { + if (x.isExcludedWeeks != undefined && x.weeks != undefined) { + if (this.backupDisciplines[x.disciplineId]) + x.discipline = this.backupDisciplines[x.disciplineId]; + else + this.backupDisciplines[x.disciplineId] = x.discipline; + + x.discipline = `${(x.isExcludedWeeks ? 'кр.' : 'н.')} ${x.weeks.join(', ')} ${x.discipline}`; + } + } else if (this.backupDisciplines[x.disciplineId]) + x.discipline = this.backupDisciplines[x.disciplineId]; + }); + + convertedData.data[k.toString()] = filteredData; } tableData.push(convertedData); diff --git a/src/pages/schedule/schedule.component.html b/src/pages/schedule/schedule.component.html index c9f787f..c9c92ca 100644 --- a/src/pages/schedule/schedule.component.html +++ b/src/pages/schedule/schedule.component.html @@ -1,6 +1,18 @@ - - - + + + + + + + + + + + + + + Показать недели в дисциплине + diff --git a/src/pages/schedule/schedule.component.ts b/src/pages/schedule/schedule.component.ts index 127b129..64125c1 100644 --- a/src/pages/schedule/schedule.component.ts +++ b/src/pages/schedule/schedule.component.ts @@ -38,11 +38,12 @@ import {MatCheckbox} from "@angular/material/checkbox"; }) export class ScheduleComponent { - protected startWeek!: Date; + protected startWeek: Date; protected data: ScheduleResponse[] = []; protected startTerm: Date; protected isLoadTable: boolean = false; protected pairPeriods: PeriodTimes = {}; + protected disciplineWithWeeks: boolean = false; @ViewChild('tableHeader') childComponent!: TableHeaderComponent; @@ -50,6 +51,11 @@ export class ScheduleComponent { this.startTerm = new Date(1, 1, 1); this.startWeek = new Date(1, 1, 1); + let disciplineWithWeeksStorage = localStorage.getItem('disciplineWithWeeks'); + + if (disciplineWithWeeksStorage) + this.disciplineWithWeeks = disciplineWithWeeksStorage.toLowerCase() === 'true'; + api.pairPeriod().subscribe(date => { this.pairPeriods = date; }); @@ -122,4 +128,9 @@ export class ScheduleComponent { return result; } + + protected changeDisciplineWeeksView(checked: boolean) { + localStorage.setItem('disciplineWithWeeks', checked.toString()); + this.disciplineWithWeeks = checked; + } }