1- import { Component , OnInit } from '@angular/core' ;
2- import { SchedulerEvent , CreateFormGroupArgs , KENDO_SCHEDULER } from '@progress/kendo-angular-scheduler' ;
3- import { FormGroup , FormBuilder , ReactiveFormsModule } from '@angular/forms' ;
4- import { sampleDataWithCustomSchema , displayDate , customModelFields } from './scheduler-data' ;
5- import { KENDO_TOOLBAR } from '@progress/kendo-angular-toolbar' ;
1+ import { Component , OnInit } from "@angular/core" ;
2+ import { FormBuilder , FormGroup , ReactiveFormsModule } from "@angular/forms" ;
3+ import { KENDO_DROPDOWNLIST } from "@progress/kendo-angular-dropdowns" ;
4+ import { CreateFormGroupArgs , KENDO_SCHEDULER } from "@progress/kendo-angular-scheduler" ;
5+ import { KENDO_TOOLBAR } from "@progress/kendo-angular-toolbar" ;
6+ import { customModelFields , displayDate , sampleDataWithCustomSchema } from "./scheduler-data" ;
7+ import { SchedulerMessageService } from "../../services/scheduler-message.service" ;
8+ import { MessageService } from "@progress/kendo-angular-l10n" ;
69
710@Component ( {
8- selector : 'app-scheduler' ,
9- standalone : true ,
10- imports : [ KENDO_SCHEDULER , KENDO_TOOLBAR , ReactiveFormsModule ] ,
11- templateUrl : './scheduler.component.html' ,
12- styleUrls : [ './scheduler.component.css' ]
11+ selector : "app-scheduler" ,
12+ standalone : true ,
13+ imports : [ KENDO_SCHEDULER , KENDO_TOOLBAR , KENDO_DROPDOWNLIST , ReactiveFormsModule ] ,
14+ providers : [ { provide : MessageService , useClass : SchedulerMessageService } ] ,
15+ templateUrl : "./scheduler.component.html" ,
16+ styleUrls : [ "./scheduler.component.css" ] ,
1317} )
1418export class SchedulerComponent implements OnInit {
15- public selectedDate : Date = displayDate ;
16- public events : any [ ] = [ ] ;
17- public currentView : string = 'day' ;
18- public modelFields = customModelFields ;
19- public orientation : 'horizontal' | 'vertical' = 'horizontal' ;
20- public formGroup ! : FormGroup ;
21- public group : any = { resources : [ 'Rooms' , 'Persons' ] }
22-
23- public resources = [
24- {
25- name : 'Rooms' ,
26- data : [
27- { text : 'Meeting Room 101' , value : 1 , color : "#5392E4" } ,
28- { text : 'Meeting Room 201' , value : 2 , color : '#FF7272' }
29- ] ,
30- field : 'RoomID' ,
31- valueField : 'value' ,
32- textField : 'text' ,
33- colorField : 'color'
34- } ,
35- {
36- name : 'Persons' ,
37- data : [
38- { text : 'Peter' , value : 1 , color : '#5392E4' } ,
39- { text : 'Alex' , value : 2 , color : '#54677B' }
40- ] ,
41- field : 'PersonIDs' ,
42- valueField : 'value' ,
43- textField : 'text' ,
44- colorField : 'color'
45- }
46- ] ;
19+ public selectedDate : Date = displayDate ;
20+ public events : any [ ] = [ ] ;
21+ public currentView : string = "day" ;
22+ public modelFields = customModelFields ;
23+ public orientation : "horizontal" | "vertical" = "horizontal" ;
24+ public formGroup ! : FormGroup ;
25+ public group : any = { resources : [ "Rooms" , "Persons" ] } ;
4726
48- constructor ( private formBuilder : FormBuilder ) {
49- this . createFormGroup = this . createFormGroup . bind ( this ) ;
50- }
27+ public resources = [
28+ {
29+ name : "Rooms" ,
30+ data : [
31+ { text : "Meeting Room 101" , value : 1 , color : "#5392E4" } ,
32+ { text : "Meeting Room 201" , value : 2 , color : "#FF7272" } ,
33+ ] ,
34+ field : "RoomID" ,
35+ valueField : "value" ,
36+ textField : "text" ,
37+ colorField : "color" ,
38+ } ,
39+ {
40+ name : "Persons" ,
41+ data : [
42+ { text : "Peter" , value : 1 , color : "#5392E4" } ,
43+ { text : "Alex" , value : 2 , color : "#54677B" } ,
44+ ] ,
45+ field : "PersonIDs" ,
46+ valueField : "value" ,
47+ textField : "text" ,
48+ colorField : "color" ,
49+ } ,
50+ ] ;
51+ public languages : any [ ] = [
52+ { text : "English" , value : "en" } ,
53+ { text : "Spanish" , value : "es" }
54+ ] ;
55+ public selectedLanguage : any = { text : "English" , value : "en-US" } ;
56+ constructor ( private formBuilder : FormBuilder , private messages : MessageService ) {
57+ this . createFormGroup = this . createFormGroup . bind ( this ) ;
58+ }
5159
52- ngOnInit ( ) : void {
53- this . events = sampleDataWithCustomSchema ;
54- }
60+ ngOnInit ( ) : void {
61+ this . events = sampleDataWithCustomSchema ;
62+ }
5563
56- public createFormGroup ( args : CreateFormGroupArgs ) : FormGroup {
57- const dataItem = args . dataItem ;
58- // const isOccurrence = args.isOccurrence;
64+ public createFormGroup ( args : CreateFormGroupArgs ) : FormGroup {
65+ const dataItem = args . dataItem ;
5966
60- const formGroup = this . formBuilder . group ( {
61- 'Id' : args . isNew ? this . getNextId ( ) : dataItem . TaskID ,
62- ' Title' : dataItem . Title ,
63- ' Start' : dataItem . Start ,
64- ' End' : dataItem . End ,
65- ' StartTimezone' : dataItem . StartTimezone ,
66- ' EndTimezone' : dataItem . EndTimezone ,
67- ' Description' : dataItem . Description ,
68- ' RecurrenceRule' : dataItem . RecurrenceRule ,
69- ' RecurrenceID' : dataItem . RecurrenceID ,
70- ' RecurrenceException' : dataItem . RecurrenceException ,
71- ' isAllDay' : dataItem . isAllDay ,
72- ' RoomID' : dataItem . RoomID ,
73- ' PersonIDs' : dataItem . PersonIDs
74- } ) ;
67+ const formGroup = this . formBuilder . group ( {
68+ Id : args . isNew ? this . getNextId ( ) : dataItem . TaskID ,
69+ Title : dataItem . Title ,
70+ Start : dataItem . Start ,
71+ End : dataItem . End ,
72+ StartTimezone : dataItem . StartTimezone ,
73+ EndTimezone : dataItem . EndTimezone ,
74+ Description : dataItem . Description ,
75+ RecurrenceRule : dataItem . RecurrenceRule ,
76+ RecurrenceID : dataItem . RecurrenceID ,
77+ RecurrenceException : dataItem . RecurrenceException ,
78+ isAllDay : dataItem . isAllDay ,
79+ RoomID : dataItem . RoomID ,
80+ PersonIDs : dataItem . PersonIDs ,
81+ } ) ;
7582
76- return formGroup ;
77- }
83+ return formGroup ;
84+ }
7885
79- public getNextId ( ) : number {
80- const len = this . events . length ;
81- return ( len > 0 ) ? this . events [ this . events . length - 1 ] . TaskID + 1 : 1 ;
82- }
86+ public getNextId ( ) : number {
87+ const len = this . events . length ;
88+ return len > 0 ? this . events [ this . events . length - 1 ] . TaskID + 1 : 1 ;
89+ }
8390
84- public handleViewChange ( view : string ) : void {
85- this . currentView = view ;
86- }
91+ public handleViewChange ( view : string ) : void {
92+ this . currentView = view ;
93+ }
8794
88- public handleDateChange ( date : Date ) : void {
89- this . selectedDate = date ;
90- }
95+ public handleDateChange ( date : Date ) : void {
96+ this . selectedDate = date ;
97+ }
9198
92- public handleDataChange ( { created, updated, deleted } : any ) : void {
93- this . events = this . events
94- . filter ( item => deleted . findIndex ( ( current : any ) => current . TaskID === item . TaskID ) === - 1 )
95- . map ( item => {
96- const updatedItem = updated . find ( ( current : any ) => current . TaskID === item . TaskID ) ;
97- return updatedItem ? updatedItem : item ;
98- } ) ;
99+ public handleDataChange ( { created, updated, deleted } : any ) : void {
100+ this . events = this . events
101+ . filter ( ( item ) => deleted . findIndex ( ( current : any ) => current . TaskID === item . TaskID ) === - 1 )
102+ . map ( ( item ) => {
103+ const updatedItem = updated . find ( ( current : any ) => current . TaskID === item . TaskID ) ;
104+ return updatedItem ? updatedItem : item ;
105+ } ) ;
99106
100- if ( created . length > 0 ) {
101- this . events = this . events . concat ( created ) ;
107+ if ( created . length > 0 ) {
108+ this . events = this . events . concat ( created ) ;
109+ }
102110 }
103- }
104111
105- public handleOrientationChange ( orientation : 'horizontal' | 'vertical' ) : void {
106- this . orientation = orientation ;
107- }
108- }
112+ public handleOrientationChange ( orientation : "horizontal" | "vertical" ) : void {
113+ this . orientation = orientation ;
114+ }
115+ public changeLanguage ( language : string ) : void {
116+ const svc = < SchedulerMessageService > this . messages ;
117+ svc . language = svc . language === "es" ? "en" : "es" ;
118+ }
119+ }
0 commit comments