create event from gabinete

This commit is contained in:
Peter Maquiran
2024-07-04 16:33:45 +01:00
parent 0e12b5de5e
commit 06417ead0f
22 changed files with 881 additions and 311 deletions
@@ -25,7 +25,7 @@
</div>
</div>
<div class="container-div" >
<div *ngIf="(sharedCalendar | async) as calendarData" class="container-div" >
<div class="ion-item-class-2 d-flex">
<div class="ion-icon-class">
<ion-icon slot="start" src="assets/images/icons-calendar.svg"></ion-icon>
@@ -33,19 +33,22 @@
<div class="ion-input-class flex-grow-1 justify-center align-center material-inputs " [class.input-error]="Form?.get('CalendarName')?.invalid && validateFrom ">
<mat-form-field appearance="none" class="width-100" color="ion-color-secondary" placeholder="Selecione agenda">
<mat-select [(value)]="CalendarName" (selectionChange)="changeAgenda()">
<div *ngIf="utils.hasPrCalendar(calendarData) && !hasChangeCalendar " style="margin-bottom: -20px;">PR</div>
<div *ngIf="selectedUserCalendar == sessionStore.user.UserId && !hasChangeCalendar && sessionStore.user.Profile != 'PR' " style="margin-bottom: -20px;">
Minha agenda
</div>
<!-- <mat-option *ngFor="let calendars of _eventService.calendarNamesAry; let i = index" value="{{calendars}}">
<div *ngIf="calendars != 'Meu calendario' && calendars == 'Presidente da República'"> {{ environment.agendaPR}} </div>
<div *ngIf="calendars != 'Meu calendario' && calendars == 'Ministro e Director do Gabinete do PR'"> {{ environment.agendaVP}} </div>
<div *ngIf="calendars != 'Meu calendario' && calendars != 'Ministro e Director do Gabinete do PR' && calendars != 'Presidente da República'"> Agenda do {{calendars}} </div>
<mat-select [(value)]="selectedUserCalendar" (selectionChange)="changeAgenda();changeSegmentCalendar()">
<mat-option *ngFor="let calendars of calendarData" value="{{calendars.wxUserId}}">
<div *ngIf="calendars.roleId == RoleIdService.PRES">PR </div>
<div *ngIf="calendars.roleId == RoleIdService.MD && calendars.roleId != sessionStore.user.RoleID">AGENDA DO MDGPR</div>
<div *ngIf="calendars.roleId != RoleIdService.MD && calendars.roleId != RoleIdService.PRES && calendars.wxFullName && calendars.wxUserId != sessionStore.user.UserId"> Agenda do {{calendars.wxFullName}} </div>
<div *ngIf="calendars.wxUserId == sessionStore.user.UserId && sessionStore.user.Profile != 'PR'">
Minha agenda
</div>
<div *ngIf="calendars == 'Meu calendario'"> Minha agenda </div> -->
<mat-option *ngFor="let calendars of eventService.calendarNamesAry" value="{{ calendars.Fullname || calendars}}">
<div *ngIf="calendars != 'Meu calendario' && calendars.Role == 'Presidente da República'"> {{ environment.agendaPR}} </div>
<div *ngIf="calendars != 'Meu calendario' && calendars.Role == 'Ministro e Director do Gabinete do PR'"> {{ environment.agendaVP}} </div>
<div *ngIf="calendars != 'Meu calendario' && calendars.Role != 'Ministro e Director do Gabinete do PR' && calendars.Role != 'Presidente da República'"> Agenda do {{calendars.Fullname}} </div>
<div *ngIf="calendars == 'Meu calendario'"> Minha agenda </div>
</mat-option>
</mat-select>
@@ -72,7 +75,6 @@
<ion-icon slot="start" src="assets/images/icons-calendar.svg"></ion-icon>
</div>
<div class="ion-input-class flex-grow-1 justify-center align-center material-inputs " [class.input-error]="Form?.get('CalendarName')?.invalid && validateFrom ">
<mat-form-field appearance="none" class="width-100" color="ion-color-secondary" placeholder="Selecione agenda">
<mat-select [(value)]="postData.CalendarName" >
<mat-option *ngFor="let calendars of CalendarNamesOptions" value="{{calendars}}">
@@ -81,13 +83,10 @@
</mat-select>
</mat-form-field>
</div>
</div>
</div>
<div class="container-div">
<div class="ion-item-class-2">
<div class="ion-icon-class">
@@ -95,7 +94,6 @@
</div>
<div class="ion-input-class" [class.input-error]="Form?.get('Categories')?.invalid && validateFrom ">
<mat-form-field appearance="none" class="width-100" placeholder="Sample Type" required>
<!-- <input matInput type="text" > -->
<mat-select [(ngModel)]="postData.Category" >
@@ -114,10 +112,84 @@
</mat-select>
</mat-form-field>
</div>
</div>
</div>
<div class="container-div">
<div>
<ion-item>
<ion-label>Todo dia</ion-label>
<ion-checkbox [(ngModel)]="allDayCheck" (ionChange)="onCheckboxChange($event)"></ion-checkbox>
</ion-item>
</div>
</div>
<div class="container-div">
<div class="ion-item-class-2 d-flex">
<div class="ion-icon-class">
<ion-icon slot="start" src="assets/images/icons-reapet.svg"></ion-icon>
</div>
<div class="ion-input-class flex-grow-1 justify-center align-center material-inputs">
<mat-form-field appearance="none" class="width-100" placeholder="Sample Type" required>
<!-- <input matInput type="text" > -->
<mat-select [(value)]="postData.EventRecurrence.frequency" >
<mat-option value="never">
Nunca
</mat-option>
<mat-option value="daily">
Diário
</mat-option>
<mat-option value="weekly">
Semanalmente
</mat-option>
<mat-option value="monthly">
Mensal
</mat-option>
<mat-option value="yearly">
Anual
</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
</div>
<div *ngIf="postData.EventRecurrence.frequency != 'never'" class="container-div">
<div class="ion-item-class-2 d-flex" >
<div class="ion-icon-class">
<ion-icon slot="start" src="assets/images/icons-reapet.svg"></ion-icon>
</div>
<div class="ion-input-class flex-grow-1 justify-center align-center material-inputs materia-top" >
<mat-form-field appearance="none" class="date-hour-picker">
<input matInput [ngxMatDatetimePicker]="picker1"
placeholder="Data Fim de Recorrência*"
[(ngModel)]="postData.EventRecurrence.until"
[disabled]="disabled"
>
<mat-datepicker-toggle id="new-inicio" matSuffix [for]="picker1" ></mat-datepicker-toggle>
<ngx-mat-datetime-picker #picker1
[showSpinners]="showSpinners"
[showSeconds]="showSeconds"
[stepHour]="stepHour" [stepMinute]="stepMinute"
[stepSecond]="stepSecond"
[touchUi]="touchUi"
[hideTime]="true"
>
</ngx-mat-datetime-picker>
</mat-form-field>
</div>
</div>
</div>
<div class="container-div">
<div class="ion-item-class-2">
@@ -129,7 +201,7 @@
<mat-form-field appearance="none" class="width-100 date-hour-picker">
<input matInput [ngxMatDatetimePicker]="picker1"
placeholder="Choose a date*"
[formControl]="dateControlStart"
[(ngModel)]="postData.StartDate"
[disabled]="disabled"
>
<mat-datepicker-toggle id="new-inicio" matSuffix [for]="picker1" ></mat-datepicker-toggle>
@@ -156,9 +228,8 @@
<mat-form-field appearance="none" class="date-hour-picker width-100 ">
<input matInput [ngxMatDatetimePicker]="fim"
placeholder="Fim*"
[formControl]="dateControlEnd"
[(ngModel)]="postData.EndDate"
[disabled]="disabled"
[min] = "dateControlStart.value"
>
<mat-datepicker-toggle id="new-fim" matSuffix [for]="fim" ></mat-datepicker-toggle>
<ngx-mat-datetime-picker #fim
@@ -173,37 +244,6 @@
</div>
</div>
<div *ngIf="EventRecurrenceType != '-1'" class="container-div width-100">
<div class="ion-item-class-2 d-flex">
<div class="ion-icon-class">
<ion-icon slot="start" src="assets/images/icons-calendar.svg"></ion-icon>
</div>
<div (click)="openLastOccurrence()" class="ion-input-class flex-grow-1">
<mat-form-field class="date-hour-picker">
<input matInput [ngxMatDatetimePicker]="occurrrence"
placeholder="Choose a date"
[(ngModel)]="Occurrence"
[disabled]="disabled"
[min]="dateStart"
>
<mat-datepicker-toggle id="last-occurrence" matSuffix [for]="occurrrence"></mat-datepicker-toggle>
<ngx-mat-datetime-picker #occurrrence
[showSpinners]="showSpinners"
[showSeconds]="showSeconds"
[stepHour]="stepHour" [stepMinute]="stepMinute"
[stepSecond]="stepSecond"
[touchUi]="touchUi"
>
</ngx-mat-datetime-picker>
</mat-form-field>
</div>
</div>
</div>
<div class="container-div">
<div class="ion-item-class-2">
<div class="ion-icon-class">
@@ -318,4 +358,3 @@
<button class="btn-cancel" shape="round" (click)="close()">Cancelar</button>
</div>
</ion-footer>
@@ -9,7 +9,6 @@ import { AttachmentsService } from 'src/app/services/attachments.service';
import { SearchPage } from 'src/app/pages/search/search.page';
import { SearchList } from 'src/app/models/search-document';
import { LoginUserRespose } from 'src/app/models/user.model';
import { AuthService } from 'src/app/services/auth.service';
import { AttendeesPageModal } from 'src/app/pages/events/attendees/attendees.page';
import { ToastService } from 'src/app/services/toast.service';
import { FormControl, FormGroup, Validators } from '@angular/forms';
@@ -24,6 +23,12 @@ import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { environment } from 'src/environments/environment';
import { TaskService } from 'src/app/services/task.service'
import { ContactsService } from 'src/app/services/contacts.service';
import { Utils } from 'src/app/services/Repositorys/Agenda/utils';
import { Observable } from 'rxjs';
import { TableSharedCalendar } from 'src/app/services/Repositorys/Agenda/agenda-local-data-source.service';
import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service';
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
import { isHttpError } from 'src/app/services/http.service';
const moment = _rollupMoment || _moment;
@@ -66,8 +71,6 @@ export class BookMeetingModalPage implements OnInit {
public stepMinute = 15;
public stepSecond = 5;
public dateControlStart = new FormControl(moment("DD MM YYYY hh"));
public dateControlEnd = new FormControl(moment("DD MM YYYY hh"));
CalendarNamesOptions = ['Oficial', 'Pessoal']
Form: FormGroup;
@@ -78,13 +81,6 @@ export class BookMeetingModalPage implements OnInit {
showLoader = false
get dateStart() {
return this.dateControlStart.value;
}
get dateEnd() {
return this.dateControlEnd.value;
}
@ViewChild('picker') picker: any;
@ViewChild('fim') fim: any;
@@ -94,7 +90,7 @@ export class BookMeetingModalPage implements OnInit {
task: any;
fulltask: any;
taskParticipants: EventPerson[];
taskParticipants: EventPerson[] = [];
taskParticipantsCc: EventPerson[] = [];
taskDocId: string;
@@ -111,14 +107,18 @@ export class BookMeetingModalPage implements OnInit {
showAttendees = false;
emptyTextDescription = "Selecionar intervenientes";
CalendarName
sessionStore = SessionStore;
environment = environment
loggeduser: LoginUserRespose;
eventPersons: EventPerson[];
contacts: EventPerson[];
hasChangeCalendar = false
selectedUserCalendar:any;
sharedCalendar: Observable<TableSharedCalendar[]>
allDayCheck: boolean = false;
CalendarNameShow = true
constructor(
private modalController: ModalController,
private navParams: NavParams,
@@ -131,8 +131,8 @@ export class BookMeetingModalPage implements OnInit {
private httpErroHandle: HttpErrorHandle,
public TaskService: TaskService,
private contactsService: ContactsService,
public utils: Utils,
private agendaDataRepository: AgendaDataRepositoryService,
) {
this.taskParticipants = [];
@@ -153,19 +153,11 @@ export class BookMeetingModalPage implements OnInit {
this.postData.CalendarName = "Oficial";
let startDate = this.roundTimeQuarterHour()
this.dateControlStart = new FormControl(moment(startDate));
this.dateControlEnd = new FormControl(moment(this.roundTimeQuarterHourPlus15(startDate)));
this.postData.StartDate = startDate;
this.postData.EndDate = this.roundTimeQuarterHourPlus15(startDate);
this.postData.Category = 'Reunião'
if (!this.CalendarName) {
if (this.eventService.calendarNamesAry.includes('Meu calendario')) {
this.CalendarName = 'Meu calendario';
// console.log(this.eventService.calendarNamesAry)
} else {
this.CalendarName = this.eventService.calendarNamesAry[0]
}
}
this.postData.IsAllDayEvent = false
if (this.taskParticipants.length == 0) {
this.taskParticipants = [
@@ -180,11 +172,19 @@ export class BookMeetingModalPage implements OnInit {
this.changeAgenda();
this.loggeduser = SessionStore.user;
this.sharedCalendar = this.agendaDataRepository.getShareCalendarItemsLiveWithOrder()
this.postData.EventRecurrence = {
frequency: 'never',
until: "",
Type: ''
}
}
ngOnInit() {
// console.log('TEsTEROLE',this.eventService.calendarNamesAry)
this.adding = "intervenient";
this.setCalendarByDefault(true)
this.getAttachments();
this.setDefaultTime()
this.getRecurrenceTypes();
@@ -193,6 +193,24 @@ export class BookMeetingModalPage implements OnInit {
}
async setCalendarByDefault(force) {
if (!this.selectedUserCalendar || force) {
const data = await this.agendaDataRepository.geCalendars()
const prObject = data.find(e => e?.roleId == 100000014)
if(prObject) {
this.selectedUserCalendar = prObject.wxUserId
} else {
this.selectedUserCalendar = SessionStore.user.UserId
}
this.changeAgenda()
}
}
ngOnDestroy() {
clearInterval(this.myInterval)
}
@@ -205,33 +223,34 @@ export class BookMeetingModalPage implements OnInit {
})
}, 1000);
getRecurrenceTypes() {
this.calendarService.getRecurrenceTypes().subscribe(res => {
this.recurringTypes = res;
});
}
changeSegmentCalendar() {
this.hasChangeCalendar = true
}
changeAgenda() {
async changeAgenda() {
setTimeout(() => {
this.CalendarNameShow = false
if (this.calendarService.calendarNamesType[this.CalendarName]?.['Oficial'] && this.calendarService.calendarNamesType[this.CalendarName]?.['Pessoal']) {
const result = await this.agendaDataRepository.geCalendars()
this.CalendarNamesOptions = ['Oficial', 'Pessoal']
} else if (this.calendarService.calendarNamesType[this.CalendarName]?.['Oficial']) {
const selectedCalendar = result.find(e => e.wxUserId == this.selectedUserCalendar)
if(selectedCalendar) {
if(selectedCalendar.shareType == 1) {
this.CalendarNamesOptions = ['Oficial']
this.postData.CalendarName = 'Oficial'
} else if (this.calendarService.calendarNamesType[this.CalendarName]?.['Pessoal']) {
} else if(selectedCalendar.shareType == 2) {
this.CalendarNamesOptions = ['Pessoal']
this.postData.CalendarName = 'Pessoal'
} else {
} else if (selectedCalendar.shareType == 3) {
this.CalendarNamesOptions = ['Oficial', 'Pessoal']
}
}, 50)
}
}
@@ -258,13 +277,13 @@ export class BookMeetingModalPage implements OnInit {
runValidation() {
this.validateFrom = true
if (new Date(this.dateStart).getTime() > new Date(this.dateEnd).getTime()) {
if (new Date(this.postData.StartDate).getTime() > new Date(this.postData.EndDate).getTime()) {
this.toastService._badRequest("A data de fim não pode ser inferior a data de início do evento")
}
}
get dateValid() {
return new Date(this.dateControlStart.value).getTime() < new Date(this.dateControlEnd.value).getTime() ? 'ok' : null
return new Date(this.postData.StartDate).getTime() < new Date(this.postData.EndDate).getTime() ? 'ok' : null
}
injectValidation() {
@@ -293,7 +312,8 @@ export class BookMeetingModalPage implements OnInit {
})
}
async saveTask() {
@XTracerAsync({name:'convocar-reunia', bugPrint: true})
async saveTask(tracing?: TracingType) {
if (SessionStore.user.Profile != 'PR') {
this.injectValidation()
@@ -303,6 +323,8 @@ export class BookMeetingModalPage implements OnInit {
let Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
console.log({Attendees})
this.eventBody = {
BodyType: '1',
Text: this.postData.Body.Text,
@@ -314,26 +336,23 @@ export class BookMeetingModalPage implements OnInit {
Location: this.postData.Location,
CalendarId: '',
CalendarName: this.postData.CalendarName,
StartDate: this.dateStart,
EndDate: this.dateEnd,
EventType: 'Reunião',
StartDate: this.postData.StartDate,
EndDate: this.postData.EndDate,
EventType: 'Meeting',
Attendees: Attendees,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: 'UTC',
Organizer: null,
Category: 'Reunião',
Category: 'Meeting',
HasAttachments: true,
EventRecurrence: {
Type: this.EventRecurrenceType,
LastOccurrence: this.Occurrence
},
IsAllDayEvent: this.postData.IsAllDayEvent,
EventRecurrence: this.postData.EventRecurrence,
Attachments: []
}
const DocumentToSave = this.documents.map((e: any) => {
console.log('ASSUNTO', e.Assunto)
return {
ApplicationId: e.ApplicationType || e.ApplicationId,
Source: 1,
@@ -345,69 +364,105 @@ export class BookMeetingModalPage implements OnInit {
});
postData.Attachments = DocumentToSave;
let loader = this.toastService.loading();
if (this.task.FsId == '8') {
const loader = this.toastService.loading()
const calendar = await this.agendaDataRepository.getCalendarByUserId(this.selectedUserCalendar)
if(calendar.isOk()) {
try {
const CalendarId = this.selectedCalendarId()
await this.calendarService.genericPostExpedientEvent(this.task.DocId, postData, "", this.task.SerialNumber, this.task.FsId, CalendarId).toPromise();
this.modalController.dismiss();
this.httpErroHandle.httpsSucessMessagge('Marcar Reunião')
const value = await this.agendaDataRepository.createEvent(postData, this.documents, calendar.value, tracing).toPromise()
console.log(value)
this.httpErroHandle.httpsSucessMessagge('new event')
loader.remove();
tracing.setAttribute('outcome', 'success')
this.close();
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
}
finally {
loader.remove()
if(!isHttpError(error)) {
this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #1')
console.log(error)
tracing.bugFlag()
} else {
this.httpErroHandle.httpStatusHandle(error.status)
}
console.log('create event error: ', error)
tracing.setAttribute('outcome', 'failed')
}
} else {
tracing.setAttribute('outcome', 'failed')
tracing.setAttribute('no', 'this.selectedUserCalendar')
tracing.bugFlag()
}
if (this.task.FsId == '8') {
// const calendar = await this.agendaDataRepository.getCalendarByUserId(this.selectedUserCalendar)
// if(calendar.isOk()) {
// try {
// const value = await this.agendaDataRepository.createEvent(this.postData, this.documents, calendar.value, tracing).toPromise()
// console.log(value)
// this.httpErroHandle.httpsSucessMessagge('new event')
// loader.remove();
// tracing.setAttribute('outcome', 'success')
// } catch (error) {
// console.log('create event error: ', error)
// tracing.setAttribute('outcome', 'failed')
// this.httpErroHandle.httpStatusHandle(error.status)
// }
// } else {
// }
}
else if (this.task.FsId == '361') {
console.log('361')
const loader = this.toastService.loading()
try {
// console.log('361')
// const loader = this.toastService.loading()
// try {
const CalendarId = this.selectedCalendarId()
console.log({ CalendarId })
await this.calendarService.genericCreateTaskEvent(this.task.FolderID | this.task.FolderId, postData, "", this.task.SerialNumber, this.task.FsId, CalendarId).toPromise();
// const CalendarId = this.selectedCalendarId()
// console.log({ CalendarId })
// await this.calendarService.genericCreateTaskEvent(this.task.FolderID | this.task.FolderId, postData, "", this.task.SerialNumber, this.task.FsId, CalendarId).toPromise();
this.close();
this.httpErroHandle.httpsSucessMessagge('Marcar Reunião')
// this.close();
// this.httpErroHandle.httpsSucessMessagge('Marcar Reunião')
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
// } catch (error) {
// this.httpErroHandle.httpStatusHandle(error)
// } finally {
// loader.remove()
// }
}
else {
this.toastService._successMessage('Não é possível marcar a reunião de momento');
}
loader.remove();
}
onCheckboxChange(event: any) {
if (this.allDayCheck) {
this.postData.IsAllDayEvent = this.allDayCheck;
this.postData.StartDate = this.setAlldayTime(this.postData.StartDate)
this.postData.EndDate = this.setAlldayTimeEndDate(this.postData.EndDate)
selectedCalendarId() {
if (this.calendarService.calendarNamesType[this.CalendarName]?.['Oficial'] && this.postData.CalendarName == 'Oficial') {
return this.calendarService.calendarNamesType[this.CalendarName]['OficialId']
} else if (this.calendarService.calendarNamesType[this.CalendarName]?.['Pessoal'] && this.postData.CalendarName == 'Pessoal') {
return this.calendarService.calendarNamesType[this.CalendarName]['PessoalId']
console.log('Recurso ativado!!');
} else {
return '11:11'
this.postData.IsAllDayEvent = this.allDayCheck;
this.postData.EndDate = this.setAlldayTimeEndDateNotAlday(this.postData.EndDate)
console.log('Recurso desativado');
}
}
async addParticipants() {
this.adding = "intervenient";
@@ -626,4 +681,37 @@ export class BookMeetingModalPage implements OnInit {
}
}
setAlldayTime(timeToReturn) {
let date: any = new Date(timeToReturn) || new Date();
let newdate = new Date();
date.setHours(0)
date.setMinutes(0)
date.setSeconds(0);
return date
}
setAlldayTimeEndDate(timeToReturn) {
let date: any = new Date(timeToReturn) || new Date();
let newdate = new Date();
date.setHours(23)
date.setMinutes(59)
date.setSeconds(0);
return date
}
setAlldayTimeEndDateNotAlday(timeToReturn) {
let date: any = new Date(timeToReturn) || new Date();
let newdate = new Date();
date.setHours(23)
date.setMinutes(0)
date.setSeconds(0);
return date
}
}