<project-header class="top-header"></project-header>
  <project-page>

  <!-- Middle section -->
  <div class="middle-section">
    <div id="scrollable-content" class="middle-container has-scroll">
      <div class="middle-header header-light">
        <div class="container-fluid">
          <div class="page-header page-header-bleed-right page-header-bleed-left">
            <h1>Builds</h1>
          </div>
          <alerts alerts="alerts"></alerts>
          <div ng-if="!renderOptions.showGetStarted" class="data-toolbar">
            <div class="data-toolbar-filter">
              <project-filter></project-filter>
            </div>
          </div>
        </div>
      </div><!-- /middle-header-->
      <div class="middle-content">
        <div class="container-fluid">
          <div class="row">
            <div class="col-md-12 gutter-top">
              <table class="table table-bordered table-hover table-mobile">
                <thead>
                  <tr>
                    <th>Name</th>
                    <th>Last Build</th>
                    <th>Status</th>
                    <th>Created</th>
                    <th>Type</th>
                    <th>Source</th>
                  </tr>
                </thead>
                <tbody ng-if="((buildsByBuildConfig | hashSize) == 0)">
                  <tr><td colspan="6"><em>{{emptyMessage}}</em></td></tr>
                </tbody>
                <tbody ng-repeat="(buildConfigName, buildConfigBuilds) in buildsByBuildConfig">
                  <!-- Build config with no builds-->
                  <tr ng-if="(buildConfigBuilds | hashSize) == 0">
                    <td data-title="Name">
                      <a href="{{buildConfigName | navigateResourceURL : 'BuildConfig' : projectName}}">{{buildConfigName}}</a>
                    </td>
                    <td data-title="Last Build"><em>No builds</em></td>
                    <td class="hidden-xs">&nbsp;</td>
                    <td class="hidden-xs">&nbsp;</td>
                    <td data-title="Type">{{buildConfigs[buildConfigName].spec.strategy.type}}</td>
                    <td data-title="Source"><span ng-if="buildConfigs[buildConfigName].spec.source.type == 'Git'" ng-bind-html='buildConfigs[buildConfigName].spec.source.git.uri | githubLink : buildConfigs[buildConfigName].spec.source.git.ref : buildConfigs[buildConfigName].spec.source.contextDir | linky'></span></td>
                  </tr>
                  <!-- Build config with builds, or builds whose build config has since been deleted -->
                  <!-- We only show the first build from a build config for now-->
                  <tr ng-repeat="build in buildConfigBuilds | orderObjectsByDate : true | limitTo : 1" ng-if="buildConfigs[buildConfigName] || !unfilteredBuildConfigs[buildConfigName]">
                    <td data-title="Name">
                      <a ng-if="buildConfigName" href="{{buildConfigName | navigateResourceURL : 'BuildConfig' : projectName}}">{{buildConfigName}}</a>
                      <span ng-if="buildConfigs && buildConfigName && !buildConfigs[buildConfigName]" class="pficon pficon-warning-triangle-o" data-toggle="tooltip" title="This build config no longer exists" style="cursor: help;"></span>
                      <span ng-if="buildConfigName == ''"><em>none</em></span>
                    </td>
                    <td data-title="Last Build">
                      <!-- Build number and link -->
                      <span ng-if="(build | annotation : 'buildNumber') && buildConfigName">
                        <a ng-href="{{build | navigateResourceURL}}">#{{build | annotation : 'buildNumber'}}</a>
                      </span>
                      <span ng-if="!(build | annotation : 'buildNumber') && buildConfigName">
                        <a ng-href="{{build | navigateResourceURL}}">{{build.metadata.name}}</a>
                      </span>
                      <span ng-if="buildConfigName == ''">
                        <a ng-href="{{build | navigateResourceURL}}">{{build.metadata.name}}</a>
                      </span>
                    </td>
                    <td data-title="Status">
                      <div row class="status">
                        <status-icon status="build.status.phase" disable-animation></status-icon>
                        <span flex>
                          <span>{{build.status.phase}}</span>
                          <!-- Build duration -->
                          <span ng-switch="build.status.phase" class="hide-ng-leave">
                            <span ng-switch-when="Complete"> in {{(build.status.startTimestamp || build.metadata.creationTimestamp) | duration : build.status.completionTimestamp}}</span>
                            <span ng-switch-when="Failed">after <span ng-if="!build.status.startTimestamp">waiting </span>{{(build.status.startTimestamp || build.metadata.creationTimestamp) | duration : build.status.completionTimestamp}}</span>
                            <span ng-switch-when="Cancelled"> after {{(build.status.startTimestamp || build.metadata.creationTimestamp) | duration : build.status.completionTimestamp}}</span>
                            <span ng-switch-when="Running"> for <duration-until-now timestamp="build.status.startTimestamp"></duration-until-now></span>
                            <span ng-switch-when="New">, waiting for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
                            <span ng-switch-when="Pending"> for <duration-until-now timestamp="build.metadata.creationTimestamp"></duration-until-now></span>
                            <span ng-switch-default>
                              <span ng-if="build.status.startTimestamp">, finished in {{build.status.startTimestamp | duration : build.status.completionTimestamp}}</span>
                              <span ng-if="!build.status.startTimestamp">, waited for {{build.metadata.creationTimestamp | duration : build.status.completionTimestamp}}</span>
                            </span>
                          </span>
                        </span>
                      </div>
                    </td>
                    <td data-title="Created">
                      <relative-timestamp timestamp="build.metadata.creationTimestamp"></relative-timestamp>
                      <span>- {{build.metadata.creationTimestamp | date : 'short'}}</span>
                    </td>
                    <td data-title="Type">{{build.spec.strategy.type}}</td>
                    <td data-title="Source">
                      <span ng-if="build.spec.source">
                        <span ng-if="build.spec.source.type == 'Git'" ng-bind-html='build.spec.source.git.uri | githubLink : build.spec.source.git.ref : build.spec.source.contextDir | linky' class="word-break"></span>
                      </span>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div><!-- /col-* -->
          </div>
        </div>
      </div><!-- /middle-content -->
    </div><!-- /middle-container -->
  </div><!-- /middle-section -->
  </project-page>
