edit and delete

This commit is contained in:
Eudes Inácio
2024-05-31 11:21:32 +01:00
parent 44b2fa7307
commit 2e6f4fd642
8 changed files with 233 additions and 144 deletions
@@ -27,17 +27,18 @@ import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda
export class EditEventPage implements OnInit {
stEvent: Event;
isRecurring:string;
isRecurring: string;
isEventEdited: boolean;
loadedEvent: Event;
initCalendarName: string;
eventBody: EventBody;
segment:string = "true";
segment: string = "true";
eventAttendees: EventPerson[];
// minDate: string;
loadedEventAttachments: Attachment[]=[];
loadedEventAttachments: Attachment[] = [];
recurringTypes = [];
selectedRecurringType: any;
deletedAttachmentsList = [];
public date: any;
public disabled = false;
@@ -45,8 +46,8 @@ export class EditEventPage implements OnInit {
public showSeconds = false;
public touchUi = false;
public enableMeridian = false;
public minDate = new Date().toISOString().slice(0,10)
public endMinDate = new Date(new Date().getTime() + 15 * 60000).toISOString().slice(0,10)
public minDate = new Date().toISOString().slice(0, 10)
public endMinDate = new Date(new Date().getTime() + 15 * 60000).toISOString().slice(0, 10)
public maxDate: any;
public stepHour = 1;
public stepMinute = 15;
@@ -57,7 +58,7 @@ export class EditEventPage implements OnInit {
@Input() taskParticipants: EventPerson[];
@Input() taskParticipantsCc: EventPerson[];
@Input() profile:string;
@Input() profile: string;
@Input() selectedSegment: string;
@Input() postEvent: Event;
@Output() clearContact = new EventEmitter<any>();
@@ -89,12 +90,13 @@ export class EditEventPage implements OnInit {
public stepMinutes = [1, 5, 10, 15, 20, 25];
public stepSeconds = [1, 5, 10, 15, 20, 25];
private participantsPipe = new ParticipantsPipe()
private participantsPipe = new ParticipantsPipe()
sesseionStora = SessionStore
CalendarNameOwnerName = ''
CalendarNamesOptions = []
allDayCheck: boolean = false;
addedAttachmentsList = [];
constructor(
private modalController: ModalController,
@@ -107,19 +109,19 @@ export class EditEventPage implements OnInit {
private domSanitizeService: DomSanitizerService,
private agendaDataRepository: AgendaDataRepositoryService
) {
}
ngOnInit() {
console.log(this.postEvent)
this._postEvent = this.postEvent
this.allDayCheck = this.postEvent.IsAllDayEvent;
if(!this.restoreTemporaryData()) {
if (!this.restoreTemporaryData()) {
// clear
if(this._postEvent) {
if( this._postEvent.Body){
if(typeof(this._postEvent.Body.Text) == 'string'){
if (this._postEvent) {
if (this._postEvent.Body) {
if (typeof (this._postEvent.Body.Text) == 'string') {
this._postEvent.Body.Text = this._postEvent.Body.Text.replace(/<[^>]+>/g, '');
}
}
@@ -127,18 +129,18 @@ export class EditEventPage implements OnInit {
for(const index in this._postEvent.Attendees) {
const user = this._postEvent.Attendees[index]
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')
}
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
@@ -175,8 +177,8 @@ export class EditEventPage implements OnInit {
}
myInterval = setInterval(() => {
document.querySelectorAll('.ngx-mat-timepicker input').forEach((e :any) => {
if(e) {
document.querySelectorAll('.ngx-mat-timepicker input').forEach((e: any) => {
if (e) {
e.disabled = true;
}
})
@@ -196,7 +198,7 @@ export class EditEventPage implements OnInit {
}
getRecurrenceTypes() {
this.eventsService.getRecurrenceTypes().subscribe(res=>{
this.eventsService.getRecurrenceTypes().subscribe(res => {
this.recurringTypes = res;
});
@@ -204,12 +206,12 @@ export class EditEventPage implements OnInit {
runValidation() {
this.validateFrom = true
this.validateFrom = true
}
injectValidation() {
if (typeof(this._postEvent.EventRecurrence.Type) == 'number') {
if (typeof (this._postEvent.EventRecurrence.Type) == 'number') {
const str: any = this._postEvent.EventRecurrence.Type.toString()
this._postEvent.EventRecurrence.Type = str
}
@@ -226,13 +228,13 @@ export class EditEventPage implements OnInit {
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( true,[
Date: new FormControl(true, [
Validators.required
]),
@@ -242,7 +244,7 @@ export class EditEventPage implements OnInit {
openInicio() {
let input: any = document.querySelector('#new-inicio')
if(input) {
if (input) {
input.click()
}
@@ -250,14 +252,14 @@ export class EditEventPage implements OnInit {
openFim() {
let input: any = document.querySelector('#new-fim')
if(input) {
if (input) {
input.click()
}
}
openLastOccurrence() {
let input: any = document.querySelector('#last-occurrence')
if(input) {
if (input) {
input.click()
}
}
@@ -267,7 +269,7 @@ export class EditEventPage implements OnInit {
const minutes = date.getMinutes();
date.setSeconds(0);
if(minutes % 15 != 0) {
if (minutes % 15 != 0) {
if (minutes > 45) {
date.setMinutes(60)
@@ -284,39 +286,39 @@ export class EditEventPage implements OnInit {
return date
}
roundTimeQuarterHourPlus15(date:Date) {
roundTimeQuarterHourPlus15(date: Date) {
const _date = new Date(date);
const minutes = _date .getMinutes();
_date .setMinutes(minutes + 15)
const minutes = _date.getMinutes();
_date.setMinutes(minutes + 15)
return _date
}
onSelectedRecurringChanged(ev:any){
onSelectedRecurringChanged(ev: any) {
this.calculetedLastOccurrence(ev);
if(ev.length > 1){
if (ev.length > 1) {
this._postEvent.EventRecurrence.Type = ev.filter(data => data != '-1');
}
if(ev.length == 0){
if (ev.length == 0) {
this._postEvent.EventRecurrence.Type = "-1";
}
}
calculetedLastOccurrence(type:number){
calculetedLastOccurrence(type: number) {
var valor;
var opcao: boolean;
if (type == 0) {
valor = 7;
opcao = true;
} else if(type == 1){
} else if (type == 1) {
valor = 30;
opcao = true;
} else if(type == 2){
} else if (type == 2) {
valor = 1;
opcao = false;
}else if(type == 3){
} else if (type == 3) {
valor = 5;
opcao = false;
}
@@ -324,7 +326,7 @@ export class EditEventPage implements OnInit {
}
defineLastOccurrence(valor:number, opcao:boolean){
defineLastOccurrence(valor: number, opcao: boolean) {
var time = new Date(this._postEvent.EndDate);
if (opcao == true) {
time.setDate(time.getDate() + valor);
@@ -342,17 +344,108 @@ export class EditEventPage implements OnInit {
}
save_v2() {
atendeesSeletedType(type) {
var selectedType = {
'true': 1,
'false': 2,
'other': 3,
}
return selectedType[type];
}
documentAdded(documents: any[]) {
console.log('document added', documents)
return documents.map((element) => {
return {
docId: parseInt(element.SourceId),
sourceName: element.SourceName,
description: "",
applicationId: parseInt(element.ApplicationId)
};
});
}
attendeesAdded(taskParticipants: any[]) {
return taskParticipants.map((e) => {
return {
name: e.Name,
emailAddress: e.EmailAddress,
attendeeType: this.atendeesSeletedType(JSON.stringify(e.IsRequired)),
wxUserId: e.wxUserId,
}
});
}
async save_v2() {
this.injectValidation()
this.runValidation()
if (this.Form.invalid) {
return false
}
/* this._postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
console.log('1',this._postEvent.Attendees)
console.log('2',this.postEvent.Attendees)
if (JSON.stringify(this._postEvent.Attendees) === JSON.stringify(this.postEvent.Attendees)) {
console.log(true)
} else {
console.log(false)
}
return */
this._postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
this.showLoader = true;
this.agendaDataRepository.updateEvent(this._postEvent.EventId, this._postEvent,this._postEvent.CalendarName,this.loadedEventAttachments);
this.showLoader = false;
this.httpErrorHandle.httpsSucessMessagge('Editar evento')
try {
this.agendaDataRepository.updateEvent(this._postEvent.EventId, this._postEvent, this._postEvent.CalendarName, this.loadedEventAttachments).subscribe((value) => {
console.log(value)
}, ((error) => {
console.log('edit event error: ', error)
}));
this.agendaDataRepository.addEventAttendee(this._postEvent.EventId, { attendees: this.attendeesAdded(this._postEvent.Attendees) }).subscribe((value) => {
console.log(value)
}, ((error) => {
console.log('add Attendee error: ', error)
}));
await this.saveDocument()
if (this.addedAttachmentsList.length > 0) {
this.agendaDataRepository.addEventAttachment(this._postEvent.EventId, { "attachments": this.documentAdded(this._postEvent.Attachments) }).subscribe((value) => {
console.log(value)
}, ((error) => {
this.showLoader = false
console.log('add attachment error: ', error)
}));
}
if (this.deletedAttachmentsList.length > 0) {
this.agendaDataRepository.removeEventAttachment(this._postEvent.EventId, { attachments: this.deletedAttachmentsList }).subscribe((value) => {
console.log(value)
}, ((error) => {
this.showLoader = false
console.log('remove attachment error: ', error)
}));
}
this.clearPostEvent.emit();
this.deleteTemporaryData();
this.showLoader = false;
this.close();
this.httpErrorHandle.httpsSucessMessagge('Editar evento')
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
console.log('edit: ', error)
}
}
@@ -361,7 +454,7 @@ export class EditEventPage implements OnInit {
this.injectValidation()
this.runValidation()
if(this.Form.invalid) {
if (this.Form.invalid) {
return false
}
@@ -370,22 +463,22 @@ export class EditEventPage implements OnInit {
this._postEvent.Location = /* this.domSanitizeService.sanitizeInput( */this._postEvent.Location/* ) */;
this._postEvent.Body.Text = /* this.domSanitizeService.sanitizeInput( */this._postEvent.Body.Text/* ) */;
if(!this._postEvent.EventRecurrence.hasOwnProperty('Type')) {
if (!this._postEvent.EventRecurrence.hasOwnProperty('Type')) {
this._postEvent.EventRecurrence.Type = '-1'
} else {
}
if(this._postEvent.EventRecurrence.Type == undefined) {
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') {
if (this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') {
await this.eventsService.editEvent(this._postEvent, 2, 3, this._postEvent.CalendarId).toPromise()
if(this.initCalendarName != this._postEvent.CalendarName) {
if (this.initCalendarName != this._postEvent.CalendarName) {
let body = {
"EventId": this._postEvent.EventId,
"CalendarDestinationName": this._postEvent.CalendarName,
@@ -393,14 +486,14 @@ export class EditEventPage implements OnInit {
try {
await this.eventsService.changeAgenda(body).toPromise();
} catch (e) {}
} catch (e) { }
}
this.showLoader = false;
this.httpErrorHandle.httpsSucessMessagge('Editar evento')
} else {
console.log(this._postEvent, 2, 3, this._postEvent.CalendarId)
await this.eventsService.editEvent(this._postEvent, 2, 3, this._postEvent.CalendarId).toPromise()
if(this.initCalendarName != this._postEvent.CalendarName) {
if (this.initCalendarName != this._postEvent.CalendarName) {
let body = {
"EventId": this._postEvent.EventId,
"CalendarDestinationName": this._postEvent.CalendarName,
@@ -408,14 +501,14 @@ export class EditEventPage implements OnInit {
try {
await this.eventsService.changeAgenda(body).toPromise();
} catch (e) {}
} catch (e) { }
}
this.showLoader = false;
this.httpErrorHandle.httpsSucessMessagge('Editar evento')
}
} catch(error) {
} catch (error) {
this.showLoader = false
this.httpErrorHandle.httpStatusHandle(error)
}
@@ -431,14 +524,14 @@ export class EditEventPage implements OnInit {
async saveDocument() {
console.log('save document', this.loadedEventAttachments)
try {
for( let e of this.loadedEventAttachments) {
for (let e of this.loadedEventAttachments) {
const id: any = e.Id
const remove = e['remove']
if ( id == 'add') {
if (id == 'add') {
//data.selected
const DocumentToSave = {
SourceTitle: e.SourceName,
@@ -453,7 +546,7 @@ export class EditEventPage implements OnInit {
// await this.attachmentsService.setEventAttachmentById(DocumentToSave).toPromise();
} else if(remove) {
} else if (remove) {
await this.attachmentsService.deleteEventAttachmentById(e.Id).toPromise()
}
}
@@ -498,9 +591,9 @@ export class EditEventPage implements OnInit {
restoreTemporaryData(): boolean {
const restoredData = window['temp.path:/home/agenda/edit-event.component.ts']
const restoredData = window['temp.path:/home/agenda/edit-event.component.ts']
if(JSON.stringify(restoredData) != "{}" && undefined != restoredData){
if (JSON.stringify(restoredData) != "{}" && undefined != restoredData) {
this._postEvent = restoredData.postEvent
this.eventBody = restoredData.eventBody
this.segment = restoredData.segment
@@ -513,15 +606,16 @@ export class EditEventPage implements OnInit {
}
deleteTemporaryData(){
deleteTemporaryData() {
window['temp.path:/home/agenda/edit-event.component.ts'] = {}
}
async getAttachments(eventId: string){
if(this._postEvent.HasAttachments) {
async getAttachments(eventId: string) {
if (this._postEvent.HasAttachments) {
let rest: any;
try {
rest = this.attachmentsService.getAttachmentsById(eventId).toPromise()
console.log('GetAttachment', rest)
} catch (error) {
console.error('getAttchment', error)
}
@@ -533,10 +627,11 @@ export class EditEventPage implements OnInit {
const id: any = this.loadedEventAttachments[index].Id
if(id == 'add') {
this.loadedEventAttachments = this.loadedEventAttachments.filter((e,i)=> i!=index)
if (id == 'add') {
this.loadedEventAttachments = this.loadedEventAttachments.filter((e, i) => i != index)
} else {
this.loadedEventAttachments[index]['remove'] = true
this.deletedAttachmentsList.push(id)
}
}
@@ -553,15 +648,16 @@ export class EditEventPage implements OnInit {
}
});
modal.onDidDismiss().then( async (res) => {
if(res) {
modal.onDidDismiss().then(async (res) => {
if (res) {
const data = res.data;
console.log(data)
const ApplicationIdDocumentToSave: any = {
SourceName: data.selected.Assunto,
ParentId: this._postEvent.EventId,
SourceId: data.selected.Id,
Stakeholders: data.selected.EntidadeOrganicaNome | data.selected.Stakeholders,
Stakeholders: data.selected.EntidadeOrganicaNome | data.selected.Stakeholders,
ApplicationId: data.selected.ApplicationType.toString(),
CreateDate: data.selected.Data,
Id: 'add',
@@ -572,6 +668,7 @@ export class EditEventPage implements OnInit {
}
this.loadedEventAttachments.push(ApplicationIdDocumentToSave)
this.addedAttachmentsList.push(ApplicationIdDocumentToSave)
}
});
@@ -584,7 +681,7 @@ export class EditEventPage implements OnInit {
setTimeout(() => {
if(this.eventsService.calendarNamesType[this.CalendarNameOwnerName]?.['Oficial'] && this.eventsService.calendarNamesType[this.CalendarNameOwnerName]?.['Pessoal']) {
if (this.eventsService.calendarNamesType[this.CalendarNameOwnerName]?.['Oficial'] && this.eventsService.calendarNamesType[this.CalendarNameOwnerName]?.['Pessoal']) {
this.CalendarNamesOptions = ['Oficial', 'Pessoal']
@@ -163,7 +163,7 @@ export class NewEventPage implements OnInit {
ngOnInit() {
console.log(' INTERVENIENTES',this.taskParticipants)
console.log(' INTERVENIENTES', this.taskParticipants)
this.changeProfileService.registerCallback(() => {
this.initializeData()
})
@@ -193,7 +193,7 @@ export class NewEventPage implements OnInit {
}
})
}
console.log('Attendes',this.taskParticipants)
console.log('Attendes', this.taskParticipants)
this.taskParticipants = removeDuplicate(this.taskParticipants);
this.taskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
@@ -526,7 +526,12 @@ export class NewEventPage implements OnInit {
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
this.postEvent.IsAllDayEvent = this.allDayCheck;
this.agendaDataRepository.createEvent(this.postEvent,this.CalendarName,this.documents);
this.agendaDataRepository.createEvent(this.postEvent, this.CalendarName, this.documents).subscribe((value) => {
console.log(value)
}, ((error) => {
console.log('create event error: ', error)
}));
loader.remove();
this.afterSave();
this.hhtpErrorHandle.httpsSucessMessagge('new event')
@@ -539,7 +544,7 @@ export class NewEventPage implements OnInit {
if (this.Form.invalid) {
if(new Date(this.postEvent.StartDate).getTime() < new Date(this.postEvent.EndDate).getTime()) {
if (new Date(this.postEvent.StartDate).getTime() < new Date(this.postEvent.EndDate).getTime()) {
this.toastService._badRequest("Data de inicio menor que a data de fim")
}
@@ -1042,7 +1047,7 @@ export class NewEventPage implements OnInit {
}
async fetchContacts(filter: string) {
console.log(this.loggeduser.Profile)
console.log(this.loggeduser.Profile)
if (this.loggeduser.Profile == 'PR') {
this.contactsService.getContacts(filter).subscribe(result => {
if (this.eventPersons != null) {
@@ -1063,7 +1068,7 @@ console.log(this.loggeduser.Profile)
this.contacts = filterLoggedUserEmail;
this.taskParticipants.push(this.contacts[0]);
this.setIntervenient.emit(this.taskParticipants);
this.setIntervenient.emit(this.taskParticipants);
console.log('Attendes Email', this.taskParticipants)
}
);
@@ -1075,13 +1080,13 @@ console.log(this.loggeduser.Profile)
this.postEvent.IsAllDayEvent = this.allDayCheck;
this.postEvent.StartDate = this.setAlldayTime(this.postEvent.StartDate)
this.postEvent.EndDate = this.setAlldayTimeEndDate(this.postEvent.EndDate)
console.log('Recurso ativado!!');
} else {
this.postEvent.IsAllDayEvent = this.allDayCheck;
this.postEvent.EndDate = this.setAlldayTimeEndDateNotAlday(this.postEvent.EndDate)
console.log('Recurso desativado');
}
}
@@ -170,7 +170,12 @@ export class ViewEventPage implements OnInit {
}
deleteEvent_v2() {
this.agendaDataRepository.deleteEvent(this.loadedEvent.EventId)
console.log(this.loadedEvent.EventId)
this.agendaDataRepository.deleteEvent(this.loadedEvent.EventId).subscribe(() => {
console.log()
},((error) => {
console.log('delete event error: ',error)
}))
}
async deleteEvent() {