@@ -24,6 +24,7 @@ wb.datamodel.SnakList = util.inherit( 'WbDataModelSnakList', PARENT, function( s
24
24
*
25
25
* @param {string } propertyId
26
26
* @return {wikibase.datamodel.SnakList }
27
+ * @private
27
28
*/
28
29
getFilteredSnakList : function ( propertyId ) {
29
30
if ( ! propertyId ) {
@@ -94,161 +95,6 @@ wb.datamodel.SnakList = util.inherit( 'WbDataModelSnakList', PARENT, function( s
94
95
} ) ;
95
96
96
97
return propertyIds ;
97
- } ,
98
-
99
- /**
100
- * Returns the indices of the snak list where a certain snak may be moved to. A snak may be
101
- * moved within its property group. It may also be moved to the slots between property groups
102
- * which involves moving the whole property group the snak belongs to.
103
- *
104
- * @param {wikibase.datamodel.Snak } snak
105
- * @return {number[] }
106
- */
107
- getValidMoveIndices : function ( snak ) {
108
- var self = this ,
109
- indices = [ ] ,
110
- isGroupLast = false ;
111
-
112
- this . each ( function ( i , snakListSnak ) {
113
- if ( snakListSnak . getPropertyId ( ) === snak . getPropertyId ( ) ) {
114
- // Detect slots within the snak's property group.
115
- if ( snakListSnak !== snak ) {
116
- indices . push ( i ) ;
117
- } else {
118
- var nextSnak = self . _items [ i + 1 ] ;
119
- if ( nextSnak && nextSnak . getPropertyId ( ) !== snak . getPropertyId ( ) ) {
120
- // Snak is the last of its group.
121
- isGroupLast = true ;
122
- }
123
- }
124
- } else {
125
- // Detect slots between property groups.
126
- var previousSnak = self . _items [ i - 1 ] ,
127
- isNewPropertyGroup = (
128
- i !== 0
129
- && snakListSnak . getPropertyId ( ) !== previousSnak . getPropertyId ( )
130
- ) ;
131
-
132
- if (
133
- // Since this snak's property group is not at the top of the snak list, the
134
- // snak (with its group) may always be moved to the top:
135
- i === 0
136
- // The snak (with its group) may always be moved to between groups except to
137
- // adjacent slots between property groups since the snak's property group would
138
- // in fact not be moved.
139
- || isNewPropertyGroup && previousSnak . getPropertyId ( ) !== snak . getPropertyId ( )
140
- ) {
141
- indices . push ( i ) ;
142
- }
143
- }
144
- } ) ;
145
-
146
- // Allow moving to last position if snak is not at the end already:
147
- if ( snak !== this . _items [ this . _items . length - 1 ] ) {
148
- indices . push ( this . _items . length ) ;
149
- }
150
-
151
- return indices ;
152
- } ,
153
-
154
- /**
155
- * Moves a SnakList's Snak to a new index.
156
- *
157
- * @param {wikibase.datamodel.Snak } snak Snak to move within the list.
158
- * @param {number } toIndex
159
- * @return {wikibase.datamodel.SnakList } This SnakList object.
160
- *
161
- * @throws {Error } if snak is not allowed to be moved to toIndex.
162
- */
163
- move : function ( snak , toIndex ) {
164
- if ( this . indexOf ( snak ) === toIndex ) {
165
- return this ;
166
- }
167
-
168
- var validIndices = this . getValidMoveIndices ( snak ) ;
169
-
170
- if ( $ . inArray ( toIndex , validIndices ) === - 1 ) {
171
- throw new Error ( 'Tried to move snak to index ' + toIndex + ' but only the following '
172
- + 'indices are allowed: ' + validIndices . join ( ', ' ) ) ;
173
- }
174
-
175
- var previousSnak = this . _items [ toIndex - 1 ] ,
176
- nextSnak = this . _items [ toIndex + 1 ] ,
177
- insertBefore = this . _items [ toIndex ] ;
178
-
179
- if (
180
- previousSnak && previousSnak . getPropertyId ( ) === snak . getPropertyId ( )
181
- || nextSnak && nextSnak . getPropertyId ( ) === snak . getPropertyId ( )
182
- ) {
183
- // Moving snak within its property group.
184
- this . _items . splice ( this . indexOf ( snak ) , 1 ) ;
185
-
186
- if ( insertBefore ) {
187
- this . _items . splice ( toIndex , 0 , snak ) ;
188
- } else {
189
- this . _items . push ( snak ) ;
190
- }
191
- } else {
192
- // Moving the whole snak group.
193
- var groupedSnaks = [ ] ;
194
-
195
- for ( var i = 0 ; i < this . _items . length ; i ++ ) {
196
- if ( this . _items [ i ] . getPropertyId ( ) === snak . getPropertyId ( ) ) {
197
- groupedSnaks . push ( this . _items [ i ] ) ;
198
- }
199
- }
200
-
201
- for ( i = 0 ; i < groupedSnaks . length ; i ++ ) {
202
- this . _items . splice ( this . indexOf ( groupedSnaks [ i ] ) , 1 ) ;
203
- if ( insertBefore ) {
204
- this . _items . splice ( this . indexOf ( insertBefore ) , 0 , groupedSnaks [ i ] ) ;
205
- } else {
206
- this . _items . push ( groupedSnaks [ i ] ) ;
207
- }
208
- }
209
- }
210
-
211
- return this ;
212
- } ,
213
-
214
- /**
215
- * Moves a snak towards the top of the snak list by one step.
216
- *
217
- * @param {wikibase.datamodel.Snak } snak
218
- * @return {wikibase.datamodel.SnakList } This SnakList object.
219
- */
220
- moveUp : function ( snak ) {
221
- var index = this . indexOf ( snak ) ,
222
- validIndices = this . getValidMoveIndices ( snak ) ;
223
-
224
- for ( var i = validIndices . length - 1 ; i >= 0 ; i -- ) {
225
- if ( validIndices [ i ] < index ) {
226
- this . move ( snak , validIndices [ i ] ) ;
227
- break ;
228
- }
229
- }
230
-
231
- return this ;
232
- } ,
233
-
234
- /**
235
- * Moves a snak towards the bottom of the snak list by one step.
236
- *
237
- * @param {wikibase.datamodel.Snak } snak
238
- * @return {wikibase.datamodel.SnakList } This SnakList object.
239
- */
240
- moveDown : function ( snak ) {
241
- var index = this . indexOf ( snak ) ,
242
- validIndices = this . getValidMoveIndices ( snak ) ;
243
-
244
- for ( var i = 0 ; i < validIndices . length ; i ++ ) {
245
- if ( validIndices [ i ] > index ) {
246
- this . move ( snak , validIndices [ i ] ) ;
247
- break ;
248
- }
249
- }
250
-
251
- return this ;
252
98
}
253
99
} ) ;
254
100
0 commit comments