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

Last change on this file since 7347 was 7347, checked in by Nicklas Nordborg, 6 years ago

Fixes #2081: Improve visibility of child items in the "Item overview"

I have made two changes.

  • A light gray background color is used to indicate all sub-child elements. This is applied both to the selected element and when hovering (using a slight darker gray).
  • First-level child elements to the selected element are displayed in bold text.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.8 KB
Line 
1<%-- $Id: tree.jsp 7347 2017-04-28 07:51:14Z 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.BioPlateType"
34  import="net.sf.basedb.core.BioPlate"
35  import="net.sf.basedb.core.RawDataType"
36  import="net.sf.basedb.core.RawBioAssay"
37  import="net.sf.basedb.core.ItemContext"
38  import="net.sf.basedb.core.Permission"
39  import="net.sf.basedb.clients.web.Base"
40  import="net.sf.basedb.clients.web.util.HTML"
41  import="net.sf.basedb.util.Values"
42  import="net.sf.basedb.util.overview.GenericOverview"
43  import="net.sf.basedb.util.overview.OverviewUtil"
44  import="net.sf.basedb.util.overview.Node"
45  import="net.sf.basedb.util.overview.ValidationOptions"
46  import="org.json.simple.JSONArray"
47  import="org.json.simple.JSONObject"
48  import="java.util.Arrays"
49  import="java.util.HashSet"
50  import="java.util.Set"
51  import="java.util.List"
52%>
53<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
54<%!
55Set<Item> collapsedChildNodes = new HashSet<Item>(
56    Arrays.asList(Item.SAMPLE, Item.EXTRACT, Item.PHYSICALBIOASSAY, Item.DERIVEDBIOASSAY, Item.RAWBIOASSAY)
57  );
58
59void generateSubTree(DbControl dc, Node startNode, JSONObject jsonParent, boolean showFailures)
60{
61 
62  List<Node> children = startNode.getChildren();
63  if (children == null) return;
64 
65  for (Node child : children)
66  {
67    if (child.getNodeType() == Node.Type.FOLDER && child.numChildren() == 1)
68    {
69      Node child2 = child.getChildren().get(0);
70      if (collapsedChildNodes.contains(child2.getItemType())) child = child2;
71    }
72   
73    int errors = child.getNumErrors();
74    int warnings = child.getNumWarnings();
75    int childErrors = child.getChildErrors();
76    int childWarnings = child.getChildWarnings();
77
78    String folderIcon = child.getNodeType() == Node.Type.FOLDER ? "Folder" : "Item";
79    String tooltip = "";
80    if (child.getItemType() == Item.ANNOTATIONTYPE)
81    {
82      if (startNode.getItemType() == Item.PROTOCOL)
83      {
84        folderIcon = "ProtocolParameter";
85      }
86      else
87      {
88        try
89        {
90          AnnotationType at = (AnnotationType)child.getItem(dc);
91          if (at.isProtocolParameter()) folderIcon = "ProtocolParameter";
92        }
93        catch (Throwable t)
94        {}
95      }
96    }
97    else if (child.getItemType() == Item.ANNOTATION)
98    {
99      folderIcon = "Annotation";
100      try
101      {
102        AnnotationType at = ((Annotation)child.getItem(dc)).getAnnotationType();
103        if (at.isProtocolParameter()) folderIcon = "ProtocolParameter";
104      }
105      catch (Throwable t)
106      {}
107    }
108   
109    if (showFailures)
110    {
111      if (errors > 0)
112      {
113        folderIcon += "Error";
114      }
115      else if (warnings > 0)
116      {
117        folderIcon += "Warning";
118      }
119      else if (childErrors > 0)
120      {
121        folderIcon += "ChildError";
122      }
123      else if (childWarnings > 0)
124      {
125        folderIcon += "ChildWarning";
126      }     
127      if (warnings > 0 && errors > 0)
128      {
129        tooltip += errors + " error(s); " + warnings + " warning(s) on this item";
130      }
131      else if (errors > 0)
132      {
133        tooltip += errors + " error(s) on this item";
134      }
135      else if (warnings > 0)
136      {
137        tooltip += warnings + " warning(s) on this item";
138      }
139      if (childErrors > 0 && childWarnings > 0)
140      {
141        if (tooltip.length() > 0) tooltip += "; ";
142        tooltip += childErrors + " error(s); " + childWarnings + " warning(s) on child items";
143      }
144      else if (childErrors > 0)
145      {
146        if (tooltip.length() > 0) tooltip += "; ";
147        tooltip += childErrors + " error(s) on child items";
148      }
149      else if (childWarnings > 0)
150      {
151        if (tooltip.length() > 0) tooltip += "; ";
152        tooltip += childWarnings + " warning(s) on child items";
153      }
154    }
155    int numChildren = child.getChildren() == null ? 0 : child.getChildren().size();
156    String subtitle = null;
157    if (child.getNodeType() == Node.Type.FOLDER)
158    {
159      subtitle = child.getChildren() == null ? "0" : Integer.toString(child.getChildren().size());
160    }
161    else if (child.getItem() instanceof Subtypable)
162    {
163      try
164      {
165        ItemSubtype subtype = ((Subtypable)child.getItem(dc)).getItemSubtype();
166        if (subtype != null) subtitle = subtype.getName();
167      }
168      catch (Throwable t)
169      {}
170    }
171    else if (child.getItem() instanceof BioPlate)
172    {
173      try
174      {
175        BioPlateType plateType = ((BioPlate)child.getItem(dc)).getBioPlateType();
176        if (plateType != null) subtitle = plateType.getName();
177      }
178      catch (Throwable t)
179      {}
180    }
181    else if (child.getItem() instanceof RawBioAssay)
182    {
183      RawDataType rawDataType = ((RawBioAssay)child.getItem(dc)).getRawDataType();
184      subtitle = rawDataType.getName();
185    }
186   
187    String text = HTML.encodeTags(child.getTitle()) + (subtitle != null ? " <span class=\"subtitle\">(" + subtitle + ")</span>" : "");
188    JSONObject jsonChild = newJoustEntry(jsonParent, folderIcon, text, child.getId());
189    jsonChild.put("tooltip", tooltip);
190    jsonChild.put("className", child.getNodeType().name());
191    if (!child.isChildrenLoaded())
192    {
193      jsonChild.put("isLazy", 1);
194    }
195    generateSubTree(dc, child, jsonChild, showFailures);
196  }
197}
198
199
200JSONObject newJoustEntry(JSONObject jsonParent, String icon, String text, String id)
201{
202  JSONObject jsonJoust = new JSONObject();
203  jsonJoust.put("icon", icon);
204  jsonJoust.put("text", text);
205  jsonJoust.put("id", id);
206  if (jsonParent != null)
207  {
208    JSONArray jsonChildren = (JSONArray)jsonParent.get("children");
209    if (jsonChildren == null)
210    {
211      jsonChildren = new JSONArray();
212      jsonParent.put("children", jsonChildren);
213    }
214    jsonChildren.add(jsonJoust);
215  }
216  return jsonJoust;
217}
218
219%>
220<%
221final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
222final String ID = sc.getId();
223final float scale = Base.getScale(sc);
224final DbControl dc = sc.newDbControl();
225try
226{
227  GenericOverview overview = OverviewUtil.getCurrentOverview(sc);
228  boolean showFailures = Values.getBoolean(request.getParameter("show_failures"), false);
229  Node rootNode = overview.getRootNode();
230  Nameable rootItem = (Nameable)rootNode.getItem(dc);
231  String subtitle = null;
232  if (rootItem instanceof Subtypable)
233  {
234    try
235    {
236      ItemSubtype subtype = ((Subtypable)rootItem).getItemSubtype();
237      if (subtype != null) subtitle = subtype.getName();
238    }
239    catch (Throwable t)
240    {}
241  }
242  String rootIcon = "Home";
243  if (showFailures)
244  {
245    if (rootNode.getNumErrors() > 0 || rootNode.getChildErrors() > 0)
246    {
247      rootIcon = "Error";
248    }
249    else if (rootNode.getNumWarnings() > 0 || rootNode.getChildWarnings() > 0)
250    {
251      rootIcon = "Warning";
252    }
253  }
254 
255  // Build the Joust menu tree
256  JSONArray jsonJoust = new JSONArray();
257  JSONObject jsonRoot = newJoustEntry(null, rootIcon, HTML.encodeTags(rootItem.getName())+ (subtitle != null ? " <span class=\"subtitle\">(" + subtitle + ")</span>" : ""), rootNode.getId());
258  jsonRoot.put("isOpen", 1);
259  jsonRoot.put("noOutlineIcon", 1);
260 
261  generateSubTree(dc, rootNode, jsonRoot, showFailures);
262  jsonJoust.add(jsonRoot);
263  %>
264  <base:page title="" type="iframe">
265  <base:head scripts="joust-2.js,dragdrop.js,~tree.js" styles="joust-2.css">
266  <style>
267  .subtitle
268  {
269    font-size: 0.85em;
270    color: #666666;
271  }
272  .selected .subtitle
273  {
274    color: #E8E8E8;
275  }
276
277  /* The selected item and all children get a gray background */
278  .selected, .selected + .children
279  {
280    background-color: #F8F8F8;
281  }
282 
283  /* A slighly darker background when hovering */
284  .joustitem:hover, .joustitem:hover + .children .joustitem
285  {
286    background-color: #F0F0F0;
287  }
288 
289  /* First-level child items to the selected item get bold text */
290  .selected + .children > .joustitem, .selected + .children > .children.FOLDER > .joustitem
291  {
292    font-weight: bold;
293  }
294  </style>
295 
296  </base:head>
297    <base:body>
298    <div id="page-data" class="datacontainer"
299      data-show-failures="<%=showFailures ? 1 : 0 %>"
300    ></div>
301    <div id="main" class="joust absolutefull auto-init" data-auto-init="drag-support">
302      <div id="joust" class="joust absolutefull" 
303        data-joust-tree="<%=HTML.encodeTags(jsonJoust.toJSONString()) %>"
304        style="overflow: auto;">
305      </div>
306    </div>
307    </base:body>
308  </base:page>
309  <%
310}
311finally
312{
313  if (dc != null) dc.close();
314}
315%>
Note: See TracBrowser for help on using the repository browser.