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

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

Fixes #2047: The "Share" and "Delete" icon in table listing seems to always be enabled

The "Delete" icon has been fixed.

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