mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
125 lines
3.4 KiB
TypeScript
125 lines
3.4 KiB
TypeScript
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
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';
|
|
|
|
@Component({
|
|
selector: 'app-edit-action',
|
|
templateUrl: './edit-action.page.html',
|
|
styleUrls: ['./edit-action.page.scss'],
|
|
})
|
|
export class EditActionPage implements OnInit {
|
|
|
|
Form: FormGroup;
|
|
validateFrom = false
|
|
|
|
public date: any;
|
|
public disabled = false;
|
|
public showSpinners = true;
|
|
public showSeconds = false;
|
|
public touchUi = false;
|
|
public enableMeridian = false;
|
|
public minDate = new Date().toISOString().slice(0,10)
|
|
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
|
|
public maxDate: any;
|
|
public stepHour = 1;
|
|
public stepMinute = 15;
|
|
public stepSecond = 5;
|
|
public dateControlStart = new FormControl(moment("DD MM YYYY hh"));
|
|
public dateControlEnd = new FormControl(moment("DD MM YYYY hh"));
|
|
public currentDate = new Date();
|
|
|
|
folder: PublicationFolder;
|
|
@Input() folderId: string;
|
|
@Output() closeDesktopComponent= new EventEmitter<any>();
|
|
@Output() updateDesktopComponent= new EventEmitter<any>();
|
|
@Output() getActions= new EventEmitter<any>();
|
|
|
|
constructor(
|
|
private publicationsService: PublicationsService,
|
|
private toastService: ToastService,
|
|
) {
|
|
this.folder = new PublicationFolder();
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.getPublicationDetail();
|
|
}
|
|
|
|
close() {
|
|
this.closeDesktopComponent.emit();
|
|
}
|
|
|
|
getPublicationDetail() {
|
|
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)));
|
|
|
|
});
|
|
}
|
|
|
|
get dateValid() {
|
|
if (window.innerWidth < 701) {
|
|
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
|
|
]),
|
|
})
|
|
}
|
|
|
|
async save() {
|
|
this.injectValidation();
|
|
this.runValidation();
|
|
|
|
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,
|
|
}
|
|
// dconsole.log(this.folder.DateEnd);
|
|
|
|
const loader = this.toastService.loading()
|
|
|
|
try {
|
|
await this.publicationsService.UpdatePresidentialAction(body).toPromise()
|
|
this.close();
|
|
this.updateDesktopComponent.emit();
|
|
this.toastService._successMessage('Acção presidencial atualizada')
|
|
this.getActions.emit()
|
|
|
|
} catch (error) {
|
|
if(error.status == 0) {
|
|
this.toastService._badRequest('Sem acesso à internet. Por favor verifique sua conexão')
|
|
} else {
|
|
this.toastService._badRequest('Não foi possivel atualizar a acção presidencial')
|
|
}
|
|
} finally {
|
|
loader.remove()
|
|
}
|
|
|
|
}
|
|
}
|