Files
doneit-web/src/app/shared/agenda/new-event/new-event.page.ts
T

1049 lines
30 KiB
TypeScript
Raw Normal View History

2021-02-24 09:14:58 +01:00
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';
2021-04-19 15:21:35 +01:00
import { AttachmentsService } from 'src/app/services/attachments.service';
2021-02-24 09:14:58 +01:00
import { Event } from 'src/app/models/event.model';
2021-07-14 15:38:58 +01:00
import { ModalController } from '@ionic/angular';
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
import { SearchPage } from 'src/app/pages/search/search.page';
2021-08-20 12:02:27 +01:00
import { SearchList } from "src/app/models/search-document";
2023-09-06 21:23:21 +01:00
import { EventAttachment } from 'src/app/models/attachment.model';
2021-06-21 14:29:49 +01:00
2021-06-15 15:09:20 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-08-27 15:21:15 +01:00
import { LoginUserRespose } from 'src/app/models/user.model';
2021-06-03 11:44:32 +01:00
2023-09-06 21:23:21 +01:00
import { DateAdapter } from '@angular/material/core';
2021-06-17 13:58:56 +01:00
import * as _moment from 'moment';
import * as _rollupMoment from 'moment';
2021-06-23 15:39:45 +01:00
import { FormControl } from '@angular/forms';
2021-06-18 12:02:14 +01:00
import { NgxMatDateFormats } from '@angular-material-components/datetime-picker';
import { ThemePalette } from '@angular/material/core';
2021-08-25 15:23:30 +01:00
import { ViewChild } from '@angular/core';
2023-09-06 21:23:21 +01:00
import { FormGroup, Validators } from '@angular/forms';
2021-06-21 14:29:49 +01:00
import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker';
2021-10-22 15:43:57 +01:00
import { ThemeService } from 'src/app/services/theme.service'
import { ChatMethodsService } from 'src/app/services/chat/chat-methods.service';
2023-02-02 12:01:18 +01:00
import { ServerConnectionService } from 'src/app/services/server-connection.service';
2022-10-12 17:01:09 +01:00
import { SessionStore } from 'src/app/store/session.service';
2023-02-27 09:34:36 +01:00
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
2023-03-22 15:31:01 +01:00
import { environment } from 'src/environments/environment';
2023-09-06 21:23:21 +01:00
import { EventToAprove } from 'src/app/models/eventToAprove.model';
import { ProcessesService } from 'src/app/services/processes.service';
import { Subject } from 'rxjs';
2021-10-22 15:43:57 +01:00
2023-08-31 12:00:52 +01:00
import { TaskService } from 'src/app/services/task.service'
import { ContactsService } from 'src/app/services/contacts.service';
2023-11-14 12:04:31 +01:00
import { DomSanitizerService } from 'src/app/services/DomSanitizer.service';
import { ChangeProfileService } from 'src/app/services/change-profile.service';
2021-06-18 12:02:14 +01:00
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
2021-06-17 13:58:56 +01:00
parse: {
2021-06-18 12:02:14 +01:00
dateInput: "YYYY-MMMM-DD HH:mm"
2021-06-17 13:58:56 +01:00
},
display: {
2021-06-18 12:02:14 +01:00
dateInput: "DD MMM YYYY H:mm",
monthYearLabel: "MMM YYYY",
dateA11yLabel: "LL",
monthYearA11yLabel: "MMMM YYYY"
}
}
2021-06-17 13:58:56 +01:00
2021-02-24 09:14:58 +01:00
@Component({
selector: 'app-new-event',
2021-06-03 11:44:32 +01:00
templateUrl: './new-event.page.html',
styleUrls: ['./new-event.page.scss'],
2021-06-17 13:58:56 +01:00
providers: [
2021-06-18 12:02:14 +01:00
{ provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_DATE_FORMATS },
2021-06-17 13:58:56 +01:00
]
2021-02-24 09:14:58 +01:00
})
2021-06-17 13:58:56 +01:00
2021-02-24 09:14:58 +01:00
export class NewEventPage implements OnInit {
2021-02-24 09:14:58 +01:00
eventBody: EventBody;
2023-09-06 21:23:21 +01:00
segment: string = "true";
2021-06-18 12:02:14 +01:00
public date: any;
public disabled = false;
public showSpinners = true;
public showSeconds = false;
public touchUi = false;
public enableMeridian = false;
public stepHour = 1;
public stepMinute = 15;
public stepSecond = 15;
currentDate = this.roundTimeQuarterHour();
2021-06-18 12:02:14 +01:00
public color: ThemePalette = 'primary';
2021-08-25 11:51:02 +01:00
recurringTypes = []
2021-07-12 14:32:43 +01:00
selectedRecurringType: any;
2023-08-11 16:14:25 +01:00
loggedAttendDad: boolean = true;
mostrarModal = false;
2021-06-18 12:02:14 +01:00
2023-01-24 15:56:47 +01:00
@Input() attendees: []
2023-09-06 21:23:21 +01:00
@Input() profile: string;
@Input() roomId: string;
2021-02-24 09:14:58 +01:00
@Input() selectedSegment: string;
@Input() selectedDate: Date;
2023-01-24 15:56:47 +01:00
@Input() CalendarDate: Date;
2021-06-28 11:16:21 +01:00
@Input() taskParticipants: EventPerson[] = [];
2021-04-07 15:13:31 +01:00
@Input() taskParticipantsCc: any = [];
2021-07-12 14:32:43 +01:00
2021-04-07 15:13:31 +01:00
@Output() setIntervenient = new EventEmitter<any>();
@Output() setIntervenientCC = new EventEmitter<any>();
2021-02-24 09:14:58 +01:00
postEvent: Event;
2023-09-06 21:23:21 +01:00
postEventToAprove: EventToAprove;
2021-02-24 09:14:58 +01:00
@Output() onAddEvent = new EventEmitter<any>();
2021-03-24 15:10:46 +01:00
@Output() openAttendeesComponent = new EventEmitter<any>();
2021-03-25 10:50:58 +01:00
@Output() clearContact = new EventEmitter<any>();
2023-09-06 21:23:21 +01:00
@Output() GoBackEditOrAdd = new EventEmitter<any>();
2021-03-25 15:51:19 +01:00
@Output() cloneAllmobileComponent = new EventEmitter<any>();
2022-10-03 11:02:32 +01:00
@Output() backToChat = new EventEmitter<any>();
2021-02-24 09:14:58 +01:00
2023-09-06 21:23:21 +01:00
documents: SearchList[] = [];
2021-08-27 15:21:15 +01:00
loggeduser: LoginUserRespose;
2021-06-18 12:02:14 +01:00
@ViewChild('picker') picker: any;
2021-06-21 14:29:49 +01:00
@ViewChild('fim') fim: any;
2021-06-23 15:39:45 +01:00
@ViewChild('inicio') inicio: any;
2021-07-12 15:48:25 +01:00
@ViewChild('occurrence') occurrence: any;
2021-06-23 15:39:45 +01:00
@ViewChild('picker1') picker1: any;
2021-07-01 14:54:54 +01:00
Form: FormGroup;
validateFrom = false;
autoStartTime;
2023-09-06 21:23:21 +01:00
autoEndTime;
2021-06-28 11:16:21 +01:00
2021-06-23 15:39:45 +01:00
public options = [
{ value: true, label: 'True' },
{ value: false, label: 'False' }
];
public listColors = ['primary', 'accent', 'warn'];
public stepHours = [1, 2, 3, 4, 5];
public stepMinutes = [1, 5, 10, 15, 20, 25];
public stepSeconds = [1, 5, 10, 15, 20, 25];
showLoader = false
2021-12-21 15:46:26 +01:00
CalendarName;
2022-05-12 16:54:11 +01:00
CalendarNameShow = true
CalendarNamesOptions = ['Oficial', 'Pessoal']
2023-03-22 15:31:01 +01:00
environment = environment
eventPersons: EventPerson[];
contacts: EventPerson[] = [];
2021-07-12 15:48:25 +01:00
2021-02-24 09:14:58 +01:00
constructor(
private modalController: ModalController,
2022-05-12 16:54:11 +01:00
public eventService: EventsService,
2021-06-08 15:59:06 +01:00
private attachmentsService: AttachmentsService,
2021-06-16 13:29:57 +01:00
private toastService: ToastService,
2021-06-21 14:29:49 +01:00
private dateAdapter: DateAdapter<any>,
public ThemeService: ThemeService,
private chatMethodService: ChatMethodsService,
2023-09-06 21:23:21 +01:00
private hhtpErrorHandle: HttpErrorHandle,
private processeService: ProcessesService,
public TaskService: TaskService,
private contactsService: ContactsService,
private domSanitazerService: DomSanitizerService,
private changeProfileService: ChangeProfileService,
2021-06-16 13:29:57 +01:00
) {
2021-06-18 12:02:14 +01:00
this.dateAdapter.setLocale('pt');
2022-10-12 17:01:09 +01:00
this.loggeduser = SessionStore.user;
2021-07-14 14:29:03 +01:00
this.postEvent = new Event();
2021-06-23 15:39:45 +01:00
2021-06-16 13:29:57 +01:00
}
2021-02-24 09:14:58 +01:00
ngOnInit() {
2022-05-30 16:43:54 +01:00
2023-12-06 17:01:00 +01:00
console.log(' INTERVENIENTES',this.taskParticipants)
this.changeProfileService.registerCallback(() => {
this.initializeData()
})
2023-12-06 17:01:00 +01:00
2023-09-06 21:23:21 +01:00
if (!this.CalendarName) {
if (this.eventService.calendarNamesAry.includes('Meu calendario')) {
2022-12-30 14:31:19 +01:00
this.CalendarName = 'Meu calendario';
2023-01-24 15:56:47 +01:00
} else {
2022-12-30 14:31:19 +01:00
this.CalendarName = this.eventService.calendarNamesAry[0]
}
2022-05-30 16:43:54 +01:00
}
2021-12-21 15:46:26 +01:00
2021-07-12 14:32:43 +01:00
this.getRecurrenceTypes();
2023-09-06 21:23:21 +01:00
if (!this.restoreTemporaryData()) {
// clear
2023-09-06 21:23:21 +01:00
this.eventBody = { BodyType: "1", Text: "" };
2021-07-12 14:32:43 +01:00
this.postEvent.Body = this.eventBody;
this.initializeData()
2023-09-06 21:23:21 +01:00
if (this.postEvent.Attendees != null) {
2022-07-04 18:15:55 +01:00
this.postEvent.Attendees.forEach(e => {
2023-09-06 21:23:21 +01:00
if (e.IsRequired) {
this.taskParticipants.push(e);
} else {
this.taskParticipantsCc.push(e);
}
2021-07-12 14:32:43 +01:00
})
}
console.log('Attendes',this.taskParticipants)
this.taskParticipants = removeDuplicate(this.taskParticipants);
this.taskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
this.setIntervenient.emit(this.taskParticipants);
this.setIntervenientCC.emit(this.taskParticipantsCc);
2023-07-31 14:54:10 +01:00
this.setDefaultTime();
2021-02-24 09:14:58 +01:00
}
2021-06-18 12:02:14 +01:00
2023-09-06 21:23:21 +01:00
this.date = new Date(2021, 9, 4, 5, 6, 7);
2021-06-28 11:16:21 +01:00
2021-07-12 14:32:43 +01:00
this.injectValidation();
2023-03-22 15:31:01 +01:00
this.changeAgenda()
this.fetchContacts("")
2021-07-12 14:32:43 +01:00
2021-06-28 11:16:21 +01:00
}
initializeData() {
if (this.selectedSegment != "Combinada") {
this.postEvent = {
EventId: '',
Subject: '',
Body: this.eventBody,
Location: '',
CalendarId: '',
CalendarName: 'Oficial',
StartDate: this.autoStartTime,
EndDate: this.autoEndTime,
EventType: 'Reunião',
Attendees: this.attendees || null,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
Category: 'Reunião',
HasAttachments: false,
EventRecurrence: { Type: '-1', LastOccurrence: this.autoEndTime },
};
}
else {
this.postEvent = {
EventId: '',
Subject: '',
Body: this.eventBody,
Location: '',
CalendarId: '',
CalendarName: 'Oficial',
StartDate: this.autoStartTime,
EndDate: this.autoEndTime,
EventType: 'Reunião',
Attendees: this.attendees || null,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
Category: 'Reunião',
HasAttachments: false,
EventRecurrence: { Type: '-1', LastOccurrence: this.autoEndTime },
}
}
}
2023-01-24 15:56:47 +01:00
setDefaultTime() {
this.postEvent.StartDate = this.roundTimeQuarterHour(this.CalendarDate);
2023-02-13 18:50:31 +01:00
this.postEvent.EndDate = this.roundTimeQuarterHourPlus15(this.postEvent.StartDate);
2023-01-24 15:56:47 +01:00
}
2023-02-06 17:54:06 +01:00
roundTimeQuarterHour(timeToReturn = new Date()): Date {
2023-09-06 21:23:21 +01:00
2023-02-06 17:54:06 +01:00
let date = new Date(timeToReturn) || new Date();
2024-02-29 05:59:53 +01:00
let newdate = new Date();
const minutes = newdate.getMinutes();
date.setHours(newdate.getHours())
date.setSeconds(0);
2023-09-06 21:23:21 +01:00
if (minutes % 15 != 0) {
if (minutes > 45) {
date.setMinutes(60)
} else if (minutes > 30) {
date.setMinutes(45)
} else if (minutes > 15) {
date.setMinutes(30)
2023-02-06 19:04:26 +01:00
} else if (minutes > 0) {
date.setMinutes(15)
}
2023-09-06 21:23:21 +01:00
}
return date
}
2023-09-06 21:23:21 +01:00
roundTimeQuarterHourPlus15(date: Date) {
2023-02-13 18:50:31 +01:00
const _date = new Date(date);
2023-09-06 21:23:21 +01:00
const minutes = _date.getMinutes();
_date.setMinutes(minutes + 15)
return _date
2023-02-13 18:50:31 +01:00
}
2023-09-06 21:23:21 +01:00
roundTimeQuarterHour1(timeToReturn) {
2023-02-06 17:54:06 +01:00
let date: any = new Date(timeToReturn) || new Date();
const minutes = date.getMinutes();
date.setSeconds(0);
2023-09-06 21:23:21 +01:00
if ((minutes % 15) != 0) {
let a = (Math.floor(minutes / 15) + 1) * 15
date.setMinutes(a)
}
return date
}
2023-09-06 21:23:21 +01:00
setStartDate() {
2023-01-24 15:56:47 +01:00
// this.postEvent.StartDate = this.roundTimeQuarterHour();
}
2023-09-06 21:23:21 +01:00
setEndDate() {
2023-01-24 15:56:47 +01:00
// this.postEvent.EndDate = this.postEvent.StartDate;
}
2021-06-28 11:16:21 +01:00
runValidation() {
2023-09-06 21:23:21 +01:00
this.validateFrom = true;
if (new Date(this.postEvent.StartDate).getTime() > new Date(this.postEvent.EndDate).getTime()) {
2021-12-13 15:34:16 +01:00
this.toastService._badRequest("A data de fim não pode ser inferior a data de início do evento")
}
2021-06-28 11:16:21 +01:00
}
injectValidation() {
2023-09-06 21:23:21 +01:00
if (typeof (this.postEvent.EventRecurrence.Type) == 'number') {
2021-07-20 19:22:11 +01:00
const str: any = this.postEvent.EventRecurrence.Type.toString()
this.postEvent.EventRecurrence.Type = str
}
2021-12-13 15:34:16 +01:00
2021-06-28 11:16:21 +01:00
this.Form = new FormGroup({
Subject: new FormControl(this.postEvent.Subject, [
Validators.required,
2021-07-01 14:54:54 +01:00
// Validators.minLength(4)
2021-06-28 11:16:21 +01:00
]),
Location: new FormControl(this.postEvent.Location, [
Validators.required,
]),
CalendarName: new FormControl(this.postEvent.CalendarName),
Categories: new FormControl(this.postEvent.Category, [
2021-06-28 11:16:21 +01:00
Validators.required
]),
2021-07-14 09:46:03 +01:00
dateStart: new FormControl(this.postEvent.StartDate, [
2021-06-28 11:16:21 +01:00
Validators.required
]),
2021-07-14 09:46:03 +01:00
dateEnd: new FormControl(this.postEvent.EndDate, [
2021-07-12 15:48:25 +01:00
Validators.required
]),
2023-09-06 21:23:21 +01:00
dateOccurrence: new FormControl(this.postEvent.EventRecurrence.Type.toString() == '-1' ? ['ok'] : this.postEvent.EventRecurrence.LastOccurrence && new Date(this.postEvent.EventRecurrence.LastOccurrence).getTime() > new Date(this.postEvent.EndDate).getTime() ? 'ok' : null, [
2021-06-28 11:16:21 +01:00
Validators.required
]),
2021-07-08 13:41:27 +01:00
participantes: new FormControl(this.taskParticipants, [
2021-07-20 12:30:52 +01:00
// Validators.required
2021-06-28 11:16:21 +01:00
]),
2023-09-06 21:23:21 +01:00
Date: new FormControl(new Date(this.postEvent.StartDate).getTime() < new Date(this.postEvent.EndDate).getTime() ? 'ok' : null, [
2021-07-12 16:05:05 +01:00
Validators.required
]),
2021-06-28 11:16:21 +01:00
})
2021-12-13 15:34:16 +01:00
2021-06-28 11:16:21 +01:00
}
2021-06-18 12:02:14 +01:00
2021-06-21 14:29:49 +01:00
openInicio() {
let input: any = document.querySelector('#new-inicio')
2023-09-06 21:23:21 +01:00
if (input) {
2021-06-21 14:29:49 +01:00
input.click()
}
}
openFim() {
let input: any = document.querySelector('#new-fim')
2023-09-06 21:23:21 +01:00
if (input) {
2021-06-21 14:29:49 +01:00
input.click()
}
}
2022-05-12 16:54:11 +01:00
changeAgenda() {
this.CalendarNameShow = false
2023-09-06 21:23:21 +01:00
setTimeout(() => {
2022-05-12 16:54:11 +01:00
this.CalendarNameShow = true
2023-09-06 21:23:21 +01:00
if (this.eventService.calendarNamesType[this.CalendarName]?.['Oficial'] && this.eventService.calendarNamesType[this.CalendarName]?.['Pessoal']) {
2022-05-12 16:54:11 +01:00
this.CalendarNamesOptions = ['Oficial', 'Pessoal']
2023-09-06 21:23:21 +01:00
console.log(this.postEvent.CalendarName)
2022-05-12 16:54:11 +01:00
} else if (this.eventService.calendarNamesType[this.CalendarName]?.['Oficial']) {
this.CalendarNamesOptions = ['Oficial']
this.postEvent.CalendarName = 'Oficial'
2023-09-06 21:23:21 +01:00
console.log(this.postEvent.CalendarName)
2022-05-12 16:54:11 +01:00
} else if (this.eventService.calendarNamesType[this.CalendarName]?.['Pessoal']) {
this.CalendarNamesOptions = ['Pessoal']
this.postEvent.CalendarName = 'Pessoal'
2023-09-06 21:23:21 +01:00
console.log(this.postEvent.CalendarName)
2022-05-12 16:54:11 +01:00
} else {
this.CalendarNamesOptions = ['Oficial', 'Pessoal']
2023-09-06 21:23:21 +01:00
console.log(this.postEvent.CalendarName)
2022-05-12 16:54:11 +01:00
}
}, 50)
}
2023-09-06 21:23:21 +01:00
2021-07-12 15:48:25 +01:00
openLastOccurrence() {
let input: any = document.querySelector('#last-occurrence')
2023-09-06 21:23:21 +01:00
if (input) {
2021-07-12 15:48:25 +01:00
input.click()
}
}
2023-01-24 15:56:47 +01:00
async getDoc() {
const modal = await this.modalController.create({
component: SearchPage,
2021-04-21 19:59:49 +01:00
cssClass: 'modal-width-100-width-background modal',
componentProps: {
type: 'AccoesPresidenciais & ArquivoDespachoElect',
showSearchInput: true,
select: true
}
});
2023-07-15 11:01:09 +01:00
2023-01-24 15:56:47 +01:00
modal.onDidDismiss().then((res) => {
2023-09-06 21:23:21 +01:00
if (res) {
const data = res.data;
this.documents.push(data.selected);
}
});
2023-07-15 11:01:09 +01:00
await modal.present();
}
2021-07-12 14:32:43 +01:00
2022-08-04 16:52:35 +01:00
close() {
this.deleteTemporaryData();
2021-03-25 10:50:58 +01:00
this.clearContact.emit();
this.setIntervenient.emit([]);
this.setIntervenientCC.emit([]);
2022-12-16 18:16:19 +01:00
// chat exit
2023-09-06 21:23:21 +01:00
this.backToChat.emit({ roomId: this.roomId })
2022-12-16 18:16:19 +01:00
// agenda exit
this.cloneAllmobileComponent.emit({})
2021-02-24 09:14:58 +01:00
}
2021-07-12 14:32:43 +01:00
getRecurrenceTypes() {
2023-09-06 21:23:21 +01:00
this.eventService.getRecurrenceTypes().subscribe(res => {
2021-07-12 14:32:43 +01:00
this.recurringTypes = res;
});
}
2023-09-06 21:23:21 +01:00
onSelectedRecurringChanged(ev: any) {
this.calculetedLastOccurrence(ev);
2023-09-06 21:23:21 +01:00
if (ev.length > 1) {
2021-07-12 14:32:43 +01:00
this.postEvent.EventRecurrence.Type = ev.filter(data => data != '-1');
}
2023-09-06 21:23:21 +01:00
if (ev.length == 0) {
2021-07-12 14:32:43 +01:00
this.postEvent.EventRecurrence.Type = "-1";
}
}
2023-09-06 21:23:21 +01:00
calculetedLastOccurrence(type: number) {
2023-05-26 14:23:37 +01:00
2023-09-06 21:23:21 +01:00
var valor;
var opcao: boolean;
if (type == 0) {
valor = 7;
opcao = true;
2023-09-06 21:23:21 +01:00
} else if (type == 1) {
valor = 30;
opcao = true;
2023-09-06 21:23:21 +01:00
} else if (type == 2) {
valor = 1;
opcao = false;
2023-09-06 21:23:21 +01:00
} else if (type == 3) {
valor = 5;
opcao = false;
}
this.defineLastOccurrence(valor, opcao);
}
2021-06-23 15:39:45 +01:00
2023-09-06 21:23:21 +01:00
defineLastOccurrence(valor: number, opcao: boolean) {
var time = new Date(this.postEvent.EndDate);
if (opcao == true) {
time.setDate(time.getDate() + valor);
this.postEvent.EventRecurrence.LastOccurrence = time;
} else {
time = new Date(
2023-09-06 21:23:21 +01:00
time.getFullYear() + valor,
time.getMonth(),
time.getDate(),
time.getHours(),
time.getMinutes()
);
this.postEvent.EventRecurrence.LastOccurrence = time;
}
2023-09-06 21:23:21 +01:00
}
2021-07-20 19:22:11 +01:00
2021-06-28 11:16:21 +01:00
async save() {
2021-07-01 14:54:54 +01:00
this.injectValidation()
2021-06-28 11:16:21 +01:00
this.runValidation()
2021-07-01 16:23:47 +01:00
2023-09-06 21:23:21 +01:00
if (this.Form.invalid) {
2024-02-29 09:40:51 +01:00
if(new Date(this.postEvent.StartDate).getTime() < new Date(this.postEvent.EndDate).getTime()) {
this.toastService._badRequest("Data de inicio menor que a data de fim")
}
2021-07-14 09:46:03 +01:00
return false
}
2021-06-23 15:39:45 +01:00
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
this.postEvent.Subject = /* this.domSanitazerService.sanitizeInput( */this.postEvent.Subject/* ); */
this.postEvent.Location = /* this.domSanitazerService.sanitizeInput( */this.postEvent.Location/* ); */
this.postEvent.Body.Text = /* this.domSanitazerService.sanitizeInput( */this.postEvent.Body.Text/* ); */
2021-04-19 15:21:35 +01:00
2023-09-06 21:23:21 +01:00
if (this.documents.length > 0) {
2021-04-19 15:21:35 +01:00
this.postEvent.HasAttachments = true;
}
2021-07-20 12:30:52 +01:00
2023-09-06 21:23:21 +01:00
if (this.postEvent.EventRecurrence.Type == undefined) {
2021-07-20 12:30:52 +01:00
this.postEvent.EventRecurrence.Type = '-1'
}
2023-09-06 21:23:21 +01:00
if (this.loggeduser.Profile == 'MDGPR') {
2022-05-12 16:54:11 +01:00
const CalendarId = this.selectedCalendarId()
2021-06-25 11:00:25 +01:00
this.showLoader = true;
2023-08-20 00:26:24 +01:00
this.postEvent.CalendarId = CalendarId
2023-09-06 21:23:21 +01:00
2021-07-12 14:32:43 +01:00
let loader = this.toastService.loading();
2023-09-06 21:23:21 +01:00
2022-05-12 16:54:11 +01:00
this.eventService.postEventGeneric(this.postEvent, this.postEvent.CalendarName, CalendarId).subscribe(
2021-05-28 15:45:41 +01:00
async (id) => {
2021-07-07 16:25:36 +01:00
loader.remove()
2021-06-23 15:39:45 +01:00
this.showLoader = false
2021-06-16 13:29:57 +01:00
const eventId: any = id;
2021-04-19 15:21:35 +01:00
const DocumentToSave: EventAttachment[] = this.documents.map((e) => {
return {
2021-04-20 15:05:40 +01:00
SourceTitle: e.Assunto,
2021-04-19 15:21:35 +01:00
ParentId: eventId,
Source: '1',
SourceId: e.Id,
ApplicationId: e.ApplicationType.toString(),
Id: '',
Link: '',
SerialNumber: ''
};
});
2021-05-28 15:45:41 +01:00
await DocumentToSave.forEach((attachments, i) => {
2023-09-06 21:23:21 +01:00
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) => {
if (DocumentToSave.length == (i + 1)) {
2021-04-21 19:59:49 +01:00
this.afterSave();
}
});
2021-04-19 15:21:35 +01:00
});
2023-09-06 21:23:21 +01:00
if (DocumentToSave.length == 0) {
2021-04-21 19:59:49 +01:00
this.afterSave();
}
2023-02-27 09:34:36 +01:00
this.hhtpErrorHandle.httpsSucessMessagge('new event')
let data = {
"subject": this.postEvent.Subject,
"start": this.postEvent.StartDate,
"end": this.postEvent.EndDate,
"venue": this.postEvent.Location,
"id": id,
2022-08-03 16:31:03 +01:00
"calendarId": CalendarId
}
2022-08-04 16:52:35 +01:00
2023-09-06 21:23:21 +01:00
if (this.roomId) {
this.chatMethodService.sendMessage(this.roomId, data);
2022-08-04 16:52:35 +01:00
}
2023-09-06 21:23:21 +01:00
2021-05-24 16:49:25 +01:00
},
error => {
2021-07-07 16:25:36 +01:00
loader.remove()
2021-06-23 15:39:45 +01:00
this.showLoader = false
2023-02-27 09:34:36 +01:00
this.hhtpErrorHandle.httpStatusHandle(error)
2023-09-06 21:23:21 +01:00
});
2021-07-14 09:46:03 +01:00
2021-02-24 09:14:58 +01:00
}
2023-09-06 21:23:21 +01:00
else if (this.loggeduser.Profile == 'PR') {
2022-05-12 16:54:11 +01:00
const CalendarId = this.selectedCalendarId()
2022-08-01 16:20:26 +01:00
let loader = this.toastService.loading();
2023-08-20 00:26:24 +01:00
this.postEvent.CalendarId = CalendarId
2023-09-06 21:23:21 +01:00
2022-05-12 16:54:11 +01:00
this.eventService.postEventGeneric(this.postEvent, this.postEvent.CalendarName, CalendarId).subscribe(
2021-04-19 15:21:35 +01:00
(id) => {
2023-09-06 21:23:21 +01:00
2022-08-01 16:20:26 +01:00
loader.remove()
2021-07-12 14:32:43 +01:00
2023-09-06 21:23:21 +01:00
const eventId: any = id;
2021-04-19 15:21:35 +01:00
const DocumentToSave: EventAttachment[] = this.documents.map((e) => {
2021-04-19 15:21:35 +01:00
return {
2021-04-20 15:05:40 +01:00
SourceTitle: e.Assunto,
2021-04-19 15:21:35 +01:00
ParentId: eventId,
Source: '1',
SourceId: e.Id,
ApplicationId: e.ApplicationType.toString(),
2021-04-20 15:05:40 +01:00
Id: '',
Link: '',
SerialNumber: ''
2021-04-19 15:21:35 +01:00
};
});
DocumentToSave.forEach((attachments, i) => {
2023-09-06 21:23:21 +01:00
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) => {
if (DocumentToSave.length == (i + 1)) {
2021-04-21 19:59:49 +01:00
this.afterSave();
2022-04-02 09:40:09 +01:00
}
});
});
2023-09-06 21:23:21 +01:00
if (DocumentToSave.length == 0) {
2022-04-02 09:40:09 +01:00
this.afterSave();
}
2023-02-27 09:34:36 +01:00
this.hhtpErrorHandle.httpsSucessMessagge('new event')
2022-08-01 16:44:57 +01:00
let data = {
"subject": this.postEvent.Subject,
"start": this.postEvent.StartDate,
"end": this.postEvent.EndDate,
"venue": this.postEvent.Location,
"id": id,
2022-08-03 16:31:03 +01:00
"calendarId": CalendarId
2022-08-01 16:44:57 +01:00
}
2023-09-06 21:23:21 +01:00
if (this.roomId) {
this.chatMethodService.sendMessage(this.roomId, data);
2022-08-04 16:52:35 +01:00
}
2023-09-06 21:23:21 +01:00
}, (error) => {
2023-02-02 12:01:18 +01:00
//const connectionToServer = this.ServerConnectionService.BaseAPI()
2023-02-27 09:34:36 +01:00
this.hhtpErrorHandle.httpStatusHandle(error)
2023-02-02 12:01:18 +01:00
2022-08-01 16:20:26 +01:00
loader.remove()
this.showLoader = false
2023-09-06 21:23:21 +01:00
2022-04-02 09:40:09 +01:00
});
2023-09-06 21:23:21 +01:00
} else if (this.loggeduser.Profile == 'SGGPR') {
console.log(this.postEventToAprove)
console.log(this.postEvent)
console.log(this.postEvent.CalendarName)
console.log(this.CalendarName)
console.log(this.eventService.calendarNamesAry)
const CalendarId = this.selectedCalendarId()
let selectedCalendar
try {
selectedCalendar = this.eventService.calendarNamesAry.find(calendar => calendar.Fullname === this.CalendarName)
} catch (error) {
}
console.log('selectedCalendar', selectedCalendar)
if (selectedCalendar) {
if (selectedCalendar.Role = 'Presidente da República') {
let loader = this.toastService.loading();
const DocumentToSave: EventAttachment[] = this.documents.map((e) => {
return {
SourceTitle: e.Assunto,
ParentId: "AGD_" + this.loggeduser.UserName + "_" + this.processeService.generateInstaceFormatDate(),
Source: '1',
SourceId: e.Id,
ApplicationId: e.ApplicationType.toString(),
Id: '',
Link: '',
SerialNumber: ''
};
});
let body = this.eventToaproveBody(this.postEvent, CalendarId, this.loggeduser.RoleID, this.loggeduser.UserId, DocumentToSave);
await this.processeService.createEventToAprove(this.postEvent.CalendarName, 'pr', body).subscribe((id) => {
loader.remove()
this.afterSave();
this.hhtpErrorHandle.httpsSucessMessagge('new event to aprove')
/* DocumentToSave.forEach((attachments, i) => {
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) => {
if (DocumentToSave.length == (i + 1)) {
this.afterSave();
}
});
});
2023-09-06 21:23:21 +01:00
if (DocumentToSave.length == 0) {
this.afterSave();
} */
}, (error) => {
loader.remove()
this.showLoader = false
this.hhtpErrorHandle.httpStatusHandle(error)
});
} else if (selectedCalendar.Role = 'Ministro e Director do Gabinete do PR') {
let loader = this.toastService.loading();
const DocumentToSave: EventAttachment[] = this.documents.map((e) => {
return {
SourceTitle: e.Assunto,
ParentId: "AGD_" + this.loggeduser.UserName + "_" + this.processeService.generateInstaceFormatDate(),
Source: '1',
SourceId: e.Id,
ApplicationId: e.ApplicationType.toString(),
Id: '',
Link: '',
SerialNumber: ''
};
});
let body = this.eventToaproveBody(this.postEvent, CalendarId, this.loggeduser.RoleID, this.loggeduser.UserId, DocumentToSave);
await this.processeService.createEventToAprove(this.postEvent.CalendarName, 'md', body).subscribe((id) => {
loader.remove()
this.afterSave();
this.hhtpErrorHandle.httpsSucessMessagge('new event to aprove')
/* DocumentToSave.forEach((attachments, i) => {
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) => {
if (DocumentToSave.length == (i + 1)) {
this.afterSave();
}
});
});
2023-09-06 21:23:21 +01:00
if (DocumentToSave.length == 0) {
this.afterSave();
} */
}, (error) => {
loader.remove()
this.showLoader = false
this.hhtpErrorHandle.httpStatusHandle(error)
});
}
2023-09-06 21:23:21 +01:00
}
if (!selectedCalendar && this.CalendarName == "Meu calendario") {
console.log('SG generic')
this.postEvent.CalendarName
const CalendarId = this.selectedCalendarId()
let loader = this.toastService.loading();
this.postEvent.CalendarId = CalendarId
this.eventService.postEventGeneric(this.postEvent, this.postEvent.CalendarName, CalendarId).subscribe(
(id) => {
loader.remove();
const eventId: any = 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.hhtpErrorHandle.httpsSucessMessagge('new event')
let data = {
"subject": this.postEvent.Subject,
"start": this.postEvent.StartDate,
"end": this.postEvent.EndDate,
"venue": this.postEvent.Location,
"id": id,
"calendarId": CalendarId
}
if (this.roomId) {
this.chatMethodService.sendMessage(this.roomId, data);
}
}, (error) => {
loader.remove()
this.showLoader = false
this.hhtpErrorHandle.httpStatusHandle(error)
});
}
2022-04-02 09:40:09 +01:00
} else {
2023-09-06 21:23:21 +01:00
2022-05-12 16:54:11 +01:00
this.postEvent.CalendarName
const CalendarId = this.selectedCalendarId()
2022-08-01 16:20:26 +01:00
let loader = this.toastService.loading();
2023-08-20 00:26:24 +01:00
this.postEvent.CalendarId = CalendarId
2023-09-06 21:23:21 +01:00
2022-05-12 16:54:11 +01:00
this.eventService.postEventGeneric(this.postEvent, this.postEvent.CalendarName, CalendarId).subscribe(
2022-04-02 09:40:09 +01:00
(id) => {
2022-08-01 16:20:26 +01:00
loader.remove();
2023-09-06 21:23:21 +01:00
const eventId: any = id;
2022-04-02 09:40:09 +01:00
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) => {
2023-09-06 21:23:21 +01:00
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) => {
if (DocumentToSave.length == (i + 1)) {
2022-04-02 09:40:09 +01:00
this.afterSave();
}
});
2021-04-19 15:21:35 +01:00
});
2023-09-06 21:23:21 +01:00
if (DocumentToSave.length == 0) {
2021-04-21 19:59:49 +01:00
this.afterSave();
}
2022-08-01 16:44:57 +01:00
2023-02-27 09:34:36 +01:00
this.hhtpErrorHandle.httpsSucessMessagge('new event')
2022-08-01 16:44:57 +01:00
let data = {
"subject": this.postEvent.Subject,
"start": this.postEvent.StartDate,
"end": this.postEvent.EndDate,
"venue": this.postEvent.Location,
"id": id,
2022-08-03 16:31:03 +01:00
"calendarId": CalendarId
2022-08-01 16:44:57 +01:00
}
2023-09-06 21:23:21 +01:00
if (this.roomId) {
this.chatMethodService.sendMessage(this.roomId, data);
2022-08-04 16:52:35 +01:00
}
2023-09-06 21:23:21 +01:00
}, (error) => {
2023-02-02 12:01:18 +01:00
2023-09-06 21:23:21 +01:00
loader.remove()
this.showLoader = false
this.hhtpErrorHandle.httpStatusHandle(error)
});
2022-05-12 16:54:11 +01:00
}
}
2023-09-06 21:23:21 +01:00
selectedCalendarId() {
2022-05-12 16:54:11 +01:00
2022-06-24 15:02:49 +01:00
if (this.eventService.calendarNamesType[this.CalendarName]?.['Oficial'] && this.postEvent.CalendarName == 'Oficial') {
2023-05-26 14:23:37 +01:00
2022-05-12 16:54:11 +01:00
return this.eventService.calendarNamesType[this.CalendarName]['OficialId']
2022-06-24 15:02:49 +01:00
} else if (this.eventService.calendarNamesType[this.CalendarName]?.['Pessoal'] && this.postEvent.CalendarName == 'Pessoal') {
2023-05-26 14:23:37 +01:00
2022-05-12 16:54:11 +01:00
return this.eventService.calendarNamesType[this.CalendarName]['PessoalId']
} else {
2023-05-26 14:23:37 +01:00
2022-05-12 16:54:11 +01:00
return '11:11'
2021-02-24 09:14:58 +01:00
}
2021-04-21 19:59:49 +01:00
}
2021-06-16 15:58:44 +01:00
afterSave() {
2021-04-21 19:59:49 +01:00
this.deleteTemporaryData();
2022-08-04 16:52:35 +01:00
this.onAddEvent.emit(Object.assign(this.postEvent, {
roomId: this.roomId
}));
2021-04-21 19:59:49 +01:00
this.GoBackEditOrAdd.emit();
this.setIntervenient.emit([]);
this.setIntervenientCC.emit([]);
2021-04-19 15:21:35 +01:00
}
2021-04-07 15:13:31 +01:00
2022-05-12 16:54:11 +01:00
removeAttachment(index: number) {
2023-09-06 21:23:21 +01:00
this.documents = this.documents.filter((e, i) => index != i);
2021-04-20 15:05:40 +01:00
2021-02-24 09:14:58 +01:00
}
2021-04-08 15:45:45 +01:00
async addParticipants() {
2023-09-06 21:23:21 +01:00
2021-04-09 10:33:19 +01:00
this.saveTemporaryData();
2021-04-08 15:45:45 +01:00
this.openAttendeesComponent.emit({
type: "intervenient"
});
this.clearContact.emit();
2023-08-11 16:14:25 +01:00
this.mostrarModal = true;
2021-04-08 15:45:45 +01:00
}
async addParticipantsCc() {
2021-04-09 10:33:19 +01:00
this.saveTemporaryData();
2021-07-12 14:32:43 +01:00
2021-04-08 15:45:45 +01:00
this.openAttendeesComponent.emit({
type: "CC"
});
this.clearContact.emit();
2021-03-24 15:10:46 +01:00
}
2021-02-24 09:14:58 +01:00
2021-05-24 16:49:25 +01:00
saveTemporaryData() {
window['temp.path:/home/agenda/new-event.component.ts'] = {
postEvent: this.postEvent,
eventBody: this.eventBody,
2022-05-30 16:43:54 +01:00
segment: this.segment,
2023-07-28 16:28:59 +01:00
CalendarName: this.CalendarName,
documents: this.documents
}
}
2021-07-08 13:41:27 +01:00
/**
2021-07-12 14:32:43 +01:00
*
2021-07-08 13:41:27 +01:00
* @description o pipeline já esta a funcionar tuda vez que nos fazer push na branch master e test o pipeline executa os teste, mas agora os teste temos que melhora para testar a app em tudos os pontos
* o pipeline já está a funcionar toda vez que nos fazer um push na branch master ou teste o pipeline executa os testes, mas agora os testes temos que melhorar para testar a app em todos os pontos
*/
2021-04-20 15:05:40 +01:00
restoreTemporaryData(): boolean {
2021-06-23 15:39:45 +01:00
2023-09-06 21:23:21 +01:00
const restoredData = window['temp.path:/home/agenda/new-event.component.ts']
2023-09-06 21:23:21 +01:00
if (JSON.stringify(restoredData) != "{}" && undefined != restoredData) {
this.postEvent = restoredData.postEvent
this.eventBody = restoredData.eventBody
this.segment = restoredData.segment
2022-05-30 16:43:54 +01:00
this.CalendarName = restoredData.CalendarName
2023-07-28 16:28:59 +01:00
this.documents = restoredData.documents
2021-06-23 15:39:45 +01:00
// restore dater for date and hours picker
2021-08-25 15:23:30 +01:00
return true;
} else {
2021-06-23 15:39:45 +01:00
2023-09-06 21:23:21 +01:00
}
}
2022-05-12 16:54:11 +01:00
deleteTemporaryData() {
window['temp.path:/home/agenda/new-event.component.ts'] = {}
}
2023-09-06 21:23:21 +01:00
eventToaproveBody(event, calendarId, role, userId, attachments) {
let toAproveObject = {
"EventProcess": {
"Body": event.Body,
"Location": event.Location,
"Subject": event.Subject,
"StartDate": event.StartDate,
"EndDate": event.EndDate,
"Status": "Active",
"IsAllDayEvent": event.IsRecurring,
"EventType": event.EventType,
"ParticipantsList": event.Attendees,
"EventRecurrence": event.EventRecurrence,
"HasAttachments": event.HasAttachments,
"CalendarId": calendarId,
"Role": role,
"wxUserID": userId,
"TimeZone": "W. Central Africa Standard Time"
},
"Attachments": attachments,
"InstanceID": "AGD_" + this.loggeduser.UserName + "_" + this.processeService.generateInstaceFormatDate()
}
return toAproveObject;
}
async fetchContacts(filter: string) {
2023-12-06 17:01:00 +01:00
console.log(this.loggeduser.Profile)
if (this.loggeduser.Profile == 'PR') {
this.contactsService.getContacts(filter).subscribe(result => {
if (this.eventPersons != null) {
this.eventPersons.forEach(attendee => {
const index: number = result.findIndex((cont) => {
return cont.EmailAddress.toLocaleLowerCase() == attendee.EmailAddress.toLocaleLowerCase()
});
result.splice(index, 1);
});
}
this.contacts = result;
console.log('Attendes Email', this.loggeduser.Email)
let filterLoggedUserEmail = this.contacts.filter(item => item.RoleDescription == "Ministro e Director do Gabinete do PR")
console.log('Attendes Email', filterLoggedUserEmail)
this.contacts = filterLoggedUserEmail;
this.taskParticipants.push(this.contacts[0]);
this.setIntervenient.emit(this.taskParticipants);
console.log('Attendes Email', this.taskParticipants)
}
);
}
}
2021-07-08 13:41:27 +01:00
}