source: trunk/www/admin/protocols/list_protocol.jsp @ 7943

Last change on this file since 7943 was 7943, checked in by Nicklas Nordborg, 23 months ago

Merged BASE 3.18.1 to the trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 18.9 KB
Line 
1<%-- $Id: list_protocol.jsp 7943 2021-05-04 12:23:19Z 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.Protocol"
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.ModeInfo"
56  import="net.sf.basedb.clients.web.PermissionUtil"
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.ButtonAction" 
65  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
66  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
67  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
68  import="net.sf.basedb.clients.web.util.ProjectSpecificInfoFilter"
69  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
70  import="java.util.Date"
71  import="java.util.Iterator"
72  import="java.util.List"
73  import="java.util.Map"
74  import="java.util.ArrayList"
75%>
76<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
77<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
78<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
79<%!
80  private static final Item itemType = Item.PROTOCOL;
81  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
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 ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
88
89final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
90final String callback = request.getParameter("callback");
91final String title = mode.generateTitle("protocol", "protocols");
92final DbControl dc = sc.newDbControl();
93ItemResultIterator<Protocol> protocols = null;
94List<AnnotationLoaderUtil> annotationLoaders = new ArrayList<AnnotationLoaderUtil>();
95try
96{
97  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
98  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
99  SnapshotManager manager = new SnapshotManager();
100  ProjectSpecificInfoFilter psInfo = new ProjectSpecificInfoFilter();
101  for (AnnotationType at : annotationTypeQuery.list(dc))
102  {
103    annotationLoaders.add(new AnnotationLoaderUtil(dc, manager, at));
104  }
105 
106  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
107  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
108  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
109  try
110  {
111    final ItemQuery<Protocol> query = Base.getConfiguredQuery(dc, cc, jspContext, true, Protocol.getQuery(), mode);
112    protocols = query.iterate(dc);
113  }
114  catch (Throwable t)
115  {
116    cc.setMessage(t.getMessage());
117  }
118  int numListed = 0;
119  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
120  ExtensionsInvoker<ListColumnAction<Protocol,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
121  %>
122  <base:page title="<%=title==null ? "Protocols" : title%>" type="<%=mode.getPageType()%>" id="list-page">
123  <base:head scripts="table.js,~protocols.js" styles="table.css,toolbar.css">
124    <ext:scripts context="<%=jspContext%>" />
125    <ext:stylesheets context="<%=jspContext%>" />
126  </base:head>
127 
128  <base:body>
129    <h1><%=title==null ? "Protocols" : title%></h1>
130    <div class="content">
131    <tbl:table 
132      id="protocols" 
133      columns="<%=cc.getSetting("columns")%>"
134      sortby="<%=cc.getSortProperty()%>" 
135      direction="<%=cc.getSortDirection()%>"
136      action="index.jsp"
137      sc="<%=sc%>"
138      item="<%=itemType%>"
139      filterrows="<%=cc.getFilterRows()%>"
140      subclass="fulltable"
141      stickyheaders="name"
142      >
143      <tbl:hidden 
144        name="mode" 
145        value="<%=mode.getName()%>" 
146      />
147      <tbl:hidden 
148        name="callback" 
149        value="<%=callback%>" 
150        skip="<%=callback == null%>" 
151      />
152      <tbl:columndef 
153        id="name"
154        property="name"
155        datatype="string"
156        title="Name"
157        sortable="true" 
158        filterable="true"
159        exportable="true"
160        show="always" 
161      />
162      <tbl:columndef 
163        id="id"
164        clazz="uniquecol"
165        property="id"
166        datatype="int"
167        title="ID"
168        sortable="true"
169        filterable="true"
170        exportable="true"
171      />
172      <tbl:columndef 
173        id="entryDate"
174        property="entryDate"
175        datatype="date"
176        title="Registered"
177        sortable="true" 
178        filterable="true"
179        exportable="true"
180        formatter="<%=dateFormatter%>"
181      />
182      <tbl:columndef 
183        id="externalId"
184        property="externalId"
185        datatype="string"
186        title="External id"
187        sortable="true" 
188        filterable="true"
189        exportable="true"
190      />     
191      <tbl:columndef 
192        id="itemSubtype"
193        property="itemSubtype"
194        sortproperty="itemSubtype.name"
195        exportproperty="itemSubtype.name:string"
196        datatype="int"
197        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
198        title="Type"
199        sortable="true" 
200        filterable="true"
201        exportable="true"
202      />
203      <tbl:columndef
204        id="file"
205        property="file.name"
206        datatype="string"
207        title="File"
208        sortable="true" 
209        filterable="true"
210        exportable="true"
211      />
212      <tbl:columndef 
213        id="owner"
214        property="owner.name"
215        datatype="string"
216        title="Owner"
217        sortable="true" 
218        filterable="true"
219        exportable="true"
220      />
221      <tbl:columndef 
222        id="description"
223        property="description"
224        datatype="string"
225        title="Description" 
226        sortable="true" 
227        filterable="true" 
228        exportable="true"
229      />
230      <%
231      for (AnnotationLoaderUtil loader : annotationLoaders)
232      {
233        AnnotationType at = loader.getAnnotationType();
234        Enumeration<String, String> annotationEnum = null;
235        Formatter<Object> formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
236        if (at.isEnumeration())
237        {
238          annotationEnum = new Enumeration<String, String>();
239          if (!at.getDisplayAsList()) annotationEnum.add("", "-none-");
240          List<?> values = at.getValues();
241          for (Object value : values)
242          {
243            String encoded = formatter.format(value);
244            annotationEnum.add(encoded, encoded);
245          }
246        }
247        %>
248        <tbl:columndef 
249          id="<%="at"+at.getId()%>"
250          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
251          property="<%="#"+at.getId()%>"
252          annotation="true"
253          datatype="<%=at.getValueType().getStringValue()%>"
254          enumeration="<%=annotationEnum%>"
255          smartenum="<%=at.getDisplayAsList() %>"
256          sortable="<%=at.getMultiplicity() == 1%>" 
257          filterable="true" 
258          exportable="true"
259          formatter="<%=formatter%>"
260          unit="<%=at.getDefaultUnit()%>"
261        />
262        <%
263      }
264      %> 
265      <tbl:columndef
266        id="permission"
267        title="Permission"
268      />
269      <tbl:columndef
270        id="sharedTo"
271        title="Shared to"
272        filterable="true"
273        filterproperty="!sharedTo.name"
274        datatype="string"
275      />
276      <tbl:columndef 
277        id="xt-columns" 
278        extensions="<%=columnsInvoker%>" 
279        jspcontext="<%=jspContext%>" 
280      />
281      <div class="panelgroup bg-filled-50 bottomborder">
282        <tbl:toolbar
283          subclass="bottomborder"
284          visible="<%=mode.hasToolbar()%>"
285          >
286          <tbl:button 
287            id="btnNewItem"
288            disabled="<%=!createPermission%>" 
289            image="new.png" 
290            title="New&hellip;" 
291            tooltip="<%=createPermission ? "Create new protocol" : "You do not have permission to create protocols"%>" 
292          />
293          <tbl:button 
294            id="btnDeleteItems"
295            image="delete.png"
296            title="Delete" 
297            tooltip="Delete the selected items" 
298          />
299          <tbl:button 
300            id="btnRestoreItems"
301            image="restore.png"
302            title="Restore" 
303            tooltip="Restore the selected (deleted) items"
304          />
305          <tbl:button 
306            id="btnShareItems"
307            image="share.png"
308            title="Share&hellip;" 
309            tooltip="Share the selected items"
310          />
311          <tbl:button 
312            id="btnSetOwner"
313            image="take_ownership.png"
314            title="Set owner&hellip;"
315            tooltip="Change owner of the selected items"
316          />
317          <tbl:button 
318            id="btnColumns"
319            image="columns.png" 
320            title="Columns&hellip;" 
321            tooltip="Show, hide and re-order columns" 
322          />
323          <tbl:button 
324            id="btnImport"
325            data-plugin-type="IMPORT"
326            image="import.png" 
327            title="Import&hellip;" 
328            tooltip="Import data" 
329            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
330          />
331          <tbl:button 
332            id="btnExport"
333            data-plugin-type="EXPORT"
334            image="export.png" 
335            title="Export&hellip;" 
336            tooltip="Export data" 
337            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
338          />
339          <tbl:button 
340            id="btnRunPlugin"
341            data-plugin-type="OTHER"
342            image="runplugin.png" 
343            title="Run plugin&hellip;" 
344            tooltip="Run a plugin" 
345            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
346          />
347          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
348            wrapper="<%=new PrefixSuffixRenderer<ButtonAction>(jspContext, "<td>", "</td>") %>"/>
349        </tbl:toolbar>
350        <tbl:panel>
351          <tbl:presetselector />
352          <tbl:navigator
353            page="<%=cc.getPage()%>" 
354            rowsperpage="<%=cc.getRowsPerPage()%>" 
355            totalrows="<%=protocols == null ? 0 : protocols.getTotalCount()%>" 
356            visible="<%=mode.hasNavigator()%>"
357          />
358        </tbl:panel>
359      </div>
360      <tbl:data>
361        <tbl:headers>
362          <tbl:headerrow>
363            <tbl:header clazz="row-index bg-filled-100" />
364            <tbl:columnheaders />
365          </tbl:headerrow>
366          <%
367          int numFilters = cc.getNumPropertyFilters();
368          int numRows = cc.getFilterRows();
369          for (int filterNo = 0; filterNo < numRows; filterNo++)
370          {
371            boolean lastRow = filterNo == numRows-1;
372            %>
373            <tbl:headerrow>
374              <tbl:header subclass="row-index bg-filled-100">
375                <div class="index-<%=mode.getName()%>">
376                  <div class="index"></div>
377                  <div class="check">
378                    <base:icon 
379                      subclass="link table-check"
380                      image="check_uncheck.png" 
381                      tooltip="Toggle all (use CTRL, ALT or SHIFT to check/uncheck)" 
382                      visible="<%=lastRow && mode.hasCheck()%>"
383                    />
384                  </div>
385                  <div class="icons">
386                    <base:icon
387                      subclass="link table-filter-row-action"
388                      image="add.png"
389                      tooltip="Add extra filter row"
390                      visible="<%=lastRow%>"
391                    /><base:icon
392                      subclass="link table-filter-row-action"
393                      image="remove.png"
394                      tooltip="Remove this filter row"
395                      visible="<%=numRows > 1 || numFilters > 0 %>"
396                      data-remove-row="<%=filterNo%>"
397                    />
398                  </div>
399                </div>
400              </tbl:header>
401              <tbl:propertyfilter row="<%=filterNo%>" />
402            </tbl:headerrow>
403            <%
404          }
405          %>
406          <tbl:columnsubtitles />
407        </tbl:headers>
408        <tbl:rows>
409          <%
410          if (cc.getMessage() != null)
411          {
412            %>
413            <tbl:panel subclass="bg-filled-50">
414              <div class="messagecontainer error"><%=cc.getMessage()%></div>
415            </tbl:panel>
416            <%
417            cc.setMessage(null);
418          }
419          int index = cc.getPage()*cc.getRowsPerPage();
420          int selectedItemId = Values.getInt(request.getParameter("item_id"));
421          if (protocols != null)
422          {
423            while (protocols.hasNext())
424            {
425              Protocol item = protocols.next();
426              int itemId = item.getId();
427             
428             
429              boolean deletePermission = item.hasPermission(Permission.DELETE);
430              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
431              boolean writePermission = item.hasPermission(Permission.WRITE);
432              String name = HTML.encodeTags(item.getName());
433              String tooltip = mode.isSelectionMode() ? 
434                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
435              index++;
436              numListed++;
437              %>
438              <tbl:row>
439                <tbl:header clazz="row-index bg-filled-100">
440                  <div class="index-<%=mode.getName()%>">
441                    <div class="index <%=index>999?"index-smaller":""%>"><%=index%></div>
442                    <div class="check">
443                      <base:input
444                        type="checkbox" 
445                        name="<%=itemId%>" 
446                        value="<%=itemId%>" 
447                        title="<%=name%>" 
448                        checked="<%=cc.getSelected().contains(itemId)%>"
449                        visible="<%=mode.hasCheck()%>"
450                      />
451                      <base:input 
452                        type="radio" 
453                        name="item_id" 
454                        value="<%=itemId%>" 
455                        title="<%=name%>" 
456                        checked="<%=selectedItemId == itemId%>"
457                        visible="<%=mode.hasRadio()%>"
458                      />
459                    </div>
460                    <div class="icons">
461                      <base:icon 
462                        image="deleted.png"
463                        id="<%="delete."+itemId %>"
464                        subclass="<%=deletePermission ? "table-delete-item" : "disabled" %>"
465                        data-item-id="<%=itemId%>"
466                        tooltip="This item has been scheduled for deletion" 
467                        visible="<%=item.isRemoved()%>"
468                      /><base:icon 
469                        image="shared.png" 
470                        id="<%="share."+itemId %>"
471                        subclass="<%=sharePermission ? "table-share-item" : "disabled" %>"
472                        data-item-id="<%=itemId%>"
473                        tooltip="This item is shared to other users, groups and/or projects" 
474                        visible="<%=item.isShared()%>"
475                      />
476                    </div>
477                  </div>
478                </tbl:header>
479                <tbl:cell column="name"><div
480                  class="link table-item"
481                  data-item-id="<%=itemId%>"
482                  data-no-edit="<%=writePermission ? 0 : 1 %>" 
483                  tabindex="0"
484                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
485                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
486                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
487                <tbl:cell column="owner"
488                  ><base:propertyvalue 
489                    item="<%=item%>" 
490                    property="owner"
491                    enableEditLink="<%=mode.hasEditLink()%>" 
492                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
493                  /></tbl:cell>
494                <tbl:cell column="file"
495                  ><base:propertyvalue 
496                    item="<%=item%>" 
497                    property="file"
498                    enableEditLink="<%=mode.hasEditLink()%>" 
499                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
500                  /></tbl:cell>
501                <tbl:cell column="itemSubtype"
502                  ><base:propertyvalue 
503                    item="<%=item%>" 
504                    property="itemSubtype"
505                    enableEditLink="<%=mode.hasEditLink()%>" 
506                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
507                  /></tbl:cell>
508                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>               
509                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
510                <%
511                if (item.isAnnotated())
512                {
513                  AnnotationSetSnapshot snapshot = manager.getSnapshot(dc, item.getAnnotationSet().getId());
514                  for (AnnotationLoaderUtil loader : annotationLoaders)
515                  {
516                    %>
517                    <tbl:cell 
518                      column="<%="at"+loader.getId()%>"
519                      ><%
520                      if (loader.find(snapshot, psInfo.reset())) 
521                      {
522                        %><tbl:cellvalue 
523                          list="<%=loader.getValues()%>"
524                          suffix="<%=loader.getUnitSymbol()%>"
525                          clazz="<%=psInfo.overridesDefaultAnnotation() ? "ps-annotation" : null%>"
526                        /><%
527                      }
528                      %></tbl:cell>
529                    <%
530                  }
531                }
532                %>
533                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
534                <tbl:cell column="sharedTo">
535                  <%
536                  Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator();
537                  while(sharees.hasNext())
538                  {
539                    Nameable n = sharees.next();
540                    if (mode.hasPropertyLink())
541                    {
542                      out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
543                    }
544                    else
545                    {
546                      out.write(HTML.encodeTags(n.getName()));
547                    }
548                    out.write(sharees.hasNext() ? ", " : "");
549                  }
550                  %>
551                </tbl:cell>
552                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
553                  <tbl:cell column="xt-columns" />
554                </tbl:xt-cells>
555              </tbl:row>
556              <%
557              }
558            }
559          if (numListed == 0)
560          {
561            %>
562            <tbl:panel subclass="bg-filled-50">
563              <div class="messagecontainer note">
564              <%=protocols == null || protocols.getTotalCount() == 0 ? "No protocols were found" : "No protocols on this page. Please select another page!" %>
565              </div>
566            </tbl:panel>
567            <%
568          }
569          %>
570        </tbl:rows>
571      </tbl:data>
572    </tbl:table>
573    </div>
574   
575    <base:buttongroup subclass="dialogbuttons">
576      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
577      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
578      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
579    </base:buttongroup>
580   
581  </base:body>
582  </base:page>
583  <%
584}
585finally
586{
587  if (protocols != null) protocols.close();
588  if (dc != null) dc.close();
589}
590%>
Note: See TracBrowser for help on using the repository browser.