source: trunk/www/admin/datafiletypes/list_filetypes.jsp @ 7311

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

Fixes #2066: Display item subtypes that are referencing a data file type

Also added a column in the list page.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 17.4 KB
Line 
1<%-- $Id:list_filetypes.jsp 3820 2007-10-12 10:03:18Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 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
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  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.DataFileType"
30  import="net.sf.basedb.core.ItemSubtype"
31  import="net.sf.basedb.core.PlatformFileType"
32  import="net.sf.basedb.core.Platform"
33  import="net.sf.basedb.core.PlatformVariant"
34  import="net.sf.basedb.core.PlatformFileType"
35  import="net.sf.basedb.core.ItemSubtypeFileType"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.Include"
38  import="net.sf.basedb.core.Type"
39  import="net.sf.basedb.core.Metadata"
40  import="net.sf.basedb.core.ItemResultIterator"
41  import="net.sf.basedb.core.ItemResultList"
42  import="net.sf.basedb.core.ItemContext"
43  import="net.sf.basedb.core.Permission"
44  import="net.sf.basedb.core.PluginDefinition"
45  import="net.sf.basedb.core.query.Orders"
46  import="net.sf.basedb.core.query.Hql"
47  import="net.sf.basedb.core.query.Expressions"
48  import="net.sf.basedb.core.query.Restrictions"
49  import="net.sf.basedb.core.plugin.GuiContext"
50  import="net.sf.basedb.core.plugin.Plugin"
51  import="net.sf.basedb.util.Enumeration"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.PermissionUtil"
54  import="net.sf.basedb.clients.web.ModeInfo"
55  import="net.sf.basedb.clients.web.util.HTML"
56  import="net.sf.basedb.util.formatter.Formatter"
57  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
58  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
59  import="net.sf.basedb.clients.web.extensions.JspContext"
60  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
61  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
62  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
63  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
64  import="net.sf.basedb.util.Values"
65  import="java.util.List"
66  import="java.util.Map"
67  import="java.util.Date"
68%>
69<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
70<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
71<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
72<%!
73  private static final Item itemType = Item.DATAFILETYPE;
74  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
75  private static final Enumeration<String, String> items = new Enumeration<String, String>();
76  static
77  {
78    for (Item item : Metadata.getFileStoreEnabledItems())
79    {
80      items.add(Integer.toString(item.getValue()), item.toString());
81    }
82  }
83%>
84<%
85final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
86final String ID = sc.getId();
87final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
88final boolean writePermission = sc.hasPermission(Permission.WRITE, itemType);
89final boolean deletePermission = sc.hasPermission(Permission.DELETE, itemType);
90final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
91
92final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
93final String callback = request.getParameter("callback");
94final String title = mode.generateTitle("data file type", "data file types");
95final DbControl dc = sc.newDbControl();
96ItemResultIterator<DataFileType> fileTypes = null;
97try
98{
99  // Query to get the platforms a file type is registerd with
100  final ItemQuery<PlatformFileType> platformQuery = PlatformFileType.getQuery(null, null, false);
101  platformQuery.include(cc.getInclude());
102  platformQuery.restrict(Restrictions.eq(Hql.property("dataFileType"), Expressions.parameter("fileType")));
103  platformQuery.order(Orders.asc(Hql.property("platform.name"))); 
104
105  // Query to get the item subtypes a file type is registerd with
106  final ItemQuery<ItemSubtypeFileType> subtypeQuery = ItemSubtypeFileType.getQuery((DataFileType)null);
107  subtypeQuery.include(cc.getInclude());
108  subtypeQuery.restrict(Restrictions.eq(Hql.property("dataFileType"), Expressions.parameter("fileType")));
109  subtypeQuery.order(Orders.asc(Hql.property("itemSubtype.name"))); 
110 
111  // Get all file types
112  final ItemQuery<ItemSubtype> typeQuery = ItemSubtype.getQuery(Item.FILE);
113  typeQuery.order(Orders.asc(Hql.property("name")));
114  typeQuery.setCacheResult(true);
115  Enumeration<String, String> genericTypes = new Enumeration<String, String>();
116  for (ItemSubtype ft : typeQuery.list(dc))
117  {
118    genericTypes.add(Integer.toString(ft.getId()), ft.getName());
119  }
120
121  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
122  try
123  {
124    final ItemQuery<DataFileType> query = Base.getConfiguredQuery(dc, cc, true, DataFileType.getQuery(), mode);
125    fileTypes = query.iterate(dc);
126  }
127  catch (Throwable t)
128  {
129    cc.setMessage(t.getMessage());
130  }
131  int numListed = 0;
132  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
133  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
134  ExtensionsInvoker columnsInvoker = ListColumnUtil.useExtensions(jspContext);
135  %>
136  <base:page title="<%=title==null ? "Data file types" : title%>" type="<%=mode.getPageType()%>" id="list-page">
137  <base:head scripts="table.js,~filetypes.js" styles="table.css,toolbar.css">
138    <ext:scripts context="<%=jspContext%>" />
139    <ext:stylesheets context="<%=jspContext%>" />
140  </base:head>
141 
142  <base:body>
143    <h1><%=title==null ? "Data file types" : title%></h1>
144    <div class="content">
145    <tbl:table 
146      id="fileTypes" 
147      columns="<%=cc.getSetting("columns")%>"
148      sortby="<%=cc.getSortProperty()%>" 
149      direction="<%=cc.getSortDirection()%>"
150      action="index.jsp"
151      sc="<%=sc%>"
152      item="<%=itemType%>"
153      filterrows="<%=cc.getFilterRows()%>"
154      subclass="fulltable"
155      >
156      <tbl:hidden 
157        name="mode" 
158        value="<%=mode.getName()%>" 
159      />
160      <tbl:hidden 
161        name="callback" 
162        value="<%=callback%>" 
163        skip="<%=callback == null%>" 
164      />
165      <tbl:columndef 
166        id="name"
167        property="name"
168        datatype="string"
169        title="Name"
170        sortable="true" 
171        filterable="true"
172        exportable="true"
173        show="always" 
174      />
175      <tbl:columndef 
176        id="id"
177        clazz="uniquecol"
178        property="id"
179        datatype="int"
180        title="ID"
181        sortable="true"
182        filterable="true"
183        exportable="true"
184      />
185      <tbl:columndef 
186        id="externalId"
187        clazz="uniquecol"
188        property="externalId"
189        datatype="string"
190        title="External ID"
191        sortable="true"
192        filterable="true"
193        exportable="true"
194      />
195      <tbl:columndef 
196        id="extension"
197        property="extension"
198        datatype="string"
199        title="File extension"
200        sortable="true"
201        filterable="true"
202        exportable="true"
203      />
204      <tbl:columndef 
205        id="itemType"
206        property="itemType"
207        datatype="int"
208        title="Item type"
209        enumeration="<%=items%>"
210        sortable="true"
211        filterable="true"
212        exportable="true"
213      />
214      <tbl:columndef 
215        id="genericType"
216        property="genericType"
217        sortproperty="genericType.name"
218        exportproperty="genericType.name:string"
219        datatype="int"
220        enumeration="<%=genericTypes%>"
221        title="Generic type"
222        sortable="true" 
223        filterable="true"
224        exportable="true"
225      /> 
226      <tbl:columndef
227        id="platforms"
228        title="Platforms"
229        property="&platforms(platform.name)"
230        datatype="string"
231        filterable="true"
232      />
233      <tbl:columndef
234        id="subtypes"
235        title="Subtypes"
236        property="&itemSubtypes(itemSubtype.name)"
237        datatype="string"
238        filterable="true"
239      />
240      <tbl:columndef 
241        id="description"
242        property="description"
243        datatype="string"
244        title="Description" 
245        sortable="true" 
246        filterable="true" 
247        exportable="true"
248      />
249      <tbl:columndef 
250        id="xt-columns" 
251        extensions="<%=columnsInvoker%>" 
252        jspcontext="<%=jspContext%>" 
253      />
254      <div class="panelgroup bg-filled-50 bottomborder">
255        <tbl:toolbar
256          subclass="bottomborder"
257          visible="<%=mode.hasToolbar()%>"
258          >
259          <tbl:button 
260            id="btnNewItem"
261            disabled="<%=!createPermission%>" 
262            image="new.png" 
263            title="New&hellip;" 
264            tooltip="<%=createPermission ? "Create data file type" : "You do not have permission to create data file types"%>" 
265          />
266          <tbl:button 
267            id="btnDeleteItems"
268            disabled="<%=!deletePermission%>" 
269            image="delete.png" 
270            title="Delete" 
271            tooltip="<%=deletePermission ? "Delete the selected items" : "You do not have permission to delete data file types" %>" 
272          />
273          <tbl:button 
274            id="btnRestoreItems"
275            disabled="<%=!writePermission%>" 
276            image="restore.png" 
277            title="Restore" 
278            tooltip="<%=writePermission ? "Restore the selected (deleted) items" : "You do not have permission to edit date file types" %>" 
279          />
280          <tbl:button 
281            id="btnColumns"
282            image="columns.png" 
283            title="Columns&hellip;" 
284            tooltip="Show, hide and re-order columns" 
285          />
286          <tbl:button 
287            id="btnImport"
288            data-plugin-type="IMPORT"
289            image="import.png" 
290            title="Import&hellip;" 
291            tooltip="Import data" 
292            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
293          />
294          <tbl:button 
295            id="btnExport"
296            data-plugin-type="EXPORT"
297            image="export.png" 
298            title="Export&hellip;" 
299            tooltip="Export data" 
300            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
301          />
302          <tbl:button 
303            id="btnRunPlugin"
304            data-plugin-type="OTHER"
305            image="runplugin.png" 
306            title="Run plugin&hellip;" 
307            tooltip="Run a plugin" 
308            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
309          />
310          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
311            wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
312        </tbl:toolbar>
313        <tbl:panel>
314          <tbl:presetselector />
315          <tbl:navigator
316            page="<%=cc.getPage()%>" 
317            rowsperpage="<%=cc.getRowsPerPage()%>" 
318            totalrows="<%=fileTypes == null ? 0 : fileTypes.getTotalCount()%>" 
319            visible="<%=mode.hasNavigator()%>"
320          />
321        </tbl:panel>
322      </div>
323      <tbl:data>
324        <tbl:headers>
325          <tbl:headerrow>
326            <tbl:header colspan="3" />
327            <tbl:columnheaders />
328          </tbl:headerrow>
329          <%
330          int numFilters = cc.getNumPropertyFilters();
331          int numRows = cc.getFilterRows();
332          for (int filterNo = 0; filterNo < numRows; filterNo++)
333          {
334            boolean lastRow = filterNo == numRows-1;
335            %>
336            <tbl:headerrow>
337              <tbl:header subclass="index" />
338              <tbl:header 
339                subclass="check" 
340                visible="<%=mode.hasCheck()%>"
341                ><base:icon 
342                  subclass="link table-check"
343                  image="check_uncheck.png" 
344                  tooltip="Toggle all (use CTRL, ALT or SHIFT to check/uncheck)" 
345                  visible="<%=lastRow%>"
346                /></tbl:header>
347              <tbl:header 
348                subclass="check" 
349                visible="<%=mode.hasRadio()%>"
350                />
351              <tbl:header 
352                subclass="icons" 
353                visible="<%=mode.hasIcons()%>"
354                >
355                <base:icon
356                  subclass="link table-filter-row-action"
357                  image="add.png"
358                  tooltip="Add extra filter row"
359                  visible="<%=lastRow%>"
360                /><base:icon
361                  subclass="link table-filter-row-action"
362                  image="remove.png"
363                  tooltip="Remove this filter row"
364                  visible="<%=numRows > 1 || numFilters > 0 %>"
365                  data-remove-row="<%=filterNo%>"
366                />
367              </tbl:header>
368              <tbl:propertyfilter row="<%=filterNo%>" />
369            </tbl:headerrow>
370            <%
371          }
372          %>
373        </tbl:headers>
374        <tbl:rows>
375          <%
376          if (cc.getMessage() != null)
377          {
378            %>
379            <tbl:panel subclass="bg-filled-50">
380              <div class="messagecontainer error"><%=cc.getMessage()%></div>
381            </tbl:panel>
382            <%
383            cc.setMessage(null);
384          }
385          int index = cc.getPage()*cc.getRowsPerPage();
386          int selectedItemId = cc.getId();
387          if (fileTypes != null)
388          {           
389            while (fileTypes.hasNext())
390            {
391              DataFileType item = fileTypes.next();
392              int itemId = item.getId();
393              String name = HTML.encodeTags(item.getName());
394              String tooltip = mode.isSelectionMode() ? 
395                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : ""); 
396             
397              index++;
398              numListed++;
399              %>
400              <tbl:row>
401                <tbl:header 
402                  clazz="index"
403                  ><%=index%></tbl:header>
404                <tbl:header 
405                  clazz="check" 
406                  visible="<%=mode.hasCheck()%>"
407                  ><input 
408                    type="checkbox" 
409                    name="<%=itemId%>" 
410                    value="<%=itemId%>" 
411                    title="<%=name%>" 
412                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
413                  ></tbl:header>
414                <tbl:header 
415                  clazz="check" 
416                  visible="<%=mode.hasRadio()%>"
417                  ><input 
418                    type="radio" 
419                    name="item_id" 
420                    value="<%=itemId%>" 
421                    title="<%=name%>" 
422                    <%=selectedItemId == itemId ? "checked" : ""%>
423                  ></tbl:header>
424                <tbl:header 
425                  clazz="icons" 
426                  visible="<%=mode.hasIcons()%>"
427                  ><base:icon 
428                    image="deleted.png"
429                    id="<%="delete."+itemId %>"
430                    subclass="<%=deletePermission ? "table-delete-item" : "disabled" %>"
431                    data-item-id="<%=itemId%>"
432                    tooltip="This item has been scheduled for deletion" 
433                    visible="<%=item.isRemoved()%>"
434                  />&nbsp;</tbl:header>
435                <tbl:cell column="name"><div 
436                  class="link table-item"
437                  data-item-id="<%=itemId%>"
438                  data-no-edit="<%=writePermission ? 0 : 1 %>" 
439                  tabindex="0"
440                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
441                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
442                <tbl:cell column="externalId"><%=Values.getString(item.getExternalId())%></tbl:cell>
443                <tbl:cell column="extension"><%=Values.getString(item.getExtension())%></tbl:cell>
444                <tbl:cell column="itemType"><%=item.getItemType()%></tbl:cell>
445                <tbl:cell column="genericType"
446                  ><base:propertyvalue 
447                    item="<%=item%>" 
448                    property="genericType"
449                    enableEditLink="<%=mode.hasEditLink()%>" 
450                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
451                  /></tbl:cell>
452                <tbl:cell column="platforms">
453                  <%
454                  platformQuery.setParameter("fileType", itemId, Type.INT);
455                  try
456                  {
457                    String separator = "";
458                    for (PlatformFileType pft : platformQuery.list(dc))
459                    {
460                      Platform p = pft.getPlatform();
461                      PlatformVariant v = pft.getVariant();
462                      out.write(separator);
463                      if (mode.hasPropertyLink())
464                      {
465                        out.write(Base.getLinkedName(ID, p, false, mode.hasEditLink()));
466                      }
467                      else
468                      {
469                        out.write(HTML.encodeTags(p.getName()));
470                      }
471                      separator = ", ";
472                    }
473                  }
474                  catch (Throwable t)
475                  {
476                    %>
477                    <div class="error"><%=t.getMessage()%></div>
478                    <%
479                  }
480                  %>
481                </tbl:cell>
482                <tbl:cell column="subtypes">
483                  <%
484                  subtypeQuery.setParameter("fileType", itemId, Type.INT);
485                  try
486                  {
487                    String separator = "";
488                    for (ItemSubtypeFileType st : subtypeQuery.list(dc))
489                    {
490                      ItemSubtype s = st.getItemSubtype();
491                      out.write(separator);
492                      if (mode.hasPropertyLink())
493                      {
494                        out.write(Base.getLinkedName(ID, s, false, mode.hasEditLink()));
495                      }
496                      else
497                      {
498                        out.write(HTML.encodeTags(s.getName()));
499                      }
500                      separator = ", ";
501                    }
502                  }
503                  catch (Throwable t)
504                  {
505                    %>
506                    <div class="error"><%=t.getMessage()%></div>
507                    <%
508                  }
509                  %>
510                </tbl:cell>
511                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
512                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
513                  <tbl:cell column="xt-columns" />
514                </tbl:xt-cells>
515              </tbl:row>
516              <%
517              }
518            }
519          if (numListed == 0)
520          {
521            %>
522            <tbl:panel subclass="bg-filled-50">
523              <div class="messagecontainer note">
524              <%=fileTypes == null || fileTypes.getTotalCount() == 0 ? "No data file types were found" : "No data file types on this page. Please select another page!" %>
525              </div>
526            </tbl:panel>
527            <%
528          }
529          %>
530          </tbl:rows>
531      </tbl:data>
532    </tbl:table>
533    </div>
534   
535    <base:buttongroup subclass="dialogbuttons">
536      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
537      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
538      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
539    </base:buttongroup>
540   
541  </base:body>
542  </base:page>
543  <%
544}
545finally
546{
547  if (fileTypes != null) fileTypes.close();
548  if (dc != null) dc.close();
549}
550%>
Note: See TracBrowser for help on using the repository browser.