source: trunk/www/biomaterials/tags/list_tags.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 Date Id
File size: 16.9 KB
Line 
1<%-- $Id: list_tags.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.Tag"
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.ItemResultIterator"
37  import="net.sf.basedb.core.ItemResultList"
38  import="net.sf.basedb.core.ItemContext"
39  import="net.sf.basedb.core.Nameable"
40  import="net.sf.basedb.core.Permission"
41  import="net.sf.basedb.core.PluginDefinition"
42  import="net.sf.basedb.core.plugin.GuiContext"
43  import="net.sf.basedb.core.plugin.Plugin"
44  import="net.sf.basedb.core.query.Hql"
45  import="net.sf.basedb.core.query.Orders"
46  import="net.sf.basedb.core.snapshot.AnnotationLoaderUtil"
47  import="net.sf.basedb.core.snapshot.AnnotationTypeFilter"
48  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
49  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
50  import="net.sf.basedb.core.snapshot.SnapshotManager"
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.Enumeration"
56  import="net.sf.basedb.util.ShareableUtil"
57  import="net.sf.basedb.util.Values"
58  import="net.sf.basedb.util.formatter.Formatter"
59  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
60  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
61  import="net.sf.basedb.clients.web.extensions.JspContext"
62  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
63  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
64  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
65  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
66  import="java.util.Date"
67  import="java.util.Iterator"
68  import="java.util.List"
69  import="java.util.Map"
70  import="java.util.ArrayList"
71%>
72<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
73<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
74<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
75<%!
76  private static final Item itemType = Item.TAG;
77  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
78%>
79<%
80final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
81final String ID = sc.getId();
82final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
83final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
84
85final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
86final String callback = request.getParameter("callback");
87final String title = mode.generateTitle("tag", "tags");
88final DbControl dc = sc.newDbControl();
89ItemResultIterator<Tag> tags = null;
90List<AnnotationLoaderUtil> annotationLoaders = new ArrayList<AnnotationLoaderUtil>();
91try
92{
93  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
94
95  final ItemQuery<ItemSubtype> typeQuery = ItemSubtype.getQuery(itemType);
96  typeQuery.order(Orders.asc(Hql.property("name")));
97  typeQuery.setCacheResult(true);
98  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
99  SnapshotManager manager = new SnapshotManager();
100  for (AnnotationType at : annotationTypeQuery.list(dc))
101  {
102    annotationLoaders.add(new AnnotationLoaderUtil(dc, manager, at));
103  }
104
105  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
106  try
107  {
108    final ItemQuery<Tag> query = Base.getConfiguredQuery(dc, cc, true, Tag.getQuery(), mode);
109    tags = query.iterate(dc);
110  }
111  catch (Throwable t)
112  {
113    cc.setMessage(t.getMessage());
114  }
115  int numListed = 0;
116  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
117  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
118  ExtensionsInvoker columnsInvoker = ListColumnUtil.useExtensions(jspContext);
119  %>
120  <base:page title="<%=title==null ? "Tags" : title%>" type="<%=mode.getPageType()%>" id="list-page">
121  <base:head scripts="table.js,~tags.js" styles="table.css,toolbar.css">
122    <ext:scripts context="<%=jspContext%>" />
123    <ext:stylesheets context="<%=jspContext%>" />
124  </base:head>
125 
126  <base:body>
127    <h1><%=title==null ? "Tags" : title%></h1>
128    <div class="content">
129    <tbl:table 
130      id="taglist" 
131      columns="<%=cc.getSetting("columns")%>"
132      sortby="<%=cc.getSortProperty()%>" 
133      direction="<%=cc.getSortDirection()%>"
134      action="index.jsp"
135      sc="<%=sc%>"
136      item="<%=itemType%>"
137      subclass="fulltable"
138      >
139      <tbl:hidden 
140        name="mode" 
141        value="<%=mode.getName()%>" 
142      />
143      <tbl:hidden 
144        name="callback" 
145        value="<%=callback%>" 
146        skip="<%=callback == null%>" 
147      />
148      <tbl:columndef 
149        id="name"
150        property="name"
151        datatype="string"
152        title="Name"
153        sortable="true" 
154        filterable="true"
155        exportable="true"
156        show="always" 
157      />
158      <tbl:columndef 
159        id="id"
160        clazz="uniquecol"
161        property="id"
162        datatype="int"
163        title="ID"
164        sortable="true"
165        filterable="true"
166        exportable="true"
167      />
168      <tbl:columndef 
169        id="owner"
170        property="owner.name"
171        datatype="string"
172        title="Owner"
173        sortable="true" 
174        filterable="true"
175        exportable="true"
176      />
177      <tbl:columndef 
178        id="entryDate"
179        property="entryDate"
180        datatype="date"
181        title="Registered"
182        sortable="true" 
183        filterable="true"
184        exportable="true"
185        formatter="<%=dateFormatter%>"
186      />
187      <%
188      Enumeration<String, String> tagTypes = new Enumeration<String, String>();
189      for (ItemSubtype subtype : typeQuery.list(dc))
190      {
191        tagTypes.add(Integer.toString(subtype.getId()), HTML.encodeTags(subtype.getName()));
192      }
193      %>   
194      <tbl:columndef 
195        id="itemSubtype"
196        property="itemSubtype"
197        sortproperty="itemSubtype.name"
198        exportproperty="itemSubtype.name:string"
199        datatype="int"
200        enumeration="<%=tagTypes%>"
201        title="Type"
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 tag" : "You do not have permission to create tags"%>" 
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="<%=tags == null ? 0 : tags.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 = cc.getId();
385          if (tags != null)
386          {           
387            while (tags.hasNext())
388            {
389              Tag item = tags.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 usePermission = item.hasPermission(Permission.USE);
396              boolean writePermission = item.hasPermission(Permission.WRITE);
397              String tooltip = mode.isSelectionMode() ? 
398                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
399              String name = HTML.encodeTags(item.getName());
400              index++;
401              numListed++;
402              %>
403              <tbl:row>
404                <tbl:header 
405                  clazz="index"
406                  ><%=index%></tbl:header>
407                <tbl:header 
408                  clazz="check" 
409                  visible="<%=mode.hasCheck()%>"
410                  ><input 
411                    type="checkbox" 
412                    name="<%=itemId%>" 
413                    value="<%=itemId%>" 
414                    title="<%=name%>" 
415                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
416                  ></tbl:header>
417                <tbl:header 
418                  clazz="check" 
419                  visible="<%=mode.hasRadio()%>"
420                  ><input 
421                    type="radio" 
422                    name="item_id" 
423                    value="<%=itemId%>" 
424                    title="<%=name%>" 
425                    <%=selectedItemId == itemId ? "checked" : ""%>
426                  ></tbl:header>
427                <tbl:header 
428                  clazz="icons" 
429                  visible="<%=mode.hasIcons()%>"
430                  ><base:icon 
431                    image="deleted.png"
432                    id="<%="delete."+itemId %>"
433                    subclass="<%=deletePermission ? "table-delete-item" : null %>"
434                    data-item-id="<%=itemId%>"
435                    tooltip="This item has been scheduled for deletion" 
436                    visible="<%=item.isRemoved()%>"
437                  /><base:icon 
438                    image="shared.png" 
439                    id="<%="share."+itemId %>"
440                    subclass="<%=sharePermission ? "table-share-item" : null %>"
441                    data-item-id="<%=itemId%>"
442                    tooltip="This item is shared to other users, groups and/or projects" 
443                    visible="<%=item.isShared()%>"
444                  />&nbsp;</tbl:header>
445                <tbl:cell column="name"><div
446                  class="link table-item"
447                  data-item-id="<%=itemId%>"
448                  data-no-edit="<%=writePermission ? 0 : 1 %>" 
449                  tabindex="0"
450                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
451                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
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="entryDate" value="<%=item.getEntryDate()%>" />
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                <%=tags == null || tags.getTotalCount() == 0 ? "No tags were found" : "No tags 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    <base:buttongroup subclass="dialogbuttons">
530      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
531      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
532      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
533    </base:buttongroup>
534  </base:body>
535  </base:page>
536  <%
537}
538finally
539{
540  if (tags != null) tags.close();
541  if (dc != null) dc.close();
542}
543%>
Note: See TracBrowser for help on using the repository browser.