{#
 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.
#}

{% extends "airflow/task_instance.html" %}
{% block title %}DAGs - {{ appbuilder.app_name }}{% endblock %}

{% block head_meta %}
  {{ super() }}
  <meta name="task_id" content="{{ task_id }}">
  <meta name="map_index" content="{{ map_index }}">
  <meta name="execution_date" content="{{ execution_date }}">
  <meta name="logs_with_metadata_url" content="{{ url_for('Airflow.get_logs_with_metadata') }}">
  {# Time interval to wait before next log fetching. Default 2s. #}
  <meta name="delay" content="{{ (log_fetch_delay_sec | int ) * 1000 }}">
  {# Distance away from page bottom to enable auto tailing. #}
  <meta name="auto_tailing_offset" content="{{ log_auto_tailing_offset | int }}">
  {# Animation speed for auto tailing log display. #}
  <meta name="animation_speed" content="{{ log_animation_speed | int }}">
  {# Total number of tabs to show. #}
  <meta name="total_attempts" content="{{ logs|length }}">
{% endblock %}

{% block content %}
  {{ super() }}
  <h4>{{ title }}</h4>
  <div class="row">
    <div class="col-md-8">
      <ul id="ti_log_try_number_list" class="nav nav-pills" role="tablist">
        {% for log in logs %}
          <li role="presentation" class="{{ 'active' if loop.last else '' }}">
            <a href="#{{ loop.index }}" aria-controls="{{ loop.index }}" role="tab" data-toggle="tab" data-try-number="{{ loop.index }}">
              {{ loop.index }}
            </a>
          </li>
        {% endfor %}
      </ul>
    </div>
    <div class="col-md-4 text-right">
      <a class="btn btn-default" onclick="scrollBottomLogs()">Jump To End</a>
      <a class="btn btn-default" onclick="toggleWrapLogs()">Toggle Wrap</a>
      <a class="btn btn-default" id="ti_log_download_active">Download</a>
    </div>
  </div>
  <div class="tab-content">
    {% for log in logs %}
      <div role="tabpanel" class="tab-pane {{ 'active' if loop.last else '' }}" id="{{ loop.index }}">
        <img id="loading-{{ loop.index }}" style="margin-top:0%; margin-left:50%; height:50px; width:50px; position: absolute;"
             alt="spinner" src="{{ url_for('static', filename='loading.gif') }}">
        <div id="log-group-{{ loop.index }}"></div>
      </div>
    {% endfor %}
  </div>
  <br>
{% endblock %}
{% block tail %}
  {{ super() }}
  <script src="{{ url_for_asset('tiLog.js') }}"></script>
{% endblock %}
