123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- using Comal.Classes.SecurityDescriptors;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms.Xaml;
- namespace PRS.Mobile
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class HumanResourcesModule
- {
- private CancellationTokenSource _pollingToken;
-
- public HumanResourcesModule()
- {
- InitializeComponent();
- MyDetails.IsVisible = Security.IsAllowed<ViewMobileEmployeeDetailsModule>();
- DigitalForms.IsVisible = Security.IsAllowed<ViewMobileEmployeeFormsModule>();
- LeaveRequests.IsVisible = Security.IsAllowed<ViewMobileLeaveRequestsModule>();
- Qualifications.IsVisible = Security.IsAllowed<ViewMobileQualificationsModule>();
- TimeSheets.IsVisible = Security.IsAllowed<ViewMobileTimesheetsModule>();
- }
- protected override void OnAppearing()
- {
- _pollingToken = new CancellationTokenSource();
- StartMonitoringQualifications();
- StartMonitoringForms();
- base.OnAppearing();
- }
- protected override void OnDisappearing()
- {
- base.OnDisappearing();
- _pollingToken.Cancel();
- }
- private void StartMonitoringQualifications()
- {
- var token = _pollingToken.Token;
- Task.Run(() =>
- {
- while (!_pollingToken.Token.IsCancellationRequested)
- {
- App.Data.EmployeeQualifications.Refresh(true);
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- Qualifications.Alert = App.Data.EmployeeQualifications.NeedsAttention > 0
- ? App.Data.EmployeeQualifications.NeedsAttention.ToString()
- : "";
- });
-
- Task.Delay(TimeSpan.FromSeconds(30), token)
- .Wait(token);
- }
- },
- token
- );
- }
-
- private void StartMonitoringForms()
- {
- var token = _pollingToken.Token;
- Task.Run(() =>
- {
- while (!_pollingToken.Token.IsCancellationRequested)
- {
- App.Data.EmployeeForms.Refresh(true);
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- DigitalForms.Alert = App.Data.EmployeeForms.NeedsAttention > 0
- ? App.Data.EmployeeForms.NeedsAttention.ToString()
- : "";
- });
-
- Task.Delay(TimeSpan.FromSeconds(30), token)
- .Wait(token);
- }
- },
- token
- );
- }
-
- private void MyDetails_OnTapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new MyDetailsPage());
- }
-
- private void QualificationsBtn_Tapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new EmployeeQualificationList());
- }
-
- private void EmployeeFormsBtn_Tapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new EmployeeForms());
- }
-
- private void LeaveBtn_Tapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new LeaveRequestList());
- }
-
- private void TimesheetsBtn_Tapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new MyTimesheets());
- }
-
- }
- }
|