Files
doneit-web/src/app/pages/events/events.page.ts
T

393 lines
12 KiB
TypeScript
Raw Normal View History

2021-06-10 23:24:42 +01:00
import { Component, OnInit, LOCALE_ID, EventEmitter, Output, Renderer2, ElementRef } from '@angular/core';
import { Event } from '../../models/event.model';
import { EventsService } from 'src/app/services/events.service';
2021-03-31 16:47:14 +01:00
import { NavigationExtras, Router } from '@angular/router';
import { ActivatedRoute, NavigationEnd } from '@angular/router';
import { AlertService } from 'src/app/services/alert.service';
2020-08-28 15:28:38 +01:00
import { AuthService } from 'src/app/services/auth.service';
2020-11-24 13:46:13 +01:00
import { StorageService } from 'src/app/services/storage.service';
2021-08-17 09:53:06 +01:00
import { ModalController, Platform } from '@ionic/angular';
2020-11-24 13:46:13 +01:00
import { EventDetailPage } from './event-detail/event-detail.page';
2021-01-04 10:37:13 +01:00
import { ProcessesService } from '../../services/processes.service';
import { DailyWorkTask } from '../../models/dailyworktask.model';
2021-05-21 10:38:55 +01:00
import { User } from 'src/app/models/user.model';
2021-07-20 19:22:56 +01:00
import { ToDayEventStorage } from 'src/app/store/to-day-event-storage.service';
2021-08-17 09:53:06 +01:00
import { ExpedienteStorage } from 'src/app/store/expediente-storage-service.service';
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
@Component({
selector: 'app-events',
templateUrl: './events.page.html',
styleUrls: ['./events.page.scss'],
})
export class EventsPage implements OnInit {
2020-08-21 16:18:37 +01:00
/* Get current system date */
today = new Date();
2021-07-29 14:37:09 +01:00
2020-08-21 16:18:37 +01:00
months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
2020-08-21 16:18:37 +01:00
customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]);
2020-08-21 16:18:37 +01:00
/* Setting appropriate greeting according to the time */
grettings = ["Bom dia", "Boa tarde", "Boa noite"];
greetting='';
2020-08-21 16:18:37 +01:00
timeDate = this.today.getHours() + ":" + this.today.getMinutes();
/* Set segment variable */
segment:string;
public profile:string;
2021-01-05 13:58:15 +01:00
currentEvent: any;
2021-06-23 15:42:55 +01:00
eventsList: Event[];
2021-06-24 11:07:53 +01:00
maxSubjectLength = 30;
officialeventsList: Event[];
personaleventsList: Event[];
prEventList: Event[];
mdEventList: Event[];
combinedEvents: Event[];
customText = false;
2021-01-04 10:37:13 +01:00
totalEvent=0;
2021-02-10 03:26:26 +01:00
currentHoursMinutes: Date;
2020-08-28 11:45:50 +01:00
showLoader: boolean;
2021-07-29 14:37:09 +01:00
2021-07-16 21:08:28 +01:00
taskslist:DailyWorkTask[] = [];
2021-02-10 16:02:38 +01:00
expedientList:any;
2021-07-30 14:11:19 +01:00
hideSearchBtn: boolean=false;
2021-07-20 19:22:56 +01:00
// shared data
toDayEventStorage = ToDayEventStorage
expedienteStorage = ExpedienteStorage
2021-03-31 13:52:40 +01:00
@Output() openExpedientListPage:EventEmitter<any> = new EventEmitter<any>();
2021-05-21 10:38:55 +01:00
loggeduser: User;
2021-08-17 09:53:06 +01:00
existingScreenOrientation: string;
2021-08-25 16:02:40 +01:00
pdfSrc = "https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf";
2021-06-10 23:24:42 +01:00
constructor(
2021-07-29 14:37:09 +01:00
private eventService: EventsService,
private router: Router,
2020-11-24 13:46:13 +01:00
private storageService:StorageService,
public activatedRoute: ActivatedRoute,
2020-08-28 15:28:38 +01:00
private alertController: AlertService,
private authService: AuthService,
2021-02-18 12:44:35 +01:00
private processes:ProcessesService,
2021-03-31 14:50:04 +01:00
/* private gabineteService: GabineteDigitalPage, */
2021-06-10 23:24:42 +01:00
private modalController:ModalController,
2021-08-17 09:53:06 +01:00
private screenOrientation: ScreenOrientation,
public platform: Platform,
2021-06-10 23:24:42 +01:00
) {
2021-08-17 09:53:06 +01:00
this.existingScreenOrientation = this.screenOrientation.type;
console.log(this.existingScreenOrientation);
2021-05-21 10:38:55 +01:00
2021-08-17 09:53:06 +01:00
this.loggeduser = authService.ValidatedUser;
2021-05-21 10:38:55 +01:00
this.prEventList = null;
2021-08-17 09:53:06 +01:00
this.platform.resize.subscribe(async () => {
2021-08-18 15:57:19 +01:00
//console.log('Resize event detected');
2021-08-17 09:53:06 +01:00
console.log('Resize event detected');
});
2021-07-20 19:22:56 +01:00
}
2020-08-21 16:18:37 +01:00
ngOnInit() {
2021-08-18 12:52:51 +01:00
this.segment = "Combinada";
2021-02-11 15:23:03 +01:00
this.profile = "mdgpr";
2021-01-04 10:37:13 +01:00
2020-08-21 16:18:37 +01:00
this.showGreeting();
this.router.events.forEach((event) => {
2021-08-18 12:52:51 +01:00
if(event instanceof NavigationEnd && event.url == '/home/events') {
this.RefreshEvents();
2021-04-07 09:32:17 +01:00
this.LoadList();
}
});
2021-07-30 14:11:19 +01:00
this.hideSearch();
2021-08-17 09:53:06 +01:00
//this.checkScreenOrientation();
2021-07-30 14:11:19 +01:00
}
hideSearch(){
if(this.router.url == '/home/events'){
this.hideSearchBtn = true;
}
}
doRefresh(event) {
this.RefreshEvents();
2021-04-06 16:25:20 +01:00
this.LoadList();
2021-04-07 09:32:17 +01:00
event.target.complete();
}
2021-07-20 19:22:56 +01:00
onSegmentChange() {
this.RefreshEvents();
}
2021-08-17 09:53:06 +01:00
// Lock to portrait
lockToPortrait(){
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
console.log('set');
}
// Lock to landscape
lockToLandscape(){
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
}
// Unlock screen orientation
unlockScreenOrientation(){
this.screenOrientation.unlock();
}
checkScreenOrientation(){
if( window.innerWidth < 701) {
this.lockToPortrait();
console.log('was here');
}
else{
this.unlockScreenOrientation();
}
}
2021-07-20 19:22:56 +01:00
async RefreshEvents() {
2021-04-01 10:34:41 +01:00
this.currentEvent = "";
this.showLoader = true;
2021-02-10 03:26:26 +01:00
2021-02-09 15:39:39 +01:00
let date = new Date();
date.setMonth(date.getMonth() + 1);
let start = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds();
let end = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" 23:59:59";
2021-07-29 14:37:09 +01:00
2021-07-20 19:22:56 +01:00
if(this.loggeduser.Profile == 'MDGPR') {
2021-06-16 13:29:57 +01:00
let mdOficialEvents = await this.eventService.getAllMdOficialEvents(start, end).toPromise();
let mdPessoalEvents = await this.eventService.getAllMdPessoalEvents(start, end).toPromise();
2021-07-29 14:37:09 +01:00
2021-07-20 19:22:56 +01:00
const list = mdOficialEvents.concat(mdPessoalEvents);
this.toDayEventStorage.reset(list)
2021-07-29 14:37:09 +01:00
2021-07-20 19:22:56 +01:00
if(this.toDayEventStorage.eventsList.length > 0){
this.currentEvent = this.toDayEventStorage.eventsList[0].Subject;
this.currentHoursMinutes = this.toDayEventStorage.eventsList[0].StartDate;
}
2021-07-29 14:37:09 +01:00
2021-07-20 19:22:56 +01:00
this.totalEvent = this.toDayEventStorage.eventsList.length;
this.showLoader = false;
2021-07-29 14:37:09 +01:00
2021-06-16 13:29:57 +01:00
}
2021-07-20 19:22:56 +01:00
else if (this.loggeduser.Profile == 'PR') {
2021-06-16 13:29:57 +01:00
let prOficialEvents= await this.eventService.getAllPrOficialEvents(start, end).toPromise();
let prPessoalEvents= await this.eventService.getAllPrPessoalEvents(start, end).toPromise();
2021-07-29 14:37:09 +01:00
2021-07-20 19:22:56 +01:00
const list = prOficialEvents.concat(prPessoalEvents);
2021-06-16 13:29:57 +01:00
2021-07-20 19:22:56 +01:00
this.toDayEventStorage.reset(list)
2021-06-16 13:29:57 +01:00
2021-07-20 19:22:56 +01:00
if(this.toDayEventStorage.eventsList.length > 0) {
this.currentEvent = this.toDayEventStorage.eventsList[0].Subject;
this.currentHoursMinutes = this.toDayEventStorage.eventsList[0].StartDate;
}
this.totalEvent = this.toDayEventStorage.eventsList.length;
this.showLoader = false;
2021-07-29 14:37:09 +01:00
2021-06-16 13:29:57 +01:00
}
/* switch (this.segment)
{
case "Combinada":
2021-05-21 10:38:55 +01:00
if(this.loggeduser.Profile == 'MDGPR'){
2021-06-15 17:42:51 +01:00
2021-06-16 13:29:57 +01:00
let mdOficialEvents = await this.eventService.getAllMdOficialEvents(start, end).toPromise();
let mdPessoalEvents = await this.eventService.getAllMdPessoalEvents(start, end).toPromise();
2021-07-29 14:37:09 +01:00
2021-06-15 17:42:51 +01:00
this.eventsList = mdOficialEvents.concat(mdPessoalEvents);
2021-07-29 14:37:09 +01:00
2021-06-15 17:42:51 +01:00
if(this.eventsList.length > 0){
this.currentEvent = this.eventsList[0].Subject;
this.currentHoursMinutes = this.eventsList[0].StartDate;
2021-01-13 10:02:30 +01:00
}
2021-07-29 14:37:09 +01:00
2021-01-05 13:58:15 +01:00
this.totalEvent = this.eventsList.length;
2020-08-28 11:45:50 +01:00
this.showLoader = false;
2021-07-29 14:37:09 +01:00
2021-06-15 17:42:51 +01:00
}
else{
let prOficialEvents= await this.eventService.getAllPrOficialEvents(start, end).toPromise();
let prPessoalEvents= await this.eventService.getAllPrPessoalEvents(start, end).toPromise();
this.eventsList = prOficialEvents.concat(prPessoalEvents);
console.log(this.eventsList);
console.log(this.eventsList);
if(this.eventsList.length > 0){
this.currentEvent = this.eventsList[0].Subject;
this.currentHoursMinutes = this.eventsList[0].StartDate;
}
this.totalEvent = this.eventsList.length;
this.showLoader = false;
2021-07-29 14:37:09 +01:00
}
2021-07-29 14:37:09 +01:00
break;
case "Pessoal":
2021-05-21 10:38:55 +01:00
if(this.loggeduser.Profile == 'MDGPR'){
2021-06-15 17:42:51 +01:00
this.eventService.getAllMdPessoalEvents(start, end).subscribe(res => {
this.personaleventsList = res.filter(data => data.CalendarName == "Pessoal");
this.showLoader = false;
});
2021-06-15 17:42:51 +01:00
}
else{
this.eventService.getAllPrPessoalEvents(start, end).subscribe(res => {
2020-11-20 17:02:48 +01:00
this.personaleventsList = res.filter(data => data.CalendarName == "Pessoal");
this.showLoader = false;
});
}
2021-07-29 14:37:09 +01:00
break;
case "Oficial":
2021-05-21 10:38:55 +01:00
if(this.loggeduser.Profile == 'MDGPR'){
2021-06-15 17:42:51 +01:00
this.eventService.getAllMdOficialEvents(start, end).subscribe(res => {
this.officialeventsList = res.filter(data => data.CalendarName == "Oficial");;
this.showLoader = false;
});
2021-06-15 17:42:51 +01:00
}
else{
this.eventService.getAllPrOficialEvents(start, end).subscribe(res => {
2020-11-20 17:02:48 +01:00
this.officialeventsList = res.filter(data => data.CalendarName == "Oficial");;
this.showLoader = false;
});
2021-07-29 14:37:09 +01:00
}
break;
2021-06-16 13:29:57 +01:00
} */
}
2020-08-21 16:18:37 +01:00
showGreeting(){
if(this.today.getHours() >= 6 && this.today.getHours() < 12){
this.greetting = this.grettings[0];
}
else if(this.today.getHours() >= 12 && this.today.getHours() < 18){
this.greetting = this.grettings[1];
}
else /* if(this.today.getHours() < 6 && this.today.getHours() >= 18) */{
this.greetting = this.grettings[2];
}
}
2020-08-21 16:18:37 +01:00
gotTo(){
this.router.navigate(['/home/events']);
}
changeProfile(){
if(this.profile == "mdgpr"){
console.log('pr');
this.profile ="pr";
this.RefreshEvents();
}
else{
console.log('mdgpr');
this.profile ="mdgpr";
this.RefreshEvents();
}
}
2020-08-28 15:28:38 +01:00
logout()
{
this.authService.ValidatedUser.BasicAuthKey = "";
this.router.navigate(['/home/login']);
}
2020-11-24 13:46:13 +01:00
async openEventDetail1(id:any){
console.log(id);
2021-07-29 14:37:09 +01:00
2020-11-24 13:46:13 +01:00
const modal = await this.modalController.create({
component: EventDetailPage,
componentProps: {
eventId: id,
},
cssClass: 'event-detail',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
2021-07-20 19:22:56 +01:00
LoadList() {
2021-05-26 08:53:26 +01:00
switch (this.loggeduser.Profile) {
case 'MDGPR':
this.processes.GetTasksList("Expediente", false).subscribe(result => {
2021-07-29 14:37:09 +01:00
console.log(result);
2021-07-26 15:30:41 +01:00
this.expedienteStorage.reset(result)
2021-05-26 08:53:26 +01:00
});
break;
case 'PR':
2021-08-10 09:40:14 +01:00
this.processes.GetTasksList("Expediente", false).subscribe(result => {
2021-07-26 15:30:41 +01:00
this.expedienteStorage.reset(result)
2021-05-26 08:53:26 +01:00
});
2021-07-29 14:37:09 +01:00
break;
2021-05-26 08:53:26 +01:00
default:
break;
}
}
2021-01-19 08:52:43 +01:00
sortArrayISODate(myArray: any){
return myArray.sort(function(a, b) {
return (a.CreateDate < b.CreateDate) ? -1 : ((a.CreateDate > b.CreateDate) ? 1 : 0);
});
}
2021-01-19 16:44:39 +01:00
2021-06-10 15:38:08 +01:00
goToEvent(eventId:any){
2021-06-10 23:24:42 +01:00
this.router.navigate(['/home/events', eventId, 'events']);
2021-01-31 16:14:42 +01:00
}
2021-06-10 23:24:42 +01:00
goToExpediente(SerialNumber:any){
2021-07-01 15:53:48 +01:00
if(this.loggeduser.Profile == 'MDGPR'){
this.router.navigate(['/home/events/expediente', SerialNumber, 'events']);
}
else if(this.loggeduser.Profile == 'PR'){
this.router.navigate(['/home/events/expedientes-pr', SerialNumber, 'events']);
}
2021-05-24 11:37:50 +01:00
}
2021-03-31 13:52:40 +01:00
viewExpedientListPage(){
2021-07-01 15:53:48 +01:00
if(this.loggeduser.Profile == 'MDGPR'){
if( window.innerWidth < 801){
this.router.navigate(['/home/gabinete-digital/expediente']);
}
else{
let navigationExtras: NavigationExtras = { queryParams: {"expedientes": true,} };
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
2021-03-31 13:52:40 +01:00
}
2021-07-01 15:53:48 +01:00
else if(this.loggeduser.Profile == 'PR'){
if( window.innerWidth < 801){
this.router.navigate(['/home/gabinete-digital/expedientes-pr']);
}
else{
let navigationExtras: NavigationExtras = { queryParams: {"expedientes-pr": true,} };
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
2021-03-31 13:52:40 +01:00
}
}
2021-07-29 14:37:09 +01:00
}