Skip to content

Commit

Permalink
added service online indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hanke committed Jan 27, 2025
1 parent a58225d commit c2c9be6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 9 deletions.
17 changes: 17 additions & 0 deletions ckanext/csvtocsvw/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import ckan.plugins.toolkit as toolkit
import requests


def service_available():
url = toolkit.config.get("ckanext.csvtocsvw.csvtocsvw_url")
if not url:
return False # If EXTRACT_URL is not set, return False
try:
# Perform a HEAD request (lightweight check) to see if the service responds
response = requests.head(url, timeout=5, verify=False)
if (200 <= response.status_code < 400) or response.status_code == 405:
return True # URL is reachable and returns a valid status code
else:
return False # URL is reachable but response status is not valid
except requests.RequestException as e:
# If there's any issue (timeout, connection error, etc.)
return False


def csvtocsvw_show_tools(resource):
Expand Down
27 changes: 24 additions & 3 deletions ckanext/csvtocsvw/templates/csvtocsvw/csv_annotate.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,30 @@ <h1 >{% block form_title %}{{ _('Annotation Status') }}{% endblock %}</h1>
{% block form %}
<form method="post" action="{{ action }}" class="csvtocsvw-form">
{{ h.csrf_input() }}
<button class="btn btn-primary" name="save" type="submit">
<i class="fa fa-play"></i> {{ _('Run Annotation') }}
</button>
<div class="col-12 d-flex align-items-center justify-content-between">
<div class="d-flex align-items-center">
<button class="btn btn-primary {% if not
service_status %}disabled{% endif %}" name="save" type="submit">
<i class="fa fa-play"></i> {{ _('Run Annotation') }}
</button>
<!-- Status Indicator Section -->
</div>
<style>
.indicator {
width: 20px;
height: 20px;
border-radius: 50%;
background-color: red;
/* Default: Service unavailable */
}
</style>
<div class="d-flex align-items-center">
<div id="service-indicator" class="indicator" data-bs-toggle="tooltip"
title="{{ _('The status of the service (Green means available, Red means unavailable)') }}" {% if
service_status %} style="background-color: green;" {% endif %}>
</div>
</div>
</div>
</form>
{% endblock %}
{% if status %}
Expand Down
30 changes: 25 additions & 5 deletions ckanext/csvtocsvw/templates/csvtocsvw/csv_transform.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,31 @@
<h1 >{% block form_title %}{{ _('Transform Status') }}{% endblock %}</h1>
{% block form %}
<form method="post" action="{{ action }}" class="csvtocsvw-form">
{{ h.csrf_input() }}
<button class="btn btn-primary {% if not
meta_res %}disabled{% endif %}" name="save" type="submit">
<i class="fa fa-play"></i> {{ _('Run Transformation') }}
</button>
{{ h.csrf_input() }}
<div class="col-12 d-flex align-items-center justify-content-between">
<div class="d-flex align-items-center">
<button class="btn btn-primary {% if not
meta_res or service_status %}disabled{% endif %}" name="save" type="submit">
<i class="fa fa-play"></i> {{ _('Run Transformation') }}
</button>
<!-- Status Indicator Section -->
</div>
<style>
.indicator {
width: 20px;
height: 20px;
border-radius: 50%;
background-color: red;
/* Default: Service unavailable */
}
</style>
<div class="d-flex align-items-center">
<div id="service-indicator" class="indicator" data-bs-toggle="tooltip"
title="{{ _('The status of the service (Green means available, Red means unavailable)') }}" {% if
service_status %} style="background-color: green;" {% endif %}>
</div>
</div>
</div>
</form>
{% endblock %}
{{task}}
Expand Down
4 changes: 3 additions & 1 deletion ckanext/csvtocsvw/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from flask import Blueprint
from flask.views import MethodView
from ckanext.csvtocsvw.tasks import resource_search

from ckanext.csvtocsvw.helpers import service_available

log = __import__("logging").getLogger(__name__)

Expand Down Expand Up @@ -76,6 +76,7 @@ def get(self, id: str, resource_id: str):
"pkg_dict": pkg_dict,
"resource": resource,
"status": status,
"service_status": service_available(),
},
)

Expand Down Expand Up @@ -153,6 +154,7 @@ def get(self, id: str, resource_id: str):
"meta_res": meta_res,
"resource": resource,
"status": status,
"service_status": service_available(),
},
)

Expand Down

0 comments on commit c2c9be6

Please sign in to comment.