Changeset 6336
- Timestamp:
- Oct 28, 2013, 12:57:45 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/src/docbook/appendix/incompatible.xml
r6281 r6336 45 45 that expect the parent chain of biomaterials to always be fully initialized 46 46 without explicitely having told the BASE core to do so. 47 </para> 48 49 <bridgehead>Tables can have columns with different sort order</bridgehead> 50 <para> 51 A new feature has been implemented which allows columns in a table to 52 have different sort order. This is implemented by allowing '+' or '-' 53 as a prefix to properties returned by the <methodname>ItemContext.getSortProperty()</methodname> 54 method. Properties without a prefix still use the global sort order as returned 55 by <methodname>ItemContext.getSortDirection()</methodname>. 56 </para> 57 58 <para> 59 Code that is not aware of the prefixes may fail since '+' and '-' are not 60 allowed in property names. 47 61 </para> 48 62 </sect1> -
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/table/ColumnDef.java
r6190 r6336 679 679 else 680 680 { 681 boolean sortOnThis = table.isSortedby(getSortproperty()); 682 String image = sortOnThis ? table.getDirectionImage() : ""; 683 ItemContext.SortDirection direction = sortOnThis ? table.getReverseDirection() : table.getDirection(); 681 // Current sort direction 682 ItemContext.SortDirection sortDirection = table.getSortDirection(getSortproperty()); 683 String image = table.getDirectionImage(sortDirection); 684 685 // Next sort direction if clicking on this column 686 ItemContext.SortDirection nextDirection = 687 sortDirection == null ? table.getDirection() : sortDirection.getReverseDirection(); 688 684 689 String theTooltip = getTooltip() != null ? 685 690 getTooltip() : "Sort by "+getTitle() + "; hold CTRL, ALT or SHIFT to sort by multiple columns"; … … 687 692 sb.append(" id=\"").append(idPrefix).append(".sort\""); 688 693 sb.append(" data-sort-property=\"").append(HTML.encodeTags(getSortproperty())).append("\""); 689 sb.append(" data-sort-direction=\"").append( direction.name()).append("\"");694 sb.append(" data-sort-direction=\"").append(nextDirection.name()).append("\""); 690 695 sb.append(" title=\"").append(theTooltip).append("\">"); 691 696 sb.append(getTitle()).append("</span>").append(image); -
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/table/Table.java
r6190 r6336 229 229 */ 230 230 private String sortby = null; 231 private Set<String> sortbyMultiple= null;231 private Map<String, ItemContext.SortDirection> sortColumns = null; 232 232 233 233 private String action = null; … … 313 313 { 314 314 this.sortby = sortby; 315 if (sortby != null) sortbyMultiple = new HashSet<String>(Arrays.asList(sortby.split(","))); 315 if (sortby != null) 316 { 317 sortColumns = new HashMap<String, ItemContext.SortDirection>(); 318 for (String col : sortby.split(",")) 319 { 320 if (col.startsWith("-")) 321 { 322 sortColumns.put(col.substring(1), ItemContext.SortDirection.DESC); 323 } 324 else if (col.startsWith("+")) 325 { 326 sortColumns.put(col.substring(1), ItemContext.SortDirection.ASC); 327 } 328 else 329 { 330 sortColumns.put(col, null); // NOTE! Default direction may not be set yet 331 } 332 } 333 } 316 334 } 317 335 public String getSortby() … … 467 485 return visibleColumns.size(); 468 486 } 469 boolean isSortedby(String sortcolumn) 470 { 471 return (sortbyMultiple != null) && sortbyMultiple.contains(sortcolumn); 472 } 473 ItemContext.SortDirection getReverseDirection() 474 { 475 return sortDirection == ItemContext.SortDirection.ASC ? ItemContext.SortDirection.DESC : ItemContext.SortDirection.ASC; 476 } 477 String getDirectionImage() 478 { 479 return "<img src=\""+getPage().getRoot()+"images/" + 480 (sortDirection == ItemContext.SortDirection.ASC ? "sort_asc.png" : "sort_desc.png") + 481 "\" alt=\"" + (sortDirection == ItemContext.SortDirection.ASC ? "▼" : "▲") + "\">"; 487 /** 488 Get the sort direction on the given column. If it is not 489 used for sorting, null is returned. 490 @since 3.3 491 */ 492 ItemContext.SortDirection getSortDirection(String colum) 493 { 494 ItemContext.SortDirection direction = null; 495 if (sortColumns != null && sortColumns.containsKey(colum)) 496 { 497 direction = sortColumns.get(colum); 498 if (direction == null) direction = getDirection(); 499 } 500 return direction; 501 } 502 503 /** 504 Get sort direction <img> element for the given direction. 505 Return an empty string if direction = null. 506 @since 3.3 507 */ 508 String getDirectionImage(ItemContext.SortDirection direction) 509 { 510 String image = ""; 511 if (direction != null) 512 { 513 image = "<img src=\""+getPage().getRoot()+"images/" + 514 (direction == ItemContext.SortDirection.ASC ? "sort_asc.png" : "sort_desc.png") + 515 "\" alt=\"" + (direction == ItemContext.SortDirection.ASC ? "▼" : "▲") + "\">"; 516 } 517 return image; 482 518 } 483 519 -
trunk/src/core/net/sf/basedb/core/ItemContext.java
r6127 r6336 382 382 Get the name of the property the current listing is sorted by. 383 383 If multiple properties are used for sorting they are separated by a comma. 384 Each property may also be prefixed by a '+' or '-' to override the 385 global sort direction. 384 386 */ 385 387 public String getSortProperty() … … 391 393 Set the name of the property that the current listing is sorted by. 392 394 If you want to sort by multiple properties, separate them with a 393 comma. 395 comma. By default, each property uses the same sort direction ({@link #getSortDirection()}, 396 but this can be overridden by using '+' or '-' as a prefix for 397 a property. 394 398 This property is stored in the database. 395 399 @param sortProperty The name of the property … … 434 438 String sortProperty = sp[0]; 435 439 String alias = null; 440 SortDirection sortDirection = getSortDirection(); 441 442 if (sortProperty.startsWith("+")) 443 { 444 sortDirection = SortDirection.ASC; 445 sortProperty = sortProperty.substring(1); 446 } 447 else if (sortProperty.startsWith("-")) 448 { 449 sortDirection = SortDirection.DESC; 450 sortProperty = sortProperty.substring(1); 451 } 436 452 if (sortProperty.startsWith("$")) 437 453 { … … 452 468 } 453 469 Expression hqlSortby = Hql.property(alias, sortProperty); 454 sortOrder = (SortDirection.ASC == getSortDirection() ? Orders.asc(hqlSortby) : Orders.desc(hqlSortby));470 sortOrder = sortDirection.sortBy(hqlSortby); 455 471 } 456 472 return sortOrder; … … 1176 1192 sign it is interpreted as a <code>alias.property</code> value, ignoring 1177 1193 the root alias of the query. The sort property may contain multiple properties 1178 if they are separated by a comma. 1194 if they are separated by a comma. Each property may also be prefixed by 1195 a '+' (ASC) or '-' (DESC) to override the global sort direction. 1179 1196 1180 1197 <li>{@link #getInclude()} is used to set {@link EntityQuery#include(Include[])} … … 1216 1233 if (propertyInspector == null || propertyInspector.evaluate(sortProperty)) 1217 1234 { 1235 SortDirection sortDirection = getSortDirection(); 1236 1218 1237 Expression hqlSortby = null; 1219 1238 String alias = null; 1239 1240 // Check if sort direction has been overridden 1241 if (sortProperty.startsWith("-")) 1242 { 1243 sortDirection = SortDirection.DESC; 1244 sortProperty = sortProperty.substring(1); 1245 } 1246 else if (sortProperty.startsWith("+")) 1247 { 1248 sortDirection = SortDirection.ASC; 1249 sortProperty = sortProperty.substring(1); 1250 } 1251 1220 1252 // Extract the 'alias' part if there is one 1221 1253 if (sortProperty.startsWith("$")) … … 1261 1293 if (hqlSortby != null) 1262 1294 { 1263 query.order( SortDirection.ASC == getSortDirection() ? Orders.asc(hqlSortby) : Orders.desc(hqlSortby));1295 query.order(sortDirection.sortBy(hqlSortby)); 1264 1296 } 1265 1297 } … … 1477 1509 if (propertyInspector == null || propertyInspector.evaluate(sortProperty)) 1478 1510 { 1511 SortDirection sortDirection = getSortDirection(); 1512 1513 // Check if sort direction has been overridden 1514 if (sortProperty.startsWith("-")) 1515 { 1516 sortDirection = SortDirection.DESC; 1517 sortProperty = sortProperty.substring(1); 1518 } 1519 else if (sortProperty.startsWith("+")) 1520 { 1521 sortDirection = SortDirection.ASC; 1522 sortProperty = sortProperty.substring(1); 1523 } 1524 1479 1525 Expression sortby = getDynamicExpression(dc, sortProperty); 1480 1526 if (sortby != null) 1481 1527 { 1482 query.order( SortDirection.ASC == getSortDirection() ? Orders.asc(sortby) : Orders.desc(sortby));1528 query.order(sortDirection.sortBy(sortby)); 1483 1529 if (selectionList == null || !selectionList.contains(sortProperty)) 1484 1530 { … … 1708 1754 return Orders.asc(e); 1709 1755 } 1756 @Override 1757 public SortDirection getReverseDirection() 1758 { 1759 return DESC; 1760 } 1710 1761 }, 1711 1762 … … 1719 1770 { 1720 1771 return Orders.desc(e); 1772 } 1773 @Override 1774 public SortDirection getReverseDirection() 1775 { 1776 return ASC; 1721 1777 } 1722 1778 }; … … 1779 1835 public abstract Order sortBy(Expression e); 1780 1836 1837 /** 1838 Get the reverse sort direction. 1839 @since 3.3 1840 */ 1841 public abstract SortDirection getReverseDirection(); 1842 1781 1843 @Override 1782 1844 public String toString() -
trunk/www/include/scripts/table.js
r6315 r6336 151 151 var tableId = Data.get(column, 'table-id'); 152 152 var frm = document.forms[tableId]; 153 154 if (frm.sortby.value != sortProperty || frm.direction.value!= sortDirection)153 var mainDirection = frm.direction.value; 154 if (frm.sortby.value != sortProperty || mainDirection != sortDirection) 155 155 { 156 156 if (event.altKey || event.ctrlKey || event.shiftKey) 157 157 { 158 158 // Append the current sort property to the list of already sorted columns 159 // First, if the sort property is already used we remove it159 // If the sort property is already used we keep it, but use the new sort direction 160 160 var sortArray = frm.sortby.value.split(','); 161 161 var index = sortArray.indexOf(sortProperty); 162 if (index >= 0) sortArray.splice(index, 1); 162 // Check for '+' and '-' prefix if the sort order is different from main direction 163 if (index == -1) index = sortArray.indexOf('+'+sortProperty); 164 if (index == -1) index = sortArray.indexOf('-'+sortProperty); 165 // Currently not sorted, insert at end 166 if (index == -1) index = sortArray.length; 163 167 // Add the sort property as the last property 164 sortArray[sortArray.length] = sortProperty; 168 if (sortDirection != mainDirection) 169 { 170 sortProperty = (sortDirection == 'ASC' ? '+' : '-') + sortProperty; 171 sortDirection = mainDirection; 172 } 173 sortArray[index] = sortProperty; 165 174 sortProperty = sortArray.join(','); 166 175 }
Note: See TracChangeset
for help on using the changeset viewer.