Skip to content

Commit

Permalink
Merge pull request #189 from Kleostro/fix/tu-02-61/carriages
Browse files Browse the repository at this point in the history
fix(tu-02-61): carriages
  • Loading branch information
stardustmeg authored Sep 3, 2024
2 parents 0d74478 + 66a567d commit 943f953
Show file tree
Hide file tree
Showing 71 changed files with 419 additions and 227 deletions.
File renamed without changes
Binary file added public/img/png/no-results.webp
Binary file not shown.
4 changes: 2 additions & 2 deletions src/app/admin/components/carriage/carriage.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@for (rightRow of seatsSchema.rightSeats; let i = $index; track i) {
<div class="right-seats-row">
@for (rightSeat of rightRow; let index = $index; track index) {
@let seatNumber = firstSeat() + rightSeat;
@let seatNumber = firstSeat() ? firstSeat() + rightSeat - 1 : rightSeat;
<app-seat
[classes]="[
'right',
Expand All @@ -49,7 +49,7 @@
@for (leftRow of seatsSchema.leftSeats; let i = $index; track i) {
<div class="left-seats-row">
@for (leftSeat of leftRow; let index = $index; track index) {
@let seatNumber = firstSeat() + leftSeat;
@let seatNumber = firstSeat() ? firstSeat() + leftSeat - 1 : leftSeat;
<app-seat
[classes]="['left', i === 0 ? 'first-seat' : '', isInteractive() ? 'interactive' : '']"
[carriageName]="carriage.name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import { UpdateCarriageFormComponent } from '../update-carriage-form/update-carr
export class CarriagesListComponent {
public routingService = inject(RoutingService);
public modalService = inject(ModalService);

public allCarriages = input<Carriage[]>([]);

public editCarriage = signal<Carriage | null>(null);

public firstPage = 0;
public rowsCount = 10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import { CarriageComponent } from '../carriage/carriage.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CreateCarriageFormComponent implements OnInit, AfterViewInit, OnDestroy {
private subsciption = new Subscription();

private fb = inject(FormBuilder);
private modalService = inject(ModalService);
private userMessageService = inject(UserMessageService);
private carriageService = inject(CarriageService);

private subsciption = new Subscription();

public newCarriage = signal<Carriage>(INITIAL_CARRIAGE);
public isCreated = signal(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ import { collectNewRideData } from '../../utils/collectAllRideData';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CreateRideFormComponent implements OnInit, OnDestroy {
private subscription = new Subscription();

private fb = inject(FormBuilder);

public rideService = inject(RideService);
public stationsService = inject(StationsService);
public userMessageService = inject(UserMessageService);

public stationNamesList = computed(() => {
const routeInfo = this.rideService.currentRouteInfo();
if (routeInfo) {
Expand All @@ -34,15 +38,17 @@ export class CreateRideFormComponent implements OnInit, OnDestroy {
return [];
});
public carriageTypes = computed(() => this.rideService.currentRouteInfo()?.carriages);

public createRideForm = this.fb.nonNullable.group({
times: this.fb.array<TimesFGType>([]),
carriageTypes: this.fb.array<CarriageTypesFGType>([]),
});

public isRideCreated = signal(true);

public Object = Object;
public minDate = new Date();
public time = false;
public isRideCreated = signal(true);
private subscription = new Subscription();

public submit(): void {
this.isRideCreated.set(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ import { MapService } from '../../services/map/map.service';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CreateStationFormComponent implements OnInit, OnDestroy {
private subscription = new Subscription();

private fb = inject(FormBuilder);
private mapService = inject(MapService);
private stationsService = inject(StationsService);
private userMessageService = inject(UserMessageService);
private subscription = new Subscription();

public isStationCreated = signal(false);

public filteredCountries: string[] = [];

public createStationForm = this.fb.nonNullable.group({
Expand Down
8 changes: 5 additions & 3 deletions src/app/admin/components/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ import { MapService } from '../../services/map/map.service';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MapComponent implements OnInit, AfterViewInit, OnDestroy {
private subscription = new Subscription();

private mapService = inject(MapService);
private stationsService = inject(StationsService);

private map: Map | null = null;
private lastClickedMarker: Marker | null = null;

public allStations = input.required<Station[]>();

private subscription = new Subscription();
private map: Map | null = null;
public isMapLoaded = signal(false);
private lastClickedMarker: Marker | null = null;

@ViewChild('mapContainer')
private mapContainer: ElementRef<HTMLElement> | null = null;
Expand Down
23 changes: 21 additions & 2 deletions src/app/admin/components/ride-price/ride-price.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { CurrencyPipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, EventEmitter, inject, input, OnInit, Output, signal } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
inject,
input,
OnDestroy,
OnInit,
Output,
signal,
} from '@angular/core';
import { FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';

import { ButtonModule } from 'primeng/button';
import { InputNumberModule } from 'primeng/inputnumber';
import { RippleModule } from 'primeng/ripple';
import { Subscription } from 'rxjs';

import { RidePrice } from '../../models/ride.model';

Expand All @@ -17,10 +28,14 @@ import { RidePrice } from '../../models/ride.model';
styleUrl: './ride-price.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RidePriceComponent implements OnInit {
export class RidePriceComponent implements OnInit, OnDestroy {
private subscription = new Subscription();

private fb = inject(FormBuilder);

public priceList = input<RidePrice[] | null>(null);
public isPriceEdited = input(false);

public isEdit = signal(false);

public priceForm = this.fb.group({
Expand Down Expand Up @@ -58,4 +73,8 @@ export class RidePriceComponent implements OnInit {
this.priceChanged.emit(updatedPriceList);
}
}

public ngOnDestroy(): void {
this.subscription.unsubscribe();
}
}
3 changes: 3 additions & 0 deletions src/app/admin/components/ride-time/ride-time.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ import { RidePath } from '../../models/ride.model';
})
export class RideTimeComponent {
private fb = inject(FormBuilder);

public to = input<string | null>(null);
public from = input<string | null>(null);
public isTimeEdited = input(true);

public isEdit = signal(false);

public minDate = new Date();
public fromTime = false;
public toTime = false;
Expand Down
6 changes: 5 additions & 1 deletion src/app/admin/components/ride/ride.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ import { RideTimeComponent } from '../ride-time/ride-time.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RideComponent implements OnDestroy {
private subscription = new Subscription();

private stationsService = inject(StationsService);
private rideService = inject(RideService);
private userMessageService = inject(UserMessageService);

public ride = input<CustomSchedule | null>(null);
public path = input<number[]>([]);

public stations = computed<(Station | null)[]>(() =>
this.path().map((id) => this.stationsService.findStationById(id)),
);
public fullRideData = computed(() => collectAllRideData(this.stations(), this.ride()?.segments ?? []));

public isTimeEdited = signal(true);
public isPriceEdited = signal(true);
public isRideDeleted = signal(true);
private subscription = new Subscription();

public handleTimeChanged(event: RidePath, index: number): void {
const currentRide = this.ride();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { RideComponent } from '../ride/ride.component';
export class RidesListComponent {
public schedule = input<CustomSchedule[]>([]);
public path = input<number[]>([]);

public firstPage = 0;
public rowsCount = 10;

Expand Down
22 changes: 19 additions & 3 deletions src/app/admin/components/route-form/route-form.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, effect, inject, input, signal } from '@angular/core';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
effect,
inject,
input,
OnDestroy,
signal,
} from '@angular/core';
import { FormArray, FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';

import { AutoCompleteModule } from 'primeng/autocomplete';
Expand All @@ -21,15 +30,18 @@ import { UserMessageService } from '@/app/shared/services/userMessage/user-messa
styleUrl: './route-form.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RouteFormComponent {
export class RouteFormComponent implements OnDestroy {
private subscription = new Subscription();

private stationsService = inject(StationsService);
private carriageService = inject(CarriageService);
private routeService = inject(RouteService);
private userMessageService = inject(UserMessageService);
private fb = inject(FormBuilder);
private cdr = inject(ChangeDetectorRef);

public currentRoute = input<RouteResponse | null>(null);
private subscription = new Subscription();

public filteredStations = signal<string[]>([]);
public filteredCarriages = signal<string[]>([]);
public isRouteChanged = signal(false);
Expand Down Expand Up @@ -252,4 +264,8 @@ export class RouteFormComponent {
stationsArray.splice(this.currentStationControl() + 1);
this.routeForm.controls.stations.controls = stationsArray;
}

public ngOnDestroy(): void {
this.subscription.unsubscribe();
}
}
1 change: 1 addition & 0 deletions src/app/admin/components/route/route.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { StationsService } from '@/app/api/stationsService/stations.service';
export class RouteComponent {
public stationsService = inject(StationsService);
public routeService = inject(RouteService);

public route = input<RouteResponse | null>(null);

@Output() public openDeleteConfirm: EventEmitter<number> = new EventEmitter<number>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ import { RouteComponent } from '../route/route.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RoutesListComponent implements OnDestroy {
private subscription = new Subscription();

public routeService = inject(RouteService);
public modalService = inject(ModalService);
public userMessageService = inject(UserMessageService);

public routes = input<RouteResponse[]>([]);
public stations = input<Station[]>([]);

public deletionRouteId = signal<number>(NaN);
public isRouteDeleted = signal(false);
private subscription = new Subscription();

public firstPage = 0;
public rowsCount = 10;

Expand Down
1 change: 1 addition & 0 deletions src/app/admin/components/seat/seat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SeatService } from '../../services/seat/seat.service';
})
export class SeatComponent {
public seatService = inject(SeatService);

public carriageName = input<string>('');
public carriageNumber = input<number>(NaN);
public seatNumber = input<number>(NaN);
Expand Down
6 changes: 4 additions & 2 deletions src/app/admin/components/station/station.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ import { MapService } from '../../services/map/map.service';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class StationComponent implements OnDestroy {
private subsciption = new Subscription();

private userMessageService = inject(UserMessageService);

public stationsService = inject(StationsService);
public mapService = inject(MapService);

public isStationDeleted = signal(false);

@Input() public station!: Station;

private subsciption = new Subscription();

public deleteStation(id: number): void {
this.isStationDeleted.set(true);
this.subsciption.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { CarriageComponent } from '../carriage/carriage.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UpdateCarriageFormComponent implements OnInit, OnDestroy {
private subsciption = new Subscription();

private fb = inject(FormBuilder);
private modalService = inject(ModalService);
private userMessageService = inject(UserMessageService);
Expand All @@ -41,9 +43,9 @@ export class UpdateCarriageFormComponent implements OnInit, OnDestroy {

public carriage = input<Carriage | null>(null);

private subsciption = new Subscription();
public currentCarriage = signal<Carriage | null>(null);
public isUpdating = signal(false);

public carriageForm = this.fb.nonNullable.group({
rows: [0, [Validators.required.bind(this), Validators.min(1)]],
leftSeats: [0, [Validators.required.bind(this), Validators.min(1)]],
Expand Down
27 changes: 27 additions & 0 deletions src/app/admin/pages/carriages/carriages.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { provideHttpClient } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';

import { of } from 'rxjs';

import { CarriagesComponent } from './carriages.component';

describe('CarriagesComponent', () => {
let component: CarriagesComponent;
let fixture: ComponentFixture<CarriagesComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [CarriagesComponent],
providers: [provideHttpClient(), { provide: ActivatedRoute, useValue: { queryParams: of({}) } }],
}).compileComponents();

fixture = TestBed.createComponent(CarriagesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
4 changes: 2 additions & 2 deletions src/app/admin/pages/carriages/carriages.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import { CreateCarriageFormComponent } from '../../components/create-carriage-fo
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CarriagesComponent implements OnInit, OnDestroy {
private subsciption = new Subscription();

private cdr = inject(ChangeDetectorRef);
public carriageService = inject(CarriageService);
public modalService = inject(ModalService);

private subsciption = new Subscription();

public setParamsInModal(): void {
this.modalService.position$$.set(POSITION_DIRECTION.CENTER_TOP);
}
Expand Down
Loading

0 comments on commit 943f953

Please sign in to comment.