mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
141 lines
3.3 KiB
TypeScript
141 lines
3.3 KiB
TypeScript
import { Component, EventEmitter, 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-new-action',
|
|
templateUrl: './new-action.page.html',
|
|
styleUrls: ['./new-action.page.scss'],
|
|
})
|
|
export class NewActionPage implements OnInit {
|
|
|
|
folder: PublicationFolder;
|
|
segment:string;
|
|
|
|
public date: any;
|
|
public disabled = false;
|
|
public showSpinners = true;
|
|
public showSeconds = false;
|
|
public touchUi = false;
|
|
public enableMeridian = false;
|
|
public stepHour = 1;
|
|
public stepMinute = 5;
|
|
public stepSecond = 5;
|
|
currentDate = new Date();
|
|
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
|
|
|
|
Form: FormGroup;
|
|
validateFrom = false
|
|
|
|
public dateControlStart = new FormControl(moment("DD MM YYYY hh"));
|
|
public dateControlEnd = new FormControl(moment("DD MM YYYY hh"));
|
|
|
|
|
|
@Output() closeDesktopComponent= new EventEmitter<any>();
|
|
@Output() getActions= new EventEmitter<any>();
|
|
|
|
constructor(
|
|
private publication: PublicationsService,
|
|
private toastService: ToastService
|
|
) {
|
|
this.folder = new PublicationFolder();
|
|
|
|
}
|
|
|
|
get dateStart () {
|
|
return this.dateControlStart.value
|
|
}
|
|
|
|
get dateEnd () {
|
|
return this.dateControlEnd.value
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.segment = "Evento";
|
|
}
|
|
|
|
segmentChanged(ev: any) {
|
|
|
|
}
|
|
|
|
get dateValid() {
|
|
if (window.innerWidth > 700) {
|
|
return new Date(this.folder.DateBegin).toLocaleString('pt') < new Date(this.folder.DateEnd).toLocaleString("pt")? ['ok'] : []
|
|
} else {
|
|
return ['ok']
|
|
}
|
|
}
|
|
|
|
runValidation() {
|
|
this.validateFrom = true;
|
|
if((new Date(this.folder.DateBegin).getTime()) > (new Date(this.folder.DateEnd).getTime())) {
|
|
this.toastService._badRequest("A data de início não pode ser superior a data de fim");
|
|
}
|
|
}
|
|
|
|
injectValidation() {
|
|
|
|
this.Form = new FormGroup({
|
|
Subject: new FormControl(this.folder.Description, [
|
|
Validators.required,
|
|
//Validators.minLength(1)
|
|
]),
|
|
Date: new FormControl(this.dateValid, [
|
|
Validators.required
|
|
]),
|
|
Detail: new FormControl(this.folder.Detail, [
|
|
Validators.required
|
|
])
|
|
})
|
|
}
|
|
|
|
|
|
async save() {
|
|
|
|
this.injectValidation()
|
|
this.runValidation()
|
|
|
|
if(this.Form.invalid) {
|
|
return false
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
this.folder = {
|
|
ProcessId: null,
|
|
Description: this.folder.Description,
|
|
Detail: this.folder.Detail,
|
|
DateBegin: this.folder.DateBegin,
|
|
DateEnd: this.folder.DateEnd,
|
|
ActionType: this.segment,
|
|
}
|
|
|
|
|
|
const loader = this.toastService.loading()
|
|
|
|
try {
|
|
await this.publication.CreatePublicationFolder(this.folder).toPromise()
|
|
this.close();
|
|
this.toastService._successMessage('Acção presidencial criada')
|
|
|
|
this.getActions.emit()
|
|
} catch (error) {
|
|
this.toastService._badRequest('Não foi possivel criar a acção presidencial')
|
|
} finally {
|
|
loader.remove()
|
|
}
|
|
|
|
}
|
|
|
|
close() {
|
|
this.closeDesktopComponent.emit();
|
|
}
|
|
|
|
}
|