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

380 lines
9.8 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 { ProcessesService } from 'src/app/services/processes.service';
import { EventPerson } from 'src/app/models/eventperson.model';
import { SearchPage } from 'src/app/pages/search/search.page';
import { SearchDocument } from 'src/app/models/search-document';
import { User } 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';
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';
import { MAT_DATE_LOCALE } from '@angular/material/core';
import { DiscartExpedientModalPage } from 'src/app/pages/gabinete-digital/discart-expedient-modal/discart-expedient-modal.page';
import { DocumentService } from 'src/app/Rules/document.service';
2021-07-29 15:40:24 +01:00
import { DocumentSetUpMeeting, Attachments } from 'src/app/models/CallMeeting';
2021-07-29 10:13:39 +01:00
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-document-set-up-meeting',
templateUrl: './document-set-up-meeting.page.html',
styleUrls: ['./document-set-up-meeting.page.scss'],
})
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;
public stepMinute = 5;
public stepSecond = 5;
public dateControlStart = new FormControl(moment("DD MM YYYY hh"));
public dateControlEnd = new FormControl(moment("DD MM YYYY hh"));
p: any = {}
Form: FormGroup;
validateFrom = false
showLoader = false
get dateStart () {
if( window.innerWidth < 801) {
return this.postData.StartDate;
}
else{
return this.dateControlStart.value;
}
}
get dateEnd () {
if( window.innerWidth < 801) {
return this.postData.EndDate;
}
else{
return this.dateControlEnd.value;
}
}
@ViewChild('picker') picker: any;
@ViewChild('fim') fim: any;
@ViewChild('inicio') inicio: any;
@ViewChild('picker1') picker1: any;
task: any;
taskParticipants: EventPerson[] = [];
taskParticipantsCc: EventPerson[] = [];
taskDocId:string;
loadedAttachments:any;
2021-07-29 15:40:24 +01:00
documents: SearchDocument[] = [];
attachments:SearchDocument[] = [];
2021-07-29 10:13:39 +01:00
adding: "intervenient" | "CC" = "intervenient";
postData: Event;
formLocationSatus: boolean = false;
showAttendees= false;
loggeduser: User;
emptyTextDescription = "Sem intervenientes selecionados";
2021-07-29 15:40:24 +01:00
document: any;
2021-07-29 10:13:39 +01:00
constructor(
private modalController: ModalController,
private router:Router,
private navParams: NavParams,
private processes:ProcessesService,
authService: AuthService,
private toastService: ToastService,
private documentService: DocumentService
) {
this.loggeduser = authService.ValidatedUser;
this.task = this.navParams.get('task');
2021-07-29 15:40:24 +01:00
this.document = this.navParams.get('document')
2021-07-29 10:13:39 +01:00
this.postData = new Event();
2021-07-29 15:40:24 +01:00
this.postData.Body ={ BodyType : "1", Text : ""};
2021-07-29 10:13:39 +01:00
this.postData.Subject = this.task.Folio;
this.postData.CalendarName = "Oficial";
this.postData.Category = 'Reunião'
2021-07-29 15:40:24 +01:00
}
2021-07-29 10:13:39 +01:00
ngOnInit() {
this.adding = "intervenient";
console.log(this.task);
this.setDefaultTime()
}
setDefaultTime() {
this.postData.StartDate = new Date()
this.postData.EndDate = (new Date(new Date().getTime() + 15 * 60000))
}
close() {
this.modalController.dismiss(null);
}
goBack() {
this.modalController.dismiss(null);
}
runValidation() {
this.validateFrom = true
}
get dateValid() {
if (window.innerWidth <= 800) {
return this.postData.StartDate < this.postData.EndDate? ['ok']: []
} else {
return ['ok']
}
}
injectValidation() {
this.Form = new FormGroup({
Subject: new FormControl(this.postData.Subject, [
// Validators.required,
// Validators.minLength(4)
]),
Location: new FormControl(this.postData.Location, [
// Validators.required,
]),
CalendarName: new FormControl(this.postData.CalendarName, [
// Validators.required
]),
Date: new FormControl(this.dateValid, [
Validators.required
]),
participantes: new FormControl(this.taskParticipants, [
// Validators.required
]),
Categories: new FormControl(this.postData.Category, [
// Validators.required
]),
})
}
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()
}
let Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
2021-07-29 15:40:24 +01:00
let data: DocumentSetUpMeeting = {
EventProcess: {
Body: this.postData.Body.Text,
Location: this.postData.Location,
StartDate: this.dateStart,
EndDate: this.dateEnd,
EventType: 'Reunião',
ParticipantsList: Attendees,
EventRecurrence: null,
Subject: this.postData.Subject,
IsRecurring: this.postData.IsRecurring,
Message: this.postData.Subject,
IsAllDayEvent: this.postData.IsRecurring,
},
Attachments: []
2021-07-29 10:13:39 +01:00
}
2021-07-29 15:40:24 +01:00
if(this.document.Documents) {
this.document.Documents.forEach( (ele) => {
console.log(ele)
data.Attachments.push({
ApplicationId: 361,
Source: 1,
SourceId: ele.docID || ele.docId || ele.DocId,
SourceName: ele.Assunto
})
});
} else {
data.Attachments.push({
ApplicationId: 8,
Source: 1,
SourceId: this.document.docID || this.document.docId || this.document.DocId,
SourceName: this.document.Assunto
})
}
this.attachments.forEach((e)=> {
console.log('e', e)
data.Attachments.push({
ApplicationId: e.ApplicationType,
Source: 1,
SourceId: e.Id,
SourceName: e.Assunto
})
})
const loader = this.toastService.loading()
try {
await this.documentService.setUpMeeting(data).toPromise()
this.toastService.successMessage('Processo criado')
this.close()
} catch(e) {
this.toastService.badRequest("Processo não criado")
} finally {
loader.remove()
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
});
await modal.present();
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);
}
});
} 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
});
await modal.present();
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);
}
});
} else {
this.showAttendees = true;
}
}
async getDoc() {
const modal = await this.modalController.create({
component: SearchPage,
2021-07-29 15:40:24 +01:00
cssClass: 'modal modal-desktop modal-width-100-width-background',
2021-07-29 10:13:39 +01:00
componentProps: {
type: 'AccoesPresidenciais & ArquivoDespachoElect',
showSearchInput: true,
select: true
}
});
await modal.present();
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
}
});
}
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(){
let formLocation = this.postData.Location.trim();
if(!this.postData.Location && formLocation.length <= 0){
this.formLocationSatus = true;
}
}
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;
}
}