JGirault has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/324843

Change subject: Implement third phase of event logging (Wikivoyage specific)
......................................................................

Implement third phase of event logging (Wikivoyage specific)

* Data layers now have a convenient reference to their corresponding data group

Bug: T151929
Change-Id: I2545a2258dfc3772acf56a5c0589002e18be1b30
---
M modules/box/Map.js
M modules/wikivoyage/ControlLayers.js
M modules/wikivoyage/ControlNearby.js
M modules/wikivoyage/WVMapLayers.js
M modules/wikivoyage/wikivoyage.js
5 files changed, 77 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Kartographer 
refs/changes/43/324843/1

diff --git a/modules/box/Map.js b/modules/box/Map.js
index 9de5370..7309392 100644
--- a/modules/box/Map.js
+++ b/modules/box/Map.js
@@ -296,7 +296,8 @@
 
                        if ( this.parentMap ) {
                                $.each( this.parentMap.dataLayers, function ( 
groupId, layer ) {
-                                       map.addGeoJSONLayer( groupId, 
layer.getGeoJSON(), layer.options );
+                                       var newLayer = map.addGeoJSONLayer( 
groupId, layer.getGeoJSON(), layer.options );
+                                       newLayer.dataGroup = layer.group;
                                } );
                                ready();
                                return;
@@ -387,13 +388,15 @@
 
                                $.each( dataGroups, function ( key, group ) {
                                        var layerOptions = {
-                                               attribution: group.attribution
-                                       };
+                                                       attribution: 
group.attribution
+                                               },
+                                               layer;
                                        if ( group.isExternal ) {
                                                layerOptions.name = 
group.attribution;
                                        }
                                        if ( !$.isEmptyObject( 
group.getGeoJSON() ) ) {
-                                               map.addGeoJSONLayer( group.id, 
group.getGeoJSON(), layerOptions );
+                                               layer = map.addGeoJSONLayer( 
group.id, group.getGeoJSON(), layerOptions );
+                                               layer.dataGroup = group;
                                        } else {
                                                mw.log.warn( 'Layer not found 
or contains no data: "' + group.id + '"' );
                                        }
@@ -423,12 +426,14 @@
                                        var groupId = inlineDataLayerKey + 
inlineDataLayerId++,
                                                layerOptions = {
                                                        attribution: 
group.attribution || options.attribution
-                                               };
+                                               },
+                                               layer;
                                        if ( group.isExternal ) {
                                                layerOptions.name = 
group.attribution;
                                        }
                                        if ( !$.isEmptyObject( 
group.getGeoJSON() ) ) {
-                                               map.addGeoJSONLayer( groupId, 
group.getGeoJSON(), layerOptions );
+                                               layer = map.addGeoJSONLayer( 
groupId, group.getGeoJSON(), layerOptions );
+                                               layer.dataGroup = layer;
                                        } else {
                                                mw.log.warn( 'Layer not found 
or contains no data: "' + groupId + '"' );
                                        }
diff --git a/modules/wikivoyage/ControlLayers.js 
b/modules/wikivoyage/ControlLayers.js
index de20388..351d3ca 100644
--- a/modules/wikivoyage/ControlLayers.js
+++ b/modules/wikivoyage/ControlLayers.js
@@ -33,6 +33,9 @@
                        if ( !obj.overlay && label.childNodes[ 0 ].checked ) {
                                this._previousSelected = label.childNodes[ 0 ];
                        }
+                       if ( obj.layer.dataGroup ) {
+                               label.childNodes[ 0 ].className += ' 
leaflet-control-layers-data-layer';
+                       }
                },
 
                /**
@@ -41,6 +44,7 @@
                 */
                _onInputClick: function ( event ) {
                        var self = this,
+                               map = this._map,
                                proto = 
L.Control.Layers.prototype._onInputClick,
                                input = event && event.target,
                                obj;
@@ -59,7 +63,7 @@
                                        }
                                        input.checked = false;
                                        this._expand();
-                                       wikivoyage.isAllowed( obj.layer )
+                                       wikivoyage.isAllowed( obj.layer, map )
                                                .done( function () {
                                                        input.checked = true;
                                                        proto.call( self );
diff --git a/modules/wikivoyage/ControlNearby.js 
b/modules/wikivoyage/ControlNearby.js
index 5a74bda..e96bbff 100644
--- a/modules/wikivoyage/ControlNearby.js
+++ b/modules/wikivoyage/ControlNearby.js
@@ -76,7 +76,7 @@
 
                        this.map = map;
                        this.link = link;
-                       this.pruneCluster = pruneCluster;
+                       this.map._pruneCluster = this.pruneCluster = 
pruneCluster;
 
                        L.DomEvent.addListener( link, 'click', 
this._onToggleNearbyLayer, this );
                        L.DomEvent.disableClickPropagation( container );
@@ -173,7 +173,7 @@
                        enabled = ( enabled !== undefined ) ? enabled : 
this.isEnabled();
 
                        if ( !enabled ) {
-                               wikivoyage.isAllowed( this.pruneCluster )
+                               wikivoyage.isAllowed( this.pruneCluster, 
this.map )
                                        .done( function () {
                                                control.map.addLayer( 
control.pruneCluster );
                                        } );
@@ -189,9 +189,20 @@
                _toggleDataLayers: function ( enabled ) {
                        var control = this;
 
+                       // Toggling this layer toggles data layers. We do not 
want to trigger
+                       // events like if the user manually toggled these 
layers. That's why this
+                       // boolean is temporarily set.
+                       control.map._preventTracking = true;
+
                        $.each( control.map.dataLayers, function ( group, layer 
) {
                                control.map[ enabled ? 'addLayer' : 
'removeLayer' ]( layer );
                        } );
+
+                       control.map.$container.find( 
'.leaflet-control-layers-data-layer' ).each( function () {
+                               $( this ).prop( 'checked', enabled );
+                       } );
+
+                       control.map._preventTracking = false;
                }
        } );
 }(
diff --git a/modules/wikivoyage/WVMapLayers.js 
b/modules/wikivoyage/WVMapLayers.js
index dd18a37..cbb11ac 100644
--- a/modules/wikivoyage/WVMapLayers.js
+++ b/modules/wikivoyage/WVMapLayers.js
@@ -20,6 +20,37 @@
                        this.map.wikimediaLayer,
                        wikivoyage.formatLayerName( mw.msg( 
'kartographer-wv-layer-wikimedia' ), { wvIsWMF: true } )
                );
+
+               this.map.on( 'baselayerchange', function ( event ) {
+                       mw.track( 'mediawiki.kartographer', {
+                               action: ( event.layer === map.wikimediaLayer ) 
? 'wv-select-wmflayer' : 'wv-select-exlayer',
+                               isFullScreen: !!map.options.fullscreen,
+                               feature: map
+                       } );
+               } );
+
+               this.map.on( 'overlayadd overlayremove', function ( event ) {
+                       var add = ( event.type === 'overlayadd' ),
+                               eventName;
+
+                       if ( event.layer.dataGroup ) {
+                               eventName = add ? 'wv-show-layer' : 
'wv-hide-layer';
+                       } else if ( event.layer === map._pruneCluster ) {
+                               eventName = add ? 'wv-show-nearby' : 
'wv-hide-nearby';
+                       } else {
+                               eventName = add ? 'wv-show-exlayer' : 
'wv-hide-exlayer';
+                       }
+
+                       if ( map._preventTracking ) {
+                               return;
+                       }
+
+                       mw.track( 'mediawiki.kartographer', {
+                               action: eventName,
+                               isFullScreen: !!map.options.fullscreen,
+                               feature: map
+                       } );
+               } );
        };
 
        // eslint-disable-next-line valid-jsdoc
diff --git a/modules/wikivoyage/wikivoyage.js b/modules/wikivoyage/wikivoyage.js
index 63fcad8..f25f565 100644
--- a/modules/wikivoyage/wikivoyage.js
+++ b/modules/wikivoyage/wikivoyage.js
@@ -105,9 +105,10 @@
                 * so the user won't be prompted with a confirmation dialog 
anymore.
                 *
                 * @param {L.GeoJSON} layer
+                * @param {Kartographer.Map} map
                 * @return {jQuery.Promise}
                 */
-               isAllowed: function ( layer ) {
+               isAllowed: function ( layer, map ) {
                        var deferred = $.Deferred();
 
                        mw.loader.using( 'mediawiki.storage' ).then( function 
() {
@@ -119,14 +120,29 @@
                                if ( !layer.options.wvIsExternal || 
areExternalAllowed ) {
                                        deferred.resolve();
                                } else {
+                                       mw.track( 'mediawiki.kartographer', {
+                                               action: 'wv-warn',
+                                               isFullScreen: 
!!map.options.fullscreen,
+                                               feature: map
+                                       } );
                                        alertExternalData()
                                                .then( function ( opened ) {
                                                        opened.then( function ( 
closing, data ) {
                                                                if ( data && 
data.action && data.action === 'good' ) {
                                                                        
areExternalAllowed = true;
                                                                        
mw.storage.set( STORAGE_KEY, '1' );
+                                                                       
mw.track( 'mediawiki.kartographer', {
+                                                                               
action: 'wv-warn-agree',
+                                                                               
isFullScreen: !!map.options.fullscreen,
+                                                                               
feature: map
+                                                                       } );
                                                                        
deferred.resolve();
                                                                } else {
+                                                                       
mw.track( 'mediawiki.kartographer', {
+                                                                               
action: 'wv-warn-reject',
+                                                                               
isFullScreen: !!map.options.fullscreen,
+                                                                               
feature: map
+                                                                       } );
                                                                        
deferred.reject();
                                                                }
                                                        } );

-- 
To view, visit https://gerrit.wikimedia.org/r/324843
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2545a2258dfc3772acf56a5c0589002e18be1b30
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: JGirault <julien.inbox.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to