2021-03-16 12:14:46 +01:00
|
|
|
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
|
2021-07-06 10:33:24 +01:00
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
2021-07-06 12:26:45 +01:00
|
|
|
import * as moment from 'moment';
|
2021-03-16 12:14:46 +01:00
|
|
|
import { PublicationFolder } from 'src/app/models/publicationfolder';
|
|
|
|
|
import { PublicationsService } from 'src/app/services/publications.service';
|
2021-06-15 15:09:20 +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';
|
2023-09-19 10:21:23 +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"
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-26 16:14:55 +01:00
|
|
|
|
2021-03-16 12:14:46 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-new-action',
|
|
|
|
|
templateUrl: './new-action.page.html',
|
|
|
|
|
styleUrls: ['./new-action.page.scss'],
|
2023-09-19 10:21:23 +01:00
|
|
|
providers: [
|
|
|
|
|
{ provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_DATE_FORMATS },
|
|
|
|
|
]
|
2021-03-16 12:14:46 +01:00
|
|
|
})
|
|
|
|
|
export class NewActionPage implements OnInit {
|
|
|
|
|
|
|
|
|
|
folder: PublicationFolder;
|
|
|
|
|
segment:string;
|
2021-07-07 11:13:31 +01:00
|
|
|
|
|
|
|
|
public date: any;
|
|
|
|
|
public disabled = false;
|
|
|
|
|
public showSpinners = true;
|
|
|
|
|
public showSeconds = false;
|
|
|
|
|
public touchUi = false;
|
|
|
|
|
public enableMeridian = false;
|
|
|
|
|
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;
|
2022-06-09 09:37:58 +01:00
|
|
|
currentDate = new Date();
|
2021-07-06 12:26:45 +01:00
|
|
|
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
|
2021-12-14 14:58:34 +01:00
|
|
|
|
2021-07-06 10:33:24 +01:00
|
|
|
Form: FormGroup;
|
|
|
|
|
validateFrom = false
|
2021-07-06 12:26:45 +01:00
|
|
|
|
2021-03-16 12:14:46 +01:00
|
|
|
@Output() closeDesktopComponent= new EventEmitter<any>();
|
2021-07-13 16:53:11 +01:00
|
|
|
@Output() getActions= new EventEmitter<any>();
|
2021-03-16 12:14:46 +01:00
|
|
|
|
|
|
|
|
constructor(
|
2021-06-08 15:59:06 +01:00
|
|
|
private publication: PublicationsService,
|
2023-02-27 09:34:36 +01:00
|
|
|
private toastService: ToastService,
|
|
|
|
|
private httpErrorHandle: HttpErrorHandle,
|
2021-12-14 14:58:34 +01:00
|
|
|
) {
|
2021-03-16 12:14:46 +01:00
|
|
|
this.folder = new PublicationFolder();
|
2021-07-06 12:26:45 +01:00
|
|
|
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2023-02-06 16:30:11 +01:00
|
|
|
this.setStartDate()
|
|
|
|
|
this.setEndDate()
|
2021-07-06 12:26:45 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-16 12:14:46 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2022-01-19 11:22:54 +01:00
|
|
|
this.segment = "Evento";
|
2021-03-16 12:14:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
segmentChanged(ev: any) {
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2021-03-16 12:14:46 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-15 11:25:19 +01:00
|
|
|
/* get dateValid() {
|
2022-12-17 16:19:23 +01:00
|
|
|
var validado: boolean;
|
|
|
|
|
|
|
|
|
|
if (window.innerWidth <= 800) {
|
|
|
|
|
if ((this.folder.DateBegin < this.folder.DateEnd) && (new Date(this.folder.DateBegin).getTime() > this.currentDate.getTime())) {
|
|
|
|
|
validado = true;
|
|
|
|
|
}else{
|
|
|
|
|
validado = false;
|
|
|
|
|
}
|
|
|
|
|
return validado == true ? ['ok']: [];
|
2021-07-06 16:18:00 +01:00
|
|
|
} else {
|
|
|
|
|
return ['ok']
|
|
|
|
|
}
|
2024-02-15 11:25:19 +01:00
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
get dateValid() {
|
|
|
|
|
return new Date(this.folder.DateBegin).getTime() < new Date(this.folder.DateBegin).getTime() ? 'ok': null
|
2021-07-06 16:18:00 +01:00
|
|
|
}
|
2021-12-14 14:58:34 +01:00
|
|
|
|
2021-07-06 10:33:24 +01:00
|
|
|
runValidation() {
|
2021-12-14 14:58:34 +01:00
|
|
|
this.validateFrom = true;
|
2022-04-22 16:42:37 +01:00
|
|
|
if((new Date(this.folder.DateBegin).getTime()) > (new Date(this.folder.DateEnd).getTime())) {
|
2021-12-14 14:58:34 +01:00
|
|
|
this.toastService._badRequest("A data de início não pode ser superior a data de fim");
|
|
|
|
|
}
|
2021-07-06 10:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
injectValidation() {
|
|
|
|
|
|
|
|
|
|
this.Form = new FormGroup({
|
|
|
|
|
Subject: new FormControl(this.folder.Description, [
|
|
|
|
|
Validators.required,
|
2022-10-04 16:04:23 +01:00
|
|
|
//Validators.minLength(1)
|
2021-07-06 16:18:00 +01:00
|
|
|
]),
|
|
|
|
|
Date: new FormControl(this.dateValid, [
|
|
|
|
|
Validators.required
|
|
|
|
|
]),
|
2022-10-04 16:04:23 +01:00
|
|
|
Detail: new FormControl(this.folder.Detail, [
|
|
|
|
|
Validators.required
|
|
|
|
|
])
|
2021-07-06 10:33:24 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-25 16:12:40 +01:00
|
|
|
async save() {
|
2021-07-06 12:26:45 +01:00
|
|
|
|
|
|
|
|
this.injectValidation()
|
|
|
|
|
this.runValidation()
|
|
|
|
|
|
2024-02-15 11:25:19 +01:00
|
|
|
if(this.Form.invalid) return false
|
2021-07-13 16:53:11 +01:00
|
|
|
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2021-07-06 12:26:45 +01:00
|
|
|
|
2021-03-16 12:14:46 +01:00
|
|
|
this.folder = {
|
|
|
|
|
ProcessId: null,
|
|
|
|
|
Description: this.folder.Description,
|
|
|
|
|
Detail: this.folder.Detail,
|
|
|
|
|
DateBegin: this.folder.DateBegin,
|
|
|
|
|
DateEnd: this.folder.DateEnd,
|
|
|
|
|
ActionType: this.segment,
|
|
|
|
|
}
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2021-12-14 14:58:34 +01:00
|
|
|
|
2021-07-12 11:13:29 +01:00
|
|
|
const loader = this.toastService.loading()
|
|
|
|
|
|
2021-05-25 16:12:40 +01:00
|
|
|
try {
|
|
|
|
|
await this.publication.CreatePublicationFolder(this.folder).toPromise()
|
|
|
|
|
this.close();
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Acção criada')
|
2021-07-13 16:53:11 +01:00
|
|
|
|
|
|
|
|
this.getActions.emit()
|
2021-05-25 16:12:40 +01:00
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
2023-01-24 15:56:47 +01:00
|
|
|
} finally {
|
2021-07-12 11:13:29 +01:00
|
|
|
loader.remove()
|
2021-05-25 16:12:40 +01:00
|
|
|
}
|
2021-12-14 14:58:34 +01:00
|
|
|
|
2021-03-16 12:14:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-22 16:42:37 +01:00
|
|
|
close() {
|
2021-03-16 12:14:46 +01:00
|
|
|
this.closeDesktopComponent.emit();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-24 15:56:47 +01:00
|
|
|
|
2023-02-06 16:30:11 +01:00
|
|
|
round() {
|
|
|
|
|
let date = new Date();
|
|
|
|
|
const minutes = date.getMinutes();
|
|
|
|
|
date.setSeconds(0);
|
2023-01-24 15:56:47 +01:00
|
|
|
|
2023-02-06 16:30:11 +01:00
|
|
|
if(minutes % 15 != 0) {
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2023-02-06 16:30:11 +01:00
|
|
|
if (minutes > 45) {
|
|
|
|
|
date.setMinutes(60)
|
|
|
|
|
} else if (minutes > 30) {
|
|
|
|
|
date.setMinutes(45)
|
|
|
|
|
} else if (minutes > 15) {
|
|
|
|
|
date.setMinutes(30)
|
2023-02-06 19:04:26 +01:00
|
|
|
} else if (minutes > 0) {
|
2023-02-06 16:30:11 +01:00
|
|
|
date.setMinutes(15)
|
2023-01-24 15:56:47 +01:00
|
|
|
}
|
2023-02-06 16:30:11 +01:00
|
|
|
|
2023-09-19 10:21:23 +01:00
|
|
|
}
|
2023-02-06 16:30:11 +01:00
|
|
|
|
|
|
|
|
return date
|
|
|
|
|
}
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2023-02-06 16:30:11 +01:00
|
|
|
roundTimeQuarterHour() {
|
|
|
|
|
let date = new Date();
|
|
|
|
|
const minutes = date.getMinutes();
|
|
|
|
|
date.setSeconds(0);
|
|
|
|
|
|
|
|
|
|
if(minutes % 15 != 0) {
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2023-02-06 16:30:11 +01:00
|
|
|
if (minutes > 45) {
|
|
|
|
|
date.setMinutes(60)
|
|
|
|
|
} else if (minutes > 30) {
|
|
|
|
|
date.setMinutes(45)
|
|
|
|
|
} else if (minutes > 15) {
|
|
|
|
|
date.setMinutes(30)
|
2023-02-06 19:04:26 +01:00
|
|
|
} else if (minutes > 0) {
|
2023-02-06 16:30:11 +01:00
|
|
|
date.setMinutes(15)
|
2023-01-24 15:56:47 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-19 10:21:23 +01:00
|
|
|
}
|
2023-02-06 16:30:11 +01:00
|
|
|
|
|
|
|
|
return date
|
2023-01-24 15:56:47 +01:00
|
|
|
}
|
2023-02-13 18:50:31 +01:00
|
|
|
|
|
|
|
|
roundTimeQuarterHourPlus15(date:Date) {
|
|
|
|
|
const _date = new Date(date);
|
|
|
|
|
const minutes = _date .getMinutes();
|
|
|
|
|
_date .setMinutes(minutes + 15)
|
2023-09-19 10:21:23 +01:00
|
|
|
return _date
|
2023-02-13 18:50:31 +01:00
|
|
|
}
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2023-01-24 15:56:47 +01:00
|
|
|
|
2023-02-06 16:30:11 +01:00
|
|
|
setStartDate() {
|
|
|
|
|
this.folder.DateBegin = this.roundTimeQuarterHour()
|
2023-01-24 15:56:47 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-06 16:30:11 +01:00
|
|
|
setEndDate() {
|
2023-02-13 18:50:31 +01:00
|
|
|
this.folder.DateEnd = this.roundTimeQuarterHourPlus15(this.folder.DateBegin);
|
2023-01-24 15:56:47 +01:00
|
|
|
}
|
2021-03-16 12:14:46 +01:00
|
|
|
}
|