Improve documents

This commit is contained in:
Peter Maquiran
2021-07-09 12:50:03 +01:00
parent 01d9c70975
commit cdece357e3
3 changed files with 62 additions and 19 deletions
@@ -30,7 +30,7 @@ export class EditEventPage implements OnInit {
segment:string = "true";
eventAttendees: EventPerson[];
// minDate: string;
loadedEventAttachments: Attachment[];
loadedEventAttachments: Attachment[]=[];
public date: any;
public disabled = false;
@@ -221,6 +221,41 @@ export class EditEventPage implements OnInit {
this.clearPostEvent.emit();
this.deleteTemporaryData();
this.close();
this.saveDocument()
}
saveDocument() {
this.loadedEventAttachments.forEach((e)=>{
const id: any = e.Id
const remove = e['remove']
if ( id == 'add') {
//data.selected
const DocumentToSave = {
SourceTitle: e.SourceName,
ParentId: this.postEvent.EventId,
Source: '1',
SourceId: e.SourceId,
ApplicationId: e.ApplicationId.toString(),
Id: '0',
Link: '',
SerialNumber: '',
};
this.attachmentsService.setEventAttachmentById(DocumentToSave).subscribe(()=>{
this.getAttachments(this.postEvent.EventId);
});
} else if(remove) {
this.attachmentsService.deleteEventAttachmentById(e.Id).subscribe( res=> {})
}
})
}
async addParticipants() {
@@ -300,12 +335,17 @@ export class EditEventPage implements OnInit {
});
}
deleteAttachment(attachmentID: string) {
deleteAttachment(attachmentID: string, index) {
this.attachmentsService.deleteEventAttachmentById(attachmentID).subscribe(
res=>{
this.loadedEventAttachments = this.loadedEventAttachments.filter(e=> e.Id.toString() != attachmentID);
})
const id: any = this.loadedEventAttachments[index].Id
if(id == 'add') {
this.loadedEventAttachments = this.loadedEventAttachments.filter((e,i)=> i!=index)
} else {
this.loadedEventAttachments[index]['remove'] = true
}
}
@@ -323,21 +363,25 @@ export class EditEventPage implements OnInit {
modal.onDidDismiss().then( async (res)=>{
if(res){
const data = res.data;
//data.selected
const DocumentToSave = {
SourceTitle: data.selected.Assunto,
const ApplicationIdDocumentToSave: any = {
SourceName: data.selected.Assunto,
ParentId: this.postEvent.EventId,
Source: '1',
SourceId: data.selected.Id,
Stakeholders: false,
ApplicationId: data.selected.ApplicationType.toString(),
Id: '0',
CreateDate: false,
// needed to attach this document
Id: 'add',
SourceTitle: data.selected.Assunto,
Source: '1',
Link: '',
SerialNumber: '',
};
}
console.log( this.loadedEventAttachments)
this.loadedEventAttachments.push(ApplicationIdDocumentToSave)
await this.attachmentsService.setEventAttachmentById(DocumentToSave).subscribe(()=>{
this.getAttachments(this.postEvent.EventId);
});
}
});