Changeset 6749


Ignore:
Timestamp:
Feb 19, 2015, 9:50:36 AM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1325: Lists of items (similar funcion as biomaterial lists)

Added support for filtering on membership in item lists. Used samples list view for testing. Property prefix to use is '§' (actual property name is not currently be used but recommended to be 'itemLists').

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/Base.java

    r6734 r6749  
    3333import net.sf.basedb.core.FileSet;
    3434import net.sf.basedb.core.FileStoreEnabled;
     35import net.sf.basedb.core.ItemList;
    3536import net.sf.basedb.core.ItemSubtype;
    3637import net.sf.basedb.core.Location;
     
    12431244    return lists;
    12441245  }
     1246 
     1247  /**
     1248    Get available item lists as an Enumeration that is
     1249    suitable to use in a column definition for a table.
     1250    @param dc The DbControl to use
     1251    @param memberType Only load lists with this member type, or null
     1252      to load all lists
     1253    @param include Include options
     1254    @return The found lists as an enumeration, empty if no lists are
     1255      found
     1256    @since 3.5
     1257  */
     1258  public static net.sf.basedb.util.Enumeration<String, String>
     1259    getItemListsEnum(DbControl dc, Item memberType, Collection<Include> include)
     1260  {
     1261    ItemQuery<ItemList> query = ItemList.getQuery();
     1262    query.setIncludes(include == null ? Include.ALL : include);
     1263    if (memberType != null)
     1264    {
     1265      query.restrict(
     1266        Restrictions.eq(
     1267          Hql.property("memberType"),
     1268          Expressions.integer(memberType.getValue())
     1269        )
     1270      );
     1271    }
     1272    query.order(Orders.asc(Hql.property("name")));
     1273    query.setCacheResult(true);
     1274   
     1275    net.sf.basedb.util.Enumeration<String, String> lists =
     1276      new net.sf.basedb.util.Enumeration<String, String>();
     1277    for (ItemList list : query.list(dc))
     1278    {
     1279      lists.add(Integer.toString(list.getId()), HTML.encodeTags(list.getName()));
     1280    }
     1281    return lists;
     1282  }
    12451283
    12461284 
  • trunk/src/core/net/sf/basedb/core/PropertyFilter.java

    r6735 r6749  
    640640    }
    641641   
     642    else if (property != null && property.startsWith("§"))
     643    {
     644      // Property is item list
     645      // The value is the ID of the item list to filter on
     646      // We support a single selection and either EQ or NEQ operator
     647      Integer listId = (Integer)getValueAsObject();
     648      if (operator == Operator.NEQ)
     649      {
     650        restriction = Hql.restriction("$id<>ALL(SELECT mmb FROM ItemListData lst INNER JOIN lst.members mmb WHERE lst.id=" +listId+")", "$");
     651      }
     652      else
     653      {
     654        restriction = Hql.restriction("$id=ANY(SELECT mmb FROM ItemListData lst INNER JOIN lst.members mmb WHERE lst.id=" +listId+")", "$");
     655      }
     656    }
     657   
    642658    else
    643659    {
  • trunk/www/biomaterials/samples/list_samples.jsp

    r6721 r6749  
    412412        filterable="true"
    413413        enumeration="<%=Base.getBioMaterialListsEnum(dc, itemType, cc.getInclude())%>"
     414        multiple="false"
     415      />
     416      <tbl:columndef
     417        id="itemList"
     418        property="§itemLists"
     419        datatype="int"
     420        title="Item list"
     421        filterable="true"
     422        enumeration="<%=Base.getItemListsEnum(dc, itemType, cc.getInclude())%>"
    414423        multiple="false"
    415424      />
Note: See TracChangeset for help on using the changeset viewer.