{#
  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 head_css %}
{{ super() }}
<link type="text/css" href="{{ url_for('static', filename='css/gantt.css') }}" rel="stylesheet" />
<link type="text/css" href="{{ url_for('static', filename='css/tree.css') }}" rel="stylesheet" />
<style type="text/css">
  {% for state, state_color in state_color_mapping.items() %}
    rect.{{state}} {
      fill: {{state_color}};
    }
  {% endfor %}
</style>
{% endblock %}

{% block content %}
{{ super() }}
<form method="get">
  <div class="form-inline">
    Base date: {{ form.base_date(class_="form-control") }}
    Number of runs: {{ form.num_runs(class_="form-control") }}
    Run:<input type="hidden" value="{{ dag.dag_id }}" name="dag_id">
    {{ form.execution_date(class_="form-control") }}
    <input type="submit" value="Go" class="btn btn-default" action="" method="get">
    <input type="hidden" name="root" value="{{ root if root else '' }}">
    <input name="_csrf_token" type="hidden" value="{{ csrf_token() }}">
  </div>
</form>
<div style="clear: both;"></div>
<div class="container">
  <div class="gantt"></div>
</div>
{% endblock %}

{% block tail %}
{{ super() }}
<script src="{{ url_for_asset('d3.min.js') }}"></script>
<script src="{{ url_for_asset('d3-tip.js') }}"></script>/
<script src="{{ url_for_asset('ganttChartD3v2.js') }}"></script>
<script src="{{ url_for_asset('task-instances.js') }}"></script>
<script>
  $( document ).ready(function() {
    var dag_id = '{{ dag.dag_id }}';
    var task_id = '';
    var execution_date = '';
    data = {{ data |tojson }};
    var gantt = d3.gantt()
      .taskTypes(data.taskNames)
      .height(data.height)
      .selector('.gantt')
      .tickFormat("%H:%M:%S");
    gantt(data.tasks);
    $('body').on('airflow.timezone-change', (e) => {
      gantt.redraw(data.tasks);
    });
  });
</script>

{% endblock %}
