Skip to content

Commit

Permalink
Merge pull request #3483 from ita-social-projects/fix/#7860-provide-d…
Browse files Browse the repository at this point in the history
…efault-export-time

[Fix] #7860 set default working hours
  • Loading branch information
hnativlyubomyr authored Dec 9, 2024
2 parents e884d22 + 5c2de3b commit f386c36
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { fromSelect, toSelect } from '../../../ubs-admin-table/table-cell-time/table-cell-time-range';
import { fromSelect, toSelect, WorkingHours } from '../../../ubs-admin-table/table-cell-time/table-cell-time-range';
import { formatDate } from '@angular/common';

@Component({
Expand All @@ -22,8 +22,10 @@ export class TimePickerComponent implements OnInit {
@Input() exportDate;
@Output() timeOfExport = new EventEmitter<object>();
ngOnInit(): void {
this.fromInput = this.setTimeFrom;
this.toInput = this.setTimeTo;
this.fromInput = this.setTimeFrom || WorkingHours.FROM;
this.toInput = this.setTimeTo || WorkingHours.TO;
this.from = this.fromInput;
this.to = this.toInput;
this.fromSelect = fromSelect;
this.toSelect = toSelect;
this.initTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,12 @@ <h4>{{ 'several-orders-pop-up.title' | translate }}</h4>
<ng-template #spinner>
<app-spinner></app-spinner>
</ng-template>
<app-time-picker *ngIf="showTimePicker" (timeOfExport)="setExportTime($event)" [exportDate]="getExportDate()"> </app-time-picker>
<app-time-picker
*ngIf="showTimePicker"
(timeOfExport)="setExportTime($event)"
[exportDate]="getExportDate()"
[setTimeFrom]="fromInput"
[setTimeTo]="toInput"
>
</app-time-picker>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatDialogRef } from '@angular/material/dialog';
import {
IResponsiblePersonsData,
Expand All @@ -15,6 +15,7 @@ import {
import { OrderService } from '../../services/order.service';
import { take } from 'rxjs';
import { formatDate } from '@angular/common';
import { WorkingHours } from '../ubs-admin-table/table-cell-time/table-cell-time-range';

@Component({
selector: 'app-ubs-admin-several-orders-pop-up',
Expand Down Expand Up @@ -80,8 +81,8 @@ export class UbsAdminSeveralOrdersPopUpComponent implements OnInit {
this.exportInfo?.dateExport ? formatDate(this.exportInfo.dateExport, 'yyyy-MM-dd', this.currentLang) : '',
[Validators.required]
],
timeDeliveryFrom: [this.parseTimeToStr(this.exportInfo?.timeDeliveryFrom), [Validators.required]],
timeDeliveryTo: [this.parseTimeToStr(this.exportInfo?.timeDeliveryTo), [Validators.required]],
timeDeliveryFrom: [this.parseTimeToStr(this.exportInfo?.timeDeliveryFrom, WorkingHours.FROM), [Validators.required]],
timeDeliveryTo: [this.parseTimeToStr(this.exportInfo?.timeDeliveryTo, WorkingHours.TO), [Validators.required]],
receivingStationId: [this.getReceivingStationById(this.exportInfo?.receivingStationId), [Validators.required]]
}),

Expand All @@ -102,6 +103,13 @@ export class UbsAdminSeveralOrdersPopUpComponent implements OnInit {

showTimePickerClick(): void {
this.showTimePicker = true;
this.fromInput = this.getFormControl('exportDetailsDto', FormFieldsName.TimeDeliveryFrom)?.value || '';
this.toInput = this.getFormControl('exportDetailsDto', FormFieldsName.TimeDeliveryTo)?.value || '';
}

private getFormControl(groupName: string, fieldName: string): AbstractControl | null {
const group = this.ordersForm.get(groupName);
return group ? group.get(fieldName) : null;
}

formAction(groupName: string, fieldName: string, data?: string): void {
Expand All @@ -113,8 +121,8 @@ export class UbsAdminSeveralOrdersPopUpComponent implements OnInit {
setExportTime(data: any): void {
this.formAction('exportDetailsDto', FormFieldsName.TimeDeliveryFrom, data.from);
this.formAction('exportDetailsDto', FormFieldsName.TimeDeliveryTo, data.to);
this.fromInput = this.ordersForm.get('exportDetailsDto').get(FormFieldsName.TimeDeliveryFrom).value;
this.toInput = this.ordersForm.get('exportDetailsDto').get(FormFieldsName.TimeDeliveryTo).value;
this.fromInput = this.getFormControl('exportDetailsDto', FormFieldsName.TimeDeliveryFrom)?.value || '';
this.toInput = this.getFormControl('exportDetailsDto', FormFieldsName.TimeDeliveryTo)?.value || '';
this.showTimePicker = false;
}

Expand All @@ -138,8 +146,8 @@ export class UbsAdminSeveralOrdersPopUpComponent implements OnInit {
return date ? date.toISOString().split('Z').join('') : '';
}

parseTimeToStr(dateStr: string) {
return dateStr ? formatDate(dateStr, 'HH:mm', this.currentLang) : '';
parseTimeToStr(dateStr: string, defaultTime: WorkingHours) {
return dateStr ? formatDate(dateStr, 'HH:mm', this.currentLang) : defaultTime;
}

getReceivingStationById(receivingStationId: number): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ export const toSelect: string[] = [
'21:30',
'22:00'
];

export enum WorkingHours {
FROM = '09:30',
TO = '17:30'
}
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export class UbsAdminTableComponent implements OnInit, AfterViewChecked, OnDestr
editCell(e: IEditCell): void {
if (this.allChecked) {
this.editAll(e);
} else if (this.idsToChange.length === 1) {
} else if (this.idsToChange.length === 0) {
this.editSingle(e);
} else {
this.editGroup(e);
Expand Down

0 comments on commit f386c36

Please sign in to comment.