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

350 lines
9.9 KiB
TypeScript
Raw Normal View History

2020-08-21 16:18:37 +01:00
import { Component, OnInit, LOCALE_ID } from '@angular/core';
import { Event } from '../../models/event.model';
import { EventsService } from 'src/app/services/events.service';
import { Router } from '@angular/router';
import { ActivatedRoute, NavigationEnd } from '@angular/router';
2020-08-21 16:18:37 +01:00
import { formatDate } from '@angular/common';
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';
import { AuthConnstants } from 'src/app/config/auth-constants';
import { ModalController } from '@ionic/angular';
import { EventDetailPage } from './event-detail/event-detail.page';
import { EventDetailModalPage } from './event-detail-modal/event-detail-modal.page';
2021-01-04 10:37:13 +01:00
import { ProcessesService } from '../../services/processes.service';
import { DailyWorkTask } from '../../models/dailyworktask.model';
2021-01-31 16:14:42 +01:00
import { ViewEventPage } from '../agenda/view-event/view-event.page';
2021-02-01 09:17:38 +01:00
import { ExpedientePage } from '../gabinete-digital/expediente/expediente.page';
2021-02-01 13:21:41 +01:00
import { ExpedienteDetailPage } from '../gabinete-digital/expediente/expediente-detail/expediente-detail.page';
@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-02-08 16:55:55 +01:00
todayEnd = new Date();
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;
eventsList: Event[];
officialeventsList: Event[];
personaleventsList: Event[];
prEventList: Event[];
mdEventList: Event[];
combinedEvents: Event[];
customText = false;
2021-01-04 10:37:13 +01:00
totalEvent=0;
currentHoursMinutes: String;
2020-08-28 11:45:50 +01:00
showLoader: boolean;
taskslist:DailyWorkTask[];
constructor(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,
2020-11-24 13:46:13 +01:00
private modalController: ModalController,
private authService: AuthService,
private processes:ProcessesService) {
this.prEventList = null;
// update hours and minutes
setInterval(()=> {
this.currentHoursMinutes = formatDate(new Date(), 'HH:MM', 'pt');
}, 1000);
// list
this.LoadList();
2021-02-08 16:55:55 +01:00
this.todayEnd = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 23, 59, 59);
}
2020-08-21 16:18:37 +01:00
2021-01-16 17:44:38 +01:00
swipe(){
console.log('!!!!');
}
2020-08-21 16:18:37 +01:00
ngOnInit() {
//Inicializar segment
this.segment = "Combinada";
//Initialize profile as mdgpr
2020-11-26 09:04:22 +01:00
this.profile = "mdgpr";
2020-11-24 13:46:13 +01:00
console.log(this.profile);
2021-01-04 10:37:13 +01:00
// set event list
/* if(this.profile == "mdgpr"){
this.eventService.getAllMdEvents(formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss', 'pt'), formatDate(new Date(), 'yyyy-MM-dd', 'pt') + ' 23:59:59').subscribe(res => {
2021-01-04 10:37:13 +01:00
this.eventsList = res;
console.log(this.eventsList);
2021-01-04 10:37:13 +01:00
this.totalEvent = this.eventsList.length;
});
}
else{
this.eventService.getAllPrEvents(formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss', 'pt'), formatDate(new Date(), 'yyyy-MM-dd', 'pt') + ' 23:59:59').subscribe(res => {
2021-01-04 10:37:13 +01:00
this.eventsList = res;
this.totalEvent = this.eventsList.length;
});
} */
2021-01-19 10:44:55 +01:00
this.storageService.get(AuthConnstants.USER).then(res=>{
console.log(res);
});
2020-08-21 16:18:37 +01:00
this.showGreeting();
this.router.events.forEach((event) => {
if(event instanceof NavigationEnd && event.url == this.router.url) {
this.RefreshEvents();
}
});
2020-11-24 13:46:13 +01:00
/* this.storageService.get(AuthConnstants.PROFILE).then(res=>{
this.profile = res;
}); */
}
doRefresh(event) {
this.RefreshEvents();
2020-08-28 13:38:10 +01:00
event.target.complete();
}
onSegmentChange(){
this.RefreshEvents();
}
RefreshEvents(){
this.showLoader = true;
switch (this.segment)
{
case "Combinada":
if(this.profile == "mdgpr"){
2021-02-08 16:55:55 +01:00
this.eventService.getAllMdEvents(this.today.toLocaleString(), this.todayEnd.toLocaleString()).subscribe(res => {
this.eventsList = res;
2021-01-19 08:52:43 +01:00
2021-01-13 10:02:30 +01:00
if(res.length > 0){
this.currentEvent = res[0].Subject;
}
2021-01-19 08:52:43 +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;
});
}else{
2021-02-08 16:55:55 +01:00
this.eventService.getAllPrEvents(this.today.toLocaleString(), this.todayEnd.toLocaleString()).subscribe(res => {
2020-11-20 17:02:48 +01:00
this.eventsList = res;
console.log(this.eventsList);
2021-01-15 08:16:36 +01:00
console.log(res)
console.log(res[0])
2021-01-05 13:58:15 +01:00
this.currentEvent = res[0].Subject;
this.totalEvent = this.eventsList.length;
this.showLoader = false;
});
}
break;
case "Pessoal":
if(this.profile == "mdgpr"){
2021-02-08 16:55:55 +01:00
this.eventService.getAllMdEvents(this.today.toLocaleString(), this.todayEnd.toLocaleString()).subscribe(res => {
this.personaleventsList = res.filter(data => data.CalendarName == "Pessoal");
this.showLoader = false;
});
}else{
2021-02-08 16:55:55 +01:00
this.eventService.getAllPrEvents(this.today.toLocaleString(), this.todayEnd.toLocaleString()).subscribe(res => {
2020-11-20 17:02:48 +01:00
this.personaleventsList = res.filter(data => data.CalendarName == "Pessoal");
this.showLoader = false;
});
}
break;
case "Oficial":
if(this.profile == "mdgpr"){
2021-02-08 16:55:55 +01:00
this.eventService.getAllMdEvents(this.today.toLocaleString(), this.todayEnd.toLocaleString()).subscribe(res => {
this.officialeventsList = res.filter(data => data.CalendarName == "Oficial");;
this.showLoader = false;
});
}else{
2021-02-08 16:55:55 +01:00
this.eventService.getAllPrEvents(this.today.toLocaleString(), this.todayEnd.toLocaleString()).subscribe(res => {
2020-11-20 17:02:48 +01:00
this.officialeventsList = res.filter(data => data.CalendarName == "Oficial");;
this.showLoader = false;
});
}
break;
}
}
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);
const modal = await this.modalController.create({
component: EventDetailPage,
componentProps: {
eventId: id,
},
cssClass: 'event-detail',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
async openEventDetail(id:any) {
const modal = await this.modalController.create({
component: EventDetailModalPage,
componentProps: {
eventId: id,
},
cssClass: 'my-custom-class'
});
return await modal.present();
}
/**
* @returns time in format HH:MM
*/
get hoursMinutes():String {
return this.currentHoursMinutes;
}
LoadList()
{
this.processes.GetTasksList("Expediente", false).subscribe(result => {
2021-01-19 08:52:43 +01:00
const AllResult = new Array();
result.forEach(element => {
let task: DailyWorkTask = {
"SerialNumber": element.serialNumber,
"Folio": element.workflowInstanceFolio,
"Senders": element.originator.email,
2021-02-08 16:55:55 +01:00
"CreateDate": new Date(element.taskStartDate).toLocaleString(),
"DocumentURL": element.formURL,
"Remetente": element.workflowInstanceDataFields.Remetente
}
2021-01-19 08:52:43 +01:00
// CreateDate
AllResult.push(task);
});
2021-01-19 08:52:43 +01:00
console.log(AllResult);
this.taskslist = this.sortArrayISODate(AllResult).reverse()
});
}
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-01-31 16:14:42 +01:00
async viewEventDetail(eventId:any) {
console.log(this.profile);
const modal = await this.modalController.create({
component: ViewEventPage,
componentProps:{
eventId: eventId,
profile: this.profile,
},
cssClass: 'modal',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then((res)=>{
if(res){
console.log(res);
this.RefreshEvents();
}
});
}
2021-02-01 13:21:41 +01:00
async viewExpedientDetail(serialNumber:any) {
2021-02-01 09:17:38 +01:00
console.log(this.profile);
const modal = await this.modalController.create({
2021-02-01 13:21:41 +01:00
component: ExpedienteDetailPage,
2021-02-01 09:17:38 +01:00
componentProps:{
serialNumber: serialNumber,
profile: this.profile,
},
cssClass: 'modal',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then((res)=>{
if(res){
console.log(res);
this.RefreshEvents();
}
});
}
2021-01-19 08:52:43 +01:00
}