Changeset 7034


Ignore:
Timestamp:
Dec 4, 2015, 8:47:16 AM (6 years ago)
Author:
Nicklas Nordborg
Message:

References #1975: Improve filtering in project items list

Added 'subtype' column to the project items list.

Also realised that when filtering on a column that isn't available for some item type, those items should in most cases not be included. The implementation of conditionalRestriction() now supports an option to exclude all item types not matching the filter. The trashcan list was updated to work like this.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Trashcan.java

    r7018 r7034  
    8888    but the same restriction is applied to all of them. It is recommended
    8989    that the restriction is created with {@link
    90     Restrictions#conditionalRestriction(Filter, Restriction, Restriction)}
     90    Restrictions#conditionalRestriction(Filter, Restriction, Restriction, boolean)}
    9191    so that a restriction on, for example, the 'name' is only applied
    9292    to {@link Nameable} items.
  • trunk/src/core/net/sf/basedb/core/query/Expressions.java

    r7018 r7034  
    467467  */
    468468  @SuppressWarnings("unchecked")
    469   public static Expression conditionalRestriction(Filter<? extends Query> filter, Expression ifTrue, Expression ifFalse)
     469  public static Expression conditionalExpression(Filter<? extends Query> filter, Expression ifTrue, Expression ifFalse)
    470470  {
    471471    if (filter == null || (ifTrue == null && ifFalse == null)) return ifTrue;
  • trunk/src/core/net/sf/basedb/core/query/Restrictions.java

    r7018 r7034  
    463463    case is to apply a restriction depending on the return type of
    464464    the query. This method will allow "null" restrictions but they
    465     are converted to "1=1" (or similar that doesn't limit the result).
     465    are converted to "1=1" or "1=0" depending on the nullMatchNone
     466    parameter.
    466467   
    467468    @param filter A filter, if null the 'ifTrue' restriction is returned
     
    470471    @param ifFalse The restriction to apply if the filter evaluates to FALSE, or null to not apply
    471472      any restriction in this case
     473    @param nullMatchNone FALSE to match all items if the filter is null, TRUE to
     474      match no items if the filter is null
    472475    @return A conditional restriction, or the 'ifTrue' restriction if the filter is null, or
    473476      null if both restrictions are null
     
    475478  */
    476479  @SuppressWarnings("unchecked")
    477   public static Restriction conditionalRestriction(Filter<? extends Query> filter, Restriction ifTrue, Restriction ifFalse)
     480  public static Restriction conditionalRestriction(Filter<? extends Query> filter,
     481    Restriction ifTrue, Restriction ifFalse, boolean nullMatchNone)
    478482  {
    479483    if (filter == null || (ifTrue == null && ifFalse == null)) return ifTrue;
    480484   
    481     if (ifTrue == null) ifTrue = Restrictions.eq(Expressions.integer(1), Expressions.integer(1));
    482     if (ifFalse == null) ifFalse = Restrictions.eq(Expressions.integer(1), Expressions.integer(1));
     485    if (ifTrue == null) ifTrue = Restrictions.eq(Expressions.integer(1), Expressions.integer(nullMatchNone ? 0 : 1));
     486    if (ifFalse == null) ifFalse = Restrictions.eq(Expressions.integer(1), Expressions.integer(nullMatchNone ? 0 : 1));
    483487    return new ConditionalQueryElement((Filter<Query>)filter, ifTrue, ifFalse);
    484488  }
  • trunk/src/core/net/sf/basedb/core/query/ReturnClassFilter.java

    r7032 r7034  
    3030  with the specified class. Intended to be used
    3131  with a conditiona restriction or expression as
    32   created by {@link Restrictions#conditionalRestriction(Filter, Restriction, Restriction)}
    33   and {@link Expressions#conditionalRestriction(Filter, Expression, Expression)}
     32  created by {@link Restrictions#conditionalRestriction(Filter, Restriction, Restriction, boolean)}
     33  and {@link Expressions#conditionalRestriction(Filter, Expression, Expression, boolean)}
    3434 
    3535  @author nicklas
  • trunk/www/my_base/projects/items/list_items.jsp

    r7032 r7034  
    4040  import="net.sf.basedb.core.Directory"
    4141  import="net.sf.basedb.core.Metadata"
     42  import="net.sf.basedb.core.Subtypable"
    4243  import="net.sf.basedb.core.PropertyFilter"
    4344  import="net.sf.basedb.core.query.ResultList"
     
    104105      }
    105106    }
     107   
    106108    Restriction id = cc.getFilterRestriction("id", dc, null);
    107109    Restriction sharedTo = cc.getFilterRestriction("!sharedTo.name", dc, null);
    108110    Restriction owner = cc.getFilterRestriction("owner.name", dc, null);
    109111    Restriction name = Restrictions.conditionalRestriction(new ReturnClassFilter(Nameable.class),
    110         cc.getFilterRestriction("name", dc, null), null);
     112      cc.getFilterRestriction("name", dc, null), null, true);
    111113    Restriction description = Restrictions.conditionalRestriction(new ReturnClassFilter(Nameable.class),
    112         cc.getFilterRestriction("description", dc, null), null);
    113     Restriction restriction = Restrictions.nullSafeAnd(sharedTo, owner, name, description, id);
     114      cc.getFilterRestriction("description", dc, null), null, true);
     115    Restriction subtype = Restrictions.conditionalRestriction(new ReturnClassFilter(Subtypable.class),
     116      cc.getFilterRestriction("itemSubtype.name", dc, null), null, true);
     117   
     118    Restriction restriction = Restrictions.nullSafeAnd(sharedTo, owner, name, description, subtype, id);
    114119    items = project.getItems(itemTypes,
    115120      cc.getPage() * cc.getRowsPerPage(), cc.getRowsPerPage(), cc.getItemPermission(),
     
    178183        datatype="string"
    179184      />
     185      <tbl:columndef
     186        id="itemSubtype"
     187        property="itemSubtype.name"
     188        datatype="string"
     189        title="Subtype"
     190        filterable="true"
     191      />
    180192      <tbl:columndef
    181193        id="id"
     
    216228      />
    217229      <div class="panelgroup bg-filled-50 bottomborder">
    218         <tbl:toolbar subclass="bottomborder bg-filled-50">
     230        <tbl:toolbar subclass="bottomborder">
    219231          <tbl:button
    220232            id="btnDeleteItems"
     
    372384                <tbl:cell column="description"><%=HTML.encodeTags(description)%></tbl:cell>
    373385                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
     386                <tbl:cell column="itemSubtype"><%
     387                if (item instanceof Subtypable)
     388                {
     389                  %><base:propertyvalue item="<%=item%>" property="itemSubtype" /><%
     390                }
     391                %></tbl:cell>
    374392                <tbl:cell column="sharedTo">
    375393                  <%
  • trunk/www/views/trashcan/list_trash.jsp

    r7032 r7034  
    107107    Restriction removedBy = cc.getFilterRestriction("removedBy", dc, null);
    108108    Restriction name = Restrictions.conditionalRestriction(new ReturnClassFilter(Nameable.class),
    109         cc.getFilterRestriction("name", dc, null), null);
     109        cc.getFilterRestriction("name", dc, null), null, true);
    110110    Restriction description = Restrictions.conditionalRestriction(new ReturnClassFilter(Nameable.class),
    111         cc.getFilterRestriction("description", dc, null), null);
     111        cc.getFilterRestriction("description", dc, null), null, true);
    112112    Restriction owner = Restrictions.conditionalRestriction(new ReturnClassFilter(Ownable.class),
    113         cc.getFilterRestriction("owner", dc, null), null);
     113        cc.getFilterRestriction("owner", dc, null), null, true);
    114114    Restriction sharedTo = Restrictions.conditionalRestriction(new ReturnClassFilter(Shareable.class),
    115         cc.getFilterRestriction("!sharedTo.name", dc, null), null);
     115        cc.getFilterRestriction("!sharedTo.name", dc, null), null, true);
    116116    Restriction restriction = Restrictions.nullSafeAnd(id, removedBy, name, description, owner, sharedTo);
    117117
Note: See TracChangeset for help on using the changeset viewer.