mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
Regenerate components
This commit is contained in:
@@ -0,0 +1,241 @@
|
||||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { ModalController } from '@ionic/angular';
|
||||
import { EventBody } from 'src/app/models/eventbody.model';
|
||||
import { EventPerson } from 'src/app/models/eventperson.model';
|
||||
import { EventsService } from 'src/app/services/events.service';
|
||||
import { Event } from 'src/app/models/event.model';
|
||||
import { AlertController } from '@ionic/angular';
|
||||
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
|
||||
import { SearchPage } from 'src/app/pages/search/search.page';
|
||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||
import { Attachment } from 'src/app/models/attachment.model';
|
||||
@Component({
|
||||
selector: 'app-edit-event',
|
||||
templateUrl: './edit-event.page.html',
|
||||
styleUrls: ['./edit-event.page.scss'],
|
||||
})
|
||||
export class EditEventPage implements OnInit {
|
||||
|
||||
|
||||
stEvent: Event;
|
||||
isRecurring:string;
|
||||
isEventEdited: boolean;
|
||||
loadedEvent: Event;
|
||||
eventBody: EventBody;
|
||||
segment:string = "true";
|
||||
eventAttendees: EventPerson[];
|
||||
minDate: string;
|
||||
loadedEventAttachments: Attachment[];
|
||||
|
||||
@Input() taskParticipants: EventPerson[];
|
||||
@Input() taskParticipantsCc: EventPerson[];
|
||||
@Input() profile:string;
|
||||
@Input() selectedSegment: string;
|
||||
@Input() postEvent: Event;
|
||||
@Output() clearContact = new EventEmitter<any>();
|
||||
|
||||
@Output() openAttendeesComponent = new EventEmitter<any>();
|
||||
@Output() closeComponent = new EventEmitter<any>();
|
||||
|
||||
@Output() setIntervenient = new EventEmitter<any>();
|
||||
@Output() setIntervenientCC = new EventEmitter<any>();
|
||||
@Output() clearPostEvent = new EventEmitter<any>();
|
||||
|
||||
constructor(
|
||||
private modalController: ModalController,
|
||||
private eventsService: EventsService,
|
||||
public alertController: AlertController,
|
||||
private attachmentsService: AttachmentsService,
|
||||
|
||||
) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
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, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// attendees list
|
||||
if(this.postEvent.Attendees != null) {
|
||||
this.postEvent.Attendees.forEach(e =>{
|
||||
if(e.IsRequired) {
|
||||
this.taskParticipants.push(e);
|
||||
} else {
|
||||
this.taskParticipantsCc.push(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
this.taskParticipants = removeDuplicate(this.taskParticipants);
|
||||
this.taskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
|
||||
|
||||
this.setIntervenient.emit(this.taskParticipants);
|
||||
this.setIntervenientCC.emit(this.taskParticipantsCc);
|
||||
|
||||
this.isEventEdited = false;
|
||||
|
||||
if(this.postEvent.IsRecurring == false){
|
||||
this.isRecurring = "Não se repete";
|
||||
}
|
||||
else{
|
||||
this.isRecurring = "Repete";
|
||||
}
|
||||
}
|
||||
|
||||
this.getAttachments(this.postEvent.EventId);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
close(){
|
||||
this.closeComponent.emit();
|
||||
this.setIntervenient.emit([]);
|
||||
this.setIntervenientCC.emit([]);
|
||||
this.clearContact.emit();
|
||||
|
||||
this.deleteTemporaryData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
async save(){
|
||||
|
||||
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
|
||||
|
||||
await this.eventsService.editEvent(this.postEvent, 2, 3).subscribe(async () => {
|
||||
const alert = await this.alertController.create({
|
||||
cssClass: 'my-custom-class',
|
||||
header: 'Evento actualizado',
|
||||
buttons: ['OK']
|
||||
});
|
||||
|
||||
|
||||
setTimeout(()=>{
|
||||
alert.dismiss();
|
||||
}, 1500);
|
||||
|
||||
});
|
||||
|
||||
this.clearPostEvent.emit();
|
||||
this.deleteTemporaryData();
|
||||
this.close();
|
||||
}
|
||||
|
||||
async addParticipants() {
|
||||
|
||||
this.saveTemporaryData();
|
||||
|
||||
this.openAttendeesComponent.emit({
|
||||
type: "intervenient"
|
||||
});
|
||||
|
||||
this.clearContact.emit();
|
||||
}
|
||||
|
||||
|
||||
async addParticipantsCc() {
|
||||
|
||||
this.saveTemporaryData();
|
||||
|
||||
this.openAttendeesComponent.emit({
|
||||
type: "CC"
|
||||
});
|
||||
|
||||
this.clearContact.emit();
|
||||
}
|
||||
|
||||
|
||||
saveTemporaryData(){
|
||||
|
||||
window['temp.path:/home/agenda/edit-event.component.ts'] = {
|
||||
postEvent: this.postEvent,
|
||||
eventBody: this.eventBody,
|
||||
segment: this.segment
|
||||
}
|
||||
}
|
||||
|
||||
restoreTemporaryData(): boolean{
|
||||
|
||||
const restoredData = window['temp.path:/home/agenda/edit-event.component.ts']
|
||||
|
||||
if(JSON.stringify(restoredData) != "{}" && undefined != restoredData){
|
||||
this.postEvent = restoredData.postEvent
|
||||
this.eventBody = restoredData.eventBody
|
||||
this.segment = restoredData.segment
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
deleteTemporaryData(){
|
||||
window['temp.path:/home/agenda/edit-event.component.ts'] = {}
|
||||
}
|
||||
|
||||
getAttachments(eventId: string){
|
||||
this.attachmentsService.getAttachmentsById(eventId).subscribe(res=>{
|
||||
this.loadedEventAttachments = res;
|
||||
console.log('res', res);
|
||||
});
|
||||
}
|
||||
|
||||
deleteAttachment(attachmentID: string) {
|
||||
|
||||
this.attachmentsService.deleteEventAttachmentById(attachmentID).subscribe(
|
||||
res=>{
|
||||
this.loadedEventAttachments = this.loadedEventAttachments.filter(e=> e.Id.toString() != attachmentID);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
async getDoc() {
|
||||
const modal = await this.modalController.create({
|
||||
component: SearchPage,
|
||||
cssClass: 'modal-width-100-width-background modal',
|
||||
componentProps: {
|
||||
type: 'AccoesPresidenciais & ArquivoDespachoElect',
|
||||
showSearchInput: true,
|
||||
select: true,
|
||||
}
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then( async (res)=>{
|
||||
if(res){
|
||||
const data = res.data;
|
||||
//data.selected
|
||||
const DocumentToSave = {
|
||||
SourceTitle: data.selected.Assunto,
|
||||
ParentId: this.postEvent.EventId,
|
||||
Source: '1',
|
||||
SourceId: data.selected.Id,
|
||||
ApplicationId: data.selected.ApplicationType.toString(),
|
||||
Id: '0',
|
||||
Link: '',
|
||||
SerialNumber: '',
|
||||
};
|
||||
|
||||
await this.attachmentsService.setEventAttachmentById(DocumentToSave).subscribe(()=>{
|
||||
this.getAttachments(this.postEvent.EventId);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user