Skip to content

Commit

Permalink
Journeys work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
webprofusion-chrisc committed Jun 2, 2016
1 parent c17169a commit e816696
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 78 deletions.
4 changes: 2 additions & 2 deletions App/Ionic2/ocm-app/app/core/ocm/model/Journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class JourneyBaseItem implements ISyncItem {
public Notes: string;
public _sync: SyncItem;

constructor(itemType: string, schemaVersion:number) {
constructor(itemType: string, schemaVersion: number) {
this._sync = new SyncItem(itemType, schemaVersion);
}
}
Expand All @@ -20,7 +20,7 @@ export class BookmarkedPOI extends JourneyBaseItem implements ISyncItem {
public PoiID: number;
public Type: string;
public Poi: any;

public Photos: any;
public _sync: SyncItem;
}

Expand Down
4 changes: 3 additions & 1 deletion App/Ionic2/ocm-app/app/core/ocm/services/APIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ export class APIClient extends Base {
return new Promise(resolve => {

let padding = 0.001;
this.http.get("http://www.panoramio.com/map/get_panoramas.php?set=public&from=0&to=2&minx=" + (pos.longitude - padding) + "&miny=" + (pos.latitude - padding) + "&maxx=" + (pos.longitude + padding) + "maxy=" + (pos.latitude + padding) + "&size=medium&mapfilter=true", this.getHttpRequestOptions()).subscribe(res => {
var url = "http://www.panoramio.com/map/get_panoramas.php?set=public&from=0&to=2&minx=" + (pos.longitude - padding) + "&miny=" + (pos.latitude - padding) + "&maxx=" + (pos.longitude + padding) + "maxy=" + (pos.latitude + padding) + "&size=medium&mapfilter=true&callback=?";
console.log(url);
this.http.get(url).subscribe(res => {
resolve(res.json());
});
});
Expand Down
71 changes: 48 additions & 23 deletions App/Ionic2/ocm-app/app/core/ocm/services/JourneyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,32 @@ export class JourneyManager extends Base {
public updateStoredPOI(poi) {

//updated all journeys which use this poi, TODO: this is messy
if (this.journeys != null) {
for (let j of this.journeys) {
if (j.Stages != null) {
for (let s of j.Stages) {
if (s.WayPoints != null) {
for (let w of s.WayPoints) {
if (w.PoiIDs != null) {
for (let p of w.PoiIDs) {
if (p == poi.ID) {
if (w.PoiList == null) w.PoiList = [];
w.PoiList.push(poi);
}
this.journeys.forEach(j => {
j.Stages.forEach(s => {
s.WayPoints.forEach(w => {
w.PoiIDs.forEach(p => {
if (p == poi.ID) {
if (w.PoiList == null) {
//start new bookmarks list
w.PoiList = [];
let bookmark = new BookmarkedPOI("charging", 1);
bookmark.Poi = poi;
bookmark.PoiID = poi.ID;
w.PoiList.push(bookmark);
} else {
//update existing bookmark
for (let b of w.PoiList) {
if (b.PoiID == poi.ID) {
b.Poi = poi;
}
}
}
}
}
}
}
}
});
});
});
});



//update all favourites with latest info
Expand All @@ -115,7 +121,10 @@ export class JourneyManager extends Base {
for (let j of cloneOfJourneys) {
for (let s of j.Stages) {
for (let w of s.WayPoints) {
w.PoiList = null;
for (let p of w.PoiList) {
p.Poi = null;
p.Photos=null;
}
}
}
}
Expand All @@ -140,11 +149,11 @@ export class JourneyManager extends Base {
journey.Stages.push(newStage);
this.journeys.push(journey);

alert(JSON.stringify(journey, null, 4));

}
public deleteJourney(journeyId:string){
this.journeys = this.journeys.filter(f=>f.ID!=journeyId);

public deleteJourney(journeyId: string) {
this.journeys = this.journeys.filter(f => f.ID != journeyId);
this.saveJourneys();
}

Expand All @@ -161,13 +170,29 @@ export class JourneyManager extends Base {
}
}

public getJourneyStages(journeyId: string) {
let j = this.getJourney(journeyId);
return j.Stages;
}

/**
* Add a WayPoint to the journey at the given stage index (stage must already exist)
*/
public addJourneyWaypoint(journeyId: string, stageIndex: number, waypoint: WayPoint) {
let journey = this.getJourney(journeyId);
let stage = journey.Stages[stageIndex];
stage.WayPoints.push(waypoint);

if (stageIndex == null) {
//create new journey stage, then add waypoint
var newStage: JourneyStage = new JourneyStage();
newStage.Title = "Stage " + journey.Stages.length + 1;
newStage.WayPoints.push(waypoint);
journey.Stages.push(newStage);
} else {
//add to existing journey stage
let stage = journey.Stages[stageIndex];
if (stage.WayPoints == null) stage.WayPoints = [];
stage.WayPoints.push(waypoint);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ <h1>{{poi.AddressInfo.Title}}</h1>
<ion-label stacked>Add to a Journey</ion-label>
<ion-select [(ngModel)]="selectedJourneyID">
<ion-option value="" checked>Create a New Journey</ion-option>
<ion-option *ngFor="let journey of appManager.journeyManager.journeys" [value]="journey.ID">{{journey.Title}}</ion-option>
<ion-option *ngFor="let journey of journeyManager.journeys" [value]="journey.ID">{{journey.Title}}</ion-option>
</ion-select>

</ion-item>
<ion-item *ngIf="selectedJourneyID">
<ion-label stacked>Journey Stage</ion-label>
<ion-select [(ngModel)]="selectedStageIndex">
<ion-option value="">Create a Journey Stage</ion-option>
<ion-option *ngFor="let stage of getJourneyStages(selectedJourneyID)" [value]="stage.Title" checked>{{stage.Title}}</ion-option>
<ion-option *ngFor="let stage of journeyManager.getJourneyStages(selectedJourneyID); let i=index;" [value]="i" checked>{{stage.Title}}</ion-option>
</ion-select>

</ion-item>
Expand Down
27 changes: 16 additions & 11 deletions App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Page, NavParams, NavController} from 'ionic-angular';
import {AppManager} from '../../core/ocm/services/AppManager';
import {Journey, WayPoint, GeoLatLng} from '../../core/ocm/model/AppModels';
import {Journey, WayPoint, GeoLatLng, BookmarkedPOI} from '../../core/ocm/model/AppModels';
import {JourneyManager} from '../../core/ocm/services/JourneyManager';

@Page({
templateUrl: 'build/pages/journeys/favourite-editor.html',
Expand All @@ -12,21 +13,25 @@ import {Journey, WayPoint, GeoLatLng} from '../../core/ocm/model/AppModels';
export class FavouriteEditorPage {

selectedJourneyID;
selectedStageIndex:number;
selectedStageIndex: number;
newJourneyName: string;

waypoint: WayPoint;
poi;

constructor(public appManager: AppManager, private navParams: NavParams, private nav: NavController) {
constructor(public appManager: AppManager, private navParams: NavParams, private nav: NavController, private journeyManager: JourneyManager) {

this.poi = this.navParams.get('poi');
this.waypoint = new WayPoint();
this.waypoint.Title = this.poi.AddressInfo.Title;
this.waypoint.PoiIDs = [this.poi.ID];
this.waypoint.PoiList = [this.poi];


this.waypoint.PoiList = [];

let bookmark = new BookmarkedPOI("charging", 1);
bookmark.Poi = this.poi;
bookmark.PoiID = this.poi.ID;
this.waypoint.PoiList.push(bookmark);

this.newJourneyName = "Trip to " + this.poi.AddressInfo.Title;
}

Expand All @@ -41,24 +46,24 @@ export class FavouriteEditorPage {
if (this.selectedJourneyID != null && this.selectedJourneyID != "") {

//TODO: should be injected instance of JourneyManager instead of via appManager
this.appManager.journeyManager.addJourneyWaypoint(this.selectedJourneyID,this.selectedStageIndex, this.waypoint);
this.journeyManager.addJourneyWaypoint(this.selectedJourneyID, this.selectedStageIndex, this.waypoint);

} else {
//start a new journey
let journey = new Journey();
journey.ID = Date.now().toString();
if (this.newJourneyName == "") this.newJourneyName = "New Journey";
journey.Title = this.newJourneyName;


//add new journey

this.appManager.journeyManager.addJourney(journey, this.waypoint);
this.journeyManager.addJourney(journey, this.waypoint);

}

//todo: async promise for server save
this.appManager.journeyManager.saveJourneys()
this.journeyManager.saveJourneys();

this.nav.pop();
}
Expand Down
105 changes: 71 additions & 34 deletions App/Ionic2/ocm-app/app/pages/journeys/journeys.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,77 @@
<p>
You can create and plan journeys to group your favourite charging routes together.
</p>
<p *ngIf="appManager.journeyManager.journeys==null || appManager.journeyManager.journeys.length==0">

<p *ngIf="journeyManager.journeys==null || journeyManager.journeys.length==0">
You have no journeys yet. Start by browsing to a charging location, then add it as Favourite to start a new Journey.
<button (click)="test()">test</button>
</p>

<ion-card *ngFor="let journey of appManager.journeyManager.journeys">
<ion-card-title>
{{journey.Title}}
</ion-card-title>

<ion-card-content>
<ion-avatar>
<ion-icon name="map" item-left style="font-size:4em;"></ion-icon>
</ion-avatar>
<p>{{journey.Notes}}</p>
<button (click)="journeyManager.deleteJourney(journey.ID)">Delete</button>
<div *ngFor="let s of journey.Stages">
<p>{{s.Title}}</p>
<div *ngFor="let w of s.WayPoints">
<h2>{{w.Title}}</h2>
<p>{{w.Notes}}</p>
<ul>

<li *ngFor="let p of w.PoiList">
{{p.AddressInfo.Title}} - <button (click)="viewPOIDetails(p)"> [OCM-{{p.ID}}]</button>

<a href="{{'http://www.panoramio.com/map/get_panoramas.php?set=public&from=0&to=2&minx=' + (p.AddressInfo.longitude) + '&miny=' + (p.AddressInfo.Latitue)+'size=medium&mapfilter=true'}}">Images</a>
</li>
</ul>


</p>

<ion-card *ngFor="let journey of journeyManager.journeys">


<ion-card-content>
<ion-toolbar primary>
<ion-buttons start>
<button>
<ion-icon name="map"></ion-icon>
</button>
</ion-buttons>
<ion-title> {{journey.Title}}</ion-title>
<ion-buttons end>
<button (click)="deleteJourney(journey.ID)">
<ion-icon name="close"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>

<p>{{journey.Notes}}</p>

<ion-list *ngFor="let s of journey.Stages">
<ion-list-header style="font-size:1.5rem;">
{{s.Title}} -
<ion-icon name="ios-car"></ion-icon> 35 Miles
<ion-icon name="time"></ion-icon> 32 Minutes
<ion-icon name="flash"></ion-icon> 24kWh
</ion-list-header>

<ion-item *ngFor="let w of s.WayPoints">

<ion-thumbnail item-left>
<ion-icon name="arrow-down" style="font-size:4rem;"></ion-icon>
</ion-thumbnail>
<h2>{{w.Title}}</h2>

<p>{{w.Note}}</p>



<div (click)="viewPOIDetails(p)" tappable *ngFor="let p of w.PoiList">
<div *ngIf="p.Poi">
<p *ngIf="p.Poi.AddressInfo.AddressLine1"> {{p.Poi.AddressInfo.AddressLine1}}</p>
<p *ngIf="p.Poi.AddressInfo.AddressLine2"> {{p.Poi.AddressInfo.AddressLine2}}</p>
<p *ngIf="p.Poi.AddressInfo.Town"> {{p.Poi.AddressInfo.Town}}</p>
<p *ngIf="p.Poi.AddressInfo.StateOrProvince"> {{p.Poi.AddressInfo.StateOrProvince}}</p>
<p *ngIf="p.Poi.AddressInfo.Postcode"> {{p.Poi.AddressInfo.Postcode}}</p>


<button primary clear item-right (click)="launchNavigation()">
<ion-icon name="navigate"></ion-icon>
Navigate
</button>


</div>
</div>
</div>
</ion-card-content>

</ion-card>

</ion-item>

</ion-list>



</ion-card-content>

</ion-card>

</ion-content>
Loading

0 comments on commit e816696

Please sign in to comment.