This commit is contained in:
Peter Maquiran
2023-07-25 15:56:42 +01:00
parent a26f7c4f75
commit 2628bc91e8
6 changed files with 111 additions and 66 deletions
@@ -14,6 +14,7 @@ import { ParticipantsPipe } from 'src/app/pipes/participants.pipe';
import { ThemeService } from 'src/app/services/theme.service'
import { SessionStore } from 'src/app/store/session.service';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { ContactsService } from 'src/app/services/contacts.service'
@Component({
selector: 'app-edit-event',
@@ -73,6 +74,9 @@ export class EditEventPage implements OnInit {
@ViewChild('inicio') inicio: any;
@ViewChild('picker1') picker1: any;
@Input() _postEvent: Event;
public options = [
{ value: true, label: 'True' },
{ value: false, label: 'False' }
@@ -95,24 +99,39 @@ export class EditEventPage implements OnInit {
public alertController: AlertController,
private attachmentsService: AttachmentsService,
public ThemeService: ThemeService,
private httpErrorHandle: HttpErrorHandle
private httpErrorHandle: HttpErrorHandle,
private contactsService: ContactsService
) {}
ngOnInit() {
this._postEvent = this.postEvent
if(!this.restoreTemporaryData()) {
// clear
if(this.postEvent) {
if( this.postEvent.Body){
if(typeof(this.postEvent.Body.Text) == 'string'){
this.postEvent.Body.Text = this.postEvent.Body.Text.replace(/<[^>]+>/g, '');
if(this._postEvent) {
if( this._postEvent.Body){
if(typeof(this._postEvent.Body.Text) == 'string'){
this._postEvent.Body.Text = this._postEvent.Body.Text.replace(/<[^>]+>/g, '');
}
}
}
if (this.postEvent.Attendees != null) {
const result = this.participantsPipe.transform(this.postEvent.Attendees)
for(const index in this._postEvent.Attendees) {
const user = this._postEvent.Attendees[index]
const userData = this.contactsService.constacts.find(e => user.EmailAddress == e.EmailAddress)
if(userData) {
this._postEvent.Attendees[index].UserType = userData.UserType
} else {
console.log('user not set')
}
}
if (this._postEvent.Attendees != null) {
const result = this.participantsPipe.transform(this._postEvent.Attendees)
this.taskParticipants = result.taskParticipants
this.taskParticipantsCc = result.taskParticipantsCc
@@ -124,23 +143,25 @@ export class EditEventPage implements OnInit {
}
}
this.initCalendarName = this.postEvent.CalendarName;
this.initCalendarName = this._postEvent.CalendarName;
this.getRecurrenceTypes();
setTimeout(() => {
this.postEvent.EventRecurrence.Type = this.postEvent.EventRecurrence.Type.toString();
this._postEvent.EventRecurrence.Type = this._postEvent.EventRecurrence.Type.toString();
}, 500);
this.CalendarNameOwnerName = this.eventsService.detectCalendarNameByCalendarId(this.postEvent.CalendarId)
this.CalendarNameOwnerName = this.eventsService.detectCalendarNameByCalendarId(this._postEvent.CalendarId)
this.changeAgenda()
}
ngOnChanges(changes: any): void {
this.loadedEventAttachments = this.postEvent.Attachments
this.loadedEventAttachments = this._postEvent.Attachments
}
close() {
@@ -166,30 +187,30 @@ export class EditEventPage implements OnInit {
injectValidation() {
if (typeof(this.postEvent.EventRecurrence.Type) == 'number') {
const str: any = this.postEvent.EventRecurrence.Type.toString()
this.postEvent.EventRecurrence.Type = str
if (typeof(this._postEvent.EventRecurrence.Type) == 'number') {
const str: any = this._postEvent.EventRecurrence.Type.toString()
this._postEvent.EventRecurrence.Type = str
}
this.Form = new FormGroup({
Subject: new FormControl(this.postEvent.Subject, [
Subject: new FormControl(this._postEvent.Subject, [
Validators.required,
// Validators.minLength(4)
]),
Location: new FormControl(this.postEvent.Location, [
Location: new FormControl(this._postEvent.Location, [
Validators.required,
]),
CalendarName: new FormControl(this.postEvent.CalendarName),
Categories: new FormControl(this.postEvent.Category, [
CalendarName: new FormControl(this._postEvent.CalendarName),
Categories: new FormControl(this._postEvent.Category, [
Validators.required
]),
dateOccurrence: new FormControl(this.postEvent.EventRecurrence.Type.toString() == '-1' ? ['ok']: this.postEvent.EventRecurrence.LastOccurrence && new Date(this.postEvent.EventRecurrence.LastOccurrence).getTime() > new Date(this.postEvent.EndDate).getTime() ? 'ok': null, [
dateOccurrence: new FormControl(this._postEvent.EventRecurrence.Type.toString() == '-1' ? ['ok']: this._postEvent.EventRecurrence.LastOccurrence && new Date(this._postEvent.EventRecurrence.LastOccurrence).getTime() > new Date(this._postEvent.EndDate).getTime() ? 'ok': null, [
Validators.required
]),
participantes: new FormControl(this.taskParticipants, [
// Validators.required
]),
Date: new FormControl( new Date(this.postEvent.StartDate).toLocaleString('pt') <= new Date(this.postEvent.EndDate).toLocaleString('pt')? 'ok': null,[
Date: new FormControl( new Date(this._postEvent.StartDate).toLocaleString('pt') <= new Date(this._postEvent.EndDate).toLocaleString('pt')? 'ok': null,[
Validators.required
]),
@@ -254,10 +275,10 @@ export class EditEventPage implements OnInit {
if(ev.length > 1){
this.postEvent.EventRecurrence.Type = ev.filter(data => data != '-1');
this._postEvent.EventRecurrence.Type = ev.filter(data => data != '-1');
}
if(ev.length == 0){
this.postEvent.EventRecurrence.Type = "-1";
this._postEvent.EventRecurrence.Type = "-1";
}
}
@@ -282,10 +303,10 @@ export class EditEventPage implements OnInit {
defineLastOccurrence(valor:number, opcao:boolean){
var time = new Date(this.postEvent.EndDate);
var time = new Date(this._postEvent.EndDate);
if (opcao == true) {
time.setDate(time.getDate() + valor);
this.postEvent.EventRecurrence.LastOccurrence = time;
this._postEvent.EventRecurrence.LastOccurrence = time;
} else {
time = new Date(
time.getFullYear() + valor,
@@ -294,7 +315,7 @@ export class EditEventPage implements OnInit {
time.getHours(),
time.getMinutes()
);
this.postEvent.EventRecurrence.LastOccurrence = time;
this._postEvent.EventRecurrence.LastOccurrence = time;
}
}
@@ -309,27 +330,27 @@ export class EditEventPage implements OnInit {
return false
}
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
this._postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
if(!this.postEvent.EventRecurrence.hasOwnProperty('Type')) {
this.postEvent.EventRecurrence.Type = '-1'
if(!this._postEvent.EventRecurrence.hasOwnProperty('Type')) {
this._postEvent.EventRecurrence.Type = '-1'
} else {
}
if(this.postEvent.EventRecurrence.Type == undefined) {
this.postEvent.EventRecurrence.Type = '-1'
if(this._postEvent.EventRecurrence.Type == undefined) {
this._postEvent.EventRecurrence.Type = '-1'
}
this.showLoader = true;
try {
if(this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') {
await this.eventsService.editEvent(this.postEvent, 2, 3).toPromise()
if(this.initCalendarName != this.postEvent.CalendarName) {
await this.eventsService.editEvent(this._postEvent, 2, 3).toPromise()
if(this.initCalendarName != this._postEvent.CalendarName) {
let body = {
"EventId": this.postEvent.EventId,
"CalendarDestinationName": this.postEvent.CalendarName,
"EventId": this._postEvent.EventId,
"CalendarDestinationName": this._postEvent.CalendarName,
}
try {
@@ -339,11 +360,11 @@ export class EditEventPage implements OnInit {
this.showLoader = false;
this.httpErrorHandle.httpsSucessMessagge('Editar evento')
} else {
await this.eventsService.editEvent(this.postEvent, 2, 3, this.postEvent.CalendarId).toPromise()
if(this.initCalendarName != this.postEvent.CalendarName) {
await this.eventsService.editEvent(this._postEvent, 2, 3, this._postEvent.CalendarId).toPromise()
if(this.initCalendarName != this._postEvent.CalendarName) {
let body = {
"EventId": this.postEvent.EventId,
"CalendarDestinationName": this.postEvent.CalendarName,
"EventId": this._postEvent.EventId,
"CalendarDestinationName": this._postEvent.CalendarName,
}
try {
@@ -382,7 +403,7 @@ export class EditEventPage implements OnInit {
//data.selected
const DocumentToSave = {
SourceTitle: e.SourceName,
ParentId: this.postEvent.EventId,
ParentId: this._postEvent.EventId,
Source: '1',
SourceId: e.SourceId,
ApplicationId: e.ApplicationId.toString(),
@@ -429,7 +450,7 @@ export class EditEventPage implements OnInit {
saveTemporaryData() {
window['temp.path:/home/agenda/edit-event.component.ts'] = {
postEvent: this.postEvent,
postEvent: this._postEvent,
eventBody: this.eventBody,
segment: this.segment
}
@@ -440,7 +461,7 @@ export class EditEventPage implements OnInit {
const restoredData = window['temp.path:/home/agenda/edit-event.component.ts']
if(JSON.stringify(restoredData) != "{}" && undefined != restoredData){
this.postEvent = restoredData.postEvent
this._postEvent = restoredData.postEvent
this.eventBody = restoredData.eventBody
this.segment = restoredData.segment
@@ -456,7 +477,7 @@ export class EditEventPage implements OnInit {
}
async getAttachments(eventId: string){
if(this.postEvent.HasAttachments) {
if(this._postEvent.HasAttachments) {
let rest: any;
try {
rest = this.attachmentsService.getAttachmentsById(eventId).toPromise()
@@ -497,7 +518,7 @@ export class EditEventPage implements OnInit {
const ApplicationIdDocumentToSave: any = {
SourceName: data.selected.Assunto,
ParentId: this.postEvent.EventId,
ParentId: this._postEvent.EventId,
SourceId: data.selected.Id,
Stakeholders: data.selected.Stakeholders | data.selected.EntidadeOrganicaNome,
ApplicationId: data.selected.ApplicationType.toString(),
@@ -528,11 +549,11 @@ export class EditEventPage implements OnInit {
} else if (this.eventsService.calendarNamesType[this.CalendarNameOwnerName]?.['Oficial']) {
this.CalendarNamesOptions = ['Oficial']
this.postEvent.CalendarName = 'Oficial'
this._postEvent.CalendarName = 'Oficial'
} else if (this.eventsService.calendarNamesType[this.CalendarNameOwnerName]?.['Pessoal']) {
this.CalendarNamesOptions = ['Pessoal']
this.postEvent.CalendarName = 'Pessoal'
this._postEvent.CalendarName = 'Pessoal'
} else {
this.CalendarNamesOptions = ['Oficial', 'Pessoal']