source: trunk/www/common/history/list_history.jsp @ 5048

Last change on this file since 5048 was 5048, checked in by Nicklas Nordborg, 14 years ago

References #108: Logging the change history of an item

  • Added list and view pages for the change history
  • The biosource view page is used as a prototype
  • Made it possible to disable the "Change history" with setting in base.config
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.4 KB
Line 
1<%-- $Id: list_history.jsp 5048 2009-08-17 07:25:22Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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 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.BasicItem"
30  import="net.sf.basedb.core.ChangeHistory"
31  import="net.sf.basedb.core.Permission"
32  import="net.sf.basedb.core.Nameable"
33  import="net.sf.basedb.core.ItemContext"
34  import="net.sf.basedb.core.ItemQuery"
35  import="net.sf.basedb.core.ItemResultIterator"
36  import="net.sf.basedb.core.PermissionDeniedException"
37  import="net.sf.basedb.core.PluginDefinition"
38  import="net.sf.basedb.core.query.Orders"
39  import="net.sf.basedb.core.query.Hql"
40  import="net.sf.basedb.core.plugin.GuiContext"
41  import="net.sf.basedb.core.plugin.Plugin"
42  import="net.sf.basedb.core.log.ChangeType"
43  import="net.sf.basedb.util.Values"
44  import="net.sf.basedb.util.Enumeration"
45  import="net.sf.basedb.util.formatter.Formatter"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.ModeInfo"
48  import="net.sf.basedb.clients.web.ChangeHistoryUtil"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
51  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
52  import="net.sf.basedb.clients.web.extensions.JspContext"
53  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
54  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
55  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
56  import="java.util.List"
57  import="java.util.Date"
58  import="java.util.Map"
59%>
60<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
61<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
62<%!
63  private static final Item itemType = Item.CHANGEHISTORY;
64  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
65%>
66<%
67final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
68final String ID = sc.getId();
69final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
70
71final Item sourceType = Item.valueOf(request.getParameter("source_type"));
72final int sourceId = Values.getInt(request.getParameter("source_id"));
73final float scale = Base.getScale(sc);
74final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
75final String callback = request.getParameter("callback");
76final String title = mode.generateTitle("history entry", "history entries");
77final DbControl dc = sc.newDbControl();
78ItemResultIterator<ChangeHistory> history = null;
79
80try
81{
82  final BasicItem source = sourceType.getById(dc, sourceId); 
83  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
84  try
85  {
86    final ItemQuery<ChangeHistory> query = 
87      Base.getConfiguredQuery(dc, cc, true, ChangeHistory.getHistoryOf(source), mode);
88    history = query.iterate(dc);
89    //cc.setMessage(query.toString());
90  }
91  catch (Throwable t)
92  {
93    cc.setMessage(t.getMessage());
94    t.printStackTrace();
95  }
96  Formatter<Date> dateFormatter = FormatterFactory.getDateTimeFormatter(sc);
97  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
98  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
99  int numListed = 0;
100  %>
101  <base:page type="popup">
102  <base:head scripts="table.js" styles="table.css">
103  </base:head>
104  <base:body style="padding: 0px; background: #E0E0E0">
105    <script language="JavaScript">
106    var submitPage = 'index.jsp';
107    var formId = 'history';
108    function viewItem(itemId)
109    {
110      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false, '&source_id=<%=sourceId%>&source_type=<%=sourceType.name()%>');
111    }
112    function itemOnClick(evt, itemId)
113    {
114      viewItem(itemId);
115    }
116
117    function configureColumns()
118    {
119      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
120    }
121    function presetOnChange()
122    {
123      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
124    }
125    function returnSelected()
126    {
127      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
128      window.close();
129    }
130    function runPlugin(cmd)
131    {
132      Table.submitToPopup(formId, cmd, 740, 540);
133    }
134    </script>
135    <%
136    if (cc.getMessage() != null)
137    {
138      %>
139      <div class="error"><%=cc.getMessage()%></div>
140      <%
141      cc.setMessage(null);
142    }
143    %>
144    <tbl:table 
145      id="history" 
146      clazz="itemlist" 
147      columns="<%=cc.getSetting("columns")%>"
148      sortby="<%=cc.getSortProperty()%>" 
149      direction="<%=cc.getSortDirection()%>"
150      title="<%=title%>"
151      action="index.jsp"
152      sc="<%=sc%>"
153      item="<%=itemType%>"
154      >
155      <tbl:hidden 
156        name="source_id"
157        value="<%=String.valueOf(sourceId)%>" 
158      />
159      <tbl:hidden 
160        name="source_type" 
161        value="<%=sourceType.name()%>" 
162      />
163      <tbl:columndef 
164         id="id"
165        clazz="uniquecol"
166         property="id"
167         datatype="int"
168         title="ID"
169         sortable="true" 
170         filterable="true"
171         exportable="true"
172      />
173      <tbl:columndef 
174        id="time"
175        property="$hst.time"
176        exportproperty="changeHistory.time"
177        datatype="date"
178        title="Time"
179        sortable="true" 
180        filterable="true"
181        exportable="true"
182        show="always" 
183      />
184      <%
185      Enumeration<String, String> types = new Enumeration<String, String>();
186      for (ChangeType ct : ChangeType.values())
187      {
188        types.add(Integer.toString(ct.getValue()), ct.toString());
189      }
190      %>
191      <tbl:columndef 
192        id="changeType"
193        property="changeType"
194        datatype="int"
195        title="Type"
196        sortable="true" 
197        filterable="true"
198        exportable="true"
199        enumeration="<%=types%>"
200      />
201      <tbl:columndef 
202        id="user"
203        property="$hst.user.name"
204        exportproperty="changeHistory.user.name"
205        datatype="string"
206        title="User"
207        sortable="true" 
208        filterable="true"
209        exportable="true"
210      />
211      <tbl:columndef 
212        id="session"
213        property="$hst.session.loginTime"
214        exportproperty="changeHistory.session.loginTime"
215        datatype="date"
216        title="Session"
217        sortable="true" 
218        filterable="true"
219        exportable="true"
220      />
221      <tbl:columndef 
222        id="client"
223        property="$hst.client.name"
224        exportproperty="changeHistory.client.name"
225        datatype="string"
226        title="Client"
227        sortable="true" 
228        filterable="true"
229        exportable="true"
230      />
231      <tbl:columndef 
232        id="project"
233        property="$hst.project.name"
234        exportproperty="changeHistory.project.name"
235        datatype="string"
236        title="Project"
237        sortable="true" 
238        filterable="true"
239        exportable="true"
240      />
241      <tbl:columndef 
242        id="plugin"
243        property="$hst.plugin.name"
244        exportproperty="changeHistory.plugin.name"
245        datatype="string"
246        title="Plugin"
247        sortable="true"
248        filterable="true"
249        exportable="true"
250      />
251      <tbl:columndef 
252        id="job"
253        property="$hst.job.name"
254        exportproperty="changeHistory.job.name"
255        datatype="string"
256        title="Job"
257        sortable="true" 
258        filterable="true"
259        exportable="true"
260      />
261      <tbl:columndef 
262        id="changeInfo"
263        property="changeInfo"
264        datatype="string"
265        title="Change info" 
266        sortable="true" 
267        filterable="true" 
268        exportable="true"
269      />
270      <tbl:toolbar
271        visible="<%=mode.hasToolbar()%>"
272        >
273        <tbl:button 
274          image="columns.gif" 
275          onclick="configureColumns()" 
276          title="Columns&hellip;" 
277          tooltip="Show, hide and re-order columns" 
278        />
279        <tbl:button 
280          image="export.gif" 
281          onclick="runPlugin('ExportItems')" 
282          title="Export&hellip;" 
283          tooltip="Export data" 
284          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
285        />
286        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
287          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
288      </tbl:toolbar>
289      <tbl:navigator
290        page="<%=cc.getPage()%>" 
291        rowsperpage="<%=cc.getRowsPerPage()%>" 
292        totalrows="<%=history == null ? 0 : history.getTotalCount()%>" 
293        visible="<%=mode.hasNavigator()%>"
294      />
295      <tbl:data>
296        <tbl:columns>
297        <tbl:presetselector 
298          clazz="columnheader"
299          colspan="3"
300          onchange="presetOnChange()"
301        />
302        </tbl:columns>
303
304        <tr>
305          <tbl:header 
306            clazz="index"
307            >&nbsp;</tbl:header>
308          <tbl:header 
309            clazz="check" 
310            visible="<%=mode.hasCheck()%>"
311            ><base:icon 
312              image="check_uncheck.gif" 
313              tooltip="Check/uncheck all" 
314              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
315            /></tbl:header>
316          <tbl:header 
317            clazz="check" 
318            visible="<%=mode.hasRadio()%>"
319            >&nbsp;</tbl:header>
320          <tbl:header 
321            clazz="icons" 
322            visible="<%=mode.hasIcons()%>"
323            >&nbsp;</tbl:header>
324          <tbl:propertyfilter />
325        </tr>
326         
327          <tbl:rows>
328          <%
329          int index = cc.getPage()*cc.getRowsPerPage();
330          int selectedItemId = cc.getId();
331          if (history != null)
332          {           
333            while (history.hasNext())
334            {
335              ChangeHistory item = history.next();
336              int itemId = item.getId();
337              String tooltip = mode.isSelectionMode() ? 
338                  "Select this item" : "View this item";
339              index++;
340              numListed++;
341              %>
342              <tbl:row>
343                <tbl:header 
344                  clazz="index"
345                  ><%=index%></tbl:header>
346                <tbl:header 
347                  clazz="check" 
348                  visible="<%=mode.hasCheck()%>"
349                  ><input 
350                    type="checkbox" 
351                    name="<%=itemId%>" 
352                    value="<%=itemId%>" 
353                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
354                  ></tbl:header>
355                <tbl:header 
356                  clazz="check" 
357                  visible="<%=mode.hasRadio()%>"
358                  ><input 
359                    type="radio" 
360                    name="item_id" 
361                    value="<%=itemId%>" 
362                    <%=selectedItemId == itemId ? "checked" : ""%>
363                  ></tbl:header>
364                <tbl:header 
365                  clazz="icons" 
366                  visible="<%=mode.hasIcons()%>"
367                  >&nbsp;</tbl:header>
368                <tbl:cell column="time"><div class="link" 
369                  onclick="itemOnClick(null, <%=itemId%>)" 
370                  title="<%=tooltip%>"><%=dateFormatter.format(item.getTime())%></div></tbl:cell>
371                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
372                <tbl:cell column="changeType"><%=item.getChangeType()%></tbl:cell>
373                <tbl:cell column="changeInfo"><%=HTML.niceFormat(item.getChangeInfo())%></tbl:cell>
374                <tbl:cell column="user"><%=ChangeHistoryUtil.getUser(dc, item, mode.hasPropertyLink(), mode.hasEditLink())%></tbl:cell>
375                <tbl:cell column="session"><%=ChangeHistoryUtil.getSession(dc, item, mode.hasPropertyLink(), mode.hasEditLink())%></tbl:cell>
376                <tbl:cell column="client"><%=ChangeHistoryUtil.getClient(dc, item, mode.hasPropertyLink(), mode.hasEditLink())%></tbl:cell>
377                <tbl:cell column="project"><%=ChangeHistoryUtil.getProject(dc, item, mode.hasPropertyLink(), mode.hasEditLink())%></tbl:cell>
378                <tbl:cell column="plugin"><%=ChangeHistoryUtil.getPlugin(dc, item, mode.hasPropertyLink(), mode.hasEditLink())%></tbl:cell>
379                <tbl:cell column="job"><%=ChangeHistoryUtil.getJob(dc, item, mode.hasPropertyLink(), mode.hasEditLink())%></tbl:cell>
380              </tbl:row>
381              <%
382              }
383            }
384          %>
385          </tbl:rows>
386      </tbl:data>
387      <%
388      if (numListed == 0)
389      {
390        %>
391        <tbl:panel><%=history == null || history.getTotalCount() == 0 ? "No history entries were found" : "No history entries on this page. Please select another page!" %></tbl:panel>
392        <%
393      }
394      else
395      {
396        %>
397        <tbl:navigator
398          page="<%=cc.getPage()%>" 
399          rowsperpage="<%=cc.getRowsPerPage()%>" 
400          totalrows="<%=history == null ? 0 : history.getTotalCount()%>" 
401          visible="<%=mode.hasNavigator()%>"
402          locked="true"
403        />
404        <%
405      }
406      %>
407    </tbl:table>
408     
409     
410  </base:body>
411  </base:page>
412  <%
413}
414finally
415{
416  if (dc != null) dc.close();
417}
418
419%>
Note: See TracBrowser for help on using the repository browser.