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';
|
2023-02-27 09:34:36 +01:00
|
|
|
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
2021-06-30 16:12:47 +01:00
|
|
|
|
2023-09-22 18:12:48 +01:00
|
|
|
import { NgxMatDateFormats } from '@angular-material-components/datetime-picker';
|
|
|
|
|
import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker';
|
|
|
|
|
|
|
|
|
|
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
|
|
|
|
|
parse: {
|
|
|
|
|
dateInput: "YYYY-MMMM-DD HH:mm"
|
|
|
|
|
},
|
|
|
|
|
display: {
|
|
|
|
|
dateInput: "DD MMM YYYY",
|
|
|
|
|
monthYearLabel: "MMM YYYY",
|
|
|
|
|
dateA11yLabel: "LL",
|
|
|
|
|
monthYearA11yLabel: "MMMM YYYY"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-30 16:12:47 +01:00
|
|
|
@Component({
|
|
|
|
|
selector: 'app-edit-action',
|
|
|
|
|
templateUrl: './edit-action.page.html',
|
|
|
|
|
styleUrls: ['./edit-action.page.scss'],
|
2023-09-22 18:12:48 +01:00
|
|
|
providers: [
|
|
|
|
|
{ provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_DATE_FORMATS },
|
|
|
|
|
]
|
2021-06-30 16:12:47 +01:00
|
|
|
})
|
|
|
|
|
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;
|
2023-01-24 15:56:47 +01:00
|
|
|
public stepMinute = 15;
|
2021-07-07 11:13:31 +01:00
|
|
|
public stepSecond = 5;
|
|
|
|
|
public dateControlStart = new FormControl(moment("DD MM YYYY hh"));
|
|
|
|
|
public dateControlEnd = new FormControl(moment("DD MM YYYY hh"));
|
2022-06-15 15:19:40 +01:00
|
|
|
public currentDate = new Date();
|
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,
|
2023-02-27 09:34:36 +01:00
|
|
|
private httpErrorHandle: HttpErrorHandle,
|
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() {
|
2022-06-06 16:09:27 +01:00
|
|
|
this.injectValidation();
|
|
|
|
|
this.runValidation();
|
|
|
|
|
|
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-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();
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Editar Acção')
|
2021-07-13 16:53:11 +01:00
|
|
|
this.getActions.emit()
|
|
|
|
|
|
2021-06-30 16:12:47 +01:00
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
2022-05-27 13:36:37 +01:00
|
|
|
} 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
|
|
|
}
|
|
|
|
|
}
|