Skip to content

Commit be22366

Browse files
committed
Improved validation
- Removed unnecessary message from validation. - Clear previous validation messages when new validation is run. Added validation dock to unload
1 parent dc6b926 commit be22366

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

arho_feature_template/gui/validation_dock.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ def __init__(self):
3030
self.error_list_view.setModel(self.error_list_model)
3131
self.validate_button.clicked.connect(self.validate)
3232

33-
def update_errors(self, errors: list[str]):
34-
"""Updates the list view with the provided validation errors."""
35-
self.error_list_model.setStringList(errors)
36-
3733
def validate(self):
3834
"""Handles the button press to trigger the validation process."""
3935
active_plan_id = get_active_plan_id()
@@ -44,36 +40,39 @@ def validate(self):
4440
self.lambda_service.validate_plan(active_plan_id)
4541

4642
def list_validation_errors(self, validation_json):
47-
"""Slot for listing validation errors."""
43+
"""Slot for listing validation errors and warnings."""
4844
if not validation_json:
49-
iface.messageBar().pushMessage("Virhe", "Ei virheitä havaittu.", level=1)
45+
iface.messageBar().pushMessage("Virhe", "Validaatio json puuttuu.", level=1)
5046
return
47+
# Clear the existing errors from the list view
48+
self.error_list_model.setStringList([])
5149

52-
current_errors = self.error_list_model.stringList()
5350
new_errors = []
5451

55-
for plan_id, error_data in validation_json.items():
56-
if isinstance(error_data, str):
57-
new_errors.append(f"Validaatio epäonnistui Kaavalle id {plan_id}: {error_data}")
58-
elif isinstance(error_data, dict):
59-
title = error_data.get("title", "Tuntematon virhe")
60-
status = error_data.get("status", "Tuntematon status")
61-
detail = error_data.get("detail", "Tietoja ei saatavilla")
62-
new_errors.append(f"Virhe kaavalla: {plan_id} - {title} ({status}): {detail}")
52+
if not validation_json:
53+
# If no errors or warnings, display a message and exit
54+
iface.messageBar().pushMessage("Virhe", "Ei virheitä havaittu.", level=1)
55+
return
6356

57+
for error_data in validation_json.values():
58+
if isinstance(error_data, dict):
59+
# Get the errors for this plan
6460
errors = error_data.get("errors", [])
6561
for error in errors:
6662
rule_id = error.get("ruleId", "Tuntematon sääntö")
6763
message = error.get("message", "Ei viestiä")
68-
instance = error.get("instance", "Tuntematon instanssi")
69-
error_message = f" Sääntö: {rule_id}, Viesti: {message}, Tapaus/instanssi: {instance}"
64+
instance = error.get("instance", "Tuntematon instance")
65+
error_message = f"Validointivirhe - Sääntö: {rule_id}, Viesti: {message}, Instance: {instance}"
7066
new_errors.append(error_message)
7167

68+
# Get any warnings for this plan using list comprehension
7269
warnings = error_data.get("warnings", [])
7370
new_errors.extend([f"Varoitus: {warning}" for warning in warnings])
7471

75-
# Append the new errors to the existing list
76-
current_errors.extend(new_errors)
72+
# If no errors or warnings, display a message
73+
if not new_errors:
74+
new_errors.append("Kaava on validi. Ei virheitä tai varoituksia havaittu.")
75+
return
7776

78-
# Update the model with the combined list of errors
79-
self.error_list_model.setStringList(current_errors)
77+
# Update the list view with the new errors and warnings
78+
self.error_list_model.setStringList(new_errors)

arho_feature_template/gui/validation_dock.ui

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
21
<ui version="4.0">
32
<class>ValidationDock</class>
43
<widget class="QDockWidget" name="ValidationDock">
@@ -8,11 +7,15 @@
87
<widget class="QWidget" name="dockWidgetContents">
98
<layout class="QVBoxLayout" name="verticalLayout">
109
<item>
11-
<widget class="QPushButton" name="validate_button">
12-
<property name="text">
13-
<string>Vahvista aktiivinen kaava</string>
14-
</property>
15-
</widget>
10+
<layout class="QHBoxLayout" name="buttonLayout">
11+
<item>
12+
<widget class="QPushButton" name="validate_button">
13+
<property name="text">
14+
<string>Validoi aktiivinen kaava</string>
15+
</property>
16+
</widget>
17+
</item>
18+
</layout>
1619
</item>
1720
<item>
1821
<widget class="QListView" name="error_list_view"/>

arho_feature_template/plugin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def initGui(self) -> None: # noqa N802
140140

141141
# Instantiate and add the Validation Dock Widget
142142
self.validation_dock = ValidationDock()
143-
iface.addDockWidget(Qt.BottomDockWidgetArea, self.validation_dock)
143+
iface.addDockWidget(Qt.RightDockWidgetArea, self.validation_dock)
144144

145145
# Connect visibilityChanged signal to sync toggle action
146146
self.validation_dock.visibilityChanged.connect(self.validation_dock_visibility_changed)
@@ -243,6 +243,7 @@ def unload(self) -> None:
243243
teardown_logger(Plugin.name)
244244

245245
self.templater.template_dock.close()
246+
self.validation_dock.close()
246247

247248
def dock_visibility_changed(self, visible: bool) -> None: # noqa: FBT001
248249
self.template_dock_action.setChecked(visible)

0 commit comments

Comments
 (0)