source: trunk/www/my_base/index.jsp @ 7394

Last change on this file since 7394 was 7394, checked in by Nicklas Nordborg, 5 years ago

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.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.4 KB
Line 
1<%-- $Id: index.jsp 7394 2017-06-09 12:23:58Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
5  Copyright (C) 2007 Johan Enell
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 3
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with BASE. If not, see <http://www.gnu.org/licenses/>.
22  ------------------------------------------------------------------
23  This is the welcome page once the user has logged in to BASE.
24  It should do a lot more than display an empty page....
25
26  ...To be done....
27
28  @author Nicklas
29  @version 2.0
30--%>
31<%@ page pageEncoding="UTF-8" session="false"
32  import="net.sf.basedb.core.SessionControl"
33  import="net.sf.basedb.core.DbControl"
34  import="net.sf.basedb.core.User"
35  import="net.sf.basedb.core.Group"
36  import="net.sf.basedb.core.Message"
37  import="net.sf.basedb.core.Project"
38  import="net.sf.basedb.core.News"
39  import="net.sf.basedb.core.Include"
40  import="net.sf.basedb.core.Location"
41  import="net.sf.basedb.core.Type"
42  import="net.sf.basedb.core.Quota"
43  import="net.sf.basedb.core.QuotaType"
44  import="net.sf.basedb.core.ItemQuery"
45  import="net.sf.basedb.core.ItemResultList"
46  import="net.sf.basedb.core.SystemItems"
47  import="net.sf.basedb.core.query.Orders"
48  import="net.sf.basedb.core.query.Expression"
49  import="net.sf.basedb.core.query.Hql"
50  import="net.sf.basedb.core.query.Restrictions"
51  import="net.sf.basedb.core.query.Expressions"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.formatter.Formatter"
55  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
56  import="net.sf.basedb.clients.web.servlet.RssNewsFeed"
57  import="net.sf.basedb.util.Values"
58  import="java.util.Date" 
59  import="java.util.List"
60  import="java.util.ArrayList"
61  import="java.util.Set"
62  import="java.util.HashSet"
63%>
64<%@ taglib
65  prefix="base" uri="/WEB-INF/base.tld"
66%>
67<%!
68private String getPrintableQuota(long myQuota, long groupQuota)
69{
70  String printable = "";
71  if (myQuota == Quota.UNDEFINED && groupQuota == Quota.UNDEFINED)
72  {
73    // Both are undefined
74    printable = "";
75  }
76  else if (myQuota < 0 && groupQuota < 0)
77  {
78    // both are unlimited or one is unlimited and the other is undefined
79    printable = "unlimited";
80  }
81  else if (myQuota >= 0 && groupQuota >= 0)
82  {
83    // both are well-defined; use min value
84    printable = Values.formatBytes(Math.min(myQuota, groupQuota));
85  }
86  else
87  {
88    // Only one is well-defined; use max value
89    printable = Values.formatBytes(Math.max(myQuota, groupQuota));
90  }
91  return printable;
92}
93%>
94<%
95SessionControl sc = Base.getExistingSessionControl(pageContext, true);
96String ID = sc.getId();
97
98DbControl dc = null;
99try
100{
101  dc = sc.newDbControl();
102  User user = User.getById(dc, sc.getLoggedInUserId());
103  Quota quota = user.getQuota();
104  Group quotaGroup = user.getQuotaGroup();
105  Quota groupQuota = quotaGroup == null ? null : quotaGroup.getQuota();
106 
107  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
108  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
109
110  ItemQuery<Message> messageQuery = Message.getQuery(user);
111  messageQuery.order(Orders.desc(Hql.property("timeSent")));
112  messageQuery.restrict(Restrictions.eq(Hql.property("read"), Expressions.parameter("isread", false)));
113  ItemResultList<Message> messages = messageQuery.list(dc);
114 
115  List<Project> projects = new ArrayList<Project>();
116  String tmp = sc.getUserClientSetting("projects.recentActive");
117  Set<Integer> recentProjects = new HashSet<Integer>();
118  if (tmp != null)
119  {
120    for (String id : tmp.split(":"))
121    {
122      try
123      {
124        Project p = Project.getById(dc, Values.getInt(id));
125        if (!p.isRemoved())
126        {
127          recentProjects.add(p.getId());
128          projects.add(p);
129        }
130      }
131      catch (RuntimeException ex)
132      {}
133    }
134  }
135  ItemQuery<Project> projectQuery = Project.getQuery();
136  projectQuery.order(Orders.asc(Hql.property("name")));
137  projectQuery.include(Include.MINE, Include.SHARED);
138  projectQuery.restrict(Restrictions.not(Restrictions.in(Hql.property("id"), Expressions.parameter("projects"))));
139  projectQuery.setParameter("projects", recentProjects, Type.INT);
140  projects.addAll(projectQuery.list(dc));
141 
142  QuotaType totalQuotaType = QuotaType.getById(dc, SystemItems.getId(QuotaType.TOTAL));
143  ItemQuery<QuotaType> quotaTypeQuery = QuotaType.getQuery();
144  quotaTypeQuery.order(Orders.asc(Hql.property("id")));
145  quotaTypeQuery.restrict(
146    Restrictions.neq(
147      Hql.property("id"), 
148      Hql.entity(totalQuotaType)
149    )
150  );
151  ItemResultList<QuotaType> quotaTypes = quotaTypeQuery.list(dc);
152
153  ItemQuery<News> newsQuery = News.getQuery();
154  Expression today = Expressions.parameter("today");
155  newsQuery.restrict(Restrictions.lteq(Hql.property("startDate"), today));
156  newsQuery.restrict(
157    Restrictions.or(
158      Restrictions.gteq(Hql.property("endDate"), today),
159      Restrictions.eq(Hql.property("endDate"), null)
160    )
161  );
162  newsQuery.order(Orders.desc(Hql.property("sticky")));
163  newsQuery.order(Orders.desc(Hql.property("newsDate")));
164  newsQuery.order(Orders.desc(Hql.property("id")));
165  newsQuery.setParameter("today", new Date(), Type.DATE);
166  ItemResultList<News> news = newsQuery.list(dc);
167 
168  String help = Values.getStringOrNull(sc.getClientDefaultSetting("server.links.help"));
169  String faq = Values.getStringOrNull(sc.getClientDefaultSetting("server.links.faq"));
170  String reportBug = Values.getStringOrNull(sc.getClientDefaultSetting("server.links.reportbug"));
171  boolean hasHelp = help != null || faq != null || reportBug != null;
172%>
173<base:page title="Welcome to BASE">
174<base:head styles="login.css" scripts="~home.js"/>
175<base:body>
176
177  <h1>Welcome to BASE</h1>
178
179  <div class="content">
180 
181  <div class="absolutefull" style="width: 50%;">
182 
183    <div class="absolutefull" style="left: 1em; right: 0.5em; bottom: <%=hasHelp ? "16em" : "1em" %>;">
184
185    <div class="absolutefull" style="height: 50%;">
186      <div class="absolutefull" style="height: 2em; overflow: hidden;">
187        <h3 style="height: 100%;"><base:icon image="project.png" />Projects (<%=projects.size()%>)</h3>
188      </div>
189      <div id="projectsSection" class="absolutefull welcomesection" style="top: 2em; bottom: 0.5em;">
190      <%
191      if (projects.size() == 0)
192      {
193        %>
194        You are not member of any projects.
195        <%
196      }
197      else
198      {
199        int activeProjectId = sc.getActiveProjectId();
200        %>
201        <table style="border-spacing: 2px;">
202        <%
203        if (activeProjectId == 0)
204        {
205          %>
206          <td><base:icon image="warning.png" /></td>
207          <td><i>No active project</i></td>
208          <td>&nbsp;</td>
209          <%
210        }
211        for (Project p : projects)
212        {
213          int projectId = p.getId();
214          if (projectId == activeProjectId)
215          {
216            %>
217            <tr>
218              <td><base:icon image="bullet.png" /></td>
219              <td><b><%=Base.getLinkedName(ID, p, false, true)%></b></td>
220              <td>[active]</td>
221            </tr>
222            <%
223          }
224          else
225          {
226            %>
227            <tr>
228              <td>&nbsp;</td>
229              <td><%=Base.getLinkedName(ID, p, false, true)%></td>
230              <td>[<span class="link auto-init" data-auto-init="activate-project" 
231                data-project-id="<%=projectId%>">set active</span>]</td>
232            </tr>
233            <%
234          }
235        }
236        %>
237        </table>
238        <%
239      }
240      %>
241      </div>
242    </div>
243
244    <div class="absolutefull" style="height: 50%; top: auto;">
245      <div class="absolutefull" style="height: 2em; top: 0.5em; overflow: hidden;">
246        <h3 style="height: 100%;"><base:icon image="message.png" />New messages (<%=messages.size()%>)</h3>
247      </div>
248      <div id="messagesSection" class="absolutefull news welcomesection" style="top: 2.5em;">
249      <%
250      String broadcastTitle = (String)application.getAttribute("broadcast.title");
251      if (broadcastTitle != null)
252      {
253        String broadcastMessage = (String)application.getAttribute("broadcast.message");
254        %>
255        <div class="item note sticky">
256          <div class="headline">
257            <span class="date"><%=dateFormatter.format(new Date())%></span>
258            <%=HTML.encodeTags(broadcastTitle)%>
259          </div>
260          <div class="text"><%=HTML.niceFormat(broadcastMessage)%></div>
261        </div>
262        <% 
263      }
264      if (messages.size() == 0 && broadcastTitle == null)
265      {
266        %>
267        No new messages.
268        <%
269      }
270      else
271      {
272        for (Message m : messages)
273        {
274          String fullName = m.getName();
275          String text = Values.trimString(m.getDescription(), 100);
276          %>
277          <div class="item">
278            <div class="headline">
279              <span class="link auto-init" data-auto-init="item-link" 
280                data-item-type="MESSAGE" data-item-id="<%=m.getId()%>" 
281                title="<%=HTML.encodeTags(fullName)%>">
282              <span class="date"><%=dateTimeFormatter.format(m.getTimeSent())%></span>
283              <%=HTML.encodeTags(fullName)%></a>
284            </div>
285            <div class="text"><%=HTML.encodeTags(text)%></div>
286          </div>
287          <%
288        }
289      }
290      %>
291      </div>
292    </div>
293  </div>
294 
295  <%
296  if (hasHelp)
297  {
298    %>
299    <div class="absolutefull" style="left: 1em; right: 0.5em; top: auto; height: 14em; bottom: 1em; ">
300      <div class="absolutefull" style="height: 2em; overflow: hidden;">
301      <h3 style="height: 100%;"><base:icon image="help.png" />Help</h3>
302      </div>
303      <div id="helpSection" class="absolutefull welcomesection" style="top: 2em;">
304      <%
305      if (help != null)
306      {
307        %>
308        <a href="<%=help%>" target="Help"><base:icon image="bullet.png" />&nbsp;Help&hellip;</a><br>
309        <%
310      }
311      %>
312      <%
313      if (faq != null)
314      {
315        %>
316        <a href="<%=faq%>" target="FAQ"><base:icon image="bullet.png" />&nbsp;Frequently asked questions&hellip;</a><br>
317        <%
318      }
319      %>
320      <%
321      if (reportBug != null)
322      {
323        %>
324        <a href="<%=reportBug%>" target="ReportBug"><base:icon image="bug.png" />&nbsp;Report a bug&hellip;</a><br>
325        <%
326      }
327      %>
328      </div>
329    </div>
330    <%
331  }
332  %>
333 
334  </div>
335  <div class="absolutefull" style="width: 50%; left: auto;">
336 
337    <div class="absolutefull" style="left: 0.5em; right: 1em; bottom: 16em;">
338      <div class="absolutefull" style="height: 2em; overflow: hidden;">
339      <h3 style="height: 100%;"><base:icon image="news.png" />News and announcements (<%=news.size()%>)
340        <%
341        if (RssNewsFeed.isEnabled()) 
342        {
343          %>
344          <a href="../info/news.rss" 
345            title="Subscribe to news from this BASE server"><base:icon image="rss.png" style="float: right;"/></a>
346          <%
347        }
348        %>
349      </h3>
350      </div>
351      <div id="newsSection" class="absolutefull news welcomesection" style="top: 2em;">
352        <%
353        if (news.size() == 0)
354        {
355          %>
356          Nothing new.
357          <%
358        }
359        else
360        {
361          for (News n : news)
362          {
363            %>
364            <div class="item <%=n.isSticky() ? "note sticky" :""%>">
365              <div class="headline">
366                <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
367                <%=HTML.encodeTags(n.getName())%>
368              </div>
369              <div class="text"><%=HTML.niceFormat(n.getDescription())%></div>
370            </div>
371            <%
372          }
373        }
374        %>
375      </div>
376    </div>
377 
378    <div class="absolutefull" style="left: 0.5em; right: 1em; top: auto; height: 14em; bottom: 1em;">
379      <div class="absolutefull" style="height: 2em; overflow: hidden;">
380      <h3 style="height: 100%;"><base:icon image="diskusage.png" />Disk usage</h3>
381      </div>
382      <div id="quotaSection" class="absolutefull welcomesection" style="top: 2em;">
383      <%
384      if (quotaGroup != null)
385      {
386        %>
387        Using quota from group: <%=Base.getLinkedName(ID, quotaGroup, false, true)%>
388        <%
389      }
390      %>
391      <table style="width: 100%;">
392      <tr style="text-align: center;">
393        <th></th>
394        <th colspan="2">Primary location</th>
395        <th colspan="2">Secondary location</th>
396        <th>External</th>
397      </tr>
398      <tr style="text-align: center;">
399        <th></th>
400        <th>Used</th>
401        <th>Assigned</th>
402        <th>Used</th>
403        <th>Assigned</th>
404        <th>Used</th>
405      </tr>
406      <%
407        long myPrimaryUsage = user.getDiskUsage(totalQuotaType, Location.PRIMARY);
408        long myPrimaryQuota = quota.getQuotaValue(totalQuotaType, Location.PRIMARY);
409        long groupPrimaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(totalQuotaType, Location.PRIMARY);
410        long mySecondaryUsage = user.getDiskUsage(totalQuotaType, Location.SECONDARY);
411        long mySecondaryQuota = quota.getQuotaValue(totalQuotaType, Location.SECONDARY);
412        long groupSecondaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(totalQuotaType, Location.SECONDARY);
413        long myExternalUsage = user.getDiskUsage(totalQuotaType, Location.EXTERNAL);
414      %>
415      <tr style="text-align: center;">
416        <th>Total</th>
417        <td><%=getPrintableQuota(myPrimaryUsage, Quota.UNDEFINED)%></td>
418        <td><%=getPrintableQuota(myPrimaryQuota, groupPrimaryQuota)%></td>
419        <td><%=getPrintableQuota(mySecondaryUsage, Quota.UNDEFINED)%></td>
420        <td><%=getPrintableQuota(mySecondaryQuota, groupSecondaryQuota)%></td>
421        <td><%=getPrintableQuota(myExternalUsage, Quota.UNDEFINED)%></td>
422      </tr>
423      <tr>
424        <td colspan="6" style="border-top-width: 1px; border-top-style: dotted;"></td>
425      </tr>
426      <%
427      for (QuotaType qt : quotaTypes)
428      {
429        myPrimaryUsage = user.getDiskUsage(qt, Location.PRIMARY);
430        myPrimaryQuota = quota.getQuotaValue(qt, Location.PRIMARY);
431        groupPrimaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(qt, Location.PRIMARY);
432        mySecondaryUsage = user.getDiskUsage(qt, Location.SECONDARY);
433        mySecondaryQuota = quota.getQuotaValue(qt, Location.SECONDARY);
434        groupSecondaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(qt, Location.SECONDARY);
435        myExternalUsage = user.getDiskUsage(qt, Location.EXTERNAL);
436        %>
437        <tr style="text-align: center;">
438          <th><%=HTML.encodeTags(qt.getName())%></th>
439          <td><%=getPrintableQuota(myPrimaryUsage, Quota.UNDEFINED)%></td>
440          <td><%=getPrintableQuota(myPrimaryQuota, groupPrimaryQuota)%></td>
441          <td><%=getPrintableQuota(mySecondaryUsage, Quota.UNDEFINED)%></td>
442          <td><%=getPrintableQuota(mySecondaryQuota, groupSecondaryQuota)%></td>
443          <td><%=getPrintableQuota(myExternalUsage, Quota.UNDEFINED)%></td>
444        </tr>
445        <%
446      }
447      %>
448      <tr>
449        <td colspan="6" style="border-top-width: 1px; border-top-style: dotted;"></td>
450      </tr>
451      </table>
452      <base:buttongroup>
453        <base:button id="btnViewDiskUsage" image="bullet.png" title="View details" />
454      </base:buttongroup>
455      </div>
456    </div>
457  </div>
458  </div>
459</base:body>
460</base:page>
461  <%
462}
463finally
464{
465  if (dc != null) dc.close();
466}
467%>
Note: See TracBrowser for help on using the repository browser.