#*
 * Copyright 2018 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>
  <head>
    <title>Reportal</title>
    <link href="${context}/reportal/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="${context}/js/jquery/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="${context}/js/jqueryui/jquery-ui-1.10.1.custom.js"></script>
    <script type="text/javascript" src="${context}/reportal/js/bootstrap.min.js"></script>

    <script type="text/javascript">
      var contextURL = "${context}";
      var currentTime = ${currentTime};
      var timezone = "${timezone}";
      var homeDir = "${homedir}";
#if($project)
      var projectId = ${project.id};
#end
    </script>
    <script type="text/javascript" src="${context}/reportal/js/reportal.js"></script>
    <script type="text/javascript" src="${context}/reportal/js/reportal-data.js"></script>
    <link href="${context}/reportal/css/reportal.css" rel="stylesheet">
  </head>
  <body>
#set($current_page="$viewerName")
#if(!$hideNavigation)
  #parse("azkaban/webapp/servlet/velocity/nav.vm")
#end

#parse("azkaban/viewer/reportal/reportalnavigation.vm")

    <div class="content" style="margin-top: 41px;">
      <div id="box-error">
  #if($errorMsg)
        <div class="box-error-message">$errorMsg</div>
  #else
    #if($error_message != "null")
        <div class="box-error-message">$error_message</div>
    #elseif($success_message != "null")
        <div class="box-success-message">$success_message</div>
    #end
  #end
      </div>
      <div>&nbsp;</div>
#if($project)
      <div class="container">
        <h2 style="font-size: 31.5px;">${project.metadata.title}</h2>
        <div class="well">${project.description}</div>
      </div>
#end
      <div style="text-align: center;">
        <a class="btn btn-info" href="${context}/reportal">Reportal Home</a>
#if($project)
        <a class="btn btn-primary" href="${context}/reportal?view&amp;id=${project.id}">Report History</a>
#if($execid)
        <a class="btn btn-primary" href="${context}/reportal?view&amp;id=${project.id}&amp;execid=${execid}">Data</a>
        <a class="btn btn-primary" href="${context}/reportal?view&amp;logs&amp;id=${project.id}&amp;execid=${execid}">Logs</a>
#end
        <a class="btn btn-warning" href="${context}/reportal?edit&amp;id=${project.id}">Edit</a>
        <a class="btn btn-success button-run" href="${context}/reportal?run&amp;id=${project.id}">Run</a>
#end
      </div>
      <div>&nbsp;</div>
      <div class="container">
        <div>
#if($view-executions)
          <div style="text-align: center;">
  #if($pagePrev)
            <a class="btn btn-primary" href="${context}/reportal?view&amp;id=${project.id}&amp;page=${pagePrev}">Previous page</a>
  #end
            <a class="btn btn-inverse" href="${context}/reportal?view&amp;id=${project.id}&amp;page=${page}">Page ${page}</a>
  #if($pageNext)
            <a class="btn btn-primary" href="${context}/reportal?view&amp;id=${project.id}&amp;page=${pageNext}">Next page</a>
  #end
          </div>
          <div>&nbsp;</div>
          <table id="report-results" border="0" cellspacing="0" cellpadding="0" class="table table-bordered table-striped">
            <thead>
              <tr>
                <th>Time</th>
                <th>Status</th>
                <th>View Data</th>
                <th>View Logs</th>
              </tr>
            </thead>
            <tbody>
  #if($executions)
    #foreach($execution in $executions)
              <tr>
                <td>$utils.formatDateTime($execution.startTime)</td>
                <td>${execution.status}</td>
                <td><a href="${context}/reportal?view&amp;id=${project.id}&amp;execid=${execution.execId}">Data</a></td>
                <td><a href="${context}/reportal?view&amp;logs&amp;id=${project.id}&amp;execid=${execution.execId}">Logs</a></td>
              </tr>
    #end
  #else
              <tr>
                <td colspan="4" style="text-align:center;">#if($page > 1)There are no reports in this page. #else This report has never been run.#end</td>
              </tr>
  #end
            </tbody>
          </table>
#end
#if($view-logs)
          <table id="report-results" border="0" cellspacing="0" cellpadding="0" class="table table-bordered table-striped">
            <thead>
              <tr>
                <th>Title</th>
                <th>Status</th>
                <th>View Log</th>
              </tr>
            </thead>
            <tbody>
  #if($logs)
    #foreach($log in $logs)
              <tr>
                <td>${log.id}</td>
                <td>${log.status}</td>
                <td><a href="${context}/reportal?view&amp;logs&amp;id=${project.id}&amp;execid=${execid}&amp;log=${log.id}">Log</a></td>
              </tr>
    #end
  #else
              <tr>
                <td colspan="2" style="text-align:center;">No log available.</td>
              </tr>
  #end
            </tbody>
          </table>
#end
#if($view-log)
          <script>
          var execId = ${execid};
          var jobId = "${jobId}";
          var projectId = ${project.id};
          </script>
          <script type="text/javascript" src="${context}/reportal/js/reportal-data-log.js"></script>
          <div id="jobLogView" class="logView" style="top:245px;">
            <div style="text-align: center;">
              <a class="btn btn-inverse" id="updateLogBtn" href="#">Refresh</a>
              <a class="btn btn-inverse" id="toggleLineWrap" href="#">Toggle Line wrapping</a>
            </div>
            <div class="logViewer">
              <pre id="logSection" class="log" style="background-color:#FFFFFF;">Loading log...</pre>
            </div>
          </div>
#end
#if($view-preview)
  #if($files)
    #foreach($file in $files)
      #set($fileName = $file.get("name"))
          <div>
            <a download="$fileName" href="$context/reportal?view&amp;id=${project.id}&amp;execid=$execid&amp;download=$fileName"><b>$fileName</b></a>
          </div>

          <table id="report-results" border="0" cellspacing="0" cellpadding="0" class="table table-bordered table-striped">
      #foreach($line in $file.get("content"))
            <tr>
        #foreach($item in $line)
              <td>$esc.html($item)</td>
        #end
            </tr>
      #end

      #if($file.get("hasMore"))
        #set($numColumns = $file.get("content").get(0).size())
            <tr>
              <td colspan="$numColumns">...</td>
            </tr>
      #end
          </table>
    #end
  #else
          <div style="text-align:center;">No data available.</div>
  #end
#end
        </div>
      </div>
    </div>
  </body>
</html>
