#import koji
#from kojiweb import util

#include "includes/header.chtml"

  <div class="pageHeader">$welcomeMessage</div>
  
  <div class="dataHeader noPaginate" id="buildlist">#if $user then 'Your ' else ''#Recent Builds</div>
  <table class="data-list">
    <tr class="list-header">
      <th>ID $util.sortImage(self, 'id')</th>
      <th>NVR</th>
      #if not $user
      <th>Built by</th>
      #end if
      <th>Finished</th>
      <th>State</th>
    </tr>
    #for $build in $builds
    <tr class="$util.rowToggle($self)">
      #set $stateName = $util.stateName($build.state)
      <td>$build.build_id</td>
      <td><a href="buildinfo?buildID=$build.build_id">$build.nvr</a></td>
      #if not $user
      <td class="user-$build.owner_name"><a href="userinfo?userID=$build.owner_id">$build.owner_name</a></td>
      #end if
      <td>$util.formatTime($build.completion_time)</td>
      <td class="$stateName">$util.stateImage($build.state)</td>
    </tr>
    #end for
    #if not $builds
    <tr class="row-odd">
      <td colspan="3">No builds</td>
    </tr>
    #end if
  </table>

  <br/>
  
  <div class="dataHeader noPaginate" id="tasklist">#if $user then 'Your ' else ''#Recent Tasks</div>
  <table class="data-list">
    <tr class="list-header">
      <th>ID $util.sortImage($self, 'id')</th>
      <th>Type</th>
      #if not $user
      <th>Owner</th>
      #end if
      <th>Arch</th>
      <th>Finished</th>
      <th>State</th>
    </tr>
    #for $task in $tasks
    #set $scratch = $util.taskScratchClass($task)
    <tr class="$util.rowToggle($self) $scratch">
      #set $state = $util.taskState($task.state)
      <td>$task.id</td>
      <td><a href="taskinfo?taskID=$task.id" class="task$state" title="$state">$koji.taskLabel($task)</a></td>
      #if not $user
      <td class="user-$task.owner_name">
        #if $task.owner_type == $koji.USERTYPES['HOST']
        <a href="hostinfo?userID=$task.owner">$task.owner_name</a>
        #else
        <a href="userinfo?userID=$task.owner">$task.owner_name</a>
        #end if
      </td>
      #end if
      <td>$task.arch</td>
      <td>$util.formatTime($task.completion_time)</td>
      <td class="task$state">$util.imageTag($state)</td>
    </tr>
    #end for
    #if not $tasks
      <tr class="row-odd">
        <td colspan="5">No tasks</td>
      </tr>
    #end if
  </table>

  #if $user
  <br/>

  <div class="dataHeader" id="packagelist">Your Packages</div>
  <table class="data-list">
    <tr>
      <td class="paginate" colspan="3">
        #if $len($packagePages) > 1
        <form class="pageJump" action="">
          Page:
          <select onchange="javascript: window.location = 'index?packageStart=' + this.value * $packageRange + '$util.passthrough($self, 'packageOrder', 'buildOrder', 'buildStart', 'taskOrder', 'taskStart')#packagelist';">
            #for $pageNum in $packagePages
            <option value="$pageNum"#if $pageNum == $packageCurrentPage then ' selected="selected"' else ''#>#echo $pageNum + 1#</option>
            #end for
          </select>
        </form>
        #end if
        #if $packageStart > 0
        <a href="index?packageStart=#echo $packageStart - $packageRange #$util.passthrough($self, 'packageOrder', 'buildOrder', 'buildStart', 'taskOrder', 'taskStart')#packagelist">&lt;&lt;&lt;</a>
        #end if
        #if $totalPackages != 0
        <strong>Package #echo $packageStart + 1 # through #echo $packageStart + $packageCount # of $totalPackages</strong>
        #end if
        #if $packageStart + $packageCount < $totalPackages
        <a href="index?packageStart=#echo $packageStart + $packageRange#$util.passthrough($self, 'packageOrder', 'buildOrder', 'buildStart', 'taskOrder', 'taskStart')#packagelist">&gt;&gt;&gt;</a>
        #end if
      </td>
    </tr>
    <tr class="list-header">
      <th><a href="index?packageOrder=$util.toggleOrder($self, 'package_name', 'packageOrder')$util.passthrough($self, 'buildOrder', 'buildStart', 'taskOrder', 'taskStart')#packagelist">Name</a> $util.sortImage($self, 'package_name', 'packageOrder')</th>
      <th><a href="index?packageOrder=$util.toggleOrder($self, 'tag_name', 'packageOrder')$util.passthrough($self, 'buildOrder', 'buildStart', 'taskOrder', 'taskStart')#packagelist">Tag</a> $util.sortImage($self, 'tag_name', 'packageOrder')</th>
      <th><a href="index?packageOrder=$util.toggleOrder($self, 'blocked', 'packageOrder')$util.passthrough($self, 'buildOrder', 'buildStart', 'taskOrder', 'taskStart')#packagelist">Included?</a> $util.sortImage($self, 'blocked', 'packageOrder')</th>
    </tr>
    #for $package in $packages
    <tr class="$util.rowToggle($self)">
      <td><a href="packageinfo?packageID=$package.package_id">$package.package_name</a></td>
      <td><a href="taginfo?tagID=$package.tag_id">$package.tag_name</a></td>
      #set $included = $package.blocked and 'no' or 'yes'
      <td>$util.imageTag($included)</td>
    </tr>
    #end for
    #if $totalPackages == 0
    <tr class="row-odd">
      <td colspan="3">No packages</td>
    </tr>
    #end if
  </table>
  
  <br/>
  
  <div class="dataHeader" id="notificationlist">Your Notifications</div>
  <table class="data-list">
    <tr>
      <td colspan="5"></td>
    </tr>
    <tr class="list-header">
      <th>Package</th>
      <th>Tag</th>
      <th>Type</th>
      <th></th>
      <th></th>
    </tr>
    #for $notif in $notifs
    <tr class="$util.rowToggle($self)">
      <td>#if $notif.package then $notif.package.name else 'all'#</td>
      <td>#if $notif.tag then $notif.tag.name else 'all'#</td>
      <td>#if $notif.success_only then 'success only' else 'all'#</td>
      <td><a href="notificationedit?notificationID=$notif.id$util.authToken($self)">edit</a></td>
      <td><a href="notificationdelete?notificationID=$notif.id$util.authToken($self)">delete</a></td>
    </tr>
    #end for
    #if $len($notifs) == 0
    <tr class="row-odd">
      <td colspan="5">No notifications</td>
    </tr>
    #end if
  </table>

  <br/>
  <a href="notificationcreate$util.authToken($self, first=True)">Add a Notification</a>
  #end if
    
#include "includes/footer.chtml"
