source: trunk/www/admin/hardware/list_hardware.jsp @ 6604

Last change on this file since 6604 was 6604, checked in by Nicklas Nordborg, 9 years ago

References #1890: Improve skinnability of BASE

Updated table listings with some new css classes to make it easier to modify background color.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.0 KB
Line 
1<%-- $Id: list_hardware.jsp 6604 2014-11-18 10:39:22Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.Hardware"
31  import="net.sf.basedb.core.ItemSubtype"
32  import="net.sf.basedb.core.Annotation"
33  import="net.sf.basedb.core.AnnotationType"
34  import="net.sf.basedb.core.AnnotationSet"
35  import="net.sf.basedb.core.ItemQuery"
36  import="net.sf.basedb.core.Include"
37  import="net.sf.basedb.core.ItemResultIterator"
38  import="net.sf.basedb.core.ItemResultList"
39  import="net.sf.basedb.core.ItemContext"
40  import="net.sf.basedb.core.Nameable"
41  import="net.sf.basedb.core.Permission"
42  import="net.sf.basedb.core.PluginDefinition"
43  import="net.sf.basedb.core.query.Orders"
44  import="net.sf.basedb.core.query.Hql"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.core.plugin.Plugin"
47  import="net.sf.basedb.core.snapshot.AnnotationLoaderUtil"
48  import="net.sf.basedb.core.snapshot.AnnotationTypeFilter"
49  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
50  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
51  import="net.sf.basedb.core.snapshot.SnapshotManager"
52  import="net.sf.basedb.util.Enumeration"
53  import="net.sf.basedb.util.ShareableUtil"
54  import="net.sf.basedb.clients.web.Base"
55  import="net.sf.basedb.clients.web.PermissionUtil"
56  import="net.sf.basedb.clients.web.ModeInfo"
57  import="net.sf.basedb.clients.web.util.HTML"
58  import="net.sf.basedb.util.Values"
59  import="net.sf.basedb.util.formatter.Formatter"
60  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
61  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
62  import="net.sf.basedb.clients.web.extensions.JspContext"
63  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
64  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
65  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
66  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
67  import="java.util.Date"
68  import="java.util.Iterator"
69  import="java.util.List"
70  import="java.util.Map"
71  import="java.util.ArrayList"
72%>
73<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
74<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
75<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
76<%!
77  private static final Item itemType = Item.HARDWARE;
78  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
79%>
80<%
81final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
82final String ID = sc.getId();
83final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
84final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
85
86final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
87final String callback = request.getParameter("callback");
88final String title = mode.generateTitle("hardware", "hardware");
89final DbControl dc = sc.newDbControl();
90ItemResultIterator<Hardware> hardware = null;
91List<AnnotationLoaderUtil> annotationLoaders = new ArrayList<AnnotationLoaderUtil>();
92try
93{
94  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
95  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
96  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
97  SnapshotManager manager = new SnapshotManager();
98  for (AnnotationType at : annotationTypeQuery.list(dc))
99  {
100    annotationLoaders.add(new AnnotationLoaderUtil(dc, manager, at));
101  }
102
103  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
104  try
105  {
106    final ItemQuery<Hardware> query = Base.getConfiguredQuery(dc, cc, true, Hardware.getQuery(), mode);
107    hardware = query.iterate(dc);
108  }
109  catch (Throwable t)
110  {
111    cc.setMessage(t.getMessage());
112  }
113  int numListed = 0;
114  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
115  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
116  ExtensionsInvoker columnsInvoker = ListColumnUtil.useExtensions(jspContext);
117  %>
118  <base:page title="<%=title==null ? "Hardware" : title%>" type="<%=mode.getPageType()%>" id="list-page">
119  <base:head scripts="table.js,~hardware.js" styles="table.css,toolbar.css">
120    <ext:scripts context="<%=jspContext%>" />
121    <ext:stylesheets context="<%=jspContext%>" />
122  </base:head>
123 
124  <base:body>
125    <h1><%=title==null ? "Hardware" : title%></h1>
126    <div class="content">
127    <tbl:table 
128      id="hardware" 
129      columns="<%=cc.getSetting("columns")%>"
130      sortby="<%=cc.getSortProperty()%>" 
131      direction="<%=cc.getSortDirection()%>"
132      action="index.jsp"
133      sc="<%=sc%>"
134      item="<%=itemType%>"
135      subclass="fulltable"
136      >
137      <tbl:hidden 
138        name="mode" 
139        value="<%=mode.getName()%>" 
140      />
141      <tbl:hidden 
142        name="callback" 
143        value="<%=callback%>" 
144        skip="<%=callback == null%>" 
145      />
146      <tbl:columndef 
147        id="name"
148        property="name"
149        datatype="string"
150        title="Name"
151        sortable="true" 
152        filterable="true"
153        exportable="true"
154        show="always" 
155      />
156      <tbl:columndef 
157        id="id"
158        clazz="uniquecol"
159        property="id"
160        datatype="int"
161        title="ID"
162        sortable="true"
163        filterable="true"
164        exportable="true"
165      />
166      <tbl:columndef 
167        id="entryDate"
168        property="entryDate"
169        datatype="date"
170        title="Registered"
171        sortable="true" 
172        filterable="true"
173        exportable="true"
174        formatter="<%=dateFormatter%>"
175      />
176      <tbl:columndef 
177        id="version"
178        property="versionString"
179        datatype="string"
180        title="Version"
181        sortable="true"
182        filterable="true"
183        exportable="true"
184      />
185      <tbl:columndef 
186        id="itemSubtype"
187        property="itemSubtype"
188        sortproperty="itemSubtype.name"
189        exportproperty="itemSubtype.name:string"
190        datatype="int"
191        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
192        title="Type"
193        sortable="true" 
194        filterable="true"
195        exportable="true"
196      />
197      <tbl:columndef 
198        id="owner"
199        property="owner.name"
200        datatype="string"
201        title="Owner"
202        sortable="true" 
203        filterable="true"
204        exportable="true"
205      />
206      <tbl:columndef 
207        id="description"
208        property="description"
209        datatype="string"
210        title="Description" 
211        sortable="true" 
212        filterable="true" 
213        exportable="true"
214      />
215      <%
216      for (AnnotationLoaderUtil loader : annotationLoaders)
217      {
218        AnnotationType at = loader.getAnnotationType();
219        Enumeration<String, String> annotationEnum = null;
220        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
221        if (at.isEnumeration())
222        {
223          annotationEnum = new Enumeration<String, String>();
224          List<?> values = at.getValues();
225          for (Object value : values)
226          {
227            String encoded = formatter.format(value);
228            annotationEnum.add(encoded, encoded);
229          }
230        }
231        %>
232        <tbl:columndef 
233          id="<%="at"+at.getId()%>"
234          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
235          property="<%="#"+at.getId()%>"
236          annotation="true"
237          datatype="<%=at.getValueType().getStringValue()%>"
238          enumeration="<%=annotationEnum%>"
239          smartenum="<%=at.getDisplayAsList() %>"
240          sortable="<%=at.getMultiplicity() == 1%>" 
241          filterable="true" 
242          exportable="true"
243          formatter="<%=formatter%>"
244          unit="<%=at.getDefaultUnit()%>"
245        />
246        <%
247      }
248      %> 
249      <tbl:columndef
250        id="permission"
251        title="Permission"
252      />
253      <tbl:columndef
254        id="sharedTo"
255        title="Shared to"
256        filterable="true"
257        filterproperty="!sharedTo.name"
258        datatype="string"
259      />
260      <tbl:columndef 
261        id="xt-columns" 
262        extensions="<%=columnsInvoker%>" 
263        jspcontext="<%=jspContext%>" 
264      />
265      <div class="panelgroup bg-filled-50 bottomborder">
266        <tbl:toolbar
267          subclass="bottomborder"
268          visible="<%=mode.hasToolbar()%>"
269          >
270          <tbl:button 
271            id="btnNewItem"
272            disabled="<%=!createPermission%>" 
273            image="new.png" 
274            title="New&hellip;" 
275            tooltip="<%=createPermission ? "Create new hardware" : "You do not have permission to create hardware"%>" 
276          />
277          <tbl:button 
278            id="btnDeleteItems"
279            image="delete.png"
280            title="Delete" 
281            tooltip="Delete the selected items" 
282          />
283          <tbl:button 
284            id="btnRestoreItems"
285            image="restore.png"
286            title="Restore" 
287            tooltip="Restore the selected (deleted) items"
288          />
289          <tbl:button 
290            id="btnShareItems"
291            image="share.png"
292            title="Share&hellip;" 
293            tooltip="Share the selected items"
294          />
295          <tbl:button 
296            id="btnSetOwner"
297            image="take_ownership.png"
298            title="Set owner&hellip;"
299            tooltip="Change owner of the selected items"
300          />
301          <tbl:button 
302            id="btnColumns"
303            image="columns.png" 
304            title="Columns&hellip;" 
305            tooltip="Show, hide and re-order columns" 
306          />
307          <tbl:button 
308            id="btnImport"
309            data-plugin-type="IMPORT"
310            image="import.png" 
311            title="Import&hellip;" 
312            tooltip="Import data" 
313            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
314          />
315          <tbl:button 
316            id="btnExport"
317            data-plugin-type="EXPORT"
318            image="export.png" 
319            title="Export&hellip;" 
320            tooltip="Export data" 
321            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
322          />
323          <tbl:button 
324            id="btnRunPlugin"
325            data-plugin-type="OTHER"
326            image="runplugin.png" 
327            title="Run plugin&hellip;" 
328            tooltip="Run a plugin" 
329            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
330          />
331          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
332            wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
333        </tbl:toolbar>
334        <tbl:panel>
335          <tbl:presetselector />
336          <tbl:navigator
337            page="<%=cc.getPage()%>" 
338            rowsperpage="<%=cc.getRowsPerPage()%>" 
339            totalrows="<%=hardware == null ? 0 : hardware.getTotalCount()%>" 
340            visible="<%=mode.hasNavigator()%>"
341          />
342        </tbl:panel>
343      </div>
344      <tbl:data>
345        <tbl:headers>
346          <tbl:headerrow>
347            <tbl:header colspan="3" />
348            <tbl:columnheaders />
349          </tbl:headerrow>
350          <tbl:headerrow>
351            <tbl:header subclass="index" />
352            <tbl:header 
353              subclass="check" 
354              visible="<%=mode.hasCheck()%>"
355              ><base:icon 
356                id="check.uncheck"
357                image="check_uncheck.png" 
358                tooltip="Check/uncheck all" 
359                 
360              /></tbl:header>
361            <tbl:header 
362              subclass="check" 
363              visible="<%=mode.hasRadio()%>"
364              />
365            <tbl:header 
366              subclass="icons" 
367              visible="<%=mode.hasIcons()%>"
368              />
369            <tbl:propertyfilter />
370          </tbl:headerrow>
371        </tbl:headers>
372        <tbl:rows>
373          <%
374          if (cc.getMessage() != null)
375          {
376            %>
377            <tbl:panel subclass="bg-filled-50">
378              <div class="messagecontainer error"><%=cc.getMessage()%></div>
379            </tbl:panel>
380            <%
381            cc.setMessage(null);
382          }
383          int index = cc.getPage()*cc.getRowsPerPage();
384          int selectedItemId = Values.getInt(request.getParameter("item_id"));
385          if (hardware != null)
386          {
387            while (hardware.hasNext())
388            {
389              Hardware item = hardware.next();
390              int itemId = item.getId();
391             
392             
393              boolean deletePermission = item.hasPermission(Permission.DELETE);
394              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
395              boolean writePermission = item.hasPermission(Permission.WRITE);
396              String name = HTML.encodeTags(item.getName());
397              String tooltip = mode.isSelectionMode() ? 
398                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
399              index++;
400              numListed++;
401              %>
402              <tbl:row>
403                <tbl:header 
404                  clazz="index"
405                  ><%=index%></tbl:header>
406                <tbl:header 
407                  clazz="check" 
408                  visible="<%=mode.hasCheck()%>"
409                  ><input 
410                    type="checkbox" 
411                    name="<%=itemId%>" 
412                    value="<%=itemId%>" 
413                    title="<%=name%>" 
414                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
415                  ></tbl:header>
416                <tbl:header 
417                  clazz="check" 
418                  visible="<%=mode.hasRadio()%>"
419                  ><input 
420                    type="radio" 
421                    name="item_id" 
422                    value="<%=itemId%>" 
423                    title="<%=name%>" 
424                    <%=selectedItemId == itemId ? "checked" : ""%>
425                  ></tbl:header>
426                <tbl:header 
427                  clazz="icons" 
428                  visible="<%=mode.hasIcons()%>"
429                  ><base:icon 
430                    image="deleted.png"
431                    id="<%="delete."+itemId %>"
432                    subclass="<%=deletePermission ? "table-delete-item" : null %>"
433                    data-item-id="<%=itemId%>"
434                    tooltip="This item has been scheduled for deletion" 
435                    visible="<%=item.isRemoved()%>"
436                  /><base:icon 
437                    image="shared.png" 
438                    id="<%="share."+itemId %>"
439                    subclass="<%=sharePermission ? "table-share-item" : null %>"
440                    data-item-id="<%=itemId%>"
441                    tooltip="This item is shared to other users, groups and/or projects" 
442                    visible="<%=item.isShared()%>"
443                  />&nbsp;</tbl:header>
444                <tbl:cell column="name"><div 
445                  class="link table-item"
446                  data-item-id="<%=itemId%>"
447                  data-no-edit="<%=writePermission ? 0 : 1 %>" 
448                  tabindex="0"
449                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
450                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
451                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
452                <tbl:cell column="owner"
453                  ><base:propertyvalue 
454                    item="<%=item%>" 
455                    property="owner"
456                    enableEditLink="<%=mode.hasEditLink()%>" 
457                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
458                  /></tbl:cell>
459                <tbl:cell column="version"><%=HTML.encodeTags(item.getVersionString())%></tbl:cell>
460                <tbl:cell column="itemSubtype"
461                  ><base:propertyvalue 
462                    item="<%=item%>" 
463                    property="itemSubtype"
464                    enableEditLink="<%=mode.hasEditLink()%>" 
465                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
466                  /></tbl:cell>
467                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
468                <%
469                if (item.isAnnotated())
470                {
471                  AnnotationSetSnapshot snapshot = manager.getSnapshot(dc, item.getAnnotationSet().getId());
472                  for (AnnotationLoaderUtil loader : annotationLoaders)
473                  {
474                    if (loader.find(snapshot))
475                    {
476                      %>
477                      <tbl:cell 
478                        column="<%="at"+loader.getId()%>"
479                        ><tbl:cellvalue 
480                          list="<%=loader.getValues()%>"
481                          suffix="<%=loader.getUnitSymbol()%>"
482                      /></tbl:cell>
483                      <%
484                    }
485                  }
486                }
487                %>
488                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
489                <tbl:cell column="sharedTo">
490                  <%
491                  Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator();
492                  while(sharees.hasNext())
493                  {
494                    Nameable n = sharees.next();
495                    if (mode.hasPropertyLink())
496                    {
497                      out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
498                    }
499                    else
500                    {
501                      out.write(HTML.encodeTags(n.getName()));
502                    }
503                    out.write(sharees.hasNext() ? ", " : "");
504                  }
505                  %>
506                </tbl:cell>
507                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
508                  <tbl:cell column="xt-columns" />
509                </tbl:xt-cells>
510              </tbl:row>
511              <%
512              }
513            }
514          if (numListed == 0)
515          {
516            %>
517            <tbl:panel subclass="bg-filled-50">
518              <div class="messagecontainer note">
519              <%=hardware == null || hardware.getTotalCount() == 0 ? "No hardware were found" : "No hardware on this page. Please select another page!" %>
520              </div>
521            </tbl:panel>
522            <%
523          }
524          %>
525          </tbl:rows>
526      </tbl:data>
527    </tbl:table>
528    </div>
529   
530    <base:buttongroup subclass="dialogbuttons">
531      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
532      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
533      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
534    </base:buttongroup>
535   
536  </base:body>
537  </base:page>
538  <%
539}
540finally
541{
542  if (hardware != null) hardware.close();
543  if (dc != null) dc.close();
544}
545%>
Note: See TracBrowser for help on using the repository browser.