mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 23:38:24 -04:00
Improved job/activity list ordering and display. Jobs are now shown by most recent activity (processing started or created)
This commit is contained in:
@@ -35,6 +35,7 @@ from app.extensions import redis_client
|
|||||||
from app.formatters import (
|
from app.formatters import (
|
||||||
convert_markdown_template,
|
convert_markdown_template,
|
||||||
convert_to_boolean,
|
convert_to_boolean,
|
||||||
|
convert_time_unixtimestamp,
|
||||||
format_auth_type,
|
format_auth_type,
|
||||||
format_billions,
|
format_billions,
|
||||||
format_date,
|
format_date,
|
||||||
@@ -672,6 +673,7 @@ def add_template_filters(application):
|
|||||||
format_thousands,
|
format_thousands,
|
||||||
id_safe,
|
id_safe,
|
||||||
convert_to_boolean,
|
convert_to_boolean,
|
||||||
|
convert_time_unixtimestamp,
|
||||||
format_list_items,
|
format_list_items,
|
||||||
iteration_count,
|
iteration_count,
|
||||||
recipient_count,
|
recipient_count,
|
||||||
|
|||||||
@@ -78,47 +78,45 @@ def handle_pagination(jobs, service_id, page):
|
|||||||
return prev_page, next_page, pagination
|
return prev_page, next_page, pagination
|
||||||
|
|
||||||
|
|
||||||
|
JOB_STATUS_DELIVERED = "delivered"
|
||||||
|
JOB_STATUS_FAILED = "failed"
|
||||||
|
|
||||||
|
|
||||||
|
def get_job_statistics(job, status):
|
||||||
|
statistics = job.get("statistics", [])
|
||||||
|
for stat in statistics:
|
||||||
|
if stat.get("status") == status:
|
||||||
|
return stat.get("count")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def create_job_dict_entry(job):
|
||||||
|
job_id = job.get("id")
|
||||||
|
can_download = get_time_left(job.get("created_at")) != "Data no longer available"
|
||||||
|
activity_time = job.get("processing_started") or job.get("created_at")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"job_id": job_id,
|
||||||
|
"can_download": can_download,
|
||||||
|
"download_link": url_for(
|
||||||
|
".view_job_csv",
|
||||||
|
service_id=current_service.id,
|
||||||
|
job_id=job_id
|
||||||
|
) if can_download else None,
|
||||||
|
"view_job_link": url_for(
|
||||||
|
".view_job",
|
||||||
|
service_id=current_service.id,
|
||||||
|
job_id=job_id
|
||||||
|
),
|
||||||
|
"activity_time": activity_time,
|
||||||
|
"created_by": job.get("created_by"),
|
||||||
|
"template_name": job.get("template_name"),
|
||||||
|
"delivered_count": get_job_statistics(job, JOB_STATUS_DELIVERED),
|
||||||
|
"failed_count": get_job_statistics(job, JOB_STATUS_FAILED),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def generate_job_dict(jobs):
|
def generate_job_dict(jobs):
|
||||||
return [
|
if not jobs or not jobs.get("data"):
|
||||||
{
|
return []
|
||||||
"job_id": job["id"],
|
return [create_job_dict_entry(job) for job in jobs["data"]]
|
||||||
"time_left": get_time_left(job["created_at"]),
|
|
||||||
"download_link": url_for(
|
|
||||||
".view_job_csv", service_id=current_service.id, job_id=job["id"]
|
|
||||||
),
|
|
||||||
"view_job_link": url_for(
|
|
||||||
".view_job", service_id=current_service.id, job_id=job["id"]
|
|
||||||
),
|
|
||||||
"created_at": job["created_at"],
|
|
||||||
"time_sent_data_value": convert_time_unixtimestamp(
|
|
||||||
job["processing_finished"]
|
|
||||||
if job["processing_finished"]
|
|
||||||
else (
|
|
||||||
job["processing_started"]
|
|
||||||
if job["processing_started"]
|
|
||||||
else job["created_at"]
|
|
||||||
)
|
|
||||||
),
|
|
||||||
"processing_finished": job["processing_finished"],
|
|
||||||
"processing_started": job["processing_started"],
|
|
||||||
"created_by": job["created_by"],
|
|
||||||
"template_name": job["template_name"],
|
|
||||||
"delivered_count": next(
|
|
||||||
(
|
|
||||||
stat["count"]
|
|
||||||
for stat in job.get("statistics", [])
|
|
||||||
if stat["status"] == "delivered"
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
"failed_count": next(
|
|
||||||
(
|
|
||||||
stat["count"]
|
|
||||||
for stat in job.get("statistics", [])
|
|
||||||
if stat["status"] == "failed"
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
for job in jobs["data"]
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -96,13 +96,12 @@
|
|||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="table-field template">{{ job.template_name }}</td>
|
<td class="table-field template">{{ job.template_name }}</td>
|
||||||
<td data-sort-value="{{job.time_sent_data_value}}" class="table-field time-sent">
|
<td data-sort-value="{{ job.activity_time | convert_time_unixtimestamp }}" class="table-field time-sent">
|
||||||
{{ (job.processing_finished if job.processing_finished else job.processing_started
|
{{ job.activity_time|format_datetime_table }}
|
||||||
if job.processing_started else job.created_at)|format_datetime_table }}
|
|
||||||
</td>
|
</td>
|
||||||
<td class="table-field sender">{{ job.created_by.name }}</td>
|
<td class="table-field sender">{{ job.created_by.name }}</td>
|
||||||
<td class="table-field report">
|
<td class="table-field report">
|
||||||
{% if job.time_left != "Data no longer available" %}
|
{% if job.can_download %}
|
||||||
<a href="{{ job.download_link }}">
|
<a href="{{ job.download_link }}">
|
||||||
<img src="{{ url_for('static', filename='img/material-icons/file_download.svg') }}" alt="">
|
<img src="{{ url_for('static', filename='img/material-icons/file_download.svg') }}" alt="">
|
||||||
<span class="usa-sr-only">Download report link</span>
|
<span class="usa-sr-only">Download report link</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user