source: trunk/www/admin/groups/list_groups.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: 16.8 KB
Line 
1<%-- $Id: list_groups.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, Nicklas Nordborg
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.Group"
31  import="net.sf.basedb.core.User"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.ItemResultIterator"
35  import="net.sf.basedb.core.ItemResultList"
36  import="net.sf.basedb.core.ItemContext"
37  import="net.sf.basedb.core.Permission"
38  import="net.sf.basedb.core.Type"
39  import="net.sf.basedb.core.PluginDefinition"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.core.query.Restrictions"
43  import="net.sf.basedb.core.query.Expressions"
44  import="net.sf.basedb.core.plugin.GuiContext"
45  import="net.sf.basedb.core.plugin.Plugin"
46  import="net.sf.basedb.util.Enumeration"
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.PermissionUtil"
49  import="net.sf.basedb.clients.web.ModeInfo"
50  import="net.sf.basedb.clients.web.util.HTML"
51  import="net.sf.basedb.util.Values"
52  import="net.sf.basedb.util.formatter.Formatter"
53  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
54  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
55  import="net.sf.basedb.clients.web.extensions.JspContext"
56  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
57  import="net.sf.basedb.clients.web.extensions.toolbar.ButtonAction" 
58  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
59  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
60  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
61  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
62  import="java.util.Date"
63  import="java.util.List"
64  import="java.util.Map"
65%>
66<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
67<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
68<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
69<%!
70  private static final Item itemType = Item.GROUP;
71  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
72%>
73<%
74final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
75final String ID = sc.getId();
76final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
77final boolean writePermission = sc.hasPermission(Permission.WRITE, itemType);
78final boolean deletePermission = sc.hasPermission(Permission.DELETE, itemType);
79final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
80
81final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
82final String callback = request.getParameter("callback");
83final String title = mode.generateTitle("group", "groups");
84final DbControl dc = sc.newDbControl();
85ItemResultIterator<Group> groups = null;
86try
87{
88  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
89  // Query for groups relatated to the current group
90  final ItemQuery<Group> groupQuery = Group.getQuery();
91  groupQuery.include(cc.getInclude());
92  groupQuery.join(Hql.innerJoin("parents", "p"));
93  groupQuery.restrict(Restrictions.eq(Hql.alias("p"), Expressions.parameter("group")));
94  groupQuery.order(Orders.asc(Hql.property("name"))); 
95
96  // Query for users relatated to the current group
97  final ItemQuery<User> userQuery = User.getQuery();
98  userQuery.include(cc.getInclude());
99  userQuery.join(Hql.innerJoin("groups", "grp"));
100  userQuery.restrict(Restrictions.eq(Hql.alias("grp"), Expressions.parameter("group")));
101  userQuery.order(Orders.asc(Hql.property("name"))); 
102
103  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
104  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
105  try
106  {
107    final ItemQuery<Group> query = Base.getConfiguredQuery(dc, cc, jspContext, true, Group.getQuery(), mode);
108    groups = query.iterate(dc);
109  }
110  catch (Throwable t)
111  {
112    cc.setMessage(t.getMessage());
113  }
114  int numListed = 0;
115  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
116  ExtensionsInvoker<ListColumnAction<Group,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
117  %>
118  <base:page title="<%=title==null ? "Groups" : title%>" type="<%=mode.getPageType()%>" id="list-page">
119  <base:head scripts="table.js,~groups.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 ? "Groups" : title%></h1>
126    <div class="content">
127    <tbl:table 
128      id="groups" 
129      columns="<%=cc.getSetting("columns")%>"
130      sortby="<%=cc.getSortProperty()%>" 
131      direction="<%=cc.getSortDirection()%>"
132      action="index.jsp"
133      sc="<%=sc%>"
134      item="<%=itemType%>"
135      filterrows="<%=cc.getFilterRows()%>"
136      subclass="fulltable"
137      stickyheaders="name"
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="entryDate"
170        property="entryDate"
171        datatype="date"
172        title="Registered"
173        sortable="true" 
174        filterable="true"
175        exportable="true"
176        formatter="<%=dateFormatter%>"
177      />
178      <tbl:columndef 
179        id="systemId"
180        clazz="uniquecol"
181        property="systemId"
182        datatype="string"
183        title="System ID"
184        sortable="true"
185        filterable="true"
186        exportable="true"
187      />
188      <tbl:columndef 
189        id="quota"
190        property="quota.name"
191        datatype="string"
192        title="Quota"
193        sortable="true" 
194        filterable="true"
195        exportable="true"
196      />
197      <tbl:columndef 
198        id="isDefault"
199        property="default"
200        datatype="boolean"
201        title="Is default"
202        sortable="true" 
203        filterable="true"
204        exportable="true"
205      />
206      <tbl:columndef 
207        id="hiddenMembers"
208        property="hiddenMembers"
209        datatype="boolean"
210        title="Hidden members"
211        sortable="true" 
212        filterable="true"
213        exportable="true"
214      />
215      <tbl:columndef
216        id="users"
217        title="Users"
218        property="&users(name)"
219        datatype="string"
220        filterable="true"
221        exportable="true"
222      />
223      <tbl:columndef
224        id="groups"
225        title="Groups"
226        property="&children(name)"
227        datatype="string"
228        filterable="true"
229        exportable="true"
230      />
231      <tbl:columndef 
232        id="description"
233        property="description"
234        datatype="string"
235        title="Description" 
236        sortable="true" 
237        filterable="true" 
238        exportable="true"
239      />
240      <tbl:columndef 
241        id="xt-columns" 
242        extensions="<%=columnsInvoker%>" 
243        jspcontext="<%=jspContext%>" 
244      />
245      <div class="panelgroup bg-filled-50 bottomborder">
246        <tbl:toolbar
247          subclass="bottomborder"
248          visible="<%=mode.hasToolbar()%>"
249          >
250          <tbl:button 
251            id="btnNewItem"
252            disabled="<%=!createPermission%>" 
253            image="new.png" 
254            title="New&hellip;" 
255            tooltip="<%=createPermission ? "Create new group" : "You do not have permission to create groups"%>" 
256          />
257          <tbl:button 
258            id="btnDeleteItems"
259            disabled="<%=!deletePermission%>" 
260            image="delete.png" 
261            title="Delete" 
262            tooltip="<%=deletePermission ? "Delete the selected items" : "You do not have permission to delete groups" %>" 
263          />
264          <tbl:button 
265            id="btnRestoreItems"
266            disabled="<%=!writePermission%>" 
267            image="restore.png" 
268            title="Restore" 
269            tooltip="<%=writePermission ? "Restore the selected (deleted) items" : "You do not have permission to edit groups" %>" 
270          />
271          <tbl:button 
272            id="btnColumns"
273            image="columns.png" 
274            title="Columns&hellip;" 
275            tooltip="Show, hide and re-order columns" 
276          />
277          <tbl:button 
278            id="btnImport"
279            data-plugin-type="IMPORT"
280            image="import.png" 
281            title="Import&hellip;" 
282            tooltip="Import data" 
283            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
284          />
285          <tbl:button 
286            id="btnExport"
287            data-plugin-type="EXPORT"
288            image="export.png" 
289            title="Export&hellip;" 
290            tooltip="Export data" 
291            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
292          />
293          <tbl:button 
294            id="btnRunPlugin"
295            data-plugin-type="OTHER"
296            image="runplugin.png" 
297            title="Run plugin&hellip;" 
298            tooltip="Run a plugin" 
299            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
300          />
301          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
302            wrapper="<%=new PrefixSuffixRenderer<ButtonAction>(jspContext, "<td>", "</td>") %>"/>
303        </tbl:toolbar>
304        <tbl:panel>
305          <tbl:presetselector />
306          <tbl:navigator
307            page="<%=cc.getPage()%>" 
308            rowsperpage="<%=cc.getRowsPerPage()%>" 
309            totalrows="<%=groups == null ? 0 : groups.getTotalCount()%>" 
310            visible="<%=mode.hasNavigator()%>"
311          />
312        </tbl:panel>
313      </div>
314      <tbl:data>
315        <tbl:headers>
316          <tbl:headerrow>
317            <tbl:header clazz="row-index bg-filled-100" />
318            <tbl:columnheaders />
319          </tbl:headerrow>
320          <%
321          int numFilters = cc.getNumPropertyFilters();
322          int numRows = cc.getFilterRows();
323          for (int filterNo = 0; filterNo < numRows; filterNo++)
324          {
325            boolean lastRow = filterNo == numRows-1;
326            %>
327            <tbl:headerrow>
328              <tbl:header subclass="row-index bg-filled-100">
329                <div class="index-<%=mode.getName()%>">
330                  <div class="index"></div>
331                  <div class="check">
332                    <base:icon 
333                      subclass="link table-check"
334                      image="check_uncheck.png" 
335                      tooltip="Toggle all (use CTRL, ALT or SHIFT to check/uncheck)" 
336                      visible="<%=lastRow && mode.hasCheck()%>"
337                    />
338                  </div>
339                  <div class="icons">
340                    <base:icon
341                      subclass="link table-filter-row-action"
342                      image="add.png"
343                      tooltip="Add extra filter row"
344                      visible="<%=lastRow%>"
345                    /><base:icon
346                      subclass="link table-filter-row-action"
347                      image="remove.png"
348                      tooltip="Remove this filter row"
349                      visible="<%=numRows > 1 || numFilters > 0 %>"
350                      data-remove-row="<%=filterNo%>"
351                    />
352                  </div>
353                </div>
354              </tbl:header>
355              <tbl:propertyfilter row="<%=filterNo%>" />
356            </tbl:headerrow>
357            <%
358          }
359          %>
360          <tbl:columnsubtitles />
361        </tbl:headers>
362        <tbl:rows>
363          <%
364          if (cc.getMessage() != null)
365          {
366            %>
367            <tbl:panel subclass="bg-filled-50">
368              <div class="messagecontainer error"><%=cc.getMessage()%></div>
369            </tbl:panel>
370            <%
371            cc.setMessage(null);
372          }
373          int index = cc.getPage()*cc.getRowsPerPage();
374          int selectedItemId = cc.getId();
375          if (groups != null)
376          {           
377            while (groups.hasNext())
378            {
379              Group item = groups.next();
380              int itemId = item.getId();
381              String name = HTML.encodeTags(item.getName());
382              String tooltip = mode.isSelectionMode() ? 
383                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
384             
385              index++;
386              numListed++;
387              %>
388              <tbl:row>
389                <tbl:header clazz="row-index bg-filled-100">
390                  <div class="index-<%=mode.getName()%>">
391                    <div class="index <%=index>999?"index-smaller":""%>"><%=index%></div>
392                    <div class="check">
393                      <base:input
394                        type="checkbox" 
395                        name="<%=itemId%>" 
396                        value="<%=itemId%>" 
397                        title="<%=name%>" 
398                        checked="<%=cc.getSelected().contains(itemId)%>"
399                        visible="<%=mode.hasCheck()%>"
400                      />
401                      <base:input 
402                        type="radio" 
403                        name="item_id" 
404                        value="<%=itemId%>" 
405                        title="<%=name%>" 
406                        checked="<%=selectedItemId == itemId%>"
407                        visible="<%=mode.hasRadio()%>"
408                      />
409                    </div>
410                    <div class="icons">
411                      <base:icon 
412                        image="deleted.png"
413                        id="<%="delete."+itemId %>"
414                        subclass="<%=deletePermission ? "table-delete-item" : "disabled" %>"
415                        data-item-id="<%=itemId%>"
416                        tooltip="This item has been scheduled for deletion" 
417                        visible="<%=item.isRemoved()%>"
418                      /><base:icon
419                        image="systemitem.png"
420                        tooltip="This item is a system item"
421                        visible="<%=item.isSystemItem()%>" 
422                      />
423                    </div>
424                  </div>
425                </tbl:header>
426                <tbl:cell column="name"><div 
427                  class="link table-item"
428                  data-item-id="<%=itemId %>"
429                  data-no-edit="<%=writePermission ? 0 : 1 %>"
430                  tabindex="0" 
431                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
432                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
433                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
434                <tbl:cell column="systemId"><%=HTML.encodeTags(item.getSystemId())%></tbl:cell>
435                <tbl:cell column="quota"
436                  ><base:propertyvalue 
437                    item="<%=item%>" 
438                    property="quota"
439                    enableEditLink="<%=mode.hasEditLink()%>" 
440                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
441                  /></tbl:cell>
442                <tbl:cell column="isDefault"><%=item.isDefault() ? "yes" : "no" %></tbl:cell>
443                <tbl:cell column="hiddenMembers"><%=item.hasHiddenMembers() ? "yes" : "no" %></tbl:cell>
444                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
445                <tbl:cell column="groups">
446                  <%
447                  groupQuery.setParameter("group", itemId, Type.INT);
448                  try
449                  {
450                    String separator = "";
451                    for (Group g : groupQuery.list(dc))
452                    {
453                      out.write(separator);
454                      if (mode.hasPropertyLink())
455                      {
456                        out.write(Base.getLinkedName(ID, g, false, mode.hasEditLink()));
457                      }
458                      else
459                      {
460                        out.write(HTML.encodeTags(g.getName()));
461                      }
462                      separator = ", ";
463                    }
464                  }
465                  catch (Throwable t)
466                  {
467                    %>
468                    <div class="error"><%=t.getMessage()%></div>
469                    <%
470                  }
471                  %>
472                </tbl:cell>
473                <tbl:cell column="users">
474                  <%
475                  userQuery.setParameter("group", itemId, Type.INT);
476                  try
477                  {
478                    String separator = "";
479                    for (User u : userQuery.list(dc))
480                    {
481                      out.write(separator);
482                      if (mode.hasPropertyLink())
483                      {
484                        out.write(Base.getLinkedName(ID, u, false, mode.hasEditLink()));
485                      }
486                      else
487                      {
488                        out.write(HTML.encodeTags(u.getName()));
489                      }
490                      separator = ", ";
491                    }
492                  }
493                  catch (Throwable t)
494                  {
495                    %>
496                    <div class="error"><%=t.getMessage()%></div>
497                    <%
498                  }
499                  %>
500                </tbl:cell>
501                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
502                  <tbl:cell column="xt-columns" />
503                </tbl:xt-cells>
504              </tbl:row>
505              <%
506              }
507            }
508          if (numListed == 0)
509          {
510            %>
511            <tbl:panel subclass="bg-filled-50">
512              <div class="messagecontainer note">
513              <%=groups == null || groups.getTotalCount() == 0 ? "No groups were found" : "No groups on this page. Please select another page!" %>
514              </div>
515            </tbl:panel>
516            <%
517          }
518          %>
519        </tbl:rows>
520      </tbl:data>
521    </tbl:table>
522    </div>
523   
524    <base:buttongroup subclass="dialogbuttons">
525      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
526      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
527      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
528    </base:buttongroup>
529   
530  </base:body>
531  </base:page>
532  <%
533}
534finally
535{
536  if (groups != null) groups.close();
537  if (dc != null) dc.close();
538}
539%>
Note: See TracBrowser for help on using the repository browser.