{#
 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/dag.html" %}
{% block title %}Dag Audit Log{% endblock %}

{% block head_css %}
{{ super() }}
<link href="{{ url_for_asset('dataTables.bootstrap.min.css') }}" rel="stylesheet" type="text/css" >
<link href="{{ url_for_asset('bootstrap-toggle.min.css') }}" rel="stylesheet" type="text/css">
{% endblock %}

{% block content %}
  {{ super() }}
  <h2>Dag Audit Log</h2>
    <h4 style="display: block; padding-top: 10px; padding-bottom: 4px">
      <p>
        This view displays selected events and operations that have been taken on this dag.
        The included and excluded events are set in the Airflow configuration,
        which by default remove view only actions. For a full list of events regarding this DAG, click
        <a href="{{ url_for('LogModelView.list', _flt_3_dag_id=dag_id) }}">here</a>.
      </p>
    </h4>
    <table id="dag_audit_log_table" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th style="min-width: 140px">Time</th>
                <th style="min-width: 140px">Task ID</th>
                <th>Event</th>
                <th style="min-width: 140px">Logical Date</th>
                <th>Owner
                  <span class="material-icons text-muted js-tooltip" aria-hidden="true" data-original-title="This is the user who triggered the event.">info</span>
                </th>
                <th>Details</th>
            </tr>
        </thead>
        <tbody>
        {% for log in dag_logs %}
            <tr>
              <!--     Time     -->
              <td><time datetime="{{ log.dttm }}">{{ log.dttm }}</time></td>
              <!--     Task Id: task id is None for Dag level events    -->
              <td>{{ log.task_id if log.task_id else None }}</td>
              <!--     Event    -->
              <td>{{ log.event if log.event else None }}</td>
              <!--     Execution Date     -->
              <td>{{ log.execution_date if log.execution_date else None }}</td>
              <!--     By User     -->
              <td>{{ log.owner if log.owner else None }}</td>
              <!--     Details     -->
              <td>{{ log.extra if log.extra else None }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endblock %}

{% block tail %}
  {{ super() }}
  <script src="{{ url_for_asset('jquery.dataTables.min.js') }}"></script>
  <script src="{{ url_for_asset('dataTables.bootstrap.min.js') }}"></script>
  <script>
  $(document).ready(function() {
      <!-- Set rowCallback once add TaskNote annotations to highlight actions -->
      $('#dag_audit_log_table').DataTable( {
          "order": [[ 0, "desc" ]],
          "pageLength": '{{ page_size }}',
          <!-- lazy loading: deferred rendering for speed -->
          "deferRender": true,
      } );
  } );
  </script>
{% endblock %}
