From c17169ad173a357b6d30d610f5680f482d4ce93c Mon Sep 17 00:00:00 2001 From: Christopher Cook Date: Tue, 31 May 2016 17:06:27 +0800 Subject: [PATCH] Use new map markers and more work on Journeys --- App/Ionic2/ocm-app/app/app.ts | 10 +- .../ocm/mapping/providers/GoogleMapsNative.ts | 10 +- .../ocm/mapping/providers/GoogleMapsWeb.ts | 24 ++- .../core/ocm/mapping/providers/LeafletMap.ts | 29 +-- .../ocm-app/app/core/ocm/model/AppModels.ts | 5 +- .../ocm-app/app/core/ocm/model/Journey.ts | 66 +++++-- .../ocm-app/app/core/ocm/model/SyncItem.ts | 23 +++ .../app/core/ocm/services/AppManager.ts | 17 +- .../app/core/ocm/services/JourneyManager.ts | 175 +++++++++++++++++- .../app/core/ocm/services/POIManager.ts | 27 +-- .../core/ocm/services/ReferenceDataManager.ts | 1 - .../app/core/ocm/services/SubmissionQueue.ts | 2 +- .../app/pages/journeys/favourite-editor.html | 8 + .../app/pages/journeys/favourite-editor.ts | 38 ++-- .../ocm-app/app/pages/journeys/journeys.html | 29 ++- .../ocm-app/app/pages/journeys/journeys.ts | 30 ++- .../ocm-app/app/pages/search/search.html | 2 +- App/Ionic2/ocm-app/app/pages/search/search.ts | 15 +- .../ocm-app/app/pages/settings/settings.ts | 5 +- .../icons/map/level0_nonoperational_icon.png | Bin 0 -> 4494 bytes .../icons/map/level0_operational_icon.png | Bin 0 -> 4658 bytes .../images/icons/map/level0_private_icon.png | Bin 0 -> 4563 bytes .../icons/map/level1_nonoperational_icon.png | Bin 0 -> 4700 bytes .../icons/map/level1_operational_icon.png | Bin 0 -> 4863 bytes .../images/icons/map/level1_private_icon.png | Bin 0 -> 4760 bytes .../icons/map/level2_nonoperational_icon.png | Bin 0 -> 4725 bytes .../icons/map/level2_operational_icon.png | Bin 0 -> 4881 bytes .../images/icons/map/level2_private_icon.png | Bin 0 -> 4800 bytes .../icons/map/level3_nonoperational_icon.png | Bin 0 -> 4697 bytes .../icons/map/level3_operational_icon.png | Bin 0 -> 4847 bytes .../images/icons/map/level3_private_icon.png | Bin 0 -> 4779 bytes .../icons/map/level4_nonoperational_icon.png | Bin 0 -> 4156 bytes .../icons/map/level4_operational_icon.png | Bin 0 -> 4302 bytes .../images/icons/map/level4_private_icon.png | Bin 0 -> 4233 bytes .../www/images/icons/map/set4_level0.png | Bin 4961 -> 0 bytes .../images/icons/map/set4_level0_private.png | Bin 4881 -> 0 bytes .../www/images/icons/map/set4_level1.png | Bin 5184 -> 0 bytes .../images/icons/map/set4_level1_private.png | Bin 5063 -> 0 bytes .../www/images/icons/map/set4_level2.png | Bin 5271 -> 0 bytes .../images/icons/map/set4_level2_private.png | Bin 5164 -> 0 bytes .../www/images/icons/map/set4_level3.png | Bin 5232 -> 0 bytes .../images/icons/map/set4_level3_private.png | Bin 5102 -> 0 bytes .../www/images/icons/map/set4_level4.png | Bin 4571 -> 0 bytes .../images/icons/map/set4_level4_private.png | Bin 4503 -> 0 bytes 44 files changed, 397 insertions(+), 119 deletions(-) create mode 100644 App/Ionic2/ocm-app/app/core/ocm/model/SyncItem.ts create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level0_nonoperational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level0_operational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level0_private_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level1_nonoperational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level1_operational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level1_private_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level2_nonoperational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level2_operational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level2_private_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level3_nonoperational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level3_operational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level3_private_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level4_nonoperational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level4_operational_icon.png create mode 100644 App/Ionic2/ocm-app/www/images/icons/map/level4_private_icon.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level0.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level0_private.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level1.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level1_private.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level2.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level2_private.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level3.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level3_private.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level4.png delete mode 100644 App/Ionic2/ocm-app/www/images/icons/map/set4_level4_private.png diff --git a/App/Ionic2/ocm-app/app/app.ts b/App/Ionic2/ocm-app/app/app.ts index af6b9cb..419e4c7 100644 --- a/App/Ionic2/ocm-app/app/app.ts +++ b/App/Ionic2/ocm-app/app/app.ts @@ -7,6 +7,8 @@ import {APIClient} from './core/ocm/services/APIClient'; import {AppManager} from './core/ocm/services/AppManager' import {POIManager} from './core/ocm/services/POIManager' import {SubmissionQueue} from './core/ocm/services/SubmissionQueue' +import {JourneyManager} from './core/ocm/services/JourneyManager'; +import {ReferenceDataManager} from './core/ocm/services/ReferenceDataManager'; import {Base} from './core/ocm/Base'; import {TabsPage} from './pages/tabs/tabs'; @@ -22,14 +24,18 @@ enableProdMode(); template: '', providers: [ AppManager, + POIManager, Events, provide(TranslateLoader, { useFactory: (http: Http) => new TranslateStaticLoader(http, 'lang', '.json'), deps: [Http] }), TranslateService, - - APIClient, SubmissionQueue], + APIClient, + SubmissionQueue, + JourneyManager, + ReferenceDataManager + ], config: { mode: "ios" } diff --git a/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/GoogleMapsNative.ts b/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/GoogleMapsNative.ts index 986ee2c..47a6236 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/GoogleMapsNative.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/GoogleMapsNative.ts @@ -169,12 +169,18 @@ this.map.setDebuggable(true); var shadow = null; var markerImg = null; - iconURL = "images/icons/map/set4_level" + poiLevel; + iconURL = "images/icons/map/level" + poiLevel; + if (poi.UsageType != null && poi.UsageType.Title.indexOf("Private") > -1) { iconURL += "_private"; + } else if (poi.StatusType != null && poi.StatusType.IsOperational != true) { + iconURL += "_nonoperational"; + } else { + iconURL += "_operational"; } - iconURL += ".png"; + iconURL += "_icon.png"; + var markerTooltip = "OCM-" + poi.ID + ": " + poi.AddressInfo.Title + ":"; if (poi.UsageType != null) markerTooltip += " " + poi.UsageType.Title; diff --git a/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/GoogleMapsWeb.ts b/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/GoogleMapsWeb.ts index 60fd98e..83f6da9 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/GoogleMapsWeb.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/GoogleMapsWeb.ts @@ -93,8 +93,8 @@ export class GoogleMapsWeb extends Base implements IMapProvider { google.maps.event.addListener(this.map, 'zoom_changed', function () { mapProviderContext.events.publish('ocm:mapping:zoom'); }); - - google.maps.event.addListener(this.map, 'idle', function () { + + google.maps.event.addListener(this.map, 'idle', function () { mapProviderContext.events.publish('ocm:mapping:ready'); }); @@ -169,12 +169,18 @@ export class GoogleMapsWeb extends Base implements IMapProvider { var shadow = null; var markerImg = null; - iconURL = "images/icons/map/set4_level" + poiLevel; + iconURL = "images/icons/map/level" + poiLevel; + if (poi.UsageType != null && poi.UsageType.Title.indexOf("Private") > -1) { iconURL += "_private"; + } else if (poi.StatusType != null && poi.StatusType.IsOperational != true) { + iconURL += "_nonoperational"; + } else { + iconURL += "_operational"; } - iconURL += ".png"; + iconURL += "_icon.png"; + markerImg = new google.maps.MarkerImage( iconURL, @@ -265,11 +271,11 @@ export class GoogleMapsWeb extends Base implements IMapProvider { //wrap getCenter in an observable let obs = Observable.create(observer => { var pos = this.map.getCenter(); - if (pos != null) { - observer.next(new GeoPosition(pos.lat(), pos.lng())); - observer.complete(); - } - + if (pos != null) { + observer.next(new GeoPosition(pos.lat(), pos.lng())); + observer.complete(); + } + }); return obs; diff --git a/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/LeafletMap.ts b/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/LeafletMap.ts index 221c4af..184b623 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/LeafletMap.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/mapping/providers/LeafletMap.ts @@ -95,7 +95,7 @@ export class LeafletMap extends Base implements IMapProvider { /** Clear current markers */ clearMarkers() { if (this.markerList != null) { - this.log("Clearing all markers ["+this.markerList.size()+"]"); + this.log("Clearing all markers [" + this.markerList.size() + "]"); for (var i = 0; i < this.markerList.size(); i++) { if (this.markerList[i]) { this.markerList[i].setMap(null); @@ -126,13 +126,7 @@ export class LeafletMap extends Base implements IMapProvider { if (poiList != null) { //render poi markers - var defaultMarkerIcon = L.icon({ - iconUrl: 'images/icons/map/set4_level0.png', - iconSize: [34, 50], // size of the icon - iconAnchor: [15, 45] // point of the icon which will correspond to marker's location - // popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor - }); var poiCount = poiList.length; for (var i = 0; i < poiList.length; i++) { @@ -160,13 +154,24 @@ export class LeafletMap extends Base implements IMapProvider { var shadow = null; var markerImg = null; - iconURL = "images/icons/map/set4_level" + poiLevel; + iconURL = "images/icons/map/level" + poiLevel; if (poi.UsageType != null && poi.UsageType.Title.indexOf("Private") > -1) { iconURL += "_private"; + } else if (poi.StatusType != null && poi.StatusType.IsOperational != true) { + iconURL += "_nonoperational"; + } else { + iconURL += "_operational"; } - iconURL += ".png"; + iconURL += "_icon.png"; + var defaultMarkerIcon = L.icon({ + iconUrl: iconURL, + + iconSize: [34, 50], // size of the icon + iconAnchor: [15, 45] // point of the icon which will correspond to marker's location + // popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor + }); var markerTooltip = "OCM-" + poi.ID + ": " + poi.AddressInfo.Title + ":"; if (poi.UsageType != null) markerTooltip += " " + poi.UsageType.Title; @@ -260,10 +265,10 @@ export class LeafletMap extends Base implements IMapProvider { } setMapZoom(zoomLevel: number) { - if (this.mapReady){ - this.map.setZoom(zoomLevel); + if (this.mapReady) { + this.map.setZoom(zoomLevel); } - + } getMapZoom(): Observable { diff --git a/App/Ionic2/ocm-app/app/core/ocm/model/AppModels.ts b/App/Ionic2/ocm-app/app/core/ocm/model/AppModels.ts index f4cb77d..0a1447c 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/model/AppModels.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/model/AppModels.ts @@ -3,10 +3,11 @@ export {AsyncResult} from "./AsyncResult"; export {SubmissionQueueItem} from "./SubmissionQueueItem"; export {SubmissionType} from './SubmissionType'; export {UserComment} from './UserComment'; -export {Journey,WayPoint} from './Journey'; +export {Journey, JourneyStage, WayPoint, BookmarkedPOI} from './Journey'; export {PlaceSearchResult} from './PlaceSearchResult'; export {GeoLatLng, GeoPosition} from './GeoPosition'; export {SearchSettings} from './SearchSettings'; export {CoreReferenceData} from './CoreReferenceData'; export {ConnectionInfo} from './ConnectionInfo'; -export {POISearchParams} from './POISearchParams'; \ No newline at end of file +export {POISearchParams} from './POISearchParams'; +export {SyncItem} from './SyncItem'; \ No newline at end of file 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 edd93c4..6835bef 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/model/Journey.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/model/Journey.ts @@ -1,23 +1,65 @@ import {GeoLatLng} from './GeoPosition'; +import {SyncItem} from './SyncItem'; -export class WayPoint{ + +export interface ISyncItem { + _sync: SyncItem; +} + +class JourneyBaseItem implements ISyncItem { public Title: string; public Notes: string; + public _sync: SyncItem; + + constructor(itemType: string, schemaVersion:number) { + this._sync = new SyncItem(itemType, schemaVersion); + } +} + +export class BookmarkedPOI extends JourneyBaseItem implements ISyncItem { + public PoiID: number; + public Type: string; + public Poi: any; + + public _sync: SyncItem; +} + +export class WayPoint extends JourneyBaseItem { + public Stage: number; public Position: GeoLatLng; - public PoiIDs:Array; - public PoiList: Array; - + public PoiIDs: Array; + public PoiList: Array; + + public constructor() { + super("waypoint", 1); + } + } -export class Journey{ - public ID:string; - public Title:string; - public Notes: string; +export class JourneyStage extends JourneyBaseItem { + public WayPoints: Array; - - public constructor(){ - this.ID = ""+Date.now; - this.WayPoints=[]; + + public constructor() { + super("journey_stage", 1); + + this.WayPoints = []; + } +} + +export class Journey extends JourneyBaseItem { + + public ID: string; + + public Stages: Array; + + + + public constructor() { + super("journey", 1); + this.ID = "" + Date.now(); + this.Stages = []; + } } \ No newline at end of file diff --git a/App/Ionic2/ocm-app/app/core/ocm/model/SyncItem.ts b/App/Ionic2/ocm-app/app/core/ocm/model/SyncItem.ts new file mode 100644 index 0000000..e6ea067 --- /dev/null +++ b/App/Ionic2/ocm-app/app/core/ocm/model/SyncItem.ts @@ -0,0 +1,23 @@ +export class SyncItem { + + public itemType: string; + public itemId: string; + public version: number; + public schemaVersion: number; + public syncTimeStamp: string; + + public constructor(itemType: string, schemaVersion: number) { + this.itemType = itemType; + this.itemId = SyncItem.getNewItemId(); + this.version = 1; + this.schemaVersion = schemaVersion; + this.syncTimeStamp = SyncItem.getNewSyncTimeStamp(); + + } + public static getNewSyncTimeStamp() { + return Date.now().toString(); + } + public static getNewItemId() { + return "_syncitem_" + Date.now().toString(); + } +} \ No newline at end of file diff --git a/App/Ionic2/ocm-app/app/core/ocm/services/AppManager.ts b/App/Ionic2/ocm-app/app/core/ocm/services/AppManager.ts index 32254da..3657d1f 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/services/AppManager.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/services/AppManager.ts @@ -11,18 +11,13 @@ import {JwtHelper} from 'angular2-jwt'; import {UserProfile, SubmissionType, SearchSettings, Journey, WayPoint, GeoLatLng} from '../model/AppModels' import {SubmissionQueue} from './SubmissionQueue'; import {ReferenceDataManager} from './ReferenceDataManager'; -import {POIManager} from './POIManager'; import {JourneyManager} from './JourneyManager'; @Injectable() - export class AppManager extends Base { jwtHelper = new JwtHelper(); enableSubmissionQueue: boolean; - public referenceDataManager: ReferenceDataManager; - public journeyManager : JourneyManager; - public poiManager: POIManager; public searchSettings: SearchSettings; public platformMode: string; public journeys: Array; @@ -35,7 +30,7 @@ export class AppManager extends Base { public isRequestInProgress: boolean = false; - constructor(public http: Http, public events: Events, public api: APIClient, public submissionQueue: SubmissionQueue, private platform: Platform) { + constructor(public http: Http, public events: Events, public api: APIClient, public submissionQueue: SubmissionQueue, private platform: Platform, public referenceDataManager: ReferenceDataManager, public journeyManager: JourneyManager) { super(); this.api.clientName = "ocm.app.ionic.v6_0_0"; this.isDebugMode = false; @@ -48,15 +43,17 @@ export class AppManager extends Base { this.platformMode = "web"; } - this.referenceDataManager = new ReferenceDataManager(http); - this.journeyManager = new JourneyManager(); - this.poiManager = new POIManager(this); + // this.referenceDataManager = new ReferenceDataManager(http); + + // this.poiManager = new POIManager(this); this.searchSettings = new SearchSettings(); this.loadSearchSettings(); - this.journeyManager.setupTestJourneys(); + + //this.journeyManager.setupTestJourneys(); + this.journeyManager.loadJourneys(); } /** 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 61be473..06e1548 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/services/JourneyManager.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/services/JourneyManager.ts @@ -7,27 +7,176 @@ import {Injectable} from '@angular/core'; import {Base, LogLevel} from '../Base'; import {AppManager} from './AppManager'; import {Http, Response} from '@angular/http'; -import {Journey, WayPoint, GeoLatLng} from '../model/AppModels'; +import {APIClient} from './APIClient'; +import {POIManager} from './POIManager'; +import {Journey, JourneyStage, WayPoint, BookmarkedPOI, GeoLatLng, SyncItem, POISearchParams} from '../model/AppModels'; @Injectable() - /** - * Manage access to Journey information + * Manage access to Journey information. Journeys are a collection of journey Stages, each with multiple WayPoints. Each WayPoint has one or more optional Bookmarked POIs. */ export class JourneyManager extends Base { public journeys: Array; - - constructor() { + public favourites: Array; + constructor(private api: APIClient, private poiManager: POIManager) { super(); this.journeys = []; + this.favourites = []; } + public loadJourneys() { //load journeys from local cache, then check for newer server copy + let journeyJson = localStorage.getItem("journeys"); + if (journeyJson != null) { + this.journeys = JSON.parse(journeyJson); + + } + + //TODO: check server, reconcile sync + + //load POI Details + + if (this.journeys != null) { + for (var j of this.journeys) { + //attempt to populate POI details of each journey waypoint + this.fetchAllJourneyPOIDetails(j); + } + } + } + + /** + * For a given journey, fetch the full POI details for all WayPoints + */ + public fetchAllJourneyPOIDetails(journey: Journey) { + + this.log("Journeys - fetching poi details for Journey " + journey.Title); + let searchParams = new POISearchParams(); + searchParams.poiIdList = []; + + //gather list of POIs to fetch details for + for (let s of journey.Stages) { + for (let w of s.WayPoints) { + for (let p of w.PoiIDs) { + searchParams.poiIdList.push(p); + } + } + } + + this.api.fetchPOIListByParam(searchParams, this.poiManager).subscribe((results) => { + //populate journeys with POI details + for (let poi of results) { + this.updateStoredPOI(poi); + } + }); + } + + /** Update details of a POI if ti occurs in a jounrey or favourites */ + 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); + } + } + } + } + } + } + } + } + } + + + //update all favourites with latest info + if (this.favourites != null) { + for (let f of this.favourites) { + if (f.Type == "charging" && f.PoiID == poi.ID) { + f.Poi = poi; + } + } + } + } public saveJourneys() { //save to local cache, then save to server copy + let cloneOfJourneys = >JSON.parse(JSON.stringify(this.journeys)); + //remove waypoint POI references + for (let j of cloneOfJourneys) { + for (let s of j.Stages) { + for (let w of s.WayPoints) { + w.PoiList = null; + } + } + } + var journeyString = JSON.stringify(cloneOfJourneys); + localStorage.setItem("journeys", journeyString); + + //TODO: send to server, merge synce and get results + } + + + /** + * Add new journey wtih a default single stagem, optionally adding the given Waypoint + */ + public addJourney(journey: Journey, waypoint?: WayPoint) { + + + var newStage: JourneyStage = new JourneyStage(); + newStage.Title = "Stage 1"; + if (waypoint != null) { + newStage.WayPoints.push(waypoint); + } + 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); + this.saveJourneys(); + } + + /** + * Get a journey by the given ID + */ + public getJourney(journeyId: string) { + let j = this.journeys.filter(j => j.ID == journeyId); + if (j.length > 0) { + let journey = j[0]; + return journey; + } else { + return null; + } + } + + /** + * 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); + } + + /** + * Add a journey stage and return the new index of the Stage + */ + public addJourneyStage(journeyId: string, stage: JourneyStage): number { + let journey = this.getJourney(journeyId); + var numStages = journey.Stages.push(stage); + return numStages - 1; } public setupTestJourneys() { @@ -37,25 +186,30 @@ export class JourneyManager extends Base { journey1.Title = "New York to Brooklyn"; journey1.Notes = "A little jaunt to Brooklyn"; - journey1.WayPoints = []; + journey1.Stages = []; + + let stage1 = new JourneyStage(); let waypoint1 = new WayPoint(); waypoint1.Notes = "Starting point"; waypoint1.Position = new GeoLatLng(40, 1.2); waypoint1.Title = "Start"; - journey1.WayPoints.push(waypoint1); + + stage1.WayPoints.push(waypoint1); let waypoint2 = new WayPoint(); waypoint2.Notes = "Middle point"; waypoint2.Position = new GeoLatLng(40, 1.33); waypoint2.Title = "Middle"; - journey1.WayPoints.push(waypoint2); + stage1.WayPoints.push(waypoint2); let waypoint3 = new WayPoint(); waypoint3.Notes = "End point"; waypoint3.Position = new GeoLatLng(40, 1.33); waypoint3.Title = "End"; - journey1.WayPoints.push(waypoint3); + stage1.WayPoints.push(waypoint3); + + journey1.Stages.push(stage1); this.journeys.push(journey1); //////// @@ -63,7 +217,8 @@ export class JourneyManager extends Base { let journey2 = new Journey(); journey2.Title = "Aberdeen to London"; journey2.Notes = "Roadtrip"; - journey2.WayPoints = []; + journey2.Stages = []; + this.journeys.push(journey2); } diff --git a/App/Ionic2/ocm-app/app/core/ocm/services/POIManager.ts b/App/Ionic2/ocm-app/app/core/ocm/services/POIManager.ts index b29a1be..255db52 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/services/POIManager.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/services/POIManager.ts @@ -3,44 +3,47 @@ * @copyright Webprofusion Ltd http://webprofusion.com */ import {AppManager} from './AppManager'; -import {Injectable} from '@angular/core'; +import {Injectable, Inject} from '@angular/core'; +import {Events} from 'ionic-angular'; import {Observable} from 'rxjs/Observable'; import {Base, LogLevel} from '../Base'; import {POISearchParams} from '../Model/AppModels'; - +import {APIClient} from './APIClient'; +import {ReferenceDataManager} from './ReferenceDataManager'; @Injectable() - export class POIManager extends Base { poiList; - constructor(private appManager: AppManager) { + isRequestInProgress:boolean=false; + + constructor(private api:APIClient, private events:Events, private referenceDataManager:ReferenceDataManager) { super(); } public fetchPOIList(searchParams: POISearchParams) { - this.appManager.isRequestInProgress = true; - this.appManager.api.fetchPOIListByParam(searchParams, this) + this.isRequestInProgress = true; + this.api.fetchPOIListByParam(searchParams, this) .subscribe( (results) => { console.log('fetched POI list:'); this.poiList = results; - this.appManager.events.publish('ocm:poiList:updated'); - this.appManager.isRequestInProgress = false; + this.events.publish('ocm:poiList:updated'); + //this.appManager.isRequestInProgress = false; }, (reason) => { //alert(JSON.stringify(reason)); - this.appManager.isRequestInProgress = false; + this.isRequestInProgress = false; } ); } public clearResults() { this.poiList = []; - this.appManager.events.publish('ocm:poiList:cleared'); + this.events.publish('ocm:poiList:cleared'); this.log('clearing results after settings change', LogLevel.VERBOSE); } @@ -65,14 +68,14 @@ export class POIManager extends Base { //still not found it, fetch via api var params = new POISearchParams(); params.poiIdList = [poiId]; - return this.appManager.api.fetchPOIListByParam(params, this); + return this.api.fetchPOIListByParam(params, this); } hydrateCompactPOI(poi: any): Array { - let refData = this.appManager.referenceDataManager; + let refData = this.referenceDataManager; if (poi.DataProviderID != null && poi.DataProvider == null) { poi.DataProvider = refData.getDataProviderByID(poi.DataProviderID); diff --git a/App/Ionic2/ocm-app/app/core/ocm/services/ReferenceDataManager.ts b/App/Ionic2/ocm-app/app/core/ocm/services/ReferenceDataManager.ts index 1bae371..3235d70 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/services/ReferenceDataManager.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/services/ReferenceDataManager.ts @@ -10,7 +10,6 @@ import {Http, Response} from '@angular/http'; import {CoreReferenceData} from '../model/CoreReferenceData'; @Injectable() - /** * Manage access to OCM reference data and filtered reference (country specific etc)) */ diff --git a/App/Ionic2/ocm-app/app/core/ocm/services/SubmissionQueue.ts b/App/Ionic2/ocm-app/app/core/ocm/services/SubmissionQueue.ts index 5bf51fe..9d1f624 100644 --- a/App/Ionic2/ocm-app/app/core/ocm/services/SubmissionQueue.ts +++ b/App/Ionic2/ocm-app/app/core/ocm/services/SubmissionQueue.ts @@ -7,8 +7,8 @@ import {Injectable} from '@angular/core'; import {Events} from 'ionic-angular'; import {Base, LogLevel} from '../Base'; import {SubmissionQueueItem, SubmissionType} from '../model/AppModels'; -@Injectable() +@Injectable() export class SubmissionQueue extends Base { public isQueueProcessing: boolean; 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 ecf11c4..586e12d 100644 --- a/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.html +++ b/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.html @@ -21,6 +21,14 @@

{{poi.AddressInfo.Title}}

{{journey.Title}} + + + Journey Stage + + Create a Journey Stage + {{stage.Title}} + + New Journey Name 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 d3b9e92..fa099d7 100644 --- a/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.ts +++ b/App/Ionic2/ocm-app/app/pages/journeys/favourite-editor.ts @@ -12,7 +12,9 @@ import {Journey, WayPoint, GeoLatLng} from '../../core/ocm/model/AppModels'; export class FavouriteEditorPage { selectedJourneyID; + selectedStageIndex:number; newJourneyName: string; + waypoint: WayPoint; poi; @@ -21,9 +23,9 @@ export class FavouriteEditorPage { 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.PoiIDs = [this.poi.ID]; this.waypoint.PoiList = [this.poi]; - + this.newJourneyName = "Trip to " + this.poi.AddressInfo.Title; } @@ -33,33 +35,31 @@ export class FavouriteEditorPage { } add() { -//TODO: validation + //TODO: validation //store new waypoint in journey - if (this.selectedJourneyID != null) { - + if (this.selectedJourneyID != null && this.selectedJourneyID != "") { + //TODO: should be injected instance of JourneyManager instead of via appManager - let j = this.appManager.journeyManager.journeys.filter(j => j.ID == this.selectedJourneyID); - if (j.length > 0) { - let journey = j[0]; - //add waypoint to existing journey - journey.WayPoints.push(this.waypoint); - } + this.appManager.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.ID = Date.now().toString(); + if (this.newJourneyName == "") this.newJourneyName = "New Journey"; journey.Title = this.newJourneyName; - journey.WayPoints = []; - journey.WayPoints.push(this.waypoint); - + + //add new journey - - this.appManager.journeyManager.journeys.push(journey); - + + this.appManager.journeyManager.addJourney(journey, this.waypoint); + } + //todo: async promise for server save + this.appManager.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 47a33bb..9d15295 100644 --- a/App/Ionic2/ocm-app/app/pages/journeys/journeys.html +++ b/App/Ionic2/ocm-app/app/pages/journeys/journeys.html @@ -7,26 +7,39 @@

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.Title}} - + + + +

{{journey.Notes}}

- - -