{#
 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 }} - Duration chart - {{ appbuilder.app_name }}{% endblock %}

{% block head_css %}
  {{ super() }}
  <link rel="stylesheet" type="text/css" href="{{ url_for_asset('chart.css') }}">
  <link rel="stylesheet" type="text/css" href="{{ url_for_asset('nv.d3.min.css') }}">
  <script src="{{ url_for_asset('d3.min.js') }}"></script>
  <script src="{{ url_for_asset('nv.d3.min.js') }}"></script>
{% endblock %}

{% block content %}
  {{ super() }}
  <div class="row dag-view-tools">
    <div class="col-md-10">
      <form method="get" class="form-inline">
        <input type="hidden" name="root" value="{{ root if root else '' }}">
        <input type="hidden" value="{{ dag.dag_id }}" name="dag_id">
        <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>
        <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 class="col-md-2 text-right">
      <div class="checkbox">
        <label for="isCumulative">
          <input type="checkbox" id="isCumulative" value="1"> Cumulative Duration
        </label>
      </div>
    </div>
  </div>
  <div id="dur_chart">{{ chart }}</div>
  <div id="cum_dur_chart">{{ cum_chart }}</div>
{% endblock %}

{% block tail %}
  <script src="{{ url_for_asset('durationChart.js') }}"></script>
  {{ super() }}
{% endblock %}
