From cd9b4f4087f69c3a256253281d6e362fb09e18b8 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sun, 1 Sep 2024 12:52:45 +0200 Subject: [PATCH 01/11] =?UTF-8?q?simplify=20oeox=20URI=C2=B4s=20by=20remov?= =?UTF-8?q?ing=20class=20category=20->=20leads=20to=20do=20harmonized=20UR?= =?UTF-8?q?I=20for=20all=20concepts=20stored=20in=20the=20oeox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oeo_ext/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oeo_ext/utils.py b/oeo_ext/utils.py index f77d3ae8d..a0d5f6836 100644 --- a/oeo_ext/utils.py +++ b/oeo_ext/utils.py @@ -146,8 +146,8 @@ def get_new_iri( # Generate the new IRI using the count + 1 new_counter = generate_id(existing_count + 1) - # Build URI of pattern: oeox-base:ConceptLike#ConceptID - new_uri = URIRef(f"{base}{concept_type.value}/{id_prefix}{new_counter}") + # Build URI of pattern: oeox-base/ConceptID + new_uri = URIRef(f"{base}/{id_prefix}{new_counter}") return new_uri From 64ee5a96642f4cd11185ec505974f6b5f9784e2b Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sun, 1 Sep 2024 13:45:36 +0200 Subject: [PATCH 02/11] load the oeox classes each time the user requests any URI - in case of new classes --- ontology/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ontology/views.py b/ontology/views.py index 0300e1d0f..590070e9d 100644 --- a/ontology/views.py +++ b/ontology/views.py @@ -149,7 +149,10 @@ def get( if ontology in [OPEN_ENERGY_ONTOLOGY_NAME]: ontology_data = OEO_COMMON_DATA elif ontology in [OEO_EXT_NAME]: - ontology_data = OEOX_COMMON_DATA + # ontology_data = OEOX_COMMON_DATA + ontology_data = get_common_data( + OEO_EXT_NAME, file=OEO_EXT_OWL_NAME, path=OEO_EXT_PATH + ) sub_classes = [] super_classes = [] From 54ab0a3255f48e335859df1c5ec07eb539f56ec8 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sun, 1 Sep 2024 13:46:00 +0200 Subject: [PATCH 03/11] remove deprecated form context --- oeo_ext/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/oeo_ext/views.py b/oeo_ext/views.py index 9843aaad9..8e9f35fb9 100644 --- a/oeo_ext/views.py +++ b/oeo_ext/views.py @@ -66,7 +66,6 @@ def post(self, request): return JsonResponse(response_data, status=200) else: errors = { - # "form": form, "form_errors": form.errors, "nominator_errors": [f.errors for f in nominator_forms], "denominator_errors": [f.errors for f in denominator_forms], From 6db0adec17b867455f32161e39ffabeb160b6eb0 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sun, 1 Sep 2024 13:50:36 +0200 Subject: [PATCH 04/11] fix bug in oeox template --- .../oeox_template/oeo_ext_template_empty.owl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oeo_ext/oeo_extended_store/oeox_template/oeo_ext_template_empty.owl b/oeo_ext/oeo_extended_store/oeox_template/oeo_ext_template_empty.owl index d66ff83e7..8f332bfc3 100644 --- a/oeo_ext/oeo_extended_store/oeox_template/oeo_ext_template_empty.owl +++ b/oeo_ext/oeo_extended_store/oeox_template/oeo_ext_template_empty.owl @@ -5,12 +5,12 @@ xmlns:owl="http://www.w3.org/2002/07/owl#" xml:base="http://openenergy-platform.org/ontology/oeox" xmlns="http://openenergy-platform.org/ontology/oeox#" - xmlns:x_1.1="http://purl.org/dc/elements/1.1/" + xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:term="http://purl.org/dc/terms/"> - The Open Energy Ontology Extended (OEOX) extends the Open Energy Ontology. It contains compositions of terms that are too specific for the OEO. + The Open Energy Ontology Extended (OEOX) extends the Open Energy Ontology. It contains compositions of terms that are too specific for the OEO. http://creativecommons.org/publicdomain/zero/1.0/ Open Energy Ontology Extended (OEOX) From 19ac9e11ce20cfcea999638168e6ce963b92cecc Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sun, 1 Sep 2024 13:51:06 +0200 Subject: [PATCH 05/11] handle error msg after invalid form was send --- .../oeo_ext/partials/oeo-ext-plugin-ui.html | 103 +++++++++++++----- 1 file changed, 73 insertions(+), 30 deletions(-) diff --git a/oeo_ext/templates/oeo_ext/partials/oeo-ext-plugin-ui.html b/oeo_ext/templates/oeo_ext/partials/oeo-ext-plugin-ui.html index f380a3f9c..cdf285129 100644 --- a/oeo_ext/templates/oeo_ext/partials/oeo-ext-plugin-ui.html +++ b/oeo_ext/templates/oeo_ext/partials/oeo-ext-plugin-ui.html @@ -15,7 +15,6 @@

Result

Numerator

-
@@ -147,35 +146,79 @@

Denominator

// }); // }); - // document.addEventListener('htmx:afterRequest', function (event) { - // if (event.detail.xhr.status === 400) { - // let response = JSON.parse(event.detail.xhr.responseText); - // if (!response.success) { - // for (const [field, message] of Object.entries(response.errors)) { - // let errorDiv = document.getElementById(`${field}_error`); - // if (errorDiv) { - // errorDiv.innerText = message; - // errorDiv.style.display = 'block'; - // } - // let inputField = document.getElementById(field); - // if (inputField) { - // inputField.classList.add('is-invalid'); - // } - // } - // } - // } else { - // // Clear previous errors if any - // let errorFields = document.querySelectorAll('.invalid-feedback'); - // errorFields.forEach(function (field) { - // field.style.display = 'none'; - // field.innerText = ''; - // }); - // let inputFields = document.querySelectorAll('.form-control'); - // inputFields.forEach(function (field) { - // field.classList.remove('is-invalid'); - // }); - // } - // }); + document.addEventListener('htmx:afterRequest', function (event) { + if (event.detail.xhr.status === 400) { + let response = JSON.parse(event.detail.xhr.responseText); + + if (!response.success) { + // Clear previous errors + document.querySelectorAll('.invalid-feedback').forEach(errorDiv => { + errorDiv.innerText = ''; + errorDiv.style.display = 'none'; + }); + document.querySelectorAll('.form-control').forEach(inputField => { + inputField.classList.remove('is-invalid'); + }); + + // Handle nominator errors + response.errors.nominator_errors.forEach((nominatorError, index) => { + const nominatorElement = document.querySelectorAll(`#nominator-elements .unit-element`)[index]; + + if (nominatorElement && Object.keys(nominatorError).length > 0) { + Object.entries(nominatorError).forEach(([field, messages]) => { + let inputField = nominatorElement.querySelector(`.${field}`); + let errorDiv = inputField ? inputField.closest('.mb-2').querySelector('.invalid-feedback') : null; + + if (errorDiv && messages.length > 0) { + errorDiv.innerText = messages.join(', '); + errorDiv.style.display = 'block'; + } + + if (inputField) { + inputField.classList.add('is-invalid'); + } + }); + } + }); + + // Handle denominator errors + response.errors.denominator_errors.forEach((denominatorError, index) => { + const denominatorElement = document.querySelectorAll(`#denominator-elements .unit-element`)[index]; + + if (denominatorElement && Object.keys(denominatorError).length > 0) { + Object.entries(denominatorError).forEach(([field, messages]) => { + let inputField = denominatorElement.querySelector(`.${field}`); + let errorDiv = inputField ? inputField.closest('.mb-2').querySelector('.invalid-feedback') : null; + + if (errorDiv && messages.length > 0) { + errorDiv.innerText = messages.join(', '); + errorDiv.style.display = 'block'; + } + + if (inputField) { + inputField.classList.add('is-invalid'); + } + }); + } + }); + } + } else { + // Clear previous errors if any + let errorFields = document.querySelectorAll('.invalid-feedback'); + errorFields.forEach(function (field) { + field.style.display = 'none'; + field.innerText = ''; + }); + let inputFields = document.querySelectorAll('.form-control'); + inputFields.forEach(function (field) { + field.classList.remove('is-invalid'); + }); + } + }); + + + + initializeUnitElement(document); // Initialize existing elements From 751bff517d8c64934e45ca76cdb6ac4989d7e546 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sun, 1 Sep 2024 13:51:20 +0200 Subject: [PATCH 06/11] update changelog --- versions/changelogs/current.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/versions/changelogs/current.md b/versions/changelogs/current.md index f179bd2be..0e4502c07 100644 --- a/versions/changelogs/current.md +++ b/versions/changelogs/current.md @@ -2,8 +2,8 @@ ## Changes - - Enhance embargo area feature (UI & API) [(#1804)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1804) + - Refactor code - The REST API raises an error when creating a table with embargo period but false date time for start/end data - Update the table creation http "put" endpoint to handle embargo periods @@ -12,11 +12,12 @@ - Enhance the ontology pages, remove the modules page and fully rework the about page and oeo download capabilities. Additionally add the oeox and make its URIs available, also add more cases where a Http404 is raised to make [1807](https://github.com/OpenEnergyPlatform/oeplatform/pull/1807) - ## Features - Add the OEP-extended (oeo-ext) feature. It enables users to create new composed units (ontology classes) that extent the units available in the OEO. The feature is implemented as a plugin html form, it can be easily added to any Webpage of the oeplatform. [(#1680)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1680) +- Add error message display to oeox-plugin view. [(#)](https://github.com/OpenEnergyPlatform/oeplatform/pull/) + ## Bugs ## Documentation updates From 7cfe6b0308693188fd7006bffa48a839a590ef71 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sun, 1 Sep 2024 14:39:40 +0200 Subject: [PATCH 07/11] enhance success / error rendering after form was submitted successfully or empty (causing an error) --- oeo_ext/templates/oeo_ext/partials/success.html | 11 +++++++++++ oeo_ext/views.py | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 oeo_ext/templates/oeo_ext/partials/success.html diff --git a/oeo_ext/templates/oeo_ext/partials/success.html b/oeo_ext/templates/oeo_ext/partials/success.html new file mode 100644 index 000000000..e26e82347 --- /dev/null +++ b/oeo_ext/templates/oeo_ext/partials/success.html @@ -0,0 +1,11 @@ +
+ {% if response_data.success %} +

{{ response_data.message }}

+

Your new unit has been created successfully.

+

New Composed Unit URI:

+

{{ response_data.newComposedUnitURI }}

+ {% else %} +

{{ response_data.message }}

+

{{ response_data.errors.error }}

+ {% endif %} +
\ No newline at end of file diff --git a/oeo_ext/views.py b/oeo_ext/views.py index 8e9f35fb9..600b5577f 100644 --- a/oeo_ext/views.py +++ b/oeo_ext/views.py @@ -59,11 +59,21 @@ def post(self, request): # error is either dict with key:value or None new_unit, error = create_new_unit(numerator=n, denominator=d) if error: - response_data = error + # response_data = error + response_data = { + "success": False, + "message": "Form data is not valid!", + "errors": error, + } else: data["newComposedUnitURI"] = new_unit response_data = data - return JsonResponse(response_data, status=200) + return render( + request, + "oeo_ext/partials/success.html", + {"response_data": response_data}, + ) + # return JsonResponse(response_data, status=200) else: errors = { "form_errors": form.errors, From 3ee201ac8e092d3e4cb69f9f40079b2c59e1888e Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sun, 1 Sep 2024 14:40:05 +0200 Subject: [PATCH 08/11] remove deprecated / from oeox URI creation function --- oeo_ext/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oeo_ext/utils.py b/oeo_ext/utils.py index a0d5f6836..53627c96f 100644 --- a/oeo_ext/utils.py +++ b/oeo_ext/utils.py @@ -147,7 +147,7 @@ def get_new_iri( # Generate the new IRI using the count + 1 new_counter = generate_id(existing_count + 1) # Build URI of pattern: oeox-base/ConceptID - new_uri = URIRef(f"{base}/{id_prefix}{new_counter}") + new_uri = URIRef(f"{base}{id_prefix}{new_counter}") return new_uri From eca266093cbecc0bd592a1e4ad47a7376f319bdd Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sun, 1 Sep 2024 14:40:25 +0200 Subject: [PATCH 09/11] only replace the form field --- oeo_ext/templates/oeo_ext/partials/oeo-ext-plugin-ui.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/oeo_ext/templates/oeo_ext/partials/oeo-ext-plugin-ui.html b/oeo_ext/templates/oeo_ext/partials/oeo-ext-plugin-ui.html index cdf285129..bdc97fb4f 100644 --- a/oeo_ext/templates/oeo_ext/partials/oeo-ext-plugin-ui.html +++ b/oeo_ext/templates/oeo_ext/partials/oeo-ext-plugin-ui.html @@ -8,7 +8,7 @@

Result


-
+ {% csrf_token %}
@@ -46,6 +46,7 @@

Denominator

+