#from kojiweb import util

#include "includes/header.chtml"

#def getID()
  #if $type == 'image'
imageID=$image.id #slurp
  #else
buildrootID=$buildroot.id #slurp
  #end if
#end def

#def getColspan()
  #if $type == 'component'
colspan="3" #slurp
  #elif $type == 'image'
colspan="2" #slurp
  #else
  #pass
  #end if
#end def

  #if $type == 'component'
  <h4>Component RPMs of buildroot <a href="buildrootinfo?buildrootID=$buildroot.id">$util.brLabel($buildroot)</a></h4>
  #elif $type == 'image'
  <h4>RPMs installed in <a href="archiveinfo?archiveID=$image.id">$image.filename</a></h4>
  #else
  <h4>RPMs built in buildroot <a href="buildrootinfo?buildrootID=$buildroot.id">$util.brLabel($buildroot)</a></h4>
  #end if

  <table class="data-list">
    <tr>
      <td class="paginate" $getColspan()>
        #if $len($rpmPages) > 1
        <form class="pageJump" action="">
          Page:
          <select onchange="javascript: window.location = 'rpmlist?$getID()&start=' + this.value * $rpmRange + '$util.passthrough($self, 'order', 'type')';">
            #for $pageNum in $rpmPages
            <option value="$pageNum"#if $pageNum == $rpmCurrentPage then ' selected="selected"' else ''#>#echo $pageNum + 1#</option>
            #end for
          </select>
        </form>
        #end if
        #if $rpmStart > 0
        <a href="rpmlist?$getID()&start=#echo $rpmStart - $rpmRange #$util.passthrough($self, 'order', 'type')">&lt;&lt;&lt;</a>
        #end if
        #if $totalRpms != 0
        <strong>RPMs #echo $rpmStart + 1 # through #echo $rpmStart + $rpmCount # of $totalRpms</strong>
        #end if
        #if $rpmStart + $rpmCount < $totalRpms
        <a href="rpmlist?$getID()&start=#echo $rpmStart + $rpmRange#$util.passthrough($self, 'order', 'type')">&gt;&gt;&gt;</a>
        #end if
      </td>
    </tr>
    <tr class="list-header">
      <th><a href="rpmlist?$getID()&order=$util.toggleOrder($self, 'nvr')$util.passthrough($self, 'type')">NVR</a> $util.sortImage($self, 'nvr')</th>
      #if $type in ['component', 'image']
      <th><a href="rpmlist?$getID()&order=$util.toggleOrder($self, 'external_repo_name')$util.passthrough($self, 'type')">Origin</a> $util.sortImage($self, 'external_repo_name')</th>
      #end if
      #if $type == 'component'
      <th><a href="rpmlist?$getID()&order=$util.toggleOrder($self, 'is_update')$util.passthrough($self, 'type')">Update?</a> $util.sortImage($self, 'is_update')</th>
      #end if
    </tr>
    #if $len($rpms) > 0
    #for $rpm in $rpms
    <tr class="$util.rowToggle($self)">
      #set $epoch = ($rpm.epoch != None and $str($rpm.epoch) + ':' or '')
      <td><a href="rpminfo?rpmID=$rpm.id">$rpm.name-$epoch$rpm.version-$rpm.release.${rpm.arch}.rpm</a></td>
      #if $type in ['component', 'image']
      #if $rpm.external_repo_id == 0
      <td>internal</td>
      #else
      <td><a href="externalrepoinfo?extrepoID=$rpm.external_repo_id">$rpm.external_repo_name</a></td>
      #end if
      #end if
      #if $type == 'component'
      #set $update = $rpm.is_update and 'yes' or 'no'
      <td class="$update">$util.imageTag($update)</td>
      #end if
    </tr>
    #end for
    #else
    <tr class="row-odd">
      <td $getColspan()>No RPMs</td>
    </tr>
    #end if
    <tr>
      <td class="paginate" $getColspan()>
        #if $len($rpmPages) > 1
        <form class="pageJump" action="">
          Page:
          <select onchange="javascript: window.location = 'rpmlist?$getID()&start=' + this.value * $rpmRange + '$util.passthrough($self, 'order', 'type')';">
            #for $pageNum in $rpmPages
            <option value="$pageNum"#if $pageNum == $rpmCurrentPage then ' selected="selected"' else ''#>#echo $pageNum + 1#</option>
            #end for
          </select>
        </form>
        #end if
        #if $rpmStart > 0
        <a href="rpmlist?$getID()&start=#echo $rpmStart - $rpmRange #$util.passthrough($self, 'order', 'type')">&lt;&lt;&lt;</a>
        #end if
        #if $totalRpms != 0
        <strong>RPMs #echo $rpmStart + 1 # through #echo $rpmStart + $rpmCount # of $totalRpms</strong>
        #end if
        #if $rpmStart + $rpmCount < $totalRpms
        <a href="rpmlist?$getID()&start=#echo $rpmStart + $rpmRange#$util.passthrough($self, 'order', 'type')">&gt;&gt;&gt;</a>
        #end if
      </td>
    </tr>
  </table>

#include "includes/footer.chtml"
