Files
doneit-web/src/app/modals/document-set-up-meeting/document-set-up-meeting.page.ts
T

517 lines
14 KiB
TypeScript
Raw Normal View History

2021-07-29 10:13:39 +01:00
import { Component, OnInit, ViewChild } from '@angular/core';
2021-07-29 15:40:24 +01:00
import { Router } from '@angular/router';
import { ModalController, NavParams } from '@ionic/angular';
2021-07-29 10:13:39 +01:00
import { Event } from 'src/app/models/event.model'
import { EventPerson } from 'src/app/models/eventperson.model';
import { SearchPage } from 'src/app/pages/search/search.page';
2021-10-08 19:29:21 +01:00
import { SearchDocumentDetails, SearchFolderDetails, SearchList } from 'src/app/models/search-document';
2021-08-27 15:21:15 +01:00
import { LoginUserRespose } from 'src/app/models/user.model';
2021-07-29 10:13:39 +01:00
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';
import * as _moment from 'moment';
import * as _rollupMoment from 'moment';
import { NgxMatDateFormats } from '@angular-material-components/datetime-picker';
import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker';
2021-08-06 14:34:39 +01:00
import { EventsService } from 'src/app/services/events.service';
2021-08-20 12:02:27 +01:00
import { EventService } from 'src/app/services/rules/event.service';
import { EventPipe } from 'src/app/pipes/event.pipe';
2023-05-18 17:40:52 +01:00
import { ThemeService } from 'src/app/services/theme.service';
2022-10-12 17:01:09 +01:00
import { SessionStore } from 'src/app/store/session.service';
2023-02-27 17:39:10 +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-08-31 12:00:52 +01:00
import { TaskService } from 'src/app/services/task.service'
2021-10-22 15:43:57 +01:00
2021-07-29 10:13:39 +01:00
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
parse: {
dateInput: "YYYY-MMMM-DD HH:mm"
},
display: {
dateInput: "DD MMM YYYY H:mm",
monthYearLabel: "MMM YYYY",
dateA11yLabel: "LL",
monthYearA11yLabel: "MMMM YYYY"
}
}
@Component({
selector: 'app-document-set-up-meeting',
templateUrl: './document-set-up-meeting.page.html',
styleUrls: ['./document-set-up-meeting.page.scss'],
2021-08-06 14:34:39 +01:00
providers: [
{ provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_DATE_FORMATS },
]
2021-07-29 10:13:39 +01:00
})
export class DocumentSetUpMeetingPage implements OnInit {
public date: any;
public disabled = false;
public showSpinners = true;
public showSeconds = false;
public touchUi = false;
public enableMeridian = false;
public minDate = new Date();
public stepHour = 1;
2023-01-24 15:56:47 +01:00
public stepMinute = 15;
2021-07-29 10:13:39 +01:00
public stepSecond = 5;
p: any = {}
Form: FormGroup;
validateFrom = false
2021-08-06 14:34:39 +01:00
recurringTypes = [];
Occurrence: Date = new Date()
EventRecurrenceType = '-1'
2021-07-29 10:13:39 +01:00
showLoader = false
@ViewChild('picker') picker: any;
@ViewChild('fim') fim: any;
@ViewChild('inicio') inicio: any;
@ViewChild('picker1') picker1: any;
taskParticipants: EventPerson[] = [];
taskParticipantsCc: EventPerson[] = [];
taskDocId:string;
loadedAttachments:any;
2021-07-29 15:40:24 +01:00
2021-08-20 12:02:27 +01:00
attachments: SearchList[] = [];
2021-07-29 10:13:39 +01:00
adding: "intervenient" | "CC" = "intervenient";
postData: Event;
formLocationSatus: boolean = false;
showAttendees= false;
2021-08-27 15:21:15 +01:00
loggeduser: LoginUserRespose;
emptyTextDescription = "Selecionar intervenientes";
2021-07-29 10:13:39 +01:00
2021-08-20 12:02:27 +01:00
document: SearchFolderDetails | SearchDocumentDetails | any;
2021-09-15 13:38:14 +01:00
subject: string;
docs:any[] = [];
2021-08-20 17:14:25 +01:00
eventPipe = new EventPipe()
2022-06-13 15:27:28 +01:00
CalendarName;
CalendarNameShow = true
CalendarNamesOptions
2023-02-09 17:03:26 +01:00
testeFormDefaul = "Eudes"
2023-03-22 15:31:01 +01:00
environment = environment
2023-09-22 18:12:48 +01:00
2021-07-29 10:13:39 +01:00
constructor(
private modalController: ModalController,
private router:Router,
private navParams: NavParams,
authService: AuthService,
private toastService: ToastService,
2021-08-10 16:24:14 +01:00
private calendarService: EventsService,
2021-10-22 15:43:57 +01:00
private eventService: EventService,
2022-06-13 15:27:28 +01:00
public ThemeService: ThemeService,
public _eventService: EventsService,
2023-08-31 12:00:52 +01:00
private httpErroHandle: HttpErrorHandle,
public TaskService: TaskService
2021-10-08 19:29:21 +01:00
) {
2022-10-12 17:01:09 +01:00
this.loggeduser = SessionStore.user;
2021-10-08 19:29:21 +01:00
this.document = this.navParams.get('document')
2023-08-20 22:00:23 +01:00
if(Array.isArray(this.document)) {
this.attachments = this.document
} else {
this.attachments = [this.document]
}
2023-09-22 18:12:48 +01:00
2023-08-20 22:00:23 +01:00
this.document = []
2021-10-08 19:29:21 +01:00
this.subject = this.navParams.get('subject')
2021-07-29 15:40:24 +01:00
2021-10-08 19:29:21 +01:00
this.postData = new Event();
this.postData.Body ={ BodyType : "1", Text : ""};
2021-07-29 10:13:39 +01:00
2021-10-08 19:29:21 +01:00
this.postData.Subject = this.subject
this.postData.CalendarName = "Oficial";
2021-07-29 10:13:39 +01:00
2021-10-08 19:29:21 +01:00
this.postData.Category = 'Reunião'
2023-01-24 15:56:47 +01:00
if(!this.CalendarName) {
if(this._eventService.calendarNamesAry.includes('Meu calendario')) {
this.CalendarName = 'Meu calendario';
} else {
this.CalendarName = this._eventService.calendarNamesAry[0]
}
}
if(this.taskParticipants.length == 0) {
2023-08-22 17:50:18 +01:00
this.taskParticipants = [
// {
// EmailAddress: SessionStore.user.Email,
// IsRequired: true,
// Name: SessionStore.user.FullName,
// UserType: "GD"
// }
]
2023-01-24 15:56:47 +01:00
}
2023-07-16 21:38:37 +01:00
this.changeAgenda()
2021-07-29 15:40:24 +01:00
}
2021-07-29 10:13:39 +01:00
ngOnInit() {
this.adding = "intervenient";
this.setDefaultTime()
2021-08-06 14:34:39 +01:00
this.getRecurrenceTypes();
2023-09-22 18:12:48 +01:00
2021-08-06 14:34:39 +01:00
}
2023-08-22 08:35:44 +01:00
ngOnDestroy() {
clearInterval(this.myInterval)
}
myInterval = setInterval(() => {
document.querySelectorAll('.ngx-mat-timepicker input').forEach((e :any) => {
if(e) {
e.disabled = true;
}
})
}, 1000);
2021-08-06 14:34:39 +01:00
getRecurrenceTypes() {
2021-10-08 19:29:21 +01:00
this.calendarService.getRecurrenceTypes().subscribe( res=> {
2021-08-06 14:34:39 +01:00
this.recurringTypes = res;
});
2021-07-29 10:13:39 +01:00
}
setDefaultTime() {
this.setStartDate()
this.setEndDate();
}
setStartDate() {
if(!this.postData.StartDate) {
this.postData.StartDate = this.roundTimeQuarterHour();
}
}
setEndDate() {
if(!this.postData.EndDate) {
2023-02-13 18:50:31 +01:00
this.postData.EndDate = this.roundTimeQuarterHourPlus15(this.postData.StartDate);
}
2021-07-29 10:13:39 +01:00
}
close() {
this.modalController.dismiss(null);
}
runValidation() {
this.validateFrom = true
}
2023-02-06 13:52:08 +01:00
get dateValid() {
return new Date(this.postData.StartDate).getTime() < new Date(this.postData.EndDate).getTime() ? 'ok': null
}
2021-07-29 10:13:39 +01:00
injectValidation() {
this.Form = new FormGroup({
Subject: new FormControl(this.postData.Subject, [
2023-02-23 18:03:22 +01:00
Validators.required,
2021-07-29 10:13:39 +01:00
// Validators.minLength(4)
]),
Location: new FormControl(this.postData.Location, [
2023-02-23 18:03:22 +01:00
Validators.required,
2021-07-29 10:13:39 +01:00
]),
CalendarName: new FormControl(this.postData.CalendarName, [
// Validators.required
]),
2023-02-06 13:52:08 +01:00
Date: new FormControl( (this.dateValid), [
2021-07-29 10:13:39 +01:00
Validators.required
]),
participantes: new FormControl(this.taskParticipants, [
// Validators.required
]),
Categories: new FormControl(this.postData.Category, [
// Validators.required
]),
})
}
2022-06-13 15:27:28 +01:00
changeAgenda() {
this.CalendarNameShow = false
setTimeout(() => {
this.CalendarNameShow = true
if(this._eventService.calendarNamesType[this.CalendarName]?.['Oficial'] && this._eventService.calendarNamesType[this.CalendarName]?.['Pessoal']) {
2023-09-22 18:12:48 +01:00
2022-06-13 15:27:28 +01:00
this.CalendarNamesOptions = ['Oficial', 'Pessoal']
2023-09-22 18:12:48 +01:00
2022-06-13 15:27:28 +01:00
} else if (this._eventService.calendarNamesType[this.CalendarName]?.['Oficial']) {
this.CalendarNamesOptions = ['Oficial']
this.postData.CalendarName = 'Oficial'
2023-09-22 18:12:48 +01:00
2022-06-13 15:27:28 +01:00
} else if (this._eventService.calendarNamesType[this.CalendarName]?.['Pessoal']) {
this.CalendarNamesOptions = ['Pessoal']
this.postData.CalendarName = 'Pessoal'
2023-09-22 18:12:48 +01:00
2022-06-13 15:27:28 +01:00
} else {
this.CalendarNamesOptions = ['Oficial', 'Pessoal']
}
}, 50)
}
2021-07-29 15:40:24 +01:00
async saveTask() {
2021-07-29 10:13:39 +01:00
if(this.loggeduser.Profile == 'MDGPR') {
this.injectValidation()
this.runValidation()
2021-08-06 14:34:39 +01:00
if(this.Form.invalid) return false
2021-07-29 10:13:39 +01:00
}
let Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
2022-06-13 15:27:28 +01:00
if(this.document.Documents) {
2021-09-16 09:35:09 +01:00
this.document.Documents.forEach((e)=> {
this.docs.push({
ApplicationId: e.ApplicationId || e.ApplicationType,
Source: 1,
SourceId: e.DocId || e.docID || e.docId || e.SourceId || e.Id,
2021-09-16 09:35:09 +01:00
SourceName: e.Assunto
})
})
}
else{
2021-09-15 13:38:14 +01:00
this.docs.push({
2021-09-16 09:35:09 +01:00
ApplicationId: this.document.ApplicationId || this.document.ApplicationType,
2021-09-15 13:38:14 +01:00
Source: 1,
SourceId: this.document.DocId || this.document.docID || this.document.docId || this.document.SourceId || this.document.Id,
2021-09-16 09:35:09 +01:00
SourceName: this.document.Assunto
2021-09-15 13:38:14 +01:00
})
2021-09-16 09:35:09 +01:00
}
2021-07-29 15:40:24 +01:00
2021-08-20 12:02:27 +01:00
let postEvent = {
EventId: '',
Subject: this.postData.Subject,
Body: this.postData.Body.Text,
Location: this.postData.Location,
CalendarId: this.selectedCalendarId(),
2021-08-20 12:02:27 +01:00
CalendarName: this.postData.CalendarName,
StartDate: this.postData.StartDate,
EndDate: this.postData.EndDate,
EventType: 'Reunião',
Attendees: Attendees,
IsMeeting: false, //
IsRecurring: this.postData.IsRecurring,
AppointmentState: 0, //
TimeZone: '', //
Organizer: '', //
Category: 'Reunião',
HasAttachments: false,
EventRecurrence: {
Type: this.EventRecurrenceType,
2021-09-15 14:19:16 +01:00
LastOccurrence: this.Occurrence,
2021-08-20 12:02:27 +01:00
},
2023-05-18 17:40:52 +01:00
// Attachments: this.docs,
2021-07-29 10:13:39 +01:00
}
2021-09-15 13:38:14 +01:00
const laoder = this.toastService.loading()
2021-08-20 12:02:27 +01:00
2021-09-15 13:38:14 +01:00
this.eventService.create({ body: postEvent, calendar: this.postData.CalendarName }).subscribe(async (respose) => {
2023-05-18 17:40:52 +01:00
laoder.remove();
2023-02-27 17:39:10 +01:00
this.httpErroHandle.httpsSucessMessagge('new event');
2021-08-20 12:04:38 +01:00
this.modalController.dismiss()
2021-10-08 19:29:21 +01:00
}, (error) => {
2023-05-18 17:40:52 +01:00
laoder.remove();
2023-02-27 17:39:10 +01:00
this.httpErroHandle.httpStatusHandle(error)
2021-10-08 19:29:21 +01:00
}, ()=>{
2023-05-18 17:40:52 +01:00
laoder.remove();
2021-09-16 10:11:29 +01:00
});
2021-08-20 12:02:27 +01:00
2021-07-29 10:13:39 +01:00
}
async addParticipants() {
this.adding = "intervenient";
if(window.innerWidth <= 801){
const modal = await this.modalController.create({
component: AttendeesPageModal,
componentProps: {
adding: this.adding,
taskParticipants: this.taskParticipants,
taskParticipantsCc: this.taskParticipantsCc
},
cssClass: 'modal modal-desktop',
backdropDismiss: false
});
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);
}
2023-07-14 10:19:33 +01:00
}, (error) => {
2023-09-22 18:12:48 +01:00
console.log(error)
2021-07-29 10:13:39 +01:00
});
2023-07-15 11:01:09 +01:00
await modal.present()
2021-07-29 10:13:39 +01:00
} else {
this.showAttendees = true;
}
}
async addParticipantsCc() {
this.adding = "CC";
if(window.innerWidth <= 800) {
const modal = await this.modalController.create({
component: AttendeesPageModal,
componentProps: {
adding: this.adding,
taskParticipants: this.taskParticipants,
taskParticipantsCc: this.taskParticipantsCc
},
cssClass: 'modal modal-desktop',
backdropDismiss: false
});
2023-09-22 18:12:48 +01:00
2021-07-29 10:13:39 +01:00
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);
}
2023-07-14 10:19:33 +01:00
}, (error) => {
console.log(error)
2021-07-29 10:13:39 +01:00
});
2023-07-15 11:01:09 +01:00
await modal.present();
2021-07-29 10:13:39 +01:00
} else {
this.showAttendees = true;
}
}
async getDoc() {
const modal = await this.modalController.create({
component: SearchPage,
2021-07-29 15:57:08 +01:00
cssClass: 'modal modal-desktop modal-width-100-width-background modal-background',
2021-07-29 10:13:39 +01:00
componentProps: {
type: 'AccoesPresidenciais & ArquivoDespachoElect',
showSearchInput: true,
select: true
}
});
2023-09-22 18:12:48 +01:00
2021-07-29 10:13:39 +01:00
modal.onDidDismiss().then((res)=> {
if(res){
const data = res.data;
2021-07-29 15:40:24 +01:00
this.attachments.push(data.selected);
2021-07-29 10:13:39 +01:00
}
2023-07-14 10:19:33 +01:00
}, (error) => {
console.log(error)
});
2023-07-15 11:01:09 +01:00
await modal.present();
2021-07-29 10:13:39 +01:00
}
removeAttachment(index: number) {
2021-07-29 15:40:24 +01:00
this.attachments = this.attachments.filter( (e, i) => index != i);
2021-07-29 10:13:39 +01:00
}
validateFormInputs() {
2021-07-29 10:13:39 +01:00
let formLocation = this.postData.Location.trim();
if(!this.postData.Location && formLocation.length <= 0){
this.formLocationSatus = true;
}
}
selectedCalendarId () {
if (this._eventService.calendarNamesType[this.CalendarName]?.['Oficial'] && this.postData.CalendarName == 'Oficial') {
return this._eventService.calendarNamesType[this.CalendarName]['OficialId']
} else if (this._eventService.calendarNamesType[this.CalendarName]?.['Pessoal'] && this.postData.CalendarName == 'Pessoal') {
return this._eventService.calendarNamesType[this.CalendarName]['PessoalId']
} else {
return '11:11'
}
}
2023-09-22 18:12:48 +01:00
2021-07-29 10:13:39 +01:00
dynamicSetIntervenient({taskParticipants, taskParticipantsCc}) {
this.taskParticipants = taskParticipants;
this.taskParticipantsCc = taskParticipantsCc;
}
goToGabinete() {
this.router.navigate(['/home/gabinete-digital']);
}
setIntervenient(data) {
this.taskParticipants = data;
}
setIntervenientCC(data) {
this.taskParticipantsCc = data;
}
2023-01-24 15:56:47 +01:00
2023-02-06 17:54:06 +01:00
roundTimeQuarterHour(timeToReturn = new Date()) {
let date = timeToReturn || new Date();
const minutes = date.getMinutes();
date.setSeconds(0);
2023-01-24 15:56:47 +01:00
if(minutes % 15 != 0) {
2023-09-22 18:12:48 +01:00
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-01-24 15:56:47 +01:00
}
2023-09-22 18:12:48 +01:00
}
2023-01-24 15:56:47 +01:00
return date
2023-01-24 15:56:47 +01:00
}
2023-02-13 18:50:31 +01:00
roundTimeQuarterHourPlus15(date:Date) {
const _date = new Date(date);
const minutes = _date .getMinutes();
_date .setMinutes(minutes + 15)
2023-09-22 18:12:48 +01:00
return _date
2023-02-13 18:50:31 +01:00
}
checkRoleInArray(str) {
return this._eventService.calendarRole.includes(str);
}
2023-01-24 15:56:47 +01:00
2023-09-22 18:12:48 +01:00
}