#from kojiweb import util
#from urllib.parse import quote
#import pprint

#include "includes/header.chtml"

  <h4>Information for tag <a href="taginfo?tagID=$tag.id">$util.escapeHTML($tag.name)</a></h4>

  <table>
    #if $child and 'admin' in $perms
    <tr>
      <th colspan="2"><a href="tagparent?tagID=$child.id&parentID=$tag.id&action=add$util.authToken($self)">Add $util.escapeHTML($tag.name) as parent of $util.escapeHTML($child.name)</a></th>
    </tr>
    #end if
    <tr>
      <th>Name</th><td>$util.escapeHTML($tag.name)</td>
    </tr>
    <tr>
      <th>ID</th><td>$tag.id</td>
    </tr>
    <tr>
      <th>Arches</th><td>$util.escapeHTML($tag.arches)</td>
    </tr>
    <tr>
      <th>Locked</th><td class="$str(not $tag.locked).lower()">#if $tag.locked then 'yes' else 'no'#</td>
    </tr>
    <tr>
      <th>Permission</th><td>#if $tag.perm_id then $allPerms[$tag.perm_id] else 'none'#</td>
    </tr>
    #if $mavenEnabled
    <tr>
      <th>Maven Support?</th><td class="$str($tag.maven_support).lower()">#if $tag.maven_support then 'yes' else 'no'#</td>
    </tr>
    <tr>
      <th>Include All Maven Builds?</th><td class="$str($tag.maven_include_all).lower()">#if $tag.maven_include_all then 'yes' else 'no'#</td>
    </tr>
    #end if
    <tr>
      <th>Inheritance</th>
      <td class="tree">
        <span class="root">$util.escapeHTML($tag.name)</span>
        #set $numParents = $len($inheritance)
        #set $iter = 0
        #set $maxDepth = 0
        #set $TRUNC_DEPTH = 7
        <ul>
          #for $parent in $inheritance
          #set $iter += 1
          #set $nextDepth = ($iter < $numParents and $inheritance[$iter].currdepth or 1)
          #set $depth = $parent.currdepth
          #if $depth > $maxDepth
          #set $maxDepth = $depth
          #end if
          #if $depth == $TRUNC_DEPTH and not $all
          <li><span class="treeBranch"><span class="treeToggle treeLabel">...</span></span></li>
          <li class="hidden">
          #else if $len($tagsByChild[$parent.child_id]) > 1
          <li class="sibling">
          #else
          <li>
          #end if
          #silent $tagsByChild[$parent.child_id].pop()
            <span class="treeBranch">
              <span class="treeLabel">
                <a href="taginfo?tagID=$parent.parent_id">$util.escapeHTML($parent.name)</a>
                #if $depth == 1 and 'admin' in $perms
                <span class="treeLink">(<a href="tagparent?tagID=$tag.id&parentID=$parent.parent_id&action=edit$util.authToken($self)">edit</a>) (<a href="tagparent?tagID=$tag.id&parentID=$parent.parent_id&action=remove$util.authToken($self)">remove</a>)</span>
                #end if
              </span>
            </span>
           #if $nextDepth > $depth
          <ul>
          #else
          </li>
          #end if
          #while $nextDepth < $depth
          </ul>
          </li>
          #set $depth -= 1
          #end while
          #end for
        </ul>
      </td>
    </tr>
    #if $maxDepth >= $TRUNC_DEPTH
    <tr>
      <td colspan="2">
        #if $all
        <a href="taginfo?tagID=$tag.id$util.passthrough($self, 'inherited')">Show abbreviated tree</a>
        #else
        <a href="taginfo?tagID=$tag.id$util.passthrough($self, 'inherited')&all=1">Show full tree</a>
        #end if
      </td>
    </tr>
    #end if
    #if 'admin' in $perms
    <tr>
      <td colspan="2"><a href="tags?childID=$tag.id">Add parent</a></td>
    </tr>
    #end if
    #if $external_repos
    <tr>
      <th>External&nbsp;repos</th>
      <td>
	#for $external_repo in $external_repos
	<a href="externalrepoinfo?extrepoID=$external_repo.external_repo_id">$util.escapeHTML($external_repo.external_repo_name)</a> [$external_repo.merge_mode]
	#if $external_repo.tag_id != $tag.id
	<span class="smaller">(inherited from <a href="taginfo?tagID=$external_repo.tag_id">$util.escapeHTML($external_repo.tag_name)</a>)</span>
	#end if
	<br/>
	#end for
      </td>
    </tr>
    #end if
    <tr>
      <th>Repo&nbsp;created</th>
      <td>
      #if $repo
        <a href="repoinfo?repoID=$repo.id">$util.formatTimeRSS($repo.create_ts)</a>
      #end if
      </td>
    </tr>
    <tr>
      <th>Packages</th>
      <td><a href="packages?blocked=0&tagID=$tag.id">$numPackages</a></td>
    </tr>
    <tr>
      <th>Packages (blocked packages included)</th>
      <td><a href="packages?tagID=$tag.id">$numPackagesBlocked</a></td>
    </tr>
    <tr>
      <th>Builds</th>
      <td><a href="builds?tagID=$tag.id">$numBuilds</a></td>
    </tr>
    <tr>
      <th>Targets building from this tag</th>
      <td>
        #if $len($srcTargets)
        #for $target in $srcTargets
        <a href="buildtargetinfo?name=$quote($target.name)">$util.escapeHTML($target.name)</a><br/>
        #end for
        #else
        No build targets
        #end if
      </td>
    </tr>
    <tr>
      <th>Targets building to this tag</th>
      <td>
        #if $len($destTargets)
        #for $target in $destTargets
        <a href="buildtargetinfo?name=$quote($target.name)">$util.escapeHTML($target.name)</a><br/>
        #end for
        #else
        No build targets
        #end if
      </td>
    </tr>
    #if 'admin' in $perms
    <tr>
      <td colspan="2"><a href="tagedit?tagID=$tag.id$util.authToken($self)">Edit tag</a></td>
    </tr>
    <tr>
      <td colspan="2"><a href="tagdelete?tagID=$tag.id$util.authToken($self)">Delete tag</a></td>
    </tr>
    #end if
    #if $tag.get('extra')
    <tr>
        <th>Extra options:</th>
    </tr>
    #for $key in $tag['extra']
    <tr>
        <th>$key</th>
        <td>$pprint.pformat($tag['extra'][$key])</td>
    </tr>
    #end for
    #end if
  </table>

#include "includes/footer.chtml"
