refactor: transfer the calculation of the current month to the parent component

This commit is contained in:
Polianin Nikita 2024-02-19 13:21:34 +03:00
parent 86934cecaa
commit b8a591c1ca
2 changed files with 21 additions and 7 deletions

View File

@ -6,7 +6,7 @@
Неделя: {{ startWeek | date:"shortDate" }} Неделя: {{ startWeek | date:"shortDate" }}
- -
{{ addDays(startWeek, 6) | date: "shortDate" }}  {{ addDays(startWeek, 6) | date: "shortDate" }} 
<span [matBadge]="currentWeek()" matBadgeOverlap="false"></span> <span [matBadge]="currentWeek" matBadgeOverlap="false"></span>
</div> </div>
<div class="nav-button mat-h5"> <div class="nav-button mat-h5">
<button mat-flat-button (click)="weekEvent.emit(false)" [disabled]="!canBefore()"> <button mat-flat-button (click)="weekEvent.emit(false)" [disabled]="!canBefore()">

View File

@ -1,6 +1,6 @@
import {Component, EventEmitter, Input, Output} from '@angular/core'; import {Component, EventEmitter, Input, Output} from '@angular/core';
import {DatePipe} from "@angular/common"; import {DatePipe} from "@angular/common";
import {addDays, weekInYear} from "@progress/kendo-date-math"; import {addDays} from "@progress/kendo-date-math";
import {MatButton} from "@angular/material/button"; import {MatButton} from "@angular/material/button";
import {MatIcon} from "@angular/material/icon"; import {MatIcon} from "@angular/material/icon";
import {MatBadge} from "@angular/material/badge"; import {MatBadge} from "@angular/material/badge";
@ -20,15 +20,29 @@ import {MatBadge} from "@angular/material/badge";
export class TableHeaderComponent { export class TableHeaderComponent {
@Input() startWeek!: Date; @Input() startWeek!: Date;
@Input() startTerm!: Date; @Input() currentWeek!: number;
@Output() weekEvent: EventEmitter<boolean | null> = new EventEmitter<boolean | null>(); @Output() weekEvent: EventEmitter<boolean | null> = new EventEmitter<boolean | null>();
currentWeek(): number { AdditionalText(tab: AdditionalText = AdditionalText.Other, data: string | null = null) {
return (weekInYear(this.startWeek) - weekInYear(this.startTerm)) + 1; if (data !== null) {
this.dataText = data;
}
switch (tab) {
case AdditionalText.Group:
this.additionalText = 'для группы';
break;
case AdditionalText.LectureHall:
this.additionalText = 'в аудитории';
break;
case AdditionalText.Professor:
this.additionalText = 'для преподавателя';
break;
}
} }
canBefore(): boolean { protected canBefore(): boolean {
return this.currentWeek() > 1; return this.currentWeek > 1;
} }
protected readonly addDays = addDays; protected readonly addDays = addDays;