#*
 * Copyright 2012 LinkedIn Corp.
 *
 * Licensed 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.
*#

<!DOCTYPE html>
<html lang="en">
<head>

  #parse("azkaban/webapp/servlet/velocity/style.vm")
  #parse("azkaban/webapp/servlet/velocity/javascript.vm")
  #parse("azkaban/webapp/servlet/velocity/svgflowincludes.vm")
  <script type="text/javascript" src="${context}/js/raphael.min.js"></script>
  <script type="text/javascript" src="${context}/js/morris.min.js"></script>
  <script type="text/javascript" src="${context}/js/moment.min.js"></script>
  <script type="text/javascript" src="${context}/js/bootstrap-datetimepicker.min.js"></script>

  <script type="text/javascript" src="${context}/js/dust-full-2.2.3.min.js"></script>
  <script type="text/javascript" src="${context}/js/flowstats.js"></script>
  <script type="text/javascript" src="${context}/js/flowstats-no-data.js"></script>

  <script type="text/javascript" src="${context}/js/azkaban/view/flow-execution-list.js"></script>
  <script type="text/javascript" src="${context}/js/azkaban/view/flow-trigger-list.js"></script>
  <script type="text/javascript" src="${context}/js/azkaban/view/flow-execute-dialog.js"></script>
  <script type="text/javascript" src="${context}/js/azkaban/view/flow-stats.js"></script>
  <script type="text/javascript" src="${context}/js/azkaban/view/exflow.js"></script>
  <script type="text/javascript">
    var contextURL = "${context}";
    var currentTime = ${currentTime};
    var timezone = "${timezone}";
    var errorMessage = null;
    var successMessage = null;
    var projectId = "${projectId}";
    var projectName = "${projectName}";
    var flowId = "${flowid}";
    var execId = "${execid}";
    var triggerInstanceId = "${triggerInstanceId}";
  </script>
  <link rel="stylesheet" type="text/css" href="${context}/css/morris.css"/>
  <link rel="stylesheet" type="text/css" href="${context}/css/jquery-ui-1.10.1.custom.css"/>
</head>
<body>

  #set ($current_page="all")
  #set ($show_schedule="false")
  #parse ("azkaban/webapp/servlet/velocity/nav.vm")

  #if ($errorMsg)
    #parse ("azkaban/webapp/servlet/velocity/errormsg.vm")
  #else

  ## Page header

  <div class="az-page-header page-header-bare">
    <div class="container-full" id="flow-status">
      <div class="row">
        <div class="header-title">
          <h1>
            <a href="${context}/executor?execid=${execid}">
              Flow Execution
              #if (${execid} == "-1" || ${execid} == "-2")
                <small>not started <span id="flowStatus">-</span></small>
              #else
                <small>$execid <span id="flowStatus">-</span></small>
              #end
            </a>
          </h1>
        </div>
        <div class="header-control">
          <div class="exflow-stats">
            <div class="col-xs-5">
              <p><strong>Submit User</strong> <span id="submitUser">-</span></p>
              <p><strong>Duration</strong> <span id="duration">-</span></p>
            </div>
            <div class="col-xs-7">
              <p><strong>Start Time</strong> <span id="startTime">-</span></p>
              <p><strong>End Time</strong> <span id="endTime">-</span></p>
            </div>
          </div>
          <div class="clearfix"></div>
        </div>
      </div>
    </div>
  </div>
  <div class="page-breadcrumb">
    <div class="container-full">
      <ol class="breadcrumb">
        <li><a
            href="${context}/manager?project=${projectName}"><strong>Project</strong> $projectName
        </a></li>
        <li><a
            href="${context}/manager?project=${projectName}&flow=${flowid}"><strong>Flow</strong>
          $flowid
        </a></li>
        <li class="active"><strong>Execution</strong> $execid</li>
      </ol>
    </div>
  </div>

  <div class="container-full">

    #parse ("azkaban/webapp/servlet/velocity/alerts.vm")

  ## Tabs and buttons.

    <ul class="nav nav-tabs nav-sm" id="headertabs">
      <li id="graphViewLink"><a href="#graph">Graph</a></li>
      <li id="flowTriggerlistViewLink"><a href="#triggerslist">Flow Trigger List</a></li>
      <li id="jobslistViewLink"><a href="#jobslist">Job List</a></li>
      <li id="flowLogViewLink"><a href="#log">Flow Log</a></li>
      <li id="statsViewLink"><a href="#stats">Stats</a></li>
      #if ($executionExternalLinkURL)
        <li><a id="analyzerButton" href="${executionExternalLinkURL}" class="btn btn-info btn-sm"
               type="button" target="_blank"
               title="Analyze job in ${executionExternalLinkLabel}">${executionExternalLinkLabel}</a>
        </li>
      #end
      <li class="nav-button pull-right">
        <button type="button" id="pausebtn" class="btn btn-primary btn-sm">Pause</button>
      </li>
      <li class="nav-button pull-right">
        <button type="button" id="resumebtn" class="btn btn-primary btn-sm">Resume</button>
      </li>
      <li class="nav-button pull-right">
        <button type="button" id="cancelbtn" class="btn btn-danger btn-sm">Kill</button>
      </li>
      <li class="nav-button pull-right">
        <button type="button" id="retrybtn" class="btn btn-success btn-sm">Retry Failed</button>
      </li>
      <li class="nav-button pull-right">
        <button type="button" id="executebtn" class="btn btn-success btn-sm">Prepare Execution
        </button>
      </li>
    </ul>
  </div>

  ## Graph View

    #parse ("azkaban/webapp/servlet/velocity/flowgraphview.vm")

  ## Flow Trigger List View

  <div class="container-full" id="flowTriggerListView">
    <div class="row">
      <div class="col-xs-12">
        <table class="table table-bordered table-condensed table-hover executions-table">
          <thead>
          <tr>
            <th>Trigger Instance Id</th>
            <th>Submitted by</th>
            <th class="date">Start Time</th>
            <th class="date">End Time</th>
            <th class="elapse">Elapsed</th>
            <th class="status">Status</th>
            <th class="props">Trigger Properties</th>
            <th class="action">Action</th>
          </tr>

          <div class="modal fade" id="dependencyList" tabindex="-1"
               role="dialog"
               aria-labelledby="dependencyLabel">
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                  <h4 class="modal-title" id="dependencyLabel">Dependencies</h4>
                </div>
                <div id="triggerProp" class="modal-body">
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close
                  </button>
                </div>
              </div>
            </div>
          </div>

          </thead>
          <tbody id="triggerBody">
          </tbody>
          <thead>
          <tr>
            <th>Trigger Instance Id</th>
            <th>Dependency Name</th>
            <th class="triggertype">Dependency Type</th>
            <th class="date">Start Time</th>
            <th class="date">End Time</th>
            <th class="elapse">Elapsed</th>
            <th class="status">Status</th>
            <th class="cause">Cancellation Cause</th>
          </tr>
          </thead>
          <tbody id="triggerExecutableBody">
          </tbody>
        </table>
      </div><!-- /.col-xs-12 -->
    </div><!-- /.row -->
  </div><!-- /.container-full -->

  ## Job List View

  <div class="container-full" id="jobListView">
    <div class="row">
      <div class="col-xs-12">
        <table class="table table-bordered table-condensed table-hover executions-table">
          <thead>
          <tr>
            <th>Name</th>
            <th class="jobtype">Type</th>
            <th class="timeline">Timeline</th>
            <th class="date">Start Time</th>
            <th class="date">End Time</th>
            <th class="elapse">Elapsed</th>
            <th class="status">Status</th>
            <th class="logs">Details</th>
          </tr>
          </thead>
          <tbody id="executableBody">
          </tbody>
        </table>
      </div><!-- /.col-xs-12 -->
    </div><!-- /.row -->
  </div><!-- /.container-full -->

  ## Flow Log View

  <div class="container-full container-fill" id="flowLogView">
    <div class="row">
      <div class="col-xs-12 col-content">
        <div class="log-viewer">
          <div class="panel panel-default">
            <div class="panel-heading">
              <div class="pull-right">
                <button type="button" id="updateLogBtn" class="btn btn-xs btn-info">Refresh</button>
              </div>
              Flow log
            </div>
            <div class="panel-body">
              <pre id="logSection"></pre>
            </div>
          </div><!-- /.panel -->
        </div><!-- /.log-viewer -->
      </div><!-- /.col-xs-12 -->
    </div><!-- /.row -->
  </div><!-- /.container-full -->

  ## Stats view.

  <div class="container-full" id="statsView">
    <div id="flow-stats-container">
      <div class="row">
        <div class="col-lg-12">
          <div class="callout callout-default">
            <h4>No stats available</h4>
            <p>Stats for this flow execution are not available.</p>
          </div>
        </div>
      </div>
    </div><!-- /.row -->
  </div><!-- /.container-fill -->

  ## Error message message dialog.

  <div class="container-full">
    <div class="modal" id="messageDialog">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header" id="messageTitle">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
            </button>
            <h4 class="modal-title">Error</h4>
          </div>
          <div class="modal-body" id="messageDiv">
            <p id="messageBox"></p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-primary" data-dismiss="modal">Dismiss</button>
          </div>
        </div>
      </div>
    </div>

    <div id="contextMenu"></div>

    #parse ("azkaban/webapp/servlet/velocity/invalidsessionmodal.vm")
    #parse ("azkaban/webapp/servlet/velocity/flowexecutionpanel.vm")
    #parse ("azkaban/webapp/servlet/velocity/messagedialog.vm")
  </div>
  #end
</body>
</html>
