{#
 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 base_template %}
{% from 'appbuilder/dag_docs.html' import dag_docs %}

{% block head_css %}
  {{ super() }}
  <link rel="stylesheet" type="text/css" href="{{ url_for_asset('codemirror.css') }}">
  <link rel="stylesheet" type="text/css" href="{{ url_for_asset('lint.css') }}">
  <link rel="stylesheet" type="text/css" href="{{ url_for_asset('switch.css') }}">
{% endblock %}

{% block content %}
  {{ super() }}
  <h2>Trigger DAG: {{ dag_id }}</h2>
  {{ dag_docs(doc_md) }}
  <form method="POST">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
    <input type="hidden" name="dag_id" value="{{ dag_id }}">
    <input type="hidden" name="origin" value="{{ origin }}">
    <div class="form-group">
      <label for="execution_date">Logical date</label>
      <div class="input-group">
        {{ form.execution_date(class_="form-control", disabled=False) }}
      </div>
    </div>
    <div class="form-group row">
      <div class="col-md-2">
        <label for="run_id">Run id (Optional)</label>
        <input type="text" class="form-control" placeholder="Run ID" name="run_id" >
      </div>
    </div>
    <label for="conf">Configuration JSON (Optional, must be a dict object)</label>
    <textarea class="form-control" name="conf" id="json">{{ conf }}</textarea>
    </div>
    <p>
      To access configuration in your DAG use <code>{{ '{{ dag_run.conf }}' }}</code>.
      {% if is_dag_run_conf_overrides_params %}
        As <code>core.dag_run_conf_overrides_params</code> is set to <code>True</code>, so passing any configuration
        here will override task params which can be accessed via <code>{{ '{{ params }}' }}</code>.
      {% else %}
        As <code>core.dag_run_conf_overrides_params</code> is set to <code>False</code>, so passing any configuration
        here won't override task params.
      {% endif %}
    </p>
    <div class="form-group">
      <label class="switch-label">
        <input class="switch-input" name="unpause" id="unpause" type="checkbox" checked>
        <span class="switch" aria-hidden="true"></span>
        Unpause DAG when triggered
      </label>
    </div>
    <button type="submit" class="btn btn-primary">Trigger</button>
    <a class="btn" href="{{ origin }}">Cancel</a>
  </form>
{% endblock %}

{% block tail_js %}
  <script src="{{ url_for_asset('codemirror.js') }}"></script>
  <script src="{{ url_for_asset('javascript.js') }}"></script>
  <script src="{{ url_for_asset('lint.js') }}"></script>
  <script src="{{ url_for_asset('javascript-lint.js') }}"></script>
  <script src="{{ url_for_asset('jshint.js') }}"></script>
  <script src="{{ url_for_asset('trigger.js') }}"></script>
  {{ super() }}
{% endblock %}
