[MediaWiki-commits] [Gerrit] Support different types of claims in WikiGrok version A. - change (mediawiki...MobileFrontend)

2014-10-27 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Support different types of claims in WikiGrok version A.
..


Support different types of claims in WikiGrok version A.

* Add support for 'nationality'

Change-Id: I43d46fbaf4ef313331a22368797179dffef46aa1
---
M javascripts/modules/wikigrok/WikiGrokApi.js
M javascripts/modules/wikigrok/WikiGrokDialog.js
M javascripts/modules/wikigrok/WikiGrokDialogB.js
3 files changed, 71 insertions(+), 44 deletions(-)

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



diff --git a/javascripts/modules/wikigrok/WikiGrokApi.js 
b/javascripts/modules/wikigrok/WikiGrokApi.js
index 83abb09..0e544c7 100644
--- a/javascripts/modules/wikigrok/WikiGrokApi.js
+++ b/javascripts/modules/wikigrok/WikiGrokApi.js
@@ -32,17 +32,6 @@
source: 'mobile ' + this.version
} );
},
-   recordOccupation: function ( occupationId, occupation, 
claimIsCorrect ) {
-   var claim = {
-   correct: claimIsCorrect,
-   prop: 'occupation',
-   propid: 'P106',
-   value: occupation,
-   valueid: occupationId
-   };
-
-   return this.recordClaims( [ claim ] );
-   },
/**
 * Get suggestions for the current person.
 * Currently 50% of time returns occupations, 50% of time 
nationalities
diff --git a/javascripts/modules/wikigrok/WikiGrokDialog.js 
b/javascripts/modules/wikigrok/WikiGrokDialog.js
index e678152..49c5d48 100644
--- a/javascripts/modules/wikigrok/WikiGrokDialog.js
+++ b/javascripts/modules/wikigrok/WikiGrokDialog.js
@@ -50,7 +50,7 @@
Panel.prototype.initialize.apply( this, arguments );
 
// log page impression and widget impression when the 
widget is shown
-   this.on( 'show', function () {
+   this.once( 'show', function () {
self.logPageImpression();
self.initializeWidgetImpressionLogging();
 
@@ -74,8 +74,8 @@
},
/**
 * Return a new array from 'array' with 'count' randomly 
selected elements.
-* @param {array} array Array from which random elements are 
selected
-* @param {integer} count - Positive number of random elements 
to select
+* @param {Array} array Array from which random elements are 
selected
+* @param {Integer} count - Positive number of random elements 
to select
 * @returns {Array}
 */
chooseRandomItemsFromArray: function ( array, count ) {
@@ -97,36 +97,45 @@
randomIndex = Math.round( Math.random() 
* ( arrayLength - 1 ) );
result.push( array[ randomIndex ] );
}
-
}
return result;
},
 
askWikidataQuestion: function ( options ) {
var self = this,
-   occupationArray = options.occupations;
+   vowels = [ 'a', 'e', 'i', 'o', 'u' ],
+   theCountries = [ 'United States', 'United 
Kingdom', 'Philippines',
+   'Marshall Islands', 'Central African 
Republic' ];
 
-   // If there are potential occupations for this person, 
select one at
-   // random and ask if it is a correct occupation for the 
person.
-   if ( occupationArray.length ) {
-   // Choose a random occupation from the list of 
possible occupations.
-   options.occupationId = 
this.chooseRandomItemsFromArray( occupationArray, 1 )[0];
+   if ( options.suggestions.length ) {
+   // choose a suggestion category (dob, dod, 
occupation, or nationality) randomly
+   options.suggestion = 
this.chooseRandomItemsFromArray( options.suggestions, 1 )[0];
+   // pick a claim randomly
+   options.claimId = 
this.chooseRandomItemsFromArray( options.suggestion.list, 1 )[0];
 
-   // Get the name of the occupation from Wikidata.
-   self.apiWikiData.getLabels( [ 
options.occupationId ] ).done( function ( labels ) {
-   var vowels = [ 'a', 'e', 'i', 'o', 'u' 
],
- 

[MediaWiki-commits] [Gerrit] Support different types of claims in WikiGrok version A. - change (mediawiki...MobileFrontend)

2014-10-24 Thread Bmansurov (Code Review)
Bmansurov has uploaded a new change for review.

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

Change subject: Support different types of claims in WikiGrok version A.
..

Support different types of claims in WikiGrok version A.

* Add support for 'nationality'

Change-Id: I43d46fbaf4ef313331a22368797179dffef46aa1
---
M javascripts/modules/wikigrok/WikiGrokApi.js
M javascripts/modules/wikigrok/WikiGrokDialog.js
M javascripts/modules/wikigrok/WikiGrokDialogB.js
3 files changed, 82 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/63/168663/1

diff --git a/javascripts/modules/wikigrok/WikiGrokApi.js 
b/javascripts/modules/wikigrok/WikiGrokApi.js
index 83abb09..5d005d5 100644
--- a/javascripts/modules/wikigrok/WikiGrokApi.js
+++ b/javascripts/modules/wikigrok/WikiGrokApi.js
@@ -32,6 +32,17 @@
source: 'mobile ' + this.version
} );
},
+   recordNationality: function ( nationalityId, nationality, 
claimIsCorrect ) {
+   var claim = {
+   correct: claimIsCorrect,
+   prop: 'nationality',
+   propid: 'P27',
+   value: nationality,
+   valueid: nationalityId
+   };
+
+   return this.recordClaims( [ claim ] );
+   },
recordOccupation: function ( occupationId, occupation, 
claimIsCorrect ) {
var claim = {
correct: claimIsCorrect,
diff --git a/javascripts/modules/wikigrok/WikiGrokDialog.js 
b/javascripts/modules/wikigrok/WikiGrokDialog.js
index e678152..840939b 100644
--- a/javascripts/modules/wikigrok/WikiGrokDialog.js
+++ b/javascripts/modules/wikigrok/WikiGrokDialog.js
@@ -50,6 +50,7 @@
Panel.prototype.initialize.apply( this, arguments );
 
// log page impression and widget impression when the 
widget is shown
+   // FIXME: stop listening to 'show' once the below 
execute successfully
this.on( 'show', function () {
self.logPageImpression();
self.initializeWidgetImpressionLogging();
@@ -74,8 +75,8 @@
},
/**
 * Return a new array from 'array' with 'count' randomly 
selected elements.
-* @param {array} array Array from which random elements are 
selected
-* @param {integer} count - Positive number of random elements 
to select
+* @param {Array} array Array from which random elements are 
selected
+* @param {Integer} count - Positive number of random elements 
to select
 * @returns {Array}
 */
chooseRandomItemsFromArray: function ( array, count ) {
@@ -97,36 +98,39 @@
randomIndex = Math.round( Math.random() 
* ( arrayLength - 1 ) );
result.push( array[ randomIndex ] );
}
-
}
return result;
},
 
askWikidataQuestion: function ( options ) {
var self = this,
-   occupationArray = options.occupations;
+   vowels = [ 'a', 'e', 'i', 'o', 'u' ];
 
-   // If there are potential occupations for this person, 
select one at
-   // random and ask if it is a correct occupation for the 
person.
-   if ( occupationArray.length ) {
-   // Choose a random occupation from the list of 
possible occupations.
-   options.occupationId = 
this.chooseRandomItemsFromArray( occupationArray, 1 )[0];
+   if ( options.suggestions.length ) {
+   // choose a suggestion category (dob, dod, 
occupation, or nationality) randomly
+   options.suggestion = 
this.chooseRandomItemsFromArray( options.suggestions, 1 )[0];
+   // pick a claim randomly
+   options.claimId = 
this.chooseRandomItemsFromArray( options.suggestion.list, 1 )[0];
 
-   // Get the name of the occupation from Wikidata.
-   self.apiWikiData.getLabels( [ 
options.occupationId ] ).done( function ( labels ) {
-   var vowels = [ 'a', 'e', 'i', 'o', 'u' 
],
-   label = 
labels[options.occupationId];
+