{% extends 'generic/object_detail.html' %}
{% load helpers %}
{% load perms %}
{% load plugins %}

{% block extra_breadcrumbs %}
    <li>{{ object.grouping }}</li>
{% endblock extra_breadcrumbs %}

{% block extra_buttons %}
    {% if perms.extras.run_job %}
        <a href="{% url 'extras:job_run' pk=object.pk %}" class="btn btn-primary"
           {% if not object.installed or not object.enabled %}disabled="disabled"{% endif %}>
            <i class="mdi mdi-play" aria-hidden="true"></i> Run/Schedule
        </a>
    {% endif %}
{% endblock extra_buttons %}

{% block content_left_page %}
    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>Source Code</strong>
        </div>
        <table class="table table-hover panel-body attr-table">
            <tr>
                <td>Module</td>
                <td><code>{{ object.module_name }}</code></td>
            </tr>
            <tr>
                <td>Job Class</td>
                <td><code>{{ object.job_class_name }}</code></td>
            </tr>
            <tr>
                <td>Class Path</td>
                <td>
                    <span class="hover_copy">
                        <span id="job_class_path_copy"><code>{{ object.class_path }}</code></span>
                        <button class="btn btn-inline btn-default hover_copy_button" data-clipboard-target="#job_class_path_copy">
                            <span class="mdi mdi-content-copy"></span>
                        </button>
                    </span>
                </td>
            </tr>
            <tr>
                <td>Installed</td>
                <td>{{ object.installed | render_boolean }}</td>
            </tr>
            <tr>
                <td>Is Job Hook Receiver</td>
                <td>{{ object.is_job_hook_receiver | render_boolean }}</td>
                <td></td>
            </tr>
            <tr>
                <td>Is Job Button Receiver</td>
                <td>{{ object.is_job_button_receiver | render_boolean }}</td>
                <td></td>
            </tr>
        </table>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>Job</strong>
        </div>
        <table class="table table-hover panel-body attr-table">
            <tr>
                <td>Grouping</td>
                <td>{{ object.grouping }}</td>
                <td>
                    {% if object.grouping_override %}
                        <span class="text-muted">
                            overridden; default is
                            {% if object.installed %}
                                “{{ object.job_class.grouping }}”
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Name</td>
                <td>{{ object.name }}</td>
                <td>
                    {% if object.name_override %}
                        <span class="text-muted">
                            overridden; default is
                            {% if object.installed %}
                                “{{ object.job_class.name }}”
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Description</td>
                <td>{{ object.description | render_markdown | placeholder }}</td>
                <td>
                    {% if object.description_override %}
                        <div class="text-muted">
                            overridden; default is:<br>
                            {% if object.installed %}
                                {{ object.job_class.description | render_markdown | placeholder }}
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </div>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Enabled</td>
                <td>{{ object.enabled | render_boolean }}</td>
                <td></td>
            </tr>
        </table>
    </div>
{% endblock content_left_page %}

{% block content_right_page %}
    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>Properties</strong>
        </div>
        <table class="table table-hover panel-body attr-table">
            <tr>
                <td>Approval Required to Execute</td>
                <td>{{ object.approval_required | render_boolean }}</td>
                <td>
                    {% if object.approval_required_override %}
                        <span class="text-muted">
                            overridden; default is
                            {% if object.installed %}
                                {{ object.job_class.approval_required | render_boolean }}
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Supports Dryrun</td>
                <td colspan="2">{{ object.supports_dryrun | render_boolean }}</td>
            </tr>
            <tr>
                <td>Default to Dryrun</td>
                <td>{{ object.dryrun_default | render_boolean }}</td>
                <td>
                    {% if object.dryrun_default_override %}
                        <span class="text-muted">
                            overridden; default is
                            {% if object.installed %}
                                {{ object.job_class.dryrun_default | render_boolean }}
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Read-Only Execution</td>
                <td colspan="2">{{ object.read_only | render_boolean }}</td>
            </tr>
            <tr>
                <td>Hide from Default UI</td>
                <td>{{ object.hidden | render_boolean }}</td>
                <td>
                    {% if object.hidden_override %}
                        <span class="text-muted">
                            overridden; default is
                            {% if object.installed %}
                                {{ object.job_class.hidden | render_boolean }}
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Has Sensitive Variables</td>
                <td>{{ object.has_sensitive_variables | render_boolean }}</td>
                <td>
                    {% if object.has_sensitive_variables_override %}
                        <span class="text-muted">
                            overridden; default is
                            {% if object.installed %}
                                {{ object.job_class.has_sensitive_variables | render_boolean }}
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Execution Soft Time Limit</td>
                <td>
                    {% if object.soft_time_limit > 0 %}
                        {{ object.soft_time_limit }} seconds
                    {% else %}
                        {{ "CELERY_TASK_SOFT_TIME_LIMIT" | settings_or_config }} seconds (system default)
                    {% endif %}
                </td>
                <td>
                    {% if object.soft_time_limit_override %}
                        <span class="text-muted">
                            overridden; default is
                            {% if object.installed %}
                                {% if object.job_class.soft_time_limit > 0 %}
                                    {{ object.job_class.soft_time_limit }} seconds
                                {% else %}
                                    {{ "CELERY_TASK_SOFT_TIME_LIMIT" | settings_or_config }} seconds (system default)
                                {% endif %}
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Execution Hard Time Limit</td>
                <td>
                    {% if object.time_limit > 0 %}
                        {{ object.time_limit }} seconds
                    {% else %}
                        {{ "CELERY_TASK_TIME_LIMIT" | settings_or_config }} seconds (system default)
                    {% endif %}
                </td>
                <td>
                    {% if object.time_limit_override %}
                        <span class="text-muted">
                            overridden; default is
                            {% if object.installed %}
                                {% if object.job_class.time_limit > 0 %}
                                    {{ object.job_class.time_limit }} seconds
                                {% else %}
                                    {{ "CELERY_TASK_TIME_LIMIT" | settings_or_config }} seconds (system default)
                                {% endif %}
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Task Queues</td>
                <td colspan="2">
                    {% include 'extras/inc/json_data.html' with data=object.task_queues format="json" %}
                    {% if object.task_queues_override %}
                        <span class="text-muted">
                            overridden; default is:<br>
                            {% if object.installed %}
                                {% include 'extras/inc/json_data.html' with data=object.job_class.task_queues format="json" %}
                            {% else %}
                                unknown (not currently installed)
                            {% endif %}
                        </span>
                    {% endif %}
                </td>
            </tr>
        </table>
    </div>
{% endblock content_right_page %}
