mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 14:36:51 +00:00
VE include subref count in warning message
Include subref count in warning messages in VE editPanel dialog and contextItem Bug: T373023 Change-Id: Ie7d162c4a2291db441846ec338159e8955c206c2
This commit is contained in:
parent
2890772a9f
commit
bdcbcc08f8
|
@ -206,6 +206,24 @@ ve.dm.MWGroupReferences.prototype.getRefUsages = function ( key ) {
|
|||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the total number of usages for a reference, including sub-references.
|
||||
*
|
||||
* @param {string} listKey Full key of the reference
|
||||
* @return {number} Total usage count of main refs and subrefs
|
||||
*/
|
||||
ve.dm.MWGroupReferences.prototype.getTotalUsageCount = function ( listKey ) {
|
||||
const mainRefs = this.getRefUsages( listKey );
|
||||
const mainRefsCount = mainRefs.length;
|
||||
|
||||
const subrefs = this.getSubrefs( listKey );
|
||||
const subrefsCount = subrefs.length;
|
||||
|
||||
const totalUsageCount = mainRefsCount + subrefsCount;
|
||||
|
||||
return totalUsageCount;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} parentKey parent ref key
|
||||
* @return {ve.dm.MWReferenceNode[]} List of subrefs for this parent
|
||||
|
|
|
@ -74,11 +74,13 @@ ve.ui.MWReferenceContextItem.prototype.getRendering = function () {
|
|||
* @return {jQuery|undefined}
|
||||
*/
|
||||
ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
|
||||
const usageCount = this.groupRefs.getRefUsages( this.model.getAttribute( 'listKey' ) ).length;
|
||||
if ( usageCount > 1 ) {
|
||||
const listKey = this.model.getAttribute( 'listKey' );
|
||||
const totalUsageCount = this.groupRefs.getTotalUsageCount( listKey );
|
||||
|
||||
if ( totalUsageCount > 1 ) {
|
||||
return $( '<div>' )
|
||||
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
||||
.text( mw.msg( 'cite-ve-dialog-reference-editing-reused', usageCount ) );
|
||||
.text( mw.msg( 'cite-ve-dialog-reference-editing-reused', totalUsageCount ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -253,13 +253,12 @@ ve.ui.MWReferenceEditPanel.prototype.setFormFieldsFromRef = function ( ref ) {
|
|||
* @param {ve.dm.MWReferenceModel} ref
|
||||
*/
|
||||
ve.ui.MWReferenceEditPanel.prototype.updateReuseWarningFromRef = function ( ref ) {
|
||||
const usageCount = this.docRefs
|
||||
const totalUsageCount = this.docRefs
|
||||
.getGroupRefs( ref.getListGroup() )
|
||||
.getRefUsages( ref.getListKey() )
|
||||
.length;
|
||||
.getTotalUsageCount( ref.getListKey() );
|
||||
this.reuseWarning
|
||||
.toggle( usageCount > 1 )
|
||||
.setLabel( mw.msg( 'cite-ve-dialog-reference-editing-reused-long', usageCount ) );
|
||||
.toggle( totalUsageCount > 1 )
|
||||
.setLabel( mw.msg( 'cite-ve-dialog-reference-editing-reused-long', totalUsageCount ) );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc );
|
||||
const plainGroupRefs = docRefs.getGroupRefs( '' );
|
||||
const fooGroupRefs = docRefs.getGroupRefs( 'foo' );
|
||||
const emptyGroupRefs = docRefs.getGroupRefs( 'doenotexist' );
|
||||
const emptyGroupRefs = docRefs.getGroupRefs( 'doesnotexist' );
|
||||
|
||||
QUnit.test( 'isEmpty', ( assert ) => {
|
||||
assert.false( plainGroupRefs.isEmpty() );
|
||||
|
@ -55,13 +55,13 @@
|
|||
|
||||
QUnit.test( 'getRefNode', ( assert ) => {
|
||||
assert.strictEqual( plainGroupRefs.getRefNode( 'auto/0' ).getAttribute( 'listKey' ), 'auto/0' );
|
||||
assert.strictEqual( plainGroupRefs.getRefNode( 'doenotexist' ), undefined );
|
||||
assert.strictEqual( plainGroupRefs.getRefNode( 'doesnotexist' ), undefined );
|
||||
} );
|
||||
|
||||
QUnit.test( 'getInternalModelNode', ( assert ) => {
|
||||
// TODO: assert something that makes sense
|
||||
// assert.strictEqual( plainGroupRefs.getInternalModelNode( 'auto/0' ), undefined );
|
||||
assert.strictEqual( plainGroupRefs.getInternalModelNode( 'doenotexist' ), undefined );
|
||||
assert.strictEqual( plainGroupRefs.getInternalModelNode( 'doesnotexist' ), undefined );
|
||||
} );
|
||||
|
||||
QUnit.test( 'getRefUsages', ( assert ) => {
|
||||
|
@ -72,7 +72,17 @@
|
|||
'literal/bar'
|
||||
]
|
||||
);
|
||||
assert.deepEqual( plainGroupRefs.getRefUsages( 'doenotexist' ), [] );
|
||||
assert.deepEqual( plainGroupRefs.getRefUsages( 'doesnotexist' ), [] );
|
||||
} );
|
||||
|
||||
QUnit.test( 'getTotalUsageCount', ( assert ) => {
|
||||
const mockListKey = 'literal/bar';
|
||||
|
||||
// The total usage count should be the sum of main refs and subrefs
|
||||
assert.strictEqual(
|
||||
plainGroupRefs.getTotalUsageCount( mockListKey ),
|
||||
plainGroupRefs.getRefUsages( mockListKey ).length + plainGroupRefs.getSubrefs( mockListKey ).length
|
||||
);
|
||||
} );
|
||||
|
||||
QUnit.test( 'sub-references', ( assert ) => {
|
||||
|
|
|
@ -18,7 +18,12 @@
|
|||
function getDocRefsMock( node, reUse ) {
|
||||
const groupRefs = {
|
||||
getRefUsages: () => ( reUse ? [ node, node ] : [] ),
|
||||
getInternalModelNode: () => ( node )
|
||||
getInternalModelNode: () => ( node ),
|
||||
getTotalUsageCount: () => {
|
||||
const mainRefsCount = reUse ? 2 : 0;
|
||||
const subRefsCount = reUse ? 1 : 0;
|
||||
return mainRefsCount + subRefsCount;
|
||||
}
|
||||
};
|
||||
return {
|
||||
getAllGroupNames: () => ( [ 'mwReference/' ] ),
|
||||
|
|
Loading…
Reference in a new issue