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

Last change on this file since 7943 was 7943, checked in by Nicklas Nordborg, 2 years ago

Merged BASE 3.18.1 to the trunk.

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