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

Commit 221f70f

Browse files
author
evombau
committed
bug fixes
1 parent 5f3fa3c commit 221f70f

File tree

10 files changed

+160
-29
lines changed

10 files changed

+160
-29
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ build_app:
4848
# tags:
4949
# - ng-test
5050

51-
build-image:
51+
npm-publish:
5252
stage: npm-publish
5353
script:
5454
- touch .npmrc
55-
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
55+
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
5656
- cd dist/material-calendar
5757
- npm publish
5858
- rm .npmrc
Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,129 @@
1-
# MaterialCalendar
1+
# Material Calendar
2+
Please read this **before** usage!
3+
This material calendar is just beginning. As in the angular material components, a beautiful calendar is to be generated by simple integration. Cooperation is welcome.
24

3-
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.9.
5+
### Live demo
6+
comming soon...
7+
8+
## Installing
9+
`npm i material-calendar`
10+
11+
## Usage
12+
app.module.ts
13+
``` typescript
14+
import { BrowserModule } from '@angular/platform-browser';
15+
import { NgModule, LOCALE_ID } from '@angular/core';
16+
17+
import { AppComponent } from './app.component';
18+
import { MaterialCalendarModule } from 'material-calendar';
19+
20+
@NgModule({
21+
declarations: [
22+
AppComponent
23+
],
24+
imports: [
25+
BrowserModule,
26+
MaterialCalendarModule
27+
],
28+
providers: [
29+
{provide: LOCALE_ID, useValue: 'de-DE' }
30+
],
31+
bootstrap: [AppComponent]
32+
})
33+
export class AppModule { }
34+
```
35+
import the `MaterialCalendarModule` and optional provide your location.
36+
In my case: `{provide: LOCALE_ID, useValue: 'de-DE' }`
37+
38+
In your html:
39+
``` html
40+
<calendar-panels></calendar-panels>
41+
```
42+
and you are good to go ;)
43+
44+
All options are shown here:
45+
46+
``` html
47+
<calendar-panels
48+
[mode]="mode"
49+
[placeholderDay]="placeholder"
50+
year="2020"
51+
month="3"
52+
monthsBefore="1"
53+
monthsAfter="1"
54+
[config]="calendarConfig">
55+
</calendar-panels>
56+
<!--
57+
default placeholderDay = false
58+
default year = current year
59+
default month = current month
60+
default monthsBefore = 1
61+
default monthsAfter = 1
62+
-->
63+
```
64+
``` typescript
65+
import { CalendarConfig } from 'material-calendar';
66+
67+
placeholder = false // boolean
68+
mode = 'monthly' // 'annual' | 'monthly'
69+
70+
calendarConfig: CalendarConfig = {
71+
panelBgColor: '#00677f', // use only hex or rbg colors
72+
autoTextColor: true,
73+
textColor: '#fff', // use only hex or rbg colors
74+
useHolidays: false,
75+
holidayColor: 'rgb(253, 173, 0)', // use only hex or rbg colors
76+
holidayTextColor: 'rgb(253, 173, 0)', // use only hex or rbg colors
77+
displayYear: true,
78+
calendarWeek: true,
79+
switches: false,
80+
}
81+
```
82+
``` javascript
83+
/**
84+
* @param {boolean} autoTextColor Sets the text color automatically, based on the backgroud colors
85+
* @param {boolean} calendarWeek display the calendar week
86+
* @param {boolean} useHolidays use holidays, only german (for now)
87+
* @param {boolean} displayYear displays the year next to the Month name
88+
* @param {boolean} switches not fullt implemented!
89+
* @param {string} panelBgColor sets the background color of the panel
90+
* @param {string} textColor if autoTextColor false this must be set to a custom color
91+
* @param {string} holidayColor sets the background color of the holiday field
92+
* @param {string} holidayTextColor sets the text color of the holiday field
93+
*
94+
*/
95+
```
96+
97+
## Planned features
98+
99+
- insert your own calendar data and render the new template
100+
- multiselect days optional (returns the daily span)
101+
102+
and many more...
4103

5104
## Code scaffolding
6105

7-
Run `ng generate component component-name --project material-calendar` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project material-calendar`.
8-
> Note: Don't forget to add `--project material-calendar` or else it will be added to the default project in your `angular.json` file.
106+
For code scaffolding, the project can be checked out from the public repository and pull requests can be made.
107+
9108

10109
## Build
11110

111+
12112
Run `ng build material-calendar` to build the project. The build artifacts will be stored in the `dist/` directory.
13113

14114
## Publishing
15115

16116
After building your library with `ng build material-calendar`, go to the dist folder `cd dist/material-calendar` and run `npm publish`.
17117

118+
119+
18120
## Running unit tests
19121

122+
123+
20124
Run `ng test material-calendar` to execute the unit tests via [Karma](https://karma-runner.github.io).
21125

22-
## Further help
126+
23127

24-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
128+
## Further help
129+
For feature requests or problems, please open a ticket in the issue tracker.

projects/material-calendar/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "material-calendar",
3-
"version": "0.0.2",
3+
"version": "0.0.5",
44
"license": "MIT",
55
"peerDependencies": {
66
"@angular/common": "^9.1.9",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
</mat-grid-list>
3333
</div>
34-
<mat-icon>
34+
<!-- <mat-icon>
3535
navigate_next
36-
</mat-icon>
36+
</mat-icon> -->
3737
</div>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export class CalendarPanelsComponent implements OnInit {
1414
private _data = null;
1515
calendar = null
1616

17-
get mode(): String {
17+
get mode(): string {
1818
return this._mode;
1919
}
2020
get data(): any {
2121
return this._data;
2222
}
2323

2424
@Input()
25-
set mode(val: String) {
25+
set mode(val: string) {
2626
this._mode = val;
2727
this.generateX()
2828
}
@@ -90,10 +90,10 @@ export class CalendarPanelsComponent implements OnInit {
9090

9191
generateX() {
9292
if (this.mode === 'annual') {
93-
this.calendar = this.calendarService.generateMatrix(this.config.calendarWeek, null, this.year)
93+
this.calendar = this.calendarService.generateMatrix(this.mode, this.config.calendarWeek, null, this.year)
9494
} else if (this.mode === 'monthly') {
9595
console.log(this.month)
96-
this.calendar = this.calendarService.generateMatrix(this.config.calendarWeek, null, this.year, this.month, this.monthsBefore, this.monthsAfter)
96+
this.calendar = this.calendarService.generateMatrix(this.mode, this.config.calendarWeek, null, this.year, this.month, this.monthsBefore, this.monthsAfter)
9797
}
9898
console.log(this.calendar)
9999
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,37 @@ export class CalendarService {
2020
monthNames = this.momentLoc.monthsShort()
2121

2222
/**
23+
* @param {String} mode calendar mode (monthly|annual)
24+
* @param {boolean} calendarWeek Display calendar week
2325
* @param {Calendar} calendar Custom data, (optinal)
2426
* @param {Number} year Gerarate calender for one year, (optinal)
2527
* @param {Number} currMonth current selected month, (optinal)
2628
* @param {Number} monthsBefore months before the selected month, (optinal) default 0
2729
* @param {Number} monthsAfter months after the selected month, (optinal) default 0
2830
*/
29-
generateMatrix(calendarWeek: boolean, calendar?: Calendar, year?: number, currMonth?: number, monthsBefore?: number, monthsAfter?: number) {
31+
generateMatrix(mode: string, calendarWeek: boolean, calendar?: Calendar, year?: number, currMonth?: number, monthsBefore?: number, monthsAfter?: number) {
3032
let cal;
3133
// Custom calendar data?
34+
monthsAfter = monthsAfter ? parseInt(monthsAfter.toString(), 10) : monthsAfter
35+
monthsBefore = monthsBefore ? parseInt(monthsBefore.toString(), 10) : monthsBefore
36+
currMonth = currMonth ? parseInt(currMonth.toString(), 10) : currMonth
3237
if (calendar != undefined || calendar != null) {
3338
console.log('Custom Calendar!!')
3439
cal = calendar
3540
} else {
3641
// Standard calendar
37-
if ((currMonth + 1) > 0) {
42+
if (mode === 'monthly') {
3843
const months: Month[] = []
3944
months.push(this.generateMonth(currMonth, year))
4045
for (let index = 0; index < monthsBefore; index++) {
4146
const calculatedMonth = currMonth - monthsBefore + index
42-
const actualYear = (calculatedMonth + 1 < 1) ? year - 1 : year
47+
const actualYear = (calculatedMonth + 1 < 1) ? year-- : year
4348
const actualMonth = (calculatedMonth + 1 < 1) ? 12 + calculatedMonth : calculatedMonth
4449
months.splice(index, 0, this.generateMonth(actualMonth, actualYear))
4550
}
4651
for (let index = 0; index < monthsAfter; index++) {
4752
const calculatedMonth = currMonth + index + 1
48-
const actualYear = (calculatedMonth > 11) ? year + 1 : year
53+
const actualYear = (calculatedMonth > 11) ? year++ : year
4954
const actualMonth = (calculatedMonth > 11) ? calculatedMonth - 12 : calculatedMonth
5055
months.push(this.generateMonth(actualMonth, actualYear))
5156
}

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
/**
2+
* @param {boolean} autoTextColor Sets the text color automatically, based on the backgroud colors
3+
* @param {boolean} calendarWeek display the calendar week
4+
* @param {boolean} useHolidays use holidays, only german (for now)
5+
* @param {boolean} displayYear displays the year next to the Month name
6+
* @param {boolean} switches not fullt implemented!
7+
* @param {string} panelBgColor sets the background color of the panel
8+
* @param {string} textColor if autoTextColor false this must be set to a custom color
9+
* @param {string} holidayColor sets the background color of the holiday field
10+
* @param {string} holidayTextColor sets the text color of the holiday field
11+
*
12+
*/
113
export interface CalendarConfig {
214
autoTextColor: boolean;
3-
textColor?: string;
4-
panelBgColor?: string;
5-
panelColor?: string;
15+
calendarWeek: boolean;
616
useHolidays: boolean;
7-
holidayColor?: string;
8-
holidayTextColor?: string;
917
displayYear: boolean;
10-
calendarWeek: boolean;
1118
switches: boolean;
19+
panelBgColor?: string;
20+
textColor?: string;
21+
holidayColor?: string;
22+
holidayTextColor?: string;
1223
}
1324

1425
export interface Calendar {

projects/material-calendar/src/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
*/
44

55
export * from './lib/service/calendar.service';
6+
export * from './lib/service/models';
67
export * from './lib/calendar-panels/calendar-panels.component';
78
export * from './lib/material-calendar.module';
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<button mat-button (click)="placeholder=!placeholder">switch placeholder</button>
22
<button mat-button (click)="switchMode()">switch mode: {{mode}}</button>
33
<p>{{placeholder}}</p>
4-
<calendar-panels [mode]="mode" [placeholderDay]="placeholder" ></calendar-panels><!-- [config]="calendarConfig" -->
4+
<calendar-panels
5+
[mode]="mode"
6+
[placeholderDay]="placeholder"
7+
year="2020"
8+
month="3"
9+
monthsBefore="1"
10+
monthsAfter="1"
11+
[config]="calendarConfig">
12+
</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
@@ -1,5 +1,5 @@
11
import { Component } from '@angular/core';
2-
import { CalendarConfig } from 'projects/material-calendar/src/lib/service/models';
2+
import { CalendarConfig } from 'projects/material-calendar/src/public-api';
33

44
@Component({
55
selector: 'app-root',
@@ -9,7 +9,9 @@ import { CalendarConfig } from 'projects/material-calendar/src/lib/service/model
99
export class AppComponent {
1010
title = 'my-first-app';
1111

12-
placeholder = false
12+
placeholder = false // boolean
13+
mode = 'monthly' // 'annual' | 'monthly'
14+
1315
calendarConfig: CalendarConfig = {
1416
panelBgColor: '#00677f', // 00677f 006105
1517
autoTextColor: true,
@@ -21,7 +23,6 @@ export class AppComponent {
2123
calendarWeek: true,
2224
switches: false,
2325
}
24-
mode = 'monthly'
2526

2627
switchMode() {
2728
this.mode = (this.mode === 'monthly') ? 'annual' : 'monthly'

0 commit comments

Comments
 (0)