mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-18 00:10:14 +01:00
refactor(calendar): move fullCalendar into baFullCalendar
This commit is contained in:
parent
6bca50b36e
commit
8e82cc57ff
9 changed files with 108 additions and 60 deletions
|
|
@ -1,73 +1,44 @@
|
||||||
import {Component, ViewEncapsulation} from '@angular/core';
|
import {Component, ViewEncapsulation} from '@angular/core';
|
||||||
|
|
||||||
import './calendar.loader.ts';
|
import {BaFullCalendar} from '../../../theme/components';
|
||||||
import {BaThemeConfigProvider} from '../../../theme';
|
import {CalendarService} from "./calendar.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'calendar',
|
selector: 'calendar',
|
||||||
encapsulation: ViewEncapsulation.None,
|
encapsulation: ViewEncapsulation.None,
|
||||||
styles: [require('fullcalendar/dist/fullcalendar.css'), require('./calendar.scss')],
|
styles: [require('./calendar.scss')],
|
||||||
template: require('./calendar.html')
|
template: require('./calendar.html'),
|
||||||
|
directives: [BaFullCalendar],
|
||||||
|
providers: [CalendarService]
|
||||||
})
|
})
|
||||||
export class Calendar {
|
export class Calendar {
|
||||||
|
|
||||||
constructor(private _baConfig:BaThemeConfigProvider) {
|
public calendarConfiguration:any;
|
||||||
|
private _calendar:Object;
|
||||||
|
|
||||||
|
constructor(private _calendarService:CalendarService) {
|
||||||
|
this.calendarConfiguration = this._calendarService.getData();
|
||||||
|
this.calendarConfiguration.select = (start, end) => this._onSelect(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
public onCalendarReady(calendar):void {
|
||||||
this._initCalendar();
|
this._calendar = calendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
_initCalendar() {
|
private _onSelect(start, end):void {
|
||||||
let dashboardColors = this._baConfig.get().colors.dashboard;
|
|
||||||
|
|
||||||
let $element = $('#calendar').fullCalendar({
|
if (this._calendar != null) {
|
||||||
header: {
|
var title = prompt('Event Title:');
|
||||||
left: 'prev,next today',
|
var eventData;
|
||||||
center: 'title',
|
if (title) {
|
||||||
right: 'month,agendaWeek,agendaDay'
|
eventData = {
|
||||||
},
|
title: title,
|
||||||
defaultDate: '2016-03-08',
|
start: start,
|
||||||
selectable: true,
|
end: end
|
||||||
selectHelper: true,
|
};
|
||||||
select: function (start, end) {
|
$(this._calendar).fullCalendar('renderEvent', eventData, true);
|
||||||
var title = prompt('Event Title:');
|
}
|
||||||
var eventData;
|
$(this._calendar).fullCalendar('unselect');
|
||||||
if (title) {
|
}
|
||||||
eventData = {
|
|
||||||
title: title,
|
|
||||||
start: start,
|
|
||||||
end: end
|
|
||||||
};
|
|
||||||
$element.fullCalendar('renderEvent', eventData, true);
|
|
||||||
}
|
|
||||||
$element.fullCalendar('unselect');
|
|
||||||
},
|
|
||||||
editable: true,
|
|
||||||
eventLimit: true, // allow "more" link when too many events
|
|
||||||
events: [
|
|
||||||
{
|
|
||||||
title: 'All Day Event',
|
|
||||||
start: '2016-03-01',
|
|
||||||
color: dashboardColors.silverTree
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Long Event',
|
|
||||||
start: '2016-03-07',
|
|
||||||
end: '2016-03-10',
|
|
||||||
color: dashboardColors.blueStone
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Dinner',
|
|
||||||
start: '2016-03-14T20:00:00',
|
|
||||||
color: dashboardColors.surfieGreen
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Birthday Party',
|
|
||||||
start: '2016-04-01T07:00:00',
|
|
||||||
color: dashboardColors.gossip
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
<div id="calendar" class="blurCalendar"></div>
|
<ba-full-calendar [baFullCalendarConfiguration]="calendarConfiguration" baFullCalendarClass="blurCalendar" (onCalendarReady)="onCalendarReady($event)"></ba-full-calendar>
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
require('fullcalendar/dist/fullcalendar.js');
|
|
||||||
|
|
||||||
49
src/app/pages/dashboard/calendar/calendar.service.ts
Normal file
49
src/app/pages/dashboard/calendar/calendar.service.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
import {Injectable} from '@angular/core';
|
||||||
|
import {BaThemeConfigProvider} from '../../../theme';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CalendarService {
|
||||||
|
|
||||||
|
constructor(private _baConfig:BaThemeConfigProvider) {
|
||||||
|
}
|
||||||
|
|
||||||
|
getData() {
|
||||||
|
|
||||||
|
let dashboardColors = this._baConfig.get().colors.dashboard;
|
||||||
|
return {
|
||||||
|
header: {
|
||||||
|
left: 'prev,next today',
|
||||||
|
center: 'title',
|
||||||
|
right: 'month,agendaWeek,agendaDay'
|
||||||
|
},
|
||||||
|
defaultDate: '2016-03-08',
|
||||||
|
selectable: true,
|
||||||
|
selectHelper: true,
|
||||||
|
editable: true,
|
||||||
|
eventLimit: true,
|
||||||
|
events: [
|
||||||
|
{
|
||||||
|
title: 'All Day Event',
|
||||||
|
start: '2016-03-01',
|
||||||
|
color: dashboardColors.silverTree
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Long Event',
|
||||||
|
start: '2016-03-07',
|
||||||
|
end: '2016-03-10',
|
||||||
|
color: dashboardColors.blueStone
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Dinner',
|
||||||
|
start: '2016-03-14T20:00:00',
|
||||||
|
color: dashboardColors.surfieGreen
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Birthday Party',
|
||||||
|
start: '2016-04-01T07:00:00',
|
||||||
|
color: dashboardColors.gossip
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import {Component, ViewChild, ViewEncapsulation, Input, Output, ElementRef, EventEmitter} from '@angular/core';
|
||||||
|
|
||||||
|
import './baFullCalendar.loader.ts';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'ba-full-calendar',
|
||||||
|
template: require('./baFullCalendar.html'),
|
||||||
|
encapsulation: ViewEncapsulation.None,
|
||||||
|
})
|
||||||
|
export class BaFullCalendar {
|
||||||
|
|
||||||
|
@Input() baFullCalendarConfiguration:Object;
|
||||||
|
@Input() baFullCalendarClass:string;
|
||||||
|
@Output() onCalendarReady = new EventEmitter<any>();
|
||||||
|
|
||||||
|
@ViewChild('baFullCalendar') private _selector:ElementRef;
|
||||||
|
|
||||||
|
constructor () {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngAfterViewInit() {
|
||||||
|
let calendar = $(this._selector.nativeElement).fullCalendar(this.baFullCalendarConfiguration);
|
||||||
|
this.onCalendarReady.emit(calendar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<div #baFullCalendar class="ba-full-calendar {{baFullCalendarClass || ''}}"></div>
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
require('fullcalendar/dist/fullcalendar.js');
|
||||||
|
require('style-loader!fullcalendar/dist/fullcalendar.css');
|
||||||
1
src/app/theme/components/baFullCalendar/index.ts
Normal file
1
src/app/theme/components/baFullCalendar/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './baFullCalendar.component.ts';
|
||||||
|
|
@ -6,3 +6,4 @@ export * from './baCard';
|
||||||
export * from './baAmChart';
|
export * from './baAmChart';
|
||||||
export * from './baChartistChart';
|
export * from './baChartistChart';
|
||||||
export * from './baBackTop';
|
export * from './baBackTop';
|
||||||
|
export * from './BaFullCalendar';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue