2021-01-29 09:45:27 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-06-08 15:59:06 +01:00
|
|
|
import { AlertController, AnimationController, ModalController, NavParams } from '@ionic/angular';
|
2021-04-23 10:35:53 +01:00
|
|
|
import { Attachment } from 'src/app/models/attachment.model';
|
2021-01-31 01:40:19 +01:00
|
|
|
import { EventBody } from 'src/app/models/eventbody.model';
|
|
|
|
|
import { EventPerson } from 'src/app/models/eventperson.model';
|
|
|
|
|
import { AlertService } from 'src/app/services/alert.service';
|
2021-04-23 10:35:53 +01:00
|
|
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
2021-01-31 01:40:19 +01:00
|
|
|
import { EventsService } from 'src/app/services/events.service';
|
2021-06-08 15:59:06 +01:00
|
|
|
import { BadRequestPage } from 'src/app/shared/popover/bad-request/bad-request.page';
|
|
|
|
|
import { SuccessMessagePage } from 'src/app/shared/popover/success-message/success-message.page';
|
2021-01-31 01:40:19 +01:00
|
|
|
import { Event } from '../../../models/event.model';
|
|
|
|
|
import { AttendeesPage } from '../../events/attendees/attendees.page';
|
2021-04-23 10:35:53 +01:00
|
|
|
import { SearchPage } from '../../search/search.page';
|
2021-01-29 09:45:27 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-edit-event',
|
|
|
|
|
templateUrl: './edit-event.page.html',
|
|
|
|
|
styleUrls: ['./edit-event.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class EditEventPage implements OnInit {
|
|
|
|
|
|
2021-01-31 01:40:19 +01:00
|
|
|
postEvent: Event;
|
|
|
|
|
isRecurring:string;
|
|
|
|
|
isEventEdited: boolean;
|
|
|
|
|
loadedEvent: Event;
|
|
|
|
|
eventBody: EventBody;
|
|
|
|
|
segment:string = "true";
|
|
|
|
|
profile:string;
|
|
|
|
|
eventAttendees: EventPerson[];
|
|
|
|
|
selectedSegment: string;
|
|
|
|
|
selectedDate: Date;
|
|
|
|
|
minDate: string;
|
|
|
|
|
|
2021-04-06 11:28:46 +01:00
|
|
|
|
2021-04-23 10:35:53 +01:00
|
|
|
loadedEventAttachments: Attachment[];
|
2021-04-06 11:28:46 +01:00
|
|
|
taskParticipants: any = [];
|
|
|
|
|
taskParticipantsCc: any = [];
|
|
|
|
|
adding: "intervenient" | "CC" = "intervenient";
|
|
|
|
|
|
2021-04-09 13:57:31 +01:00
|
|
|
|
|
|
|
|
showAttendees = false;
|
|
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalController: ModalController,
|
2021-01-31 01:40:19 +01:00
|
|
|
private navParams: NavParams,
|
|
|
|
|
private eventsService: EventsService,
|
|
|
|
|
public alertController: AlertController,
|
2021-04-23 10:35:53 +01:00
|
|
|
private attachmentsService: AttachmentsService,
|
2021-06-08 15:59:06 +01:00
|
|
|
private animationController: AnimationController,
|
2021-04-07 10:04:58 +01:00
|
|
|
) {
|
2021-01-31 01:40:19 +01:00
|
|
|
this.isEventEdited = false;
|
|
|
|
|
this.postEvent = this.navParams.get('event');
|
2021-04-23 10:35:53 +01:00
|
|
|
|
2021-04-08 09:14:28 +01:00
|
|
|
if(this.postEvent){
|
2021-04-23 10:35:53 +01:00
|
|
|
if( this.postEvent.Body){
|
|
|
|
|
if(typeof(this.postEvent.Body.Text) == 'string'){
|
|
|
|
|
this.postEvent.Body.Text = this.postEvent.Body.Text.replace(/<[^>]+>/g, '');
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-08 09:14:28 +01:00
|
|
|
}
|
2021-04-06 11:28:46 +01:00
|
|
|
|
2021-05-06 13:32:54 +01:00
|
|
|
if(this.postEvent.Attendees == null) {
|
2021-04-06 11:28:46 +01:00
|
|
|
this.taskParticipants = []
|
|
|
|
|
} else {
|
2021-04-08 13:39:48 +01:00
|
|
|
|
|
|
|
|
this.postEvent.Attendees.forEach(e =>{
|
|
|
|
|
if(e.IsRequired){
|
|
|
|
|
this.taskParticipants.push(e);
|
|
|
|
|
} else {
|
|
|
|
|
this.taskParticipantsCc.push(e);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-12 10:01:43 +01:00
|
|
|
if(this.postEvent.IsRecurring == false) {
|
2021-01-31 01:40:19 +01:00
|
|
|
this.isRecurring = "Não se repete";
|
|
|
|
|
}
|
2021-04-12 10:01:43 +01:00
|
|
|
else {
|
2021-01-31 01:40:19 +01:00
|
|
|
this.isRecurring = "Repete";
|
|
|
|
|
}
|
|
|
|
|
this.profile = this.navParams.get('profile');
|
2021-04-23 10:35:53 +01:00
|
|
|
|
|
|
|
|
this.getAttachments(this.postEvent.EventId);
|
2021-01-31 01:40:19 +01:00
|
|
|
}
|
2021-01-29 09:45:27 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-04-08 09:14:28 +01:00
|
|
|
|
2021-04-13 15:12:24 +01:00
|
|
|
|
2021-02-24 20:23:15 +01:00
|
|
|
window.onresize = (event) => {
|
|
|
|
|
// if not mobile remove all component
|
2021-05-06 13:32:54 +01:00
|
|
|
if( window.innerWidth >= 1024) {
|
2021-02-24 20:23:15 +01:00
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
2021-05-06 13:32:54 +01:00
|
|
|
}
|
2021-01-31 01:40:19 +01:00
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-04-12 10:01:43 +01:00
|
|
|
close() {
|
2021-01-31 01:40:19 +01:00
|
|
|
this.modalController.dismiss();
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-04-12 10:01:43 +01:00
|
|
|
save() {
|
2021-04-08 13:39:48 +01:00
|
|
|
|
|
|
|
|
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc)
|
|
|
|
|
|
2021-05-24 16:49:25 +01:00
|
|
|
try{
|
|
|
|
|
this.eventsService.editEvent(this.postEvent, 2, 3).subscribe(async () => {
|
|
|
|
|
/* const alert = await this.alertController.create({
|
|
|
|
|
cssClass: 'my-custom-class',
|
|
|
|
|
header: 'Evento actualizado',
|
|
|
|
|
buttons: ['OK']
|
|
|
|
|
});
|
|
|
|
|
await alert.present(); */
|
|
|
|
|
|
|
|
|
|
this.successMessage()
|
|
|
|
|
}, error => {
|
|
|
|
|
this.badRequest()
|
2021-01-31 01:40:19 +01:00
|
|
|
});
|
2021-05-24 16:49:25 +01:00
|
|
|
|
|
|
|
|
this.isEventEdited = true;
|
|
|
|
|
this.modalController.dismiss(this.isEventEdited);
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.badRequest()
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 10:04:58 +01:00
|
|
|
async openAttendees() {
|
2021-01-31 01:40:19 +01:00
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-05-04 15:44:48 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: AttendeesPage,
|
|
|
|
|
componentProps: {
|
|
|
|
|
adding: this.adding,
|
|
|
|
|
taskParticipants: this.taskParticipants,
|
|
|
|
|
taskParticipantsCc: this.taskParticipantsCc
|
|
|
|
|
},
|
|
|
|
|
cssClass: 'attendee',
|
|
|
|
|
backdropDismiss: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await modal.present();
|
|
|
|
|
|
|
|
|
|
modal.onDidDismiss().then((data) => {
|
|
|
|
|
|
|
|
|
|
if(data){
|
|
|
|
|
data = data['data'];
|
|
|
|
|
|
|
|
|
|
const newAttendees: EventPerson[] = data['taskParticipants'];
|
|
|
|
|
const newAttendeesCC: EventPerson[] = data['taskParticipantsCc'];
|
|
|
|
|
|
|
|
|
|
this.setIntervenient(newAttendees);
|
|
|
|
|
this.setIntervenientCC(newAttendeesCC);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
setIntervenient(data){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.taskParticipants = data;
|
|
|
|
|
this.postEvent.Attendees = data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
setIntervenientCC(data){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.taskParticipantsCc = data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
addParticipants(){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.adding = 'intervenient'
|
2021-04-07 10:04:58 +01:00
|
|
|
|
|
|
|
|
this.openAttendees();
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
addParticipantsCC(){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.adding = 'CC'
|
2021-04-07 10:04:58 +01:00
|
|
|
this.openAttendees();
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
2021-01-31 01:40:19 +01:00
|
|
|
|
2021-04-08 13:39:48 +01:00
|
|
|
dynamicSetIntervenient({taskParticipants, taskParticipantsCc}){
|
|
|
|
|
this.taskParticipants = taskParticipants;
|
|
|
|
|
this.taskParticipantsCc = taskParticipantsCc;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-23 10:35:53 +01:00
|
|
|
|
|
|
|
|
getAttachments(eventId: string){
|
|
|
|
|
this.attachmentsService.getAttachmentsById(eventId).subscribe(res=>{
|
|
|
|
|
this.loadedEventAttachments = res;
|
|
|
|
|
console.log('res', res);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteAttachment(attachmentID: string) {
|
|
|
|
|
|
|
|
|
|
this.attachmentsService.deleteEventAttachmentById(attachmentID).subscribe(
|
|
|
|
|
res=>{
|
|
|
|
|
this.loadedEventAttachments = this.loadedEventAttachments.filter(e=> e.Id.toString() != attachmentID);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getDoc() {
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: SearchPage,
|
|
|
|
|
cssClass: 'modal-width-100-width-background modal',
|
|
|
|
|
componentProps: {
|
2021-04-30 14:12:45 +01:00
|
|
|
type: 'AccoesPresidenciais & ArquivoDespachoElect',
|
2021-05-03 17:24:48 +01:00
|
|
|
showSearchInput: true,
|
|
|
|
|
select: true,
|
2021-04-23 10:35:53 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
await modal.present();
|
|
|
|
|
modal.onDidDismiss().then( async (res)=>{
|
|
|
|
|
if(res){
|
|
|
|
|
const data = res.data;
|
|
|
|
|
//data.selected
|
|
|
|
|
const DocumentToSave = {
|
|
|
|
|
SourceTitle: data.selected.Assunto,
|
|
|
|
|
ParentId: this.postEvent.EventId,
|
|
|
|
|
Source: '1',
|
|
|
|
|
SourceId: data.selected.Id,
|
|
|
|
|
ApplicationId: data.selected.ApplicationType.toString(),
|
|
|
|
|
Id: '0',
|
|
|
|
|
Link: '',
|
|
|
|
|
SerialNumber: '',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await this.attachmentsService.setEventAttachmentById(DocumentToSave).subscribe(()=>{
|
|
|
|
|
this.getAttachments(this.postEvent.EventId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 13:38:46 +01:00
|
|
|
async successMessage(message?: string) {
|
2021-05-24 16:49:25 +01:00
|
|
|
|
2021-06-08 15:59:06 +01:00
|
|
|
const enterAnimation = (baseEl: any) => {
|
|
|
|
|
const backdropAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('ion-backdrop')!)
|
|
|
|
|
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
|
|
|
|
|
|
|
|
|
|
const wrapperAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('.modal-wrapper')!)
|
|
|
|
|
.keyframes([
|
|
|
|
|
{ offset: 0, opacity: '1', right: '-100%' },
|
|
|
|
|
{ offset: 1, opacity: '1', right: '0px' }
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return this.animationController.create()
|
|
|
|
|
.addElement(baseEl)
|
|
|
|
|
.easing('ease-out')
|
|
|
|
|
.duration(500)
|
|
|
|
|
.addAnimation([backdropAnimation, wrapperAnimation]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const leaveAnimation = (baseEl: any) => {
|
|
|
|
|
return enterAnimation(baseEl).direction('reverse');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-24 16:49:25 +01:00
|
|
|
const modal = await this.modalController.create({
|
2021-06-08 15:59:06 +01:00
|
|
|
enterAnimation,
|
|
|
|
|
leaveAnimation,
|
|
|
|
|
component: SuccessMessagePage,
|
2021-05-24 16:49:25 +01:00
|
|
|
componentProps: {
|
2021-05-25 13:38:46 +01:00
|
|
|
message: message || 'Processo efetuado' ,
|
2021-05-24 16:49:25 +01:00
|
|
|
},
|
2021-06-08 15:59:06 +01:00
|
|
|
cssClass: 'notification-modal'
|
2021-05-24 16:49:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modal.present()
|
|
|
|
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
modal.dismiss()
|
2021-06-09 10:49:37 +01:00
|
|
|
},7000)
|
2021-05-24 16:49:25 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 15:59:06 +01:00
|
|
|
async badRequest(message?) {
|
|
|
|
|
const enterAnimation = (baseEl: any) => {
|
|
|
|
|
const backdropAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('ion-backdrop')!)
|
|
|
|
|
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
|
|
|
|
|
|
|
|
|
|
const wrapperAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('.modal-wrapper')!)
|
|
|
|
|
.keyframes([
|
|
|
|
|
{ offset: 0, opacity: '1', right: '-100%' },
|
|
|
|
|
{ offset: 1, opacity: '1', right: '0px' }
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return this.animationController.create()
|
|
|
|
|
.addElement(baseEl)
|
|
|
|
|
.easing('ease-out')
|
|
|
|
|
.duration(500)
|
|
|
|
|
.addAnimation([backdropAnimation, wrapperAnimation]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const leaveAnimation = (baseEl: any) => {
|
|
|
|
|
return enterAnimation(baseEl).direction('reverse');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-24 16:49:25 +01:00
|
|
|
const modal = await this.modalController.create({
|
2021-06-08 15:59:06 +01:00
|
|
|
enterAnimation,
|
|
|
|
|
leaveAnimation,
|
|
|
|
|
component: BadRequestPage,
|
|
|
|
|
componentProps: {
|
|
|
|
|
message: message || 'Processo efetuado' ,
|
2021-05-24 16:49:25 +01:00
|
|
|
},
|
2021-06-08 15:59:06 +01:00
|
|
|
cssClass: 'notification-modal'
|
2021-05-24 16:49:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modal.present()
|
|
|
|
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
modal.dismiss()
|
2021-06-09 10:49:37 +01:00
|
|
|
},7000)
|
2021-05-24 16:49:25 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 10:04:58 +01:00
|
|
|
}
|