diff --git a/angular/src/app/_components/image-upload/image-upload.component.html b/angular/src/app/_components/image-upload/image-upload.component.html index 9be071e..17c80d8 100644 --- a/angular/src/app/_components/image-upload/image-upload.component.html +++ b/angular/src/app/_components/image-upload/image-upload.component.html @@ -13,7 +13,7 @@ @if (imageUrl && showImage) { -
+
 
diff --git a/angular/src/app/_components/list/list.component.html b/angular/src/app/_components/list/list.component.html index e166b63..9674637 100644 --- a/angular/src/app/_components/list/list.component.html +++ b/angular/src/app/_components/list/list.component.html @@ -5,7 +5,7 @@ [hidePageSize]="hidePageSize" [displayOptions]="displayOptions" [defaultDisplayOption]="defaultDisplayOption" - [showCreateDataButton]="dataFormComponent !== undefined" + [showCreateDataButton]="showCreateButton && dataFormComponent !== undefined" (createNewData)="onCreateData()" (displayOptionChange)="onDisplayOptionChange($event)" > diff --git a/angular/src/app/_components/list/list.component.ts b/angular/src/app/_components/list/list.component.ts index 4028c61..8111f94 100644 --- a/angular/src/app/_components/list/list.component.ts +++ b/angular/src/app/_components/list/list.component.ts @@ -35,6 +35,7 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { @Input() public showDetailButton: boolean; @Input() public showEditButton: boolean; @Input() public showRemoveButton: boolean; + @Input() public showCreateButton: boolean; @Input() public showPosition: boolean; @Input() public showFilterBar: boolean; @Input() public listColDefinitions!: ListColDefinition[]; @@ -91,6 +92,7 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { this.showDetailButton = true; this.showEditButton = true; this.showRemoveButton = true; + this.showCreateButton = true; this.showFilterBar = true; this.filterExists = false; this.filterObj = {}; diff --git a/angular/src/app/_components/search-select/search-select.component.ts b/angular/src/app/_components/search-select/search-select.component.ts index 8155d23..f63b9a0 100644 --- a/angular/src/app/_components/search-select/search-select.component.ts +++ b/angular/src/app/_components/search-select/search-select.component.ts @@ -365,6 +365,78 @@ export class SearchSelectComponent implements OnInit, AfterViewInit { ]; } + public static getDefaultColDefTrips(subResource?: string): ListColDefinition[] { + return [ + { + name: 'pilotageReference', + text: 'trip.pilot_reference', + type: ListComponent.COLUMN_TYPE_TEXT_BOLD, + field: 'pilotageReference', + sortable: true, + filterType: FilterBarComponent.FILTER_TYPE_TEXT, + } as ListColDefinition, + { + name: 'vessel', + text: 'trip.vessel', + type: ListComponent.COLUMN_TYPE_TEXT, + subResource: 'vessel', + field: 'name', + sortable: true, + filterType: FilterBarComponent.FILTER_TYPE_TEXT, + } as ListColDefinition, + { + name: 'startLocation', + text: 'trip.start_location', + type: ListComponent.COLUMN_TYPE_TEXT, + subResource: 'startLocation', + field: 'name', + sortable: true, + filterType: FilterBarComponent.FILTER_TYPE_TEXT, + } as ListColDefinition, + { + name: 'endLocation', + text: 'trip.end_location', + type: ListComponent.COLUMN_TYPE_TEXT, + subResource: 'endLocation', + field: 'name', + sortable: true, + filterType: FilterBarComponent.FILTER_TYPE_TEXT, + } as ListColDefinition, + { + name: 'startDate', + text: 'trip.start_date', + type: ListComponent.COLUMN_TYPE_DATE, + field: 'startDate', + sortable: true, + filterType: FilterBarComponent.FILTER_TYPE_DATE, + } as ListColDefinition, + { + name: 'endDate', + text: 'trip.end_date', + type: ListComponent.COLUMN_TYPE_DATE, + field: 'endDate', + sortable: true, + filterType: FilterBarComponent.FILTER_TYPE_DATE, + } as ListColDefinition, + { + name: 'completed', + text: 'trip.completed', + type: ListComponent.COLUMN_TYPE_BOOLEAN, + field: 'completed', + sortable: true, + filterType: FilterBarComponent.FILTER_TYPE_BOOLEAN, + } as ListColDefinition, + { + name: 'createdAt', + text: 'common.created_at', + type: ListComponent.COLUMN_TYPE_DATE, + field: 'createdAt', + sortable: true, + filterType: FilterBarComponent.FILTER_TYPE_DATE, + } as ListColDefinition, + ]; + } + public static getDefaultColDefEvents(subResource?: string): ListColDefinition[] { return [ { diff --git a/angular/src/app/_views/trip/trip-detail/trip-detail.component.html b/angular/src/app/_views/trip/trip-detail/trip-detail.component.html index 49a1c54..3bf0ed6 100644 --- a/angular/src/app/_views/trip/trip-detail/trip-detail.component.html +++ b/angular/src/app/_views/trip/trip-detail/trip-detail.component.html @@ -6,55 +6,27 @@
- +
+ +
-

{{ 'trip.itinerary_locations' | translate }}

- +
-

{{ 'trip.assigned_users' | translate }}

-
-
-
- - - -
-
-
- -
-
- -
-
- -
-
- -
-
+
diff --git a/angular/src/app/_views/trip/trip-list/trip-list.component.ts b/angular/src/app/_views/trip/trip-list/trip-list.component.ts index 6f6b267..e082d4d 100644 --- a/angular/src/app/_views/trip/trip-list/trip-list.component.ts +++ b/angular/src/app/_views/trip/trip-list/trip-list.component.ts @@ -7,6 +7,7 @@ import {AppHelperService} from "@app/_helpers/app-helper.service"; import {FilterBarComponent} from "@app/_components/filter-bar/filter-bar.component"; import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; import {Observable} from "rxjs"; +import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; @Component({ selector: 'app-trip-list', @@ -24,75 +25,7 @@ export class TripListComponent { private tripService: TripService, protected appHelperService: AppHelperService, ) { - this.listColDefinitions = [ - { - name: 'pilotageReference', - text: 'trip.pilot_reference', - type: ListComponent.COLUMN_TYPE_TEXT_BOLD, - field: 'pilotageReference', - sortable: true, - filterType: FilterBarComponent.FILTER_TYPE_TEXT, - } as ListColDefinition, - { - name: 'vessel', - text: 'trip.vessel', - type: ListComponent.COLUMN_TYPE_TEXT, - subResource: 'vessel', - field: 'name', - sortable: true, - filterType: FilterBarComponent.FILTER_TYPE_TEXT, - } as ListColDefinition, - { - name: 'startLocation', - text: 'trip.start_location', - type: ListComponent.COLUMN_TYPE_TEXT, - subResource: 'startLocation', - field: 'name', - sortable: true, - filterType: FilterBarComponent.FILTER_TYPE_TEXT, - } as ListColDefinition, - { - name: 'endLocation', - text: 'trip.end_location', - type: ListComponent.COLUMN_TYPE_TEXT, - subResource: 'endLocation', - field: 'name', - sortable: true, - filterType: FilterBarComponent.FILTER_TYPE_TEXT, - } as ListColDefinition, - { - name: 'startDate', - text: 'trip.start_date', - type: ListComponent.COLUMN_TYPE_DATE, - field: 'startDate', - sortable: true, - filterType: FilterBarComponent.FILTER_TYPE_DATE, - } as ListColDefinition, - { - name: 'endDate', - text: 'trip.end_date', - type: ListComponent.COLUMN_TYPE_DATE, - field: 'endDate', - sortable: true, - filterType: FilterBarComponent.FILTER_TYPE_DATE, - } as ListColDefinition, - { - name: 'completed', - text: 'trip.completed', - type: ListComponent.COLUMN_TYPE_BOOLEAN, - field: 'completed', - sortable: true, - filterType: FilterBarComponent.FILTER_TYPE_BOOLEAN, - } as ListColDefinition, - { - name: 'createdAt', - text: 'common.created_at', - type: ListComponent.COLUMN_TYPE_DATE, - field: 'createdAt', - sortable: true, - filterType: FilterBarComponent.FILTER_TYPE_DATE, - } as ListColDefinition, - ]; + this.listColDefinitions = SearchSelectComponent.getDefaultColDefTrips(); } ngOnInit() { diff --git a/angular/src/app/_views/trip/trip-location-form/trip-location-form.component.html b/angular/src/app/_views/trip/trip-location-form/trip-location-form.component.html index ba6566a..493c7bd 100644 --- a/angular/src/app/_views/trip/trip-location-form/trip-location-form.component.html +++ b/angular/src/app/_views/trip/trip-location-form/trip-location-form.component.html @@ -51,7 +51,7 @@ @if (isEditMode()) { }
diff --git a/angular/src/app/_views/trip/trip-location-form/trip-location-form.component.ts b/angular/src/app/_views/trip/trip-location-form/trip-location-form.component.ts index d0d8c57..485ebc4 100644 --- a/angular/src/app/_views/trip/trip-location-form/trip-location-form.component.ts +++ b/angular/src/app/_views/trip/trip-location-form/trip-location-form.component.ts @@ -59,12 +59,14 @@ export class TripLocationFormComponent extends AbstractDataFormComponent @if (data !== undefined) {
- - - -
+ @if (trip) { +
{{ 'model.trip' | translate }}: {{ trip.pilotageReference }}
+ } @else { +
+ + + + +
+ } + @if (user) { +
{{ 'user_trip.pilot' | translate }}: {{ user.fullName }}
+ } @else { +
+ + + + +
+ } +
@@ -25,8 +58,7 @@
- - + { protected readonly userTripForm = userTripForm; + protected userColDefinitions: ListColDefinition[]; + protected tripColDefinitions: ListColDefinition[]; + protected trip?: TripJsonld; + protected user?: UserJsonld; constructor( - private userTripService: UserTripService, + protected userTripService: UserTripService, + protected userService: UserService, + protected tripService: TripService, imageUploadService: ImageUploadService, appHelperService: AppHelperService, translateService: TranslateService, @@ -28,18 +39,107 @@ export class UserTripFormComponent extends AbstractImageFormComponent this.userTripService.userTripsPost(data), (id: string | number, data: UserTripJsonld) => this.userTripService.userTripsIdPatch( id.toString(), this.appHelperService.convertJsonldToJson(data) - ), + ), (id: string | number) => userTripService.userTripsIdDelete(id.toString()), 'signatureIri', 'signature.dbId', translateService, router ); - this.redirectAfterDelete = '/' + ROUTE_USER_TRIPS; + this.redirectAfterDelete = '/' + ROUTE_USER_TRIPS + this.userColDefinitions = SearchSelectComponent.getDefaultColDefUsers(); + this.tripColDefinitions = SearchSelectComponent.getDefaultColDefTrips(); + } + + override ngOnInit() { + super.ngOnInit(); + + if (this.data?.trip && !this.trip) { + this.trip = this.data?.trip; + } + if (this.data?.user && !this.user) { + this.user = this.data?.user; + } + + if (this.trip && !this.data!.tripIri!) { + this.data!.tripIri = this.trip.id!; + this.form.get('tripIri')?.setValue(this.trip.id!); + } + if (this.user && !this.data!.userIri!) { + this.data!.userIri = this.user.id!; + this.form.get('userIri')?.setValue(this.user.id!); + } + if (!this.isEditMode()) { + this.form.get('completed')?.setValue(false); + this.form.get('approved')?.setValue(false); + } + } + + getUsers: ListGetDataFunctionType = ( + index: number, + pageSize: number, + term?: string, + ) => { + // Hole alle Benutzer mit isPilot=true + return this.userService.usersGetCollection( + index, + pageSize, + undefined, + undefined, + term, + '{"isPilot":true}' + ).pipe( + switchMap(usersResponse => { + // Wenn kein Trip vorhanden ist, gib alle Benutzer zurück + if (!this.trip?.id) { + return of(usersResponse); + } + + // Hole alle UserTrips für diesen Trip + return this.userTripService.userTripsGetCollection( + 1, + 100, + this.trip.id + ).pipe( + map(userTripsResponse => { + // Extrahiere die User-IDs aus den UserTrips + const usedUserIds = new Set( + userTripsResponse.member?.map( + (userTrip: UserTripJsonld) => userTrip.userIri + ) || [] + ); + + // Filtere die Benutzer, die noch nicht zugeordnet sind + if (usersResponse.member) { + usersResponse.member = usersResponse.member.filter( + (user: UserJsonld) => !usedUserIds.has(user.id!) + ); + // Aktualisiere die totalItems Anzahl + if (usersResponse.totalItems) { + usersResponse.totalItems = usersResponse.member.length; + } + } + + return usersResponse; + }) + ); + }) + ); + } + + getTrips: ListGetDataFunctionType = ( + index: number, + pageSize: number, + term?: string, + ) => { + return this.tripService.tripsGetCollection( + index, + pageSize, + ); } } \ No newline at end of file diff --git a/angular/src/app/_views/user-trip/user-trip-list/user-trip-list.component.html b/angular/src/app/_views/user-trip/user-trip-list/user-trip-list.component.html index d428640..658ab11 100644 --- a/angular/src/app/_views/user-trip/user-trip-list/user-trip-list.component.html +++ b/angular/src/app/_views/user-trip/user-trip-list/user-trip-list.component.html @@ -3,5 +3,10 @@ [listId]="'userTripList'" [getDataFunction]="getData" [listColDefinitions]="listColDefinitions" + [dataFormComponent]="userTripLocationFormComponent" + [dataFormComponentData]="dataFormComponentData" + [deleteItemFunction]="deleteItemFunction" + [showCreateButton]="showCreateButton" + [getCustomDetailLinkFunction]="getCustomDetailLink" >
\ No newline at end of file diff --git a/angular/src/app/_views/user-trip/user-trip-list/user-trip-list.component.ts b/angular/src/app/_views/user-trip/user-trip-list/user-trip-list.component.ts index b1f6ffc..73aa5b2 100644 --- a/angular/src/app/_views/user-trip/user-trip-list/user-trip-list.component.ts +++ b/angular/src/app/_views/user-trip/user-trip-list/user-trip-list.component.ts @@ -1,10 +1,13 @@ import {Component, Input, ViewChild} from '@angular/core'; import {ListComponent} from "@app/_components/list/list.component"; import {ListColDefinition} from "@app/_components/list/list-col-definition"; -import {UserJsonld, UserTripService} from "@app/core/api/v1"; +import {LocationJsonld, TripJsonld, UserJsonld, UserTripService} from "@app/core/api/v1"; import {AppHelperService} from "@app/_helpers/app-helper.service"; import {FilterBarComponent} from "@app/_components/filter-bar/filter-bar.component"; import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; +import {Observable} from "rxjs"; +import {UserTripFormComponent} from "@app/_views/user-trip/user-trip-form/user-trip-form.component"; +import {ROUTE_LOCATIONS, ROUTE_USER_TRIPS} from "@app/app-routing.module"; @Component({ selector: 'app-user-trip-list', @@ -13,14 +16,19 @@ import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-funct }) export class UserTripListComponent { @Input() public user?: UserJsonld; + @Input() public trip?: TripJsonld; + @Input() public showCreateButton: boolean; @ViewChild("listComponent", {static: false}) listComponent!: ListComponent; + protected readonly userTripLocationFormComponent = UserTripFormComponent; protected listColDefinitions!: ListColDefinition[]; + protected dataFormComponentData: any; constructor( private userTripService: UserTripService, protected appHelperService: AppHelperService, ) { + this.showCreateButton = false; this.listColDefinitions = [ { name: 'pilotageReference', @@ -102,7 +110,13 @@ export class UserTripListComponent { } ngOnInit() { - + this.dataFormComponentData = {}; + if (this.trip) { + this.dataFormComponentData['trip'] = this.trip; + } + if (this.user) { + this.dataFormComponentData['user'] = this.user; + } } ngAfterViewInit(): void { @@ -117,13 +131,20 @@ export class UserTripListComponent { return this.userTripService.userTripsGetCollection( index, pageSize, - undefined, + this.trip ? this.trip.id : undefined, undefined, this.user ? this.user.id : undefined, undefined, - // term ? Number(term) : undefined, this.listComponent.getFilterJsonString(), this.listComponent.getSortingJsonString() ); } + + get deleteItemFunction(): (id: string) => Observable { + return (id: string) => this.userTripService.userTripsIdDelete(id); + } + + getCustomDetailLink(element: LocationJsonld) { + return ROUTE_USER_TRIPS + '/' + this.appHelperService.extractId(element?.id); + } } diff --git a/angular/src/assets/i18n/en.json b/angular/src/assets/i18n/en.json index b8516da..b8fbb79 100644 --- a/angular/src/assets/i18n/en.json +++ b/angular/src/assets/i18n/en.json @@ -83,7 +83,7 @@ }, "trip": { "add_itinerary_location": "Add itinerary location", - "assigned_users": "Assigned Pilots", + "pilotage": "Pilotage", "captain_name": "Captain name", "completed": "Completed", "customer_reference": "Customer reference", @@ -116,6 +116,7 @@ "completed_at": "Completed at", "event_date": "Event date", "events": "Events", + "pilot": "Pilot", "signature": "Signature Image", "view": "Pilotage" },