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

Commit 9630928

Browse files
author
evombau
committed
zwischenstand
1 parent 55116da commit 9630928

File tree

8 files changed

+105
-32
lines changed

8 files changed

+105
-32
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
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>
6+
</button>
27
<div class="month mat-elevation-z8" *ngFor="let monat of calendar.months">
38
<mat-grid-list cols="{{config.calendarWeek? 8 : 7}}" rowHeight="30px">
49
<mat-grid-tile colspan="{{config.calendarWeek? 8 : 7}}" rowspan="1">
@@ -31,7 +36,9 @@
3136

3237
</mat-grid-list>
3338
</div>
34-
<!-- <mat-icon>
35-
navigate_next
36-
</mat-icon> -->
39+
<button mat-raised-button *ngIf="config.switches && mode == 'monthly'" (click)="onMonthForward()">
40+
<mat-icon>
41+
navigate_next
42+
</mat-icon>
43+
</button>
3744
</div>

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

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,47 @@ import { CalendarConfig } from '../service/models';
1010
})
1111
export class CalendarPanelsComponent implements OnInit {
1212

13-
private _mode;
13+
private _mode: string;
14+
private _config: CalendarConfig = {
15+
panelBgColor: '#00677f', // 00677f 006105
16+
autoTextColor: true,
17+
textColor: '#fff',
18+
useHolidays: false,
19+
holidayColor: 'rgb(253, 173, 0)',
20+
holidayTextColor: 'rgb(253, 173, 0)',
21+
displayYear: true,
22+
firstDayOfWeekMonday: true,
23+
calendarWeek: true,
24+
switches: false,
25+
};
1426
private _data = null;
27+
private _month = new Date().getUTCMonth();
28+
private _year: number = new Date().getFullYear()
29+
private _monthsBefore: number = 1;
30+
private _monthsAfter: number = 1;
1531
calendar = null
1632

1733
get mode(): string {
1834
return this._mode;
1935
}
36+
get config(): CalendarConfig {
37+
return this._config;
38+
}
2039
get data(): any {
2140
return this._data;
2241
}
42+
get month(): number {
43+
return this._month;
44+
}
45+
get year(): number {
46+
return this._year;
47+
}
48+
get monthsBefore(): number {
49+
return this._monthsBefore;
50+
}
51+
get monthsAfter(): number {
52+
return this._monthsAfter;
53+
}
2354

2455
@Input()
2556
set mode(val: string) {
@@ -30,24 +61,34 @@ export class CalendarPanelsComponent implements OnInit {
3061
set data(data: any) {
3162
this._data = data;
3263
this.generateX()
33-
};
64+
}
65+
@Input()
66+
set month(data: number) {
67+
this._month = data;
68+
this.generateX()
69+
}
70+
@Input()
71+
set config(data: CalendarConfig) {
72+
this._config = data;
73+
this.generateX()
74+
}
75+
@Input()
76+
set year(data: number){
77+
this._year = data;
78+
this.generateX()
79+
}
80+
@Input()
81+
set monthsBefore(data: number){
82+
this._monthsBefore = data;
83+
this.generateX()
84+
}
85+
@Input()
86+
set monthsAfter(data: number){
87+
this._monthsAfter = data;
88+
this.generateX()
89+
}
3490

3591
@Input() placeholderDay: boolean = false;
36-
@Input() year: number = new Date().getFullYear()
37-
@Input() month: number = new Date().getUTCMonth();
38-
@Input() monthsBefore: number = 1;
39-
@Input() monthsAfter: number = 1;
40-
@Input() config: CalendarConfig = {
41-
panelBgColor: '#00677f', // 00677f 006105
42-
autoTextColor: true,
43-
textColor: '#fff',
44-
useHolidays: false,
45-
holidayColor: 'rgb(253, 173, 0)',
46-
holidayTextColor: 'rgb(253, 173, 0)',
47-
displayYear: true,
48-
calendarWeek: true,
49-
switches: false,
50-
}
5192

5293
isLoading = true
5394

@@ -88,14 +129,31 @@ export class CalendarPanelsComponent implements OnInit {
88129
this.isLoading = false
89130
}
90131

132+
onMonthForward() {
133+
if (this.month >= 11) {
134+
this._year = this.year + 1
135+
this.month = 0
136+
} else {
137+
this.month = this.month + 1
138+
}
139+
}
140+
141+
onMonthBackward() {
142+
if (this.month <= 0) {
143+
this._year = this.year - 1
144+
this.month = 11
145+
} else {
146+
this.month = this.month - 1
147+
}
148+
}
149+
91150
generateX() {
92151
if (this.mode === 'annual') {
93152
this.calendar = this.calendarService.generateMatrix(this.mode, this.config.calendarWeek, null, this.year)
94153
} else if (this.mode === 'monthly') {
95-
console.log(this.month)
96154
this.calendar = this.calendarService.generateMatrix(this.mode, this.config.calendarWeek, null, this.year, this.month, this.monthsBefore, this.monthsAfter)
97155
}
98-
console.log(this.calendar)
156+
// console.log(this.calendar)
99157
}
100158

101159
lightOrDarkTextColor(color) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { NgModule } from '@angular/core';
22
import { CalendarPanelsComponent } from './calendar-panels/calendar-panels.component';
33
import { BrowserModule } from '@angular/platform-browser';
4+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
45

56
import { MatGridListModule } from '@angular/material/grid-list';
67
import { MatIconModule } from '@angular/material/icon';
7-
8-
8+
import { MatButtonModule } from '@angular/material/button';
99

1010
@NgModule({
1111
declarations: [CalendarPanelsComponent],
1212
imports: [
1313
BrowserModule,
14+
BrowserAnimationsModule,
1415
MatGridListModule,
15-
MatIconModule
16+
MatIconModule,
17+
MatButtonModule
1618
],
1719
exports: [CalendarPanelsComponent]
1820
})

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export class CalendarService {
1818
}
1919
});
2020
monthNames = this.momentLoc.monthsShort()
21+
dayNamesEn = this.momentLoc.weekdaysShort()
22+
dayNamesDeVor = JSON.parse(JSON.stringify(this.dayNamesEn))
23+
dayNamesDe = this.dayNamesDeVor.push(this.dayNamesDeVor.shift())
2124

2225
/**
2326
* @param {String} mode calendar mode (monthly|annual)
@@ -56,7 +59,7 @@ export class CalendarService {
5659
}
5760
cal = {
5861
months: months,
59-
dayNames: this.momentLoc.weekdaysShort(),
62+
dayNames: this.dayNamesDeVor,
6063
year: year
6164
}
6265
} else {
@@ -134,14 +137,13 @@ export class CalendarService {
134137
}
135138

136139
generateCal(year: number): Calendar {
137-
//if ()
138140
const months = []
139141
for (let index = 0; index < this.monthNames.length; index++) {
140142
months.push(this.generateMonth(index, year))
141143
}
142144
return {
143145
year: year,
144-
dayNames: this.momentLoc.weekdaysShort(),
146+
dayNames: this.dayNamesDeVor,
145147
months: months
146148
}
147149
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface CalendarConfig {
1616
useHolidays: boolean;
1717
displayYear: boolean;
1818
switches: boolean;
19+
firstDayOfWeekMonday: boolean;
1920
panelBgColor?: string;
2021
textColor?: string;
2122
holidayColor?: string;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[placeholderDay]="placeholder"
77
year="2020"
88
month="3"
9-
monthsBefore="1"
9+
monthsBefore="0"
1010
monthsAfter="1"
1111
[config]="calendarConfig">
1212
</calendar-panels>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ export class AppComponent {
1919
useHolidays: false,
2020
holidayColor: 'rgb(253, 173, 0)',
2121
holidayTextColor: 'rgb(253, 173, 0)',
22-
displayYear: true,
23-
calendarWeek: true,
24-
switches: false,
22+
displayYear: false,
23+
firstDayOfWeekMonday: true,
24+
calendarWeek: false,
25+
switches: true,
2526
}
2627

2728
switchMode() {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { NgModule, LOCALE_ID } from '@angular/core';
33

44
import { AppComponent } from './app.component';
55
import { MaterialCalendarModule } from 'projects/material-calendar/src/public-api';
6+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
67

78
@NgModule({
89
declarations: [
910
AppComponent
1011
],
1112
imports: [
1213
BrowserModule,
14+
BrowserAnimationsModule,
1315
MaterialCalendarModule
1416
],
1517
providers: [

0 commit comments

Comments
 (0)