@ -4,12 +4,6 @@ import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { BikesService , CargoBikeResult } from 'src/app/services/bikes.service' ;
import { BikesService , CargoBikeResult } from 'src/app/services/bikes.service' ;
import { flatten } from 'src/app/helperFunctions/flattenObject' ;
import { flatten } from 'src/app/helperFunctions/flattenObject' ;
import { deepen } from 'src/app/helperFunctions/deepenObject' ;
import { deepen } from 'src/app/helperFunctions/deepenObject' ;
import { isPartOfGraphQLDoc } from 'src/app/helperFunctions/isPartOfGraphQLFunction' ;
import { filter } from 'graphql-anywhere' ;
import {
CargoBikeFieldsMutableFragmentDoc ,
CargoBikeUpdateInput ,
} from 'src/generated/graphql' ;
import { SchemaService } from 'src/app/services/schema.service' ;
import { SchemaService } from 'src/app/services/schema.service' ;
import { logArrayInColumnInfoForm } from 'src/app/helperFunctions/logArrayInColumnInfoForm' ;
import { logArrayInColumnInfoForm } from 'src/app/helperFunctions/logArrayInColumnInfoForm' ;
@ -27,6 +21,8 @@ export class BikesComponent {
columnInfo : {
columnInfo : {
name : string ;
name : string ;
header : string ;
header : string ;
acceptedForCreation? : boolean ;
requiredForCreation? : boolean ;
sticky? : boolean ;
sticky? : boolean ;
readonly ? : boolean ;
readonly ? : boolean ;
type ? : string ;
type ? : string ;
@ -41,9 +37,18 @@ export class BikesComponent {
{ name : 'insuranceData.name' , header : 'Versicherer' } ,
{ name : 'insuranceData.name' , header : 'Versicherer' } ,
{ name : 'insuranceData.benefactor' , header : 'Kostenträger' } ,
{ name : 'insuranceData.benefactor' , header : 'Kostenträger' } ,
{ name : 'insuranceData.noPnP' , header : 'Nr. P&P' } ,
{ name : 'insuranceData.noPnP' , header : 'Nr. P&P' } ,
{ name : 'insuranceData.maintenanceResponsible' , header : 'Wartung zuständig' } ,
{
{ name : 'insuranceData.maintenanceBenefactor' , header : 'Wartung Kostenträger' } ,
name : 'insuranceData.maintenanceResponsible' ,
{ name : 'insuranceData.maintenanceAgreement' , header : 'Wartungsvereinbarung' } ,
header : 'Wartung zuständig' ,
} ,
{
name : 'insuranceData.maintenanceBenefactor' ,
header : 'Wartung Kostenträger' ,
} ,
{
name : 'insuranceData.maintenanceAgreement' ,
header : 'Wartungsvereinbarung' ,
} ,
{ name : 'insuranceData.projectAllowance' , header : 'Projektzuschuss' } ,
{ name : 'insuranceData.projectAllowance' , header : 'Projektzuschuss' } ,
{ name : 'insuranceData.notes' , header : 'Sonstiges' } ,
{ name : 'insuranceData.notes' , header : 'Sonstiges' } ,
{ name : 'dimensionsAndLoad.bikeLength' , header : 'Länge' } ,
{ name : 'dimensionsAndLoad.bikeLength' , header : 'Länge' } ,
@ -56,7 +61,10 @@ export class BikesComponent {
{ name : 'dimensionsAndLoad.hasCoverBox' , header : 'Boxabdeckung j/n' } ,
{ name : 'dimensionsAndLoad.hasCoverBox' , header : 'Boxabdeckung j/n' } ,
{ name : 'dimensionsAndLoad.lockable' , header : 'Box abschließbar' } ,
{ name : 'dimensionsAndLoad.lockable' , header : 'Box abschließbar' } ,
{ name : 'dimensionsAndLoad.maxWeightBox' , header : 'max Zuladung Box' } ,
{ name : 'dimensionsAndLoad.maxWeightBox' , header : 'max Zuladung Box' } ,
{ name : 'dimensionsAndLoad.maxWeightLuggageRack' , header : 'max Zuladung Gepäckträger' } ,
{
name : 'dimensionsAndLoad.maxWeightLuggageRack' ,
header : 'max Zuladung Gepäckträger' ,
} ,
{ name : 'dimensionsAndLoad.maxWeightTotal' , header : 'max Gesamtgewicht' } ,
{ name : 'dimensionsAndLoad.maxWeightTotal' , header : 'max Gesamtgewicht' } ,
{ name : 'numberOfChildren' , header : 'Anzahl Kinder' } ,
{ name : 'numberOfChildren' , header : 'Anzahl Kinder' } ,
{ name : 'numberOfWheels' , header : 'Anzahl Räder' } ,
{ name : 'numberOfWheels' , header : 'Anzahl Räder' } ,
@ -64,8 +72,14 @@ export class BikesComponent {
{ name : 'forChildren' , header : 'für Kinder j/n' } ,
{ name : 'forChildren' , header : 'für Kinder j/n' } ,
{ name : 'security.frameNumber' , header : 'Rahmennummer' } ,
{ name : 'security.frameNumber' , header : 'Rahmennummer' } ,
{ name : 'security.adfcCoding' , header : 'ADFC Codierung' } ,
{ name : 'security.adfcCoding' , header : 'ADFC Codierung' } ,
{ name : 'security.keyNumberAXAChain' , header : 'Schlüsselnrummer Rahmenschloss' } ,
{
{ name : 'security.keyNumberFrameLock' , header : 'Schlüsselnrummer AXA-Kette' } ,
name : 'security.keyNumberAXAChain' ,
header : 'Schlüsselnrummer Rahmenschloss' ,
} ,
{
name : 'security.keyNumberFrameLock' ,
header : 'Schlüsselnrummer AXA-Kette' ,
} ,
{ name : 'security.policeCoding' , header : 'Polizei Codierung' } ,
{ name : 'security.policeCoding' , header : 'Polizei Codierung' } ,
{ name : 'technicalEquipment.bicycleShift' , header : 'Schaltung' } ,
{ name : 'technicalEquipment.bicycleShift' , header : 'Schaltung' } ,
{ name : 'technicalEquipment.isEBike' , header : 'E-Bike j/n' } ,
{ name : 'technicalEquipment.isEBike' , header : 'E-Bike j/n' } ,
@ -92,6 +106,10 @@ export class BikesComponent {
{ name : 'lendingStation.address.zip' , header : '' } ,
{ name : 'lendingStation.address.zip' , header : '' } ,
] ;
] ;
tableDataGQLType : string = 'CargoBike' ;
tableDataGQLCreateInputType : string = 'CargoBikeCreateInput' ;
tableDataGQLUpdateInputType : string = 'CargoBikeUpdateInput' ;
@ViewChild ( MatPaginator ) paginator : MatPaginator ;
@ViewChild ( MatPaginator ) paginator : MatPaginator ;
@ViewChild ( MatSort ) sort : MatSort ;
@ViewChild ( MatSort ) sort : MatSort ;
@ -116,9 +134,15 @@ export class BikesComponent {
) { }
) { }
ngAfterViewInit() {
ngAfterViewInit() {
this . addTypesToColumnInfo ( ) ;
this . addColumnPropertiesFromGQLSchemaToColumnInfo ( ) ;
this . addReadOnlyPropertiesToColumnInfo ( ) ;
this . data . paginator = this . paginator ;
this . data . paginator = this . paginator ;
this . data . sortingDataAccessor = ( item , columnName ) = > {
if ( typeof item [ columnName ] === 'string' ) {
return item [ columnName ] . toLocaleLowerCase ( ) ;
}
return item [ columnName ] ;
}
this . data . sort = this . sort ;
this . data . sort = this . sort ;
this . columnInfo . forEach ( ( column ) = >
this . columnInfo . forEach ( ( column ) = >
@ -162,19 +186,28 @@ export class BikesComponent {
clearInterval ( this . relockingInterval ) ;
clearInterval ( this . relockingInterval ) ;
}
}
add Types ToColumnInfo() {
add ColumnPropertiesFromGQLSchema ToColumnInfo() {
for ( const column of this . columnInfo ) {
for ( const column of this . columnInfo ) {
if ( ! column . type ) {
const typeInformation = this . schemaService . getTypeInformation (
column . type = this . getType ( column . name ) ;
this . tableDataGQLType ,
}
column . name
) ;
column . type = column . type || typeInformation . type ;
}
}
}
addReadOnlyPropertiesToColumnInfo() {
for ( const column of this . columnInfo ) {
for ( const column of this . columnInfo ) {
if ( ! column . readonly ) {
const typeInformation = this . schemaService . getTypeInformation (
column . readonly = this . isReadonly ( column . name ) ;
this . tableDataGQLUpdateInputType ,
}
column . name
) ;
column . readonly = column . readonly || ! typeInformation . isPartOfType ;
}
for ( const column of this . columnInfo ) {
const typeInformation = this . schemaService . getTypeInformation (
this . tableDataGQLCreateInputType ,
column . name
) ;
column . requiredForCreation = typeInformation . isRequired ;
column . acceptedForCreation = typeInformation . isPartOfType ;
}
}
}
}
@ -185,20 +218,6 @@ export class BikesComponent {
) ;
) ;
}
}
getType ( propertyName : string ) {
return this . schemaService . getPropertyTypeFromSchema (
'CargoBike' ,
propertyName
) ;
}
isReadonly ( propertyName : string ) {
return (
this . columnInfo . find ( ( column ) = > column . name === propertyName ) . readonly ||
! isPartOfGraphQLDoc ( propertyName , CargoBikeFieldsMutableFragmentDoc )
) ;
}
isStickyColumn ( propertyName : string ) {
isStickyColumn ( propertyName : string ) {
return (
return (
this . columnInfo . find ( ( column ) = > column . name === propertyName ) ? . sticky ||
this . columnInfo . find ( ( column ) = > column . name === propertyName ) ? . sticky ||
@ -210,18 +229,50 @@ export class BikesComponent {
return this . loadingRowIds . includes ( id ) ;
return this . loadingRowIds . includes ( id ) ;
}
}
validityChange ( row : any , columnName : string , isValid : Event ) {
if ( ! row . FieldsValidity ) {
row [ 'FieldsValidity' ] = { } ;
}
row [ 'FieldsValidity' ] [ columnName ] = isValid ;
}
countUnvalidFields ( row : any ) {
let unvalidFieldsCount = 0 ;
if ( ! row . FieldsValidity ) {
return 99 ;
}
for ( const prop in row . FieldsValidity ) {
if ( ! row . FieldsValidity [ prop ] ) {
unvalidFieldsCount ++ ;
}
}
return unvalidFieldsCount ;
}
reloadTable() {
reloadTable() {
this . reloadingTable = true ;
this . reloadingTable = true ;
this . bikesService . loadBikes ( ) ;
this . bikesService . loadBikes ( ) ;
}
}
addEmptyRow() {
this . data . data = [ { newObject : true } , . . . this . data . data ] ;
}
create ( row : any ) {
const newBike = this . schemaService . filterObject (
this . tableDataGQLCreateInputType ,
deepen ( row )
) ;
this . bikesService . createBike ( { bike : newBike } ) ;
}
edit ( row : CargoBikeResult ) {
edit ( row : CargoBikeResult ) {
this . bikesService . lockBike ( { id : row.id } ) ;
this . bikesService . lockBike ( { id : row.id } ) ;
}
}
save ( row : CargoBikeResult ) {
save ( row : CargoBikeResult ) {
const deepenRow : CargoBikeUpdateInput = filter (
const deepenRow = this . schemaService . filterObject (
CargoBikeFieldsMutableFragmentDoc ,
this . tableDataGQLUpdateInputType ,
deepen ( row )
deepen ( row )
) ;
) ;
this . bikesService . updateBike ( { bike : deepenRow } ) ;
this . bikesService . updateBike ( { bike : deepenRow } ) ;