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

Last change on this file since 4897 was 4897, checked in by Nicklas Nordborg, 13 years ago

References #1294: Limit the vertical size of "Projects", "New messages" and "News and announcements" sections on the Home view

Specified the height of each section and made them use a scrollbar if the content gets larger.

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