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

548 lines
14 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'
2021-04-19 11:35:48 +01:00
import { SearchPage } from 'src/app/pages/search/search.page';
import { SearchDocument } from "src/app/models/search-document";
2021-04-19 15:21:35 +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-06-16 13:29:57 +01:00
import { User } from 'src/app/models/user.model';
import { AuthService } from 'src/app/services/auth.service';
2021-06-03 11:44:32 +01:00
2021-06-21 14:29:49 +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';
import { NgZone, ViewChild } from '@angular/core';
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-06-17 13:58:56 +01:00
const moment = _rollupMoment || _moment;
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;
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;
2021-07-08 14:45:38 +01:00
public minDate = new Date().toISOString().slice(0,10)
2021-07-01 16:23:47 +01:00
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
2021-06-18 12:02:14 +01:00
public stepHour = 1;
2021-06-21 14:29:49 +01:00
public stepMinute = 5;
public stepSecond = 5;
2021-06-18 12:02:14 +01:00
public color: ThemePalette = 'primary';
2021-07-12 14:32:43 +01:00
recurringTypes: any;
selectedRecurringType: any;
2021-06-18 12:02:14 +01:00
2021-02-24 09:14:58 +01:00
@Input() profile:string;
@Input() selectedSegment: string;
@Input() selectedDate: 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
2021-04-21 14:27:55 +01:00
postEvent: Event;
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>();
2021-03-25 15:18:12 +01:00
@Output() GoBackEditOrAdd = new EventEmitter<any>();
2021-03-25 15:51:19 +01:00
@Output() cloneAllmobileComponent = new EventEmitter<any>();
2021-02-24 09:14:58 +01:00
2021-04-19 11:35:48 +01:00
documents:SearchDocument[] = [];
2021-06-18 12:02:14 +01:00
// minDate: string;
2021-02-24 09:14:58 +01:00
2021-06-16 13:29:57 +01:00
loggeduser: User;
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;
2021-06-28 11:16:21 +01:00
validateFrom = false
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];
2021-07-12 15:48:25 +01:00
public dateControlOccurrence = new FormControl(moment("DD MM YYYY hh"));
2021-06-23 15:39:45 +01:00
showLoader = false
2021-07-12 15:48:25 +01:00
get dateOccurrence () {
return this.dateControlOccurrence.value
}
2021-02-24 09:14:58 +01:00
constructor(
private modalController: ModalController,
2021-07-12 14:32:43 +01:00
private eventService: EventsService,
2021-06-08 15:59:06 +01:00
private attachmentsService: AttachmentsService,
2021-06-16 13:29:57 +01:00
private toastService: ToastService,
private userService: AuthService,
2021-06-21 14:29:49 +01:00
private dateAdapter: DateAdapter<any>,
// private translate: TranslateService
2021-06-16 13:29:57 +01:00
) {
2021-06-18 12:02:14 +01:00
this.dateAdapter.setLocale('pt');
2021-06-16 13:29:57 +01:00
this.loggeduser = userService.ValidatedUser;
2021-07-14 14:29:03 +01:00
this.postEvent = new Event();
2021-06-23 15:39:45 +01:00
2021-07-14 11:37:31 +01:00
this.postEvent.StartDate = new Date();
this.postEvent.EndDate = new Date(new Date().getTime() + 15 * 60000);
2021-06-16 13:29:57 +01:00
}
2021-02-24 09:14:58 +01:00
ngOnInit() {
2021-07-12 14:32:43 +01:00
this.getRecurrenceTypes();
if(!this.restoreTemporaryData()){
2021-04-21 14:27:55 +01:00
// clear
this.eventBody = { BodyType : "1", Text : ""};
2021-07-12 14:32:43 +01:00
this.postEvent.Body = this.eventBody;
2021-04-01 14:44:12 +01:00
/* console.log(this.profile); */
2021-07-12 14:32:43 +01:00
let selectedStartdDate = this.selectedDate;
let selectedEndDate = new Date(this.selectedDate);
/* Set + 30minutes to seleted datetime */
2021-07-12 14:32:43 +01:00
selectedEndDate.setMinutes(this.selectedDate.getMinutes() + 30) ;
2021-06-28 11:16:21 +01:00
if(this.selectedSegment != "Combinada"){
this.postEvent ={
EventId: '',
Subject: '',
Body: this.eventBody,
Location: '',
CalendarId: '',
2021-06-23 15:39:45 +01:00
CalendarName: 'Oficial',
StartDate: selectedStartdDate,
EndDate: new Date(selectedEndDate),
EventType: 'Reunião',
Attendees: null,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
2021-07-15 08:53:54 +01:00
Category: 'Reunião',
HasAttachments: false,
2021-07-12 14:32:43 +01:00
EventRecurrence: {Type:'-1'},
};
}
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-07-15 08:53:54 +01:00
Category: 'Reunião',
HasAttachments: false,
2021-07-12 14:32:43 +01:00
EventRecurrence: {Type:'-1'},
};
}
if(this.postEvent.Attendees != null) {
this.postEvent.Attendees.forEach(e =>{
if(e.IsRequired) {
this.taskParticipants.push(e);
} else {
this.taskParticipantsCc.push(e);
}
2021-07-12 14:32:43 +01:00
})
}
this.taskParticipants = removeDuplicate(this.taskParticipants);
this.taskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
this.setIntervenient.emit(this.taskParticipants);
this.setIntervenientCC.emit(this.taskParticipantsCc);
2021-02-24 09:14:58 +01:00
}
2021-06-18 12:02:14 +01:00
this.date = new Date(2021,9,4,5,6,7);
2021-06-23 15:39:45 +01:00
this.getDatepickerData()
2021-06-28 11:16:21 +01:00
2021-07-12 14:32:43 +01:00
this.injectValidation();
2021-06-28 11:16:21 +01:00
}
runValidation() {
this.validateFrom = true
}
injectValidation() {
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),
2021-07-15 08:53:54 +01:00
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
]),
2021-07-14 09:46:03 +01:00
dateOccurrence: new FormControl(this.postEvent.EventRecurrence.Type.toString() == '-1' ? ['ok']: this.dateOccurrence, [
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-08 13:57:08 +01:00
Validators.required
2021-06-28 11:16:21 +01:00
]),
2021-07-16 23:16:55 +01:00
Date: new FormControl(this.postEvent.StartDate.getTime() < 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-06-18 12:02:14 +01:00
2021-06-21 14:29:49 +01:00
openInicio() {
let input: any = document.querySelector('#new-inicio')
if(input) {
console.log(input)
input.click()
}
}
openFim() {
let input: any = document.querySelector('#new-fim')
if(input) {
input.click()
}
}
2021-07-12 15:48:25 +01:00
openLastOccurrence() {
let input: any = document.querySelector('#last-occurrence')
if(input) {
input.click()
}
}
2021-04-19 11:35:48 +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',
2021-04-19 11:35:48 +01:00
componentProps: {
2021-04-29 15:25:14 +01:00
type: 'AccoesPresidenciais & ArquivoDespachoElect',
2021-04-30 14:12:45 +01:00
showSearchInput: true,
select: true
2021-04-19 11:35:48 +01:00
}
});
await modal.present();
modal.onDidDismiss().then((res)=>{
if(res){
const data = res.data;
this.documents.push(data.selected);
}
});
}
2021-07-12 14:32:43 +01:00
2021-02-24 09:14:58 +01:00
close(){
this.deleteTemporaryData();
2021-03-25 15:51:19 +01:00
this.cloneAllmobileComponent.emit();
2021-03-25 10:50:58 +01:00
this.clearContact.emit();
this.setIntervenient.emit([]);
this.setIntervenientCC.emit([]);
2021-02-24 09:14:58 +01:00
}
2021-07-12 14:32:43 +01:00
getRecurrenceTypes() {
this.eventService.getRecurrenceTypes().subscribe(res=>{
console.log(res);
this.recurringTypes = res;
});
}
onSelectedRecurringChanged(ev:any){
console.log(ev);
if(ev.length > 1){
console.log(ev.filter(data => data != '-1'));
this.postEvent.EventRecurrence.Type = ev.filter(data => data != '-1');
}
if(ev.length == 0){
this.postEvent.EventRecurrence.Type = "-1";
}
}
2021-06-23 15:39:45 +01:00
getDatepickerData() {
if (this.postEvent) {
2021-07-12 15:48:25 +01:00
this.postEvent.EventRecurrence.LastOccurrence = this.dateOccurrence
2021-06-23 15:39:45 +01:00
}
}
restoreDatepickerData() {
if (this.postEvent) {
2021-07-14 16:26:51 +01:00
this.dateControlOccurrence = new FormControl(moment(this.postEvent.EventRecurrence.LastOccurrence, "DD MM YYYY HH:mm"))
2021-06-23 15:39:45 +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
2021-07-14 09:46:03 +01:00
if(this.Form.invalid) {
console.log('not passed')
return false
}
2021-06-23 15:39:45 +01:00
this.getDatepickerData()
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
2021-04-19 15:21:35 +01:00
2021-04-21 14:27:55 +01:00
if(this.documents.length >= 0) {
2021-04-19 15:21:35 +01:00
this.postEvent.HasAttachments = true;
}
2021-07-12 14:32:43 +01:00
if(this.selectedRecurringType != '-1'){
2021-07-13 12:17:19 +01:00
this.postEvent.EventRecurrence.Type = this.selectedRecurringType;
2021-07-12 14:32:43 +01:00
}
2021-04-19 15:21:35 +01:00
2021-06-16 13:29:57 +01:00
if(this.loggeduser.Profile == 'MDGPR') {
2021-06-23 15:39:45 +01:00
// console.log('MD - Aqui');
// console.log(this.postEvent);
2021-06-25 11:00:25 +01:00
this.showLoader = true;
console.log(this.postEvent);
2021-06-23 15:39:45 +01:00
2021-07-12 14:32:43 +01:00
let loader = this.toastService.loading();
console.log(this.postEvent);
2021-07-07 16:25:36 +01:00
2021-04-19 15:21:35 +01:00
this.eventService.postEventMd(this.postEvent, this.postEvent.CalendarName).subscribe(
2021-05-28 15:45:41 +01:00
async (id) => {
2021-04-19 15:21:35 +01:00
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-07-12 14:32:43 +01:00
2021-05-28 15:45:41 +01:00
await DocumentToSave.forEach((attachments, i) => {
2021-04-21 14:27:55 +01:00
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) =>{
2021-07-12 14:32:43 +01:00
2021-04-21 14:27:55 +01:00
if(DocumentToSave.length == (i+1)){
2021-04-21 19:59:49 +01:00
this.afterSave();
2021-04-21 14:27:55 +01:00
}
});
2021-04-19 15:21:35 +01:00
});
2021-07-12 14:32:43 +01:00
2021-04-21 19:59:49 +01:00
if(DocumentToSave.length == 0){
this.afterSave();
}
2021-06-15 15:09:20 +01:00
this.toastService.successMessage('Evento criado')
2021-05-24 16:49:25 +01:00
},
error => {
2021-07-12 14:32:43 +01:00
2021-07-07 16:25:36 +01:00
loader.remove()
2021-06-23 15:39:45 +01:00
this.showLoader = false
2021-06-15 15:09:20 +01:00
this.toastService.badRequest('Evento não criado')
2021-07-14 16:49:56 +01:00
2021-07-14 09:46:03 +01:00
});
2021-02-24 09:14:58 +01:00
}
2021-06-16 13:29:57 +01:00
else if(this.loggeduser.Profile == 'PR') {
2021-06-16 16:55:47 +01:00
console.log('PR - Aqui');
console.log(this.postEvent);
2021-04-19 15:21:35 +01:00
this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).subscribe(
(id) => {
2021-06-16 13:29:57 +01:00
console.log(id);
2021-07-12 14:32:43 +01:00
2021-04-19 15:21:35 +01:00
2021-06-16 13:29:57 +01:00
const eventId: any = id;
2021-04-19 15:21:35 +01:00
2021-04-21 14:27:55 +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
};
});
2021-04-21 14:27:55 +01:00
DocumentToSave.forEach((attachments, i) => {
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) =>{
2021-07-12 14:32:43 +01:00
2021-04-21 14:27:55 +01:00
if(DocumentToSave.length == (i+1)){
2021-04-21 19:59:49 +01:00
this.afterSave();
2021-04-21 14:27:55 +01:00
}
});
2021-04-19 15:21:35 +01:00
});
2021-04-21 19:59:49 +01:00
if(DocumentToSave.length == 0){
this.afterSave();
}
2021-06-15 15:09:20 +01:00
this.toastService.successMessage('Evento criado')
2021-04-19 15:21:35 +01:00
});
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-06-23 15:39:45 +01:00
this.getDatepickerData()
2021-04-21 19:59:49 +01:00
this.deleteTemporaryData();
this.onAddEvent.emit(this.postEvent);
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
2021-04-20 15:05:40 +01:00
removeAttachment(index: number){
this.documents = this.documents.filter( (e, i) => index != i);
2021-02-24 09:14:58 +01:00
}
2021-04-08 15:45:45 +01:00
async addParticipants() {
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();
}
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() {
2021-06-23 15:39:45 +01:00
this.getDatepickerData()
window['temp.path:/home/agenda/new-event.component.ts'] = {
postEvent: this.postEvent,
eventBody: this.eventBody,
segment: this.segment
}
}
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
const restoredData = window['temp.path:/home/agenda/new-event.component.ts']
2021-04-19 15:21:35 +01:00
if(JSON.stringify(restoredData) != "{}" && undefined != restoredData) {
this.postEvent = restoredData.postEvent
this.eventBody = restoredData.eventBody
this.segment = restoredData.segment
2021-06-23 15:39:45 +01:00
// restore dater for date and hours picker
this.restoreDatepickerData()
return true;
} else {
2021-06-23 15:39:45 +01:00
return false;
}
}
deleteTemporaryData(){
window['temp.path:/home/agenda/new-event.component.ts'] = {}
}
2021-07-08 13:41:27 +01:00
}