From 49f5c4ce3b74c66428dede38978145fad37433ef Mon Sep 17 00:00:00 2001 From: steveszc Date: Thu, 13 Apr 2017 15:54:17 -0600 Subject: [PATCH 1/4] standardize this._super calls --- addon/components/g-map-address-route.js | 2 +- addon/components/g-map-infowindow.js | 4 ++-- addon/components/g-map-marker.js | 4 ++-- addon/components/g-map-polyline-coordinate.js | 4 ++-- addon/components/g-map-polyline.js | 4 ++-- addon/components/g-map-route-address-waypoint.js | 2 +- addon/components/g-map-route-waypoint.js | 4 ++-- addon/components/g-map-route.js | 4 ++-- addon/components/g-map.js | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/addon/components/g-map-address-route.js b/addon/components/g-map-address-route.js index 8d7bc92..ebcc8ee 100644 --- a/addon/components/g-map-address-route.js +++ b/addon/components/g-map-address-route.js @@ -11,7 +11,7 @@ const GMapAddressRouteComponent = Ember.Component.extend({ map: computed.alias('mapContext.map'), didInsertElement() { - this._super(); + this._super(...arguments); this.initPlacesService(); }, diff --git a/addon/components/g-map-infowindow.js b/addon/components/g-map-infowindow.js index 1c21ef8..30f6155 100644 --- a/addon/components/g-map-infowindow.js +++ b/addon/components/g-map-infowindow.js @@ -20,7 +20,7 @@ const GMapInfowindowComponent = Ember.Component.extend({ marker: computed.alias('mapContext.marker'), init() { - this._super(arguments); + this._super(...arguments); const mapContext = this.get('mapContext'); const hasMap = mapContext instanceof GMapComponent; @@ -32,7 +32,7 @@ const GMapInfowindowComponent = Ember.Component.extend({ }, didInsertElement() { - this._super(); + this._super(...arguments); if (isEmpty(this.get('infowindow'))) { const infowindow = this.buildInfowindow(); this.set('infowindow', infowindow); diff --git a/addon/components/g-map-marker.js b/addon/components/g-map-marker.js index 5ef7386..5943898 100644 --- a/addon/components/g-map-marker.js +++ b/addon/components/g-map-marker.js @@ -11,7 +11,7 @@ const GMapMarkerComponent = Ember.Component.extend({ map: computed.alias('mapContext.map'), init() { - this._super(arguments); + this._super(...arguments); this.infowindow = null; if (isEmpty(this.get('group'))) { this.set('group', null); @@ -24,7 +24,7 @@ const GMapMarkerComponent = Ember.Component.extend({ }, didInsertElement() { - this._super(); + this._super(...arguments); if (isEmpty(this.get('marker')) && (typeof FastBoot === 'undefined')) { const marker = new google.maps.Marker(); diff --git a/addon/components/g-map-polyline-coordinate.js b/addon/components/g-map-polyline-coordinate.js index 747515c..8e0ae98 100644 --- a/addon/components/g-map-polyline-coordinate.js +++ b/addon/components/g-map-polyline-coordinate.js @@ -11,7 +11,7 @@ const GMapPolylineCoordinateComponent = Ember.Component.extend({ polyline: computed.alias('polylineContext.polyline'), init() { - this._super(arguments); + this._super(...arguments); const polylineContext = this.get('polylineContext'); assert('Must be inside {{#g-map-polyline}} component with context set', @@ -21,7 +21,7 @@ const GMapPolylineCoordinateComponent = Ember.Component.extend({ }, didInsertElement() { - this._super(); + this._super(...arguments); if (isEmpty(this.get('coordinate'))) { const coordinate = new google.maps.LatLng(); this.set('coordinate', coordinate); diff --git a/addon/components/g-map-polyline.js b/addon/components/g-map-polyline.js index d87b697..6b93997 100644 --- a/addon/components/g-map-polyline.js +++ b/addon/components/g-map-polyline.js @@ -14,7 +14,7 @@ const GMapPolylineComponent = Ember.Component.extend({ map: computed.alias('mapContext.map'), init() { - this._super(arguments); + this._super(...arguments); this.infowindow = null; this.set('coordinates', Ember.A()); if (isEmpty(this.get('group'))) { @@ -28,7 +28,7 @@ const GMapPolylineComponent = Ember.Component.extend({ }, didInsertElement() { - this._super(); + this._super(...arguments); if (isEmpty(this.get('polyline'))) { const options = compact(this.getProperties(allowedPolylineOptions)); const polyline = new google.maps.Polyline(options); diff --git a/addon/components/g-map-route-address-waypoint.js b/addon/components/g-map-route-address-waypoint.js index ad22423..1b56aea 100644 --- a/addon/components/g-map-route-address-waypoint.js +++ b/addon/components/g-map-route-address-waypoint.js @@ -10,7 +10,7 @@ const GMapRouteAddressWaypointComponent = Ember.Component.extend({ map: computed.alias('routeContext.map'), didInsertElement() { - this._super(); + this._super(...arguments); this.initPlacesService(); }, diff --git a/addon/components/g-map-route-waypoint.js b/addon/components/g-map-route-waypoint.js index ad0e397..6191438 100644 --- a/addon/components/g-map-route-waypoint.js +++ b/addon/components/g-map-route-waypoint.js @@ -11,7 +11,7 @@ const GMapRouteWaypointComponent = Ember.Component.extend({ map: computed.alias('routeContext.map'), init() { - this._super(arguments); + this._super(...arguments); if (isEmpty(this.stopover)) { this.stopover = true; } @@ -22,7 +22,7 @@ const GMapRouteWaypointComponent = Ember.Component.extend({ }, didInsertElement() { - this._super(); + this._super(...arguments); this.updateWaypoint(); }, diff --git a/addon/components/g-map-route.js b/addon/components/g-map-route.js index 38622cf..ad59150 100644 --- a/addon/components/g-map-route.js +++ b/addon/components/g-map-route.js @@ -22,14 +22,14 @@ const GMapRouteComponent = Ember.Component.extend({ map: computed.alias('mapContext.map'), init() { - this._super(arguments); + this._super(...arguments); this.set('waypoints', Ember.A()); const mapContext = this.get('mapContext'); assert('Must be inside {{#g-map}} component with context set', mapContext instanceof GMapComponent); }, didInsertElement() { - this._super(); + this._super(...arguments); this.initDirectionsService(); }, diff --git a/addon/components/g-map.js b/addon/components/g-map.js index 083b475..d02e64a 100644 --- a/addon/components/g-map.js +++ b/addon/components/g-map.js @@ -9,7 +9,7 @@ export default Ember.Component.extend({ bannedOptions: Ember.A(['center', 'zoom']), init() { - this._super(); + this._super(...arguments); this.set('markers', Ember.A()); this.set('polylines', Ember.A()); if (isEmpty(this.get('options'))) { @@ -29,7 +29,7 @@ export default Ember.Component.extend({ }), didInsertElement() { - this._super(); + this._super(...arguments); if (isEmpty(this.get('map')) && (typeof FastBoot === 'undefined')) { const canvas = this.$().find('.g-map-canvas').get(0); From 74988b71f057b316e164edbce4bb4f9c8ab170ec Mon Sep 17 00:00:00 2001 From: steveszc Date: Thu, 13 Apr 2017 16:29:53 -0600 Subject: [PATCH 2/4] Add onOpen handler to info-window, with tests, documentation --- README.md | 6 ++- addon/components/g-map-infowindow.js | 13 ++++++ .../unit/components/g-map-infowindow-test.js | 41 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab3a38f..07c4a80 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ ENV['g-map'] = { libraries: ['places', 'geometry'], key: 'your-unique-google-map-api-key', client: 'gme-your-unique-google-client-id', + channel: 'my-google-map-api-channel', version: '3.26', language: 'ru', protocol: 'https' @@ -120,8 +121,7 @@ myIcon: { ## Map with Info Windows These Info Windows will be open right after component is rendered -and will be closed forever after user closes them. You can specify -optional `onClose` action to tear down anything you need when Info Window +and will be closed forever after user closes them. You can specify optional `onOpen` action to trigger anything you need to when the Info Window has been opened by the user. You can specify optional `onClose` action to tear down anything you need when Info Window has been closed by user. Available options (see details [in docs](https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoWindowOptions)): @@ -140,9 +140,11 @@ Available options (see details [in docs](https://developers.google.com/maps/docu title="Blockless form" message="Plain text."}} {{g-map-infowindow context lat=37.7733 lng=-122.4067 title="With action set" + onOpen="myOnOpenAction" onClose="myOnCloseAction"}} {{g-map-infowindow context lat=37.7733 lng=-122.4067 title="With closure action set" + onClose=(action "myOnOpenAction") onClose=(action "myOnCloseAction")}} {{/g-map}} ``` diff --git a/addon/components/g-map-infowindow.js b/addon/components/g-map-infowindow.js index 30f6155..de91d6f 100644 --- a/addon/components/g-map-infowindow.js +++ b/addon/components/g-map-infowindow.js @@ -70,6 +70,10 @@ const GMapInfowindowComponent = Ember.Component.extend({ content: this.get('element') }); + if (isPresent(this.get('attrs.onOpen'))) { + infowindow.addListener('domready', () => this.handleOpenClickEvent()); + } + if (isPresent(this.get('attrs.onClose'))) { infowindow.addListener('closeclick', () => this.handleCloseClickEvent()); } @@ -77,6 +81,15 @@ const GMapInfowindowComponent = Ember.Component.extend({ } }, + handleOpenClickEvent() { + const { onOpen } = this.attrs; + if (typeOf(onOpen) === 'function') { + onOpen(); + } else { + this.sendAction('onOpen', this); + } + }, + handleCloseClickEvent() { const { onClose } = this.attrs; if (typeOf(onClose) === 'function') { diff --git a/tests/unit/components/g-map-infowindow-test.js b/tests/unit/components/g-map-infowindow-test.js index 643ee32..dc5585b 100644 --- a/tests/unit/components/g-map-infowindow-test.js +++ b/tests/unit/components/g-map-infowindow-test.js @@ -102,6 +102,14 @@ test('it constructs new `InfoWindow` object during `buildInfowindow`', function( assert.equal(returnedInfowindow, fakeInfowindowObject); }); +test('it triggers `addListener` of infowindow during `buildInfowindow` if onOpen attr specified', function() { + run(() => component.set('attrs', { onOpen: 'action' })); + run(() => component.buildInfowindow()); + + sinon.assert.calledOnce(fakeInfowindowObject.addListener); + sinon.assert.calledWith(fakeInfowindowObject.addListener, 'domready'); +}); + test('it triggers `addListener` of infowindow during `buildInfowindow` if onClose attr specified', function() { run(() => component.set('attrs', { onClose: 'action' })); run(() => component.buildInfowindow()); @@ -110,12 +118,28 @@ test('it triggers `addListener` of infowindow during `buildInfowindow` if onClos sinon.assert.calledWith(fakeInfowindowObject.addListener, 'closeclick'); }); +test('it doesn\'t trigger `addListener` during `buildInfowindow` if onOpen isn\'t specified', function() { + run(() => component.set('attrs', { onOpen: undefined })); + run(() => component.buildInfowindow()); + sinon.assert.notCalled(fakeInfowindowObject.addListener); +}); + test('it doesn\'t trigger `addListener` during `buildInfowindow` if onClose isn\'t specified', function() { run(() => component.set('attrs', { onClose: undefined })); run(() => component.buildInfowindow()); sinon.assert.notCalled(fakeInfowindowObject.addListener); }); +test('it triggers `handleOpenClickEvent` on callback for `domready` event', function() { + fakeInfowindowObject.addListener.callsArg(1); + component.handleOpenClickEvent = sinon.stub(); + + run(() => component.set('attrs', { onOpen: 'action' })); + run(() => component.buildInfowindow()); + + sinon.assert.calledOnce(component.handleOpenClickEvent); +}); + test('it triggers `handleCloseClickEvent` on callback for `closeclick` event', function() { fakeInfowindowObject.addListener.callsArg(1); component.handleCloseClickEvent = sinon.stub(); @@ -126,6 +150,16 @@ test('it triggers `handleCloseClickEvent` on callback for `closeclick` event', f sinon.assert.calledOnce(component.handleCloseClickEvent); }); +test('it sends action `onOpen` on `handleOpenClickEvent`', function() { + component.sendAction = sinon.stub(); + + run(() => component.set('attrs', { onOpen: 'action' })); + run(() => component.handleOpenClickEvent()); + + sinon.assert.calledOnce(component.sendAction); + sinon.assert.calledWith(component.sendAction, 'onOpen'); +}); + test('it sends action `onClose` on `handleCloseClickEvent`', function() { component.sendAction = sinon.stub(); @@ -136,6 +170,13 @@ test('it sends action `onClose` on `handleCloseClickEvent`', function() { sinon.assert.calledWith(component.sendAction, 'onClose'); }); +test('it runs closure action `attrs.onOpen` directly on `handleOpenClickEvent`', function() { + run(() => component.set('attrs', { onOpen: sinon.stub() })); + run(() => component.handleOpenClickEvent()); + + sinon.assert.calledOnce(component.attrs.onOpen); +}); + test('it runs closure action `attrs.onClose` directly on `handleCloseClickEvent`', function() { run(() => component.set('attrs', { onClose: sinon.stub() })); run(() => component.handleCloseClickEvent()); From 8b35f722a23df22b6a30601292f3bbec4e132185 Mon Sep 17 00:00:00 2001 From: steveszc Date: Thu, 13 Apr 2017 16:34:10 -0600 Subject: [PATCH 3/4] fix readme typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07c4a80..f194a20 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ Available options (see details [in docs](https://developers.google.com/maps/docu onClose="myOnCloseAction"}} {{g-map-infowindow context lat=37.7733 lng=-122.4067 title="With closure action set" - onClose=(action "myOnOpenAction") + onOpen=(action "myOnOpenAction") onClose=(action "myOnCloseAction")}} {{/g-map}} ``` From 16904ceaf18f39d1a103bc825770b8a0f5f71acf Mon Sep 17 00:00:00 2001 From: steveszc Date: Fri, 14 Apr 2017 08:47:36 -0600 Subject: [PATCH 4/4] improve documentation for infowindow onOpen --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f194a20..f8640c9 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ myIcon: { ## Map with Info Windows These Info Windows will be open right after component is rendered -and will be closed forever after user closes them. You can specify optional `onOpen` action to trigger anything you need to when the Info Window has been opened by the user. You can specify optional `onClose` action to tear down anything you need when Info Window +and will be closed forever after user closes them. You can specify optional `onOpen` action to trigger anything you need to when the Info Window opens. The infowindow is passed as the only argument to the `onOpen` action. You can specify optional `onClose` action to tear down anything you need when Info Window has been closed by user. Available options (see details [in docs](https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoWindowOptions)):