diff --git a/src/app/components/table/table.component.html b/src/app/components/table/table.component.html index d151df6..fd5c353 100644 --- a/src/app/components/table/table.component.html +++ b/src/app/components/table/table.component.html @@ -184,6 +184,9 @@ (element.newObject && column.required) || (element.isLockedByMe && column.required) " + (validityChange)=" + validityChange(element, column.dataPath, $event) + " [(from)]="element[column.dataPath + '.from']" [(to)]="element[column.dataPath + '.to']" > diff --git a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.html b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.html index 0e27bdc..40e482a 100644 --- a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.html +++ b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.html @@ -1,25 +1,38 @@ - - {{label}} - - - - - - - - -
{{toLocaleDate(from)}} bis {{toLocaleDate(to)}}
-
+
+ {{ label }} + + + + + + bis + + + + + + +
+ +
+ {{ toLocaleDate(from) }} bis {{ toLocaleDate(to) }} +
+
diff --git a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.scss b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.scss index dbc6e25..a0d4828 100644 --- a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.scss +++ b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.scss @@ -1,5 +1,9 @@ -.date-range-input { - min-width: 11em; +.dateRange-wrapper { + display: flex; + align-items: center; + .spacer-string { + margin: 0 0.5em; + } } .date-string { min-width: 10em; diff --git a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.ts b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.ts index 90c46ba..e88f119 100644 --- a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.ts +++ b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.ts @@ -12,7 +12,7 @@ import { FormControl, FormGroup, Validators } from '@angular/forms'; @Component({ selector: 'app-date-range-cell', templateUrl: './date-range-cell.component.html', - styleUrls: ['./date-range-cell.component.scss'] + styleUrls: ['./date-range-cell.component.scss'], }) export class DateRangeCellComponent implements OnInit { @Input() @@ -26,7 +26,7 @@ export class DateRangeCellComponent implements OnInit { @Input() editable = false; - + @Input() required = false; @Input() @@ -34,19 +34,58 @@ export class DateRangeCellComponent implements OnInit { @Output() validityChange = new EventEmitter(); isValid = true; + dateRangeGroup: FormGroup; + constructor(private cdr: ChangeDetectorRef, public datepipe: DatePipe) {} ngOnInit() { + this.dateRangeGroup = new FormGroup({ + from: new FormControl(), + to: new FormControl(), + }); + this.dateRangeGroup.controls['from'].markAsTouched(); + this.dateRangeGroup.controls['to'].markAsTouched(); + + if (this.editable) { + setTimeout(()=>this.checkIfDateRangeIsValid()); + } } startDateChange(event): void { this.from = this.transformDate(event.value); this.fromChange.emit(this.from); + this.checkIfDateRangeIsValid(); } endDateChange(event) { this.to = this.transformDate(event.value); this.toChange.emit(this.to); + this.checkIfDateRangeIsValid(); + } + + checkIfDateRangeIsValid() { + if (this.required && this.from == null) { + this.setRangeError(true); + return; + } + if (this.to == null || this.from == null) { + this.setRangeError(false); + return; + } + const isValid = new Date(this.to) >= new Date(this.from); + this.setRangeError(!isValid); + } + + setRangeError(error: boolean): void { + console.log("error", error) + this.validityChange.emit(!error); + if (error) { + this.dateRangeGroup.controls['from'].setErrors({ rangeError: true }); + this.dateRangeGroup.controls['to'].setErrors({ rangeError: true }); + } else { + this.dateRangeGroup.controls['from'].setErrors(null); + this.dateRangeGroup.controls['to'].setErrors(null); + } } transformDate(date) { @@ -54,10 +93,9 @@ export class DateRangeCellComponent implements OnInit { } toLocaleDate(date: string): string { - if (date == "") { - return ""; + if (date == '') { + return ''; } return new Date(date).toLocaleDateString(); } - } diff --git a/src/app/graphqlOperations/fragments/equipment.graphql b/src/app/graphqlOperations/fragments/equipment.graphql index a777431..b2579b2 100644 --- a/src/app/graphqlOperations/fragments/equipment.graphql +++ b/src/app/graphqlOperations/fragments/equipment.graphql @@ -3,6 +3,9 @@ fragment EquipmentFieldsForBikePage on Equipment { serialNo title description + cargoBike { + name + } } fragment EquipmentFieldsForTable on Equipment { diff --git a/src/app/pages/dataPages/bike/bike.component.ts b/src/app/pages/dataPages/bike/bike.component.ts index 8ed87ea..3092149 100644 --- a/src/app/pages/dataPages/bike/bike.component.ts +++ b/src/app/pages/dataPages/bike/bike.component.ts @@ -211,7 +211,7 @@ export class BikeComponent implements OnInit { { dataPath: 'description', translation: 'Beschreibung' }, ], nameToShowInSelection: (element) => { - return element.title + ' (' + element.serialNo + ')'; + return element.title + ' (' + element.serialNo + ')' + (element.cargoBike ? " [aktuell Teil von "+element.cargoBike.name+']' : ''); }, linkToTable: (element) => '/table/equipment', linkToTableParams: (bike) => { diff --git a/src/generated/graphql.ts b/src/generated/graphql.ts index 16ecf26..2852913 100644 --- a/src/generated/graphql.ts +++ b/src/generated/graphql.ts @@ -2071,7 +2071,7 @@ export type EngagementFieldsForBikePageFragment = { __typename?: 'Engagement', i export type EngagementTypeFieldsFragment = { __typename?: 'EngagementType', id: string, name: string, description: string, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe, lockedUntil?: Maybe }; -export type EquipmentFieldsForBikePageFragment = { __typename?: 'Equipment', id: string, serialNo: string, title: string, description?: Maybe }; +export type EquipmentFieldsForBikePageFragment = { __typename?: 'Equipment', id: string, serialNo: string, title: string, description?: Maybe, cargoBike?: Maybe<{ __typename?: 'CargoBike', name: string }> }; export type EquipmentFieldsForTableFragment = { __typename?: 'Equipment', id: string, serialNo: string, title: string, description?: Maybe, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe, lockedUntil?: Maybe, cargoBike?: Maybe<{ __typename?: 'CargoBike', id: string, name: string }> }; @@ -2491,6 +2491,9 @@ export const EquipmentFieldsForBikePageFragmentDoc = gql` serialNo title description + cargoBike { + name + } } `; export const EquipmentTypeFieldsFragmentDoc = gql`