mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
506 lines
13 KiB
TypeScript
506 lines
13 KiB
TypeScript
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';
|
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
|
import { Event } from 'src/app/models/event.model';
|
|
import { AnimationController, ModalController } from '@ionic/angular';
|
|
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
|
|
import { SearchPage } from 'src/app/pages/search/search.page';
|
|
import { SearchDocument } from "src/app/models/search-document";
|
|
import { EventAttachment } from 'src/app/models/attachment.model';
|
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
import { User } from 'src/app/models/user.model';
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
|
|
import {DateAdapter} from '@angular/material/core';
|
|
import * as _moment from 'moment';
|
|
import * as _rollupMoment from 'moment';
|
|
import { FormControl } from '@angular/forms';
|
|
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';
|
|
import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker';
|
|
|
|
const moment = _rollupMoment || _moment;
|
|
|
|
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-new-event',
|
|
templateUrl: './new-event.page.html',
|
|
styleUrls: ['./new-event.page.scss'],
|
|
providers: [
|
|
{ provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_DATE_FORMATS },
|
|
]
|
|
})
|
|
|
|
|
|
export class NewEventPage implements OnInit {
|
|
|
|
eventBody: EventBody;
|
|
segment:string = "true";
|
|
|
|
public date: any;
|
|
public disabled = false;
|
|
public showSpinners = true;
|
|
public showSeconds = false;
|
|
public touchUi = false;
|
|
public enableMeridian = false;
|
|
public minDate = new Date();
|
|
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
|
|
public stepHour = 1;
|
|
public stepMinute = 5;
|
|
public stepSecond = 5;
|
|
public color: ThemePalette = 'primary';
|
|
|
|
@Input() profile:string;
|
|
@Input() selectedSegment: string;
|
|
@Input() selectedDate: Date;
|
|
@Input() taskParticipants: EventPerson[] = [];
|
|
@Input() taskParticipantsCc: any = [];
|
|
|
|
@Output() setIntervenient = new EventEmitter<any>();
|
|
@Output() setIntervenientCC = new EventEmitter<any>();
|
|
|
|
postEvent: Event;
|
|
@Output() onAddEvent = new EventEmitter<any>();
|
|
@Output() openAttendeesComponent = new EventEmitter<any>();
|
|
@Output() clearContact = new EventEmitter<any>();
|
|
@Output() GoBackEditOrAdd = new EventEmitter<any>();
|
|
@Output() cloneAllmobileComponent = new EventEmitter<any>();
|
|
|
|
documents:SearchDocument[] = [];
|
|
|
|
// minDate: string;
|
|
|
|
loggeduser: User;
|
|
@ViewChild('picker') picker: any;
|
|
@ViewChild('fim') fim: any;
|
|
@ViewChild('inicio') inicio: any;
|
|
@ViewChild('picker1') picker1: any;
|
|
|
|
Form: FormGroup;
|
|
validateFrom = false
|
|
|
|
|
|
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];
|
|
|
|
public dateControlStart = new FormControl(moment("DD MM YYYY hh"));
|
|
public dateControlEnd = new FormControl(moment("DD MM YYYY hh"));
|
|
|
|
showLoader = false
|
|
|
|
get dateStart () {
|
|
return this.dateControlStart.value
|
|
}
|
|
|
|
get dateEnd () {
|
|
return this.dateControlEnd.value
|
|
}
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private eventService: EventsService,
|
|
private attachmentsService: AttachmentsService,
|
|
private toastService: ToastService,
|
|
private userService: AuthService,
|
|
private dateAdapter: DateAdapter<any>,
|
|
// private translate: TranslateService
|
|
) {
|
|
this.dateAdapter.setLocale('pt');
|
|
this.loggeduser = userService.ValidatedUser;
|
|
|
|
this.dateControlStart = new FormControl(moment(new Date()));
|
|
this.dateControlEnd = new FormControl(moment(new Date(new Date().getTime() + 15 * 60000)));
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
if(!this.restoreTemporaryData()){
|
|
// clear
|
|
|
|
this.postEvent = new Event();
|
|
this.eventBody = { BodyType : "1", Text : ""};
|
|
this.postEvent.Body = this.eventBody;
|
|
|
|
/* console.log(this.profile); */
|
|
|
|
let selectedStartdDate = this.selectedDate;
|
|
let selectedEndDate = new Date(this.selectedDate);
|
|
/* Set + 30minutes to seleted datetime */
|
|
selectedEndDate.setMinutes(this.selectedDate.getMinutes() + 30) ;
|
|
|
|
|
|
if(this.selectedSegment != "Combinada"){
|
|
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: '',
|
|
Categories: ['Reunião'],
|
|
HasAttachments: false,
|
|
};
|
|
}
|
|
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: '',
|
|
Categories: ['Reunião'],
|
|
HasAttachments: false,
|
|
};
|
|
}
|
|
|
|
if(this.postEvent.Attendees != null) {
|
|
this.postEvent.Attendees.forEach(e =>{
|
|
if(e.IsRequired) {
|
|
this.taskParticipants.push(e);
|
|
} else {
|
|
this.taskParticipantsCc.push(e);
|
|
}
|
|
})
|
|
}
|
|
|
|
this.taskParticipants = removeDuplicate(this.taskParticipants);
|
|
this.taskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
|
|
|
|
this.setIntervenient.emit(this.taskParticipants);
|
|
this.setIntervenientCC.emit(this.taskParticipantsCc);
|
|
|
|
}
|
|
|
|
|
|
this.date = new Date(2021,9,4,5,6,7);
|
|
this.getDatepickerData()
|
|
|
|
this.injectValidation()
|
|
}
|
|
|
|
runValidation() {
|
|
this.validateFrom = true
|
|
}
|
|
|
|
injectValidation() {
|
|
|
|
this.Form = new FormGroup({
|
|
Subject: new FormControl(this.postEvent.Subject, [
|
|
Validators.required,
|
|
// Validators.minLength(4)
|
|
]),
|
|
Location: new FormControl(this.postEvent.Location, [
|
|
Validators.required,
|
|
]),
|
|
CalendarName: new FormControl(this.postEvent.CalendarName),
|
|
Categories: new FormControl(this.postEvent.Categories[0], [
|
|
Validators.required
|
|
]),
|
|
dateStart: new FormControl(this.dateStart, [
|
|
Validators.required
|
|
]),
|
|
dateEnd: new FormControl(this.dateEnd, [
|
|
Validators.required
|
|
]),
|
|
IsRecurring: new FormControl(this.postEvent.IsRecurring, [
|
|
Validators.required
|
|
]),
|
|
participantes: new FormControl(this.taskParticipantsCc.concat(this.taskParticipants), [
|
|
// Validators.required
|
|
]),
|
|
|
|
})
|
|
}
|
|
|
|
|
|
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()
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then((res)=>{
|
|
if(res){
|
|
const data = res.data;
|
|
this.documents.push(data.selected);
|
|
}
|
|
});
|
|
}
|
|
|
|
close(){
|
|
|
|
this.deleteTemporaryData();
|
|
|
|
this.cloneAllmobileComponent.emit();
|
|
this.clearContact.emit();
|
|
this.setIntervenient.emit([]);
|
|
this.setIntervenientCC.emit([]);
|
|
}
|
|
|
|
getDatepickerData() {
|
|
if (this.postEvent) {
|
|
this.postEvent.StartDate = this.dateStart
|
|
this.postEvent.EndDate = this.dateEnd
|
|
}
|
|
}
|
|
|
|
restoreDatepickerData() {
|
|
if (this.postEvent) {
|
|
this.dateControlStart = new FormControl(moment(this.postEvent.StartDate, "DD MM YYYY hh:mm"));
|
|
this.dateControlEnd = new FormControl(moment(this.postEvent.EndDate, "DD MM YYYY hh:mm"));
|
|
}
|
|
|
|
}
|
|
|
|
async save() {
|
|
|
|
this.injectValidation()
|
|
this.runValidation()
|
|
|
|
if(this.Form.invalid) return false
|
|
|
|
this.getDatepickerData()
|
|
|
|
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
|
|
|
|
if(this.documents.length >= 0) {
|
|
this.postEvent.HasAttachments = true;
|
|
}
|
|
|
|
if(this.loggeduser.Profile == 'MDGPR') {
|
|
// console.log('MD - Aqui');
|
|
// console.log(this.postEvent);
|
|
|
|
this.showLoader = true;
|
|
|
|
console.log(this.postEvent);
|
|
|
|
|
|
let loader = this.toastService.loading()
|
|
|
|
this.eventService.postEventMd(this.postEvent, this.postEvent.CalendarName).subscribe(
|
|
async (id) => {
|
|
|
|
loader.remove()
|
|
|
|
this.showLoader = false
|
|
|
|
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: ''
|
|
};
|
|
});
|
|
|
|
await DocumentToSave.forEach((attachments, i) => {
|
|
this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) =>{
|
|
|
|
if(DocumentToSave.length == (i+1)){
|
|
this.afterSave();
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
|
|
if(DocumentToSave.length == 0){
|
|
|
|
this.afterSave();
|
|
}
|
|
|
|
this.toastService.successMessage('Evento criado')
|
|
|
|
},
|
|
error => {
|
|
|
|
loader.remove()
|
|
this.showLoader = false
|
|
this.toastService.badRequest('Evento não criado')
|
|
});
|
|
}
|
|
else if(this.loggeduser.Profile == 'PR') {
|
|
console.log('PR - Aqui');
|
|
console.log(this.postEvent);
|
|
this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).subscribe(
|
|
(id) => {
|
|
console.log(id);
|
|
|
|
|
|
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.toastService.successMessage('Evento criado')
|
|
});
|
|
}
|
|
}
|
|
|
|
afterSave() {
|
|
this.getDatepickerData()
|
|
this.deleteTemporaryData();
|
|
|
|
this.onAddEvent.emit(this.postEvent);
|
|
this.GoBackEditOrAdd.emit();
|
|
|
|
this.setIntervenient.emit([]);
|
|
this.setIntervenientCC.emit([]);
|
|
}
|
|
|
|
removeAttachment(index: number){
|
|
this.documents = this.documents.filter( (e, i) => index != i);
|
|
|
|
}
|
|
|
|
async addParticipants() {
|
|
|
|
this.saveTemporaryData();
|
|
|
|
this.openAttendeesComponent.emit({
|
|
type: "intervenient"
|
|
});
|
|
|
|
this.clearContact.emit();
|
|
}
|
|
|
|
async addParticipantsCc() {
|
|
|
|
this.saveTemporaryData();
|
|
|
|
this.openAttendeesComponent.emit({
|
|
type: "CC"
|
|
});
|
|
|
|
this.clearContact.emit();
|
|
}
|
|
|
|
saveTemporaryData() {
|
|
this.getDatepickerData()
|
|
window['temp.path:/home/agenda/new-event.component.ts'] = {
|
|
postEvent: this.postEvent,
|
|
eventBody: this.eventBody,
|
|
segment: this.segment
|
|
}
|
|
}
|
|
|
|
restoreTemporaryData(): boolean {
|
|
|
|
|
|
const restoredData = window['temp.path:/home/agenda/new-event.component.ts']
|
|
|
|
if(JSON.stringify(restoredData) != "{}" && undefined != restoredData) {
|
|
this.postEvent = restoredData.postEvent
|
|
this.eventBody = restoredData.eventBody
|
|
this.segment = restoredData.segment
|
|
|
|
// restore dater for date and hours picker
|
|
this.restoreDatepickerData()
|
|
return true;
|
|
} else {
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
deleteTemporaryData(){
|
|
window['temp.path:/home/agenda/new-event.component.ts'] = {}
|
|
}
|
|
|
|
} |