2021-07-01 09:36:17 +01:00
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
2021-06-30 16:12:47 +01:00
|
|
|
import { PublicationFolder } from 'src/app/models/publicationfolder';
|
2021-06-30 16:33:53 +01:00
|
|
|
import { PublicationsService } from 'src/app/services/publications.service';
|
2021-07-01 09:36:17 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2021-06-30 16:12:47 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-edit-action',
|
|
|
|
|
templateUrl: './edit-action.page.html',
|
|
|
|
|
styleUrls: ['./edit-action.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class EditActionPage implements OnInit {
|
|
|
|
|
|
|
|
|
|
folder: PublicationFolder;
|
2021-07-01 11:08:04 +01:00
|
|
|
@Input() folderId: string;
|
2021-06-30 16:12:47 +01:00
|
|
|
@Output() closeDesktopComponent= new EventEmitter<any>();
|
2021-07-01 14:30:44 +01:00
|
|
|
@Output() updateDesktopComponent= new EventEmitter<any>();
|
2021-06-30 16:12:47 +01:00
|
|
|
|
2021-06-30 16:33:53 +01:00
|
|
|
constructor(
|
|
|
|
|
private publicationsService: PublicationsService,
|
2021-07-01 09:36:17 +01:00
|
|
|
private toastService: ToastService,
|
2021-06-30 16:33:53 +01:00
|
|
|
) {
|
2021-06-30 16:12:47 +01:00
|
|
|
this.folder = new PublicationFolder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-07-01 09:36:17 +01:00
|
|
|
this.getPublicationDetail();
|
2021-06-30 16:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(){
|
|
|
|
|
this.closeDesktopComponent.emit();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-01 09:36:17 +01:00
|
|
|
getPublicationDetail(){
|
|
|
|
|
this.publicationsService.GetPresidentialAction(this.folderId).subscribe(res=>{
|
|
|
|
|
this.folder = res;
|
2021-06-30 16:33:53 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
async save() {
|
2021-07-01 11:08:04 +01:00
|
|
|
let body = {
|
|
|
|
|
ProcessId: this.folderId,
|
2021-06-30 16:12:47 +01:00
|
|
|
Description: this.folder.Description,
|
|
|
|
|
Detail: this.folder.Detail,
|
|
|
|
|
DateBegin: this.folder.DateBegin,
|
|
|
|
|
DateEnd: this.folder.DateEnd,
|
2021-07-01 09:36:17 +01:00
|
|
|
ActionType: this.folder.ActionType,
|
2021-06-30 16:12:47 +01:00
|
|
|
}
|
2021-07-01 11:08:04 +01:00
|
|
|
console.log(body);
|
2021-06-30 16:12:47 +01:00
|
|
|
|
2021-07-01 11:08:04 +01:00
|
|
|
try {
|
|
|
|
|
await this.publicationsService.UpdatePresidentialAction(body).toPromise()
|
2021-06-30 16:12:47 +01:00
|
|
|
this.close();
|
2021-07-01 14:30:44 +01:00
|
|
|
this.updateDesktopComponent.emit();
|
|
|
|
|
this.toastService.successMessage('Acção presidencial atualizada')
|
2021-06-30 16:12:47 +01:00
|
|
|
} catch (error) {
|
2021-07-01 14:30:44 +01:00
|
|
|
this.toastService.badRequest('Não foi possivel atualizar a acção presidencial')
|
2021-07-01 09:36:17 +01:00
|
|
|
}
|
2021-07-01 11:08:04 +01:00
|
|
|
|
2021-06-30 16:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|