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

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

Fixes #1546: Publish news as a rss feed

Added possibility to disable the RSS feed by commenting out the servlet definition in web.xml.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.5 KB
Line 
1<%-- $Id: index.jsp 5479 2010-11-08 07:33:46Z 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("newsDate")));
163  newsQuery.order(Orders.desc(Hql.property("id")));
164  newsQuery.setParameter("today", new Date(), Type.DATE);
165  ItemResultList<News> news = newsQuery.list(dc);
166%>
167<base:page title="Welcome to BASE">
168<base:head styles="login.css">
169
170<script language="JavaScript">
171
172  function viewMessage(messageId)
173  {
174    Main.viewOrEditItem('<%=ID%>', 'MESSAGE', messageId, false);
175  }
176  function setActiveProject(projectId)
177  {
178    Main.openPopup('projects/set_active.jsp?ID=<%=ID%>&project_id='+projectId, 'ActivateProject', 300, 140)
179  }
180</script>
181
182</base:head>
183<base:body onload="top.frames['footnote'].location.reload()">
184
185
186<table border="0" cellspacing="0" cellpadding="0" width="100%">
187<tr valign="top">
188  <td width="50%">
189 
190  <h3 class="light docked">
191    <base:icon image="project.gif" />
192    &nbsp;Projects (<%=projects.size()%>)
193  </h3>
194    <div id="projects" class="welcomesection" style="height: 210px; overflow: auto;">
195    <%
196    if (projects.size() == 0)
197    {
198      %>
199      You are not member of any projects.
200      <%
201    }
202    else
203    {
204      int activeProjectId = sc.getActiveProjectId();
205      %>
206      <table border="0" cellspacing="0" cellpadding="2">
207      <%
208      if (activeProjectId == 0)
209      {
210        %>
211        <td><base:icon image="warning.gif" /></td>
212        <td><i>No active project</i></td>
213        <td>&nbsp;</td>     
214        <%
215      }
216      for (Project p : projects)
217      {
218        int projectId = p.getId();
219        if (projectId == activeProjectId)
220        {
221          %>
222          <tr>
223            <td><base:icon image="bullet.gif" /></td>
224            <td><b><%=Base.getLinkedName(ID, p, false, true)%></b></td>
225            <td>[active]</td>
226          </tr>
227          <%
228        }
229        else
230        {
231          %>
232          <tr>
233            <td>&nbsp;</td>
234            <td><%=Base.getLinkedName(ID, p, false, true)%></td>
235            <td>[<a href="javascript:setActiveProject(<%=projectId%>)">set active</a>]</td>
236          </tr>
237          <%
238        }
239      }
240      %>
241      </table>
242      <%
243    }
244    %>
245    </div>
246
247  <h3 class="light docked">
248    <base:icon image="message.gif" />
249    &nbsp;New messages (<%=messages.size()%>)</h3>
250    <div id="messages" class="news welcomesection" style="height: 210px; overflow: auto;">
251    <%
252    String broadcastTitle = (String)application.getAttribute("broadcast.title");
253    if (broadcastTitle != null)
254    {
255      String broadcastMessage = (String)application.getAttribute("broadcast.message");
256      %>
257      <div class="item"><base:icon image="warning.gif" />
258        <span class="date"><%=dateFormatter.format(new Date())%></span>
259        <span class="headline"><%=HTML.encodeTags(broadcastTitle)%></span><br>
260        <span class="text"><%=HTML.niceFormat(broadcastMessage)%></span>
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 shortName = Values.trimString(fullName, 50);
276        String text = Values.trimString(m.getDescription(), 100);
277        %>
278        <div class="item">
279          <a href="javascript:viewMessage(<%=m.getId()%>)"
280            title="<%=HTML.encodeTags(fullName)%>">
281          <span class="date"><%=dateTimeFormatter.format(m.getTimeSent())%></span>
282          <span class="headline"><%=HTML.encodeTags(shortName)%></span></a><br>
283          <span class="text"><%=HTML.encodeTags(text)%></span>
284        </div>
285        <%
286      }
287    }
288    %>
289    </div>
290  <%
291  String help = Values.getStringOrNull(sc.getClientDefaultSetting("server.links.help"));
292  String faq = Values.getStringOrNull(sc.getClientDefaultSetting("server.links.faq"));
293  String reportBug = Values.getStringOrNull(sc.getClientDefaultSetting("server.links.reportbug"));
294  if (help != null || faq != null || reportBug != null)
295  {
296    %>
297    <h3 class="light docked"><base:icon image="help.gif" />&nbsp;Help</h3>
298      <div id="help" class="welcomesection" style="height: 80px; overflow: auto;">
299      <%
300      if (help != null)
301      {
302        %>
303        &nbsp;<base:icon image="bullet.gif" />&nbsp;<a href="<%=help%>" target="Help">Help&hellip;</a><br>
304        <%
305      }
306      %>
307      <%
308      if (faq != null)
309      {
310        %>
311        &nbsp;<base:icon image="bullet.gif" />&nbsp;<a href="<%=faq%>" target="FAQ">Frequently asked questions&hellip;</a><br>
312        <%
313      }
314      %>
315      <%
316      if (reportBug != null)
317      {
318        %>
319        &nbsp;<base:icon image="bug.gif" />&nbsp;<a href="<%=reportBug%>" target="ReportBug">Report a bug&hellip;</a><br>
320        <%
321      }
322      %>
323      </div>
324    <%
325  }
326  %>
327
328  </td>
329  <td>&nbsp;&nbsp;</td>
330  <td width="50%">
331 
332  <h3 class="light docked"><base:icon image="news.gif" />&nbsp;News and announcements (<%=news.size()%>)
333    <%
334    if (RssNewsFeed.isEnabled()) 
335    {
336      %>
337      <a href="../info/news.rss" 
338        title="Subscribe to news from this BASE server"
339        ><base:icon image="rss.png" /></a>
340      <%
341    }
342    %>
343  </h3>
344    <div id="news" class="news welcomesection" style="height: 400px; overflow: auto;">
345    <%
346    if (news.size() == 0)
347    {
348      %>
349      Nothing new.
350      <%
351    }
352    else
353    {
354      for (News n : news)
355      {
356        %>
357        <div class="item">
358          <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
359          <span class="headline"><%=HTML.encodeTags(n.getName())%></span><br>
360          <span class="text"><%=HTML.niceFormat(n.getDescription())%></span>
361        </div>
362        <%
363      }
364    }
365    %>
366    </div>
367
368  <h3 class="light docked"><base:icon image="diskusage.gif" />&nbsp;Disk usage</h3>
369    <div id="quota" class="welcomesection">
370    <%
371    if (quotaGroup != null)
372    {
373      %>
374      Using quota from group: <%=Base.getLinkedName(ID, quotaGroup, false, true)%>
375      <%
376    }
377    %>
378    <table border="0" cellspacing="0" cellpadding="2" width="100%">
379    <tr align="center">
380      <th>&nbsp;</th>
381      <th colspan="2">Primary location</th>
382      <th colspan="2">Secondary location</th>
383      <th>External</th>
384    </tr>
385    <tr align="center">
386      <th>&nbsp;</th>
387      <th>Used</th>
388      <th>Assigned</th>
389      <th>Used</th>
390      <th>Assigned</th>
391      <th>Used</th>
392    </tr>
393    <%
394      long myPrimaryUsage = user.getDiskUsage(totalQuotaType, Location.PRIMARY);
395      long myPrimaryQuota = quota.getQuotaValue(totalQuotaType, Location.PRIMARY);
396      long groupPrimaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(totalQuotaType, Location.PRIMARY);
397      long mySecondaryUsage = user.getDiskUsage(totalQuotaType, Location.SECONDARY);
398      long mySecondaryQuota = quota.getQuotaValue(totalQuotaType, Location.SECONDARY);
399      long groupSecondaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(totalQuotaType, Location.SECONDARY);
400      long myExternalUsage = user.getDiskUsage(totalQuotaType, Location.EXTERNAL);
401    %>
402    <tr align="center">
403      <th>Total</th>
404      <td><%=getPrintableQuota(myPrimaryUsage, Quota.UNDEFINED)%></td>
405      <td><%=getPrintableQuota(myPrimaryQuota, groupPrimaryQuota)%></td>
406      <td><%=getPrintableQuota(mySecondaryUsage, Quota.UNDEFINED)%></td>
407      <td><%=getPrintableQuota(mySecondaryQuota, groupSecondaryQuota)%></td>
408      <td><%=getPrintableQuota(myExternalUsage, Quota.UNDEFINED)%></td>
409    </tr>
410    <tr>
411      <td colspan="6" style="border-top: 1px dotted #999999"></td>
412    </tr>
413    <%
414    for (QuotaType qt : quotaTypes)
415    {
416      myPrimaryUsage = user.getDiskUsage(qt, Location.PRIMARY);
417      myPrimaryQuota = quota.getQuotaValue(qt, Location.PRIMARY);
418      groupPrimaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(qt, Location.PRIMARY);
419      mySecondaryUsage = user.getDiskUsage(qt, Location.SECONDARY);
420      mySecondaryQuota = quota.getQuotaValue(qt, Location.SECONDARY);
421      groupSecondaryQuota = groupQuota == null ? Quota.UNDEFINED : groupQuota.getQuotaValue(qt, Location.SECONDARY);
422      myExternalUsage = user.getDiskUsage(qt, Location.EXTERNAL);
423      %>
424      <tr style="text-align: center;">
425        <th><%=HTML.encodeTags(qt.getName())%></th>
426        <td><%=getPrintableQuota(myPrimaryUsage, Quota.UNDEFINED)%></td>
427        <td><%=getPrintableQuota(myPrimaryQuota, groupPrimaryQuota)%></td>
428        <td><%=getPrintableQuota(mySecondaryUsage, Quota.UNDEFINED)%></td>
429        <td><%=getPrintableQuota(mySecondaryQuota, groupSecondaryQuota)%></td>
430        <td><%=getPrintableQuota(myExternalUsage, Quota.UNDEFINED)%></td>
431      </tr>
432      <%
433    }
434    %>
435    <tr>
436      <td colspan="6" style="border-top: 1px dotted #999999"></td>
437    </tr>
438    </table>
439    &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>
440    </div>
441
442  </td>
443</tr>
444
445</table>
446
447</base:body>
448</base:page>
449  <%
450}
451finally
452{
453  if (dc != null) dc.close();
454}
455%>
Note: See TracBrowser for help on using the repository browser.