Fixes in edit/create travel

This commit is contained in:
Eneko Nieto
2021-02-09 13:29:17 +01:00
parent adccf113f3
commit 8afe477620
7 changed files with 29 additions and 30 deletions

View File

@@ -37,7 +37,7 @@ export const authConfig: AuthConfig = {
useSilentRefresh: useSilentRefreshForCodeFlow,
showDebugInformation: true,
showDebugInformation: false,
sessionChecksEnabled: true,
sessionCheckIntervall: 10000,

View File

@@ -2,6 +2,7 @@ export type UserId = string;
export interface UserInfo {
id: UserId;
username: string;
matrixId?: string;
name: string;
}

View File

@@ -2,6 +2,7 @@ export type UserId = string;
export interface User {
id: UserId;
username: string;
matrixId?: string;
name: string;
}

View File

@@ -1,7 +1,6 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { TravelFormComponent } from 'src/app/views/travel-form/travel-form.component';
import { PUBLIC_API_URL } from '../../app.config';
import { Travel, TravelId } from '../../entities/travel';
import { ApiService } from '../../services/api.service';
@@ -32,21 +31,22 @@ export class EditTravelComponent implements OnInit {
this.travel = res.data;
}
else {
console.error('Error getting travel ' + travelId + ': ' + res.error);
console.error('Error getting travel ' + travelId + ': ' + res.error.code + ' ' + res.error.msg);
}
});
});
}
editTravel(travel: Travel): void {
this.apiService.createTravel(travel)
this.apiService.editTravel(travel)
.subscribe(res => {
if (res.success) {
console.log('Travel edited');
this.router.navigateByUrl('/');
}
else {
console.error('Error creating travel: ' + res.error);
console.error('Error editing travel: ' + res.error.code + ' ' + res.error.msg);
this.form.submitted = false;
}
});
}

View File

@@ -15,10 +15,11 @@ export class HomeComponent implements OnInit {
userTravels: Travel[];
displayedColumns = [
'driver',
'departureDate',
'origin',
'destination',
'availablePlaces',
'driver',
'description',
];
travelsApiCall = this.apiService.getTravels;

View File

@@ -30,7 +30,8 @@ export class NewTravelComponent implements OnInit {
this.router.navigateByUrl('/');
}
else {
console.error('Error creating travel: ' + res.error);
console.error('Error creating travel: ' + res.error.code + ' ' + res.error.msg);
this.form.submitted = false;
}
});
}

View File

@@ -7,45 +7,44 @@
<mat-spinner></mat-spinner>
</div>
<mat-table
class="travel-table mat-elevation-z8"
[dataSource]="dataSource"
matSort
matSortActive="driver"
matSortDirection="asc"
matSortDisableClear
>
<ng-container matColumnDef="driver">
<mat-header-cell *matHeaderCellDef mat-sort-header>#</mat-header-cell>
<mat-cell *matCellDef="let travel">{{ travel.driverId }}</mat-cell>
</ng-container>
<mat-table class="travel-table mat-elevation-z8" [dataSource]="dataSource" matSort matSortActive="driver"
matSortDirection="asc" matSortDisableClear>
<ng-container matColumnDef="departureDate">
<mat-header-cell *matHeaderCellDef mat-sort-header>Departure date</mat-header-cell>
<mat-cell *matCellDef="let travel">{{
travel.departureDate
}}</mat-cell>
}}</mat-cell>
</ng-container>
<ng-container matColumnDef="origin">
<mat-header-cell *matHeaderCellDef mat-sort-header>Origin</mat-header-cell>
<mat-cell *matCellDef="let travel">{{
travel.origin
}}</mat-cell>
}}</mat-cell>
</ng-container>
<ng-container matColumnDef="destination">
<mat-header-cell *matHeaderCellDef mat-sort-header>Destination</mat-header-cell>
<mat-cell *matCellDef="let travel">{{
travel.destination
}}</mat-cell>
}}</mat-cell>
</ng-container>
<ng-container matColumnDef="availablePlaces">
<mat-header-cell *matHeaderCellDef mat-sort-header>Available places</mat-header-cell>
<mat-cell *matCellDef="let travel">{{ travel.places - travel.travelersInfo.length }}</mat-cell>
</ng-container>
<ng-container matColumnDef="driver">
<mat-header-cell *matHeaderCellDef mat-sort-header>Driver</mat-header-cell>
<mat-cell *matCellDef="let travel">{{ travel.driverInfo.name }}</mat-cell>
</ng-container>
<ng-container matColumnDef="description">
<mat-header-cell *matHeaderCellDef>Description</mat-header-cell>
<mat-cell class="description-cell" *matCellDef="let travel">{{
travel.description
}}</mat-cell>
}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
@@ -53,9 +52,5 @@
<mat-row *matRowDef="let row; columns: displayedColumns" (click)="rowClicked(row)"></mat-row>
</mat-table>
<mat-paginator
[length]=dataSource.total
[pageSize]="3"
[pageSizeOptions]="[3, 5, 10]"
></mat-paginator>
</div>
<mat-paginator [length]=dataSource.total [pageSize]="3" [pageSizeOptions]="[3, 5, 10]"></mat-paginator>
</div>