Changeset 3448


Ignore:
Timestamp:
Jun 5, 2007, 9:34:56 AM (14 years ago)
Author:
Nicklas Nordborg
Message:
 
Location:
branches/2.3.1
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.3.1/src/core/net/sf/basedb/core/Project.java

    r3045 r3448  
    3333
    3434import java.util.ArrayList;
     35import java.util.EnumSet;
    3536import java.util.HashSet;
    3637import java.util.List;
     
    345346
    346347  /**
     348     @deprecated Use {@link #getItems(Item, int, int, Permission, Set)} instead
     349  */
     350  public ResultList<Shareable> getItems(Item itemType, int firstItem, int maxItems, Permission permission)
     351  {
     352    return getItems(itemType, firstItem, maxItems, permission, null);
     353  }
     354 
     355 
     356  /**
    347357    Load the items in a project. If this project is the active project it will load
    348358    all items in the project. If this project isn't the active project it will
     
    353363    @param firstItem The index of the first item to return (0-based)
    354364    @param maxItems The maximum number of items to return, or 0 to return all items
     365    @param permissions The permission the logged in user must have on the item
     366    @param include Options for which items that should be included/excluded from the
     367      result, or null to include all non-removed items
    355368    @return A list containing shareable items
    356369    @see SessionControl#setActiveProject(Project)
    357370  */
    358   public ResultList<Shareable> getItems(Item itemType, int firstItem, int maxItems, Permission permission)
    359   {
     371  public ResultList<Shareable> getItems(Item itemType, int firstItem, int maxItems,
     372    Permission permission, Set<Include> include)
     373  {
     374    if (include == null) include = EnumSet.of(Include.NOT_REMOVED, Include.MINE, Include.OTHERS);
     375   
    360376    DbControl dc = getDbControl();
    361377    SessionControl sc = dc.getSessionControl();
     
    376392      projectKeys = new HashSet<Integer>(HibernateUtil.loadList(Integer.class, query));
    377393     
    378       // Enable 'ownedBy' filter since this is not the active project
    379       org.hibernate.Filter ownerFilter = HibernateUtil.enableFilter(session, "ownedBy");
    380       ownerFilter.setParameter("owner", sc.getLoggedInUserId());
     394      include.remove(Include.OTHERS);
    381395    }
    382396    else
     
    409423    keyFilter.setParameter("owner", sc.getLoggedInUserId());
    410424   
     425    // Add filters for 'removed' option
     426    if (!(include.contains(Include.REMOVED) && include.contains(Include.NOT_REMOVED)))
     427    {
     428      org.hibernate.Filter removedFilter = HibernateUtil.enableFilter(session, "isRemoved");
     429      removedFilter.setParameter("removed", include.contains(Include.REMOVED));
     430    }
     431    // Add filter for 'owned by me' and 'owned by others' options
     432    if (include.contains(Include.MINE) && include.contains(Include.OTHERS))
     433    {
     434      // Do nothing; all items are included
     435    }
     436    else if (include.contains(Include.MINE))
     437    {
     438      org.hibernate.Filter ownerFilter = HibernateUtil.enableFilter(session, "ownedBy");
     439      ownerFilter.setParameter("owner", sc.getLoggedInUserId());
     440    }
     441    else if (include.contains(Include.OTHERS))
     442    {
     443      org.hibernate.Filter otherFilter = HibernateUtil.enableFilter(session, "notOwnedBy");
     444      otherFilter.setParameter("owner", sc.getLoggedInUserId());     
     445    }
     446    else
     447    {
     448      org.hibernate.Filter denyAllFilter = HibernateUtil.enableFilter(session, "denyAll");
     449    }
     450   
    411451    // Query to load all shareable items
    412452    org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_SHARED_ITEMS");
     
    422462    HibernateUtil.disableFilter(session, "inProject");
    423463    HibernateUtil.disableFilter(session, "ownedBy");
     464    HibernateUtil.disableFilter(session, "notOwnedBy");
     465    HibernateUtil.disableFilter(session, "isRemoved");
     466    HibernateUtil.disableFilter(session, "denyAll");
    424467   
    425468    Class<? extends BasicData> dataClass = itemType == null ? null : itemType.getDataClass();
  • branches/2.3.1/www/my_base/projects/items/list_items.jsp

    r3190 r3448  
    6969final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null);
    7070final int projectId = Values.getInt(request.getParameter("project_id"));
     71final int activeProjectId = sc.getActiveProjectId();
    7172final DbControl dc = sc.newDbControl();
    7273ResultList<Shareable> items = null;
     
    7879  {
    7980    items = project.getItems(filterItem == null ? null : Item.valueOf(filterItem),
    80       cc.getPage() * cc.getRowsPerPage(), cc.getRowsPerPage(), cc.getItemPermission());
     81      cc.getPage() * cc.getRowsPerPage(), cc.getRowsPerPage(), cc.getItemPermission(),
     82      cc.getInclude());
    8183  }
    8284  catch (Throwable t)
     
    147149      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>');
    148150    }
     151    function setToActive()
     152    {
     153      Main.openPopup('../set_active.jsp?ID=<%=ID%>&project_id=<%=projectId%>', 'ActivateProject', 300, 140);
     154    }
    149155    function switchTab(tabControlId, tabId)
    150156    {
     
    253259        />
    254260      </tbl:toolbar>
     261      <%
     262      if (projectId != activeProjectId)
     263      {
     264        %>
     265        <tbl:panel>
     266          <div class="error" onclick="setToActive()" style="cursor: pointer;"
     267            title="Click to make this project the active project">
     268          This project is not the active project. The list can't display items
     269          that are owned by other members of the project.
     270          </div>
     271        </tbl:panel>
     272        <%
     273      }
     274      %>
    255275      <tbl:navigator
    256276        page="<%=cc.getPage()%>"
     
    264284            colspan="3"
    265285            onchange="presetOnChange()"
     286            disablesharedto="true"
     287            disableothers="<%=projectId != activeProjectId%>"
    266288          />
    267289        </tbl:columns>
  • branches/2.3.1/www/my_base/projects/set_active.jsp

    r2978 r3448  
    2828  import="net.sf.basedb.core.SessionControl"
    2929  import="net.sf.basedb.core.DbControl"
     30  import="net.sf.basedb.core.Item"
    3031  import="net.sf.basedb.core.Project"
     32  import="net.sf.basedb.core.Include"
     33  import="net.sf.basedb.core.ItemContext"
    3134  import="net.sf.basedb.clients.web.Base"
    3235  import="net.sf.basedb.util.Values"
     
    4851{
    4952  Project p = null;
    50   if (projectId != 0) p = Project.getById(dc, projectId);
     53  ItemContext allItems = sc.getCurrentContext(Item.PROJECT, "items");
     54  allItems.getInclude().add(Include.MINE);
     55  if (projectId != 0)
     56  {
     57    p = Project.getById(dc, projectId);
     58    allItems.getInclude().add(Include.OTHERS);
     59  }
    5160  sc.setActiveProject(p);
    5261  sc.setUserClientSetting("projects.lastactive", projectId == 0 ? null : Integer.toString(projectId));
Note: See TracChangeset for help on using the changeset viewer.