|
| 1 | +{% load buttons %} |
| 2 | +{% load helpers %} |
| 3 | +{% load perms %} |
| 4 | +{% load i18n %} |
| 5 | + |
| 6 | +{# Core script list content - used by both full page and embedded views #} |
| 7 | +{% for module in script_modules %} |
| 8 | + {% include 'inc/sync_warning.html' with object=module %} |
| 9 | + <div class="card{% if embedded %} mb-3{% endif %}"> |
| 10 | + {% if not embedded %} |
| 11 | + <h2 class="card-header" id="module{{ module.pk }}"> |
| 12 | + <i class="mdi mdi-file-document-outline"></i> {{ module }} |
| 13 | + <div class="card-actions"> |
| 14 | + {% if perms.extras.edit_scriptmodule %} |
| 15 | + <a href="{% url 'extras:scriptmodule_edit' pk=module.pk %}" class="btn btn-ghost-warning btn-sm"> |
| 16 | + <i class="mdi mdi-pencil" aria-hidden="true"></i> {% trans "Edit" %} |
| 17 | + </a> |
| 18 | + {% endif %} |
| 19 | + {% if perms.extras.delete_scriptmodule %} |
| 20 | + <a href="{% url 'extras:scriptmodule_delete' pk=module.pk %}" class="btn btn-ghost-danger btn-sm"> |
| 21 | + <i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {% trans "Delete" %} |
| 22 | + </a> |
| 23 | + {% endif %} |
| 24 | + </div> |
| 25 | + </h2> |
| 26 | + {% endif %} |
| 27 | + {% with scripts=module.ordered_scripts %} |
| 28 | + {% if scripts %} |
| 29 | + <table class="table table-hover scripts{% if embedded %} object-list table-sm{% endif %}"> |
| 30 | + <thead> |
| 31 | + <tr> |
| 32 | + <th>{% trans "Name" %}</th> |
| 33 | + <th>{% trans "Description" %}</th> |
| 34 | + <th>{% trans "Last Run" %}</th> |
| 35 | + <th>{% trans "Status" %}</th> |
| 36 | + <th></th> |
| 37 | + </tr> |
| 38 | + </thead> |
| 39 | + <tbody> |
| 40 | + {% for script in scripts %} |
| 41 | + {% with last_job=script.get_latest_jobs|first %} |
| 42 | + <tr> |
| 43 | + <td> |
| 44 | + {% if script.is_executable %} |
| 45 | + <a href="{% url 'extras:script' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a> |
| 46 | + {% else %} |
| 47 | + <a href="{% url 'extras:script_jobs' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a> |
| 48 | + <span class="text-danger"> |
| 49 | + <i class="mdi mdi-alert" title="{% trans "Script is no longer present in the source file" %}"></i> |
| 50 | + </span> |
| 51 | + {% endif %} |
| 52 | + </td> |
| 53 | + <td>{{ script.python_class.description|markdown|placeholder }}</td> |
| 54 | + {% if last_job %} |
| 55 | + <td> |
| 56 | + <a href="{% url 'extras:script_result' job_pk=last_job.pk %}">{{ last_job.created|isodatetime }}</a> |
| 57 | + </td> |
| 58 | + <td> |
| 59 | + {% badge last_job.get_status_display last_job.get_status_color %} |
| 60 | + </td> |
| 61 | + {% else %} |
| 62 | + <td class="text-muted">{% trans "Never" %}</td> |
| 63 | + <td>{{ ''|placeholder }}</td> |
| 64 | + {% endif %} |
| 65 | + <td> |
| 66 | + {% if request.user|can_run:script and script.is_executable %} |
| 67 | + <div class="float-end d-print-none"> |
| 68 | + <form action="{% url 'extras:script' script.pk %}" method="post"> |
| 69 | + {% if script.python_class.commit_default %} |
| 70 | + <input type="checkbox" name="_commit" hidden checked> |
| 71 | + {% endif %} |
| 72 | + {% csrf_token %} |
| 73 | + <button type="submit" name="_run" class="btn btn-primary{% if embedded %} btn-sm{% endif %}"> |
| 74 | + {% if last_job %} |
| 75 | + <i class="mdi mdi-replay"></i> {% if not embedded %}{% trans "Run Again" %}{% endif %} |
| 76 | + {% else %} |
| 77 | + <i class="mdi mdi-play"></i> {% if not embedded %}{% trans "Run Script" %}{% endif %} |
| 78 | + {% endif %} |
| 79 | + </button> |
| 80 | + </form> |
| 81 | + </div> |
| 82 | + {% endif %} |
| 83 | + </td> |
| 84 | + </tr> |
| 85 | + {% if last_job and not embedded %} |
| 86 | + {% for test_name, data in last_job.data.tests.items %} |
| 87 | + <tr> |
| 88 | + <td colspan="4" class="method"> |
| 89 | + <span class="ps-3">{{ test_name }}</span> |
| 90 | + </td> |
| 91 | + <td class="text-end text-nowrap script-stats"> |
| 92 | + <span class="badge text-bg-success">{{ data.success }}</span> |
| 93 | + <span class="badge text-bg-info">{{ data.info }}</span> |
| 94 | + <span class="badge text-bg-warning">{{ data.warning }}</span> |
| 95 | + <span class="badge text-bg-danger">{{ data.failure }}</span> |
| 96 | + </td> |
| 97 | + </tr> |
| 98 | + {% endfor %} |
| 99 | + {% elif last_job and not last_job.data.log and not embedded %} |
| 100 | + {# legacy #} |
| 101 | + {% for method, stats in last_job.data.items %} |
| 102 | + <tr> |
| 103 | + <td colspan="4" class="method"> |
| 104 | + <span class="ps-3">{{ method }}</span> |
| 105 | + </td> |
| 106 | + <td class="text-end text-nowrap report-stats"> |
| 107 | + <span class="badge bg-success">{{ stats.success }}</span> |
| 108 | + <span class="badge bg-info">{{ stats.info }}</span> |
| 109 | + <span class="badge bg-warning">{{ stats.warning }}</span> |
| 110 | + <span class="badge bg-danger">{{ stats.failure }}</span> |
| 111 | + </td> |
| 112 | + </tr> |
| 113 | + {% endfor %} |
| 114 | + {% endif %} |
| 115 | + {% endwith %} |
| 116 | + {% endfor %} |
| 117 | + </tbody> |
| 118 | + </table> |
| 119 | + {% else %} |
| 120 | + <div class="card-body"> |
| 121 | + <div class="alert alert-warning" role="alert"> |
| 122 | + <i class="mdi mdi-alert"></i> |
| 123 | + {% blocktrans with module=module.name %}Could not load scripts from module {{ module }}{% endblocktrans %} |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + {% endif %} |
| 127 | + {% endwith %} |
| 128 | + </div> |
| 129 | +{% empty %} |
| 130 | + <div class="alert alert-info" role="alert"> |
| 131 | + <h4 class="alert-heading">{% trans "No Scripts Found" %}</h4> |
| 132 | + {% if perms.extras.add_scriptmodule and not embedded %} |
| 133 | + {% url 'extras:scriptmodule_add' as create_script_url %} |
| 134 | + {% blocktrans trimmed %} |
| 135 | + Get started by <a href="{{ create_script_url }}">creating a script</a> from an uploaded file or data source. |
| 136 | + {% endblocktrans %} |
| 137 | + {% endif %} |
| 138 | + </div> |
| 139 | +{% endfor %} |
0 commit comments