mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 14:36:51 +00:00
Merge "[refactor] Update some usages to new refs interface"
This commit is contained in:
commit
1bae4d71c9
|
@ -246,15 +246,13 @@ ve.ui.MWReferenceEditPanel.prototype.setFormFieldsFromRef = function ( ref ) {
|
|||
* @param {ve.dm.MWReferenceModel} ref
|
||||
*/
|
||||
ve.ui.MWReferenceEditPanel.prototype.updateReuseWarningFromRef = function ( ref ) {
|
||||
const group = this.internalList.getNodeGroup( ref.getListGroup() );
|
||||
const nodes = ve.getProp( group, 'keyedNodes', ref.getListKey() );
|
||||
const usages = nodes ? nodes.filter(
|
||||
( node ) => !node.findParent( ve.dm.MWReferencesListNode )
|
||||
).length : 0;
|
||||
|
||||
const usageCount = ve.dm.MWDocumentReferences.static.refsForDoc( this.internalList.getDocument() )
|
||||
.getGroupRefs( ref.getListGroup() )
|
||||
.getRefUsages( ref.getListKey() )
|
||||
.length;
|
||||
this.reuseWarning
|
||||
.toggle( usages > 1 )
|
||||
.setLabel( mw.msg( 'cite-ve-dialog-reference-editing-reused-long', usages ) );
|
||||
.toggle( usageCount > 1 )
|
||||
.setLabel( mw.msg( 'cite-ve-dialog-reference-editing-reused-long', usageCount ) );
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -263,15 +261,18 @@ ve.ui.MWReferenceEditPanel.prototype.updateReuseWarningFromRef = function ( ref
|
|||
*/
|
||||
ve.ui.MWReferenceEditPanel.prototype.updateExtendsWarningFromRef = function ( ref ) {
|
||||
if ( ref.extendsRef ) {
|
||||
const mainRefId = this.internalList.keys.indexOf( ref.extendsRef );
|
||||
const parentNode = ve.dm.MWDocumentReferences.static.refsForDoc( this.internalList.getDocument() )
|
||||
.getGroupRefs( ref.getListGroup() )
|
||||
.getInternalModelNode( ref.extendsRef );
|
||||
this.extendsWarning.setLabel(
|
||||
$( '<p>' )
|
||||
.text( mw.msg( 'cite-ve-dialog-reference-editing-extends' ) )
|
||||
.append( mainRefId === -1 ?
|
||||
.append( parentNode ?
|
||||
new ve.ui.MWPreviewElement( parentNode, { useView: true } ).$element :
|
||||
$( '<div>' )
|
||||
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
||||
.text( ve.msg( 'cite-ve-dialog-reference-missing-parent-ref' ) ) :
|
||||
new ve.ui.MWPreviewElement( this.internalList.getItemNode( mainRefId ), { useView: true } ).$element )
|
||||
.text( ve.msg( 'cite-ve-dialog-reference-missing-parent-ref' ) )
|
||||
)
|
||||
);
|
||||
this.extendsWarning.toggle( true );
|
||||
} else {
|
||||
|
|
|
@ -172,7 +172,7 @@ ve.ui.MWReferenceSearchWidget.prototype.buildSearchIndex = function () {
|
|||
let $element;
|
||||
// Make visible text, citation and reference name searchable
|
||||
let text = ( citation + ' ' + name ).toLowerCase();
|
||||
const itemNode = this.internalList.getItemNode( node.getAttribute( 'listIndex' ) );
|
||||
const itemNode = groupRefs.getInternalModelNode( listKey );
|
||||
if ( itemNode.length ) {
|
||||
$element = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element;
|
||||
text = $element.text().toLowerCase() + ' ' + text;
|
||||
|
|
|
@ -6,15 +6,9 @@ QUnit.test( 'setReferenceForEditing', ( assert ) => {
|
|||
ve.init.target.surface = { commandRegistry: { registry: {} } };
|
||||
const editPanel = new ve.ui.MWReferenceEditPanel();
|
||||
|
||||
const emptyDoc = new ve.dm.Document( [
|
||||
{ type: 'paragraph', internal: { generated: 'empty' } },
|
||||
{ type: '/paragraph' },
|
||||
{ type: 'internalList' },
|
||||
{ type: '/internalList' }
|
||||
] );
|
||||
const ref = new ve.dm.MWReferenceModel( emptyDoc );
|
||||
|
||||
editPanel.setInternalList( emptyDoc.getInternalList() );
|
||||
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
|
||||
const ref = new ve.dm.MWReferenceModel( doc );
|
||||
editPanel.setInternalList( doc.getInternalList() );
|
||||
|
||||
const changeHandlerStub = sinon.stub();
|
||||
editPanel.connect( changeHandlerStub );
|
||||
|
|
|
@ -11,7 +11,8 @@ function getInternalListMock( hasNode ) {
|
|||
default: return undefined;
|
||||
}
|
||||
},
|
||||
getAttributes: () => ( {} )
|
||||
getAttributes: () => ( {} ),
|
||||
getInternalItem: () => ( {} )
|
||||
} : {};
|
||||
const groups = hasNode ? {
|
||||
'mwReference/': {
|
||||
|
|
Loading…
Reference in a new issue