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

109 lines
2.9 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;
public minDate: any;
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"));
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-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
}
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;
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() {
if (window.innerWidth <= 800) {
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
}
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-06-30 16:12:47 +01:00
}
}