#import koji
#from kojiweb import util

#attr _PASSTHROUGH = ['userID', 'tagID', 'packageID', 'order', 'prefix', 'state', 'inherited', 'latest', 'type']

#include "includes/header.chtml"

  <h4>#if $latest then 'Latest ' else ''##if $state != None then $util.stateName($state).capitalize() + ' ' else ''##if $type then $type.capitalize() + ' ' else ''#Builds#if $package then ' of <a href="packageinfo?packageID=%i">%s</a>' % ($package.id, $package.name) else ''##if $prefix then ' starting with "%s"' % $prefix else ''##if $user then ' by <a href="userinfo?userID=%i">%s</a>' % ($user.id, $user.name) else ''##if $tag then ' in tag <a href="taginfo?tagID=%i">%s</a>' % ($tag.id, $tag.name) else ''#</h4>

  <table class="data-list">
    <tr>
      <td colspan="#if $tag then '6' else '5'#">
        <table class="nested">
        <tr><td>
        #if $tag
        <strong>Latest</strong>:
        </td><td>
        <select name="latest" class="filterlist" onchange="javascript: window.location = 'builds?latest=' + this.value + '$util.passthrough_except($self, 'latest')';">
          <option value="1" #if $latest then 'selected="selected"' else ''#>yes</option>
          <option value="0" #if not $latest then 'selected="selected"' else ''#>no</option>
        </select>
        #else
        <strong>State</strong>:
        </td><td>
        <select name="state" class="filterlist" onchange="javascript: window.location = 'builds?state=' + this.value + '$util.passthrough_except($self, 'state')';">
          <option value="all">all</option>
          #for $stateOpt in ['BUILDING', 'COMPLETE', 'FAILED', 'CANCELED']
          <option value="$koji.BUILD_STATES[$stateOpt]" #if $state == $koji.BUILD_STATES[$stateOpt] then 'selected="selected"' else ''#>$stateOpt.lower()</option>
          #end for
        </select>
        #end if
        </td><td>
        <strong>Built by</strong>:
        </td><td>
        <select name="userID" class="filterlist" onchange="javascript: window.location = 'builds?userID=' + this.value + '$util.passthrough_except($self, 'userID')';">
          <option value="" #if not $user then 'selected="selected"' else ''#>everyone</option>
          #if $loggedInUser
          <option value="$loggedInUser.name">me</option>
          #end if
          #for $userOption in $users
          <option value="$userOption.name" #if $userOption.name == ($user and $user.name or None) then 'selected="selected"' else ''#>$userOption.name</option>
          #end for
        </select>
        </td></tr>
        <tr>
        <td>
        <strong>Type</strong>:
        </td>
        <td>
        <select name="type" class="filterlist" onchange="javascript: window.location='builds?type=' + this.value + '$util.passthrough_except($self, 'type')';">
          <option value="all" #if not $type then 'selected="selected"' else ''#>all</option>
          #for $btype in $btypes
          <option value="$btype" #if $type == $btype then 'selected="selected"' else ''#>$btype</option>
          #end for
        </select>
        </td>
        #if $tag
        <td>
        <strong>Inherited</strong>:
        </td><td>
        <select name="inherited" class="filterlist" onchange="javascript: window.location = 'builds?inherited=' + this.value + '$util.passthrough_except($self, 'inherited')';">
          <option value="1" #if $inherited then 'selected="selected"' else ''#>yes</option>
          <option value="0" #if not $inherited then 'selected="selected"' else ''#>no</option>
        </select>
        </td>
        #end if
        </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td class="charlist" colspan="#if $tag then '6' else '5'#">
        #for $char in $chars
        #if $prefix == $char
        <strong>$char</strong>
        #else
        <a href="builds?prefix=$char$util.passthrough_except($self, 'prefix')">$char</a>
        #end if
        | 
        #end for
        #if $prefix
        <a href="builds?${util.passthrough_except($self, 'prefix')[1:]}">all</a>
        #else
        <strong>all</strong>
        #end if
      </td>
    </tr>
    <tr>
      <td class="paginate" colspan="#if $tag then '6' else '5'#">
        #if $len($buildPages) > 1
        <form class="pageJump" action="">
          Page:
          <select onchange="javascript: window.location = 'builds?start=' + this.value * $buildRange + '$util.passthrough_except($self)';">
            #for $pageNum in $buildPages
            <option value="$pageNum"#if $pageNum == $buildCurrentPage then ' selected="selected"' else ''#>#echo $pageNum + 1#</option>
            #end for
          </select>
        </form>
        #end if
        #if $buildStart > 0
        <a href="builds?start=#echo $buildStart - $buildRange #$util.passthrough_except($self)">&lt;&lt;&lt;</a>
        #end if
        #if $totalBuilds != 0
        <strong>Builds #echo $buildStart + 1 # through #echo $buildStart + $buildCount # of $totalBuilds</strong>
        #end if
        #if $buildStart + $buildCount < $totalBuilds
        <a href="builds?start=#echo $buildStart + $buildRange#$util.passthrough_except($self)">&gt;&gt;&gt;</a>
        #end if
      </td>
    </tr>
    <tr class="list-header">
      <th><a href="builds?order=$util.toggleOrder($self, 'build_id')$util.passthrough_except($self, 'order')">ID</a> $util.sortImage($self, 'build_id')</th>
      <th><a href="builds?order=$util.toggleOrder($self, 'nvr')$util.passthrough_except($self, 'order')">NVR</a> $util.sortImage($self, 'nvr')</th>
      #if $tag
      <th><a href="builds?order=$util.toggleOrder($self, 'tag_name')$util.passthrough_except($self, 'order')">Tag</a> $util.sortImage($self, 'tag_name')</th>
      #end if
      <th><a href="builds?order=$util.toggleOrder($self, 'owner_name')$util.passthrough_except($self, 'order')">Built by</a> $util.sortImage($self, 'owner_name')</th>
      <th><a href="builds?order=$util.toggleOrder($self, 'completion_time')$util.passthrough_except($self, 'order')">Finished</a> $util.sortImage($self, 'completion_time')</th>
      <th><a href="builds?order=$util.toggleOrder($self, 'state')$util.passthrough_except($self, 'order')">State</a> $util.sortImage($self, 'state')</th>
    </tr>
    #if $len($builds) > 0
      #for $build in $builds
        <tr class="$util.rowToggle($self)">
          <td>$build.build_id</td>
          <td><a href="buildinfo?buildID=$build.build_id">$koji.buildLabel($build)</a></td>
          #if $tag
          <td><a href="taginfo?tagID=$build.tag_id">$build.tag_name</a></td>
          #end if
          <td class="user-$build.owner_name"><a href="userinfo?userID=$build.owner_id">$build.owner_name</a></td>
          <td>$util.formatTime($build.completion_time)</td>
          #set $stateName = $util.stateName($build.state)
          <td class="$stateName">$util.stateImage($build.state)</td>
        </tr>
      #end for
    #else
      <tr class="row-odd">
        <td colspan="#if $tag then '6' else '5'#">No builds</td>
      </tr>
    #end if
    <tr>
      <td class="paginate" colspan="#if $tag then '6' else '5'#">
        #if $len($buildPages) > 1
        <form class="pageJump" action="">
          Page:
          <select onchange="javascript: window.location = 'builds?start=' + this.value * $buildRange + '$util.passthrough_except($self)';">
            #for $pageNum in $buildPages
            <option value="$pageNum"#if $pageNum == $buildCurrentPage then ' selected="selected"' else ''#>#echo $pageNum + 1#</option>
            #end for
          </select>
        </form>
        #end if
        #if $buildStart > 0
        <a href="builds?start=#echo $buildStart - $buildRange #$util.passthrough_except($self)">&lt;&lt;&lt;</a>
        #end if
        #if $totalBuilds != 0
        <strong>Builds #echo $buildStart + 1 # through #echo $buildStart + $buildCount # of $totalBuilds</strong>
        #end if
        #if $buildStart + $buildCount < $totalBuilds
        <a href="builds?start=#echo $buildStart + $buildRange#$util.passthrough_except($self)">&gt;&gt;&gt;</a>
        #end if
      </td>
    </tr>
  </table>

#include "includes/footer.chtml"
