Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 0e8e77b3

Přidáno uživatelem Václav Jirák před téměř 6 roky(ů)

Re #7500 Day picker component modified - displaying vacations + emits change of month

Zobrazit rozdíly:

webapp/src/app/dashboard/employer-dashboard/employer-dashboard.component.html
24 24
      <div class="employer-dashboard-day-picker">
25 25
        <app-day-picker
26 26
          (selectedDate)="onDateSelect($event)"
27
          (selectedMonth)="onMonthSelect($event)"
27 28
        ></app-day-picker>
28 29
      </div>
29 30

  
webapp/src/app/dashboard/employer-dashboard/employer-dashboard.component.ts
76 76
      }
77 77
    });
78 78
  }
79

  
80
  onMonthSelect(month: number) {
81
    // TODO API CALL
82
    console.log(month);
83
  }
79 84
}
webapp/src/app/day-picker/day-picker.component.html
2 2
  <div class="row text-center day-picker-month-selection">
3 3
    <div class="col-4"></div>
4 4
    <div class="col-1">
5
      <div class="btn btn-primary"
6
           mwlCalendarPreviousView
7
           [view]="view"
8
           [(viewDate)]="viewDate"
5
      <button
6
        mat-icon-button
7
        mwlCalendarPreviousView
8
        [view]="view"
9
        [(viewDate)]="viewDate"
10
        (click)="setMonth(currentMonth - 1)"
9 11
      >
10
        <
11
      </div>
12
        <i class="material-icons change-month">navigate_before</i>
13
      </button>
12 14
    </div>
13 15
    <div class="col-2">
14 16
      <span id="day-picker-date">{{ viewDate | calendarDate:(view + 'ViewTitle'):locale }}</span>
15 17
    </div>
16 18
    <div class="col-1">
17
      <div class="btn btn-primary"
18
           mwlCalendarNextView
19
           [view]="view"
20
           [(viewDate)]="viewDate"
19
      <button
20
        mat-icon-button
21
        mwlCalendarNextView
22
        [view]="view"
23
        [(viewDate)]="viewDate"
24
        (click)="setMonth(currentMonth + 1)"
21 25
      >
22
        >
23
      </div>
26
        <i class="material-icons change-month">navigate_next</i>
27
      </button>
24 28
      <div class="col-4"></div>
25 29
    </div>
26 30
  </div>
27 31

  
28
  <!-- Refresh attribute for localization purposes (refresh component after change of language -->
32
  <!-- Refresh attribute for localization purposes (refresh component after change of language) -->
29 33
  <mwl-calendar-month-view
30 34
    [viewDate]="viewDate"
31
    (dayClicked)="dayClicked($event.day)"
32
    weekStartsOn="1"
33 35
    [locale]="locale"
34 36
    [refresh]="localizationService.currentLanguage"
37
    [events]="events"
38
    [cellTemplate]="customCellTemplate"
39
    (dayClicked)="dayClicked($event.day)"
40
    weekStartsOn="1"
35 41
  >
36 42
  </mwl-calendar-month-view>
43

  
44
  <ng-template #customCellTemplate let-day="day" let-locale="locale">
45
    <div class="cal-cell-top">
46
      <span class="cal-day-number">
47
        {{ day.date | calendarDate:'monthViewDayNumber':locale }}
48
      </span>
49
    </div>
50
      <span class="vacation-type" *ngFor="let event of day.events">
51
        <i class="material-icons sickday" *ngIf="event.title == vacationType.SICKDAY">local_hospital</i>
52
        <i class="material-icons vacation" *ngIf="event.title == vacationType.VACATION">beach_access</i>
53

  
54
        {{ event.start | date:'HH:mm' }} - {{ event.end | date:'HH:mm' }}
55
      </span>
56
  </ng-template>
37 57
</div>
webapp/src/app/day-picker/day-picker.component.sass
6 6
#day-picker-date
7 7
  font-weight: bold
8 8
  text-transform: uppercase
9
  line-height: 45px
10
  text-align: center
11

  
9 12

  
10 13
.day-picker-month-selection
11 14
  margin-bottom: 10px
15
  button
16
    outline: none
17
    border: 0
18
  .change-month
19
    color: blue
20

  
21

  
22

  
23
.vacation-type
24
  font-size: 10px
25
  .material-icons
26
    font-size: 14px
27
  .sickday
28
    color: red
29
  .vacation
30
    color: blue
webapp/src/app/day-picker/day-picker.component.ts
1
import { Component, ChangeDetectionStrategy, Output, EventEmitter } from '@angular/core';
2
import { CalendarView } from 'angular-calendar';
1
import { Component, ChangeDetectionStrategy, Input, Output, EventEmitter } from '@angular/core';
2
import { CalendarView, CalendarEvent } from 'angular-calendar';
3 3
import {LocalizationService} from '../localization/localization.service';
4
import {VacationType} from '../enums/common.enum';
4 5

  
5 6
@Component({
6 7
  selector: 'app-day-picker',
......
12 13

  
13 14
  private locale;
14 15

  
16
  private vacationType = VacationType;
17

  
18
  private currentMonth: number;
19

  
15 20
  // Type of calendar (constant)
16 21
  view: CalendarView = CalendarView.Month;
17 22

  
18 23
  // Selected date for this component's purpose
19
  private viewDate: Date = new Date();
24
  private viewDate: Date;
25

  
26
  // Events which are shown in calendar (title = VacationType)
27
  @Input() events: CalendarEvent[] = [];
20 28

  
21 29
  // EventEmitter informing about changes of selected date
22 30
  @Output() selectedDate = new EventEmitter<Date>();
23 31

  
32
  // EventEmitter informing about changes of selected month
33
  @Output() selectedMonth = new EventEmitter<number>();
34

  
24 35
  constructor(private localizationService: LocalizationService) {
25 36
    this.locale = localizationService.defaultLanguage;
26 37
    localizationService.currentLanguage
27 38
      .subscribe((data) => {
28 39
        this.locale = data;
29 40
      });
41

  
42
    this.viewDate = new Date();
43
    this.currentMonth = this.viewDate.getMonth();
44
    console.log(this.currentMonth);
30 45
  }
31 46

  
32 47
  /**
......
39 54
    this.viewDate = date;
40 55
    this.selectedDate.emit(date);
41 56
  }
57

  
58
  private setMonth(newMonth: number): void {
59
    this.currentMonth = newMonth % 12;
60
    if (this.currentMonth < 0) {
61
      this.currentMonth = 11;
62
    }
63
    this.selectedMonth.emit(this.currentMonth);
64
  }
42 65
}
webapp/src/app/day-picker/day-picker.module.ts
3 3
import { adapterFactory } from 'angular-calendar/date-adapters/date-fns';
4 4
import { DayPickerComponent } from './day-picker.component';
5 5
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
6
import {MatButtonModule} from '@angular/material';
6 7

  
7 8
@NgModule({
8 9
  declarations: [ DayPickerComponent ],
......
12 13
                    provide: DateAdapter,
13 14
                    useFactory: adapterFactory
14 15
                  }),
15
                  BrowserAnimationsModule
16
                  BrowserAnimationsModule,
17
                  MatButtonModule
16 18
                ],
17 19
})
18 20
export class DayPickerModule {}

Také k dispozici: Unified diff