Ignore:
Timestamp:
Aug 21, 2009, 12:15:11 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

References #108: Logging the change history of an item

Added "Changed items" tab to the job popup that makes it possible to show all changes made by that job.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/views/jobs/view_job.jsp

    r4890 r5073  
    3939  import="net.sf.basedb.core.Path"
    4040  import="net.sf.basedb.core.User"
     41  import="net.sf.basedb.core.ChangeHistory"
     42  import="net.sf.basedb.core.ItemResultIterator"
    4143  import="net.sf.basedb.core.ItemQuery"
    4244  import="net.sf.basedb.core.ItemResultList"
     
    4547  import="net.sf.basedb.core.PluginConfiguration"
    4648  import="net.sf.basedb.core.ParameterInfo"
     49  import="net.sf.basedb.core.query.Orders"
     50  import="net.sf.basedb.core.query.Hql"
    4751  import="net.sf.basedb.core.plugin.GuiContext"
    4852  import="net.sf.basedb.core.plugin.Plugin"
     
    5155  import="net.sf.basedb.plugins.util.Parameters"
    5256  import="net.sf.basedb.clients.web.Base"
     57  import="net.sf.basedb.clients.web.ChangeHistoryUtil"
    5358  import="net.sf.basedb.clients.web.util.HTML"
    5459  import="net.sf.basedb.util.Values"
     
    6873  private static final Item itemType = Item.JOB;
    6974  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
     75
     76  private String getItemName(BasicItem item)
     77  {
     78    String itemName = "";
     79    if (item instanceof File)
     80    {
     81      itemName = ((File)item).getPath().toString();
     82    }
     83    else if (item instanceof Nameable)
     84    {
     85      itemName = ((Nameable)item).getName();
     86    }
     87    else
     88    {
     89      itemName = item.toString();
     90    }
     91    return itemName;
     92  }
    7093%>
    7194<%
     
    153176  }
    154177  %>
    155 
    156178  <base:page type="popup" title="<%=title%>">
    157   <base:head scripts="tabcontrol.js" styles="tabcontrol.css,progressbar.css">
     179  <base:head scripts="tabcontrol.js,table.js" styles="tabcontrol.css,progressbar.css,table.css">
    158180  <script language="JavaScript">
    159181  function autoUpdate()
     
    409431                if (value instanceof BasicItem)
    410432                {
    411                   BasicItem item = (BasicItem)value;
    412                   String itemName = "";
    413                   if (item instanceof File)
    414                   {
    415                     itemName = ((File)item).getPath().toString();
    416                   }
    417                   else if (item instanceof Nameable)
    418                   {
    419                     itemName = ((Nameable)item).getName();
    420                   }
    421                   else
    422                   {
    423                     itemName = item.toString();
    424                   }
    425                   sb.append(HTML.encodeTags(itemName));
     433                  sb.append(HTML.encodeTags(getItemName((BasicItem)value)));
    426434                }
    427435                else if (value instanceof Date)
     
    494502                  if (value instanceof BasicItem)
    495503                  {
    496                     BasicItem item = (BasicItem)value;
    497                     String itemName = "";
    498                     if (item instanceof File)
    499                     {
    500                       itemName = ((File)item).getPath().toString();
    501                     }
    502                     else if (item instanceof Nameable)
    503                     {
    504                       itemName = ((Nameable)item).getName();
    505                     }
    506                     else
    507                     {
    508                       itemName = item.toString();
    509                     }
    510                     sb.append(HTML.encodeTags(itemName));
     504                    sb.append(HTML.encodeTags(getItemName((BasicItem)value)));
    511505                  }
    512506                  else if (value instanceof Date)
     
    542536       
    543537      </t:tab>
     538     
     539      <t:tab id="changes" title="Changed items"
     540        tooltip="Display a log of all modifications made by this job"
     541        visible="<%=!autoUpdate && ChangeHistoryUtil.showChangeHistoryTab(sc) %>">
     542        <%
     543        ItemQuery<ChangeHistory> query = ChangeHistory.getChangesBy(job);
     544        query.order(Orders.asc(Hql.property("id")));
     545        ItemResultIterator<ChangeHistory> changes = query.iterate(dc);
     546        int numChanges = 0;
     547        %>
     548        <tbl:table id="history" clazz="itemlist" columns="all">
     549          <tbl:columndef id="changeType" title="Change type" />
     550          <tbl:columndef id="item" title="Item" />
     551          <tbl:columndef id="info" title="Info" />
     552         
     553          <tbl:data>
     554            <tbl:columns>
     555            </tbl:columns>
     556            <tbl:rows>
     557            <%
     558            while (changes.hasNext())
     559            {
     560              numChanges++;
     561              ChangeHistory change = changes.next();
     562              %>
     563              <tbl:row>
     564                <tbl:cell column="changeType"><%=change.getChangeType()%> <%=change.getItemType()%></tbl:cell>
     565                <tbl:cell column="item"><%=ChangeHistoryUtil.getItem(dc, change, false, false)%></tbl:cell>
     566                <tbl:cell column="info"><%=HTML.encodeTags(change.getChangeInfo())%></tbl:cell>
     567              </tbl:row>
     568              <%
     569            }
     570            %>
     571            </tbl:rows>
     572          </tbl:data>
     573          <%
     574          if (numChanges == 0)
     575          {
     576            %>
     577            <tbl:panel>
     578            No log entries found for this job. NOTE! This job may have made
     579            other changes that are not recorded by the logging mechanism.
     580            </tbl:panel>
     581            <%
     582          }
     583          %>
     584        </tbl:table>
     585       
     586      </t:tab>
     587     
    544588      </t:tabcontrol>
    545589 
Note: See TracChangeset for help on using the changeset viewer.