Skip to content

Commit

Permalink
fix: datapicker issues in ghg policy[3141]
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihar committed Dec 28, 2024
1 parent b166083 commit ea76b28
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="container">
<p-calendar [(ngModel)]="value"
<p-calendar [(ngModel)]="currentDate"
(onSelect)="onValue($event)"
[placeholder]="placeholder"
[disabled]="readonly"
Expand All @@ -10,6 +10,8 @@
[stepMinute]="stepMinute"
[stepSecond]="stepSecond"
[touchUI]="touchUi"
class="p-inputtext">
class="p-inputtext"
[appendTo]="appendTo ? 'body' : null"
>
</p-calendar>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import moment from 'moment';
export class DatetimePicker {
@Input() placeholder!: string;
@Input() readonly!: boolean;
@Input() value!: Date;
@Input() value!: string;
@Input() format!: any;
@Input() appendTo: string | null = null;
@Output() valueChange = new EventEmitter<string>();

private _currentValue!: string;
Expand All @@ -27,17 +28,22 @@ export class DatetimePicker {
public stepMinute = 5;
public stepSecond = 1;
public defaultTime = [new Date().getHours(), 0, 0]
public currentDate: Date

constructor() {
}

ngOnInit() {
this.placeholder = this.placeholder || 'Choose a date & time';
if (this.value) {
this.currentDate = new Date(this.value);
}
}

onValue(event: Date) {
const utcValue = moment(event).utc().toISOString();
if (this.value !== event) {

if (this.value !== utcValue) {
this.valueChange.emit(utcValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<h1 mat-dialog-title>Custom Period</h1>
<div mat-dialog-content class="dialog-content" [attr.started]="started">
<h1 class="dialog-title">Custom Period</h1>
<div class="dialog-content" [attr.started]="started">
<form [formGroup]="dataForm" (ngSubmit)="onSubmit()">
<div class="c1">
<div class="f1" style="padding: 6px 4px; margin-right: 8px;">
<div class="f1">
<label for="startDate">Start Date:</label>
<p-calendar
id="startDate"
[(ngModel)]="startDate"
[readonlyInput]="true"
dateFormat="dd/mm/yy">
</p-calendar>
formControlName="startDate"
dateFormat="dd/mm/yy"
[appendTo]="'body'"
[hourFormat]="'12'"
[showTime]="true"
[stepHour]="true"
[stepMinute]="true"
></p-calendar>
</div>

<div class="f1" style="padding: 15px 10px; margin-left: 28px;">
<div class="f1">
<label for="interval">Interval:</label>
<input
id="interval"
Expand All @@ -24,19 +28,20 @@ <h1 mat-dialog-title>Custom Period</h1>
(change)="selectPeriod()">
</div>

<div class="f1" style="padding: 15px 10px; margin-left: 8px;">
<div class="f1">
<label for="period">Period:</label>
<p-dropdown
id="period"
[(ngModel)]="period"
formControlName="period"
[options]="periodOptions"
placeholder="Select a period"
(onChange)="selectPeriod()">
</p-dropdown>
(onChange)="selectPeriod()"
[appendTo]="'body'"
></p-dropdown>
</div>
</div>

<div class="delimiter"></div>
<div class="delimiter"></div>

<div *ngIf="period=='week'" style="height: 80px;width: 100%;"></div>
<div *ngIf="period=='month'" style="height: 120px;width: 100%;"></div>
Expand All @@ -47,19 +52,19 @@ <h1 mat-dialog-title>Custom Period</h1>
<div class="delimiter"></div>
<p-accordion [multiple]="true">
<p-accordionTab header="Cron Mask (advanced)">
<div class="form-group">
<div class="form-group input-mask-container">
<label>* Mask: minute hour day(month) month day(week)</label>
<input pInputText type="text" placeholder="* * * * *" formControlName="mask"
class="example-full-width"/>
</div>
</p-accordionTab>
</p-accordion>

<div mat-dialog-actions>
<button mat-raised-button color="primary" type="submit" [attr.started]="started"
[disabled]="!dataForm.valid">Ok
</button>
<button mat-button type="button" (click)="onNoClick()">Cancel</button>
<div class="dialog-actions">
<p-button label="Ok" icon="pi pi-check" type="submit" [attr.started]="started"
[disabled]="!dataForm.valid" styleClass="p-button-ok p-button-primary"></p-button>
<p-button label="Cancel" icon="pi pi-times" type="button" (click)="onNoClick()"
styleClass="p-button-cancel"></p-button>
</div>
</form>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ form {

.f1 {
height: 50px;
border: 1px solid #dfdfdf;
border-radius: 4px;
margin-bottom: 10px;
position: relative;
margin-top: 10px;
margin-top: 20px;
box-sizing: border-box;
}


.f1 mat-label {
.f1 label {
position: absolute;
background: #fff;
font-size: 11px;
color: rgb(0 0 0 / 60%);
line-height: 11px;
top: -4px;
left: 4px;
top: -5px;
left: 15px;
padding: 0 5px;
z-index: 100;
}

.delimiter {
Expand Down Expand Up @@ -139,4 +139,57 @@ mat-accordion {
position: relative;
left: -6px;
width: 516px;
}
}

.dialog-title {
margin: 0 0 10px 0;
font-size: 22px;
font-weight: 500;
font-family: 'Roboto', sans-serif;
}

.input-mask-container {
position: relative;
}

.input-mask-container label {
position: absolute;
font-size: 12px;
top: -7px;
left: 15px;
background: white;
color: gray;
padding: 0 4px;
}

.input-mask-container input {
width: 465px;
}

.dialog-actions {
display: flex;
justify-content: flex-start;
gap: 10px;
margin-top: 30px;
}

::ng-deep .p-dialog .p-button {
background-color: var(--color-grey-white);
color: var(--primary-color);
border-radius: 20px;
padding: 8px 24px;
font-weight: bold;
}

::ng-deep .p-dialog .p-button-ok {
background-color: var(--primary-color);
color: var(--color-grey-white);
}

::ng-deep .p-dialog .p-button:hover {
background-color: var(--blue-100);
}

::ng-deep .p-dialog .p-button-ok:hover {
background-color: var(--blue-700);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, Inject} from '@angular/core';
import {UntypedFormBuilder, Validators} from '@angular/forms';
import {FormControl, UntypedFormBuilder, Validators} from '@angular/forms';
import moment from 'moment';
import cronstrue from 'cronstrue';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
Expand All @@ -20,6 +20,11 @@ export class CronConfigDialog {
dataForm = this.fb.group({
mask: ['* * * * *', Validators.required],
interval: [1, Validators.required],
period: ['week', Validators.required],
startDate: new FormControl(
{ value: new Date(), disabled: true },
Validators.required
),
});

weekDay = {
Expand Down Expand Up @@ -66,8 +71,7 @@ export class CronConfigDialog {

if (data.startDate) {
this.startDate = new Date(data.startDate) as Date;
} else {
this.startDate = new Date() as Date;
this.dataForm.patchValue({ startDate: this.startDate })
}

this.period = 'week';
Expand Down Expand Up @@ -247,6 +251,8 @@ export class CronConfigDialog {
}

selectPeriod() {
this.period = this.dataForm.get('period')?.value;
console.log("this.period", this.period);
this.setMask(this.getMask());
this.setText(this.getMaskByInterval());
}
Expand All @@ -263,7 +269,7 @@ export class CronConfigDialog {

setMask(mask: string) {
const data = this.dataForm.value;
this.dataForm.setValue({mask: mask, interval: data.interval});
this.dataForm.patchValue({ mask, interval: data.interval })
}

setText(mask: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@
<td class="propRowCol"></td>
<td class="propRowCell cellName">Start Date</td>
<td class="propRowCell">
<datetime-picker [(value)]="properties.startDate" [readonly]="readonly"></datetime-picker>
<datetime-picker
[(value)]="properties.startDate"
[readonly]="readonly"
[appendTo]="'body'"
></datetime-picker>
</td>
</tr>
<tr class="propRow" [attr.collapse]="propHidden.options">
<td class="propRowCol"></td>
<td class="propRowCell cellName">End Date</td>
<td class="propRowCell">
<datetime-picker [(value)]="properties.endDate" [readonly]="readonly"></datetime-picker>
<datetime-picker
[(value)]="properties.endDate"
[readonly]="readonly"
[appendTo]="'body'"
></datetime-picker>
</td>
</tr>
<tr class="propRow" [attr.collapse]="propHidden.options">
Expand All @@ -31,7 +39,9 @@
[disabled]="readonly"
(onHide)="selectPeriod()"
placeholder="Select a period"
[options]="periodOptions">
[options]="periodOptions"
[appendTo]="'body'"
>
</p-dropdown>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.propRowCell {
height: 38px
}

0 comments on commit ea76b28

Please sign in to comment.