From 42877ca736dedd415f473d16df4b6c11faeb2281 Mon Sep 17 00:00:00 2001 From: gap95 Date: Mon, 9 Dec 2019 13:46:35 +0100 Subject: [PATCH] Ride history functionality added --- src/app/app-routing.module.ts | 4 + src/app/app.component.ts | 2 +- src/app/hirebike/hirebike.page.ts | 4 +- .../ridehistory/ridehistory-routing.module.ts | 17 +++ src/app/ridehistory/ridehistory.module.ts | 20 +++ src/app/ridehistory/ridehistory.page.html | 131 ++++++++++++++++++ src/app/ridehistory/ridehistory.page.scss | 28 ++++ src/app/ridehistory/ridehistory.page.spec.ts | 24 ++++ src/app/ridehistory/ridehistory.page.ts | 53 +++++++ 9 files changed, 280 insertions(+), 3 deletions(-) create mode 100644 src/app/ridehistory/ridehistory-routing.module.ts create mode 100644 src/app/ridehistory/ridehistory.module.ts create mode 100644 src/app/ridehistory/ridehistory.page.html create mode 100644 src/app/ridehistory/ridehistory.page.scss create mode 100644 src/app/ridehistory/ridehistory.page.spec.ts create mode 100644 src/app/ridehistory/ridehistory.page.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 485a1d4..1c655ac 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 8243678..7e77b65 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 b0ccdd3..bd3f9bc 100644 --- a/src/app/hirebike/hirebike.page.ts +++ b/src/app/hirebike/hirebike.page.ts @@ -121,7 +121,7 @@ export class HirebikePage implements OnInit { }); } - startTrip1() { + 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); @@ -138,7 +138,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 0000000..a947e24 --- /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 0000000..e231df3 --- /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 0000000..55213cb --- /dev/null +++ b/src/app/ridehistory/ridehistory.page.html @@ -0,0 +1,131 @@ + + + + + + + Ride History + + + + + +
+
+
+ + + + Bike ID + + + + {{ride.bikeId}} + + + + + + Price + + + + {{ride.price}} + + + + + + Distance + + + + {{ride.distance}} + + + + + + Start-Date + + + + {{ride.startDate}} + + + + + + End-Date + + + + {{ride.endDate}} + + + + +
+
+
+
+
+
+ + + + Bike ID + + + + {{ride.bikeId}} + + + + + + Price + + + + {{ride.price}} + + + + + + Distance + + + + {{ride.distance}} + + + + + + Start-Date + + + + {{ride.startDate}} + + + + + + End-Date + + + + {{ride.endDate}} + + + + +
+
+ +
+ +
\ 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 0000000..9a74ed8 --- /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 0000000..f79ccc8 --- /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; + + 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 0000000..c9a92d7 --- /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; + 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'); + } +} -- GitLab