| @@ -21,7 +21,7 @@ | |||||
| [getDataFunction]="getZones" | [getDataFunction]="getZones" | ||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [listColDefinitions]="zoneColDefinitions" | [listColDefinitions]="zoneColDefinitions" | ||||
| [dataSet]="data?.zoneIri" | |||||
| [dataSet]="data?.zone" | |||||
| > | > | ||||
| </app-search-select> | </app-search-select> | ||||
| <input id="zoneIri" type="hidden" formControlName="zoneIri"/> | <input id="zoneIri" type="hidden" formControlName="zoneIri"/> | ||||
| @@ -9,6 +9,7 @@ import { TranslateService } from "@ngx-translate/core"; | |||||
| import { Router } from "@angular/router"; | import { Router } from "@angular/router"; | ||||
| import { ROUTE_BASE_DATA } from "@app/app-routing.module"; | import { ROUTE_BASE_DATA } from "@app/app-routing.module"; | ||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | import {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| import {Validators} from "@angular/forms"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-location-form', | selector: 'app-location-form', | ||||
| @@ -42,6 +43,17 @@ export class LocationFormComponent extends AbstractDataFormComponent<LocationJso | |||||
| this.zoneColDefinitions = SearchSelectComponent.getDefaultColDefZones(); | this.zoneColDefinitions = SearchSelectComponent.getDefaultColDefZones(); | ||||
| } | } | ||||
| override ngOnInit(): void { | |||||
| super.ngOnInit(); | |||||
| // Wenn wir einen neuen Benutzer erstellen, initialisiere active mit false | |||||
| if (!this.isEditMode()) { | |||||
| this.form.get('isZone')?.setValue(false); | |||||
| this.form.get('isPlace')?.setValue(false); | |||||
| this.form.get('isPort')?.setValue(false); | |||||
| } | |||||
| } | |||||
| getZones: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | getZones: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | ||||
| return this.zoneService.zonesGetCollection(index, pageSize, term); | return this.zoneService.zonesGetCollection(index, pageSize, term); | ||||
| } | } | ||||
| @@ -28,7 +28,7 @@ | |||||
| </button> | </button> | ||||
| @if (isEditMode()) { | @if (isEditMode()) { | ||||
| <button type="button" class="spt-button spt-button-danger" (click)="onDelete()"> | |||||
| <button type="button" class="ms-3 btn btn-primary" (click)="onDelete()"> | |||||
| {{ 'basic.delete' | translate }} {{ 'model.shipping_company' | translate }} | {{ 'basic.delete' | translate }} {{ 'model.shipping_company' | translate }} | ||||
| </button> | </button> | ||||
| } | } | ||||
| @@ -22,7 +22,7 @@ | |||||
| <div class="col-12 col-md-4 mb-3"> | <div class="col-12 col-md-4 mb-3"> | ||||
| <label [for]="'location_' + i" class="form-label">Location*:</label> | <label [for]="'location_' + i" class="form-label">Location*:</label> | ||||
| <app-search-select | <app-search-select | ||||
| [formId]="'locationIri'" | |||||
| [formId]="'location'" | |||||
| [formLabelLangKey]="'model.location'" | [formLabelLangKey]="'model.location'" | ||||
| [documentForm]="locationForms[i]" | [documentForm]="locationForms[i]" | ||||
| [getDataFunction]="getLocations" | [getDataFunction]="getLocations" | ||||
| @@ -83,8 +83,8 @@ | |||||
| </div> | </div> | ||||
| <div class="mt-4"> | <div class="mt-4"> | ||||
| <button type="button" class="btn btn-success" (click)="saveAllTripLocations()"> | |||||
| {{ 'trip.save_itinerary' | translate }} | |||||
| <button type="button" class="btn btn-primary" (click)="saveAllTripLocations()"> | |||||
| {{ 'basic.save' | translate }} | |||||
| </button> | </button> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| @@ -305,6 +305,7 @@ export class TripDetailComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| saveAllTripLocations() { | saveAllTripLocations() { | ||||
| // First update the location objects in our tripLocations array | // First update the location objects in our tripLocations array | ||||
| this.tripLocations.forEach((tripLocation, index) => { | this.tripLocations.forEach((tripLocation, index) => { | ||||
| const locationFormValue = this.locationForms[index].get('location')?.value; | const locationFormValue = this.locationForms[index].get('location')?.value; | ||||
| @@ -322,7 +323,7 @@ export class TripDetailComponent implements OnInit, AfterViewInit { | |||||
| }); | }); | ||||
| // Filter out trip locations that have no location set | // Filter out trip locations that have no location set | ||||
| const validTripLocations = this.tripLocations.filter(tl => tl.location); | |||||
| const validTripLocations = this.tripLocations.filter(tl => tl.locationIri); | |||||
| if (validTripLocations.length === 0) { | if (validTripLocations.length === 0) { | ||||
| return; | return; | ||||
| @@ -96,7 +96,7 @@ | |||||
| </div> | </div> | ||||
| <div class="mt-4"> | <div class="mt-4"> | ||||
| <button type="button" class="btn btn-success" (click)="saveAllUserTripEvents()"> | |||||
| <button type="button" class="btn btn-primary" (click)="saveAllUserTripEvents()"> | |||||
| {{ 'basic.save' | translate }} | {{ 'basic.save' | translate }} | ||||
| </button> | </button> | ||||
| </div> | </div> | ||||
| @@ -31,7 +31,7 @@ | |||||
| [getDataFunction]="getShippingCompanies" | [getDataFunction]="getShippingCompanies" | ||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [listColDefinitions]="shippingCompanyColDefinitions" | [listColDefinitions]="shippingCompanyColDefinitions" | ||||
| [dataSet]="data?.companyIri"> | |||||
| [dataSet]="data?.company"> | |||||
| </app-search-select> | </app-search-select> | ||||
| <input id="companyIri" type="hidden" formControlName="companyIri"/> | <input id="companyIri" type="hidden" formControlName="companyIri"/> | ||||
| </div> | </div> | ||||
| @@ -42,7 +42,7 @@ | |||||
| </button> | </button> | ||||
| @if (isEditMode()) { | @if (isEditMode()) { | ||||
| <button type="button" class="spt-button spt-button-danger" (click)="onDelete()"> | |||||
| <button type="button" class="ms-3 btn btn-primary" (click)="onDelete()"> | |||||
| {{ 'basic.delete' | translate }} {{ 'model.vessel' | translate }} | {{ 'basic.delete' | translate }} {{ 'model.vessel' | translate }} | ||||
| </button> | </button> | ||||
| } | } | ||||
| @@ -15,7 +15,7 @@ | |||||
| </button> | </button> | ||||
| @if (isEditMode()) { | @if (isEditMode()) { | ||||
| <button type="button" class="spt-button spt-button-danger" (click)="onDelete()"> | |||||
| <button type="button" class="ms-3 btn btn-primary" (click)="onDelete()"> | |||||
| {{ 'basic.delete' | translate }} {{ 'model.zone' | translate }} | {{ 'basic.delete' | translate }} {{ 'model.zone' | translate }} | ||||
| </button> | </button> | ||||
| } | } | ||||
| @@ -33,13 +33,13 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||||
| security: 'is_granted("ROLE_USER")' | security: 'is_granted("ROLE_USER")' | ||||
| ), | ), | ||||
| new Post( | new Post( | ||||
| security: 'is_granted("ROLE_ADMIN")' | |||||
| security: 'is_granted("ROLE_USER")' | |||||
| ), | ), | ||||
| new Patch( | new Patch( | ||||
| security: 'is_granted("ROLE_ADMIN")' | |||||
| security: 'is_granted("ROLE_USER")' | |||||
| ), | ), | ||||
| new Delete( | new Delete( | ||||
| security: 'is_granted("ROLE_ADMIN")' | |||||
| security: 'is_granted("ROLE_USER")' | |||||
| ) | ) | ||||
| ], | ], | ||||
| order: ['date' => 'ASC'], | order: ['date' => 'ASC'], | ||||
| @@ -12,6 +12,7 @@ use Symfony\Component\Security\Core\User\UserInterface; | |||||
| class User implements UserInterface, PasswordAuthenticatedUserInterface | class User implements UserInterface, PasswordAuthenticatedUserInterface | ||||
| { | { | ||||
| public const ROLE_ADMIN = "ROLE_ADMIN"; | public const ROLE_ADMIN = "ROLE_ADMIN"; | ||||
| public const ROLE_USER = "ROLE_USER"; | |||||
| #[ORM\Id] | #[ORM\Id] | ||||
| #[ORM\GeneratedValue] | #[ORM\GeneratedValue] | ||||
| @@ -32,11 +32,11 @@ class LocationApiToEntityMapper implements MapperInterface | |||||
| return $entity; | return $entity; | ||||
| } | } | ||||
| if (!$dto->zone) { | |||||
| if (!$dto->zoneIri) { | |||||
| throw new \Exception('Zone is required for new locations'); | throw new \Exception('Zone is required for new locations'); | ||||
| } | } | ||||
| $zone = $this->zoneRepository->find($dto->zone->id); | |||||
| $zone = $this->zoneRepository->find($dto->zoneIri->id); | |||||
| if (!$zone) { | if (!$zone) { | ||||
| throw new \Exception('Zone not found'); | throw new \Exception('Zone not found'); | ||||
| } | } | ||||
| @@ -57,8 +57,8 @@ class LocationApiToEntityMapper implements MapperInterface | |||||
| $entity->setIsPlace($dto->isPlace); | $entity->setIsPlace($dto->isPlace); | ||||
| $entity->setIsPort($dto->isPort); | $entity->setIsPort($dto->isPort); | ||||
| if ($dto->zone) { | |||||
| $zone = $this->zoneRepository->find($dto->zone->id); | |||||
| if ($dto->zoneIri) { | |||||
| $zone = $this->zoneRepository->find($dto->zoneIri->id); | |||||
| if (!$zone) { | if (!$zone) { | ||||
| throw new \Exception('Zone not found'); | throw new \Exception('Zone not found'); | ||||
| } | } | ||||
| @@ -35,24 +35,24 @@ class TripApiToEntityMapper implements MapperInterface | |||||
| } | } | ||||
| // For new trips, we need the vessel and locations | // For new trips, we need the vessel and locations | ||||
| if (!$dto->vessel?->id) { | |||||
| if (!$dto->vesselIri->id) { | |||||
| throw new \Exception('Vessel is required for new trips'); | throw new \Exception('Vessel is required for new trips'); | ||||
| } | } | ||||
| if (!$dto->startLocation?->id || !$dto->endLocation?->id) { | |||||
| if (!$dto->startLocationIri->id || !$dto->endLocationIri->id) { | |||||
| throw new \Exception('Start and end locations are required for new trips'); | throw new \Exception('Start and end locations are required for new trips'); | ||||
| } | } | ||||
| $vessel = $this->vesselRepository->find($dto->vessel->id); | |||||
| $vessel = $this->vesselRepository->find($dto->vesselIri->id); | |||||
| if (!$vessel) { | if (!$vessel) { | ||||
| throw new \Exception('Vessel not found'); | throw new \Exception('Vessel not found'); | ||||
| } | } | ||||
| $startLocation = $this->locationRepository->find($dto->startLocation->id); | |||||
| $startLocation = $this->locationRepository->find($dto->startLocationIri->id); | |||||
| if (!$startLocation) { | if (!$startLocation) { | ||||
| throw new \Exception('Start location not found'); | throw new \Exception('Start location not found'); | ||||
| } | } | ||||
| $endLocation = $this->locationRepository->find($dto->endLocation->id); | |||||
| $endLocation = $this->locationRepository->find($dto->endLocationIri->id); | |||||
| if (!$endLocation) { | if (!$endLocation) { | ||||
| throw new \Exception('End location not found'); | throw new \Exception('End location not found'); | ||||
| } | } | ||||
| @@ -79,6 +79,31 @@ class TripApiToEntityMapper implements MapperInterface | |||||
| $entity->setEndDate($dto->endDate); | $entity->setEndDate($dto->endDate); | ||||
| $entity->setNote($dto->note); | $entity->setNote($dto->note); | ||||
| if ($dto->vesselIri->id) { | |||||
| $vessel = $this->vesselRepository->find($dto->vesselIri->id); | |||||
| if (!$vessel) { | |||||
| throw new \Exception('Vessel not found'); | |||||
| } | |||||
| $entity->setVessel($vessel); | |||||
| } | |||||
| if ($dto->startLocationIri->id) { | |||||
| $startLocation = $this->locationRepository->find($dto->startLocationIri->id); | |||||
| if (!$startLocation) { | |||||
| throw new \Exception('Start location not found'); | |||||
| } | |||||
| $entity->setStartLocation($startLocation); | |||||
| } | |||||
| if ($dto->endLocationIri->id) { | |||||
| $endLocation = $this->locationRepository->find($dto->endLocationIri->id); | |||||
| if (!$endLocation) { | |||||
| throw new \Exception('End location not found'); | |||||
| } | |||||
| $entity->setEndLocation($endLocation); | |||||
| } | |||||
| return $entity; | return $entity; | ||||
| } | } | ||||
| } | } | ||||
| @@ -35,16 +35,16 @@ class TripLocationApiToEntityMapper implements MapperInterface | |||||
| } | } | ||||
| // For new trip locations, we need trip and location | // For new trip locations, we need trip and location | ||||
| if (!$dto->trip?->id || !$dto->location?->id) { | |||||
| if (!$dto->tripIri->id || !$dto->locationIri->id) { | |||||
| throw new \Exception('Trip and Location are required for new trip locations'); | throw new \Exception('Trip and Location are required for new trip locations'); | ||||
| } | } | ||||
| $trip = $this->tripRepository->find($dto->trip->id); | |||||
| $trip = $this->tripRepository->find($dto->tripIri->id); | |||||
| if (!$trip) { | if (!$trip) { | ||||
| throw new \Exception('Trip not found'); | throw new \Exception('Trip not found'); | ||||
| } | } | ||||
| $location = $this->locationRepository->find($dto->location->id); | |||||
| $location = $this->locationRepository->find($dto->locationIri->id); | |||||
| if (!$location) { | if (!$location) { | ||||
| throw new \Exception('Location not found'); | throw new \Exception('Location not found'); | ||||
| } | } | ||||
| @@ -60,7 +60,7 @@ class TripLocationApiToEntityMapper implements MapperInterface | |||||
| assert($entity instanceof TripLocation); | assert($entity instanceof TripLocation); | ||||
| if ($dto->location) { | if ($dto->location) { | ||||
| $location = $this->locationRepository->find($dto->location->id); | |||||
| $location = $this->locationRepository->find($dto->locationIri->id); | |||||
| if (!$location) { | if (!$location) { | ||||
| throw new \Exception('Location not found'); | throw new \Exception('Location not found'); | ||||
| } | } | ||||
| @@ -49,11 +49,11 @@ class UserApiToEntityMapper implements MapperInterface | |||||
| $roles = $entity->getRoles(); | $roles = $entity->getRoles(); | ||||
| if ($dto->isAdmin && !in_array(User::ROLE_ADMIN, $roles, true)) { | if ($dto->isAdmin && !in_array(User::ROLE_ADMIN, $roles, true)) { | ||||
| $entity->setRoles([User::ROLE_ADMIN]); | |||||
| $entity->setRoles([User::ROLE_ADMIN, User::ROLE_USER]); | |||||
| } | } | ||||
| if (!$dto->isAdmin && in_array(User::ROLE_ADMIN, $roles, true)) { | if (!$dto->isAdmin && in_array(User::ROLE_ADMIN, $roles, true)) { | ||||
| $entity->setRoles([]); | |||||
| $entity->setRoles([User::ROLE_USER]); | |||||
| } | } | ||||
| if ($dto->password) { | if ($dto->password) { | ||||