jenkins-bot has submitted this change and it was merged.

Change subject: Implemented ordering of statement groups in the UI
......................................................................


Implemented ordering of statement groups in the UI

Introducing the claimlistview option "firstClaimIndex" and moved the toolbar 
definition to
move statements to the claimgrouplistview widget as functionality to move claim 
groups is
added to the toolbar definition.

Change-Id: I9ca4ea979bdab4a632acded1106a0293a10d6d4a
---
M lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js
M lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
M lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
3 files changed, 151 insertions(+), 92 deletions(-)

Approvals:
  Tobias Gritschacher: Looks good to me, approved
  jenkins-bot: Verified



diff --git 
a/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js
index 0f8ab80..4fd75e6 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js
@@ -146,6 +146,18 @@
        _createClaimGroupListview: function() {
                var self = this;
 
+               function indexOf( claimsSubset, claims ) {
+                       if(
+                               !$.isArray( claimsSubset ) || 
!claimsSubset.length
+                               || !$.isArray( claims ) || !claims.length
+                       ) {
+                               return null;
+                       }
+
+                       var index = $.inArray( claimsSubset[0], claims );
+                       return ( index !== -1 ) ? index : null;
+               }
+
                this.$listview.listview( {
                        listItemAdapter: new 
$.wikibase.listview.ListItemAdapter( {
                                listItemWidget: $.wikibase.claimlistview,
@@ -153,7 +165,8 @@
                                newItemOptionsFn: function( value ) {
                                        return {
                                                value: value,
-                                               entityType: self.option( 
'entityType' )
+                                               entityType: self.option( 
'entityType' ),
+                                               firstClaimIndex: indexOf( 
value, self.option( 'value' ) )
                                        };
                                }
                        } )
@@ -334,4 +347,128 @@
        }
 } );
 
+// TODO: The following toolbar manages claimviews/statementviews as well as 
claimgrouplistviews.
+//   There should be separate toolbars for managing the content of these two 
widgets.
+$.wikibase.toolbarcontroller.definition( 'movetoolbar', {
+       id: 'claimlistview-claimview',
+       selector: '.wb-claimview',
+       events: {
+               'claimviewstartediting statementviewstartediting': function( 
event ) {
+                       // Initialize movetoolbar.
+
+                       var $claimview = $( event.target ),
+                               $claimlistview = $claimview.closest( 
':wikibase-claimlistview' ),
+                               claimlistview = $claimlistview.data( 
'claimlistview' ),
+                               claimlistviewListview = 
claimlistview.$listview.data( 'listview' ),
+                               $claimviews = claimlistviewListview.items(),
+                               $claimgrouplistview = $claimlistview.closest( 
':wikibase-claimgrouplistview' ),
+                               claimgrouplistview = $claimgrouplistview.data( 
'claimgrouplistview' ),
+                               claimgrouplistviewListview = 
claimgrouplistview.$listview.data( 'listview' ),
+                               $claimlistviews = 
claimgrouplistviewListview.items();
+
+                       $claimview.movetoolbar();
+
+                       // If the claimview is the topmost claimview in the 
topmost claimgroup, the "move up"
+                       // button needs to be disabled; Same for the "move 
down" button if the claimview is
+                       // the bottommost claimview in the bottommost 
claimgroup.
+                       var isInTopmostClaimgroup = 
$claimlistviews.first().get( 0 ) === $claimlistview.get( 0 ),
+                               isTopmostInClaimlistview = 
$claimviews.first().get( 0 ) === $claimview.get( 0 ),
+                               isInBottommostClaimgroup = 
$claimlistviews.last().get( 0 ) === $claimlistview.get( 0 ),
+                               isBottommostInClaimlistview = 
$claimviews.last().get( 0 ) === $claimview.get( 0 );
+
+                       if ( isInTopmostClaimgroup && isTopmostInClaimlistview 
) {
+                               $claimview.data( 'movetoolbar' 
).$btnMoveUp.data( 'toolbarbutton' ).disable();
+                       }
+
+                       if( isInBottommostClaimgroup && 
isBottommostInClaimlistview ) {
+                               $claimview.data( 'movetoolbar' 
).$btnMoveDown.data( 'toolbarbutton' ).disable();
+                       }
+               },
+               'claimviewafterstopediting statementviewafterstopediting': 
function( event ) {
+                       // Destroy movetoolbar.
+
+                       var $claimview = $( event.target ),
+                               movetoolbar = $claimview.data( 'movetoolbar' );
+
+                       if( movetoolbar ) {
+                               // Toolbar might be destroyed already by 
cancelling a pending claimview.
+                               movetoolbar.destroy();
+                       }
+               },
+               'movetoolbarup movetoolbardown': function( event ) {
+                       var $claimview = $( event.target ),
+                               claimview = $claimview.data( 'claimview' ) || 
$claimview.data( 'statementview' );
+
+                       if( !claimview ) {
+                               // Not the event of the corresponding toolbar 
but of some other movetoolbar.
+                               return;
+                       }
+
+                       var action = ( event.type === 'movetoolbarup' ) ? 
'moveUp' : 'moveDown',
+                               $claimlistview = $claimview.closest( 
':wikibase-claimlistview' ),
+                               claimlistview = $claimlistview.data( 
'claimlistview' ),
+                               claimlistviewListview = 
claimlistview.$listview.data( 'listview' ),
+                               $claimviews = claimlistviewListview.items(),
+                               $claimgrouplistview = $claimlistview.closest( 
':wikibase-claimgrouplistview' ),
+                               claimgrouplistview = $claimgrouplistview.data( 
'claimgrouplistview' ),
+                               claimgrouplistviewListview = 
claimgrouplistview.$listview.data( 'listview' ),
+                               $claimlistviews = 
claimgrouplistviewListview.items();
+
+                       // Determine whether the whole group has to be moved:
+                       var isTopmostInClaimlistview = $claimview.get( 0 ) === 
$claimviews.first().get( 0 ),
+                               isBottommostInClaimlistview = $claimview.get( 0 
) === $claimviews.last().get( 0 );
+
+                       if(
+                               isTopmostInClaimlistview && action === 'moveUp'
+                               || isBottommostInClaimlistview && action === 
'moveDown'
+                       ) {
+                               claimgrouplistviewListview[action]( 
$claimlistview );
+                       } else {
+                               claimlistviewListview[action]( $claimview );
+                       }
+
+                       // Reflect the position change in the button state:
+                       $claimviews = claimlistviewListview.items();
+                       $claimlistviews = claimgrouplistviewListview.items();
+                       isTopmostInClaimlistview = $claimview.get( 0 ) === 
$claimviews.first().get( 0 );
+                       isBottommostInClaimlistview = $claimview.get( 0 ) === 
$claimviews.last().get( 0 );
+
+                       var $btnMoveUp = $claimview.data( 'movetoolbar' 
).$btnMoveUp,
+                               btnMoveUp = $btnMoveUp.data( 'toolbarbutton' ),
+                               $btnMoveDown = $claimview.data( 'movetoolbar' 
).$btnMoveDown,
+                               btnMoveDown = $btnMoveDown.data( 
'toolbarbutton' ),
+                               isInTopmostClaimgroup = 
$claimlistviews.first().get( 0 ) === $claimlistview.get( 0 ),
+                               isInBottommostClaimgroup = 
$claimlistviews.last().get( 0 ) === $claimlistview.get( 0 ),
+                               isTopmost = isTopmostInClaimlistview && 
isInTopmostClaimgroup,
+                               isBottommost = isBottommostInClaimlistview && 
isInBottommostClaimgroup;
+
+                       btnMoveUp[isTopmost ? 'disable' : 'enable' ]();
+                       btnMoveDown[isBottommost ? 'disable' : 'enable' ]();
+
+                       // Update claimview indices:
+                       var index = 0;
+
+                       for( var i = 0; i < $claimlistviews.length; i++ ) {
+                               var claimlistviewInstance = 
claimgrouplistviewListview.listItemAdapter().liInstance(
+                                               $claimlistviews.eq( i )
+                                       );
+
+                               var claimlistviewInstanceLv = 
claimlistviewInstance.$listview.data( 'listview' ),
+                                       $claimviewNodes = 
claimlistviewInstanceLv.items();
+
+                               for( var j = 0; j < $claimviewNodes.length; j++ 
) {
+                                       var claimviewInstance = 
claimlistviewInstanceLv.listItemAdapter().liInstance(
+                                               $claimviewNodes.eq( j )
+                                       );
+
+                                       claimviewInstance.option( 'index', 
index );
+
+                                       index++;
+                               }
+                       }
+
+               }
+       }
+} );
+
 }( mediaWiki, wikibase, jQuery ) );
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
index 04af396..3116634 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
@@ -16,6 +16,12 @@
  *         view will initialize an empty claimview with edit mode started.
  *         Default: null
  *
+ * @option [firstClaimIndex] {number|null} The index of the claimlistview's 
first claim within a
+ *         list of claims.
+ *         Default: null
+ *         TODO: Remove this option and use a proper mechanism to store the 
ordered claim structure
+ *         at a higher level independent from claimlistview (bug #56050).
+ *
  * @event startediting: Triggered when one of the claimlistview's items enters 
edit mode.
  *        (1) {jQuery.Event}
  *
@@ -53,7 +59,8 @@
                        '$listview': '.wb-claims'
                },
                value: null,
-               entityType: null
+               entityType: null,
+               firstClaimIndex: null
        },
 
        /**
@@ -134,9 +141,9 @@
                        propertyId = claims[0].getMainSnak().getPropertyId();
                }
 
-               function indexOf( element, array ) {
+               function indexOf( element, array, firstClaimIndex ) {
                        var index = $.inArray( element, array );
-                       return ( index !== -1 ) ? index : null;
+                       return ( index !== -1 ) ? index + firstClaimIndex : 
null;
                }
 
                this.$listview
@@ -157,7 +164,7 @@
                                                                property: 
!!propertyId
                                                        }
                                                },
-                                               index: indexOf( value, ( claims 
|| [] ) )
+                                               index: indexOf( value, ( claims 
|| [] ), self.option( 'firstClaimIndex' ) )
                                        };
                                }
                        } ),
@@ -410,92 +417,6 @@
                        }
 
                        btnSave[shouldEnableSaveButton( statementview ) ? 
'enable' : 'disable']();
-               }
-       }
-} );
-
-$.wikibase.toolbarcontroller.definition( 'movetoolbar', {
-       id: 'claimlistview-claimview',
-       selector: '.wb-claimview',
-       events: {
-               'claimviewstartediting statementviewstartediting': function( 
event ) {
-                       // Initialize movetoolbar.
-
-                       var $claimview = $( event.target ),
-                               $claimlistview = $claimview.closest( 
':wikibase-claimlistview' ),
-                               claimlistview = $claimlistview.data( 
'claimlistview' ),
-                               claimlistviewListview = 
claimlistview.$listview.data( 'listview' );
-
-                       $claimview.movetoolbar();
-
-                       // Disable "move up" button of topmost and "move down" 
button of bottommost
-                       // referenceview:
-                       var $topMostReferenceview = 
claimlistviewListview.items().first();
-                       var $bottomMostReferenceview = 
claimlistviewListview.items().last();
-
-                       if ( $topMostReferenceview.get( 0 ) === $claimview.get( 
0 ) ) {
-                               $claimview.data( 'movetoolbar' 
).$btnMoveUp.data( 'toolbarbutton' ).disable();
-                       }
-
-                       if( $bottomMostReferenceview.get( 0 ) === 
$claimview.get( 0 ) ) {
-                               $claimview.data( 'movetoolbar' 
).$btnMoveDown.data( 'toolbarbutton' ).disable();
-                       }
-               },
-               'claimviewafterstopediting statementviewafterstopediting': 
function( event ) {
-                       // Destroy movetoolbar.
-
-                       var $claimview = $( event.target ),
-                               movetoolbar = $claimview.data( 'movetoolbar' );
-
-                       if( movetoolbar ) {
-                               // Toolbar might be destroyed already by 
cancelling a pending claimview.
-                               movetoolbar.destroy();
-                       }
-               },
-               'movetoolbarup movetoolbardown': function( event ) {
-                       var $claimview = $( event.target ),
-                               claimview = $claimview.data( 'claimview' ) || 
$claimview.data( 'statementview' );
-
-                       if( !claimview ) {
-                               // Not the event of the corresponding toolbar 
but of some other movetoolbar.
-                               return;
-                       }
-
-                       var $claimlistview = $claimview.closest( 
':wikibase-claimlistview' ),
-                               claimlistview = $claimlistview.data( 
'claimlistview' ),
-                               claimlistviewListview = 
claimlistview.$listview.data( 'listview' ),
-                               action = ( event.type === 'movetoolbarup' ) ? 
'moveUp' : 'moveDown',
-                               claimviewIndex = claimlistviewListview.indexOf( 
$claimview ),
-                               isLastListItem = ( claimviewIndex !== 
claimlistviewListview.items().length - 1 );
-
-                       if( action === 'moveUp' && 
claimlistviewListview.indexOf( $claimview ) !== 0 ) {
-                               claimlistviewListview.moveUp( $claimview );
-                       } else if( action === 'moveDown' && isLastListItem ) {
-                               claimlistviewListview.moveDown( $claimview );
-                       }
-
-                       // Disable "move up" button if the claimview is the 
topmost in its claimlistview and/or
-                       // "move down" button if it is the bottommost claimview:
-                       var $btnMoveUp = $claimview.data( 'movetoolbar' 
).$btnMoveUp,
-                               btnMoveUp = $btnMoveUp.data( 'toolbarbutton' ),
-                               $btnMoveDown = $claimview.data( 'movetoolbar' 
).$btnMoveDown,
-                               btnMoveDown = $btnMoveDown.data( 
'toolbarbutton' ),
-                               $topmostClaimview = 
claimlistviewListview.items().first(),
-                               isTopmost = $topmostClaimview.get( 0 ) === 
$claimview.get( 0 ),
-                               $bottommostClaimview = 
claimlistviewListview.items().last(),
-                               isBottommost = $bottommostClaimview.get( 0 ) 
=== $claimview.get( 0 );
-
-                       btnMoveUp[( isTopmost ) ? 'disable' : 'enable' ]();
-                       btnMoveDown[( isBottommost ) ? 'disable' : 'enable' ]();
-
-                       // Update claimview indices:
-                       var $claimviews = claimlistviewListview.items(),
-                               claimlistviewListviewLia = 
claimlistviewListview.listItemAdapter();
-
-                       for( var i = 0; i < $claimviews.length; i++ ) {
-                               claimview = 
claimlistviewListviewLia.liInstance( $claimviews.eq( i ) );
-                               claimview.option( 'index', i );
-                       }
                }
        }
 } );
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
index 56b9a72..9475350 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
@@ -276,7 +276,8 @@
                return abstractedApi.removeReferences(
                        guid,
                        reference.getHash(),
-                       wb.getRevisionStore().getClaimRevision( guid )
+                       wb.getRevisionStore().getClaimRevision( guid ),
+                       this.option( 'index' )
                ).done( function( baseRevId ) {
                        // update revision store
                        wb.getRevisionStore().setClaimRevision( baseRevId, guid 
);

-- 
To view, visit https://gerrit.wikimedia.org/r/91191
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9ca4ea979bdab4a632acded1106a0293a10d6d4a
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to