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

Last change on this file since 5478 was 5478, checked in by Nicklas Nordborg, 12 years ago

References #1545: Publish news as a rss feed

Added servlet RssNewsFeed to serve rss document. It will cache the current news so it should not be too heavy even if clients update often.

The feed includes all public news and the broadcast message that the admin can set in the Administrate -> Broadcast message dialog.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.3 KB
Line 
1<%-- $Id: index.jsp 5478 2010-11-05 10:38:08Z 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.util.Values"
57  import="java.util.Date" 
58  import="java.util.List"
59  import="java.util.ArrayList"
60  import="java.util.Set"
61  import="java.util.HashSet"
62%>
63<%@ taglib
64  prefix="base" uri="/WEB-INF/base.tld"
65%>
66<%!
67private String getPrintableQuota(long myQuota, long groupQuota)
68{
69  String printable = "";
70  if (myQuota == Quota.UNDEFINED && groupQuota == Quota.UNDEFINED)
71  {
72    // Both are undefined
73    printable = "";
74  }
75  else if (myQuota < 0 && groupQuota < 0)
76  {
77    // both are unlimited or one is unlimited and the other is undefined
78    printable = "unlimited";
79  }
80  else if (myQuota >= 0 && groupQuota >= 0)
81  {
82    // both are well-defined; use min value
83    printable = Values.formatBytes(Math.min(myQuota, groupQuota));
84  }
85  else
86  {
87    // Only one is well-defined; use max value
88    printable = Values.formatBytes(Math.max(myQuota, groupQuota));
89  }
90  return printable;
91}
92%>
93<%
94SessionControl sc = Base.getExistingSessionControl(pageContext, true);
95String ID = sc.getId();
96
97DbControl dc = null;
98try
99{
100  dc = sc.newDbControl();
101  User user = User.getById(dc, sc.getLoggedInUserId());
102  Quota quota = user.getQuota();
103  Group quotaGroup = user.getQuotaGroup();
104  Quota groupQuota = quotaGroup == null ? null : quotaGroup.getQuota();
105 
106  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
107  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
108
109  ItemQuery<Message> messageQuery = Message.getQuery(user);
110  messageQuery.order(Orders.desc(Hql.property("timeSent")));
111  messageQuery.restrict(Restrictions.eq(Hql.property("read"), Expressions.parameter("isread", false)));
112  ItemResultList<Message> messages = messageQuery.list(dc);
113 
114  List<Project> projects = new ArrayList<Project>();
115  String tmp = sc.getUserClientSetting("projects.recentActive");
116  Set<Integer> recentProjects = new HashSet<Integer>();
117  if (tmp != null)
118  {
119    for (String id : tmp.split(":"))
120    {
121      try
122      {
123        Project p = Project.getById(dc, Values.getInt(id));
124        if (!p.isRemoved())
125        {
126          recentProjects.add(p.getId());
127          projects.add(p);
128        }
129      }
130      catch (RuntimeException ex)
131      {}
132    }
133  }
134  ItemQuery<Project> projectQuery = Project.getQuery();
135  projectQuery.order(Orders.asc(Hql.property("name")));
136  projectQuery.include(Include.MINE, Include.SHARED);
137  projectQuery.restrict(Restrictions.not(Restrictions.in(Hql.property("id"), Expressions.parameter("projects"))));
138  projectQuery.setParameter("projects", recentProjects, Type.INT);
139  projects.addAll(projectQuery.list(dc));
140 
141  QuotaType totalQuotaType = QuotaType.getById(dc, SystemItems.getId(QuotaType.TOTAL));
142  ItemQuery<QuotaType> quotaTypeQuery = QuotaType.getQuery();
143  quotaTypeQuery.order(Orders.asc(Hql.property("id")));
144  quotaTypeQuery.restrict(
145    Restrictions.neq(
146      Hql.property("id"), 
147      Hql.entity(totalQuotaType)
148    )
149  );
150  ItemResultList<QuotaType> quotaTypes = quotaTypeQuery.list(dc);
151
152  ItemQuery<News> newsQuery = News.getQuery();
153  Expression today = Expressions.parameter("today");
154  newsQuery.restrict(Restrictions.lteq(Hql.property("startDate"), today));
155  newsQuery.restrict(
156    Restrictions.or(
157      Restrictions.gteq(Hql.property("endDate"), today),
158      Restrictions.eq(Hql.property("endDate"), null)
159    )
160  );
161  newsQuery.order(Orders.desc(Hql.property("newsDate")));
162  newsQuery.order(Orders.desc(Hql.property("id")));
163  newsQuery.setParameter("today", new Date(), Type.DATE);
164  ItemResultList<News> news = newsQuery.list(dc);
165%>
166<base:page title="Welcome to BASE">
167<base:head styles="login.css">
168
169<script language="JavaScript">
170
171  function viewMessage(messageId)
172  {
173    Main.viewOrEditItem('<%=ID%>', 'MESSAGE', messageId, false);
174  }
175  function setActiveProject(projectId)
176  {
177    Main.openPopup('projects/set_active.jsp?ID=<%=ID%>&project_id='+projectId, 'ActivateProject', 300, 140)
178  }
179</script>
180
181</base:head>
182<base:body onload="top.frames['footnote'].location.reload()">
183
184
185<table border="0" cellspacing="0" cellpadding="0" width="100%">
186<tr valign="top">
187  <td width="50%">
188 
189  <h3 class="light docked">
190    <base:icon image="project.gif" />
191    &nbsp;Projects (<%=projects.size()%>)
192  </h3>
193    <div id="projects" class="welcomesection" style="height: 210px; overflow: auto;">
194    <%
195    if (projects.size() == 0)
196    {
197      %>
198      You are not member of any projects.
199      <%
200    }
201    else
202    {
203      int activeProjectId = sc.getActiveProjectId();
204      %>
205      <table border="0" cellspacing="0" cellpadding="2">
206      <%
207      if (activeProjectId == 0)
208      {
209        %>
210        <td><base:icon image="warning.gif" /></td>
211        <td><i>No active project</i></td>
212        <td>&nbsp;</td>     
213        <%
214      }
215      for (Project p : projects)
216      {
217        int projectId = p.getId();
218        if (projectId == activeProjectId)
219        {
220          %>
221          <tr>
222            <td><base:icon image="bullet.gif" /></td>
223            <td><b><%=Base.getLinkedName(ID, p, false, true)%></b></td>
224            <td>[active]</td>
225          </tr>
226          <%
227        }
228        else
229        {
230          %>
231          <tr>
232            <td>&nbsp;</td>
233            <td><%=Base.getLinkedName(ID, p, false, true)%></td>
234            <td>[<a href="javascript:setActiveProject(<%=projectId%>)">set active</a>]</td>
235          </tr>
236          <%
237        }
238      }
239      %>
240      </table>
241      <%
242    }
243    %>
244    </div>
245
246  <h3 class="light docked">
247    <base:icon image="message.gif" />
248    &nbsp;New messages (<%=messages.size()%>)</h3>
249    <div id="messages" class="news welcomesection" style="height: 210px; overflow: auto;">
250    <%
251    String broadcastTitle = (String)application.getAttribute("broadcast.title");
252    if (broadcastTitle != null)
253    {
254      String broadcastMessage = (String)application.getAttribute("broadcast.message");
255      %>
256      <div class="item"><base:icon image="warning.gif" />
257        <span class="date"><%=dateFormatter.format(new Date())%></span>
258        <span class="headline"><%=HTML.encodeTags(broadcastTitle)%></span><br>
259        <span class="text"><%=HTML.niceFormat(broadcastMessage)%></span>
260      </div>
261      <% 
262    }
263    if (messages.size() == 0 && broadcastTitle == null)
264    {
265      %>
266      No new messages.
267      <%
268    }
269    else
270    {
271      for (Message m : messages)
272      {
273        String fullName = m.getName();
274        String shortName = Values.trimString(fullName, 50);
275        String text = Values.trimString(m.getDescription(), 100);
276        %>
277        <div class="item">
278          <a href="javascript:viewMessage(<%=m.getId()%>)"
279            title="<%=HTML.encodeTags(fullName)%>">
280          <span class="date"><%=dateTimeFormatter.format(m.getTimeSent())%></span>
281          <span class="headline"><%=HTML.encodeTags(shortName)%></span></a><br>
282          <span class="text"><%=HTML.encodeTags(text)%></span>
283        </div>
284        <%
285      }
286    }
287    %>
288    </div>
289  <%
290  String help = Values.getStringOrNull(sc.getClientDefaultSetting("server.links.help"));
291  String faq = Values.getStringOrNull(sc.getClientDefaultSetting("server.links.faq"));
292  String reportBug = Values.getStringOrNull(sc.getClientDefaultSetting("server.links.reportbug"));
293  if (help != null || faq != null || reportBug != null)
294  {
295    %>
296    <h3 class="light docked"><base:icon image="help.gif" />&nbsp;Help</h3>
297      <div id="help" class="welcomesection" style="height: 80px; overflow: auto;">
298      <%
299      if (help != null)
300      {
301        %>
302        &nbsp;<base:icon image="bullet.gif" />&nbsp;<a href="<%=help%>" target="Help">Help&hellip;</a><br>
303        <%
304      }
305      %>
306      <%
307      if (faq != null)
308      {
309        %>
310        &nbsp;<base:icon image="bullet.gif" />&nbsp;<a href="<%=faq%>" target="FAQ">Frequently asked questions&hellip;</a><br>
311        <%
312      }
313      %>
314      <%
315      if (reportBug != null)
316      {
317        %>
318        &nbsp;<base:icon image="bug.gif" />&nbsp;<a href="<%=reportBug%>" target="ReportBug">Report a bug&hellip;</a><br>
319        <%
320      }
321      %>
322      </div>
323    <%
324  }
325  %>
326
327  </td>
328  <td>&nbsp;&nbsp;</td>
329  <td width="50%">
330 
331  <h3 class="light docked"><base:icon image="news.gif" />&nbsp;News and announcements (<%=news.size()%>) <a href="../info/news.rss" 
332        title="Subscribe to news from this BASE server"
333        ><base:icon image="rss.png" /></a></h3>
334    <div id="news" class="news welcomesection" style="height: 400px; overflow: auto;">
335    <%
336    if (news.size() == 0)
337    {
338      %>
339      Nothing new.
340      <%
341    }
342    else
343    {
344      for (News n : news)
345      {
346        %>
347        <div class="item">
348          <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
349          <span class="headline"><%=HTML.encodeTags(n.getName())%></span><br>
350          <span class="text"><%=HTML.niceFormat(n.getDescription())%></span>
351        </div>
352        <%
353      }
354    }
355    %>
356    </div>
357
358  <h3 class="light docked"><base:icon image="diskusage.gif" />&nbsp;Disk usage</h3>
359    <div id="quota" class="welcomesection">
360    <%
361    if (quotaGroup != null)
362    {
363      %>
364      Using quota from group: <%=Base.getLinkedName(ID, quotaGroup, false, true)%>
365      <%
366    }
367    %>
368    <table border="0" cellspacing="0" cellpadding="2" width="100%">
369    <tr align="center">
370      <th>&nbsp;</th>
371      <th colspan="2">Primary location</th>
372      <th colspan="2">Secondary location</th>
373      <th>External</th>
374    </tr>
375    <tr align="center">
376      <th>&nbsp;</th>
377      <th>Used</th>
378      <th>Assigned</th>
379      <th>Used</th>
380      <th>Assigned</th>
381      <th>Used</th>
382    </tr>
383    <%
384      long myPrimaryUsage = user.getDiskUsage(totalQuotaType, Location.PRIMARY);
385      long myPrimaryQuota = quota.getQuotaValue(totalQuotaType, Location.PRIMARY);
386      long groupPrimaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(totalQuotaType, Location.PRIMARY);
387      long mySecondaryUsage = user.getDiskUsage(totalQuotaType, Location.SECONDARY);
388      long mySecondaryQuota = quota.getQuotaValue(totalQuotaType, Location.SECONDARY);
389      long groupSecondaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(totalQuotaType, Location.SECONDARY);
390      long myExternalUsage = user.getDiskUsage(totalQuotaType, Location.EXTERNAL);
391    %>
392    <tr align="center">
393      <th>Total</th>
394      <td><%=getPrintableQuota(myPrimaryUsage, Quota.UNDEFINED)%></td>
395      <td><%=getPrintableQuota(myPrimaryQuota, groupPrimaryQuota)%></td>
396      <td><%=getPrintableQuota(mySecondaryUsage, Quota.UNDEFINED)%></td>
397      <td><%=getPrintableQuota(mySecondaryQuota, groupSecondaryQuota)%></td>
398      <td><%=getPrintableQuota(myExternalUsage, Quota.UNDEFINED)%></td>
399    </tr>
400    <tr>
401      <td colspan="6" style="border-top: 1px dotted #999999"></td>
402    </tr>
403    <%
404    for (QuotaType qt : quotaTypes)
405    {
406      myPrimaryUsage = user.getDiskUsage(qt, Location.PRIMARY);
407      myPrimaryQuota = quota.getQuotaValue(qt, Location.PRIMARY);
408      groupPrimaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(qt, Location.PRIMARY);
409      mySecondaryUsage = user.getDiskUsage(qt, Location.SECONDARY);
410      mySecondaryQuota = quota.getQuotaValue(qt, Location.SECONDARY);
411      groupSecondaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(qt, Location.SECONDARY);
412      myExternalUsage = user.getDiskUsage(qt, Location.EXTERNAL);
413      %>
414      <tr style="text-align: center;">
415        <th><%=HTML.encodeTags(qt.getName())%></th>
416        <td><%=getPrintableQuota(myPrimaryUsage, Quota.UNDEFINED)%></td>
417        <td><%=getPrintableQuota(myPrimaryQuota, groupPrimaryQuota)%></td>
418        <td><%=getPrintableQuota(mySecondaryUsage, Quota.UNDEFINED)%></td>
419        <td><%=getPrintableQuota(mySecondaryQuota, groupSecondaryQuota)%></td>
420        <td><%=getPrintableQuota(myExternalUsage, Quota.UNDEFINED)%></td>
421      </tr>
422      <%
423    }
424    %>
425    <tr>
426      <td colspan="6" style="border-top: 1px dotted #999999"></td>
427    </tr>
428    </table>
429    &nbsp;<base:icon image="bullet.gif" />&nbsp;<a href="../admin/diskusage/details/index.jsp?ID=<%=ID%>&cmd=ViewItem&item_type=USER&item_id=<%=sc.getLoggedInUserId() %>">View details</a><br>
430    </div>
431
432  </td>
433</tr>
434
435</table>
436
437</base:body>
438</base:page>
439  <%
440}
441finally
442{
443  if (dc != null) dc.close();
444}
445%>
Note: See TracBrowser for help on using the repository browser.