source: trunk/www/common/overview/ajax.jsp @ 7316

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

Fixes #2070: Child folder in the item overview with only one child should be hidden

The folder node is now skipped for some child item types (samples, extracts, physical, derived and raw bioassays).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1<%-- $Id: ajax.jsp 7316 2017-03-30 07:05:33Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2009 Martin Svensson
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--%>
23<%@ page pageEncoding="UTF-8" session="false" contentType="application/json"
24  import="net.sf.basedb.core.SessionControl"
25  import="net.sf.basedb.core.DbControl"
26  import="net.sf.basedb.core.Annotation"
27  import="net.sf.basedb.core.AnnotationType"
28  import="net.sf.basedb.core.ItemSubtype"
29  import="net.sf.basedb.core.Subtypable"
30  import="net.sf.basedb.core.BioPlate"
31  import="net.sf.basedb.core.BioPlateType"
32  import="net.sf.basedb.core.RawDataType"
33  import="net.sf.basedb.core.RawBioAssay"
34  import="net.sf.basedb.core.Item"
35  import="net.sf.basedb.util.overview.GenericOverview"
36  import="net.sf.basedb.util.overview.Node"
37  import="net.sf.basedb.util.overview.OverviewUtil" 
38  import="net.sf.basedb.util.error.ThrowableUtil"
39  import="net.sf.basedb.clients.web.Base"
40  import="net.sf.basedb.clients.web.WebException"
41  import="org.json.simple.JSONObject"
42  import="org.json.simple.JSONArray"
43  import="java.util.Arrays"
44  import="java.util.HashSet"
45  import="java.util.Set"
46%>
47<%!
48  Set<Item> collapsedChildNodes = new HashSet<Item>(
49      Arrays.asList(Item.SAMPLE, Item.EXTRACT, Item.PHYSICALBIOASSAY, Item.DERIVEDBIOASSAY, Item.RAWBIOASSAY)
50    );
51%>
52<%
53response.setHeader("Cache-Control", "no-cache, max-age=0");
54final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
55final String ID = sc.getId();
56final String cmd = request.getParameter("cmd");
57final String root = request.getContextPath()+"/";
58final String nodeId = request.getParameter("node_id");
59DbControl dc = null;
60out.clear();
61JSONObject json = new JSONObject();
62json.put("status", "ok");
63try
64{
65  if ("GetSubNodes".equals(cmd))
66  {
67    dc = sc.newDbControl();
68    GenericOverview overview = OverviewUtil.getCurrentOverview(sc);
69    Node parent = overview.getNode(nodeId);
70    overview.expand(dc, parent, false);
71    overview.updateFailureCountOnNodes();
72    JSONArray jsonChildNodes = new JSONArray();
73    if (parent != null && parent.numChildren() > 0)
74    {
75      for (Node n : parent.getChildren())
76      {
77        if (n.getNodeType() == Node.Type.FOLDER && n.numChildren() == 1)
78        {
79          Node child = n.getChildren().get(0);
80          if (collapsedChildNodes.contains(child.getItemType())) n = child;
81        }
82        String folderIcon = n.getNodeType() == Node.Type.FOLDER ? "Folder" : "Item";
83        if (n.getItemType() == Item.ANNOTATIONTYPE)
84        {
85          if (parent.getItemType() == Item.PROTOCOL)
86          {
87            folderIcon = "ProtocolParameter";
88          }
89          else
90          {
91            try
92            {
93              AnnotationType at = (AnnotationType)n.getItem(dc);
94              if (at.isProtocolParameter()) folderIcon = "ProtocolParameter";
95            }
96            catch (Throwable t)
97            {}
98          }
99        }
100        else if (n.getItemType() == Item.ANNOTATION)
101        {
102          folderIcon = "Annotation";
103          try
104          {
105            AnnotationType at = ((Annotation)n.getItem(dc)).getAnnotationType();
106            if (at.isProtocolParameter()) folderIcon = "ProtocolParameter";
107          }
108          catch (Throwable t)
109          {}
110        }
111        String subtitle = null;
112        if (n.getNodeType() == Node.Type.FOLDER)
113        {
114          subtitle = n.getChildren() == null ? "0" : Integer.toString(n.getChildren().size());
115        }
116        else if (n.getItem() instanceof Subtypable)
117        {
118          try
119          {
120            ItemSubtype subtype = ((Subtypable)n.getItem(dc)).getItemSubtype();
121            if (subtype != null) subtitle = subtype.getName();
122          }
123          catch (Throwable t)
124          {}
125        }
126        else if (n.getItem() instanceof BioPlate)
127        {
128          try
129          {
130            BioPlateType plateType = ((BioPlate)n.getItem(dc)).getBioPlateType();
131            if (plateType != null) subtitle = plateType.getName();
132          }
133          catch (Throwable t)
134          {}
135        }
136        else if (n.getItem() instanceof RawBioAssay)
137        {
138          RawDataType rawDataType = ((RawBioAssay)n.getItem(dc)).getRawDataType();
139          subtitle = rawDataType.getName();
140        }
141       
142        int numChildren = n.numChildren();
143        JSONObject jsonNode = new JSONObject();
144        jsonNode.put("id", n.getId());
145        jsonNode.put("text", n.getTitle() + (subtitle != null ? " <span class=\"subtitle\">(" + subtitle + ")</span>" : ""));
146        jsonNode.put("icon", folderIcon);
147        jsonNode.put("isLazy", numChildren == 0 ? 0 : 1);
148        jsonChildNodes.add(jsonNode);
149      }
150      dc.commit();
151    }
152    json.put("childNodes", jsonChildNodes);
153  }
154  else
155  {
156    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
157  }
158}
159catch (Throwable t)
160{
161  t.printStackTrace();
162  json.clear();
163  json.put("status", "error");
164  json.put("message", t.getMessage());
165  json.put("stacktrace", ThrowableUtil.stackTraceToString(t));
166}
167finally
168{
169  json.writeJSONString(out);
170  out.flush();
171  if (dc != null) dc.close();
172}
173%>
Note: See TracBrowser for help on using the repository browser.