User

Difference between revisions of "Seb35/bluell.js"

< User:Seb35

(simplification de la requête sur les niveaux de compétence)
Line 10: Line 10:
 
).done( function( users ) {
 
).done( function( users ) {
 
console.log( users );
 
console.log( users );
var dropdown = new OO.ui.DropdownWidget( {
+
var combobox = new OO.ui.ComboBoxInputWidget( {
 +
placeholder: '👤 Speaker',
 
menu: {
 
menu: {
items: users.results.bindings.map( function( x ) {
+
 
 +
filterFromInput: true,
 +
items: users.results.bindings.map( function( x ) {
 
return new OO.ui.MenuOptionWidget( {
 
return new OO.ui.MenuOptionWidget( {
 
data: x.user.value.substr( 31 ),
 
data: x.user.value.substr( 31 ),
Line 22: Line 25:
  
 
$( '#filteruser' ).append(
 
$( '#filteruser' ).append(
dropdown.$element
+
combobox.$element
 
);
 
);
  
Line 34: Line 37:
 
).done( function( genders ) {
 
).done( function( genders ) {
 
console.log( genders );
 
console.log( genders );
var dropdown = new OO.ui.DropdownWidget( {
+
var combobox = new OO.ui.ComboBoxInputWidget( {
 +
placeholder: '♀️ ♂️ Speaker\'s gender',
 
menu: {
 
menu: {
 +
filterFromInput: true,
 
items: genders.results.bindings.map( function( x ) {
 
items: genders.results.bindings.map( function( x ) {
 
return new OO.ui.MenuOptionWidget( {
 
return new OO.ui.MenuOptionWidget( {
Line 46: Line 51:
  
 
$( '#filtergender' ).append(
 
$( '#filtergender' ).append(
dropdown.$element
+
combobox.$element
 
);
 
);
  
Line 58: Line 63:
 
).done( function( languages ) {
 
).done( function( languages ) {
 
console.log( languages );
 
console.log( languages );
var dropdown = new OO.ui.DropdownWidget( {
+
var combobox = new OO.ui.ComboBoxInputWidget( {
 +
placeholder: '🏳️ Language',
 
menu: {
 
menu: {
 +
filterFromInput: true,
 
items: languages.results.bindings.map( function( x ) {
 
items: languages.results.bindings.map( function( x ) {
 
return new OO.ui.MenuOptionWidget( {
 
return new OO.ui.MenuOptionWidget( {
Line 70: Line 77:
  
 
$( '#filterlanguage' ).append(
 
$( '#filterlanguage' ).append(
dropdown.$element
+
combobox.$element
 
);
 
);
  
Line 82: Line 89:
 
).done( function( proficiencies ) {
 
).done( function( proficiencies ) {
 
console.log( proficiencies );
 
console.log( proficiencies );
var dropdown = new OO.ui.DropdownWidget( {
+
var combobox = new OO.ui.ComboBoxInputWidget( {
 +
placeholder: '🥇 Level of proficiency',
 
menu: {
 
menu: {
 +
filterFromInput: true,
 
items: proficiencies.results.bindings.map( function( x ) {
 
items: proficiencies.results.bindings.map( function( x ) {
 
return new OO.ui.MenuOptionWidget( {
 
return new OO.ui.MenuOptionWidget( {
Line 94: Line 103:
  
 
$( '#filterlevelofproficiency' ).append(
 
$( '#filterlevelofproficiency' ).append(
dropdown.$element
+
combobox.$element
 
);
 
);
  
Line 105: Line 114:
  
  
/*
+
 
 
lang = mw.config.get( 'wgUserLanguage' );
 
lang = mw.config.get( 'wgUserLanguage' );
  
Line 132: Line 141:
 
         action: 'query',
 
         action: 'query',
 
         format: 'json',
 
         format: 'json',
 +
lang: 'fr',
 
         list: 'rwrecords',
 
         list: 'rwrecords',
 
         rwrlimit: '2',
 
         rwrlimit: '2',
Line 150: Line 160:
 
$('.selectors').append(list.$element);
 
$('.selectors').append(list.$element);
 
}
 
}
*/
 

Revision as of 10:13, 30 July 2021

$( function (){
	var userLanguage = mw.config.get( 'wgUserLanguage' );
	mw.loader.using( ['oojs', 'oojs-ui'], function () {

		$.getJSON(
			'https://lingualibre.org/bigdata/namespace/wdq/sparql',
			{
				query: 'SELECT DISTINCT ?user ?userLabel WHERE { ?user prop:P2 entity:Q3 . ?user rdfs:label ?userLabel . FILTER( LANG(?userLabel) = "en" ) } ORDER BY ?userLabel'
			}
		).done( function( users ) {
			console.log( users );
			var combobox = new OO.ui.ComboBoxInputWidget( {
placeholder: '👤 Speaker',
				menu: {

filterFromInput: true,				
items: users.results.bindings.map( function( x ) {
						return new OO.ui.MenuOptionWidget( {
							data: x.user.value.substr( 31 ),
							label: x.userLabel.value
						} );
					} )
				}
			} );

			$( '#filteruser' ).append(
				combobox.$element
			);

		} );

		$.getJSON(
			'https://lingualibre.org/bigdata/namespace/wdq/sparql',
			{
				query: 'SELECT DISTINCT ?gender ?genderLabel WHERE { ?gender prop:P2 entity:Q7 . SERVICE wikibase:label { bd:serviceParam wikibase:language "' + userLanguage + ',fr,en" } } ORDER BY ?gender'
			}
		).done( function( genders ) {
			console.log( genders );
			var combobox = new OO.ui.ComboBoxInputWidget( {
placeholder: '♀️ ♂️ Speaker\'s gender',
				menu: {
filterFromInput: true,	
					items: genders.results.bindings.map( function( x ) {
						return new OO.ui.MenuOptionWidget( {
							data: x.gender.value.substr( 31 ),
							label: x.genderLabel.value
						} );
					} )
				}
			} );

			$( '#filtergender' ).append(
				combobox.$element
			);

		} );

		$.getJSON(
			'https://lingualibre.org/bigdata/namespace/wdq/sparql',
			{
				query: 'SELECT DISTINCT ?language ?languageLabel WHERE { ?language prop:P2 entity:Q4 . SERVICE wikibase:label { bd:serviceParam wikibase:language "' + userLanguage + ',fr,en" } } ORDER BY ?languageLabel'
			}
		).done( function( languages ) {
			console.log( languages );
			var combobox = new OO.ui.ComboBoxInputWidget( {
placeholder: '🏳️ Language',
				menu: {
filterFromInput: true,	
					items: languages.results.bindings.map( function( x ) {
						return new OO.ui.MenuOptionWidget( {
							data: x.language.value.substr( 31 ),
							label: x.languageLabel.value
						} );
					} )
				}
			} );

			$( '#filterlanguage' ).append(
				combobox.$element
			);

		} );

		$.getJSON(
			'https://lingualibre.org/bigdata/namespace/wdq/sparql',
			{
				query: 'SELECT DISTINCT ?proficiency ?proficiencyLabel WHERE { ?proficiency prop:P2 entity:Q5 . SERVICE wikibase:label { bd:serviceParam wikibase:language "' + userLanguage + ',fr,en" } } ORDER BY ?proficiency'
			}
		).done( function( proficiencies ) {
			console.log( proficiencies );
			var combobox = new OO.ui.ComboBoxInputWidget( {
placeholder: '🥇 Level of proficiency',
				menu: {
filterFromInput: true,	
					items: proficiencies.results.bindings.map( function( x ) {
						return new OO.ui.MenuOptionWidget( {
							data: x.proficiency.value.substr( 31 ),
							label: x.proficiencyLabel.value
						} );
					} )
				}
			} );

			$( '#filterlevelofproficiency' ).append(
				combobox.$element
			);

		} );

	} );

} );




lang = mw.config.get( 'wgUserLanguage' );

AudioBox.prototype.display = function() {
	this.$node.find( '.ab-title' ).text( "un label" + lang ); //this.label
	this.$node.find( '.ab-metadata' ).text( this.lang + ' - ' + this.speaker );
	
	this.audioNode.src = this.media;
	this.$node.find( '.ab-playbutton' ).click( this.audioNode.play.bind( this.audioNode ) );
}


function createAudioBoxes( data ) {
	if ( data.query === undefined || data.query.rwrecords === undefined || data.query.rwrecords.length < 2 ) {
		displayError( 'nodata' );
		return;
	}

	ab1 = new AudioBox( data.query.rwrecords[ 0 ], $( '.audiobox' ).eq( 0 ) );
	ab2 = new AudioBox( data.query.rwrecords[ 1 ], $( '.audiobox' ).eq( 1 ) );
}

function getRecords() {
    var api = new mw.Api();
	api.get( {
        action: 'query',
        format: 'json',
lang: 'fr',
        list: 'rwrecords',
        rwrlimit: '2',
		rwrsort: 'pageid',
		rwrdir: 'descending',
		rwrformat: 'qid'
  } ).then( createAudioBoxes, displayError );
}

function displayError( code, error ) {
	console.warn( code, error );
}


if ( mw.config.get( 'wgPageName' ) === 'User:Nicolas_NALLET' ) {
    mw.loader.using( [ 'mediawiki.api', 'ext.recordWizard.wikibase' ] ).then( getRecords );
$('.selectors').append(lang.$element);
$('.selectors').append(list.$element);
}