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

Last change on this file since 5946 was 5946, checked in by Nicklas Nordborg, 10 years ago

References #1655: GUI improvements

Replaces a lot of GIF images with PNG.

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