Files
doneit-web/src/app/shared/publication/edit-action/edit-action.page.ts
T

117 lines
3.1 KiB
TypeScript
Raw Normal View History

2021-07-01 09:36:17 +01:00
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2021-07-07 11:13:31 +01:00
import { FormControl, FormGroup, Validators } from '@angular/forms';
import * as moment from 'moment';
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 {
2021-07-07 11:13:31 +01:00
Form: FormGroup;
validateFrom = false
public date: any;
public disabled = false;
public showSpinners = true;
public showSeconds = false;
public touchUi = false;
public enableMeridian = false;
2021-07-08 14:45:38 +01:00
public minDate = new Date().toISOString().slice(0,10)
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
2021-07-07 11:13:31 +01:00
public maxDate: any;
public stepHour = 1;
public stepMinute = 5;
public stepSecond = 5;
public dateControlStart = new FormControl(moment("DD MM YYYY hh"));
public dateControlEnd = new FormControl(moment("DD MM YYYY hh"));
2022-02-09 16:05:06 +01:00
2021-06-30 16:12:47 +01:00
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-07-13 16:53:11 +01:00
@Output() getActions= 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,
2022-02-09 16:05:06 +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
}
2021-07-07 11:13:31 +01:00
close() {
2021-06-30 16:12:47 +01:00
this.closeDesktopComponent.emit();
}
2021-07-07 11:13:31 +01:00
getPublicationDetail() {
2021-07-07 11:27:20 +01:00
this.publicationsService.GetPresidentialAction(this.folderId).subscribe( res => {
this.folder = res;
2022-02-09 16:05:06 +01:00
2021-07-07 11:27:20 +01:00
this.dateControlStart = new FormControl(moment(new Date(this.folder.DateBegin)));
this.dateControlEnd = new FormControl(moment(new Date(this.folder.DateEnd)));
2021-06-30 16:33:53 +01:00
});
}
2021-07-07 11:13:31 +01:00
get dateValid() {
2022-02-09 16:05:06 +01:00
if (window.innerWidth < 701) {
2021-07-07 11:13:31 +01:00
return this.folder.DateBegin < this.folder.DateEnd? ['ok']: []
} else {
return ['ok']
}
}
runValidation() {
this.validateFrom = true
}
injectValidation() {
this.Form = new FormGroup({
Subject: new FormControl(this.folder.Description, [
Validators.required,
// Validators.minLength(4)
]),
Date: new FormControl(this.dateValid, [
Validators.required
]),
})
}
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
}
2022-04-28 09:32:27 +01:00
2022-02-09 16:05:06 +01:00
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
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();
2022-05-27 13:36:37 +01:00
this.toastService._successMessage('Acção presidencial atualizada')
2021-07-13 16:53:11 +01:00
this.getActions.emit()
2021-06-30 16:12:47 +01:00
} catch (error) {
2022-05-27 13:36:37 +01:00
this.toastService._badRequest('Não foi possivel atualizar a acção presidencial')
} finally {
2021-07-12 11:13:29 +01:00
loader.remove()
2021-07-01 09:36:17 +01:00
}
2022-02-09 16:05:06 +01:00
2021-06-30 16:12:47 +01:00
}
}