{{!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
}}

<div id="hive-job-details">

  {{#if controller.loaded}}
    <!-- Top Bar -->
    <div class="top-bar">
      {{#link-to "jobs"}}{{t menu.item.jobs}}{{/link-to}} > {{view.content.name}}
      <a {{action "toggleShowQuery" target="view"}} href="#" id="toggle-query">{{view.toggleShowQueryText}}</a>

      <div class="pull-right">{{t apps.item.dag.type}}: <span class="label label-info">{{view.content.jobType}}</span></div>
      <div class="alert alert-info query-info">
        <table id="job-more-details-table">
          <tr>
            <td>{{t jobs.hive.query}}</td>
            <td>{{view.content.queryText}}</td>
          </tr>
          <tr>
            <td>{{t jobs.hive.yarnApplication}}</td>
            <td><a target="_blank" {{bind-attr href=view.content.tezDag.yarnApplicationLink}}>{{view.content.tezDag.yarnApplicationId}}</a></td>
          </tr>
          <tr>
            <td>{{t jobs.hive.stages}}</td>
            <td>
              <ol>
                {{#each stage in view.content.stages}}
                  <li>{{stage.id}}{{stage.description}}.</li>
                {{/each}}
              </ol>
            </td>
          </tr>
        </table>
      </div>
    </div>

    <!-- Sections -->
    <div class="row-fluid">
      <div class="span12 sections">
        <!-- Section LHS -->
        <div id="tez-dag-lhs" {{bind-attr class="view.isGraphMaximized:span12:span6 :sections-lhs"}}>
          <div id="tez-dag-section" class="box">
            <div id="tez-dag-section-top-bar"> &nbsp;
              {{t jobs.hive.tez.dag.summary.metric}}
              <div class="btn-group display-inline-block">
                <button class="btn dropdown-toggle"  data-toggle="dropdown">
                  {{view.summaryMetricTypeDisplay}}
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                  <!-- dropdown menu links -->
                  {{#each type in view.summaryMetricTypesDisplay}}
                    <li>
                      <a {{bind-attr title="type"}}
                         href="#" {{action "doSelectSummaryMetricType" type target="view"}}>{{type}}</a>
                    </li>
                  {{/each}}
                </ul>
              </div>
              <div id="tez-dag-section-top-bar-actions" class="pull-right">
                <div class="btn-group">
                  <a id="tez-dag-zoom-in-button" {{bind-attr class="view.canGraphZoomIn::disabled :btn"}} {{action "doGraphZoomIn" target="view"}}>
                    <i class="icon-zoom-in"></i>
                  </a>
                  <a id="tez-dag-zoom-out-button" {{bind-attr class="view.canGraphZoomOut::disabled :btn"}} {{action "doGraphZoomOut" target="view"}}>
                    <i class="icon-zoom-out"></i>
                  </a>
                  {{#if view.isGraphMaximized}}
                    <a id="tez-dag-resize-small-button" class="btn" {{action "doGraphMinimize" target="view"}}>
                      <i class="icon-resize-small"></i>
                    </a>
                  {{else}}
                    <a id="tez-dag-resize-full-button" class="btn" {{action "doGraphMaximize" target="view"}}>
                      <i class="icon-resize-full"></i>
                    </a>
                  {{/if}}
                </div>
              </div>
            </div>
            <div id="tez-dag-section-body">
              {{view App.MainHiveJobDetailsTezDagView
                contentBinding="view.content"
                tezDagBinding="view.content.tezDag"
                selectedVertexBinding="view.selectedVertex"
                summaryMetricTypeBinding="view.summaryMetricType"
                zoomScaleBinding="view.zoomScale"
                zoomScaleFromBinding="view.zoomScaleFrom"
                zoomScaleToBinding="view.zoomScaleTo"
              }}
            </div>
          </div>
        </div>

        <!-- Section RHS -->
        <div id="tez-vertices-rhs" {{bind-attr class="view.isGraphMaximized:hidden:span6 :sections-rhs"}}>

          <!-- Section RHS Vertices -->
          <div id="tez-vertices-table-section">
            <div id="tez-vertices-table-container" class="section">
              <table class="table table-hover table-bordered table-striped">
                {{#view App.MainHiveJobDetailsVerticesTableView
                  contentBinding="view.sortedVertices"
                  doSelectVertexBinding="view.doSelectVertex"
                  actionDoSelectVertexBinding="view.actionDoSelectVertex"
                  selectedVertexBinding="view.selectedVertex"
                }}
                  <thead>
                    {{#view view.sortView contentBinding="view.content"}}
                      {{view view.parentView.nameSort}}
                      {{view view.parentView.tasksSort}}
                      {{view view.parentView.inputSort}}
                      {{view view.parentView.outputSort}}
                      {{view view.parentView.durationSort}}
                    {{/view}}
                  </thead>
                  <tbody>
                    {{#each vertex in view.content}}
                    <tr {{bind-attr class="vertex.isSelected:info"}}>
                      <td>
                        <a {{bind-attr title="vertex.name"}} {{action "actionDoSelectVertex" vertex target="view.parentView"}}>{{vertex.name}}</a>
                      </td>
                      <td>{{vertex.tasksNumber}}</td>
                      <td>{{vertex.totalReadBytesDisplay}}</td>
                      <td>{{vertex.totalWriteBytesDisplay}}</td>
                      <td>{{vertex.durationDisplay}}</td>
                    </tr>
                    {{/each}}
                  </tbody>
                {{/view}}
              </table>
            </div>
          </div>

          <!-- Section RHS Vertex -->
          {{#if view.selectedVertex}}
            <div id="section tez-vertex-details-section">
              <div class="box">
                <div class="box-header">
                  <h4>{{view.selectedVertex.name}}</h4>
                </div>
                <div id="tez-vertex-details-section-body">
                  <table class="table no-borders table-condensed">
                    <tr>
                      <td>{{t common.status}}</td>
                      <td>{{view.selectedVertexIODisplay.status}}</td>
                      <td></td>
                    </tr>
                    <tr>
                      <td>{{t common.time.start}}</td>
                      <td>{{view.selectedVertexIODisplay.started}}</td>
                      <td></td>
                    </tr>
                    <tr>
                      <td>{{t common.time.end}}</td>
                      <td>{{view.selectedVertexIODisplay.ended}}</td>
                      <td></td>
                    </tr>
                    <tr>
                      <td>{{t jobs.hive.tez.tasks}}</td>
                      <td>{{view.selectedVertex.tasksCount}}</td>
                      <td></td>
                    </tr>
                    <tr>
                      <td>{{t jobs.hive.tez.hdfs}}</td>
                      <td>{{view.selectedVertexIODisplay.hdfs.read.ops}}
                        / {{view.selectedVertexIODisplay.hdfs.read.bytes}}</td>
                      <td>{{view.selectedVertexIODisplay.hdfs.write.ops}}
                        / {{view.selectedVertexIODisplay.hdfs.write.bytes}}</td>
                    </tr>
                    <tr>
                      <td>{{t jobs.hive.tez.localFiles}}</td>
                      <td>{{view.selectedVertexIODisplay.file.read.ops}}
                        / {{view.selectedVertexIODisplay.file.read.bytes}}</td>
                      <td>{{view.selectedVertexIODisplay.file.write.ops}}
                        / {{view.selectedVertexIODisplay.file.write.bytes}}</td>
                    </tr>
                    <tr>
                      <td>{{t jobs.hive.tez.spilledRecords}}</td>
                      <td>{{view.selectedVertex.spilledRecords}}</td>
                    </tr>
                    {{#if view.selectedVertexIODisplay.records.read}}
                      <tr>
                        <td>{{t jobs.hive.tez.records}}</td>
                        <td>{{view.selectedVertexIODisplay.records.read}}</td>
                        <td>{{view.selectedVertexIODisplay.records.write}}</td>
                      </tr>
                    {{/if}}
                  </table>
                </div>
              </div>
            </div>
          {{/if}}
        </div>
      </div>
    </div>
  {{else}}
    <div class="alert alert-info">
      <h4>{{t app.loadingPlaceholder}}</h4>
    </div>
  {{/if}}
</div>
