diff --git a/App/Ionic2/ocm-app/app/core/ocm/model/Journey.ts b/App/Ionic2/ocm-app/app/core/ocm/model/Journey.ts index 6835bef..d84afc3 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/model/Journey.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/model/Journey.ts @@ -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); } } @@ -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; } diff --git a/App/Ionic2/ocm-app/app/core/ocm/services/APIClient.ts b/App/Ionic2/ocm-app/app/core/ocm/services/APIClient.ts index 4f16c0d..3f84205 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/services/APIClient.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/services/APIClient.ts @@ -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()); }); }); diff --git a/App/Ionic2/ocm-app/app/core/ocm/services/JourneyManager.ts b/App/Ionic2/ocm-app/app/core/ocm/services/JourneyManager.ts index 06e1548..c1d5d5a 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/services/JourneyManager.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/services/JourneyManager.ts @@ -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 @@ -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; + } } } } @@ -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(); } @@ -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); + } } /** diff --git a/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.html b/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.html index 586e12d..9ec8c42 100644 --- a/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.html +++ b/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.html @@ -18,7 +18,7 @@

{{poi.AddressInfo.Title}}

Add to a Journey Create a New Journey - {{journey.Title}} + {{journey.Title}} @@ -26,7 +26,7 @@

{{poi.AddressInfo.Title}}

Journey Stage Create a Journey Stage - {{stage.Title}} + {{stage.Title}} diff --git a/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.ts b/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.ts index fa099d7..42b7383 100644 --- a/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.ts +++ b/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.ts @@ -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', @@ -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; } @@ -41,7 +46,7 @@ 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 @@ -49,16 +54,16 @@ export class FavouriteEditorPage { 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(); } diff --git a/App/Ionic2/ocm-app/app/pages/journeys/journeys.html b/App/Ionic2/ocm-app/app/pages/journeys/journeys.html index 9d15295..bd8dbe4 100644 --- a/App/Ionic2/ocm-app/app/pages/journeys/journeys.html +++ b/App/Ionic2/ocm-app/app/pages/journeys/journeys.html @@ -7,40 +7,77 @@

You can create and plan journeys to group your favourite charging routes together.

- -

+ +

You have no journeys yet. Start by browsing to a charging location, then add it as Favourite to start a new Journey. - -

- - - - {{journey.Title}} - - - - - - -

{{journey.Notes}}

- -
-

{{s.Title}}

-
-

{{w.Title}}

-

{{w.Notes}}

-
    - -
  • - {{p.AddressInfo.Title}} - - - Images -
  • -
- + +

+ + + + + + + + + + {{journey.Title}} + + + + + +

{{journey.Notes}}

+ + + + {{s.Title}} - + 35 Miles + 32 Minutes + 24kWh + + + + + + + +

{{w.Title}}

+ +

{{w.Note}}

+ + + +
+
+

{{p.Poi.AddressInfo.AddressLine1}}

+

{{p.Poi.AddressInfo.AddressLine2}}

+

{{p.Poi.AddressInfo.Town}}

+

{{p.Poi.AddressInfo.StateOrProvince}}

+

{{p.Poi.AddressInfo.Postcode}}

+ + + + + +
-
- - - + + + + + + + + + + + \ No newline at end of file diff --git a/App/Ionic2/ocm-app/app/pages/journeys/journeys.ts b/App/Ionic2/ocm-app/app/pages/journeys/journeys.ts index 8a62170..72c6686 100644 --- a/App/Ionic2/ocm-app/app/pages/journeys/journeys.ts +++ b/App/Ionic2/ocm-app/app/pages/journeys/journeys.ts @@ -1,7 +1,8 @@ -import {Page, Modal, NavController} from 'ionic-angular'; +import {Page, Modal, NavController, Alert} from 'ionic-angular'; import {AppManager} from '../../core/ocm/services/AppManager'; import {Journey, WayPoint, GeoLatLng} from '../../core/ocm/model/AppModels'; import {JourneyManager} from '../../core/ocm/services/JourneyManager'; +import {APIClient} from '../../core/ocm/services/APIClient'; import {POIDetailsPage} from '../poi-details/poi-details'; @Page({ @@ -13,13 +14,32 @@ import {POIDetailsPage} from '../poi-details/poi-details'; */ export class JourneysPage { - constructor(private appManager: AppManager, private nav: NavController, private journeyManager:JourneyManager) { + constructor(private appManager: AppManager, private nav: NavController, private journeyManager: JourneyManager, private api: APIClient) { + this.discoverImages(); + console.log(JSON.stringify(this.journeyManager.journeys, null, 4)); } - test() { - console.log(JSON.stringify(this.journeyManager.journeys, null, 4)); + discoverImages() { + //popoulate panormaio for each point + this.journeyManager.journeys.forEach(j => { + j.Stages.forEach(s => { + s.WayPoints.forEach(w => { + if (w.PoiList != null) { + w.PoiList.forEach(p => { + + if (p.Poi) { + this.api.getPanoramioLocationPhotos(new GeoLatLng(p.Poi.AddressInfo.Latitude, p.Poi.AddressInfo.Longitude)).then((photos) => { + p.Photos = photos; + }); + } + }); + } + }); + }); + }); + } getJson(p): string { @@ -30,6 +50,42 @@ export class JourneysPage { var poiDetailsModal = Modal.create(POIDetailsPage, { item: poi }); this.nav.present(poiDetailsModal); } + + get staticMapSize(): string { + + return "60x60"; + + } + + getStaticMapURL(poi): string { + + //scale=2 for retina + return "https://maps.googleapis.com/maps/api/staticmap?center=" + + poi.AddressInfo.Latitude + "," + poi.AddressInfo.Longitude + "&zoom=13&scale=2&size=" + + this.staticMapSize + "&maptype=roadmap&format=jpg&visual_refresh=true&markers=size:small%7Ccolor:0xff0000%7Clabel:%7C" + + poi.AddressInfo.Latitude + "," + poi.AddressInfo.Longitude; + } - + deleteJourney(journeyId){ + let confirm = Alert.create({ + title: 'Delete this Journey?', + message: 'Are you sure you want to delete this Journey?', + buttons: [ + { + text: 'No', + handler: () => { + //nope + } + }, + { + text: 'Delete', + handler: () => { + this.journeyManager.deleteJourney(journeyId); + } + } + ] + }); + + this.nav.present(confirm); + } }