refactor(calendar): move fullCalendar into baFullCalendar

This commit is contained in:
nixa 2016-05-20 19:44:29 +03:00
parent 6bca50b36e
commit 8e82cc57ff
9 changed files with 108 additions and 60 deletions

View file

@ -1,73 +1,44 @@
import {Component, ViewEncapsulation} from '@angular/core';
import './calendar.loader.ts';
import {BaThemeConfigProvider} from '../../../theme';
import {BaFullCalendar} from '../../../theme/components';
import {CalendarService} from "./calendar.service";
@Component({
selector: 'calendar',
encapsulation: ViewEncapsulation.None,
styles: [require('fullcalendar/dist/fullcalendar.css'), require('./calendar.scss')],
template: require('./calendar.html')
styles: [require('./calendar.scss')],
template: require('./calendar.html'),
directives: [BaFullCalendar],
providers: [CalendarService]
})
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() {
this._initCalendar();
public onCalendarReady(calendar):void {
this._calendar = calendar;
}
_initCalendar() {
let dashboardColors = this._baConfig.get().colors.dashboard;
private _onSelect(start, end):void {
let $element = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2016-03-08',
selectable: true,
selectHelper: true,
select: function (start, end) {
var title = prompt('Event Title:');
var eventData;
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
}
]
});
if (this._calendar != null) {
var title = prompt('Event Title:');
var eventData;
if (title) {
eventData = {
title: title,
start: start,
end: end
};
$(this._calendar).fullCalendar('renderEvent', eventData, true);
}
$(this._calendar).fullCalendar('unselect');
}
}
}

View file

@ -1 +1 @@
<div id="calendar" class="blurCalendar"></div>
<ba-full-calendar [baFullCalendarConfiguration]="calendarConfiguration" baFullCalendarClass="blurCalendar" (onCalendarReady)="onCalendarReady($event)"></ba-full-calendar>

View file

@ -1,2 +0,0 @@
require('fullcalendar/dist/fullcalendar.js');

View 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
}
]
};
}
}

View file

@ -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);
}
}

View file

@ -0,0 +1 @@
<div #baFullCalendar class="ba-full-calendar {{baFullCalendarClass || ''}}"></div>

View file

@ -0,0 +1,2 @@
require('fullcalendar/dist/fullcalendar.js');
require('style-loader!fullcalendar/dist/fullcalendar.css');

View file

@ -0,0 +1 @@
export * from './baFullCalendar.component.ts';

View file

@ -6,3 +6,4 @@ export * from './baCard';
export * from './baAmChart';
export * from './baChartistChart';
export * from './baBackTop';
export * from './BaFullCalendar';