1 | import { Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, Input, NgModule } from '@angular/core';
|
2 | import { CommonModule } from '@angular/common';
|
3 | import { Calendar } from '@fullcalendar/core';
|
4 |
|
5 | class FullCalendar {
|
6 | constructor(el) {
|
7 | this.el = el;
|
8 | }
|
9 | ngOnInit() {
|
10 | this.config = {
|
11 | theme: true
|
12 | };
|
13 | if (this.options) {
|
14 | for (let prop in this.options) {
|
15 | this.config[prop] = this.options[prop];
|
16 | }
|
17 | }
|
18 | }
|
19 | ngAfterViewChecked() {
|
20 | if (!this.initialized && this.el.nativeElement.offsetParent) {
|
21 | this.initialize();
|
22 | }
|
23 | }
|
24 | get events() {
|
25 | return this._events;
|
26 | }
|
27 | set events(value) {
|
28 | this._events = value;
|
29 | if (this._events && this.calendar) {
|
30 | this.calendar.removeAllEventSources();
|
31 | this.calendar.addEventSource(this._events);
|
32 | }
|
33 | }
|
34 | get options() {
|
35 | return this._options;
|
36 | }
|
37 | set options(value) {
|
38 | this._options = value;
|
39 | if (this._options && this.calendar) {
|
40 | for (let prop in this._options) {
|
41 | let optionValue = this._options[prop];
|
42 | this.config[prop] = optionValue;
|
43 | this.calendar.setOption(prop, optionValue);
|
44 | }
|
45 | }
|
46 | }
|
47 | initialize() {
|
48 | this.calendar = new Calendar(this.el.nativeElement.children[0], this.config);
|
49 | this.calendar.render();
|
50 | this.initialized = true;
|
51 | if (this.events) {
|
52 | this.calendar.removeAllEventSources();
|
53 | this.calendar.addEventSource(this.events);
|
54 | }
|
55 | }
|
56 | getCalendar() {
|
57 | return this.calendar;
|
58 | }
|
59 | ngOnDestroy() {
|
60 | if (this.calendar) {
|
61 | this.calendar.destroy();
|
62 | this.initialized = false;
|
63 | this.calendar = null;
|
64 | }
|
65 | }
|
66 | }
|
67 | FullCalendar.decorators = [
|
68 | { type: Component, args: [{
|
69 | selector: 'p-fullCalendar',
|
70 | template: '<div [ngStyle]="style" [class]="styleClass"></div>',
|
71 | changeDetection: ChangeDetectionStrategy.OnPush,
|
72 | encapsulation: ViewEncapsulation.None
|
73 | },] }
|
74 | ];
|
75 | FullCalendar.ctorParameters = () => [
|
76 | { type: ElementRef }
|
77 | ];
|
78 | FullCalendar.propDecorators = {
|
79 | style: [{ type: Input }],
|
80 | styleClass: [{ type: Input }],
|
81 | events: [{ type: Input }],
|
82 | options: [{ type: Input }]
|
83 | };
|
84 | class FullCalendarModule {
|
85 | }
|
86 | FullCalendarModule.decorators = [
|
87 | { type: NgModule, args: [{
|
88 | imports: [CommonModule],
|
89 | exports: [FullCalendar],
|
90 | declarations: [FullCalendar]
|
91 | },] }
|
92 | ];
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | export { FullCalendar, FullCalendarModule };
|
99 |
|