Changeset 7394 for trunk/www/main.jsp


Ignore:
Timestamp:
Jun 9, 2017, 2:23:58 PM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2085: Sticky news

Various places where news are displyed have been updated to sort the news with the "sticky" flag set first. The sticky news item are displayed with a different background color and a "paperclip" icon.

The login page has also been modified to show all sticky news even if there are more than 10 items which was the limit before.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/main.jsp

    r7114 r7394  
    3737  import="net.sf.basedb.core.News"
    3838  import="net.sf.basedb.core.ItemQuery"
    39   import="net.sf.basedb.core.ItemResultList"
     39  import="net.sf.basedb.core.ItemResultIterator"
    4040  import="net.sf.basedb.core.query.Orders"
    4141  import="net.sf.basedb.core.query.Hql"
     
    7878  String broadcastMessage = (String)application.getAttribute("broadcast.message");
    7979  boolean denyLogin = Boolean.TRUE.equals(application.getAttribute("broadcast.deny-login"));
    80   ItemResultList<News> news = null;
     80  ItemResultIterator<News> news = null;
    8181  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
    8282  ExtensionsInvoker<LoginFormAction> invoker = (ExtensionsInvoker<LoginFormAction>)ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form");
     
    242242      {
    243243        %>
    244         <div class="item">
     244        <div class="item note sticky">
    245245          <div class="headline">
    246             <base:icon image="warning.png" />
    247246            <span class="date"><%=dateFormatter.format(new Date())%></span>
    248247            <%=HTML.encodeTags(broadcastTitle)%><%=denyLogin ? " (login disabled)" : "" %>
     
    254253     
    255254      ItemQuery<News> query = News.getQuery();
     255      query.order(Orders.desc(Hql.property("sticky")));
    256256      query.order(Orders.desc(Hql.property("newsDate")));
    257257      query.order(Orders.desc(Hql.property("id")));
    258258      query.setCacheResult(true);
    259259      query.setReturnTotalCount(true);
    260       query.setMaxResults(10);
    261       news = query.list(dc);
    262       for (News n : news)
    263       {
    264         %>
    265         <div class="item">
     260      news = query.iterate(dc);
     261      int numListed = 0;
     262      while (news.hasNext())
     263      {
     264        News n = news.next();
     265        if (numListed >= 10 && !n.isSticky()) break;
     266        %>
     267        <div class="item <%=n.isSticky() ? "note sticky" : ""%>">
    266268          <div class="headline">
    267269            <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
     
    271273        </div>
    272274        <%
    273       }
    274       if (news.getTotalCount() > 10)
     275        numListed++;
     276      }
     277      if (numListed < news.getTotalCount())
    275278      {
    276279        %>
    277280        <base:icon image="bullet.png" /><a href="info/news.jsp"
    278           title="Show older news..."><%=news.getTotalCount()-10%> more</a>
     281          title="Show older news..."><%=news.getTotalCount()-numListed%> more</a>
    279282        <%
    280283      }
Note: See TracChangeset for help on using the changeset viewer.