Files
doneit-web/src/app/pages/agenda/view-event/view-event.page.ts
T

144 lines
4.0 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
import { AlertController, ModalController, NavParams } 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';
2021-02-01 13:21:41 +01:00
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
@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"];
constructor(
private modalController: ModalController,
private navParams: NavParams,
private eventsService: EventsService,
private attachmentsService: AttachmentsService,
public alertController: AlertController,
2021-02-01 13:21:41 +01:00
private iab: InAppBrowser,
)
{
2021-01-31 16:14:42 +01:00
this.profile = this.navParams.get('profile');
this.isEventEdited = false;
this.loadedEvent = new Event();
this.eventBody = { BodyType : "1", Text : ""};
this.loadedEvent.Body = this.eventBody;
this.eventId = this.navParams.get('eventId');
}
ngOnInit() {
/* console.log(this.eventId); */
this.loadEvent();
this.getAttachments();
2021-02-24 20:23:15 +01:00
window.onresize = (event) => {
// if not mobile remove all component
if( window.innerWidth >= 1024){
this.modalController.dismiss(this.isEventEdited);
}
};
}
close(){
console.log(this.isEventEdited);
this.modalController.dismiss(this.isEventEdited);
}
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']
});
await alert.present();
this.close();
});
}
getAttachments(){
this.attachmentsService.getAttachmentsById(this.eventId).subscribe(res=>{
this.loadedAttachments = res;
console.log(res);
});
}
async editEvent() {
2021-04-01 15:06:05 +01:00
let classs;
if( window.innerWidth <= 800){
classs = 'modal'
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: EditEventPage,
componentProps:{
event: this.loadedEvent,
profile: this.profile,
},
2021-04-01 15:06:05 +01:00
cssClass: classs,
});
await modal.present();
modal.onDidDismiss().then((res) => {
console.log(res);
if(res){
setTimeout(() => {
/* this.loadEvent(); */
this.getAttachments();
}, 250);
this.isEventEdited = true;
}
});
}
2021-04-01 15:06:05 +01:00
2021-02-01 13:21:41 +01:00
viewDocument(){
const url: string = this.loadedAttachments.DocumentURL.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
const browser = this.iab.create(url,"_blank");
browser.show();
}
}