Skip to content

Commit

Permalink
Merge "Add MUL as last language in Termbox if any MUL term exists"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jun 29, 2023
2 parents bd9f006 + 5bafe18 commit d7e2e76
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
*/
_moreLanguagesItems: {},

/**
* @type {string[]} List of languages shown per default.
*/
_defaultLanguages: [],

/**
* @see jQuery.ui.TemplatedWidget._create
*/
Expand All @@ -83,6 +88,13 @@
}

PARENT.prototype._create.call( this );
this._defaultLanguages = this.options.userLanguages;

var furtherLanguages = this._getMoreLanguages();
if ( 'mul' in furtherLanguages ) {
// We have a mul term, always show it per default (but in the last position)
this._defaultLanguages.push( 'mul' );
}

this._verifyExistingDom();
this._createListView();
Expand Down Expand Up @@ -123,19 +135,23 @@

// Scrape languages from static HTML:
var mismatchAt = null,
userLanguages = this.options.userLanguages;
languages = this._defaultLanguages;
$entitytermsforlanguageview.each( function ( i ) {
var match = $( this )
.attr( 'class' )
.match( /(?:^|\s)wikibase-entitytermsforlanguageview-(\S+)/ );
if ( match && match[ 1 ] !== userLanguages[ i ] ) {
if ( match && match[ 1 ] !== languages[ i ] ) {
if ( match[ 1 ] !== 'mul' ) {
// "mul" might be included in the existing term box, but we want it to be after
// everything else, thus discarding it is expected.
mw.log.warn( 'Existing entitytermsforlanguagelistview DOM does not match configured languages' );
}
mismatchAt = i;
return false;
}
} );

if ( mismatchAt !== null ) {
mw.log.warn( 'Existing entitytermsforlanguagelistview DOM does not match configured languages' );
$entitytermsforlanguageview.slice( mismatchAt ).remove();
}
},
Expand Down Expand Up @@ -183,7 +199,7 @@
};
}
} ),
value: this.options.userLanguages.map( function ( lang ) {
value: this._defaultLanguages.map( function ( lang ) {
return self._getValueForLanguage( lang );
} ),
listItemNodeName: 'TR'
Expand Down Expand Up @@ -222,7 +238,7 @@
*/
_hasMoreLanguages: function () {
var fingerprint = this.options.value,
minLength = this.options.userLanguages.length;
minLength = this._defaultLanguages.length;

if ( fingerprint.getLabels().length > minLength
|| fingerprint.getDescriptions().length > minLength
Expand Down Expand Up @@ -340,7 +356,7 @@
languages[ lang ] = lang;
} );

this.options.userLanguages.forEach( function ( lang ) {
this._defaultLanguages.forEach( function ( lang ) {
delete languages[ lang ];
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
undefined,
'Created widget.'
);
assert.deepEqual(
entitytermsforlanguagelistview._defaultLanguages,
[ 'de', 'en' ],
'Default languages without "mul".'
);

entitytermsforlanguagelistview.destroy();

Expand Down Expand Up @@ -158,4 +163,19 @@
assert.strictEqual( !entitytermsforlanguagelistview._hasMoreLanguages(), true );
} );

QUnit.test( 'mul handling', function ( assert ) {
var fingerprint = createFingerprint();
fingerprint.setLabel( 'mul', new datamodel.Term( 'mul', 'mul-label' ) );

var $entitytermsforlanguagelistview = createEntitytermsforlanguagelistview( { value: fingerprint } ),
entitytermsforlanguagelistview
= $entitytermsforlanguagelistview.data( 'entitytermsforlanguagelistview' );

assert.deepEqual(
entitytermsforlanguagelistview._defaultLanguages,
[ 'de', 'en', 'mul' ],
'Default languages if a "mul" term is present.'
);
} );

}() );

0 comments on commit d7e2e76

Please sign in to comment.