jenkins-bot has submitted this change and it was merged.

Change subject: Hygiene: Refactor wikiGrokCampaigns code
......................................................................


Hygiene: Refactor wikiGrokCampaigns code

* Remove unused $
* Move campaign.suggestions code to WikiGrokDialogB
* Update documentation and tests

Change-Id: I0d09e8637b0f0815c261edb72233ae0aa86ad310
---
M javascripts/modules/wikigrok/WikiGrokDialogB.js
M javascripts/modules/wikigrok/wikiGrokCampaigns.js
M tests/qunit/modules/wikigrok/test_wikiGrokCampaigns.js
3 files changed, 14 insertions(+), 14 deletions(-)

Approvals:
  Kaldari: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/javascripts/modules/wikigrok/WikiGrokDialogB.js 
b/javascripts/modules/wikigrok/WikiGrokDialogB.js
index 8bd0493..24726d9 100644
--- a/javascripts/modules/wikigrok/WikiGrokDialogB.js
+++ b/javascripts/modules/wikigrok/WikiGrokDialogB.js
@@ -27,12 +27,15 @@
                        } );
                },
                /**
-                * Renders a set of buttons to the panel
+                * Renders a set of buttons to the panel.
+                * Fetches suggestions' labels from the server.
                 * Shows panel to user when there are suggestions.
                 * @method
+                * @private
                 */
                _renderSuggestions: function ( campaign ) {
                        var suggestions,
+                               allSuggestions,
                                self = this,
                                i18n = {
                                        actor: 'Profession',
@@ -40,8 +43,12 @@
                                        album: 'Album type'
                                };
 
+                       // campaign.questions keys are WikiData item IDs
+                       allSuggestions =  $.map( campaign.questions, function ( 
value, key ) {
+                               return key;
+                       } );
                        // randomly pick 4 suggestions
-                       suggestions = self.chooseRandomItemsFromArray( 
campaign.suggestions, 4 );
+                       suggestions = self.chooseRandomItemsFromArray( 
allSuggestions, 4 );
 
                        // Now work out the labels if we have some suggestions
                        if ( suggestions.length ) {
@@ -104,7 +111,7 @@
                        }
                },
                /**
-                * Fetch suggestions from the server and show them to the user.
+                * Show suggestions to the user.
                 * Also record claims when the user hits the save button.
                 * FIXME: Please refactor
                 * @method
diff --git a/javascripts/modules/wikigrok/wikiGrokCampaigns.js 
b/javascripts/modules/wikigrok/wikiGrokCampaigns.js
index 08a4f21..89e0c3e 100644
--- a/javascripts/modules/wikigrok/wikiGrokCampaigns.js
+++ b/javascripts/modules/wikigrok/wikiGrokCampaigns.js
@@ -1,4 +1,4 @@
-( function ( M, $ ) {
+( function ( M ) {
        /**
         * Gets campaigns, claims, and labels from mw.config
         * @class wikiGrokCampaigns
@@ -11,7 +11,6 @@
                 *     name: Name of the campaign chosen, e.g. 'album'
                 *     property: Wikidata ID for the relevant property, e.g. 
'P31'
                 *     questions: object with item IDs and labels for claim 
suggestions
-                *     suggestions: array of Wikidata item IDs corresponding to 
claim suggestions
                 *     randomClaimId: Wikidata item ID of a randomly chosen 
suggestion
                 */
                getRandomCampaign: function () {
@@ -24,12 +23,6 @@
                                campaign = campaigns[campaignName];
                                campaign.name = campaignName;
                                campaign.randomClaimId = getRandomProperty( 
campaign.questions );
-
-                               // make suggestions
-                               // FIXME: Refactor dialog code to use questions 
param instead
-                               campaign.suggestions =  $.map( 
campaign.questions, function ( value, key ) {
-                                       return key;
-                               } );
                        }
                        return campaign;
                }
@@ -69,4 +62,4 @@
 
        M.define( 'modules/wikigrok/wikiGrokCampaigns', wikiGrokCampaigns );
 
-} ( mw.mobileFrontend, jQuery ) );
+} ( mw.mobileFrontend ) );
diff --git a/tests/qunit/modules/wikigrok/test_wikiGrokCampaigns.js 
b/tests/qunit/modules/wikigrok/test_wikiGrokCampaigns.js
index ea95160..dd624b8 100644
--- a/tests/qunit/modules/wikigrok/test_wikiGrokCampaigns.js
+++ b/tests/qunit/modules/wikigrok/test_wikiGrokCampaigns.js
@@ -59,8 +59,8 @@
 
                campaign = wikiGrokCampaigns.getRandomCampaign();
                assert.equal( typeof campaign.name, 'string', 'campaign name 
exists' );
-               assert.equal( typeof campaign.suggestions, 'object', 
'suggestions exist' );
-               assert.equal( typeof campaign.randomClaimId, 'string', 'random 
claim id exist' );
+               assert.equal( typeof campaign.questions, 'object', 'questions 
exist' );
+               assert.equal( typeof campaign.randomClaimId, 'string', 
'randomClaimId exist' );
        } );
 
 }( jQuery, mw.mobileFrontend, mw ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0d09e8637b0f0815c261edb72233ae0aa86ad310
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to