import { Component, OnInit, Input } from '@angular/core'; import { IStaff } from '../../shared/core/IStaff'; import { StaffService } from '../../shared/service/staff.service'; import { DialogService } from 'primeng/api'; import { NewStaffComponent } from '../../new-staff/new-staff.component'; import { CommonService } from '../../shared/service/common.service'; import { ILocalisation } from '../../shared/core/ILocalisation'; import { ILanguage } from '../../shared/core/ILanguage'; import { IDateFormat } from '../../shared/core/IDateFormat'; import { ITimeFormat } from '../../shared/core/ITimeFormat'; import { ICalendarStart } from '../../shared/core/ICalendarStart'; import { ITimeZone } from '../../shared/core/ITimeZone'; @Component({ selector: 'app-staff-dashboard', templateUrl: './staff-dashboard.component.html', styleUrls: ['./staff-dashboard.component.css'], providers:[StaffService,DialogService,CommonService] }) export class StaffDashboardComponent implements OnInit { @Input() staff:IStaff; localisation: ILocalisation; selectedLanguages:ILanguage; selectedDateFormat:IDateFormat; selectedTimeFormat:ITimeFormat; selectedCalendarStart:ICalendarStart; selectedTimeZone:ITimeZone; constructor(private staffService:StaffService,public dialogService: DialogService,private commonService: CommonService) { } ngOnInit() { // initialize component this.selectedLanguages = { Id: 0, Code: '', IsSelected: false, Name: '' }; this.selectedDateFormat = { Id: 0, Format: '', IsSelected: false, Name: '' }; this.selectedTimeFormat = { Id: 0, TimeFormat: '', IsSelected: false, Name: '' }; this.selectedCalendarStart = { Id: 0, IsSelected: false, Name: '' }; this.selectedTimeZone = { Id: 0, TimeZone: '', IsSelected: false, Name: '' }; this.getLocalisation(); } ngOnChanges(changes) { this.ngOnInit(); } //show edit staff dialog box showEditStaff(id:string, index:number=0) { const ref = this.dialogService.open(NewStaffComponent, { data: { id: id, activeTabIndex:index }, header: (id=='-1') ? 'Invite Staff' : 'Edit staff', width: '80%', closable:false }); // execute when close the add new popup ref.onClose.subscribe(data=>{ // for editing if(id!="" && id != null && id !=undefined && id !="-1"){ this.staffService.getStaffList(id, null).subscribe(staff=> { // update the edited staff this.staff = staff[0]; }); } }); } // get staff localisation getLocalisation(){ this.commonService.getLocalisationSettings(this.staff.Id, 'STF').subscribe(localisation => { this.localisation = localisation; this.selectedLanguages = (localisation.Languages.find(x=>x.IsSelected==true)) ? localisation.Languages.find(x=>x.IsSelected) :localisation.Languages[0]; this.selectedDateFormat = (localisation.DateFormat.find(x=>x.IsSelected==true)) ? localisation.DateFormat.find(x=>x.IsSelected) :localisation.DateFormat[0]; this.selectedTimeFormat = (localisation.TimeFormat.find(x=>x.IsSelected==true)) ? localisation.TimeFormat.find(x=>x.IsSelected) :localisation.TimeFormat[0]; this.selectedCalendarStart = (localisation.CalendarStart.find(x=>x.IsSelected==true)) ? localisation.CalendarStart.find(x=>x.IsSelected) :localisation.CalendarStart[0]; this.selectedTimeZone = (localisation.TimeZone.find(x=>x.IsSelected==true)) ? localisation.TimeZone.find(x=>x.IsSelected) :localisation.TimeZone[0]; }); } }