This commit is contained in:
Peter Maquiran
2021-08-20 12:02:27 +01:00
parent edb1a5c9d9
commit 375eeda2ca
31 changed files with 258 additions and 166 deletions
@@ -2,10 +2,9 @@ import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { ModalController, NavParams } from '@ionic/angular';
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 { SearchDocumentDetails, SearchFolderDetails, SearchFolderDetailsDocuments, SearchList } 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';
@@ -15,14 +14,11 @@ 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';
import { DocumentSetUpMeeting, Attachments } from 'src/app/models/CallMeeting';
import { DocumentSetUpMeeting } from 'src/app/models/CallMeeting';
import { EventsService } from 'src/app/services/events.service';
import { SearchDocumentPipe } from 'src/app/pipes/search-document.pipe';
const moment = _rollupMoment || _moment;
import { EventService } from 'src/app/services/rules/event.service';
import { EventPipe } from 'src/app/pipes/event.pipe';
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
parse: {
@@ -58,9 +54,6 @@ export class DocumentSetUpMeetingPage implements OnInit {
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;
@@ -68,42 +61,21 @@ export class DocumentSetUpMeetingPage implements OnInit {
recurringTypes = [];
Occurrence: Date = new Date()
EventRecurrenceType = '-1'
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;
documents: SearchDocument[] = [];
attachments:SearchDocument[] = [];
attachments: SearchList[] = [];
adding: "intervenient" | "CC" = "intervenient";
@@ -114,29 +86,30 @@ export class DocumentSetUpMeetingPage implements OnInit {
loggeduser: User;
emptyTextDescription = "Sem intervenientes selecionados";
document: any;
private searchDocumentPipe = SearchDocumentPipe
document: SearchFolderDetails | SearchDocumentDetails | any;
subject: string
constructor(
private modalController: ModalController,
private router:Router,
private navParams: NavParams,
private processes:ProcessesService,
authService: AuthService,
private toastService: ToastService,
private documentService: DocumentService,
private calendarService: EventsService,
private eventService: EventService,
private eventPipe: EventPipe
) {
this.loggeduser = authService.ValidatedUser;
this.task = this.navParams.get('task');
this.document = this.navParams.get('document')
this.subject = this.navParams.get('subject')
this.postData = new Event();
this.postData.Body ={ BodyType : "1", Text : ""};
this.postData.Subject = this.task.workflowInstanceDataFields.Subject;
this.postData.Subject = this.subject
this.postData.CalendarName = "Oficial";
this.postData.Category = 'Reunião'
@@ -144,7 +117,6 @@ export class DocumentSetUpMeetingPage implements OnInit {
ngOnInit() {
this.adding = "intervenient";
console.log(this.task);
this.setDefaultTime()
this.getRecurrenceTypes();
}
@@ -164,22 +136,10 @@ export class DocumentSetUpMeetingPage implements OnInit {
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({
@@ -193,7 +153,7 @@ export class DocumentSetUpMeetingPage implements OnInit {
CalendarName: new FormControl(this.postData.CalendarName, [
// Validators.required
]),
Date: new FormControl(this.dateValid, [
Date: new FormControl( (this.postData.StartDate < this.postData.EndDate), [
Validators.required
]),
participantes: new FormControl(this.taskParticipants, [
@@ -216,68 +176,80 @@ export class DocumentSetUpMeetingPage implements OnInit {
let Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
let data: DocumentSetUpMeeting = {
EventProcess: {
Body: this.postData.Body.Text,
Location: this.postData.Location,
StartDate: this.dateStart,
EndDate: this.dateEnd,
EventType: 'Reunião',
ParticipantsList: Attendees,
Subject: this.postData.Subject,
IsRecurring: this.postData.IsRecurring,
Message: this.postData.Subject,
IsAllDayEvent: this.postData.IsRecurring,
EventRecurrence: {
Type: this.EventRecurrenceType,
LastOccurrence: this.Occurrence
},
},
Attachments: []
}
if(this.document.Documents) {
this.document.Documents.forEach( (ele) => {
console.log(ele)
data.Attachments.push({
var Attachments: addAttachment[] = []
let folder: SearchFolderDetails = this.document
let document: SearchDocumentDetails = this.document
if(folder.Documents) {
this.document.Documents.forEach( (_folder: SearchFolderDetailsDocuments) => {
Attachments.push({
ApplicationId: 361,
Source: 1,
SourceId: ele.docID || ele.docId || ele.DocId,
SourceName: ele.Assunto
SourceId: _folder['docID'] || _folder['docId'] || _folder.DocId,
SourceTitle: _folder.Assunto,
})
});
} else {
data.Attachments.push({
Attachments.push({
ApplicationId: 8,
Source: 1,
SourceId: this.document.docID || this.document.docId || this.document.DocId,
SourceName: this.document.Assunto
SourceId: document['docID'] || document['docId'] || document.DocId,
SourceTitle: document.Assunto
})
}
this.attachments.forEach((e)=> {
console.log('e', e)
data.Attachments.push({
Attachments.push({
ApplicationId: e.ApplicationType,
Source: 1,
SourceId: e.Id,
SourceName: e.Assunto
SourceTitle: 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()
let postEvent = {
EventId: '',
Subject: this.postData.Subject,
Body: this.postData.Body.Text,
Location: this.postData.Location,
CalendarId: this.postData.CalendarName,
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,
LastOccurrence: this.Occurrence
},
}
this.eventService.create({
body: postEvent,
calendar: this.postData.CalendarName
}).subscribe(async (respose) => {
const res: any = respose;
const eventId: string = res
const DocumentToSave = this.attachments.map((e) => {
return this.eventPipe.AttactSearchResult(e, eventId, {})
});
await DocumentToSave.forEach(async (attachments, i) => {
await this.eventService.addAttachment(attachments).toPromise();
});
})
}
async addParticipants() {