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

322 lines
8.4 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
2021-06-08 15:59:06 +01:00
import { AnimationController, ModalController, NavParams } from '@ionic/angular';
2021-04-23 10:35:53 +01:00
import { EventAttachment } from 'src/app/models/attachment.model';
2021-01-29 14:13:31 +01:00
import { EventBody } from 'src/app/models/eventbody.model';
import { EventPerson } from 'src/app/models/eventperson.model';
2021-04-23 10:35:53 +01:00
import { SearchDocument } from 'src/app/models/search-document';
2021-06-16 13:29:57 +01:00
import { User } from 'src/app/models/user.model';
2021-04-23 10:35:53 +01:00
import { AttachmentsService } from 'src/app/services/attachments.service';
2021-06-16 13:29:57 +01:00
import { AuthService } from 'src/app/services/auth.service';
2021-01-29 14:13:31 +01:00
import { EventsService } from 'src/app/services/events.service';
2021-06-15 15:09:20 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-01-29 14:13:31 +01:00
import { Event } from '../../../models/event.model';
2021-06-15 15:28:03 +01:00
import { AttendeesPageModal } from '../../events/attendees/attendees.page';
import { SearchPage } from '../../search/search.page';
2021-07-02 10:45:27 +01:00
import { ThemePalette } from '@angular/material/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-new-event',
templateUrl: './new-event.page.html',
styleUrls: ['./new-event.page.scss'],
})
2021-04-07 11:52:28 +01:00
export class NewEventPage implements OnInit {
2021-07-02 10:45:27 +01:00
// date picker
public date: any;
public disabled = false;
public showSpinners = true;
public showSeconds = false;
public touchUi = false;
public enableMeridian = false;
2021-07-05 15:28:54 +01:00
public minDate = new Date().toISOString().slice(0,10)
2021-07-02 10:45:27 +01:00
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
public stepHour = 1;
public stepMinute = 5;
public stepSecond = 5;
public color: ThemePalette = 'primary';
Form: FormGroup;
validateFrom = false
2021-01-29 14:13:31 +01:00
postEvent: Event;
eventBody: EventBody;
segment:string = "true";
profile:string;
eventAttendees: EventPerson[];
selectedSegment: string;
selectedDate: Date;
2021-04-07 11:52:28 +01:00
adding: "intervenient" | "CC";
taskParticipants: any = [];
taskParticipantsCc: any = [];
2021-04-23 10:35:53 +01:00
documents:SearchDocument[] = [];
2021-06-16 13:29:57 +01:00
loggeduser: User;
constructor(
private modalController: ModalController,
2021-01-29 14:13:31 +01:00
private navParams: NavParams,
private eventService: EventsService,
2021-06-08 15:59:06 +01:00
private attachmentsService: AttachmentsService,
private animationController: AnimationController,
2021-06-15 15:09:20 +01:00
private toastService: ToastService,
2021-06-16 13:29:57 +01:00
userService: AuthService,
2021-01-29 14:13:31 +01:00
) {
2021-06-16 13:29:57 +01:00
this.loggeduser = userService.ValidatedUser;
2021-01-29 14:13:31 +01:00
this.postEvent = new Event();
this.eventBody = { BodyType : "1", Text : ""};
2021-04-07 11:52:28 +01:00
this.postEvent.Body = this.eventBody;
2021-06-16 13:29:57 +01:00
/* this.profile = this.navParams.get('profile'); */
2021-01-29 14:13:31 +01:00
this.selectedSegment = this.navParams.get('segment');
this.selectedDate = this.navParams.get('eventSelectedDate');
}
ngOnInit() {
2021-01-29 14:13:31 +01:00
2021-05-24 16:49:25 +01:00
/* console.log(this.profile); */
2021-01-29 14:13:31 +01:00
let selectedStartdDate = this.selectedDate;
let selectedEndDate = new Date(this.selectedDate);
/* Set + 30minutes to seleted datetime */
selectedEndDate.setMinutes(this.selectedDate.getMinutes() + 30) ;
2021-01-29 14:13:31 +01:00
if(this.selectedSegment != "Combinada"){
this.postEvent ={
EventId: '',
Subject: '',
Body: this.eventBody,
Location: '',
CalendarId: '',
2021-06-21 12:54:54 +01:00
CalendarName: '',
2021-01-29 14:13:31 +01:00
StartDate: selectedStartdDate,
EndDate: new Date(selectedEndDate),
EventType: 'Reunião',
Attendees: null,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
2021-02-02 09:02:13 +01:00
Categories: ['Reunião'],
2021-01-29 14:13:31 +01:00
HasAttachments: false,
2021-07-08 13:20:54 +01:00
EventRecurrence: null,
2021-01-29 14:13:31 +01:00
};
}
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: '',
2021-02-02 09:02:13 +01:00
Categories: ['Reunião'],
2021-01-29 14:13:31 +01:00
HasAttachments: false,
2021-07-08 13:20:54 +01:00
EventRecurrence: null,
2021-01-29 14:13:31 +01:00
};
}
2021-02-24 20:23:15 +01:00
window.onresize = (event) => {
// if not mobile remove all component
if( window.innerWidth >= 1024){
this.modalController.dismiss();
}
};
2021-05-06 13:32:54 +01:00
}
2021-07-06 16:18:06 +01:00
close(){
this.modalController.dismiss();
}
2021-05-24 16:49:25 +01:00
2021-07-02 10:45:27 +01:00
runValidation() {
this.validateFrom = true
}
2021-07-05 15:28:54 +01:00
get dateValid() {
if (window.innerWidth <= 800) {
return this.postEvent.StartDate < this.postEvent.EndDate? ['ok']: []
} else {
return ['ok']
}
}
2021-07-02 10:45:27 +01:00
injectValidation() {
this.Form = new FormGroup({
Subject: new FormControl(this.postEvent.Subject, [
Validators.required,
// Validators.minLength(4)
]),
Location: new FormControl(this.postEvent.Location, [
Validators.required,
]),
2021-07-02 11:07:08 +01:00
CalendarName: new FormControl(this.postEvent.CalendarName, [
Validators.required
]),
2021-07-05 15:28:54 +01:00
Date: new FormControl(this.dateValid, [
Validators.required
]),
2021-07-02 10:45:27 +01:00
Categories: new FormControl(this.postEvent.Categories[0], [
Validators.required
]),
IsRecurring: new FormControl(this.postEvent.IsRecurring, [
Validators.required
]),
// participantes: new FormControl(this.taskParticipantsCc.concat(this.taskParticipants), [
// Validators.required
// ]),
})
}
async save() {
2021-07-02 10:45:27 +01:00
this.injectValidation()
this.runValidation()
if(this.Form.invalid) return false
2021-04-23 10:35:53 +01:00
if(this.documents.length >= 0) {
this.postEvent.HasAttachments = true;
}
2021-06-16 13:29:57 +01:00
let eventId: any;
2021-05-24 16:49:25 +01:00
try {
2021-06-16 13:29:57 +01:00
if(this.loggeduser.Profile == 'MDGPR') {
console.log(this.loggeduser.Profile);
2021-05-24 16:49:25 +01:00
eventId = await this.eventService.postEventMd(this.postEvent, this.postEvent.CalendarName).toPromise();
2021-06-16 13:29:57 +01:00
console.log(eventId);
2021-05-24 16:49:25 +01:00
}
2021-06-16 13:29:57 +01:00
else if(this.loggeduser.Profile == 'PR'){
console.log(this.loggeduser.Profile);
2021-05-24 16:49:25 +01:00
eventId = await this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).toPromise();
}
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( async (attachments, i) => {
try {
await this.attachmentsService.setEventAttachmentById(attachments).toPromise();
} catch(error) {
alert('document error')
}
});
2021-06-15 15:09:20 +01:00
this.toastService.successMessage()
2021-05-24 16:49:25 +01:00
this.modalController.dismiss(this.postEvent);
} catch (error) {
2021-06-15 15:09:20 +01:00
this.toastService.badRequest()
2021-01-29 14:13:31 +01:00
}
2021-04-23 10:35:53 +01:00
2021-05-24 16:49:25 +01:00
}
2021-04-23 10:35:53 +01:00
2021-04-07 11:52:28 +01:00
async openAttendees() {
2021-05-04 15:44:48 +01:00
2021-01-29 14:13:31 +01:00
const modal = await this.modalController.create({
2021-06-15 15:28:03 +01:00
component: AttendeesPageModal,
2021-01-29 14:13:31 +01:00
componentProps: {
2021-04-07 11:52:28 +01:00
eventAttendees: this.postEvent.Attendees,
adding: this.adding,
taskParticipants: this.taskParticipants
2021-01-29 14:13:31 +01:00
},
cssClass: 'attendee modal modal-desktop',
2021-01-29 14:13:31 +01:00
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then((data) => {
2021-04-07 11:52:28 +01:00
if(data){
data = data['data'];
const newAttendees: EventPerson[] = data['taskParticipants'];
const newAttendeesCC: EventPerson[] = data['taskParticipantsCc'];
this.setIntervenient(newAttendees);
this.setIntervenientCC(newAttendeesCC);
2021-01-29 14:13:31 +01:00
}
});
2021-04-07 11:52:28 +01:00
}
setIntervenient(data){
this.taskParticipants = data;
this.postEvent.Attendees = data;
}
setIntervenientCC(data){
this.taskParticipantsCc = data;
}
addParticipants(){
this.adding = 'intervenient'
this.openAttendees();
}
addParticipantsCC(){
this.adding = 'CC'
this.openAttendees();
}
2021-01-29 14:13:31 +01:00
2021-04-23 10:35:53 +01:00
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
2021-04-23 10:35:53 +01:00
}
});
await modal.present();
modal.onDidDismiss().then((res)=>{
if(res){
const data = res.data;
this.documents.push(data.selected);
}
});
}
removeAttachment(index: number){
this.documents = this.documents.filter( (e, i) => index != i);
}
2021-04-07 11:52:28 +01:00
}