2021-07-07 17:02:19 +01:00
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
|
|
|
import { ModalController, NavParams } from '@ionic/angular';
|
|
|
|
|
import * as moment from 'moment';
|
|
|
|
|
import { PublicationFolder } from 'src/app/models/publicationfolder';
|
|
|
|
|
import { PublicationsService } from 'src/app/services/publications.service';
|
|
|
|
|
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';
|
2023-08-30 14:39:27 +01:00
|
|
|
import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker';
|
|
|
|
|
import { NgxMatDateFormats } from '@angular-material-components/datetime-picker';
|
|
|
|
|
|
|
|
|
|
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
|
|
|
|
|
parse: {
|
|
|
|
|
dateInput: "YYYY-MMMM-DD HH:mm"
|
|
|
|
|
},
|
|
|
|
|
display: {
|
|
|
|
|
dateInput: "DD MMM YYYY H:mm",
|
|
|
|
|
monthYearLabel: "MMM YYYY",
|
|
|
|
|
dateA11yLabel: "LL",
|
|
|
|
|
monthYearA11yLabel: "MMMM YYYY"
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-07 16:34:01 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-edit-action',
|
|
|
|
|
templateUrl: './edit-action.page.html',
|
|
|
|
|
styleUrls: ['./edit-action.page.scss'],
|
2023-08-30 14:39:27 +01:00
|
|
|
providers: [
|
|
|
|
|
{ provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_DATE_FORMATS },
|
|
|
|
|
]
|
2021-07-07 16:34:01 +01:00
|
|
|
})
|
|
|
|
|
export class EditActionPage implements OnInit {
|
|
|
|
|
|
2021-07-07 17:02:19 +01:00
|
|
|
Form: FormGroup;
|
|
|
|
|
validateFrom = false
|
|
|
|
|
|
|
|
|
|
public date: any;
|
|
|
|
|
public disabled = false;
|
|
|
|
|
public showSpinners = true;
|
|
|
|
|
public showSeconds = false;
|
|
|
|
|
public touchUi = false;
|
|
|
|
|
public enableMeridian = false;
|
2022-06-10 12:37:10 +01:00
|
|
|
public minDate = new Date().toISOString()
|
2021-07-07 17:02:19 +01:00
|
|
|
public maxDate: any;
|
|
|
|
|
public stepHour = 1;
|
2023-01-24 15:56:47 +01:00
|
|
|
public stepMinute = 15;
|
2021-07-07 17:02:19 +01:00
|
|
|
public stepSecond = 5;
|
2022-06-10 12:37:10 +01:00
|
|
|
currentDate = new Date();
|
2021-07-07 17:02:19 +01:00
|
|
|
|
|
|
|
|
folder: PublicationFolder;
|
|
|
|
|
folderId: string;
|
|
|
|
|
@Output() closeDesktopComponent= new EventEmitter<any>();
|
|
|
|
|
@Output() updateDesktopComponent= new EventEmitter<any>();
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private publicationsService: PublicationsService,
|
|
|
|
|
private toastService: ToastService,
|
|
|
|
|
private navParams: NavParams,
|
|
|
|
|
private modalController: ModalController,
|
2023-02-27 09:34:36 +01:00
|
|
|
private httpErrorHandle: HttpErrorHandle
|
2021-07-07 17:02:19 +01:00
|
|
|
) {
|
|
|
|
|
this.folder = new PublicationFolder();
|
|
|
|
|
this.folderId = this.navParams.get('folderId');
|
|
|
|
|
}
|
2021-07-07 16:34:01 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-07-07 17:02:19 +01:00
|
|
|
this.getPublicationDetail();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-22 08:35:44 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
|
clearInterval(this.myInterval)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
myInterval = setInterval(() => {
|
|
|
|
|
document.querySelectorAll('.ngx-mat-timepicker input').forEach((e :any) => {
|
|
|
|
|
if(e) {
|
|
|
|
|
e.disabled = true;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
2021-07-07 17:02:19 +01:00
|
|
|
close() {
|
|
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPublicationDetail() {
|
|
|
|
|
this.publicationsService.GetPresidentialAction(this.folderId).subscribe( res => {
|
|
|
|
|
this.folder = res;
|
|
|
|
|
|
|
|
|
|
});
|
2021-07-07 16:34:01 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-07 17:02:19 +01:00
|
|
|
get dateValid() {
|
2023-08-30 14:39:27 +01:00
|
|
|
return new Date(this.folder.DateBegin).getTime() < new Date(this.folder.DateEnd).getTime()? 'ok': null
|
2021-07-07 17:02:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
]),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async save() {
|
2022-06-10 12:37:10 +01:00
|
|
|
this.injectValidation()
|
|
|
|
|
this.runValidation()
|
|
|
|
|
|
|
|
|
|
if(this.Form.invalid) return false
|
|
|
|
|
|
2021-07-07 17:02:19 +01:00
|
|
|
let body = {
|
|
|
|
|
ProcessId: this.folderId,
|
|
|
|
|
Description: this.folder.Description,
|
|
|
|
|
Detail: this.folder.Detail,
|
|
|
|
|
DateBegin: this.folder.DateBegin,
|
|
|
|
|
DateEnd: this.folder.DateEnd,
|
|
|
|
|
ActionType: this.folder.ActionType,
|
|
|
|
|
}
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-07-12 11:13:29 +01:00
|
|
|
const loader = this.toastService.loading()
|
|
|
|
|
|
2021-07-07 17:02:19 +01:00
|
|
|
try {
|
|
|
|
|
await this.publicationsService.UpdatePresidentialAction(body).toPromise()
|
|
|
|
|
this.close();
|
|
|
|
|
this.updateDesktopComponent.emit();
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Editar publicação');
|
2021-07-07 17:02:19 +01:00
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
2021-07-12 11:13:29 +01:00
|
|
|
} finally {
|
|
|
|
|
loader.remove()
|
2021-07-07 17:02:19 +01:00
|
|
|
}
|
2021-07-12 11:13:29 +01:00
|
|
|
|
2021-07-07 17:02:19 +01:00
|
|
|
}
|
2021-07-07 16:34:01 +01:00
|
|
|
}
|