import * as calendarModule from "nativescript-ui-calendar" ; import * as observableModule from "tns-core-modules/data/observable" ; import { Frame } from "tns-core-modules/ui/frame" ; import { Color } from "tns-core-modules/color" ; export class ViewModel extends observableModule . Observable { constructor ( ) { super ( ) ; let now = new Date ( ) ; let startDate , endDate , event ; let colors = [ new Color ( 200 , 188 , 26 , 214 ) , new Color ( 220 , 255 , 109 , 130 ) , new Color ( 255 , 55 , 45 , 255 ) , new Color ( 199 , 17 , 227 , 10 ) , new Color ( 255 , 255 , 54 , 3 ) ] ; let events = new Array < calendarModule . CalendarEvent > ( ) ; for ( let i = 1 ; i < 10 ; i ++ ) { startDate = new Date ( now . getFullYear ( ) , now . getMonth ( ) , i * 2 , 1 ) ; endDate = new Date ( now . getFullYear ( ) , now . getMonth ( ) , ( i * 2 ) , 3 ) ; event = new calendarModule . CalendarEvent ( "event " + i , startDate , endDate , false , colors [ i * 10 % ( colors . length - 1 ) ] ) ; events . push ( event ) ; if ( i % 3 === 0 ) { event = new calendarModule . CalendarEvent ( "second " + i , startDate , endDate , true , colors [ i * 5 % ( colors . length - 1 ) ] ) ; events . push ( event ) ; } } this . source = events ; } set source ( value ) { this . set ( "eventSource" , value ) ; } get source ( ) : Array < calendarModule . CalendarEvent > { return < Array < calendarModule . CalendarEvent > > this . get ( "eventSource" ) ; } public onDateSelected ( args ) { const date = args . date ; const calendar = < calendarModule . RadCalendar > < any > Frame . topmost ( ) . getViewById ( "calendar" ) ; const events = calendar . getEventsForDate ( date ) ; this . set ( "myItems" , events ) ; } }