source: trunk/www/common/overview/tree.jsp @ 5957

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

References #1655: GUI improvements

  • List of annotations and failures/warnings in the 'Item overview' details.
  • Bottom border in 'Inherit annotations' dialog.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.6 KB
Line 
1<%-- $Id: tree.jsp 5957 2012-02-14 10:13:27Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2009 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21--%>
22<%@ page pageEncoding="UTF-8" session="false"
23  import="net.sf.basedb.core.SessionControl"
24  import="net.sf.basedb.core.DbControl"
25  import="net.sf.basedb.core.Project"
26  import="net.sf.basedb.core.Item"
27  import="net.sf.basedb.core.BasicItem"
28  import="net.sf.basedb.core.Annotation"
29  import="net.sf.basedb.core.AnnotationType"
30  import="net.sf.basedb.core.ItemSubtype"
31  import="net.sf.basedb.core.Nameable"
32  import="net.sf.basedb.core.Subtypable"
33  import="net.sf.basedb.core.ItemContext"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.clients.web.Base"
36  import="net.sf.basedb.clients.web.util.HTML"
37  import="net.sf.basedb.util.Values"
38  import="net.sf.basedb.util.overview.GenericOverview"
39  import="net.sf.basedb.util.overview.OverviewUtil"
40  import="net.sf.basedb.util.overview.Node"
41  import="net.sf.basedb.util.overview.ValidationOptions"
42  import="java.util.List"
43%>
44<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
45<%!
46String generateSubTree(DbControl dc, Node startNode, String ID, boolean showFailures)
47{
48  StringBuilder sb = new StringBuilder();
49  List<Node> children = startNode.getChildren();
50  if (children == null) return "";
51  for (Node child : children)
52  {
53    int errors = child.getNumErrors();
54    int warnings = child.getNumWarnings();
55    int childErrors = child.getChildErrors();
56    int childWarnings = child.getChildWarnings();
57
58    String folderIcon = child.getNodeType() == Node.Type.FOLDER ? "Folder" : "Item";
59    String tooltip = "";
60    if (child.getItemType() == Item.ANNOTATIONTYPE)
61    {
62      if (startNode.getItemType() == Item.PROTOCOL)
63      {
64        folderIcon = "ProtocolParameter";
65      }
66      else
67      {
68        try
69        {
70          AnnotationType at = (AnnotationType)child.getItem(dc);
71          if (at.isProtocolParameter()) folderIcon = "ProtocolParameter";
72        }
73        catch (Throwable t)
74        {}
75      }
76    }
77    else if (child.getItemType() == Item.ANNOTATION)
78    {
79      folderIcon = "Annotation";
80      try
81      {
82        AnnotationType at = ((Annotation)child.getItem(dc)).getAnnotationType();
83        if (at.isProtocolParameter()) folderIcon = "ProtocolParameter";
84      }
85      catch (Throwable t)
86      {}
87    }
88   
89    if (showFailures)
90    {
91      if (errors > 0)
92      {
93        folderIcon += "Error";
94      }
95      else if (warnings > 0)
96      {
97        folderIcon += "Warning";
98      }
99      else if (childErrors > 0)
100      {
101        folderIcon += "ChildError";
102      }
103      else if (childWarnings > 0)
104      {
105        folderIcon += "ChildWarning";
106      }     
107      if (warnings > 0 && errors > 0)
108      {
109        tooltip += errors + " error(s); " + warnings + " warning(s) on this item";
110      }
111      else if (errors > 0)
112      {
113        tooltip += errors + " error(s) on this item";
114      }
115      else if (warnings > 0)
116      {
117        tooltip += warnings + " warning(s) on this item";
118      }
119      if (childErrors > 0 && childWarnings > 0)
120      {
121        if (tooltip.length() > 0) tooltip += "; ";
122        tooltip += childErrors + " error(s); " + childWarnings + " warning(s) on child items";
123      }
124      else if (childErrors > 0)
125      {
126        if (tooltip.length() > 0) tooltip += "; ";
127        tooltip += childErrors + " error(s) on child items";
128      }
129      else if (childWarnings > 0)
130      {
131        if (tooltip.length() > 0) tooltip += "; ";
132        tooltip += childWarnings + " warning(s) on child items";
133      }
134    }
135    int numChildren = child.getChildren() == null ? 0 : child.getChildren().size();
136    String subtitle = null;
137    if (child.getNodeType() == Node.Type.FOLDER)
138    {
139      subtitle = child.getChildren() == null ? "0" : Integer.toString(child.getChildren().size());
140    }
141    else if (child.getItem() instanceof Subtypable)
142    {
143      try
144      {
145        ItemSubtype subtype = ((Subtypable)child.getItem(dc)).getItemSubtype();
146        if (subtype != null) subtitle = subtype.getName();
147      }
148      catch (Throwable t)
149      {}
150    }
151   
152    if (!child.isChildrenLoaded())
153    {
154      sb.append("var node").append(child.hashCode()).append(" = JoustMenu.addLazyChildItem(").append("node"+startNode.hashCode());
155      sb.append(",'").append(folderIcon).append("'");
156      sb.append(",'").append(HTML.javaScriptEncode(child.getTitle()));
157      sb.append(subtitle != null ? " <span class=\"subtitle\">(" + subtitle + ")</span>" : "").append("',");
158      sb.append("'showInfo(\"").append(child.getId()).append("\")','").append(HTML.javaScriptEncode(tooltip)).append("', '").append(child.getId()).append("',");
159      sb.append("'lazyInitSubNode(\"").append(child.getId()).append("\")')\n");
160    }
161    else
162    {
163       sb.append("var node").append(child.hashCode()).append(" = JoustMenu.addChildItem(").append("node"+startNode.hashCode());
164          sb.append(",'").append(folderIcon).append("'");
165          sb.append(",'").append(HTML.javaScriptEncode(child.getTitle()));
166          sb.append(subtitle != null ? " <span class=\"subtitle\">(" + subtitle + ")</span>" : "").append("',");
167          sb.append("'showInfo(\"").append(child.getId()).append("\")','").append(HTML.javaScriptEncode(tooltip)).append("', '").append(child.getId()).append("')\n");
168    }
169    sb.append(generateSubTree(dc, child, ID, showFailures));
170  }
171  return sb.toString();
172}
173%>
174<%
175final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
176final String ID = sc.getId();
177final float scale = Base.getScale(sc);
178final DbControl dc = sc.newDbControl();
179try
180{
181  GenericOverview overview = OverviewUtil.getCurrentOverview(sc);
182  Boolean showFailures = Values.getBoolean(request.getParameter("show_failures"), false);
183  Node rootNode = overview.getRootNode();
184  Nameable rootItem = (Nameable)rootNode.getItem(dc);
185  String subtitle = null;
186  if (rootItem instanceof Subtypable)
187  {
188    try
189    {
190      ItemSubtype subtype = ((Subtypable)rootItem).getItemSubtype();
191      if (subtype != null) subtitle = subtype.getName();
192    }
193    catch (Throwable t)
194    {}
195  }
196  String rootIcon = "Home";
197  if (showFailures)
198  {
199    if (rootNode.getNumErrors() > 0 || rootNode.getChildErrors() > 0)
200    {
201      rootIcon = "Error";
202    }
203    else if (rootNode.getNumWarnings() > 0 || rootNode.getChildWarnings() > 0)
204    {
205      rootIcon = "Warning";
206    }
207  }
208  %>
209  <base:page title="" type="iframe">
210  <base:head scripts="newjoust.js,ajax.js,json2.js" styles="newjoust.css">
211  <script language="JavaScript">
212  var isInitialised = false;
213  function initialise()
214  {
215    IconStore.init();
216    var path = getRoot()+'images/joust/';
217   
218    IconStore.addIcon('Warning', getRoot() + 'images/warning.png', 16, 16);
219    IconStore.addIcon('Error', getRoot() + 'images/error.png', 16, 16);
220    IconStore.addIcon('FolderWarning', path + 'folderwarning.gif', 18, 16);
221    IconStore.addIcon('FolderWarningSelected', path + 'folderwarningselected.gif', 18, 16);
222    IconStore.addIcon('FolderChildWarning', path + 'folderchildwarning.gif', 18, 16);
223    IconStore.addIcon('FolderChildWarningSelected', path + 'folderchildwarningselected.gif', 18, 16);
224    IconStore.addIcon('FolderError', path + 'foldererror.gif', 18, 16);
225    IconStore.addIcon('FolderErrorSelected', path + 'foldererrorselected.gif', 18, 16);
226    IconStore.addIcon('FolderChildError', path + 'folderchilderror.gif', 18, 16);
227    IconStore.addIcon('FolderChildErrorSelected', path + 'folderchilderrorselected.gif', 18, 16);
228    IconStore.addIcon('Item', path + 'item.gif', 18, 16);
229    IconStore.addIcon('ItemSelected', path + 'itemselected.gif', 18, 16);
230    IconStore.addIcon('ItemWarning', path + 'itemwarning.gif', 18, 16);
231    IconStore.addIcon('ItemWarningSelected', path + 'itemwarningselected.gif', 18, 16);
232    IconStore.addIcon('ItemChildWarning', path + 'itemchildwarning.gif', 18, 16);
233    IconStore.addIcon('ItemChildWarningSelected', path + 'itemchildwarningselected.gif', 18, 16);
234    IconStore.addIcon('ItemError', path + 'itemerror.gif', 18, 16);
235    IconStore.addIcon('ItemErrorSelected', path + 'itemerrorselected.gif', 18, 16);
236    IconStore.addIcon('ItemChildError', path + 'itemchilderror.gif', 18, 16);
237    IconStore.addIcon('ItemChildErrorSelected', path + 'itemchilderrorselected.gif', 18, 16);
238    IconStore.addIcon('ProtocolParameter', path + 'parameter.gif', 18, 16);
239    IconStore.addIcon('ProtocolParameterSelected', path + 'parameterselected.gif', 18, 16);
240    IconStore.addIcon('ProtocolParameterWarning', path + 'parameterwarning.png', 18, 16);
241    IconStore.addIcon('ProtocolParameterWarningSelected', path + 'parametererrorselected.gif', 18, 16);
242    IconStore.addIcon('ProtocolParameterError', path + 'parameterwarning.png', 18, 16);
243    IconStore.addIcon('ProtocolParameterErrorSelected', path + 'parametererrorselected.gif', 18, 16);
244    IconStore.addIcon('ProtocolParameterChildWarning', path + 'parameterchildwarning.png', 18, 16);
245    IconStore.addIcon('ProtocolParameterChildWarningSelected', path + 'parameterchilderrorselected.gif', 18, 16);
246    IconStore.addIcon('ProtocolParameterChildError', path + 'parameterchildwarning.png', 18, 16);
247    IconStore.addIcon('ProtocolParameterChildErrorSelected', path + 'parameterchilderrorselected.gif', 18, 16);
248    IconStore.addIcon('Annotation', path + 'annotation.gif', 18, 16);
249    IconStore.addIcon('AnnotationSelected', path + 'annotationselected.gif', 18, 16);
250    IconStore.addIcon('AnnotationWarning', path + 'annotationwarning.png', 18, 16);
251    IconStore.addIcon('AnnotationWarningSelected', path + 'annotationwarningselected.gif', 18, 16);
252    IconStore.addIcon('AnnotationError', path + 'annotationerror.gif', 18, 16);
253    IconStore.addIcon('AnnotationErrorSelected', path + 'annotationerrorselected.gif', 18, 16);
254    IconStore.addIcon('AnnotationChildWarning', path + 'annotationchildwarning.png', 18, 16);
255    IconStore.addIcon('AnnotationChildWarningSelected', path + 'annotationchildwarningselected.gif', 18, 16);
256    IconStore.addIcon('AnnotationChildError', path + 'annotationchilderror.gif', 18, 16);
257    IconStore.addIcon('AnnotatioChildnErrorSelected', path + 'annotationchilderrorselected.gif', 18, 16);
258    var node<%=rootNode.hashCode()%> = JoustMenu.addMenuItem(-1, '<%=rootIcon%>', '<%=HTML.javaScriptEncode(rootItem.getName())%><%=subtitle != null ? " <span class=\"subtitle\">(" + subtitle + ")</span>" : ""%>', 'showInfo("<%=rootNode.getId()%>")', '', '<%=rootNode.getId()%>');
259    <%=generateSubTree(dc, rootNode, ID, showFailures)%>
260    JoustMenu.menuItems[node<%=rootNode.hashCode()%>].isOpen = true;
261    JoustMenu.draw('joust');
262    isInitialised = true;
263  }
264
265  function openAll()
266  {
267    JoustMenu.openAll();
268  }
269
270  function closeAll()
271  {
272    JoustMenu.closeAll();
273  }
274 
275  function showInfo(nodeId)
276  {
277    parent.frames['info'].location.href = 'info.jsp?ID=<%=ID%>&nodeId='+nodeId+'&show_failures=<%=showFailures%>';
278  }
279 
280  function selectNode(nodeId)
281  {
282    var node = JoustMenu.menuItems[nodeId];
283    JoustMenu.select(node.index);
284  }
285 
286  var loadedTime = new Date().getTime();
287  function refreshIfOutdated()
288  {
289    var currentTime = new Date().getTime();
290    if (currentTime - loadedTime > 2000)
291    {
292      location.reload();
293    }
294  }
295
296  function lazyInitSubNode(nodeId)
297  {
298    var parentMenu = JoustMenu.menuItems[nodeId];
299    JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'progress');   
300    var request = Ajax.getXmlHttpRequest();
301    var url = 'ajax.jsp?ID=<%=ID%>&cmd=GetSubNodes&node_id=' + nodeId;
302    request.open("GET", url, false);
303    request.send(null);
304   
305    var response = Ajax.parseJsonResponse(request.responseText);
306    if (response.status != 'ok')
307    {
308      alert(response.message);
309      return false;
310    }
311
312    var childNodes = response.childNodes;
313    for (var i=0; i<childNodes.length; i++)
314    {
315      var node = childNodes[i];
316      var id = node.id;
317      JoustMenu.addLazyChildItem(
318          parentMenu.index, node.folderIcon, Main.trimString(node.title), 'showInfo(\''+id+'\')', 
319          '' , id, node.numChildren == '0' ? '' : 'lazyInitSubNode(\''+id+'\')');
320    }
321    JoustMenu.updateIconsAndText(parentMenu.index, true);
322    JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'pointer');
323    return childNodes.length > 0;         
324  }
325  </script>
326  <style>
327  .subtitle
328  {
329    font-size: 0.85em;
330    color: #666666;
331  }
332  .selected .subtitle
333  {
334    color: #E8E8E8;
335  }
336  </style>
337 
338  </base:head>
339    <base:body onload="initialise()">
340    <div id="main" class="joust absolutefull" onmousemove="parent.DragDrop.drag(event)" onmouseup="parent.DragDrop.endDrag(event)">
341      <div id="joust" style="overflow: auto; height: 100%;">
342      </div>
343    </div>
344    </base:body>
345  </base:page>
346  <%
347}
348finally
349{
350  if (dc != null) dc.close();
351}
352%>
Note: See TracBrowser for help on using the repository browser.