Changeset 5203


Ignore:
Timestamp:
Dec 16, 2009, 12:56:43 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1435: Reset settings for a specific list in the "Reset list settings" function

The user now has the option to reset the list settings for all lists or only for a specific list.

Location:
trunk
Files:
3 edited

Legend:

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

    r5185 r5203  
    4747import net.sf.basedb.core.authentication.AuthenticationInformation;
    4848
     49import java.util.ArrayList;
    4950import java.util.Date;
    5051import java.util.Iterator;
     
    16311632 
    16321633  /**
     1634    Get a list with the current default contexts. The list may include,
     1635    only in-memory contexts, in-database contexts, or both. If both
     1636    options are enabled and an in-memory context also has a database
     1637    representation, both are included in the list. Eg. the list
     1638    may include more than one context were {@link ItemContext#getContextId()}
     1639    returns the same value.
     1640   
     1641    @param inMemory If TRUE, the in-memory contexts are included in the list
     1642    @param inDatabase If TRUE, the in-database contexts are included in the list
     1643    @return A list with ItemContext objects
     1644    @since 2.15
     1645  */
     1646  public List<ItemContext> getAllCurrentContexts(boolean inMemory, boolean inDatabase)
     1647  {
     1648    List<ItemContext> all = new ArrayList<ItemContext>();
     1649    if (inMemory)
     1650    {
     1651      all.addAll(currentContexts.values());
     1652    }
     1653    if (inDatabase)
     1654    {
     1655      org.hibernate.Session session = null;
     1656      org.hibernate.Transaction tx = null;
     1657      ItemContext context = null;
     1658      try
     1659      {
     1660        session = HibernateUtil.newSession();
     1661        tx = HibernateUtil.newTransaction(session);
     1662       
     1663        org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
     1664          "LOAD_USER_CONTEXTS");
     1665          /*
     1666            SELECT ctx
     1667            FROM ContextData ctx
     1668            WHERE ctx.user.id = :user
     1669            AND ctx.client.id = :client
     1670            AND ctx.name = :name
     1671          */
     1672        query.setInteger("user", loginInfo.userId);
     1673        query.setInteger("client", getClientId());
     1674        query.setString("name", ItemContext.DEFAULT_NAME);
     1675        List<ContextData> contexts = HibernateUtil.loadList(ContextData.class, query, this);
     1676        for (ContextData ctx : contexts)
     1677        {
     1678          all.add(new ItemContext(ctx));
     1679        }
     1680        HibernateUtil.commit(tx);
     1681      }
     1682      catch (BaseException ex)
     1683      {
     1684        if (tx != null) HibernateUtil.rollback(tx);
     1685        throw ex;
     1686      }
     1687      finally
     1688      {
     1689        if (session != null) HibernateUtil.close(session);
     1690      }
     1691    }
     1692    return all;
     1693  }
     1694 
     1695  /**
    16331696    Delete all default contexts for the logged in user.
    16341697   
  • trunk/www/my_base/user/reset_filters.jsp

    r4889 r5203  
    2626  import="net.sf.basedb.core.SessionControl"
    2727  import="net.sf.basedb.core.Item"
     28  import="net.sf.basedb.core.ItemContext"
    2829  import="net.sf.basedb.core.DbControl"
    2930  import="net.sf.basedb.core.User"
     
    3132  import="net.sf.basedb.clients.web.util.HTML"
    3233  import="net.sf.basedb.util.Values"
     34  import="net.sf.basedb.util.ToStringComparator"
     35  import="net.sf.basedb.util.NestedIterator"
     36  import="java.util.Iterator"
    3337  import="java.util.List"
    3438  import="java.util.Set"
     
    4751{
    4852  final User user = User.getById(dc, sc.getLoggedInUserId());
     53  final List<ItemContext> inMemory = sc.getAllCurrentContexts(true, false);
     54  final List<ItemContext> inDatabase = sc.getAllCurrentContexts(false, true);
     55  final Set<Item> items = new TreeSet<Item>(new ToStringComparator<Item>(false));
     56  final Set<Item> dbOnly = new HashSet<Item>();
     57  Iterator<ItemContext> it = new NestedIterator(inMemory, inDatabase);
     58  for (ItemContext ctx : inMemory)
     59  {
     60    if (ctx.getNumPropertyFilters() > 0 || ctx.getSortProperty() != null)
     61    {
     62      items.add(ctx.getItemType());
     63    }
     64  }
     65  for (ItemContext ctx : inDatabase)
     66  {
     67    if (ctx.getNumPropertyFilters() > 0 || ctx.getSortProperty() != null)
     68    {
     69      if (items.add(ctx.getItemType())) dbOnly.add(ctx.getItemType());
     70    }
     71  }
    4972  %>
    50 
    5173  <base:page type="popup" title="<%="Reset list settings for "+HTML.encodeTags(user.getName())%>">
    5274  <base:head>
     
    5678      var frm = document.forms['preferences'];
    5779      frm.submit();
     80    }
     81    function itemTypeOnChange()
     82    {
     83      var frm = document.forms['preferences'];
     84      var dbOnly = frm.item_type[frm.item_type.selectedIndex].text.indexOf('*') >= 0;
     85      frm.database.checked = dbOnly;
    5886    }
    5987    </script>
     
    72100    <table class="form" cellspacing=0>
    73101    <tr>
    74       <td class="prompt">Which?</td>
     102      <td class="prompt">Which list?</td>
     103      <td>
     104        <select name="item_type" onchange="itemTypeOnChange()">
     105          <option value="">- all -
     106          <%
     107          for (Item item : items)
     108          {
     109            %>
     110            <option value="<%=item.name()%>"><%=dbOnly.contains(item) ? "* " : "" %><%=item%>
     111            <%
     112          }
     113          %>
     114        </select><br>
     115        * = This setting is only in the database
     116      </td>
     117    </tr>
     118    <tr>
     119      <td class="prompt">Location</td>
    75120      <td>
    76121      <input type="checkbox" name="memory" value="1" checked disabled>In-memory<br>
  • trunk/www/my_base/user/submit_user.jsp

    r5060 r5203  
    157157  {
    158158    boolean inDatabase = Values.getBoolean(request.getParameter("database"));
    159     int numDeleted = sc.deleteCurrentContexts(null, true, inDatabase);
     159    String itemType = Values.getStringOrNull(request.getParameter("item_type"));
     160    Item item = itemType == null ? null : Item.valueOf(itemType);
     161    int numDeleted = sc.deleteCurrentContexts(item, true, inDatabase);
    160162    message = numDeleted + " list settings deleted";
    161163  }
Note: See TracChangeset for help on using the changeset viewer.