Files
doneit-web/src/app/pages/agenda/view-event/view-event.page.ts
T
2021-06-18 11:08:55 +01:00

256 lines
6.8 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { AlertController, ModalController, NavParams, PopoverController } from '@ionic/angular';
import { AuthConnstants } from 'src/app/config/auth-constants';
import { Attachment } from 'src/app/models/attachment.model';
import { EventBody } from 'src/app/models/eventbody.model';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { EventsService } from 'src/app/services/events.service';
import { Event } from '../../../models/event.model';
import { EditEventPage } from '../edit-event/edit-event.page';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
import { ProcessesService } from 'src/app/services/processes.service';
import { ExpedientTaskModalPage } from '../../gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page';
import { BookMeetingModalPage } from '../../gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page';
import { OptsExpedientePage } from 'src/app/shared/popover/opts-expediente/opts-expediente.page';
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
@Component({
selector: 'app-view-event',
templateUrl: './view-event.page.html',
styleUrls: ['./view-event.page.scss'],
})
export class ViewEventPage implements OnInit {
loadedEvent: Event;
isEventEdited: boolean;
eventBody: EventBody;
loadedAttachments:any;
loadedEventAttachments: Attachment[];
pageId: string;
showLoader: boolean;
minDate: Date;
profile:string;
eventId:string;
customDate:any;
today:any;
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"];
dicIndex = 0;
constructor(
private modalController: ModalController,
/* private navParams: NavParams, */
private eventsService: EventsService,
private attachmentsService: AttachmentsService,
public alertController: AlertController,
private iab: InAppBrowser,
private processes: ProcessesService,
public popoverController: PopoverController,
private activatedRoute: ActivatedRoute,
private router: Router,
)
{
this.isEventEdited = false;
this.loadedEvent = new Event();
this.eventBody = { BodyType : "1", Text : ""};
this.loadedEvent.Body = this.eventBody;
this.activatedRoute.paramMap.subscribe(paramMap =>{
this.eventId = paramMap['params'].eventId;
});
/* this.activatedRoute.queryParams.subscribe(params => {
if(params["eventId"]) {
this.eventId = params["eventId"];
console.log(params["eventId"]);
}
}); */
}
ngOnInit() {
console.log('Notifi teste '+this.eventId);
this.loadEvent();
this.getAttachments();
window.onresize = (event) => {
// if not mobile remove all component
if( window.innerWidth >= 1024) {
this.modalController.dismiss(this.isEventEdited);
}
};
}
close(){
this.modalController.dismiss(this.isEventEdited);
}
goBack() {
this.activatedRoute.paramMap.subscribe(params => {
if(params["params"].caller == 'expediente'){
window.history.back();
}
else{
this.router.navigate(['/home',params["params"].caller]);
}
});
/* this.activatedRoute.queryParams.subscribe(params => {
if(params["caller"]) {
this.router.navigate(['/home',params["caller"]]);
}
}); */
}
loadEvent(){
this.eventsService.getEvent(this.eventId).subscribe(res => {
this.loadedEvent = res;
/* console.log(res); */
this.today = new Date(res.StartDate);
/* console.log(new Date(this.today)); */
this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]);
});
}
deleteEvent(){
this.eventsService.deleteEvent(this.loadedEvent.EventId, 0).subscribe(async () =>
{
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Evento removido',
buttons: ['OK']
});
setTimeout(()=>{
alert.dismiss();
}, 1500);
this.close();
});
}
getAttachments(){
try {
this.attachmentsService.getAttachmentsById(this.eventId).subscribe(res=>{
this.loadedAttachments = res;
console.log(res);
});
} catch (error) {
}
}
async editEventDetail() {
const modal = await this.modalController.create({
component: EditEventPage,
componentProps: {
eventId: this.loadedEvent.EventId,
profile: this.profile,
},
cssClass: 'modal modal-desktop',
});
await modal.present();
modal.onDidDismiss().then((res) => {
console.log(res);
if(res){
setTimeout(() => {
/* this.loadEvent(); */
this.loadEvent()
this.getAttachments();
}, 250);
this.isEventEdited = true;
}
});
}
async editEvent() {
let classs;
if( window.innerWidth <= 800){
classs = 'modal modal-desktop'
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: EditEventPage,
componentProps:{
event: this.loadedEvent,
profile: this.profile,
},
cssClass: classs,
});
await modal.present();
modal.onDidDismiss().then((res) => {
console.log(res);
if(res){
setTimeout(() => {
/* this.loadEvent(); */
this.loadEvent()
this.getAttachments();
}, 250);
this.isEventEdited = true;
}
});
}
viewDocument(sourceId){
this.processes.GetDocumentUrl(sourceId, '8').subscribe(res=>{
/* console.log(res); */
const url: string = res.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
const browser = this.iab.create(url,"_blank");
browser.show();
});
}
async openTaskOptions() {
const doc = this.loadedAttachments[this.dicIndex];
let customTask = {
serialNumber: doc.SourceId,
taskStartDate: doc.CreateDate,
isEvent: true,
workflowInstanceDataFields: {
FsId: doc.ApplicationId,
FolderID: null,
DocId: doc.SourceId,
Subject: doc.SourceName
},
}
const popover = await this.popoverController.create({
component: OptsExpedientePage,
cssClass: 'exp-options',
componentProps: {
fulltask: customTask,
task: customTask
},
translucent: true
});
return await popover.present();
}
docIndex(index: number){
this.dicIndex = index
}
}