{#
 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 page_title %}{{ dag.dag_id }} - Gantt - {{ appbuilder.app_name }}{% endblock %}

{% block head_css %}
  {{ super() }}
  <link rel="stylesheet" type="text/css" href="{{ url_for_asset('gantt.css') }}">
  <link rel="stylesheet" type="text/css" href="{{ url_for_asset('chart.css') }}">
  <style type="text/css">
    {% for state, state_color in state_color_mapping.items() %}
      rect.{{state}} {
        fill: {{state_color}};
      }
    {% endfor %}
  </style>
{% endblock %}

{% block content %}
  {{ super() }}
  <div class="row dag-view-tools">
    <div class="col-md-12">
      <form method="get" class="form-inline">
        <input type="hidden" value="{{ dag.dag_id }}" name="dag_id">
        <input type="hidden" name="root" value="{{ root if root else '' }}">
        <input type="hidden" name="_csrf_token" value="{{ csrf_token() }}">
        <div class="form-group">
          <label class="sr-only" for="base_date">Base date</label>
          <div class="input-group">
            {{ form.base_date(class_="form-control", disabled=not(dag.has_dag_runs())) }}
          </div>
        </div>
        <div class="form-group">
          <label class="sr-only" for="num_runs">Number of runs</label>
          <div class="input-group">
            <div class="input-group-addon">Runs</div>
            {{ form.num_runs(class_="form-control", disabled=not(dag.has_dag_runs())) }}
          </div>
        </div>
        <div class="form-group">
          <label class="sr-only" for="execution_date">Run</label>
          <div class="input-group">
            <div class="input-group-addon">Run</div>
            {{ form.execution_date(class_="form-control", disabled=not(dag.has_dag_runs())) }}
          </div>
        </div>
        <button type="submit" class="btn"{{' disabled' if not dag.has_dag_runs() else ''}}>Update</button>
        {% if not dag.has_dag_runs() %}<span class="text-warning" style="margin-left:16px;">No DAG runs yet.</span>{% endif %}
      </form>
    </div>
  </div>
  <div class="container">
    <div class="gantt"></div>
  </div>
{% endblock %}

{% block tail_js %}
  {{ super() }}
  <script src="{{ url_for_asset('d3.min.js') }}"></script>
  <script src="{{ url_for_asset('d3-tip.js') }}"></script>
  <script>
    const data = {{ data|tojson }};
  </script>
  <script src="{{ url_for_asset('gantt.js') }}"></script>
{% endblock %}
