diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 485a1d4f12f77e8f3bb8226b9ee9bdafcecadfde..1c655ac1ee577ae9d623e7bb6f265a84f6770ee1 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -29,6 +29,10 @@ const routes: Routes = [ { path: 'hirebike', loadChildren: () => import('./hirebike/hirebike.module').then( m => m.HirebikePageModule) + }, + { + path: 'ridehistory', + loadChildren: () => import('./ridehistory/ridehistory.module').then( m => m.RidehistoryPageModule) } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8243678cc567422620a7485e92ce588c9b69db1b..7e77b65f50b3a12268708e69f4d0799034cce742 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -31,7 +31,7 @@ export class AppComponent { }, { title: 'My Rides', - url: '/hirebike', + url: '/ridehistory', icon: 'clipboard' }, { diff --git a/src/app/hirebike/hirebike.page.ts b/src/app/hirebike/hirebike.page.ts index c9e2aaa7b0e8be442a7025448eb6c9d0e91a9405..8b73db8ef25546f88eb7dff4a7415c169f8561b0 100644 --- a/src/app/hirebike/hirebike.page.ts +++ b/src/app/hirebike/hirebike.page.ts @@ -195,8 +195,7 @@ export class HirebikePage implements OnInit { }); } - startTrip1() { - this.loadingService.showLoader(); + startTrip() { this.storage.get('token').then((token) => { let url = 'http://193.196.52.237:8081/rent' + '?bikeId=' + this.bikeDetails.id; const headers = new HttpHeaders().set("Authorization", "Bearer " + token); @@ -215,7 +214,7 @@ export class HirebikePage implements OnInit { } - startTrip() { + startTrip1() { this.isBikeHired = true; this.startRideSubject.next('some value'); } diff --git a/src/app/ridehistory/ridehistory-routing.module.ts b/src/app/ridehistory/ridehistory-routing.module.ts new file mode 100644 index 0000000000000000000000000000000000000000..a947e245c39922b3d31280221f3c7fcc86b06f29 --- /dev/null +++ b/src/app/ridehistory/ridehistory-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { RidehistoryPage } from './ridehistory.page'; + +const routes: Routes = [ + { + path: '', + component: RidehistoryPage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class RidehistoryPageRoutingModule {} diff --git a/src/app/ridehistory/ridehistory.module.ts b/src/app/ridehistory/ridehistory.module.ts new file mode 100644 index 0000000000000000000000000000000000000000..e231df37c2915ae4fa4ff2af23d0965b78ec316d --- /dev/null +++ b/src/app/ridehistory/ridehistory.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { RidehistoryPageRoutingModule } from './ridehistory-routing.module'; + +import { RidehistoryPage } from './ridehistory.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + RidehistoryPageRoutingModule + ], + declarations: [RidehistoryPage] +}) +export class RidehistoryPageModule {} diff --git a/src/app/ridehistory/ridehistory.page.html b/src/app/ridehistory/ridehistory.page.html new file mode 100644 index 0000000000000000000000000000000000000000..55213cbaa55c8b1b04ecc75434f202dad6a649f3 --- /dev/null +++ b/src/app/ridehistory/ridehistory.page.html @@ -0,0 +1,131 @@ +<ion-header> + <ion-toolbar> + <ion-buttons slot="start"> + <ion-menu-button></ion-menu-button> + </ion-buttons> + <ion-title slot="start"> + Ride History + </ion-title> + + </ion-toolbar> + </ion-header> +<ion-content> + <div class="ride-list-container" *ngIf="isRideActive"> + <div class="ride-container" *ngFor="let ride of rides"> + <div class="inner" (click)="showRideDetails(bike)"> + <ion-grid> + <ion-row > + <ion-col> + Bike ID + + </ion-col> + <ion-col> + {{ride.bikeId}} + </ion-col> + + </ion-row> + <ion-row> + <ion-col> + Price + + </ion-col> + <ion-col> + {{ride.price}} + </ion-col> + + </ion-row> + <ion-row> + <ion-col> + Distance + + </ion-col> + <ion-col> + {{ride.distance}} + </ion-col> + + </ion-row> + <ion-row> + <ion-col> + Start-Date + + </ion-col> + <ion-col> + {{ride.startDate}} + </ion-col> + + </ion-row> + <ion-row> + <ion-col> + End-Date + + </ion-col> + <ion-col> + {{ride.endDate}} + </ion-col> + + </ion-row> + </ion-grid> + </div> + </div> + </div> + <div class="ride-list-container" *ngIf="!isRideActive"> + <div class="ride-container" *ngFor="let ride of rides"> + <div class="inner" (click)="showRideDetails()"> + <ion-grid> + <ion-row > + <ion-col> + Bike ID + + </ion-col> + <ion-col> + {{ride.bikeId}} + </ion-col> + + </ion-row> + <ion-row> + <ion-col> + Price + + </ion-col> + <ion-col> + {{ride.price}} + </ion-col> + + </ion-row> + <ion-row> + <ion-col> + Distance + + </ion-col> + <ion-col> + {{ride.distance}} + </ion-col> + + </ion-row> + <ion-row> + <ion-col> + Start-Date + + </ion-col> + <ion-col> + {{ride.startDate}} + </ion-col> + + </ion-row> + <ion-row> + <ion-col> + End-Date + + </ion-col> + <ion-col> + {{ride.endDate}} + </ion-col> + + </ion-row> + </ion-grid> + </div> + </div> + +</div> + +</ion-content> \ No newline at end of file diff --git a/src/app/ridehistory/ridehistory.page.scss b/src/app/ridehistory/ridehistory.page.scss new file mode 100644 index 0000000000000000000000000000000000000000..9a74ed809d09b8632833f1a07833bacee0cca015 --- /dev/null +++ b/src/app/ridehistory/ridehistory.page.scss @@ -0,0 +1,28 @@ +.ride-list-container{ + position: relative; + + .bike-list-expander{ + position: absolute; + font-size: 32px; + color: gray; + z-index: 200; + left: 46%; + top: -32px; + } + } + .ride-container{ + height: 191px; + width: 100%; + border: 1px solid #aaaaaa; + border-radius: 5px; + box-sizing: border-box; + float: left; + width: 100%; + clear: both; + + div { + height: inherit; + float: left; + } + } + \ No newline at end of file diff --git a/src/app/ridehistory/ridehistory.page.spec.ts b/src/app/ridehistory/ridehistory.page.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..f79ccc8857bb37b562fc4f8049426a4cba7de0a2 --- /dev/null +++ b/src/app/ridehistory/ridehistory.page.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { IonicModule } from '@ionic/angular'; + +import { RidehistoryPage } from './ridehistory.page'; + +describe('RidehistoryPage', () => { + let component: RidehistoryPage; + let fixture: ComponentFixture<RidehistoryPage>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ RidehistoryPage ], + imports: [IonicModule.forRoot()] + }).compileComponents(); + + fixture = TestBed.createComponent(RidehistoryPage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/ridehistory/ridehistory.page.ts b/src/app/ridehistory/ridehistory.page.ts new file mode 100644 index 0000000000000000000000000000000000000000..c9a92d76a5122ce0a5dfd6eb83a7eac03dab829a --- /dev/null +++ b/src/app/ridehistory/ridehistory.page.ts @@ -0,0 +1,53 @@ +import { Component, OnInit } from '@angular/core'; +import { HttpHeaders, HttpClient } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { Storage } from '@ionic/storage'; +import { Router } from '@angular/router'; +import { RestService } from '../rest.service'; +import { ToastService } from '../services/toast.service'; +@Component({ + selector: 'app-ridehistory', + templateUrl: './ridehistory.page.html', + styleUrls: ['./ridehistory.page.scss'], +}) +export class RidehistoryPage implements OnInit { + rides = []; + rideApi: Observable<any>; + isRideActive=false; + constructor( + private router: Router, + public restService: RestService, + public httpClient: HttpClient, + private storage: Storage, + private toastService: ToastService + ) { } + + ngOnInit() { + this.showrideHistory(); + } + showrideHistory() { + + + this.storage.get('token').then((token) => { + let url = 'http://193.196.52.237:8081/rent-history' + const headers = new HttpHeaders().set("Authorization", "Bearer " + token); + this.rideApi = this.httpClient.get(url, { headers }); + this.rideApi.subscribe((resp) => { + console.log("rides response", resp); + this.rides = resp.data; + for (let i = 0; i < this.rides.length; i++) { + this.rides[i] = this.rides[i]; + if(this.rides[i].active) + this.isRideActive=true; + } + }); + }, er => { + //alert('Can not retrieve location'); + }).catch((error) => { + //alert('Error getting location - ' + JSON.stringify(error)); + }); + } + showRideDetails() { + //this.router.navigateByUrl('/myreservation'); + } +}