mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
412 lines
11 KiB
TypeScript
412 lines
11 KiB
TypeScript
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
|
import { EventBody } from 'src/app/models/eventbody.model';
|
|
import { EventPerson } from 'src/app/models/eventperson.model';
|
|
import { EventsService } from 'src/app/services/events.service';
|
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
|
import { Event } from 'src/app/models/event.model';
|
|
import { AnimationController, ModalController } from '@ionic/angular';
|
|
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
|
|
import { SearchPage } from 'src/app/pages/search/search.page';
|
|
import { SearchDocument } from "src/app/models/search-document";
|
|
import { EventAttachment } from 'src/app/models/attachment.model';
|
|
import { BadRequestPage } from '../../popover/bad-request/bad-request.page';
|
|
import { SuccessMessagePage} from '../../popover/success-message/success-message.page';
|
|
|
|
|
|
@Component({
|
|
selector: 'app-new-event',
|
|
templateUrl: './new-event.page.html',
|
|
styleUrls: ['./new-event.page.scss'],
|
|
})
|
|
export class NewEventPage implements OnInit {
|
|
|
|
|
|
eventBody: EventBody;
|
|
segment:string = "true";
|
|
|
|
@Input() profile:string;
|
|
@Input() selectedSegment: string;
|
|
@Input() selectedDate: Date;
|
|
@Input() taskParticipants: EventPerson[];
|
|
@Input() taskParticipantsCc: any = [];
|
|
|
|
@Output() setIntervenient = new EventEmitter<any>();
|
|
@Output() setIntervenientCC = new EventEmitter<any>();
|
|
|
|
postEvent: Event;
|
|
@Output() onAddEvent = new EventEmitter<any>();
|
|
@Output() openAttendeesComponent = new EventEmitter<any>();
|
|
@Output() clearContact = new EventEmitter<any>();
|
|
@Output() GoBackEditOrAdd = new EventEmitter<any>();
|
|
@Output() cloneAllmobileComponent = new EventEmitter<any>();
|
|
|
|
documents:SearchDocument[] = [];
|
|
|
|
minDate: string;
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private eventService: EventsService,
|
|
private attachmentsService: AttachmentsService,
|
|
private animationController: AnimationController,
|
|
|
|
) {}
|
|
|
|
ngOnInit() {
|
|
|
|
if(!this.restoreTemporaryData()){
|
|
// clear
|
|
|
|
this.postEvent = new Event();
|
|
this.eventBody = { BodyType : "1", Text : ""};
|
|
this.postEvent.Body = this.eventBody;
|
|
|
|
/* console.log(this.profile); */
|
|
|
|
let selectedStartdDate = this.selectedDate;
|
|
let selectedEndDate = new Date(this.selectedDate);
|
|
/* Set + 30minutes to seleted datetime */
|
|
selectedEndDate.setMinutes(this.selectedDate.getMinutes() + 30) ;
|
|
this.minDate = this.selectedDate.toString();
|
|
|
|
if(this.selectedSegment != "Combinada"){
|
|
this.postEvent ={
|
|
EventId: '',
|
|
Subject: '',
|
|
Body: this.eventBody,
|
|
Location: '',
|
|
CalendarId: '',
|
|
CalendarName: '',
|
|
StartDate: selectedStartdDate,
|
|
EndDate: new Date(selectedEndDate),
|
|
EventType: 'Reunião',
|
|
Attendees: null,
|
|
IsMeeting: false,
|
|
IsRecurring: false,
|
|
AppointmentState: 0,
|
|
TimeZone: '',
|
|
Organizer: '',
|
|
Categories: ['Reunião'],
|
|
HasAttachments: false,
|
|
};
|
|
}
|
|
else{
|
|
this.postEvent ={
|
|
EventId: '',
|
|
Subject: '',
|
|
Body: this.eventBody,
|
|
Location: '',
|
|
CalendarId: '',
|
|
CalendarName: 'Oficial',
|
|
StartDate: selectedStartdDate,
|
|
EndDate: new Date(selectedEndDate),
|
|
EventType: 'Reunião',
|
|
Attendees: null,
|
|
IsMeeting: false,
|
|
IsRecurring: false,
|
|
AppointmentState: 0,
|
|
TimeZone: '',
|
|
Organizer: '',
|
|
Categories: ['Reunião'],
|
|
HasAttachments: false,
|
|
};
|
|
}
|
|
|
|
|
|
if(this.postEvent.Attendees != null) {
|
|
this.postEvent.Attendees.forEach(e =>{
|
|
if(e.IsRequired) {
|
|
this.taskParticipants.push(e);
|
|
} else {
|
|
this.taskParticipantsCc.push(e);
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
this.taskParticipants = removeDuplicate(this.taskParticipants);
|
|
this.taskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
|
|
|
|
this.setIntervenient.emit(this.taskParticipants);
|
|
this.setIntervenientCC.emit(this.taskParticipantsCc);
|
|
|
|
}
|
|
}
|
|
|
|
async getDoc(){
|
|
const modal = await this.modalController.create({
|
|
component: SearchPage,
|
|
cssClass: 'modal-width-100-width-background modal',
|
|
componentProps: {
|
|
type: 'AccoesPresidenciais & ArquivoDespachoElect',
|
|
showSearchInput: true,
|
|
select: true
|
|
}
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then((res)=>{
|
|
if(res){
|
|
const data = res.data;
|
|
this.documents.push(data.selected);
|
|
}
|
|
});
|
|
}
|
|
|
|
close(){
|
|
|
|
this.deleteTemporaryData();
|
|
|
|
this.cloneAllmobileComponent.emit();
|
|
this.clearContact.emit();
|
|
this.setIntervenient.emit([]);
|
|
this.setIntervenientCC.emit([]);
|
|
}
|
|
|
|
async save(){
|
|
|
|
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
|
|
|
|
|
|
if(this.documents.length >= 0) {
|
|
this.postEvent.HasAttachments = true;
|
|
}
|
|
|
|
if(this.profile=='mdgpr') {
|
|
this.eventService.postEventMd(this.postEvent, this.postEvent.CalendarName).subscribe(
|
|
async (id) => {
|
|
|
|
const eventId: string = id;
|
|
|
|
const DocumentToSave: EventAttachment[] = this.documents.map((e) => {
|
|
return {
|
|
SourceTitle: e.Assunto,
|
|
ParentId: eventId,
|
|
Source: '1',
|
|
SourceId: e.Id,
|
|
ApplicationId: e.ApplicationType.toString(),
|
|
Id: '',
|
|
Link: '',
|
|
SerialNumber: ''
|
|
};
|
|
});
|
|
|
|
await DocumentToSave.forEach((attachments, i) => {
|
|
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) =>{
|
|
|
|
if(DocumentToSave.length == (i+1)){
|
|
this.afterSave();
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
|
|
if(DocumentToSave.length == 0){
|
|
|
|
this.afterSave();
|
|
}
|
|
|
|
this.successMessage('Evento criado')
|
|
|
|
},
|
|
error => {
|
|
this.badRequest('Evento não criado')
|
|
});
|
|
}
|
|
else if(this.profile=='pr') {
|
|
this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).subscribe(
|
|
(id) => {
|
|
|
|
const eventId: string = id;
|
|
|
|
const DocumentToSave: EventAttachment[] = this.documents.map((e) => {
|
|
return {
|
|
SourceTitle: e.Assunto,
|
|
ParentId: eventId,
|
|
Source: '1',
|
|
SourceId: e.Id,
|
|
ApplicationId: e.ApplicationType.toString(),
|
|
Id: '',
|
|
Link: '',
|
|
SerialNumber: ''
|
|
};
|
|
});
|
|
|
|
DocumentToSave.forEach((attachments, i) => {
|
|
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) =>{
|
|
|
|
if(DocumentToSave.length == (i+1)){
|
|
this.afterSave();
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
if(DocumentToSave.length == 0){
|
|
|
|
this.afterSave();
|
|
}
|
|
|
|
this.successMessage('Evento criado')
|
|
});
|
|
}
|
|
}
|
|
|
|
afterSave(){
|
|
this.deleteTemporaryData();
|
|
|
|
this.onAddEvent.emit(this.postEvent);
|
|
this.GoBackEditOrAdd.emit();
|
|
|
|
this.setIntervenient.emit([]);
|
|
this.setIntervenientCC.emit([]);
|
|
}
|
|
|
|
removeAttachment(index: number){
|
|
this.documents = this.documents.filter( (e, i) => index != i);
|
|
|
|
}
|
|
|
|
async addParticipants() {
|
|
|
|
this.saveTemporaryData();
|
|
|
|
this.openAttendeesComponent.emit({
|
|
type: "intervenient"
|
|
});
|
|
|
|
this.clearContact.emit();
|
|
}
|
|
|
|
async addParticipantsCc() {
|
|
|
|
this.saveTemporaryData();
|
|
|
|
this.openAttendeesComponent.emit({
|
|
type: "CC"
|
|
});
|
|
|
|
this.clearContact.emit();
|
|
}
|
|
|
|
saveTemporaryData() {
|
|
window['temp.path:/home/agenda/new-event.component.ts'] = {
|
|
postEvent: this.postEvent,
|
|
eventBody: this.eventBody,
|
|
segment: this.segment
|
|
}
|
|
}
|
|
|
|
restoreTemporaryData(): boolean {
|
|
const restoredData = window['temp.path:/home/agenda/new-event.component.ts']
|
|
|
|
if(JSON.stringify(restoredData) != "{}" && undefined != restoredData) {
|
|
this.postEvent = restoredData.postEvent
|
|
this.eventBody = restoredData.eventBody
|
|
this.segment = restoredData.segment
|
|
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
deleteTemporaryData(){
|
|
window['temp.path:/home/agenda/new-event.component.ts'] = {}
|
|
}
|
|
|
|
async successMessage(message?: string, callback?) {
|
|
|
|
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');
|
|
}
|
|
|
|
|
|
const modal = await this.modalController.create({
|
|
enterAnimation,
|
|
leaveAnimation,
|
|
component: SuccessMessagePage,
|
|
componentProps: {
|
|
message: message || 'Processo efetuado' ,
|
|
},
|
|
cssClass: 'notification-modal'
|
|
});
|
|
|
|
modal.present()
|
|
|
|
setTimeout(()=>{
|
|
if (callback) {
|
|
callback()
|
|
}
|
|
modal.dismiss()
|
|
},7000)
|
|
|
|
}
|
|
|
|
async badRequest(message?: string, callback?) {
|
|
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');
|
|
}
|
|
|
|
|
|
const modal = await this.modalController.create({
|
|
enterAnimation,
|
|
leaveAnimation,
|
|
component: BadRequestPage,
|
|
componentProps: {
|
|
message: message || 'Processo não realizado com sucesso',
|
|
},
|
|
cssClass: 'notification-modal'
|
|
});
|
|
|
|
modal.present()
|
|
|
|
setTimeout(()=>{
|
|
if (callback) {
|
|
callback()
|
|
}
|
|
modal.dismiss()
|
|
},7000)
|
|
}
|
|
|
|
|
|
}
|