Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit efeb7bd

Browse files
author
evombau
committed
monatsansicht erster wurf
1 parent 9630928 commit efeb7bd

File tree

9 files changed

+82
-34
lines changed

9 files changed

+82
-34
lines changed
30.1 KB
Loading
Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
<div class="divbox" *ngIf="!isLoading">
2-
<button mat-raised-button *ngIf="config.switches && mode == 'monthly'" (click)="onMonthBackward()">
3-
<mat-icon>
4-
navigate_before
5-
</mat-icon>
2+
<button mat-flat-button class="slideButton"
3+
*ngIf="config.switches && mode == 'monthly' && monthsBefore != 0 && monthsAfter != 0"
4+
(click)="onMonthBackward()">
5+
<span class="material-icons">
6+
keyboard_arrow_left
7+
</span>
68
</button>
79
<div class="month mat-elevation-z8" *ngFor="let monat of calendar.months">
810
<mat-grid-list cols="{{config.calendarWeek? 8 : 7}}" rowHeight="30px">
911
<mat-grid-tile colspan="{{config.calendarWeek? 8 : 7}}" rowspan="1">
10-
<a>{{monat.name}}</a> <a style="margin-left: 5px;" *ngIf="config.displayYear"> {{monat.year}}</a>
12+
<button mat-icon-button
13+
*ngIf="config.switches && mode == 'monthly' && monthsBefore == 0 && monthsAfter == 0"
14+
(click)="onMonthBackward()">
15+
<span class="material-icons">
16+
keyboard_arrow_left
17+
</span>
18+
</button>
19+
<span style="flex: 1 1 auto;"></span>
20+
<div>
21+
<a>{{monat.name}}</a>
22+
<a style="margin-left: 5px;" *ngIf="config.displayYear">{{monat.year}}</a>
23+
</div>
24+
<span style="flex: 1 1 auto;"></span>
25+
<button mat-icon-button
26+
*ngIf="config.switches && mode == 'monthly' && monthsBefore == 0 && monthsAfter == 0"
27+
(click)="onMonthForward()">
28+
<span class="material-icons">
29+
keyboard_arrow_right
30+
</span>
31+
</button>
1132
</mat-grid-tile>
1233
<mat-grid-tile *ngIf="config.calendarWeek" colspan="1" rowspan="1"></mat-grid-tile>
1334
<mat-grid-tile class="weekdayPlaceholder" *ngFor="let dayNames of calendar.dayNames" colspan="1"
@@ -23,22 +44,24 @@
2344
<mat-grid-tile *ngIf="day.type === 'leer'" colspan="1" rowspan="1"></mat-grid-tile>
2445

2546
<mat-grid-tile *ngIf="day.type === 'placeholderDay'" colspan="1" rowspan="1"
26-
[ngClass]="[day.isWeekendDay? 'Weekend' : '', placeholderDay ? 'weekdayPlaceholder':'placeholderFalse', day.isHoliday? 'Holiday' : '']">
47+
[ngClass]="[day.isWeekendDay? 'Weekend' : '', placeholderDay ? 'weekdayPlaceholder':'placeholderFalse', day.isHoliday && config.useHolidays? 'Holiday' : '']">
2748
<a>{{day.day}}</a>
2849
</mat-grid-tile>
2950

3051
<mat-grid-tile *ngIf="day.type === 'date'" colspan="1" rowspan="1" matTooltip="test"
31-
[ngClass]="[day.isWeekendDay? 'Weekend' : '', day.isHoliday && config.useHolidays ? 'Holiday' : '']">
52+
[ngClass]="[day.isWeekendDay? 'Weekend' : '', day.isHoliday && config.useHolidays ? 'Holiday' : '', day.date.setHours(0, 0, 0, 0) == today? 'today': '']">
3253
{{day.day}}
3354
</mat-grid-tile>
3455

3556
</ng-container>
3657

3758
</mat-grid-list>
3859
</div>
39-
<button mat-raised-button *ngIf="config.switches && mode == 'monthly'" (click)="onMonthForward()">
40-
<mat-icon>
41-
navigate_next
42-
</mat-icon>
60+
<button mat-flat-button class="slideButton"
61+
*ngIf="config.switches && mode == 'monthly' && monthsBefore != 0 && monthsAfter != 0"
62+
(click)="onMonthForward()">
63+
<span class="material-icons">
64+
keyboard_arrow_right
65+
</span>
4366
</button>
4467
</div>

projects/material-calendar/src/lib/calendar-panels/calendar-panels.component.scss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
display: flex;
88
flex-wrap: wrap;
99
justify-content: center;
10+
align-items: center;
1011
}
1112

1213
.month {
@@ -27,9 +28,9 @@ mat-grid-tile {
2728
color: var(--text-color);
2829
}
2930

30-
.highlight {
31+
.today {
3132
box-sizing: border-box;
32-
border: 2px solid rgba(0, 103, 127, 0.1);
33+
border: 2px solid var(--today-color);
3334
}
3435

3536
.Weekend {
@@ -57,3 +58,11 @@ mat-grid-tile {
5758
.placeholderFalse a {
5859
display: none;
5960
}
61+
62+
.slideButton {
63+
padding: 0;
64+
}
65+
66+
.slideButton span {
67+
font-size: 60px;
68+
}

projects/material-calendar/src/lib/calendar-panels/calendar-panels.component.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, HostBinding, Input } from '@angular/core';
1+
import { Component, OnInit, HostBinding, Input, Output } from '@angular/core';
22
import { CalendarService } from '../service/calendar.service';
33
import * as pSBC from '../service/pSBC';
44
import { CalendarConfig } from '../service/models';
@@ -20,6 +20,7 @@ export class CalendarPanelsComponent implements OnInit {
2020
holidayTextColor: 'rgb(253, 173, 0)',
2121
displayYear: true,
2222
firstDayOfWeekMonday: true,
23+
todayColor: '#fff',
2324
calendarWeek: true,
2425
switches: false,
2526
};
@@ -28,7 +29,9 @@ export class CalendarPanelsComponent implements OnInit {
2829
private _year: number = new Date().getFullYear()
2930
private _monthsBefore: number = 1;
3031
private _monthsAfter: number = 1;
32+
3133
calendar = null
34+
today = new Date().setHours(0, 0, 0, 0)
3235

3336
get mode(): string {
3437
return this._mode;
@@ -65,32 +68,34 @@ export class CalendarPanelsComponent implements OnInit {
6568
@Input()
6669
set month(data: number) {
6770
this._month = data;
71+
this.monthOverrride = false
6872
this.generateX()
6973
}
7074
@Input()
7175
set config(data: CalendarConfig) {
7276
this._config = data;
7377
this.generateX()
7478
}
75-
@Input()
76-
set year(data: number){
79+
@Input()
80+
set year(data: number) {
7781
this._year = data;
7882
this.generateX()
7983
}
80-
@Input()
81-
set monthsBefore(data: number){
84+
@Input()
85+
set monthsBefore(data: number) {
8286
this._monthsBefore = data;
8387
this.generateX()
8488
}
85-
@Input()
86-
set monthsAfter(data: number){
89+
@Input()
90+
set monthsAfter(data: number) {
8791
this._monthsAfter = data;
8892
this.generateX()
8993
}
9094

9195
@Input() placeholderDay: boolean = false;
9296

9397
isLoading = true
98+
monthOverrride = false
9499

95100
@HostBinding("style.--panel-color")
96101
panelBgColor = this.config.panelBgColor;
@@ -104,6 +109,8 @@ export class CalendarPanelsComponent implements OnInit {
104109
panelBgColorHoliday = this.config.holidayColor;
105110
@HostBinding("style.--text-color-holiday")
106111
panelColorHoliday = this.lightOrDarkTextColor(this.config.holidayColor);
112+
@HostBinding("style.--today-color")
113+
todayColor = this.config.todayColor;
107114

108115
constructor(private calendarService: CalendarService) {
109116
// colors
@@ -130,28 +137,34 @@ export class CalendarPanelsComponent implements OnInit {
130137
}
131138

132139
onMonthForward() {
133-
if (this.month >= 11) {
134-
this._year = this.year + 1
135-
this.month = 0
140+
this.monthOverrride = true
141+
if (this.month >= 11 || this._month >= 11) {
142+
this._year = parseInt(this.year.toString(), 10) + 1
143+
this._month = 0
136144
} else {
137-
this.month = this.month + 1
145+
this._month = parseInt(this._month.toString(), 10) + 1
138146
}
147+
this.generateX()
139148
}
140149

141150
onMonthBackward() {
142-
if (this.month <= 0) {
143-
this._year = this.year - 1
144-
this.month = 11
151+
this.monthOverrride = true
152+
if (this.month <= 0 || this._month <= 0) {
153+
this._year = parseInt(this.year.toString(), 10) - 1
154+
this._month = 11
145155
} else {
146-
this.month = this.month - 1
156+
this._month = parseInt(this._month.toString(), 10) - 1
147157
}
158+
this.generateX()
148159
}
149160

150161
generateX() {
162+
const usedYear = this.monthOverrride ? this._year : this.year
163+
const usedMonth = this.monthOverrride ? this._month : this.month
151164
if (this.mode === 'annual') {
152165
this.calendar = this.calendarService.generateMatrix(this.mode, this.config.calendarWeek, null, this.year)
153166
} else if (this.mode === 'monthly') {
154-
this.calendar = this.calendarService.generateMatrix(this.mode, this.config.calendarWeek, null, this.year, this.month, this.monthsBefore, this.monthsAfter)
167+
this.calendar = this.calendarService.generateMatrix(this.mode, this.config.calendarWeek, null, usedYear, usedMonth, this.monthsBefore, this.monthsAfter)
155168
}
156169
// console.log(this.calendar)
157170
}

projects/material-calendar/src/lib/service/calendar.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ export class CalendarService {
4747
months.push(this.generateMonth(currMonth, year))
4848
for (let index = 0; index < monthsBefore; index++) {
4949
const calculatedMonth = currMonth - monthsBefore + index
50-
const actualYear = (calculatedMonth + 1 < 1) ? year-- : year
50+
const actualYear = (calculatedMonth + 1 < 1) ? year - 1 : year
5151
const actualMonth = (calculatedMonth + 1 < 1) ? 12 + calculatedMonth : calculatedMonth
5252
months.splice(index, 0, this.generateMonth(actualMonth, actualYear))
5353
}
5454
for (let index = 0; index < monthsAfter; index++) {
5555
const calculatedMonth = currMonth + index + 1
56-
const actualYear = (calculatedMonth > 11) ? year++ : year
56+
const actualYear = (calculatedMonth > 11) ? year + 1 : year
5757
const actualMonth = (calculatedMonth > 11) ? calculatedMonth - 12 : calculatedMonth
5858
months.push(this.generateMonth(actualMonth, actualYear))
5959
}

projects/material-calendar/src/lib/service/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface CalendarConfig {
2020
panelBgColor?: string;
2121
textColor?: string;
2222
holidayColor?: string;
23+
todayColor?: string;
2324
holidayTextColor?: string;
2425
}
2526

projects/my-first-app/src/app/app.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
[mode]="mode"
66
[placeholderDay]="placeholder"
77
year="2020"
8-
month="3"
9-
monthsBefore="0"
8+
month="5"
9+
monthsBefore="1"
1010
monthsAfter="1"
1111
[config]="calendarConfig">
1212
</calendar-panels>

projects/my-first-app/src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class AppComponent {
1919
useHolidays: false,
2020
holidayColor: 'rgb(253, 173, 0)',
2121
holidayTextColor: 'rgb(253, 173, 0)',
22-
displayYear: false,
22+
displayYear: true,
2323
firstDayOfWeekMonday: true,
2424
calendarWeek: false,
2525
switches: true,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/* You can add global styles to this file, and also import other style files */
2+
3+
@import "~@angular/material/prebuilt-themes/indigo-pink.css";

0 commit comments

Comments
 (0)