Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] #7860 set default working hours #3483

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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,8 @@ export class UbsAdminSeveralOrdersPopUpComponent implements OnInit {

showTimePickerClick(): void {
this.showTimePicker = true;
this.fromInput = this.ordersForm.get('exportDetailsDto').get(FormFieldsName.TimeDeliveryFrom).value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated code in setExportTime and showTimePickerClick can be optimized to prevent duplication.
The chain of invocation of get() can lead to a potential null or undefined value, which can cause runtime errors

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

this.toInput = this.ordersForm.get('exportDetailsDto').get(FormFieldsName.TimeDeliveryTo).value;
}

formAction(groupName: string, fieldName: string, data?: string): void {
Expand Down Expand Up @@ -138,8 +141,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 @@ -110,7 +110,6 @@ export class UbsAdminTableComponent implements OnInit, AfterViewChecked, OnDestr
cancellationComment: string;
@ViewChild(MatTable, { read: ElementRef }) private matTableRef: ElementRef;
defaultColumnWidth = 120; // In px
minColumnWidth = 100;
columnsWidthPreference: Map<string, number>;
restoredFilters = [];
isRestoredFilters = false;
Expand Down Expand Up @@ -657,7 +656,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
Loading