source: trunk/www/common/expression_builder.jsp @ 6314

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

References #1729 and #1730. Several edit dialogs in the 'View' menu. Expression builder, which required changes to the 'Validate' function which is now done on the server side instead of in the browser (due to the use of eval() on user input).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 11.8 KB
Line 
1<%-- $Id: expression_builder.jsp 6314 2013-09-02 12:47:53Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006, 2007 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 modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  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  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.DbControl"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.BioAssaySet"
30  import="net.sf.basedb.core.VirtualDb"
31  import="net.sf.basedb.core.ReporterCloneTemplate"
32  import="net.sf.basedb.core.RawDataType"
33  import="net.sf.basedb.core.RawDataTypes"
34  import="net.sf.basedb.core.RawDataProperty"
35  import="net.sf.basedb.core.ExtendedProperty"
36  import="net.sf.basedb.core.ExtendedProperties"
37  import="net.sf.basedb.core.Formula"
38  import="net.sf.basedb.core.IntensityTransform"
39  import="net.sf.basedb.core.ReporterList"
40  import="net.sf.basedb.core.ItemQuery"
41  import="net.sf.basedb.core.Include"
42  import="net.sf.basedb.core.query.Orders"
43  import="net.sf.basedb.core.query.Hql"
44  import="net.sf.basedb.util.Enumeration"
45  import="net.sf.basedb.util.jep.Jep"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.util.Values"
48  import="net.sf.basedb.clients.web.util.HTML"
49  import="net.sf.basedb.clients.web.DynamicUtil"
50  import="net.sf.basedb.clients.web.taglib.table.TableColumn"
51  import="java.util.List"
52  import="java.util.LinkedList"
53%>
54<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
55<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
56<%
57  String title = request.getParameter("title");
58  String textarea = request.getParameter("textarea");
59  Formula.Type formulaType = Formula.Type.valueOf(request.getParameter("formulatype"));
60  RawDataType rawDataType = RawDataTypes.getRawDataType(request.getParameter("rawdatatype"));
61  int bioAssaySetId = Values.getInt(request.getParameter("bioassayset_id"), -1);
62  boolean restrictions = Values.getBoolean(request.getParameter("restrictions"));
63  int channels = Values.getInt(request.getParameter("channels"));
64  final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
65
66  DbControl dc = sc.newDbControl();
67  try
68  {
69    BioAssaySet bas = bioAssaySetId == -1 ? null : BioAssaySet.getById(dc, bioAssaySetId);
70    VirtualDb vdb = bas != null ? bas.getExperiment().getVirtualDb() : null;
71    ReporterCloneTemplate template = vdb != null && vdb.hasClonedReporters() ? vdb.getReporterCloneTemplate() : null;
72       
73    IntensityTransform transform = bas == null ? null : bas.getIntensityTransform();
74    int maxRawMappings = bas == null ? 1 : bas.getMaxRawMappingsForSpot();
75
76    List<TableColumn> spotProperties = new LinkedList<TableColumn>();
77    DynamicUtil.addSpotColumns(spotProperties, dc, channels, transform);
78    List<TableColumn> rawProperties = new LinkedList<TableColumn>();
79    if (rawDataType != null)
80    {
81      DynamicUtil.addFormulaColumns(spotProperties, dc, rawDataType, 
82        Formula.Type.COLUMN_EXPRESSION, transform, "", "", maxRawMappings == 1);
83      if (bas != null) DynamicUtil.addExtraColumns(spotProperties, dc, bas, "", "", "[Xtra] ");
84      if (maxRawMappings == 1) DynamicUtil.addRawDataColumns(rawProperties, dc, rawDataType, "", "", "");
85    }
86    List<TableColumn> reporterProperties = new LinkedList<TableColumn>();
87    DynamicUtil.addReporterColumns(reporterProperties, dc, template, "", "", "");
88   
89    ItemQuery<ReporterList> reporterListQuery = ReporterList.getQuery();
90    reporterListQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
91    reporterListQuery.order(Orders.asc(Hql.property("name")));
92    List<ReporterList> reporterLists = reporterListQuery.list(dc);
93   
94  %>
95  <base:page type="popup" title="<%=title%>">
96  <base:head scripts="table.js,~expression_builder.js" styles="toolbar.css" />
97  <base:body>
98    <h1>Expression builder <base:help helpid="expressionbuilder" /></h1>
99    <div id="page-data" class="datacontainer"
100      data-textarea="<%=textarea%>"
101      data-formula-type="<%=formulaType.name() %>"
102      data-raw-data-type="<%=rawDataType == null ? "" : rawDataType.getId()%>"
103      data-channels="<%=channels%>"
104    ></div>
105 
106    <form name="expression">
107    <div class="content">
108      <table class="fullform input100 bottomborder">
109      <tr>
110        <td class="filled">
111        <tbl:toolbar subclass="bottomborder">
112          <tbl:label
113            style="width: 100px;"
114            title="Operators:"
115          />
116          <tbl:button 
117            title="AND"
118            subclass="auto-init"
119            data-auto-init="enclose-selection"
120            data-prefix=" &amp;&amp; "
121            data-suffix=""
122            tooltip="BOOLEAN AND: expr1 &amp;&amp; expr2"
123          />
124          <tbl:button 
125            title="OR"
126            subclass="auto-init"
127            data-auto-init="enclose-selection"
128            data-prefix=" || "
129            data-suffix=""
130            tooltip="BOOLEAN OR: expr1 || expr2"
131          />
132          <tbl:button 
133            title="NOT"
134            subclass="auto-init"
135            data-auto-init="enclose-selection"
136            data-prefix="!"
137            data-suffix=""
138            tooltip="BOOLEAN NOT: !expr1"
139          />
140          <tbl:button 
141            title="=="
142            subclass="auto-init"
143            data-auto-init="enclose-selection"
144            data-prefix=" == "
145            data-suffix=""
146            tooltip="EQUAL: expr1 == expr2"
147          />
148          <tbl:button 
149            title="!="
150            subclass="auto-init"
151            data-auto-init="enclose-selection"
152            data-prefix=" != "
153            data-suffix=""
154            tooltip="INEQUAL: expr1 != expr2"
155          />
156          <tbl:button 
157            title="&lt;"
158            subclass="auto-init"
159            data-auto-init="enclose-selection"
160            data-prefix=" &lt; "
161            data-suffix=""
162            tooltip="LESS: expr1 &lt; expr2"
163          />
164          <tbl:button 
165            title="&lt;="
166            subclass="auto-init"
167            data-auto-init="enclose-selection"
168            data-prefix=" &lt;= "
169            data-suffix=""
170            tooltip="LESS OR EQUAL: expr1 &lt;= expr2"
171          />
172          <tbl:button 
173            title="&gt;="
174            subclass="auto-init"
175            data-auto-init="enclose-selection"
176            data-prefix=" &gt;= "
177            data-suffix=""
178            tooltip="MORE OR EQUAL: expr1 &gt;= expr2"
179            visible="<%=restrictions%>"
180          />
181          <tbl:button 
182            title="&gt;"
183            subclass="auto-init"
184            data-auto-init="enclose-selection"
185            data-prefix=" &gt; "
186            data-suffix=""
187            tooltip="MORE: expr1 &gt; expr2"
188          />
189          <tbl:button 
190            title="+"
191            subclass="auto-init"
192            data-auto-init="enclose-selection"
193            data-prefix=" + "
194            data-suffix=""
195            tooltip="ADD: expr1 + expr2"
196          />
197          <tbl:button 
198            title="-"
199            subclass="auto-init"
200            data-auto-init="enclose-selection"
201            data-prefix=" - "
202            data-suffix=""
203            tooltip="SUBTRACT: expr1 - expr2"
204          />
205          <tbl:button 
206            title="*"
207            subclass="auto-init"
208            data-auto-init="enclose-selection"
209            data-prefix=" * "
210            data-suffix=""
211            tooltip="MULTIPLY: expr1 * expr2"
212          />
213          <tbl:button 
214            title="/"
215            subclass="auto-init"
216            data-auto-init="enclose-selection"
217            data-prefix=" / "
218            data-suffix=""
219            tooltip="DIVIDE: expr1 / expr2"
220          />
221          <tbl:button 
222            title="( )"
223            subclass="auto-init"
224            data-auto-init="enclose-selection"
225            data-prefix="("
226            data-suffix=")"
227            tooltip="PARENTHESIS: (expr1)"
228          />
229        </tbl:toolbar>
230        <tbl:toolbar subclass="bottomborder">
231          <tbl:label
232            title="Functions:"
233            style="width: 100px;"
234          />
235          <%
236          Enumeration<String, String> functions = Jep.getFunctions();
237          for (int i = 0; i < functions.size(); ++i)
238          {
239            String function = functions.getKey(i);
240            %>
241            <tbl:button 
242              title="<%=function%>"
243              subclass="auto-init"
244              data-auto-init="enclose-selection"
245              data-prefix="<%=function+"(" %>"
246              data-suffix=")"
247              tooltip="<%=functions.getValue(i)%>"
248            />
249            <%
250          }
251          %>
252          <tbl:label
253            title="Constants:"
254            style="width: 100px;"
255          />
256          <tbl:button 
257            title="null"
258            subclass="auto-init"
259            data-auto-init="enclose-selection"
260            data-prefix=""
261            data-suffix="null"
262            tooltip="The null (unknown) value"
263          />
264          <tbl:button 
265            title="pi"
266            subclass="auto-init"
267            data-auto-init="enclose-selection"
268            data-prefix=""
269            data-suffix="<%=Math.PI%>"
270            tooltip="<%="The pi value: " + Math.PI %>"
271          />
272          <tbl:button 
273            title="e"
274            subclass="auto-init"
275            data-auto-init="enclose-selection"
276            data-prefix=""
277            data-suffix="<%=Math.E %>"
278            tooltip="<%="The base of the natural logarithm: " + Math.E%>"
279          />
280        </tbl:toolbar>
281        <tbl:toolbar subclass="bottomborder">
282          <%
283          if (formulaType != Formula.Type.INTENSITY_EXPRESSION)
284          {
285            %>
286            <td class="label">Spot:
287              <select name="spot" id="spot" style="width: 12em;">
288              <option value="">- select -
289              <%
290              for (TableColumn tc : spotProperties)
291              {
292                if (tc.getJepExpression() != null)
293                {
294                  %>
295                  <option data-prefix="<%=tc.getJepExpression()%>" 
296                    title="<%=HTML.encodeTags(tc.getDescription())%>"><%=HTML.encodeTags(tc.getTitle())%>
297                  <%
298                }
299              }
300              %>
301              </select>   
302            </td>
303            <%
304          }
305          %>
306          <%
307          if (rawDataType != null && rawDataType.isStoredInDb() && rawProperties.size() > 0)
308          {
309            %>
310            <td class="label">Raw data:
311              <select name="rawdata" id="rawdata" style="width: 12em;">
312              <option value="">- select -
313              <%
314              for (TableColumn tc : rawProperties)
315              {
316                %>
317                <option data-prefix="<%=tc.getJepExpression()%>" 
318                  title="<%=HTML.encodeTags(tc.getDescription())%>"><%=HTML.encodeTags(tc.getTitle())%>
319                <%
320              }
321              %>
322              </select>
323            </td>
324            <%
325          }
326          %>
327         
328          <td class="label">Reporter:
329            <select name="reporter" id="reporter" style="width: 12em;">
330            <option value="">- select -
331              <%
332              for (TableColumn tc : reporterProperties)
333              {
334                %>
335                <option data-prefix="<%=tc.getJepExpression()%>" 
336                  title="<%=HTML.encodeTags(tc.getDescription())%>"><%=HTML.encodeTags(tc.getTitle())%>
337                <%
338              }
339              %>
340            </select>
341        </tbl:toolbar>
342        <tbl:toolbar subclass="bottomborder"
343          visible="<%=reporterLists.size() > 0%>">
344          <td class="label">
345            Reporter lists:
346           
347            <select name="listFunction" >
348            <option value="score">score
349            <%
350            if (restrictions)
351            {
352              %>
353              <option value="inList">in
354              <option value="notInList">not in
355              <%
356            }
357            %>
358            </select>
359           
360            <select name="reporterList" id="reporterList">
361            <option value="">- select -
362              <%
363              for (ReporterList list : reporterLists)
364              {
365                %>
366                <option value="<%=list.getId()%>" 
367                  title="<%=HTML.encodeTags(list.getDescription())%>"><%=HTML.encodeTags(list.getName())%>
368                <%
369              }
370              %>
371            </select>
372          </td>
373        </tbl:toolbar>
374        </td>
375      </tr>
376      <tr class="dynamic">
377        <td class="filled">
378        <textarea class="autohight" name="expression" rows="16"></textarea>
379        </td>
380      </tr>
381      </table>
382
383      </div>
384    </form>
385
386    <base:buttongroup subclass="dialogbuttons">
387      <base:button 
388        id="btnValidate"
389        title="Validate&hellip;" 
390        image="validate_formula.png"
391        tooltip="Validate the expression. EXPERIMENTAL!!" />
392      <base:button id="btnSave" title="Ok" />
393      <base:button id="close" title="Cancel" />
394    </base:buttongroup>
395  </base:body>
396  </base:page>
397  <%
398  }
399finally
400{
401  if (dc != null) dc.close();
402}
403%> 
Note: See TracBrowser for help on using the repository browser.