diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a66ef9c1..7e59b633 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,12 +85,19 @@ jobs: cd backend python3.11 -m venv venv + - name: Install system libraries for the PDF report (WeasyPrint) + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends libpango-1.0-0 libpangoft2-1.0-0 libharfbuzz-subset0 fonts-dejavu-core + - name: Install packages run: | cd backend source venv/bin/activate pip install --upgrade pip find . -name 'requirements.txt' -exec pip install -r {} \; + # test-only PDF inspection tools; versions come from requirements-dev.txt + grep -E '^(pypdf|PyMuPDF)' requirements-dev.txt | xargs pip install - name: Install ifcopenshell package (temp) run: | @@ -125,3 +132,9 @@ jobs: python3 -m pytest apps/ifc_validation/checks/statistics/tests -v MEDIA_ROOT=./apps/ifc_validation/fixtures python3 manage.py test apps.ifc_validation_bff.tests.tests_report_view --settings apps.ifc_validation_bff.tests.test_settings --debug-mode --verbosity 3 MEDIA_ROOT=./apps/ifc_validation/fixtures python3 manage.py test apps.ifc_validation_bff.tests.tests_step_lines --settings apps.ifc_validation_bff.tests.test_settings --debug-mode --verbosity 3 + MEDIA_ROOT=./apps/ifc_validation/fixtures python3 manage.py test apps.ifc_validation_bff.tests.tests_ui --settings apps.ifc_validation_bff.tests.test_settings --debug-mode --verbosity 3 + MEDIA_ROOT=./apps/ifc_validation/fixtures python3 manage.py test apps.ifc_validation_bff.tests.tests_report_html --settings apps.ifc_validation_bff.tests.test_settings --debug-mode --verbosity 3 + MEDIA_ROOT=./apps/ifc_validation/fixtures python3 manage.py test apps.ifc_validation_bff.tests.tests_report_pdf --settings apps.ifc_validation_bff.tests.test_settings --debug-mode --verbosity 3 + MEDIA_ROOT=./apps/ifc_validation/fixtures python3 manage.py test apps.ifc_validation_bff.tests.tests_report_values --settings apps.ifc_validation_bff.tests.test_settings --debug-mode --verbosity 3 + MEDIA_ROOT=./apps/ifc_validation/fixtures python3 manage.py test apps.ifc_validation_bff.tests.tests_model_summary --settings apps.ifc_validation_bff.tests.test_settings --debug-mode --verbosity 3 + MEDIA_ROOT=./apps/ifc_validation/fixtures python3 manage.py test apps.ifc_validation.tests.tests_file_retention_task --settings apps.ifc_validation.test_settings --debug-mode --verbosity 3 diff --git a/.github/workflows/playwright-htmx.yml b/.github/workflows/playwright-htmx.yml new file mode 100644 index 00000000..c24620ba --- /dev/null +++ b/.github/workflows/playwright-htmx.yml @@ -0,0 +1,213 @@ +name: Playwright HTMX Tests +on: + workflow_dispatch: + push: + branches: development + paths-ignore: + - 'README.md' + - '.github/workflows/ci.yml' + - '.github/workflows/ci_cd.yml' + pull_request: + branches: development + +permissions: + contents: read + actions: read + checks: write + pull-requests: write + +jobs: + playwright: + name: 'HTMX (${{ matrix.mount }})' + strategy: + fail-fast: false + matrix: + include: + - frontend_mode: htmx + mount: / + - frontend_mode: react + mount: /v2/ + runs-on: ubuntu-latest + container: + image: mcr.microsoft.com/playwright:v1.60.0-noble + env: + # Exercise the HTMX UI at / and /v2/; neither job starts React. + FRONTEND_MODE: ${{ matrix.frontend_mode }} + DJANGO_DB: postgresql + POSTGRES_DB: postgres + POSTGRES_HOST: postgres + POSTGRES_NAME: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_PORT: 5432 + MEDIA_ROOT: /tmp/files_storage + CELERY_BROKER_URL: redis://redis:6379/0 + CELERY_RESULT_BACKEND: django-db + DJANGO_ALLOWED_HOSTS: "localhost 127.0.0.1" + DJANGO_TRUSTED_ORIGINS: "http://localhost:3000 http://127.0.0.1:3000 http://localhost:8000 http://127.0.0.1:8000" + POSTGRES_USER: postgres + VIRTUAL_ENV: backend/.dev/venv + HTMX_BASE_URL: http://localhost:8000${{ matrix.mount }} + HTMX_SERVER_COMMAND: .dev/venv/bin/python manage.py runserver 8000 --noreload + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + services: + postgres: + image: postgres:16.8-alpine + env: + POSTGRES_DB: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + --network-alias postgres + ports: + - 5432:5432 + redis: + image: redis:8.4-alpine + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 6379:6379 + volumes: + - redis_data:/data + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Prepare MEDIA_ROOT + run: | + mkdir -p /tmp/files_storage + chmod -R 777 /tmp/files_storage + + - name: Install system dependencies + run: | + apt-get update + apt-get install -y make wget unzip libpq-dev libpango-1.0-0 libpangoft2-1.0-0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/* + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.11 + + - name: Create venv + run: | + cd backend + python3.11 -m venv .dev/venv --clear + echo "venv/bin folder content:" + ls -l .dev/venv/bin + + - name: Install backend dependencies + run: | + cd backend + . .dev/venv/bin/activate + pip install --upgrade pip + find . -name 'requirements.txt' -exec pip install -r {} \; + + - name: Download and install ifcopenshell + run: | + wget -O /tmp/ifcopenshell_python.zip "https://s3.amazonaws.com/ifcopenshell-builds/ifcopenshell-python-311-v0.8.6-8b5b400-linux64.zip" + mkdir -p .dev/venv/lib/python3.11/site-packages + unzip -o -d .dev/venv/lib/python3.11/site-packages /tmp/ifcopenshell_python.zip + rm /tmp/ifcopenshell_python.zip + make install-ifcopenshell-mvd IFCOPENSHELL_SITE_PACKAGES=.dev/venv/lib/python3.11/site-packages + # Verify installation + ls -la .dev/venv/lib/python3.11/site-packages/ + echo "Checking for ifcopenshell installation:" + find .dev/venv/lib/python3.11/site-packages -name "*ifcopenshell*" || echo "No ifcopenshell files found" + working-directory: ./backend + + - name: Cache e2e dependencies + uses: actions/cache@v4 + with: + path: e2e/node_modules + key: ${{ runner.os }}-e2e-${{ hashFiles('e2e/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-e2e- + + - name: Install e2e dependencies (replicating make e2e-test) + run: npm install + working-directory: ./e2e + + - name: Setup Django database, migrations, and superusers + run: | + cd backend + .dev/venv/bin/python manage.py migrate + .dev/venv/bin/python manage.py collectstatic --noinput + DJANGO_SUPERUSER_USERNAME=root DJANGO_SUPERUSER_PASSWORD=root DJANGO_SUPERUSER_EMAIL=root@localhost .dev/venv/bin/python manage.py createsuperuser --noinput + DJANGO_SUPERUSER_USERNAME=SYSTEM DJANGO_SUPERUSER_PASSWORD=system DJANGO_SUPERUSER_EMAIL=system@localhost .dev/venv/bin/python manage.py createsuperuser --noinput || echo "SYSTEM user already exists, skipping" + .dev/venv/bin/python manage.py seed_dummy_requests + env: + DJANGO_DB: postgresql + POSTGRES_HOST: postgres + POSTGRES_NAME: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_PORT: 5432 + VIRTUAL_ENV: backend/.dev/venv + + - name: Check admin routes in both frontend modes + working-directory: ./backend + run: | + for mode in react htmx; do + FRONTEND_MODE=$mode .dev/venv/bin/python manage.py test core.tests.test_urls + done + + - name: Start Celery worker + run: | + cd backend + nohup .dev/venv/bin/python -m celery --app=core worker \ + --loglevel=INFO --concurrency 2 --hostname=worker@%n \ + > /tmp/celery.log 2>&1 & + sleep 3 + env: + DJANGO_DB: postgresql + POSTGRES_HOST: postgres + POSTGRES_NAME: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_PORT: 5432 + VIRTUAL_ENV: backend/.dev/venv + + - name: Run HTMX end-to-end tests + run: npm run test:htmx + working-directory: ./e2e + env: + DJANGO_DB: postgresql + POSTGRES_HOST: postgres + POSTGRES_NAME: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_PORT: 5432 + + - name: Run standalone HTMX browser fixtures + working-directory: ./e2e + run: | + export PATH="$GITHUB_WORKSPACE/backend/.dev/venv/bin:$PATH" + export HTMX_BASE_URL="http://localhost:8765${{ matrix.mount }}" + npm run test:htmx-fixtures + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: playwright-htmx-${{ matrix.frontend_mode }} + path: | + e2e/test-results/htmx/ + e2e/test-results/htmx-fixtures/ + e2e/playwright-report/htmx/ + /tmp/celery.log + retention-days: 7 diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index efb3447b..0cf63711 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -22,6 +22,8 @@ jobs: container: image: mcr.microsoft.com/playwright:v1.60.0-noble env: + # This suite exercises the React UI; HTMX has its own report-parity suite. + FRONTEND_MODE: react DJANGO_DB: postgresql POSTGRES_DB: postgres POSTGRES_HOST: postgres @@ -159,6 +161,13 @@ jobs: POSTGRES_PORT: 5432 VIRTUAL_ENV: backend/.dev/venv + - name: Check admin routes in both frontend modes + working-directory: ./backend + run: | + for mode in react htmx; do + FRONTEND_MODE=$mode .dev/venv/bin/python manage.py test core.tests.test_urls + done + - name: Start Celery worker run: | cd backend diff --git a/Makefile b/Makefile index 2844df16..20be65b9 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ stop: REGISTRY ?= localhost:5000 WORKERS ?= 2 ENV_FILE ?= .env -SWARM_VARS = REGISTRY CERTBOT_DOMAIN CERTBOT_EMAIL NFS_SERVER_IP TEXTFILE_DIR NFS_BASE_PATH WORKER_CPU_LIMIT WORKER_MEMORY_LIMIT WORKER_CPU_RESERVATION WORKER_MEMORY_RESERVATION WORKER_REPLICAS BACKEND_MEMORY_LIMIT SCHEDULER_MEMORY_LIMIT AV_WORKER_MEMORY_LIMIT +SWARM_VARS = FRONTEND_MODE REGISTRY CERTBOT_DOMAIN CERTBOT_EMAIL NFS_SERVER_IP TEXTFILE_DIR NFS_BASE_PATH WORKER_CPU_LIMIT WORKER_MEMORY_LIMIT WORKER_CPU_RESERVATION WORKER_MEMORY_RESERVATION WORKER_REPLICAS BACKEND_MEMORY_LIMIT SCHEDULER_MEMORY_LIMIT AV_WORKER_MEMORY_LIMIT SWARM_ENV = ENV_FILE="$(ENV_FILE)" $(foreach v,$(SWARM_VARS),$(v)="$(shell grep '^$(v)=' $(ENV_FILE) | head -1 | cut -d= -f2-)") start-swarm: diff --git a/backend/Makefile b/backend/Makefile index 4c93db89..448d362b 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -81,7 +81,7 @@ stop-worker: -$(PYTHON) -m celery -A core control shutdown \ --destination=worker@$(shell hostname) || true -test: test-models test-header-validation-task test-syntax-task test-syntax-header-validation-task test-schema-task test-magic-and-av-task test-utils test-file-retention-task test-status-combine test-management-commands test-report-views +test: test-models test-header-validation-task test-syntax-task test-syntax-header-validation-task test-schema-task test-magic-and-av-task test-utils test-file-retention-task test-status-combine test-management-commands test-report-views test-ui-and-reports test-models: MEDIA_ROOT=./apps/ifc_validation/fixtures $(PYTHON) manage.py test apps/ifc_validation_models --settings apps.ifc_validation_models.test_settings --debug-mode --verbosity 3 @@ -113,6 +113,11 @@ test-management-commands: test-report-views: MEDIA_ROOT=./apps/ifc_validation/fixtures $(PYTHON) manage.py test apps.ifc_validation_bff.tests.tests_report_view --settings apps.ifc_validation_bff.tests.test_settings --debug-mode --verbosity 3 +# HTMX UI, HTML report and PDF report. The PDF tests need the test-only packages: +# pip install $$(grep -E '^(pypdf|PyMuPDF)' requirements-dev.txt) +test-ui-and-reports: + MEDIA_ROOT=./apps/ifc_validation/fixtures $(PYTHON) manage.py test apps.ifc_validation_bff.tests.tests_ui apps.ifc_validation_bff.tests.tests_report_html apps.ifc_validation_bff.tests.tests_report_pdf apps.ifc_validation_bff.tests.tests_report_values apps.ifc_validation_bff.tests.tests_model_summary apps.ifc_validation_bff.tests.tests_step_lines --settings apps.ifc_validation_bff.tests.test_settings --debug-mode --verbosity 3 + test-utils: $(PYTHON) manage.py test core.tests.test_utils --debug-mode --verbosity 3 diff --git a/backend/apps/ifc_validation/management/commands/apply_file_retention.py b/backend/apps/ifc_validation/management/commands/apply_file_retention.py index 25f0505c..187b29e9 100644 --- a/backend/apps/ifc_validation/management/commands/apply_file_retention.py +++ b/backend/apps/ifc_validation/management/commands/apply_file_retention.py @@ -183,4 +183,4 @@ def handle(self, *args, **options): else: logger.info( f"Completed {mode_str} of {processed}, skipped {skipped}, total considered {total}. Freed up {savings_str}." - ) \ No newline at end of file + ) diff --git a/backend/apps/ifc_validation/tasks/report_tasks.py b/backend/apps/ifc_validation/tasks/report_tasks.py new file mode 100644 index 00000000..979703a5 --- /dev/null +++ b/backend/apps/ifc_validation/tasks/report_tasks.py @@ -0,0 +1,25 @@ +"""Post-validation exports. A rendering failure never changes validation results.""" +from celery import shared_task +from celery.exceptions import SoftTimeLimitExceeded + +from apps.ifc_validation_models.decorators import requires_django_user_context + +from .logger import logger + + +# acks_late=False: with the global acks_late + reject_on_worker_lost, a render whose worker +# is killed (e.g. out of memory) would be redelivered without end. +@shared_task(bind=True, max_retries=2, soft_time_limit=120, time_limit=150, acks_late=False) +@requires_django_user_context +def generate_validation_report(self, request_id): + from apps.ifc_validation_bff.report.pdf import generate_pdf + + try: + path = generate_pdf(request_id) + return str(path) if path else None + except SoftTimeLimitExceeded: + # A report that does not render within the limit will not render on a retry either. + logger.warning(f"PDF for validation request {request_id} exceeded the time limit; not retrying.") + return None + except Exception as error: + raise self.retry(exc=error, countdown=30 * (self.request.retries + 1)) diff --git a/backend/apps/ifc_validation/tasks/task_runner.py b/backend/apps/ifc_validation/tasks/task_runner.py index 64c8a605..40ae3c80 100644 --- a/backend/apps/ifc_validation/tasks/task_runner.py +++ b/backend/apps/ifc_validation/tasks/task_runner.py @@ -19,6 +19,7 @@ from .logger import logger from .email_tasks import * from .file_retention_tasks import * +from .report_tasks import generate_validation_report def terminate_subprocesses(): @@ -149,6 +150,10 @@ def on_workflow_completed(self, result, **kwargs): # queue sending email send_completion_email_task.delay(id=id, file_name=request.file_name) + # The immutable export is a post-validation artifact, outside the check registry + # and its progress/blocker semantics. PDF errors are retried independently. + generate_validation_report.delay(request_id=id) + @shared_task(bind=True) @log_execution @@ -174,6 +179,8 @@ def on_workflow_failed(self, *args, **kwargs): reason += f" Error: {exc}" request.mark_as_failed(reason) + generate_validation_report.delay(request_id=id) + # queue sending email send_failure_email_task.delay(id=id, file_name=request.file_name) send_failure_admin_email_task.delay(id=id, file_name=request.file_name) diff --git a/backend/apps/ifc_validation/tests/tests_file_retention_task.py b/backend/apps/ifc_validation/tests/tests_file_retention_task.py index aa0e0d76..f01554d9 100644 --- a/backend/apps/ifc_validation/tests/tests_file_retention_task.py +++ b/backend/apps/ifc_validation/tests/tests_file_retention_task.py @@ -1,6 +1,10 @@ from io import StringIO +from pathlib import Path +import shutil +import tempfile +from unittest.mock import patch -from django.test import TransactionTestCase +from django.test import TransactionTestCase, override_settings from django.contrib.auth.models import User from apps.ifc_validation_models.models import * @@ -10,6 +14,21 @@ class ApplyFileRetentionTaskTestCase(TransactionTestCase): + def setUp(self): + directory = tempfile.TemporaryDirectory() + self.addCleanup(directory.cleanup) + shutil.copyfile(Path(__file__).parent.parent / 'fixtures' / 'valid_file.ifc', + Path(directory.name) / 'valid_file.ifc') + settings = override_settings(MEDIA_ROOT=directory.name) + settings.enable() + self.addCleanup(settings.disable) + files = patch('apps.ifc_validation.tasks.utils.MEDIA_ROOT', directory.name) + files.start() + self.addCleanup(files.stop) + from ..tasks.utils import get_absolute_file_path + get_absolute_file_path.cache_clear() + self.addCleanup(get_absolute_file_path.cache_clear) + def set_user_context(): user, _ = User.objects.get_or_create(id=1, defaults={'username': 'SYSTEM', 'is_active': True}) set_user_context(user) @@ -65,6 +84,11 @@ def test_apply_file_retention_remove_sets_file_removed_field(self): ) request.created = timezone.now() - timezone.timedelta(days=250) request.save() + + from apps.ifc_validation_bff.report.pdf import artifact_path + report = artifact_path(request) + report.parent.mkdir(parents=True, exist_ok=True) + report.write_bytes(b'%PDF-test') # act task = apply_file_retention(dry_run=False, action="remove") @@ -72,6 +96,7 @@ def test_apply_file_retention_remove_sets_file_removed_field(self): # assert request = ValidationRequest.objects.get(id=request.id) self.assertIsNotNone(request.file_removed) + self.assertTrue(report.exists()) # the PDF outlives the IFC file def test_apply_file_retention_remove_retains_removed_field(self): diff --git a/backend/apps/ifc_validation/tests/tests_orphan_failed_request.py b/backend/apps/ifc_validation/tests/tests_orphan_failed_request.py index 8f2819bd..7a799aa2 100644 --- a/backend/apps/ifc_validation/tests/tests_orphan_failed_request.py +++ b/backend/apps/ifc_validation/tests/tests_orphan_failed_request.py @@ -29,6 +29,11 @@ class OrphanFailedRequestElegantTestCase(TestCase): + def setUp(self): + export = patch('apps.ifc_validation.tasks.task_runner.generate_validation_report') + self.export = export.start() + self.addCleanup(export.stop) + @staticmethod def _set_user_context(): user, _ = User.objects.get_or_create( @@ -91,6 +96,7 @@ def test_double_fire_is_idempotent(self, mock_user_email, mock_admin_email): "failure email must be sent exactly once across both firings") self.assertEqual(mock_admin_email.delay.call_count, 1, "admin failure email must be sent exactly once across both firings") + self.export.delay.assert_called_once_with(request_id=request.id) # --- when an exception is available it is surfaced in the reason --- @patch('apps.ifc_validation.tasks.task_runner.send_failure_admin_email_task') diff --git a/backend/apps/ifc_validation_bff/datamodel/__init__.py b/backend/apps/ifc_validation_bff/datamodel/__init__.py new file mode 100644 index 00000000..b4b1e148 --- /dev/null +++ b/backend/apps/ifc_validation_bff/datamodel/__init__.py @@ -0,0 +1 @@ +"""Materialized inputs and content shared by the HTML UI and reports.""" diff --git a/backend/apps/ifc_validation_bff/datamodel/load.py b/backend/apps/ifc_validation_bff/datamodel/load.py new file mode 100644 index 00000000..b66aa95b --- /dev/null +++ b/backend/apps/ifc_validation_bff/datamodel/load.py @@ -0,0 +1,201 @@ +"""Load ORM, configuration and file inputs for the HTML UI and reports.""" +from __future__ import annotations + +import os +import re +from dataclasses import replace + +from django.conf import settings +from django.db.models import Count, F, Window +from django.db.models.functions import RowNumber +from django.utils import timezone + +from apps.ifc_validation_models.models import Model, ValidationOutcome, ValidationRequest, ValidationTask, WhiteListEntry +from ..report.gherkin_lookup import get_feature_description, get_feature_url +from ..status import status_combine +from ..step_lines import add_step_lines, can_view_step_lines +from ..ui.build import build_dashboard, can_delete +from .model_summary import ModelSummary +from .report import CheckStatus, GherkinDescription, IfcInstance, OutcomeInput, OutcomeSeverity, ReportInput, ReportKind, SourceLocation +from .ui import Allowlist, AllowlistEntry, AllowlistPattern, DashboardEntry, DashboardOptions, Shell, UploadPolicy, Viewer + + +def load_model_summary(request: ValidationRequest) -> ModelSummary: + """Materialize metadata and combined check states for the HTML frontend. + + The legacy JSON projection remains in views_legacy.format_request. Keep its + pending policy here too: a check that has not run remains pending while the + request is unfinished, and cannot hide a warning or error from a sibling. + """ + model = request.model + unfinished = request.status not in (ValidationRequest.Status.COMPLETED, ValidationRequest.Status.FAILED) + + def status(attribute: str) -> CheckStatus: + value = getattr(model, attribute) if model is not None else None + return "p" if value is None else value + + def pending(value: CheckStatus) -> CheckStatus: + return "p" if unfinished and value == "n" else value + + return ModelSummary( + request_id=request.public_id, + file_name=request.file_name, + size_bytes=request.size, + created=request.created, + status=request.status, + progress=request.progress, + header=model.header_validation or {} if model is not None else {}, + header_status=pending(status("status_header")), + signatures_status=pending(status("status_signatures")), + security_status=pending(status("status_magic_clamav")), + syntax_status=status_combine( + status("status_syntax"), status("status_header_syntax"), + allow_not_executed=request.status == ValidationRequest.Status.COMPLETED, + ), + schema_status=pending(status_combine(status("status_schema_calculated"), status("status_prereq"))), + normative_status=pending(status_combine(status("status_ia_calculated"), status("status_ip_calculated"))), + industry_status=pending(status("status_industry_practices")), + ) + + +def load_report(validation_request: ValidationRequest, kind: ReportKind, viewer=None, *, include_successful_syntax=False) -> ReportInput: + """Read each selected task once, and fetch instances/allowlisting in bulk.""" + summary = load_model_summary(validation_request) + model = validation_request.model + task_types = { + "file": (ValidationTask.Type.DIGITAL_SIGNATURES,), + "schema": (ValidationTask.Type.SCHEMA, ValidationTask.Type.PREREQUISITES), + "normative": (ValidationTask.Type.NORMATIVE_IA, ValidationTask.Type.NORMATIVE_IP), + "industry": (ValidationTask.Type.INDUSTRY_PRACTICES,), + "syntax": (), + }[kind] + if kind == "syntax" and include_successful_syntax: + task_types = (ValidationTask.Type.HEADER_SYNTAX, ValidationTask.Type.SYNTAX) + elif kind == "syntax" and model: + if model.status_header_syntax == Model.Status.INVALID: + task_types = (ValidationTask.Type.HEADER_SYNTAX,) + elif model.status_syntax == Model.Status.INVALID: + task_types = (ValidationTask.Type.SYNTAX,) + + latest = {} + for task_type, task_id in validation_request.tasks.filter(type__in=task_types).order_by("-id").values_list("type", "id"): + latest.setdefault(task_type, task_id) + stored = ValidationOutcome.objects.filter(validation_task_id__in=latest.values()).with_effective_severity() + counts = None + if kind in ("schema", "normative", "industry"): + # A task can hold hundreds of thousands of outcomes under one rule, of which a report + # shows `MAX_OUTCOMES_PER_RULE`. Let the database count them and return only the first + # rows of every (task, feature, severity) group. Every ordering used downstream is by + # severity and then by id, so the rows it would pick are always among these. + # The window query selects ids only: sorting whole rows is far slower on large tasks. + partition = [F(name) for name in ("validation_task_id", "feature", "severity_in_db", "effective_severity")] + first = (stored.annotate(position=Window(RowNumber(), partition_by=partition, order_by=F("id").asc()), + n=Window(Count("id"), partition_by=partition)) + .filter(position__lte=settings.MAX_OUTCOMES_PER_RULE) + .values_list("id", "validation_task__type", "feature", "severity_in_db", "effective_severity", "n")) + counts, ids = {}, [] + for id, task_type, feature, severity_in_db, effective_severity, n in first: + ids.append(id) + counts[task_type, feature, severity_in_db, effective_severity] = n + stored = stored.filter(id__in=ids) + outcomes = list(stored.select_related("instance", "validation_task").order_by("validation_task_id", "id")) + sources = {} + if kind in ("schema", "normative", "industry") and outcomes and can_view_step_lines(viewer): + sources = { + o.instance.public_id: {"guid": f"#{o.instance.stepfile_id}", "type": o.instance.ifc_type} + for o in outcomes if o.instance is not None + } + # add_step_lines enriches the sources dictionary with line information read from the model when still available + add_step_lines(sources, validation_request) + + def finding(outcome) -> OutcomeInput: + instance = outcome.instance + source = sources.get(instance.public_id, {}) if instance else {} + location = SourceLocation(source["line"], source["step_line"]) if source.get("step_line") else None + return OutcomeInput( + task_type=outcome.validation_task.type, feature=outcome.feature, + severity_in_db=OutcomeSeverity(outcome.severity_in_db), + allowlisted=outcome.effective_severity != outcome.severity_in_db, + expected=outcome.expected, observed=outcome.observed, + instance=IfcInstance(instance.stepfile_id, instance.ifc_type, location) if instance else None, + ) + + rule_codes = {o.feature[:6] for o in outcomes if o.feature} if kind in ("normative", "industry") else set() + return ReportInput( + request_id=summary.request_id, file_name=summary.file_name, + size_bytes=summary.size_bytes, created=summary.created, + header=summary.header, + status={"syntax": summary.syntax_status, "schema": summary.schema_status, + "normative": summary.normative_status, "industry": summary.industry_status, + "file": summary.header_status}[kind], + outcomes=tuple(map(finding, outcomes)), + rules={code: GherkinDescription(get_feature_description(code), get_feature_url(code)) for code in rule_codes}, + outcome_limit=settings.MAX_OUTCOMES_PER_RULE, + counts=counts, + ) + + +def upload_policy() -> UploadPolicy: + from core.settings import MAX_FILES_PER_UPLOAD, MAX_FILE_SIZE_IN_MB + return UploadPolicy(getattr(settings, "MAX_FILES_PER_UPLOAD", MAX_FILES_PER_UPLOAD), + getattr(settings, "MAX_FILE_SIZE_IN_MB", MAX_FILE_SIZE_IN_MB)) + + +def load_shell(request, user, title: str, active_page: str) -> Shell: + def viewer(): + if user is None: + return None + names = (user.first_name, user.last_name) + return Viewer(" ".join(names).strip() or user.username, user.email, + "".join(name[:1] for name in names) or user.username[:1], + user.useradditionalinfo.is_vendor_self_declared is None) + + current = viewer() + version, commit = os.environ.get("VERSION", ""), os.environ.get("GIT_COMMIT_HASH", "") + return Shell(title, active_page, current, request.get_host().split(".")[0], version, commit) + + +def dashboard_options(query) -> DashboardOptions: + def integer(name, default): + try: + return int(query.get(name, default)) + except (ValueError, TypeError): + return default + size = integer("per_page", 5) + return DashboardOptions(max(1, integer("page", 1)), size if size in (5, 10, 25) else 5, + tuple(dict.fromkeys(query.getlist("selected")))) + + +def load_dashboard(user, options: DashboardOptions): + from ..report.pdf import artifact_path + + requests = ValidationRequest.objects.filter(created_by=user, deleted=False) + count = requests.count() + options = replace(options, page=min(options.page, max(1, (count + options.per_page - 1) // options.per_page))) + start = (options.page - 1) * options.per_page + page = requests.select_related("model", "created_by", "model__produced_by").order_by("-created", "-id")[start:start + options.per_page] + + def materialize(item): + summary = load_model_summary(item) + ready = item.has_final_status and not item.file_removed and artifact_path(item).is_file() + pending = bool(item.has_final_status and not item.file_removed and not ready and item.completed and + (timezone.now() - item.completed).total_seconds() < 300) + return DashboardEntry(summary.request_id, summary.file_name, summary.created, summary.status, summary.progress, + summary.header_status, bool(summary.header.get("validation_errors")), + summary.signatures_status, summary.syntax_status, summary.schema_status, + summary.normative_status, summary.industry_status, ready, pending) + + ids = [ValidationRequest.to_private_id(id) for id in options.selected if re.fullmatch(r"r\d{1,20}", id)] + selected = tuple(item.public_id for item in requests.filter(pk__in=ids).order_by("id") if can_delete(item.status, item.progress)) + return build_dashboard(tuple(map(materialize, page)), count, options, selected) + + +def load_allowlist() -> Allowlist: + def humanize(value): + return value.replace("__", " / ").replace("_", " ").split()[-1] + return Allowlist(tuple( + AllowlistEntry(entry.id, entry.description or f"Entry {entry.id}", tuple( + AllowlistPattern(humanize(fragment.column), humanize(fragment.operation), fragment.right_hand_side or "") + for fragment in entry.fragments.all() + )) for entry in WhiteListEntry.objects.prefetch_related("fragments").order_by("id") + )) diff --git a/backend/apps/ifc_validation_bff/datamodel/model_summary.py b/backend/apps/ifc_validation_bff/datamodel/model_summary.py new file mode 100644 index 00000000..721b560a --- /dev/null +++ b/backend/apps/ifc_validation_bff/datamodel/model_summary.py @@ -0,0 +1,25 @@ +"""Request metadata and model validation states used by the HTML frontend.""" +from dataclasses import dataclass +from datetime import datetime + +from .report import CheckStatus, JSONValue + + +@dataclass(frozen=True, slots=True, kw_only=True) +class ModelSummary: + """Capture a request's file metadata and combined model states without ORM objects.""" + + request_id: str + file_name: str + size_bytes: int + created: datetime + status: str + progress: int | None + header: dict[str, JSONValue] + header_status: CheckStatus + signatures_status: CheckStatus + security_status: CheckStatus + syntax_status: CheckStatus + schema_status: CheckStatus + normative_status: CheckStatus + industry_status: CheckStatus diff --git a/backend/apps/ifc_validation_bff/datamodel/report.py b/backend/apps/ifc_validation_bff/datamodel/report.py new file mode 100644 index 00000000..3e43ff8f --- /dev/null +++ b/backend/apps/ifc_validation_bff/datamodel/report.py @@ -0,0 +1,498 @@ +"""Report content, independent of Django, HTML cells, and JSON serialization. + +Rows describe outcomes. Templates own columns, labels, links, and markup. Gherkin values +are primitives or named IFC concepts, never a universal display-cell hierarchy. +""" +from __future__ import annotations + +import json +from dataclasses import dataclass +from datetime import datetime +from itertools import groupby, islice +from collections.abc import Callable, Iterable +from enum import IntEnum +from typing import Generic, Literal, TypeAlias, TypeVar + +ReportKind = Literal["file", "syntax", "schema", "normative", "industry"] +CheckStatus = Literal["v", "i", "w", "n", "p", "-"] +Scalar: TypeAlias = str | int | float | bool +JSONValue: TypeAlias = Scalar | None | list["JSONValue"] | dict[str, "JSONValue"] + + +class OutcomeSeverity(IntEnum): + """Classify validation outcomes from not applicable through error.""" + + NOT_APPLICABLE = 0 + EXECUTED = 1 + PASSED = 2 + WARNING = 3 + ERROR = 4 + + +@dataclass(frozen=True, slots=True) +class SourceLocation: + """Locate an IFC statement within its STEP source file.""" + + line_number: int + statement: str + + +@dataclass(frozen=True, slots=True) +class IfcInstance: + """Identify an IFC instance and its optional source location.""" + + step_id: int + entity: str + source: SourceLocation | None = None + + +@dataclass(frozen=True, slots=True) +class AttributeValue: + """Preserve an explicitly wrapped scalar attribute value.""" + + value: Scalar + + +@dataclass(frozen=True, slots=True) +class AllowedValues: + """Describe permitted values and their optional context.""" + + values: tuple[str, ...] + context: str | None = None + + +@dataclass(frozen=True, slots=True) +class EntityReference: + """Name an IFC entity referenced by a Gherkin outcome.""" + + name: str + + +@dataclass(frozen=True, slots=True) +class InstanceReference: + """Describe an IFC instance referenced by a Gherkin outcome.""" + + description: str + + +@dataclass(frozen=True, slots=True) +class SchemaIdentifier: + """List schema identifiers expected or observed by a Gherkin check.""" + + identifiers: tuple[str, ...] + + +@dataclass(frozen=True, slots=True) +class GuidCharacters: + """Describe expected GUID characters or invalid characters found in a GUID.""" + + characters: str + expected: bool + guid: str | None + + +@dataclass(frozen=True, slots=True) +class GuidLength: + """Describe the expected or observed length of a GUID.""" + + length: int + expected: bool + guid: str | None + + +@dataclass(frozen=True, slots=True) +class AlignmentMeasurement: + """Describe an alignment measurement and its supporting geometric details.""" + + description: str + details: tuple[str, ...] + + +@dataclass(frozen=True, slots=True) +class UnrecognizedValue: + """Preserve an unrecognized persisted value as JSON text.""" + + json: str + + +GherkinValue: TypeAlias = ( + Scalar | AttributeValue | AllowedValues | EntityReference | InstanceReference + | SchemaIdentifier | GuidCharacters | GuidLength | AlignmentMeasurement + | UnrecognizedValue | None +) + + +@dataclass(frozen=True, slots=True, kw_only=True) +class Outcome: + """Record original severity and derive the effective severity after allowlisting.""" + + severity_in_db: OutcomeSeverity + allowlisted: bool + + @property + def severity_after_whitelisting(self) -> OutcomeSeverity: + return OutcomeSeverity.PASSED if self.allowlisted else self.severity_in_db + + +@dataclass(frozen=True, slots=True, kw_only=True) +class SyntaxError(Outcome): + """Describe a syntax diagnostic with its position and source excerpt.""" + + line_number: int | None + column_number: int | None + diagnosis: str + source_excerpt: str + + +@dataclass(frozen=True, slots=True, kw_only=True) +class SchemaResult(Outcome): + """Describe a schema validation result for an optional IFC instance.""" + + instance: IfcInstance | None + message: str + + +@dataclass(frozen=True, slots=True, kw_only=True) +class GherkinResult(Outcome): + """Describe the expected and observed values of a Gherkin check.""" + + instance: IfcInstance | None + expected: GherkinValue + observed: GherkinValue + + +@dataclass(frozen=True, slots=True) +class GherkinDescription: + """Provide a Gherkin feature's explanation and documentation link.""" + + text: str | None + url: str | None + + +Result = TypeVar("Result", SchemaResult, GherkinResult) + + +@dataclass(frozen=True, slots=True) +class ResultGroup(Generic[Result]): + """Collect related outcomes with their classification and occurrence information.""" + + title: str + results: tuple[Result, ...] + occurrence_count: int + severity_after_whitelisting: OutcomeSeverity + show_occurrence_count: bool + is_truncated: bool + show_source: bool + + +@dataclass(frozen=True, slots=True) +class SchemaGroup(ResultGroup[SchemaResult]): + """Group schema results beneath a constraint title and optional subcaption.""" + + subcaption: str | None + + +@dataclass(frozen=True, slots=True) +class GherkinGroup(ResultGroup[GherkinResult]): + """Group Gherkin results with their feature description.""" + + gherkin: GherkinDescription + + +SectionItem = TypeVar("SectionItem", SyntaxError, SchemaGroup, GherkinGroup) + + +@dataclass(frozen=True, slots=True) +class Section(Generic[SectionItem]): + """Pair a validation status with typed syntax diagnostics or result groups.""" + + status: CheckStatus + items: tuple[SectionItem, ...] + + +@dataclass(frozen=True, slots=True) +class FileMetadata: + """Describe the uploaded file and its report date.""" + + file_name: str + file_size: str + report_date: str + + +@dataclass(frozen=True, slots=True) +class HeaderValidation: + """Expose named IFC header values and the fields that failed header policy checks.""" + + schema_identifier: str + model_view_definition: str + file_name: str + time_stamp: str + originating_system: str + preprocessor_version: str + company_name: str + application_name: str + application_version: str + author: str + organization: str + invalid_fields: frozenset[str] + + +@dataclass(frozen=True, slots=True) +class HeaderFinding: + """What the header policy expects and what the header declares (None: not recorded / absent).""" + + expected: str | None + observed: str | None + + +@dataclass(frozen=True, slots=True) +class HeaderFieldFindings: + """Group the header policy findings of one header field.""" + + label: str + description: str + url: str + findings: tuple[HeaderFinding, ...] + + +@dataclass(frozen=True, slots=True) +class DigitalSignature: + """Describe a digital signature, its verification result, and certificate details.""" + + verification: str + issuer: str | None + subject: str | None + hash_algorithm: str | None + rsa_key_size: int | None + valid_until: str | None + valid_from: str | None + fingerprint: str | None + payload: str | None + start: str | int | None + end: str | int | None + + +@dataclass(frozen=True, slots=True) +class TaskReport: + """Provide the content of one report kind for a web page or full-report chapter.""" + + request_id: str + kind: ReportKind + title: str + metadata: FileMetadata + header: HeaderValidation + section: Section[SyntaxError] | Section[SchemaGroup] | Section[GherkinGroup] | None + signatures: tuple[DigitalSignature, ...] + header_policy: tuple[HeaderFieldFindings, ...] = () + + +@dataclass(frozen=True, slots=True) +class ReportOptions: + """Select the web report's visibility filter and requested page.""" + + include_all: bool = False + page: int = 1 + + +@dataclass(frozen=True, slots=True) +class ReportPagination: + """Describe a selected range of syntax diagnostics or whole outcome groups.""" + + options: ReportOptions + total: int + first: int + last: int + previous_page: int | None + next_page: int | None + + @classmethod + def for_count(cls, total: int, options: ReportOptions, page_size: int = 10) -> ReportPagination: + """Calculate clamped page bounds for eligible groups or syntax diagnostics.""" + page = min(max(options.page, 1), max(1, (total + page_size - 1) // page_size)) + start = (page - 1) * page_size + return cls( + options=ReportOptions(include_all=options.include_all, page=page), + total=total, + first=start + 1 if total else 0, + last=min(start + page_size, total), + previous_page=page - 1 if page > 1 else None, + next_page=page + 1 if start + page_size < total else None, + ) + + def with_report(self, report: TaskReport) -> ReportPage: + """Attach a built task report to these page bounds without further selection.""" + return ReportPage( + options=self.options, + total=self.total, + first=self.first, + last=self.last, + previous_page=self.previous_page, + next_page=self.next_page, + report=report, + ) + + +@dataclass(frozen=True, slots=True) +class ReportPage(ReportPagination): + """Pair a built task report with its selected range and page navigation.""" + + report: TaskReport + + +@dataclass(frozen=True, slots=True) +class CheckOverview: + """Summarize a validation layer's status and classified rule and outcome counts.""" + + title: str + status: CheckStatus + error_rules: int + error_outcomes: int + warning_rules: int + warning_outcomes: int + passed_rules: int + not_applicable_rules: int + + +@dataclass(frozen=True, slots=True) +class ReportChapter: + """Collect task reports belonging to one severity chapter of a full report.""" + + anchor: str + title: str + description: str + reports: tuple[TaskReport, ...] + rule_count: int + + +@dataclass(frozen=True, slots=True) +class TaskSummary: + """Summarize a validation task's execution status.""" + + title: str + status: str + + +@dataclass(frozen=True, slots=True) +class FullReport: + """Combine file information, validation overviews, severity chapters, and task execution.""" + + file: TaskReport + generated_at: str + conformance_status: CheckStatus + header_status: CheckStatus + signature_status: CheckStatus + overview: tuple[CheckOverview, ...] + chapters: tuple[ReportChapter, ...] + tasks: tuple[TaskSummary, ...] + outcome_limit: int + + +@dataclass(frozen=True, slots=True) +class OutcomeInput(Outcome): + """Materialize a stored outcome with the raw values needed for report projection.""" + + task_type: str + feature: str | None + expected: JSONValue + observed: JSONValue + instance: IfcInstance | None + + @property + def schema_feature(self) -> dict[str, JSONValue]: + """Decode the schema processor's constraint metadata, tolerating legacy invalid values.""" + try: + feature = json.loads(self.feature) if self.feature else {} + return feature if isinstance(feature, dict) else {} + except json.JSONDecodeError: + return {} + + @property + def group_title(self) -> str: + """Identify the displayed schema constraint or Gherkin feature used for grouping.""" + match self.task_type: + case "PREREQ": + return "Schema - Version" + case "SCHEMA": + if not self.feature and self.severity_in_db == OutcomeSeverity.PASSED: + return "Schema - Validation" + feature = self.schema_feature + constraint = (feature.get("type") or "uncategorized").replace("_", " ").capitalize() + return f"{constraint} - {feature.get('attribute') or 'Uncategorized'}" + case _: + return self.feature or "" + + +@dataclass(frozen=True, slots=True) +class ReportInput: + """Materialize one report kind's metadata, status, outcomes, and Gherkin descriptions.""" + + request_id: str + file_name: str + size_bytes: int + created: datetime + header: dict[str, JSONValue] + status: CheckStatus + outcomes: tuple[OutcomeInput, ...] + rules: dict[str, GherkinDescription] + outcome_limit: int + # Stored outcomes per (task type, feature, severity in db, severity after allowlisting). + # Present when `outcomes` holds only the first rows of each of those groups; None when + # `outcomes` is complete and can be counted directly. + counts: dict[tuple[str, str | None, int, int], int] | None = None + + def group_counts(self) -> dict[str, int] | None: + """Total stored outcomes per displayed group title, or None when outcomes are complete.""" + if self.counts is None: + return None + totals: dict[str, int] = {} + for (task_type, feature, severity_in_db, _), count in self.counts.items(): + title = OutcomeInput(task_type=task_type, feature=feature, severity_in_db=OutcomeSeverity(severity_in_db), + allowlisted=False, expected=None, observed=None, instance=None).group_title + totals[title] = totals.get(title, 0) + count + return totals + + def with_outcomes(self, outcomes: Iterable[OutcomeInput]) -> ReportInput: + """Copy the report input with a new flat outcome sequence and unchanged metadata.""" + return ReportInput( + request_id=self.request_id, + file_name=self.file_name, + size_bytes=self.size_bytes, + created=self.created, + header=self.header, + status=self.status, + outcomes=tuple(outcomes), + rules=self.rules, + outcome_limit=self.outcome_limit, + counts=self.counts, + ) + + def outcomes_sorted(self, *, key: Callable[[OutcomeInput], int | tuple[int, ...]] | None = None) -> ReportInput: + """Return outcomes in severity order or the explicitly supplied order.""" + return self.with_outcomes(sorted( + self.outcomes, + key=key or (lambda outcome: (-outcome.severity_after_whitelisting, -outcome.severity_in_db)), + )) + + def outcomes_grouped(self) -> ReportInput: + """Make equal-title outcomes adjacent in a flat, title-ordered sequence for groupby.""" + return self.with_outcomes(sorted(self.outcomes, key=lambda outcome: outcome.group_title)) + + def outcome_groups_paginated( + self, kind: ReportKind, options: ReportOptions, page_size: int = 10, + ) -> tuple[ReportInput, ReportPagination]: + """Select whole visible groups from grouped input while preserving their original outcomes and counts.""" + match kind: + case "file": + return self, ReportPagination.for_count(0, options, page_size) + case "syntax": + groups = tuple((outcome,) for outcome in self.outcomes) + case _: + groups = tuple(tuple(outcomes) for _, outcomes in groupby(self.outcomes, key=lambda outcome: outcome.group_title)) + groups = tuple(group for group in groups if options.include_all or any( + outcome.severity_after_whitelisting >= OutcomeSeverity.WARNING for outcome in group + )) + pagination = ReportPagination.for_count(len(groups), options, page_size) + start = (pagination.options.page - 1) * page_size + return self.with_outcomes( + outcome for group in islice(groups, start, start + page_size) for outcome in group + ), pagination diff --git a/backend/apps/ifc_validation_bff/datamodel/ui.py b/backend/apps/ifc_validation_bff/datamodel/ui.py new file mode 100644 index 00000000..2f56b24f --- /dev/null +++ b/backend/apps/ifc_validation_bff/datamodel/ui.py @@ -0,0 +1,131 @@ +"""Page content and interaction state. No ORM objects, JSON payloads or cell types.""" +from dataclasses import dataclass +from datetime import datetime + +from .report import CheckStatus + + +@dataclass(frozen=True, slots=True) +class Viewer: + name: str + email: str + initials: str + needs_affiliation_declaration: bool + + +@dataclass(frozen=True, slots=True) +class Shell: + title: str + active_page: str + viewer: Viewer | None + environment: str + version: str + commit: str + + +@dataclass(frozen=True, slots=True) +class UploadPolicy: + max_files: int + max_size_mb: int + + +@dataclass(frozen=True, slots=True) +class UploadForm: + policy: UploadPolicy + errors: tuple[str, ...] = () + + +@dataclass(frozen=True, slots=True) +class DashboardEntry: + request_id: str + file_name: str + created: datetime + status: str + progress: int | None + header_status: CheckStatus + header_errors: bool + signatures_status: CheckStatus + syntax_status: CheckStatus + schema_status: CheckStatus + normative_status: CheckStatus + industry_status: CheckStatus + pdf_ready: bool = False + pdf_pending: bool = False + can_delete: bool = False + selected: bool = False + + +@dataclass(frozen=True, slots=True) +class DashboardOptions: + page: int = 1 + per_page: int = 5 + selected: tuple[str, ...] = () + + +@dataclass(frozen=True, slots=True) +class Dashboard: + entries: tuple[DashboardEntry, ...] + options: DashboardOptions + total: int + first: int + last: int + previous_page: int | None + next_page: int | None + poll: bool + selected: tuple[str, ...] + off_page_selected: tuple[str, ...] + errors: tuple[str, ...] = () + + +@dataclass(frozen=True, slots=True) +class AllowlistPattern: + field: str + operation: str + value: str + + +@dataclass(frozen=True, slots=True) +class AllowlistEntry: + id: int + description: str + patterns: tuple[AllowlistPattern, ...] + + +@dataclass(frozen=True, slots=True) +class Allowlist: + entries: tuple[AllowlistEntry, ...] + + +@dataclass(frozen=True, slots=True) +class ValidationLayer: + title: str + description: str + + +@dataclass(frozen=True, slots=True) +class WorkflowStep: + number: str + title: str + description: str + + +@dataclass(frozen=True, slots=True) +class FAQ: + question: str + answer: str + + +@dataclass(frozen=True, slots=True) +class Resource: + category: str + title: str + description: str + url: str + + +@dataclass(frozen=True, slots=True) +class LandingPage: + layers: tuple[ValidationLayer, ...] + steps: tuple[WorkflowStep, ...] + faqs: tuple[FAQ, ...] + resources: tuple[Resource, ...] diff --git a/backend/apps/ifc_validation_bff/management/__init__.py b/backend/apps/ifc_validation_bff/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/apps/ifc_validation_bff/management/commands/__init__.py b/backend/apps/ifc_validation_bff/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/apps/ifc_validation_bff/management/commands/generate_validation_pdf.py b/backend/apps/ifc_validation_bff/management/commands/generate_validation_pdf.py new file mode 100644 index 00000000..9e2646a7 --- /dev/null +++ b/backend/apps/ifc_validation_bff/management/commands/generate_validation_pdf.py @@ -0,0 +1,34 @@ +from pathlib import Path +import shutil + +from django.core.management.base import BaseCommand, CommandError + +from apps.ifc_validation_models.models import ValidationRequest +from apps.ifc_validation_bff.report.pdf import generate_pdf + + +class Command(BaseCommand): + help = 'Generate full report PDFs for explicitly selected validation request ids.' + + def add_arguments(self, parser): + parser.add_argument('ids', nargs='+', help='Private numeric or public r... request ids') + parser.add_argument('--force', action='store_true', help='Regenerate an existing PDF') + parser.add_argument('--output-dir', type=Path, help='Also copy review PDFs into this directory') + + def handle(self, *args, **options): + for value in options['ids']: + try: + pk = ValidationRequest.to_private_id(value) if value.startswith('r') else int(value) + path = generate_pdf(pk, force=options['force']) + except (ValueError, ValidationRequest.DoesNotExist) as error: + raise CommandError(f'Unknown validation request: {value}') from error + if not path: + raise CommandError(f'Request {value} is deleted or validation is still running.') + if output := options['output_dir']: + output.mkdir(parents=True, exist_ok=True) + item = ValidationRequest.objects.get(pk=pk) + name = Path(item.file_name.replace('\\', '/')).name + destination = output / f'{item.public_id}-{Path(name).stem}.pdf' + shutil.copyfile(path, destination) + self.stdout.write(str(destination.resolve())) + self.stdout.write(self.style.SUCCESS(f'Request {value}: {path}')) diff --git a/backend/apps/ifc_validation_bff/report/__init__.py b/backend/apps/ifc_validation_bff/report/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/apps/ifc_validation_bff/report/build.py b/backend/apps/ifc_validation_bff/report/build.py new file mode 100644 index 00000000..a6276a11 --- /dev/null +++ b/backend/apps/ifc_validation_bff/report/build.py @@ -0,0 +1,263 @@ +from __future__ import annotations + +import re +from itertools import groupby +from typing import TYPE_CHECKING + +from ..datamodel.report import ( + DigitalSignature, + FileMetadata, + HeaderFieldFindings, + HeaderFinding, + HeaderValidation, + OutcomeSeverity, + TaskReport, + ReportKind, + GherkinDescription, + GherkinGroup, + GherkinResult, + SchemaGroup, + SchemaResult, + Section, + SyntaxError, +) +from .value_formatting import coerce_to_text, interpret_rule_value, outer_whitespace, pretty_file_size, truncate + +if TYPE_CHECKING: + from ..datamodel.report import OutcomeInput, ReportInput + +REPORT_TITLES = { + "file": "File Info", + "syntax": "STEP Syntax Report", + "schema": "IFC Schema Report", + "normative": "Normative IFC Rules Report", + "industry": "Industry Practices Report", +} + +# Header policy fields -> checks/header_policy/validate_header.py +HEADER_FIELDS = { + "description": ("MVD(s)", "One or more model view definitions used in the context of this data exchange."), + "name": ("File Name in Header", "The string of graphic characters used to name this particular instance of an exchange structure"), + "time_stamp": ("File Date", "The date and time specifying when the exchange structure was created, formatted in ISO 8601"), + "originating_system": ("Originating System", "The software from which the model originated, also known as the authoring tool."), + "preprocessor_version": ("Preprocessor Version", "The system used to create the exchange structure, including the system product name and version."), + "company_name": ("Company Name", "The name of the company, derived from the originating system"), + "application_name": ("Application Name", "The software used to export the model, derived from the originating system"), + "version": ("Application Version", "The version of the model or file format used, derived from the originating system"), + "author": ("Author", "The name and mailing address of the person responsible for creating the exchange structure."), + "organization": ("Organization", "The group or organization with whom the author is associated."), + "authorization": ("Authorization", "The name and mailing address of the person who authorized the sending of the exchange structure."), + "implementation_level": ("Implementation Level", "The conformance class and implementation level of the exchange structure."), + "comments": ("Comment", "Free text comment in the description, limited to 256 characters."), + "syntax_error": ("Header Syntax", "The file header could not be parsed; see the STEP Syntax Report."), +} + + +def build_report(data: ReportInput, kind: ReportKind, *, include_all=True, prioritize_findings=False) -> TaskReport: + if prioritize_findings: + data = data.outcomes_sorted() + elif kind == "schema": + data = data.outcomes_sorted(key=lambda outcome: -outcome.severity_after_whitelisting) + if kind in ("schema", "normative", "industry"): + data = data.outcomes_grouped() + + totals = data.group_counts() + + def outcome_groups(): + for title, outcomes in groupby(data.outcomes, key=lambda outcome: outcome.group_title): + original = tuple(outcomes) + visible = tuple(outcome for outcome in original + if include_all or outcome.severity_after_whitelisting >= OutcomeSeverity.WARNING) + if visible: + yield title, visible[:data.outcome_limit], len(original) if totals is None else totals.get(title, len(original)) + + def header_validation() -> HeaderValidation: + def text(key: str, fallback: str = "-") -> str: + value = data.header.get(key) + if isinstance(value, (tuple, list)): + return " ".join(map(str, value)) + return str(value) if value else fallback + + return HeaderValidation( + schema_identifier=text("schema_identifier"), + model_view_definition=text("mvd"), + file_name=text("name"), + time_stamp=text("time_stamp"), + originating_system=text("originating_system"), + preprocessor_version=text("preprocessor_version"), + company_name=outer_whitespace(data.header.get("company_name")), + application_name=outer_whitespace(data.header.get("application_name")), + application_version=outer_whitespace(data.header.get("version")), + author=text("author"), + organization=text("organization"), + invalid_fields=frozenset(data.header.get("validation_errors") or ()), + ) + + def header_policy() -> tuple[HeaderFieldFindings, ...]: + # Files validated before the policy recorded details only list the invalid fields. + details = data.header.get("validation_details") or [ + {"field": field, "expected": None, "observed": data.header.get("mvd" if field == "description" else field)} + for field in data.header.get("validation_errors") or ()] + grouped: dict[str, list[HeaderFinding]] = {} + for detail in details: + observed = detail.get("observed") + if isinstance(observed, (tuple, list)): + observed = " ".join(map(str, observed)) + grouped.setdefault(detail["field"], []).append( + HeaderFinding(detail.get("expected"), None if observed is None else outer_whitespace(str(observed)))) + order = list(HEADER_FIELDS) + return tuple( + HeaderFieldFindings(*HEADER_FIELDS.get(field, (field, "-")), + f"https://github.com/buildingSMART/IFC4.x-IF/tree/main/docs/IFC-file-header#{field}", tuple(findings)) + for field, findings in sorted(grouped.items(), key=lambda item: order.index(item[0]) if item[0] in order else len(order))) + + def syntax() -> Section[SyntaxError]: + def error(outcome: OutcomeInput) -> SyntaxError: + observed = outcome.observed or "" + position = re.match(r"^On line (\d+) column (\d+).*", observed) + message = f"expected: {outcome.expected}, observed: {outcome.observed}" if outcome.expected is not None else observed + lines = message.split("\n") + return SyntaxError( + **severity(outcome), + line_number=int(position[1]) if position else None, + column_number=int(position[2]) if position else None, + diagnosis="\n".join(lines[:-2]), + source_excerpt="\n".join(lines[-2:]), + ) + + return Section( + data.status, + tuple( + error(outcome) + for outcome in data.outcomes + if not prioritize_findings or outcome.severity_after_whitelisting >= OutcomeSeverity.WARNING + ), + ) + + def schema() -> Section[SchemaGroup]: + def describe(outcome: OutcomeInput): + if outcome.task_type == "PREREQ": + # The prerequisites are gherkin-based checks that are rendered in the schema report - + # which otherwise consists of outputs that come from ifcopenshell.validate + description = re.sub(r"^IFC\d{3}\s*-\s*", "", outcome.feature or "") + observed = coerce_to_text(outcome.observed) + if (description and (isinstance(outcome.expected, (tuple, list)) or outcome.expected) + and (isinstance(outcome.observed, (tuple, list)) or outcome.observed)): + message = f"Description: {description} , Expected: {coerce_to_text(outcome.expected)}, Observed: {observed}" + else: + message = f"{description}\n{observed}" if outcome.feature else observed + return observed.split("\n")[0] or None, message + if not outcome.feature and outcome.severity_in_db == OutcomeSeverity.PASSED: + return None, coerce_to_text(outcome.observed) + + constraint = outcome.schema_feature.get("type") + message = coerce_to_text(outcome.observed) + subcaption = message.split("\n")[0] or None if constraint != "schema" else None + return subcaption, "\n".join(message.split("\n")[2:]) if constraint != "schema" else message + + def result(outcome: OutcomeInput) -> SchemaResult: + return SchemaResult(**severity(outcome), instance=outcome.instance, message=describe(outcome)[1]) + + return Section( + data.status, + tuple( + group( + title, + tuple(map(result, outcomes)), + count, + subcaption=describe(outcomes[0])[0], + ) + for title, outcomes, count in outcome_groups() + ), + ) + + def gherkin() -> Section[GherkinGroup]: + def result(outcome: OutcomeInput) -> GherkinResult: + return GherkinResult( + **severity(outcome), + instance=outcome.instance, + expected=interpret_rule_value(outcome.expected), + observed=interpret_rule_value(outcome.observed), + ) + + return Section( + data.status, + tuple( + group( + title, + tuple(map(result, outcomes)), + count, + gherkin=data.rules.get(title[:6], GherkinDescription(None, None)), + ) + for title, outcomes, count in outcome_groups() + ), + ) + + def signatures() -> tuple[DigitalSignature, ...]: + def signature(value: dict) -> DigitalSignature: + def text(key): + found = value.get(key) + return (str(found) if prioritize_findings else truncate(str(found))) if found else None + + return DigitalSignature( + verification=value.get("signature", "valid_known_cert"), + issuer=text("issuer"), + subject=text("subject"), + hash_algorithm=text("signature_hash_algorithm_name"), + rsa_key_size=value.get("rsa_key_size"), + valid_until=text("not_valid_after"), + valid_from=text("not_valid_before"), + fingerprint=text("fingerprint_hex"), + payload=text("payload"), + start=value.get("start"), + end=value.get("end"), + ) + + return tuple(signature(o.observed) for o in data.outcomes if isinstance(o.observed, dict)) + + match kind: + case "syntax": + section = syntax() + case "schema": + section = schema() + case "normative" | "industry": + section = gherkin() + case _: + section = None + + return TaskReport( + request_id=data.request_id, + kind=kind, + title=REPORT_TITLES[kind], + metadata=FileMetadata(data.file_name, pretty_file_size(data.size_bytes), data.created.strftime("%Y-%m-%d %H:%M:%S")), + header=header_validation(), + section=section, + signatures=signatures() if kind == "file" else (), + header_policy=header_policy() if kind == "file" else (), + ) + + +def severity(outcome: OutcomeInput) -> dict: + return dict(severity_in_db=outcome.severity_in_db, allowlisted=outcome.allowlisted) + + +def group(title, results, count, *, subcaption=None, gherkin=None): + """Build a result group and its visibility flags read by the templates. + + - Determine the highest visible severity, defaulting to not applicable. + - Preserve the supplied occurrence count and flag omitted results. + - Show the occurrence count when visible warnings/errors exist. + - Flag source availability and return a GherkinGroup or SchemaGroup + propagating gherkin description or subcaption info passed from the outside + """ + highest = max((r.severity_after_whitelisting for r in results), default=OutcomeSeverity.NOT_APPLICABLE) + common = dict( + title=title, + results=results, + occurrence_count=count, + severity_after_whitelisting=highest, + show_occurrence_count=highest >= OutcomeSeverity.WARNING, + is_truncated=count > len(results), + show_source=any(r.instance and r.instance.source for r in results), + ) + return GherkinGroup(**common, gherkin=gherkin) if gherkin is not None else SchemaGroup(**common, subcaption=subcaption) diff --git a/backend/apps/ifc_validation_bff/report/full.py b/backend/apps/ifc_validation_bff/report/full.py new file mode 100644 index 00000000..49224ec1 --- /dev/null +++ b/backend/apps/ifc_validation_bff/report/full.py @@ -0,0 +1,84 @@ +from collections import Counter, defaultdict +from dataclasses import replace + +from .build import build_report +from ..datamodel.report import CheckOverview, FullReport, ReportChapter + + +def build_full_report(inputs, *, generated_at, validation_state, tasks, + signature_status, security_status): + def trim_schema(data): + counts = Counter() + + def retain(outcome): + key = (outcome.task_type, outcome.feature or '') + counts[key] += 1 + return counts[key] <= data.outcome_limit + + ordered = data.outcomes_sorted().outcomes + # The PDF reports schema numbers after this cap, so they are counted from the kept rows. + return replace(data.with_outcomes(filter(retain, ordered)), counts=None) + + # Apply the schema cap before both overview counts and detail projection. + inputs = {**inputs, 'schema': trim_schema(inputs['schema'])} + reports = tuple(build_report(data, kind, prioritize_findings=True) for kind, data in inputs.items()) + + def overview(report): + data = inputs[report.kind] + rules = defaultdict(Counter) + if data.counts is None: + for outcome in data.outcomes: + rules[outcome.task_type, outcome.feature or ''][outcome.severity_after_whitelisting] += 1 + else: + for (task_type, feature, _, effective), count in data.counts.items(): + rules[task_type, feature or ''][effective] += count + classifications = Counter(max(counts) for counts in rules.values()) + # Passing/executed rows never make a rule pass when it also has errors or warnings. + return CheckOverview( + title=report.title.removesuffix(' Report'), status=data.status, + error_rules=classifications[4], + error_outcomes=sum(counts[4] for counts in rules.values()), + warning_rules=sum(counts[3] > 0 for counts in rules.values()), + warning_outcomes=sum(counts[3] for counts in rules.values()), + passed_rules=classifications[2] + classifications[1], + not_applicable_rules=classifications[0], + ) + + def chapter(anchor, title, description, severities): + def select(report): + section = report.section + if section and report.kind != 'syntax': + # The group belongs to its most severe effective outcome. Do not + # split one rule across chapters or derive check status from rows. + groups = tuple(replace(group, results=tuple(sorted(group.results, + key=lambda result: -result.severity_after_whitelisting))) + for group in sorted(section.items, key=lambda group: (-group.severity_after_whitelisting, group.title)) + if group.severity_after_whitelisting in severities) + return replace(report, section=replace(section, items=groups)) if groups else None + if section: + errors = tuple(error for error in section.items if error.severity_after_whitelisting in severities) + return replace(report, section=replace(section, items=errors)) if errors else None + return None + + selected = tuple(filter(None, map(select, reports))) + count = sum(len(report.section.items) for report in selected) + return ReportChapter(anchor, title, description, selected, count) + + overview_rows = tuple(map(overview, reports[1:])) + states = (inputs['file'].status, security_status, *(row.status for row in overview_rows)) + incomplete = validation_state != 'Completed' or any(status in ('n', 'p') for status in states) + conformance = ('n' if incomplete else 'i' if 'i' in states or signature_status == 'i' or any(row.error_rules for row in overview_rows) + else 'w' if 'w' in states or reports[0].header.invalid_fields or any(row.warning_rules for row in overview_rows) else 'v') + return FullReport( + file=reports[0], generated_at=generated_at, + conformance_status=conformance, + header_status='w' if reports[0].header.invalid_fields and inputs['file'].status == 'v' else inputs['file'].status, + signature_status=signature_status, + overview=overview_rows, + chapters=( + chapter('findings', 'Errors', 'Error outcomes across all validation layers, ordered before warnings and passing rules.', (4,)), + chapter('warnings', 'Warnings', 'Warning outcomes across all validation layers. A warning alone does not make an IFC file invalid.', (3,)), + chapter('passed', 'Passed rules', 'Applicable rules without errors or warnings after allowlisting, including passed and executed outcomes.', (2, 1)), + chapter('not-applicable', 'Not applicable rules', 'Rules explicitly recorded as not applicable to this model.', (0,)), + ), tasks=tuple(tasks), outcome_limit=inputs['file'].outcome_limit, + ) diff --git a/backend/apps/ifc_validation_bff/report/gherkin_lookup.py b/backend/apps/ifc_validation_bff/report/gherkin_lookup.py new file mode 100644 index 00000000..65738864 --- /dev/null +++ b/backend/apps/ifc_validation_bff/report/gherkin_lookup.py @@ -0,0 +1,55 @@ +import functools +import glob +import os +from pathlib import Path + +from core.settings import FEATURE_URL + +RULES_FOLDER = ( + Path(__file__).resolve().parents[2] + / "ifc_validation" / "checks" / "ifc_gherkin_rules" / "features" / "rules" +) + + +@functools.lru_cache(maxsize=1024) +def get_feature_filename(feature_code): + """ + Retrieve the feature filename based on the feature_code (e.g. 'ALB005') + """ + return glob.glob(os.path.join(RULES_FOLDER, "**", f"{feature_code}*.feature"), recursive=True) + + +@functools.lru_cache(maxsize=1024) +def get_feature_url(feature_code): + """ + Get the URL for the corresponding feature filename + We return the filename in the relevant branch of the repositoy, eg. + - 'development' for DEV + - 'preview' for PREVIEW + - 'main' for MAIN + """ + feature_files = get_feature_filename(feature_code) + + if feature_files: + return os.path.join(FEATURE_URL, os.path.basename(feature_files[0].replace(".feature", ".html"))) + return None + + +@functools.lru_cache(maxsize=1024) +def get_feature_description(feature_code): + feature_files = get_feature_filename(feature_code) + if feature_files: + + gherkin_desc = '' + reading = False + + with open(feature_files[0], 'r', encoding='utf-8') as input_file: + for line in input_file: + if 'Feature:' in line: + reading = True + if any(keyword in line for keyword in ['Scenario:', 'Background:', 'Scenario Outline:']): + return gherkin_desc + if reading and line.strip() and 'Feature:' not in line and '@' not in line: + gherkin_desc += '\n' + line.strip() + + return None diff --git a/backend/apps/ifc_validation_bff/report/pdf.py b/backend/apps/ifc_validation_bff/report/pdf.py new file mode 100644 index 00000000..d3bf1b36 --- /dev/null +++ b/backend/apps/ifc_validation_bff/report/pdf.py @@ -0,0 +1,102 @@ +import hashlib +import os +from pathlib import Path +from tempfile import NamedTemporaryFile +from urllib.parse import unquote, urlsplit + +from django.conf import settings +from django.contrib.staticfiles import finders +from django.db import transaction +from django.template.loader import render_to_string +from django.utils import timezone + +from apps.ifc_validation_models.models import ValidationRequest +from ..datamodel.report import TaskSummary +from .full import build_full_report +from ..datamodel.load import load_model_summary, load_report + +RENDER_VERSION = '1' + + +def artifact_path(request): + # A new validation run has a new identity; an older PDF is never advertised. + identity = f'{RENDER_VERSION}:{request.pk}:{request.started}:{request.completed}:{request.model_id}' + digest = hashlib.sha256(identity.encode()).hexdigest()[:20] + root = Path(getattr(settings, 'VALIDATION_REPORT_ROOT', Path(settings.MEDIA_ROOT) / '.reports')) + return root / request.public_id / f'{digest}.pdf' + + +def remove_pdf(request): + folder = artifact_path(request).parent + if folder.exists(): + for path in folder.glob('*.pdf'): + path.unlink(missing_ok=True) + + +def load_full_report(request): + inputs = {kind: load_report(request, kind, include_successful_syntax=True) + for kind in ('file', 'syntax', 'schema', 'normative', 'industry')} + latest = {} + for task in request.tasks.order_by('-id'): + latest.setdefault(task.type, task) + tasks = tuple(TaskSummary(task.get_type_display(), task.get_status_display()) + for task in sorted(latest.values(), key=lambda task: task.id)) + summary = load_model_summary(request) + return build_full_report(inputs, generated_at=timezone.now().strftime('%d %B %Y · %H:%M UTC'), + validation_state=request.get_status_display(), + tasks=tasks, signature_status=summary.signatures_status, security_status=summary.security_status) + + +def static_asset_uri(url): + """Only template-owned static assets can be fetched, never links from IFC data.""" + parsed = urlsplit(url) + static = urlsplit(settings.STATIC_URL) + if parsed.scheme not in ('http', 'https') or parsed.netloc not in ('report.invalid', static.netloc) or not parsed.path.startswith(static.path): + raise ValueError(f'PDF asset is not a local static resource: {url}') + name = unquote(parsed.path.removeprefix(static.path)) + if '..' in Path(name).parts: + raise ValueError('Invalid PDF asset path') + path = finders.find(name) + if not path: + raise FileNotFoundError(name) + return Path(path).resolve().as_uri() + + +def render_pdf(document): + from weasyprint import HTML, URLFetcher + + class StaticAssets(URLFetcher): + """Restrict PDF asset fetching to the report's local static files.""" + + def fetch(self, url, headers=None): + return super().fetch(static_asset_uri(url), headers) + + html = render_to_string('report/page.html', {'pdf': True, 'document': document, 'report': document.file}) + return HTML(string=html, base_url='https://report.invalid/', + url_fetcher=StaticAssets(allowed_protocols={'file'}, fail_on_errors=True)).write_pdf( + presentational_hints=True) + + +def generate_pdf(request_id, *, force=False): + request = ValidationRequest.objects.select_related('model', 'created_by', 'model__produced_by').get(pk=request_id) + if request.deleted or request.file_removed or not request.has_final_status: + return None + target = artifact_path(request) + if target.is_file() and not force: + return target + payload = render_pdf(load_full_report(request)) + with transaction.atomic(): + current = ValidationRequest.objects.select_for_update().get(pk=request_id) + if current.deleted or current.file_removed or not current.has_final_status or artifact_path(current) != target: + return None # deleted/revalidated while rendering + target.parent.mkdir(parents=True, exist_ok=True) + temporary = None + try: + with NamedTemporaryFile(dir=target.parent, suffix='.tmp', delete=False) as handle: + temporary = Path(handle.name) + handle.write(payload) + os.replace(temporary, target) + finally: + if temporary: + temporary.unlink(missing_ok=True) + return target diff --git a/backend/apps/ifc_validation_bff/report/value_formatting.py b/backend/apps/ifc_validation_bff/report/value_formatting.py new file mode 100644 index 00000000..acb0d234 --- /dev/null +++ b/backend/apps/ifc_validation_bff/report/value_formatting.py @@ -0,0 +1,93 @@ +from __future__ import annotations + +import json +import re + +from ..datamodel.report import ( + AlignmentMeasurement, AllowedValues, AttributeValue, EntityReference, + GuidCharacters, GuidLength, InstanceReference, JSONValue, GherkinValue, + SchemaIdentifier, UnrecognizedValue, +) + + +def coerce_to_text(value: JSONValue) -> str: + if not (isinstance(value, (tuple, list)) or value): + return "" + return value if isinstance(value, str) else json.dumps(value, ensure_ascii=False, separators=(",", ":")) + + +def interpret_rule_value(value: JSONValue) -> GherkinValue: + """ + Interpret a structured JSON value in the expected/observed columns into a corresponding dataclass for rendering in the templates. + """ + if not (isinstance(value, (tuple, list)) or value): + return None + if isinstance(value, (str, int, float, bool)): + return value + if isinstance(value, dict): + match value: + case {"invalid_guid_chars": chars, "expected_or_observed": side}: + chars = ",".join(map(str, chars)) if isinstance(chars, list) else str(chars) + return GuidCharacters(chars, side == "expected", value.get("inst")) + case {"length": int(length), "expected_or_observed": side}: + return GuidLength(length, side == "expected", value.get("inst")) + case {"value": inner}: + return AttributeValue(inner) if isinstance(inner, (str, int, float, bool)) else interpret_rule_value(inner) + case {"instance": str(description)}: + return InstanceReference(description) + case {"entity": str(name)}: + return EntityReference(name.split("(#")[0]) + case {"oneOf": list(choices)}: + return AllowedValues(tuple(map(str, choices)), value.get("context")) + case {"schema_identifier": str(identifier)}: + return SchemaIdentifier(tuple(identifier.split("\n"))) + case {"num_digits": int(digits)}: + return measurement(value, digits) + return UnrecognizedValue(json.dumps(value, ensure_ascii=False, separators=(",", ":"))) + + +def measurement(value: dict[str, JSONValue], digits: int) -> AlignmentMeasurement: + context = value.get("context") or "" + label = f"{context[:1].upper()}{context[1:]} :" if context else "One of:" + reported = value.get("expected") or value.get("observed") + if isinstance(reported, list): + display = "".join(map(str, reported)) + if label == "Position :": + display = f"({reported[0]}, {reported[1]})" + else: + try: + display = re.sub(r"e([+-])0+(\d+)$", r"e\1\2", f"{float(reported):.{digits}e}") + except (TypeError, ValueError): + display = str(reported) + details = value.get("continuity_details") + if not isinstance(details, dict): + return AlignmentMeasurement(f"{label} {display}", ()) + + def endpoint(segment: str, point: str, direction: str, prefix: str) -> tuple[str, ...]: + coordinates = details.get(point) or (None, None) + lines = (f"{prefix} {details.get(segment)}", f"Coords: ({coordinates[0]}, {coordinates[1]})") + direction_label = "Tangent Direction" if "direction" in context else "Gradient" if "gradient" in context else None + return (*lines, f"{direction_label}: {details.get(direction)}") if direction_label else lines + + return AlignmentMeasurement(f"{label} {display}", ( + *endpoint("segment_to_analyze", "current_end_point", "current_end_direction", "at end of"), + *endpoint("following_segment", "following_start_point", "following_start_direction", "and start of"), + )) + + +def pretty_file_size(size: int) -> str: + amount = size / 1024 + units = iter(("kB", "MB", "GB", "TB")) + unit = next(units) + while amount > 1024: + amount /= 1024 + unit = next(units, "TB") + return f"{max(amount, 0.01):.2f} {unit}" + + +def outer_whitespace(value: str | None) -> str: + return re.sub(r"^\s+|\s+$", lambda match: "□" * len(match[0]), value or "") + + +def truncate(value: str, limit: int = 64) -> str: + return value[:limit - 3] + "..." if len(value) > limit else value diff --git a/backend/apps/ifc_validation_bff/report/views.py b/backend/apps/ifc_validation_bff/report/views.py new file mode 100644 index 00000000..b9ac88b8 --- /dev/null +++ b/backend/apps/ifc_validation_bff/report/views.py @@ -0,0 +1,91 @@ +from django.http import FileResponse, HttpResponseNotAllowed, HttpResponseNotFound, HttpResponseRedirect +from django.shortcuts import render +from django.urls import reverse +from django.views.decorators.vary import vary_on_headers + +from apps.ifc_validation_models.models import ValidationRequest +from ..views_legacy import get_current_user, resolve_request_id +from .build import REPORT_TITLES, build_report +from ..datamodel.report import ReportOptions +from ..datamodel.load import load_report, load_shell + + +@vary_on_headers("HX-Request") +def report_html(request, id: str, kind=None): + def missing(user=None): + return render(request, 'ui/not_found.html', {'shell': load_shell(request, user, 'Not Found', 'report')}, status=404) + + if request.method != "GET": + return HttpResponseNotAllowed(["GET"]) + kind = kind or request.GET.get("type") or "file" + if kind not in REPORT_TITLES: + return missing() + user = get_current_user(request) + if not user: + from ..ui.views import redirect_to + return redirect_to(request, reverse('ui:login')) + if not user.is_active: + return HttpResponseRedirect(reverse('ui:waiting_zone')) + private_id = resolve_request_id(id) + if not private_id: + return missing(user) + requests = ValidationRequest.objects.select_related("model", "created_by", "model__produced_by") + if not user.is_staff: + requests = requests.filter(created_by=user, deleted=False) + validation_request = requests.filter(id=private_id).first() + if not validation_request: + return missing(user) + try: + number = int(request.GET.get("page", "1")) + except ValueError: + number = 1 + options = ReportOptions(include_all=request.GET.get("include_all") == "1", page=number) + data = load_report(validation_request, kind, viewer=user).outcomes_grouped() + data, pagination = data.outcome_groups_paginated(kind, options) + report = build_report(data, kind, include_all=options.include_all) + page = pagination.with_report(report) + template = "report/section.html" if request.headers.get("HX-Request") == "true" else "report/page.html" + context = {"request": request, "report": page.report, "page": page} + if template == "report/page.html": + context["shell"] = load_shell(request, user, report.title, "report") + return render(request, template, context) + + +def legacy_report_redirect(request, id): + kind = request.GET.get('type') or 'file' + if kind not in REPORT_TITLES: + return HttpResponseNotFound() + query = request.GET.copy() + query.pop('type', None) + segment = 'rules' if kind == 'normative' else kind + url = reverse(f'ui:report-{segment}', kwargs={'id': id}) + return HttpResponseRedirect(url + ('?' + query.urlencode() if query else '')) + + +def report_pdf(request, id): + from .pdf import artifact_path + from ..ui.views import authenticated + + @authenticated + def download(request, user): + if request.method != 'GET': + return HttpResponseNotAllowed(['GET']) + pk = resolve_request_id(id) + items = ValidationRequest.objects.filter(pk=pk, deleted=False) + if not user.is_staff: + items = items.filter(created_by=user) + item = items.first() + if not item or item.file_removed or not item.has_final_status: + return HttpResponseNotFound('PDF report is not available.') + path = artifact_path(item) + try: + handle = path.open('rb') + except FileNotFoundError: + return HttpResponseNotFound('PDF report has not been generated yet.') + from pathlib import Path + name = Path(item.file_name.replace('\\', '/')).stem + response = FileResponse(handle, as_attachment=True, filename=f'{name}-validation-report.pdf', content_type='application/pdf') + response['Cache-Control'] = 'private, no-store' + return response + + return download(request) diff --git a/backend/apps/ifc_validation_bff/static/report/htmx.LICENSE b/backend/apps/ifc_validation_bff/static/report/htmx.LICENSE new file mode 100644 index 00000000..d3061a37 --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/report/htmx.LICENSE @@ -0,0 +1,13 @@ +Zero-Clause BSD +============= + +Permission to use, copy, modify, and/or distribute this software for +any purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL +WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE +FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN +AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/backend/apps/ifc_validation_bff/static/report/htmx.min.js b/backend/apps/ifc_validation_bff/static/report/htmx.min.js new file mode 100644 index 00000000..e6b8394a --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/report/htmx.min.js @@ -0,0 +1 @@ +var htmx=function(){"use strict";const Y={onLoad:null,process:null,on:null,off:null,trigger:null,ajax:null,find:null,findAll:null,closest:null,values:function(e,t){const n=pn(e,t||"post");return n.values},remove:null,addClass:null,removeClass:null,toggleClass:null,takeClass:null,swap:null,defineExtension:null,removeExtension:null,logAll:null,logNone:null,logger:null,config:{historyEnabled:true,historyCacheSize:10,refreshOnHistoryMiss:false,defaultSwapStyle:"innerHTML",defaultSwapDelay:0,defaultSettleDelay:20,includeIndicatorStyles:true,indicatorClass:"htmx-indicator",requestClass:"htmx-request",addedClass:"htmx-added",settlingClass:"htmx-settling",swappingClass:"htmx-swapping",allowEval:true,allowScriptTags:true,inlineScriptNonce:"",inlineStyleNonce:"",attributesToSettle:["class","style","width","height"],withCredentials:false,timeout:0,wsReconnectDelay:"full-jitter",wsBinaryType:"blob",disableSelector:"[hx-disable], [data-hx-disable]",scrollBehavior:"instant",defaultFocusScroll:false,getCacheBusterParam:false,globalViewTransitions:false,methodsThatUseUrlParams:["get","delete"],selfRequestsOnly:true,ignoreTitle:false,scrollIntoViewOnBoost:true,triggerSpecsCache:null,disableInheritance:false,responseHandling:[{code:"204",swap:false},{code:"[23]..",swap:true},{code:"[45]..",swap:false,error:true}],allowNestedOobSwaps:true,historyRestoreAsHxRequest:true,reportValidityOfForms:false},parseInterval:null,location:location,_:null,version:"2.0.11"};Y.onLoad=V;Y.process=Bt;Y.on=ye;Y.off=xe;Y.trigger=ae;Y.ajax=In;Y.find=a;Y.findAll=x;Y.closest=g;Y.remove=z;Y.addClass=w;Y.removeClass=S;Y.toggleClass=G;Y.takeClass=W;Y.swap=C;Y.defineExtension=zn;Y.removeExtension=Jn;Y.logAll=$;Y.logNone=_;Y.parseInterval=d;Y._=e;const n={addTriggerHandler:Et,bodyContains:ie,canAccessLocalStorage:U,findThisElement:we,filterValues:xn,swap:C,hasAttribute:s,getAttributeValue:f,getClosestAttributeValue:te,getClosestMatch:A,getExpressionVars:qn,getHeaders:yn,getInputValues:pn,getInternalData:re,getSwapSpecification:vn,getTriggerSpecs:lt,getTarget:Se,makeFragment:D,mergeObjects:se,makeSettleInfo:En,oobSwap:Te,querySelectorExt:ce,settleImmediately:Qt,shouldCancel:dt,triggerEvent:ae,triggerErrorEvent:ue,withExtensions:Vt};const he=["get","post","put","delete","patch"];const R=he.map(function(e){return"[hx-"+e+"], [data-hx-"+e+"]"}).join(", ");function d(e){if(e==undefined){return undefined}let t=NaN;if(e.slice(-2)=="ms"){t=parseFloat(e.slice(0,-2))}else if(e.slice(-1)=="s"){t=parseFloat(e.slice(0,-1))*1e3}else if(e.slice(-1)=="m"){t=parseFloat(e.slice(0,-1))*1e3*60}else{t=parseFloat(e)}return isNaN(t)?undefined:t}function Q(e,t){return e instanceof Element&&e.getAttribute(t)}function s(e,t){return!!e.hasAttribute&&(e.hasAttribute(t)||e.hasAttribute("data-"+t))}function f(e,t){return Q(e,t)||Q(e,"data-"+t)}function u(e){const t=e.parentElement;if(!t&&e.parentNode instanceof ShadowRoot)return e.parentNode;return t}function ee(){return document}function q(e,t){return e.getRootNode?e.getRootNode({composed:t}):ee()}function A(e,t){while(e&&!t(e)){e=u(e)}return e||null}function o(e,t,n){const r=f(t,n);const o=f(t,"hx-disinherit");var i=f(t,"hx-inherit");if(e!==t){if(Y.config.disableInheritance){if(i&&(i==="*"||i.split(" ").indexOf(n)>=0)){return r}else{return null}}if(o&&(o==="*"||o.split(" ").indexOf(n)>=0)){return"unset"}}return r}function te(t,n){let r=null;A(t,function(e){return!!(r=o(t,le(e),n))});if(r!=="unset"){return r}}function h(e,t){return e instanceof Element&&e.matches(t)}function N(e){const t=/<([a-z][^\/\0>\x20\t\r\n\f]*)/i;const n=t.exec(e);if(n){return n[1].toLowerCase()}else{return""}}function I(e){if("parseHTMLUnsafe"in Document){return Document.parseHTMLUnsafe(e)}const t=new DOMParser;return t.parseFromString(e,"text/html")}function L(e,t){while(t.childNodes.length>0){e.append(t.childNodes[0])}}function r(e){const t=ee().createElement("script");oe(e.attributes,function(e){t.setAttribute(e.name,e.value)});t.textContent=e.textContent;t.async=false;if(Y.config.inlineScriptNonce){t.nonce=Y.config.inlineScriptNonce}return t}function i(e){return e.matches("script")&&(e.type==="text/javascript"||e.type==="module"||e.type==="")}function k(e){if(!Y.config.allowScriptTags){e.querySelectorAll("script").forEach(e=>e.remove());return}Array.from(e.querySelectorAll("script")).forEach(e=>{if(i(e)){const t=r(e);const n=e.parentNode;try{n.insertBefore(t,e)}catch(e){T(e)}finally{e.remove()}}})}function D(e){e=e.replace(/]*)?)>/gi,'");const t=e.replace(/]*)?>[\s\S]*?<\/head>/i,"");const n=N(t);let r;if(n==="html"){r=new DocumentFragment;const i=I(e);L(r,i.body);r.title=i.title}else if(n==="body"){r=new DocumentFragment;const i=I(t);L(r,i.body);r.title=i.title}else{const i=I('");r=i.querySelector("template").content;r.title=i.title;var o=r.querySelector("title");if(o&&o.parentNode===r){o.remove();r.title=o.innerText}}if(r){k(r)}return r}function ne(e){if(e){e()}}function t(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"}function P(e){return typeof e==="function"}function M(e){return t(e,"Object")}function re(e){const t="htmx-internal-data";let n=e[t];if(!n){n=e[t]={}}return n}function F(t){const n=[];if(t){for(let e=0;e=0}function ie(e){return e.getRootNode({composed:true})===document}function X(e){return e.trim().split(/\s+/)}function se(e,t){return Object.assign({},e,t)}function v(e){try{return JSON.parse(e)}catch(e){T(e);return null}}function U(){const e="htmx:sessionStorageTest";try{sessionStorage.setItem(e,e);sessionStorage.removeItem(e);return true}catch(e){return false}}function j(e){try{const t=new URL(e,window.location.href);e=t.pathname+t.search}catch(e){}if(e!="/"){e=e.replace(/\/+$/,"")}return e}function e(e){return Tn(ee().body,function(){return eval(e)})}function V(t){const e=Y.on("htmx:load",function(e){t(e.detail.elt)});return e}function $(){Y.logger=function(e,t,n){if(console){console.log(t,e,n)}}}function _(){Y.logger=null}function a(e,t){if(typeof e!=="string"){return e.querySelector(t)}else{return a(ee(),e)}}function x(e,t){if(typeof e!=="string"){return e.querySelectorAll(t)}else{return x(ee(),e)}}function b(){return window}function z(e,t){e=E(e);if(t){b().setTimeout(function(){z(e);e=null},t)}else{u(e).removeChild(e)}}function le(e){return e instanceof Element?e:null}function J(e){return e instanceof HTMLElement?e:null}function K(e){return typeof e==="string"?e:null}function p(e){return e instanceof Element||e instanceof Document||e instanceof DocumentFragment?e:null}function w(e,t,n){e=le(E(e));if(!e){return}if(n){b().setTimeout(function(){w(e,t);e=null},n)}else{e.classList&&e.classList.add(t)}}function S(e,t,n){let r=le(E(e));if(!r){return}if(n){b().setTimeout(function(){S(r,t);r=null},n)}else{if(r.classList){r.classList.remove(t);if(r.classList.length===0){r.removeAttribute("class")}}}}function G(e,t){e=E(e);e.classList.toggle(t)}function W(e,t){e=E(e);oe(e.parentElement.children,function(e){S(e,t)});w(le(e),t)}function g(e,t){e=le(E(e));if(e){return e.closest(t)}return null}function l(e,t){return e.substring(0,t.length)===t}function Z(e,t){return e.substring(e.length-t.length)===t}function de(e){const t=e.trim();if(l(t,"<")&&Z(t,"/>")){return t.substring(1,t.length-2)}else{return t}}function m(t,r,n){if(r.indexOf("global ")===0){return m(t,r.slice(7),true)}t=E(t);const o=[];{let t=0;let n=0;for(let e=0;e"){t--}}if(n0){const r=de(o.shift());let e;if(r.indexOf("closest ")===0){e=g(le(t),de(r.slice(8)))}else if(r.indexOf("find ")===0){e=a(p(t),de(r.slice(5)))}else if(r==="next"||r==="nextElementSibling"){e=le(t).nextElementSibling}else if(r.indexOf("next ")===0){e=pe(t,de(r.slice(5)),!!n)}else if(r==="previous"||r==="previousElementSibling"){e=le(t).previousElementSibling}else if(r.indexOf("previous ")===0){e=ge(t,de(r.slice(9)),!!n)}else if(r==="document"){e=document}else if(r==="window"){e=window}else if(r==="body"){e=document.body}else if(r==="root"){e=q(t,!!n)}else if(r==="host"){e=t.getRootNode().host}else{s.push(r)}if(e){i.push(e)}}if(s.length>0){const e=s.join(",");const c=p(q(t,!!n));i.push(...F(c.querySelectorAll(e)))}return i}var pe=function(t,e,n){const r=p(q(t,n)).querySelectorAll(e);for(let e=0;e=0;e--){const o=r[e];if(o.compareDocumentPosition(t)===Node.DOCUMENT_POSITION_FOLLOWING){return o}}};function ce(e,t){if(typeof e!=="string"){return m(e,t)[0]}else{return m(ee().body,e)[0]}}function E(e,t){if(typeof e==="string"){return a(p(t)||document,e)}else{return e}}function me(e,t,n,r){if(P(t)){return{target:ee().body,event:K(e),listener:t,options:n}}else{return{target:E(e),event:K(t),listener:n,options:r}}}function ye(t,n,r,o){Wn(function(){const e=me(t,n,r,o);e.target.addEventListener(e.event,e.listener,e.options)});const e=P(n);return e?n:r}function xe(t,n,r){Wn(function(){const e=me(t,n,r);e.target.removeEventListener(e.event,e.listener)});return P(n)?n:r}const be=ee().createElement("output");function ve(t,n){const e=te(t,n);if(e){if(e==="this"){return[we(t,n)]}else{const r=m(t,e);const o=/(^|,)(\s*)inherit(\s*)($|,)/.test(e);if(o){const i=le(A(t,function(e){return e!==t&&s(le(e),n)}));if(i){r.push(...ve(i,n))}}if(r.length===0){T('The selector "'+e+'" on '+n+" returned no matches!");return[be]}else{return r}}}}function we(e,t){return le(A(e,function(e){return f(le(e),t)!=null}))}function Se(e){const t=te(e,"hx-target");if(t){if(t==="this"){return we(e,"hx-target")}else{return ce(e,t)}}else{const n=re(e);if(n.boosted){return ee().body}else{return e}}}function Ee(e){return Y.config.attributesToSettle.includes(e)}function Ce(t,n){oe(Array.from(t.attributes),function(e){if(!n.hasAttribute(e.name)&&Ee(e.name)){t.removeAttribute(e.name)}});oe(n.attributes,function(e){if(Ee(e.name)){t.setAttribute(e.name,e.value)}})}function Oe(t,e){const n=Kn(e);for(let e=0;e0){s=e.substring(0,e.indexOf(":"));n=e.substring(e.indexOf(":")+1)}else{s=e}o.removeAttribute("hx-swap-oob");o.removeAttribute("data-hx-swap-oob");const r=m(t,n,false);if(r.length){oe(r,function(e){let t;const n=o.cloneNode(true);t=ee().createDocumentFragment();t.appendChild(n);if(!Oe(s,e)){t=p(n)}const r={shouldSwap:true,target:e,fragment:t};if(!ae(e,"htmx:oobBeforeSwap",r))return;e=r.target;if(r.shouldSwap){Re(t);Ve(s,e,e,t,i);He()}oe(i.elts,function(e){ae(e,"htmx:oobAfterSwap",r)})});o.parentNode.removeChild(o)}else{o.parentNode.removeChild(o);ue(ee().body,"htmx:oobErrorNoTarget",{content:o,target:n})}return e}function He(){const e=a("#--htmx-preserve-pantry--");if(e){for(const t of[...e.children]){const n=a("#"+t.id);n.parentNode.moveBefore(t,n);n.remove()}e.remove()}}function Re(e){oe(x(e,"[hx-preserve], [data-hx-preserve]"),function(e){const t=f(e,"id");const n=ee().getElementById(t);if(n!=null){if(e.moveBefore){let e=a("#--htmx-preserve-pantry--");if(e==null){ee().body.insertAdjacentHTML("afterend","
");e=a("#--htmx-preserve-pantry--")}e.moveBefore(n,null)}else{e.parentNode.replaceChild(n,e)}}})}function qe(i,e,s){oe(e.querySelectorAll("[id]"),function(t){const n=Q(t,"id");if(n&&n.length>0){const e=p(i);const r=e&&e.querySelector(CSS.escape(t.tagName)+"#"+CSS.escape(n));if(r&&r!==e){const o=t.cloneNode();Ce(t,r);s.tasks.push(function(){Ce(t,o)})}}})}function Ae(e){return function(){S(e,Y.config.addedClass);Bt(le(e));Ne(p(e));ae(e,"htmx:load")}}function Ne(e){const t="[autofocus]";const n=J(h(e,t)?e:e.querySelector(t));if(n!=null){n.focus()}}function c(e,t,n,r){qe(e,n,r);while(n.childNodes.length>0){const o=n.firstChild;w(le(o),Y.config.addedClass);e.insertBefore(o,t);if(o.nodeType!==Node.TEXT_NODE&&o.nodeType!==Node.COMMENT_NODE){r.tasks.push(Ae(o))}}}function Ie(e,t){let n=0;while(n0}function _e(e,n,r){var t=x(e,"[hx-swap-oob], [data-hx-swap-oob]");oe(t,function(e){if(Y.config.allowNestedOobSwaps||e.parentElement===null){const t=f(e,"hx-swap-oob");if(t!=null){Te(t,e,n,r)}}else{e.removeAttribute("hx-swap-oob");e.removeAttribute("data-hx-swap-oob")}});return t.length>0}function C(d,p,g,m){if(!m){m={}}let y=null;let n=null;let e=function(){ne(m.beforeSwapCallback);d=E(d);const r=m.contextElement&&m.contextElement.isConnected?q(m.contextElement,false):ee();const e=document.activeElement;let t={};t={elt:e,start:e?e.selectionStart:null,end:e?e.selectionEnd:null};const o=En(d);if(g.swapStyle==="textContent"){d.textContent=p}else{let n=typeof p==="string"?D(p):p;o.title=m.title||n.title;if(m.historyRequest){n=n.querySelector("[hx-history-elt],[data-hx-history-elt]")||n}if(m.selectOOB){const s=m.selectOOB.split(",");for(let t=0;t0){b().setTimeout(n,g.settleDelay)}else{n()}};let t=Y.config.globalViewTransitions;if(g.hasOwnProperty("transition")){t=g.transition}const r=m.contextElement||ee();if(t&&ae(r,"htmx:beforeTransition",m.eventInfo)&&typeof Promise!=="undefined"&&document.startViewTransition){const o=new Promise(function(e,t){y=e;n=t});const i=e;e=function(){document.startViewTransition(function(){i();return o})}}try{if(g?.swapDelay&&g.swapDelay>0){b().setTimeout(e,g.swapDelay)}else{e()}}catch(e){ue(r,"htmx:swapError",m.eventInfo);ne(n);throw e}}function ze(e,t,n){const r=e.getResponseHeader(t);if(r.indexOf("{")===0){const o=v(r)||{};for(const i of Object.keys(o)){let e=o[i];if(M(e)){n=e.target!==undefined?e.target:n}else{e={value:e}}ae(n,i,e)}}else{const s=r.split(",");for(let e=0;e0){const s=o[0];if(s==="]"){e--;if(e===0){if(n===null){t=t+"true"}o.shift();t+=")})";try{const l=Tn(r,function(){return Function(t)()},function(){return true});l.source=t;return l}catch(e){ue(ee().body,"htmx:syntax:error",{error:e,source:t});return null}}}else if(s==="["){e++}if(nt(s,n,i)){t+="(("+i+"."+s+") ? ("+i+"."+s+") : (window."+s+"))"}else{t=t+s}n=o.shift()}}}function O(e,t){let n="";while(e.length>0&&!t.test(e[0])){n+=e.shift()}return n}function ot(e){let t;if(e.length>0&&Qe.test(e[0])){e.shift();t=O(e,et).trim();e.shift()}else{t=O(e,Ke)}return t}const it="input, textarea, select";function st(e,t,n){const r=[];const o=tt(t);do{O(o,Ye);const l=o.length;const c=O(o,/[,\[\s]/);if(c!==""){if(c==="every"){const u={trigger:"every"};O(o,Ye);u.pollInterval=d(O(o,/[,\[\s]/));O(o,Ye);var i=rt(e,o,"event");if(i){u.eventFilter=i}r.push(u)}else{const a={trigger:c};var i=rt(e,o,"event");if(i){a.eventFilter=i}O(o,Ye);while(o.length>0&&o[0]!==","){const f=o.shift();if(f==="changed"){a.changed=true}else if(f==="once"){a.once=true}else if(f==="consume"){a.consume=true}else if(f==="delay"&&o[0]===":"){o.shift();a.delay=d(O(o,Ke))}else if(f==="from"&&o[0]===":"){o.shift();if(Qe.test(o[0])){var s=ot(o)}else{var s=O(o,Ke);if(s==="closest"||s==="find"||s==="next"||s==="previous"){o.shift();const h=ot(o);if(h.length>0){s+=" "+h}}}a.from=s}else if(f==="target"&&o[0]===":"){o.shift();a.target=ot(o)}else if(f==="throttle"&&o[0]===":"){o.shift();a.throttle=d(O(o,Ke))}else if(f==="queue"&&o[0]===":"){o.shift();a.queue=O(o,Ke)}else if(f==="root"&&o[0]===":"){o.shift();a[f]=ot(o)}else if(f==="threshold"&&o[0]===":"){o.shift();a[f]=O(o,Ke)}else{ue(e,"htmx:syntax:error",{token:o.shift()})}O(o,Ye)}r.push(a)}}if(o.length===l){ue(e,"htmx:syntax:error",{token:o.shift()})}O(o,Ye)}while(o[0]===","&&o.shift());if(n){n[t]=r}return r}function lt(e){const t=f(e,"hx-trigger");let n=[];if(t){const r=Y.config.triggerSpecsCache;n=r&&r[t]||st(e,t,r)}if(n.length>0){return n}else if(h(e,"form")){return[{trigger:"submit"}]}else if(h(e,'input[type="button"], input[type="submit"]')){return[{trigger:"click"}]}else if(h(e,it)){return[{trigger:"change"}]}else{return[{trigger:"click"}]}}function ct(e){re(e).cancelled=true}function ut(e,t,n){const r=re(e);r.timeout=b().setTimeout(function(){if(ie(e)&&r.cancelled!==true){if(!gt(n,e,Ut("hx:poll:trigger",{triggerSpec:n,target:e}))){t(e)}ut(e,t,n)}},n.pollInterval)}function at(e){return location.hostname===e.hostname&&Q(e,"href")&&Q(e,"href").indexOf("#")!==0}function ft(e){return g(e,Y.config.disableSelector)}function ht(t,n,e){if(t instanceof HTMLAnchorElement&&at(t)&&(t.target===""||t.target==="_self")||t.tagName==="FORM"&&String(Q(t,"method")).toLowerCase()!=="dialog"){n.boosted=true;let r,o;if(t.tagName==="A"){r="get";o=Q(t,"href")}else{const i=Q(t,"method");r=i?i.toLowerCase():"get";o=Q(t,"action");if(o==null||o===""){o=location.href}if(r==="get"&&o.includes("?")){o=o.replace(/\?[^#]+/,"")}}e.forEach(function(e){mt(t,function(e,t){const n=le(e);if(ft(n)){y(n);return}fe(r,o,n,t)},n,e,true)})}}function dt(e,t){if(e.type==="submit"&&t.tagName==="FORM"){return true}else if(e.type==="click"){const n=t.closest('input[type="submit"], button');if(n&&n.form&&n.type==="submit"){return true}const r=t.closest("a");const o=/^#.+/;if(r&&r.href&&!o.test(r.getAttribute("href"))){return true}}return false}function pt(e,t){return re(e).boosted&&e instanceof HTMLAnchorElement&&t.type==="click"&&(t.ctrlKey||t.metaKey)}function gt(e,t,n){const r=e.eventFilter;if(r){try{return r.call(t,n)!==true}catch(e){const o=r.source;ue(ee().body,"htmx:eventFilter:error",{error:e,source:o});return true}}return false}function mt(l,c,e,u,a){const f=re(l);let t;if(u.from){t=m(l,u.from)}else{t=[l]}if(u.changed){if(!("lastValue"in f)){f.lastValue=new WeakMap}t.forEach(function(e){if(!f.lastValue.has(u)){f.lastValue.set(u,new WeakMap)}f.lastValue.get(u).set(e,e.value)})}oe(t,function(i){const s=function(e){if(!ie(l)){i.removeEventListener(u.trigger,s);return}if(pt(l,e)){return}if(a||dt(e,i)){e.preventDefault()}if(gt(u,l,e)){return}const t=re(e);t.triggerSpec=u;if(t.handledFor==null){t.handledFor=[]}if(t.handledFor.indexOf(l)<0){t.handledFor.push(l);if(u.consume){e.stopPropagation()}if(u.target&&e.target){if(!h(le(e.target),u.target)){return}}if(u.once){if(f.triggeredOnce){return}else{f.triggeredOnce=true}}if(u.changed){const n=e.target;const r=n.value;const o=f.lastValue.get(u);if(o.has(n)&&o.get(n)===r){return}o.set(n,r)}if(f.delayed){clearTimeout(f.delayed)}if(f.throttle){return}if(u.throttle>0){if(!f.throttle){ae(l,"htmx:trigger");c(l,e);f.throttle=b().setTimeout(function(){f.throttle=null},u.throttle)}}else if(u.delay>0){f.delayed=b().setTimeout(function(){ae(l,"htmx:trigger");c(l,e)},u.delay)}else{ae(l,"htmx:trigger");c(l,e)}}};if(e.listenerInfos==null){e.listenerInfos=[]}e.listenerInfos.push({trigger:u.trigger,listener:s,on:i});i.addEventListener(u.trigger,s)})}let yt=false;let xt=null;function bt(){if(!xt){xt=function(){yt=true};window.addEventListener("scroll",xt);window.addEventListener("resize",xt);setInterval(function(){if(yt){yt=false;oe(ee().querySelectorAll("[hx-trigger*='revealed'],[data-hx-trigger*='revealed']"),function(e){vt(e)})}},200)}}function vt(e){if(!s(e,"data-hx-revealed")&&B(e)){e.setAttribute("data-hx-revealed","true");const t=re(e);if(t.initHash){ae(e,"revealed")}else{e.addEventListener("htmx:afterProcessNode",function(){ae(e,"revealed")},{once:true})}}}function wt(e,t,n,r){const o=function(){if(!n.loaded){n.loaded=true;ae(e,"htmx:trigger");t(e)}};if(r>0){b().setTimeout(o,r)}else{o()}}function St(t,n,e){let i=false;oe(he,function(r){if(s(t,"hx-"+r)){const o=f(t,"hx-"+r);i=true;n.path=o;n.verb=r;e.forEach(function(e){Et(t,e,n,function(e,t){const n=le(e);if(ft(n)){y(n);return}fe(r,o,n,t)})})}});return i}function Et(r,e,t,n){if(e.trigger==="revealed"){bt();mt(r,n,t,e);vt(le(r))}else if(e.trigger==="intersect"){const o={};if(e.root){o.root=ce(r,e.root)}if(e.threshold){o.threshold=parseFloat(e.threshold)}const i=new IntersectionObserver(function(t){for(let e=0;e0){t.polling=true;ut(le(r),n,e)}else{mt(r,n,t,e)}}function Ct(e){const t=le(e);if(!t){return false}const n=t.attributes;for(let e=0;e", "+e).join(""));return o}else{return[]}}function qt(e){const t=Nt(e.target);const n=Lt(e);if(n){n.lastButtonClicked=t}}function At(e){const t=Lt(e);if(t){t.lastButtonClicked=null}}function Nt(e){return g(le(e),"button, input[type='submit']")}function It(e){return e.form||g(e,"form")}function Lt(e){const t=Nt(e.target);if(!t){return}const n=It(t);if(!n){return}return re(n)}function kt(e){e.addEventListener("click",qt);e.addEventListener("focusin",qt);e.addEventListener("focusout",At)}function Dt(t,e,n){const r=re(t);if(!Array.isArray(r.onHandlers)){r.onHandlers=[]}let o;const i=function(e){Tn(t,function(){if(ft(t)){return}if(!o){o=new Function("event",n)}o.call(t,e)})};t.addEventListener(e,i);r.onHandlers.push({event:e,listener:i})}function Pt(t){ke(t);for(let e=0;eY.config.historyCacheSize){i.shift()}while(i.length>0){try{sessionStorage.setItem("htmx-history-cache",JSON.stringify(i));break}catch(e){ue(ee().body,"htmx:historyCacheError",{cause:e,cache:i});i.shift()}}}function Kt(t){if(!U()){return null}t=j(t);const n=v(sessionStorage.getItem("htmx-history-cache"))||[];for(let e=0;e=200&&this.status<400){r.response=this.response;ae(ee().body,"htmx:historyCacheMissLoad",r);C(r.historyElt,r.response,n,{contextElement:r.historyElt,historyRequest:true});_t(r.path);ae(ee().body,"htmx:historyRestore",{path:e,cacheMiss:true,serverResponse:r.response})}else{ue(ee().body,"htmx:historyCacheMissLoadError",r)}};if(ae(ee().body,"htmx:historyCacheMiss",r)){t.send()}}function tn(e){Wt();e=e||location.pathname+location.search;const t=Kt(e);if(t){const n={swapStyle:"innerHTML",swapDelay:0,settleDelay:0,scroll:t.scroll};const r={path:e,item:t,historyElt:zt(),swapSpec:n};if(ae(ee().body,"htmx:historyCacheHit",r)){C(r.historyElt,t.content,n,{contextElement:r.historyElt,title:t.title});_t(r.path);ae(ee().body,"htmx:historyRestore",r)}}else{if(Y.config.refreshOnHistoryMiss){Y.location.reload(true)}else{en(e)}}}function nn(e){let t=ve(e,"hx-indicator");if(t==null){t=[e]}oe(t,function(e){const t=re(e);t.requestCount=(t.requestCount||0)+1;w(e,Y.config.requestClass)});return t}function rn(e){let t=ve(e,"hx-disabled-elt");if(t==null){t=[]}oe(t,function(e){const t=re(e);t.requestCount=(t.requestCount||0)+1;if(!e.hasAttribute("disabled")){e.setAttribute("disabled","");e.setAttribute("data-disabled-by-htmx","")}});return t}function on(e,t){oe(e.concat(t),function(e){const t=re(e);t.requestCount=(t.requestCount||1)-1});oe(e,function(e){const t=re(e);if(t.requestCount===0){S(e,Y.config.requestClass)}});oe(t,function(e){const t=re(e);if(t.requestCount===0&&e.hasAttribute("data-disabled-by-htmx")){e.removeAttribute("disabled");e.removeAttribute("data-disabled-by-htmx")}})}function sn(t,n){for(let e=0;en.indexOf(e)<0)}else{e=e.filter(e=>e!==n)}r.delete(t);oe(e,e=>r.append(t,e))}}function an(e){if(e instanceof HTMLSelectElement&&e.multiple){return F(e.querySelectorAll("option:checked")).map(function(e){return e.value})}if(e instanceof HTMLInputElement&&e.files){return F(e.files)}return e.value}function fn(t,n,r,e,o){if(e==null||sn(t,e)){return}else{t.push(e)}if(ln(e)){const i=Q(e,"name");cn(i,an(e),n);if(o){hn(e,r)}}if(e instanceof HTMLFormElement){oe(e.elements,function(e){if(t.indexOf(e)>=0){un(e.name,an(e),n)}else{t.push(e)}if(o){hn(e,r)}});new FormData(e).forEach(function(e,t){if(e instanceof File&&e.name===""){return}cn(t,e,n)})}}function hn(e,t){const n=e;if(n.willValidate){ae(n,"htmx:validation:validate");if(!n.checkValidity()){if(ae(n,"htmx:validation:failed",{message:n.validationMessage,validity:n.validity})&&!t.length&&Y.config.reportValidityOfForms){n.reportValidity()}t.push({elt:n,message:n.validationMessage,validity:n.validity})}}}function dn(n,e){for(const t of e.keys()){n.delete(t)}e.forEach(function(e,t){n.append(t,e)});return n}function pn(e,t){const n=[];const r=new FormData;const o=new FormData;const i=[];const s=re(e);if(s.lastButtonClicked&&!ie(s.lastButtonClicked)){s.lastButtonClicked=null}let l=e instanceof HTMLFormElement&&e.noValidate!==true||f(e,"hx-validate")==="true";if(s.lastButtonClicked){l=l&&s.lastButtonClicked.formNoValidate!==true}if(t!=="get"){fn(n,o,i,It(e),l)}fn(n,r,i,e,l);if(s.lastButtonClicked||e.tagName==="BUTTON"||e.tagName==="INPUT"&&Q(e,"type")==="submit"){const u=s.lastButtonClicked||e;const a=Q(u,"name");cn(a,u.value,o)}const c=ve(e,"hx-include");oe(c,function(e){fn(n,r,i,le(e),l);if(!h(e,"form")){oe(p(e).querySelectorAll(it),function(e){fn(n,r,i,e,l)})}});dn(r,o);return{errors:i,formData:r,values:Mn(r)}}function gn(e,t,n){if(e!==""){e+="&"}if(String(n)==="[object Object]"){n=JSON.stringify(n)}const r=encodeURIComponent(n);e+=encodeURIComponent(t)+"="+r;return e}function mn(e){e=Dn(e);let n="";e.forEach(function(e,t){n=gn(n,t,e)});return n}function yn(e,t,n){const r={"HX-Request":"true","HX-Trigger":Q(e,"id"),"HX-Trigger-Name":Q(e,"name"),"HX-Target":f(t,"id"),"HX-Current-URL":location.href};On(e,"hx-headers",false,r);if(n!==undefined){r["HX-Prompt"]=n}if(re(e).boosted){r["HX-Boosted"]="true"}return r}function xn(n,e){const t=te(e,"hx-params");if(t){if(t==="none"){return new FormData}else if(t==="*"){return n}else if(t.indexOf("not ")===0){oe(t.slice(4).split(","),function(e){e=e.trim();n.delete(e)});return n}else{const r=new FormData;oe(t.split(","),function(t){t=t.trim();if(n.has(t)){n.getAll(t).forEach(function(e){r.append(t,e)})}});return r}}else{return n}}function bn(e){return!!Q(e,"href")&&Q(e,"href").indexOf("#")>=0}function vn(e,t){const n=t||te(e,"hx-swap");const r={swapStyle:re(e).boosted?"innerHTML":Y.config.defaultSwapStyle,swapDelay:Y.config.defaultSwapDelay,settleDelay:Y.config.defaultSettleDelay};if(Y.config.scrollIntoViewOnBoost&&re(e).boosted&&!bn(e)){r.show="top"}if(n){const s=X(n);if(s.length>0){for(let e=0;e0?o.join(":"):null;r.scroll=u;r.scrollTarget=i}else if(l.indexOf("show:")===0){const a=l.slice(5);var o=a.split(":");const f=o.pop();var i=o.length>0?o.join(":"):null;r.show=f;r.showTarget=i}else if(l.indexOf("focus-scroll:")===0){const h=l.slice("focus-scroll:".length);r.focusScroll=h=="true"}else if(e==0){r.swapStyle=l}else{T("Unknown modifier in hx-swap: "+l)}}}}return r}function wn(e){return te(e,"hx-encoding")==="multipart/form-data"||h(e,"form")&&Q(e,"enctype")==="multipart/form-data"}function Sn(t,n,r){let o=null;Vt(n,function(e){if(o==null){o=e.encodeParameters(t,r,n)}});if(o!=null){return o}else{if(wn(n)){return dn(new FormData,Dn(r))}else{return mn(r)}}}function En(e){return{tasks:[],elts:[e]}}function Cn(e,t){const n=e[0];const r=e[e.length-1];if(t.scroll){var o=null;if(t.scrollTarget){o=le(ce(n,t.scrollTarget))}if(t.scroll==="top"&&(n||o)){o=o||n;o.scrollTop=0}if(t.scroll==="bottom"&&(r||o)){o=o||r;o.scrollTop=o.scrollHeight}if(typeof t.scroll==="number"){b().setTimeout(function(){window.scrollTo(0,t.scroll)},0)}}if(t.show){var o=null;if(t.showTarget){let e=t.showTarget;if(t.showTarget==="window"){e="body"}o=le(ce(n,e))}if(t.show==="top"&&(n||o)){o=o||n;o.scrollIntoView({block:"start",behavior:Y.config.scrollBehavior})}if(t.show==="bottom"&&(r||o)){o=o||r;o.scrollIntoView({block:"end",behavior:Y.config.scrollBehavior})}}}function On(r,e,o,i,s){if(i==null){i={}}if(r==null){return i}const l=f(r,e);if(l){let e=l.trim();let t=o;if(e==="unset"){return null}if(e.indexOf("javascript:")===0){e=e.slice(11);t=true}else if(e.indexOf("js:")===0){e=e.slice(3);t=true}if(e.indexOf("{")!==0){e="{"+e+"}"}let n;if(t){n=Tn(r,function(){if(s){return Function("event","return ("+e+")").call(r,s)}else{return Function("return ("+e+")").call(r)}},{})}else{n=v(e)}for(const c of Object.keys(n)){if(i[c]==null){i[c]=n[c]}}}return On(le(u(r)),e,o,i,s)}function Tn(e,t,n){if(Y.config.allowEval){return t()}else{ue(e,"htmx:evalDisallowedError");return n}}function Hn(e,t,n){return On(e,"hx-vars",true,n,t)}function Rn(e,t,n){return On(e,"hx-vals",false,n,t)}function qn(e,t){return se(Hn(e,t),Rn(e,t))}function An(t,n,r){if(r!==null){try{t.setRequestHeader(n,r)}catch(e){t.setRequestHeader(n,encodeURIComponent(r));t.setRequestHeader(n+"-URI-AutoEncoded","true")}}}function Nn(t){if(t.responseURL){try{const e=new URL(t.responseURL);return e.pathname+e.search}catch(e){ue(ee().body,"htmx:badResponseUrl",{url:t.responseURL})}}}function H(e,t){return e.getResponseHeader(t)!==null}function In(t,n,r){t=t.toLowerCase();if(r){if(r instanceof Element||typeof r==="string"){return fe(t,n,null,null,{targetOverride:E(r)||be,returnPromise:true})}else{let e=E(r.target);if(r.target&&!e||r.source&&!e&&!E(r.source)){e=be}return fe(t,n,E(r.source),r.event,{handler:r.handler,headers:r.headers,values:r.values,targetOverride:e,swapOverride:r.swap,select:r.select,returnPromise:true,push:r.push,replace:r.replace,selectOOB:r.selectOOB})}}else{return fe(t,n,null,null,{returnPromise:true})}}function Ln(e){const t=[];while(e){t.push(e);e=e.parentElement}return t}function kn(e,t,n){const r=new URL(t,location.protocol!=="about:"?location.href:window.origin);const o=location.protocol!=="about:"?location.origin:window.origin;const i=o===r.origin;if(Y.config.selfRequestsOnly){if(!i){return false}}return ae(e,"htmx:validateUrl",se({url:r,sameHost:i},n))}function Dn(e){if(e instanceof FormData)return e;const t=new FormData;for(const n of Object.keys(e)){if(e[n]&&typeof e[n].forEach==="function"){e[n].forEach(function(e){t.append(n,e)})}else if(typeof e[n]==="object"&&!(e[n]instanceof Blob)){t.append(n,JSON.stringify(e[n]))}else{t.append(n,e[n])}}return t}function Pn(r,o,e){return new Proxy(e,{get:function(t,e){if(typeof e==="number")return t[e];if(e==="length")return t.length;if(e==="push"){return function(e){t.push(e);r.append(o,e)}}if(typeof t[e]==="function"){return function(){t[e].apply(t,arguments);r.delete(o);t.forEach(function(e){r.append(o,e)})}}if(t[e]&&t[e].length===1){return t[e][0]}else{return t[e]}},set:function(e,t,n){e[t]=n;r.delete(o);e.forEach(function(e){r.append(o,e)});return true}})}function Mn(o){return new Proxy(o,{get:function(e,t){if(typeof t==="symbol"){const r=Reflect.get(e,t);if(typeof r==="function"){return function(){return r.apply(o,arguments)}}else{return r}}if(t==="toJSON"){return()=>Object.fromEntries(o)}if(t in e){if(typeof e[t]==="function"){return function(){return o[t].apply(o,arguments)}}}const n=o.getAll(t);if(n.length===0){return undefined}else if(n.length===1){return n[0]}else{return Pn(e,t,n)}},set:function(t,n,e){if(typeof n!=="string"){return false}t.delete(n);if(e&&typeof e.forEach==="function"){e.forEach(function(e){t.append(n,e)})}else if(typeof e==="object"&&!(e instanceof Blob)){t.append(n,JSON.stringify(e))}else{t.append(n,e)}return true},deleteProperty:function(e,t){if(typeof t==="string"){e.delete(t)}return true},ownKeys:function(e){return Reflect.ownKeys(Object.fromEntries(e))},getOwnPropertyDescriptor:function(e,t){return Reflect.getOwnPropertyDescriptor(Object.fromEntries(e),t)}})}function fe(t,n,r,o,i,P){let s=null;let l=null;i=i!=null?i:{};if(i.returnPromise&&typeof Promise!=="undefined"){var e=new Promise(function(e,t){s=e;l=t})}if(r==null){r=ee().body}const M=i.handler||Vn;const F=i.select||null;if(!ie(r)){ne(s);return e}const c=i.targetOverride||le(Se(r));if(c==null||c==be){ue(r,"htmx:targetError",{target:te(r,"hx-target")});ne(l);return e}let u=re(r);const a=u.lastButtonClicked;if(a){const A=Q(a,"formaction");if(A!=null){n=A}const N=Q(a,"formmethod");if(N!=null){if(he.includes(N.toLowerCase())){t=N}else{ne(s);return e}}}const f=te(r,"hx-confirm");if(P===undefined){const K=function(e){return fe(t,n,r,o,i,!!e)};const G={target:c,elt:r,path:n,verb:t,triggeringEvent:o,etc:i,issueRequest:K,question:f};if(ae(r,"htmx:confirm",G)===false){ne(s);return e}}let h=r;let d=te(r,"hx-sync");let p=null;let B=false;if(d){const I=d.split(":");const L=I[0].trim();if(L==="this"){h=we(r,"hx-sync")}else{h=le(ce(r,L))}d=(I[1]||"drop").trim();u=re(h);if(d==="drop"&&u.xhr&&u.abortable!==true){ne(s);return e}else if(d==="abort"){if(u.xhr){ne(s);return e}else{B=true}}else if(d==="replace"){ae(h,"htmx:abort")}else if(d.indexOf("queue")===0){const W=d.split(" ");p=(W[1]||"last").trim()}}if(u.xhr){if(u.abortable){ae(h,"htmx:abort")}else{if(p==null){if(o){const k=re(o);if(k&&k.triggerSpec&&k.triggerSpec.queue){p=k.triggerSpec.queue}}if(p==null){p="last"}}if(u.queuedRequests==null){u.queuedRequests=[]}if(p==="first"&&u.queuedRequests.length===0){u.queuedRequests.push(function(){fe(t,n,r,o,i)})}else if(p==="all"){u.queuedRequests.push(function(){fe(t,n,r,o,i)})}else if(p==="last"){u.queuedRequests=[];u.queuedRequests.push(function(){fe(t,n,r,o,i)})}ne(s);return e}}const g=new XMLHttpRequest;u.xhr=g;u.abortable=B;const m=function(){u.xhr=null;u.abortable=false;if(u.queuedRequests!=null&&u.queuedRequests.length>0){const e=u.queuedRequests.shift();e()}};const X=te(r,"hx-prompt");if(X){var y=prompt(X);if(y===null||!ae(r,"htmx:prompt",{prompt:y,target:c})){ne(s);m();return e}}if(f&&!P){if(!confirm(f)){ne(s);m();return e}}let x=yn(r,c,y);if(t!=="get"&&!wn(r)){x["Content-Type"]="application/x-www-form-urlencoded"}if(i.headers){x=se(x,i.headers)}const U=pn(r,t);let b=U.errors;const j=U.formData;if(i.values){dn(j,Dn(i.values))}const V=Dn(qn(r,o));const v=dn(j,V);let w=xn(v,r);if(Y.config.getCacheBusterParam&&t==="get"){w.set("org.htmx.cache-buster",Q(c,"id")||"true")}if(n==null||n===""){n=location.href}const S=On(r,"hx-request");const $=re(r).boosted;let E=Y.config.methodsThatUseUrlParams.indexOf(t)>=0;const C={boosted:$,useUrlParams:E,formData:w,parameters:Mn(w),unfilteredFormData:v,unfilteredParameters:Mn(v),headers:x,elt:r,target:c,verb:t,errors:b,withCredentials:i.credentials||S.credentials||Y.config.withCredentials,timeout:i.timeout||S.timeout||Y.config.timeout,path:n,triggeringEvent:o};if(!ae(r,"htmx:configRequest",C)){ne(s);m();return e}n=C.path;t=C.verb;x=C.headers;w=Dn(C.parameters);b=C.errors;E=C.useUrlParams;if(b&&b.length>0){ae(r,"htmx:validation:halted",C);ne(s);m();return e}const _=n.split("#");const z=_[0];const O=_[1];let T=n;if(E){T=z;const Z=!w.keys().next().done;if(Z){if(T.indexOf("?")<0){T+="?"}else{T+="&"}T+=mn(w);if(O){T+="#"+O}}}if(!kn(r,T,C)){ue(r,"htmx:invalidPath",C);ne(l);m();return e}g.open(t.toUpperCase(),T,true);g.overrideMimeType("text/html");g.withCredentials=C.withCredentials;g.timeout=C.timeout;if(S.noHeaders){}else{for(const D of Object.keys(x)){An(g,D,x[D])}}const H={xhr:g,target:c,requestConfig:C,etc:i,boosted:$,select:F,pathInfo:{requestPath:n,finalRequestPath:T,responsePath:null,anchor:O}};g.onload=function(){try{const t=Ln(r);H.pathInfo.responsePath=Nn(g);M(r,H);if(H.keepIndicators!==true){on(R,q)}ae(r,"htmx:afterRequest",H);ae(r,"htmx:afterOnLoad",H);if(!ie(r)){let e=null;while(t.length>0&&e==null){const n=t.shift();if(ie(n)){e=n}}if(e){ae(e,"htmx:afterRequest",H);ae(e,"htmx:afterOnLoad",H)}}ne(s)}catch(e){ue(r,"htmx:onLoadError",se({error:e},H));throw e}finally{m()}};g.onerror=function(){on(R,q);ue(r,"htmx:afterRequest",H);ue(r,"htmx:sendError",H);ne(l);m()};g.onabort=function(){on(R,q);ue(r,"htmx:afterRequest",H);ue(r,"htmx:sendAbort",H);ne(l);m()};g.ontimeout=function(){on(R,q);ue(r,"htmx:afterRequest",H);ue(r,"htmx:timeout",H);ne(l);m()};if(!ae(r,"htmx:beforeRequest",H)){ne(s);m();return e}var R=nn(r);var q=rn(r);oe(["loadstart","loadend","progress","abort"],function(t){oe([g,g.upload],function(e){e.addEventListener(t,function(e){ae(r,"htmx:xhr:"+t,{lengthComputable:e.lengthComputable,loaded:e.loaded,total:e.total})})})});ae(r,"htmx:beforeSend",H);const J=E?null:Sn(g,r,w);g.send(J);return e}function Fn(e,t){const n=t.xhr;let r=null;let o=null;if(H(n,"HX-Push")){r=n.getResponseHeader("HX-Push");o="push"}else if(H(n,"HX-Push-Url")){r=n.getResponseHeader("HX-Push-Url");o="push"}else if(H(n,"HX-Replace-Url")){r=n.getResponseHeader("HX-Replace-Url");o="replace"}if(r){if(r==="false"){return{}}else{return{type:o,path:r}}}const i=t.pathInfo.finalRequestPath;const s=t.pathInfo.responsePath;const l=t.etc.push||te(e,"hx-push-url");let c=t.etc.replace||te(e,"hx-replace-url");if(c==="false")c=null;const u=re(e).boosted;let a=null;let f=null;if(l){a="push";f=l}else if(c){a="replace";f=c}else if(u){a="push";f=s||i}if(f){if(f==="false"){return{}}if(f==="true"){f=s||i}if(t.pathInfo.anchor&&f.indexOf("#")===-1){f=f+"#"+t.pathInfo.anchor}return{type:a,path:f}}else{return{}}}function Bn(e,t){var n=new RegExp(e.code);return n.test(t.toString(10))}function Xn(e){for(var t=0;t`+`.${t}{opacity:0;visibility: hidden} `+`.${n} .${t}, .${n}.${t}{opacity:1;visibility: visible;transition: opacity 200ms ease-in}`+"")}}function Yn(){const e=ee().querySelector('meta[name="htmx-config"]');if(e){return v(e.content)}else{return null}}function Qn(){const e=Yn();if(e){Y.config=se(Y.config,e)}}Wn(function(){Qn();Zn();let e=ee().body;Bt(e);const t=ee().querySelectorAll("[hx-trigger='restored'],[data-hx-trigger='restored']");e.addEventListener("htmx:abort",function(e){const t=e.detail.elt||e.target;const n=re(t);if(n&&n.xhr){n.xhr.abort()}});const n=window.onpopstate?window.onpopstate.bind(window):null;window.onpopstate=function(e){if(e.state&&e.state.htmx){tn();oe(t,function(e){ae(e,"htmx:restored",{document:ee(),triggerEvent:ae})})}else{if(n){n(e)}}};b().setTimeout(function(){ae(e,"htmx:load",{});e=null},0)});return Y}(); \ No newline at end of file diff --git a/backend/apps/ifc_validation_bff/static/report/print.css b/backend/apps/ifc_validation_bff/static/report/print.css new file mode 100644 index 00000000..1772a64b --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/report/print.css @@ -0,0 +1,95 @@ +@page { + size: A4; + margin: 24mm 17mm 20mm; + @top-center { content: element(report-header); vertical-align: middle; } + @bottom-left { content: element(report-footer); vertical-align: middle; } + @bottom-right { content: "Page " counter(page) " of " counter(pages); font: 8pt "DejaVu Sans"; color: #64748b; } +} +html { font-size: 9pt; } +body.pdf-report { margin: 0; background: white; color: #243446; font-family: "DejaVu Sans", sans-serif; line-height: 1.5; } +.running-header { position: running(report-header); width: 176mm; padding-bottom: 3mm; border-bottom: .5pt solid #dce3eb; } +.running-header img { width: 43mm; vertical-align: middle; } +.running-header span { float: right; margin-top: 5mm; font-size: 7pt; letter-spacing: 1.2pt; color: #64748b; } +.running-footer { position: running(report-footer); font-size: 7.5pt; color: #64748b; } +.report-content { margin: 0; padding: 0; max-width: none; } +.document-title { border-bottom: 3pt solid #1976d2; padding: 2mm 0 4mm; margin-bottom: 4mm; } +.eyebrow { font-size: 8pt; color: #64748b; letter-spacing: .5pt; } +h1 { font-size: 28pt; line-height: 1.15; color: #123b61; margin: 2mm 0 4mm; bookmark-level: none; } +.file-title { font-size: 13pt; font-weight: bold; overflow-wrap: anywhere; margin: 0 0 2mm; } +.document-meta { color: #64748b; font-size: 8pt; margin: 0; } +h2 { color: #123b61; font-size: 17pt; border-bottom: .5pt solid #b9cbdc; padding-bottom: 2mm; margin: 7mm 0 3mm; break-after: avoid; bookmark-level: 1; } +h3 { font-size: 11pt; margin: 5mm 0 2mm; break-after: avoid; bookmark-level: 2; } +h4 { font-size: 9.5pt; margin: 0; padding: 0; color: #243446; border-left: 0; background: #f1f5f9; break-after: avoid; bookmark-level: 3; bookmark-state: closed; } +.print-chapter { break-before: page; } +#file { break-before: page; } +.print-chapter.empty-chapter { break-before: auto; } +.chapter-description { color: #64748b; margin: 0 0 5mm; } +p { orphans: 3; widows: 3; } +a { color: #1767a8; text-decoration: none; overflow-wrap: anywhere; } +table { width: 100%; border-collapse: collapse; table-layout: fixed; margin: 3mm 0 5mm; } +thead { display: table-header-group; } +tfoot { display: table-footer-group; } +tr { break-inside: avoid; } +th, td { padding: 2mm 2.2mm; border-bottom: .5pt solid #dce3eb; vertical-align: top; overflow-wrap: anywhere; } +thead th { background: #eaf0f6; color: #123b61; font-weight: bold; text-align: left; } +.overview { font-size: 7.5pt; } +.overview th,.overview td { padding: 1.5mm 1.2mm; } +.overview thead th { white-space: nowrap; font-size: 7pt; text-align: center; vertical-align: middle; } +.overview thead th[rowspan] { text-align: left; } +.overview .overview-layer { width: 30%; } +.overview .overview-state { width: 14%; } +.overview tbody th { text-align: left; font-weight: normal; } +.overview td:not(:nth-child(2)) { text-align: center; } +.scope-note { background: #f1f5f9; padding: 3mm; color: #526276; font-size: 8pt; } +.notice { border-left: 3pt solid #bd482d; padding: 3mm; background: #fff3ed; } +.conformance-status { font-weight: bold; padding: 2mm 3mm; border-left: 3pt solid #64748b; background: #f1f5f9; } +.conformance-status[data-status=i] { border-color: #bd482d; color: #9b3223; background: #fff1ed; } +.conformance-status[data-status=w] { border-color: #bd8300; color: #855c00; background: #fff8e7; } +.conformance-status[data-status=v] { border-color: #258355; color: #206642; background: #eef7f1; } +.contents { margin: 4mm 0 8mm; } +.contents h3 { bookmark-level: none; } +.contents a { display: block; border-bottom: .5pt dotted #cbd5e1; padding: 1mm 0; line-height: 1.35; } +.contents a::after { content: target-counter(attr(href), page); float: right; color: #64748b; } +.contents span { color: #64748b; font-size: 8pt; margin-left: 3mm; } +.file-info, .signature { border: 0; box-shadow: none; border-radius: 0; } +.file-info td, .signature td { font-size: 8pt; padding: 2.2mm; border-color: #dce3eb; } +.file-info td:first-child, .signature td:first-child { width: 32%; } +.field-name { width: 32%; } +.signature tbody tr:last-child { break-before: avoid; } +.signature th { text-align: left; } +.signature[data-verification="invalid"] thead th { color: #a33324; background: #fff0ed; } +.field-warning { display: inline; color: #a65a00; font-size: 7pt; margin-left: 2mm; } +.result-group { padding: 0; margin: 4mm 0 6mm; background: white; } +.result-group[data-severity="0"],.result-group[data-severity="1"],.result-group[data-severity="2"] { break-inside: avoid; } +.result-group[data-severity="4"] h4, .result-group[data-severity="4"] .rule-description { background: #fff1ed; } +.result-group[data-severity="3"] h4, .result-group[data-severity="3"] .rule-description { background: #fff8e7; } +.result-group[data-severity="2"] h4, .result-group[data-severity="2"] .rule-description { background: #eef7f1; } +.section-body { background: white; padding: 0; } +.group-content { padding: 0; } +.caption { text-transform: none; } +.suffix { font-size: 8pt; font-weight: normal; } +.subcaption { visibility: visible; padding: 0; color: #64748b; } +.rule-description { font-size: 8pt; margin: 0; padding: 0; background: #f1f5f9; } +.rule-description br + br { display: none; } +.results { font-size: 7.5pt; background: white; margin: 0; } +.group-content > p { margin: 0; } +.results th,.results td { padding: 2mm; border-bottom: .5pt solid #dce3eb; } +.results th { font-weight: bold; } +.results tr:nth-child(even) { background: #f8fafc; } +.results:not(.grouped-results) th:first-child { width: 15%; } +.results:not(.grouped-results) th:nth-child(2) { width: 10%; } +.results:not(.grouped-results) th:nth-child(3) { width: 21%; } +.grouped-results .instance-id, .grouped-results .syntax-position { width: 10%; } +.grouped-results .instance-entity { width: 21%; } +.grouped-results .outcome-severity { width: 15%; } +.syntax { margin: 3mm 0; width: 100%; } +.syntax .pre { display: block; } +.syntax:not(.grouped-results) th:first-child,.syntax:not(.grouped-results) th:nth-child(2) { width: 10%; } +.syntax:not(.grouped-results) th:nth-child(3) { width: 15%; } +.pre { white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere; } +.mono { font-family: "DejaVu Sans Mono", monospace; font-size: 7pt; word-break: normal; overflow-wrap: anywhere; } +.task-summary { font-size: 7.5pt; } +.task-summary th:first-child { width: 32%; } +.task-summary th:nth-child(2) { width: 17%; } +.task-summary tbody th { text-align: left; font-weight: normal; } +.empty-chapter { color: #64748b; font-style: italic; } diff --git a/backend/apps/ifc_validation_bff/static/report/report.css b/backend/apps/ifc_validation_bff/static/report/report.css new file mode 100644 index 00000000..e9a5aec8 --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/report/report.css @@ -0,0 +1,52 @@ +body { margin: 0; background: #f2f6f8; color: #202020; font-family: Arial, sans-serif; } +body > nav { padding: 1em; background: white; } +main { max-width: 850px; margin: 1em auto; padding: 0 1em; } +main > h2 { text-align: center; } +table { width: 100%; border-collapse: collapse; } +.file-info, .signature, #report-section, #header-policy { background: white; margin: 1em 0; border-radius: 4px; box-shadow: 0 2px 4px #0002; } +#header-policy h4 { margin: 0; padding: 16px 16px 0; font-weight: normal; } +.file-info td, .signature td, .file-info th, .section-heading { padding: 16px; border-bottom: 1px solid #ddd; font-size: 14px; text-align: left } +.file-info td:first-child, .signature td:first-child { width: 33%; } +.file-info td { position: relative; } +.file-info td .icon-button { + position: absolute; + transform: translateY(-25%); +} +.header-warning svg { width: 24px; height: 24px; fill: #ed6c02; vertical-align: middle; margin-left: 8px; } +[data-status="v"], [data-severity="1"], [data-severity="2"] { --status-color: #d9f2d9; } +[data-status="i"], [data-severity="4"] { --status-color: #fcc; } +[data-status="w"], [data-severity="3"] { --status-color: #fdfd96; } +[data-status="n"], [data-status="p"], [data-status="-"], [data-severity="0"] { --status-color: #ddd; } +.section-heading { display: flex; justify-content: space-between; align-items: center } +.section-heading form { font-size: small; } +.section-body, .result-group { background: var(--status-color); padding: .1em 0; } +.section-body > p { margin: .5em 1em; } +summary { cursor: pointer; padding: 16px; } +.caption { text-transform: capitalize; } +.suffix { font-size: .9em; font-style: italic; } +.subcaption { font-size: 80%; visibility: hidden; } +details[open] .subcaption { visibility: visible; } +.group-content { padding: 16px; } +.rule-description { margin-bottom: 1em; } +.results { font-size: 80%; text-align: left; background: #ffffff80; } +.results th, .results td { padding: .2em .5em; vertical-align: top; text-align: left; } +.syntax { margin: .8em; width: calc(100% - 1.6em); background: transparent; } +.pre { white-space: pre-wrap; word-break: break-word; } +.mono { font-family: monospace; word-break: break-all; } +.attribute-value { background: #00000010; padding: 3px; } +.instance-reference { padding: 3px; border-bottom: dotted 3px gray; } +.pagination { display: flex; justify-content: center; align-items: center; gap: 1em; padding: 12px; } +.pagination a, .pagination button, .copy { font-size: 18px; border: 0; background: transparent; cursor: pointer; } +.pagination button:disabled { color: #aaa; cursor: default; } +.copy { margin-left: 1em; } +.copy svg, .pagination svg { width: 24px; height: 24px; fill: currentColor; vertical-align: middle; } +.signature { border: 2px solid green; } +.signature[data-verification="invalid"] { border-color: red; } +.signature[data-verification="valid_unknown_cert"] { border-color: gray; } +.explanation::before { + content: "ℹ "; +} +.explanation { + font-size: 80%; +} +@media (max-width: 650px) { .section-heading { display: block; } .group-content { overflow-x: auto; } } diff --git a/backend/apps/ifc_validation_bff/static/report/report.js b/backend/apps/ifc_validation_bff/static/report/report.js new file mode 100644 index 00000000..de520837 --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/report/report.js @@ -0,0 +1,12 @@ +document.addEventListener('click', async (event) => { + const button = event.target.closest('.copy'); + if (!button) return; + event.preventDefault(); + const text = button.closest('details').querySelector('.clipboard').value; + try { + await navigator.clipboard.writeText(text); + button.title = 'Copied!'; + } catch { + button.title = 'Copy failed'; + } +}); diff --git a/backend/apps/ifc_validation_bff/static/ui/background.jpg b/backend/apps/ifc_validation_bff/static/ui/background.jpg new file mode 100644 index 00000000..5ee11b9f Binary files /dev/null and b/backend/apps/ifc_validation_bff/static/ui/background.jpg differ diff --git a/backend/apps/ifc_validation_bff/static/ui/logo.png b/backend/apps/ifc_validation_bff/static/ui/logo.png new file mode 100644 index 00000000..b9a49ffe Binary files /dev/null and b/backend/apps/ifc_validation_bff/static/ui/logo.png differ diff --git a/backend/apps/ifc_validation_bff/static/ui/scorecards.png b/backend/apps/ifc_validation_bff/static/ui/scorecards.png new file mode 100644 index 00000000..c624bdb4 Binary files /dev/null and b/backend/apps/ifc_validation_bff/static/ui/scorecards.png differ diff --git a/backend/apps/ifc_validation_bff/static/ui/ui.css b/backend/apps/ifc_validation_bff/static/ui/ui.css new file mode 100644 index 00000000..e24c3b6c --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/ui/ui.css @@ -0,0 +1,179 @@ +:root { color-scheme: light; --blue: #1976d2; --text: #27333c; } +body.ui-page { color: var(--text); font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; } +a { color: var(--blue); } +button, input, select { font: inherit; } +button, a, input { accent-color: var(--blue); } +button:disabled { cursor: default; opacity: .5; } +.material-icon { display: inline-block; width: 24px; height: 24px; fill: currentColor; flex-shrink: 0; vertical-align: middle; } +a, button, summary { -webkit-tap-highlight-color: transparent; transition: background-color 150ms, box-shadow 150ms, color 150ms; } +a:focus-visible, button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; } +.icon-text { display: inline-flex; align-items: center; gap: .5em; } +.icon-button { display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box; width: 40px; height: 40px; padding: 8px; border: 0; border-radius: 50%; background: transparent; color: #0008; vertical-align: middle; cursor: pointer; text-decoration: none; } +.icon-button:not(:disabled):is(:hover,:focus-visible) { background: #0000000a; text-decoration: none; } +.icon-button:not(:disabled):active { background: #0000001f; } +.when-open { display: none; } +details[open] > summary .when-open { display: inline-flex; } +details[open] > summary .when-closed { display: none; } +.button { display: inline-block; background: var(--blue); color: white; border: 1px solid var(--blue); border-radius: 5px; padding: .7em 1.2em; cursor: pointer; text-decoration: none; } +.button:not(:disabled):is(:hover,:focus-visible) { background: #1565c0; border-color: #1565c0; box-shadow: 0 3px 6px #0003; } +.button:not(:disabled):active { box-shadow: 0 2px 3px #0004; } +.text-button { color: var(--blue); border: 0; background: none; padding: .6em; cursor: pointer; } +.text-button:not(:disabled):is(:hover,:focus-visible) { background: #1976d20a; text-decoration: underline; border-radius: 4px; } +.app-header { background: white; display: flex; flex-shrink: 0; justify-content: space-between; align-items: center; padding: 0 3%; border-bottom: 1px solid #eee; } +.brand { height: 130px; max-width: 65vw; object-fit: contain; } +.sign-in { background: white; color: black; border-color: black; } +.sign-in:is(:hover,:focus-visible) { background: #0000000a; border-color: black; box-shadow: none; } +.account-menu { position: relative; } +.account-menu > summary { border-radius: 50%; background: #777; color: white; padding: .7em; list-style: none; } +.account-menu > summary:is(:hover,:focus-visible) { background: #555; box-shadow: 0 0 0 6px #0000000a; } +.account-menu > div { position: absolute; right: 0; z-index: 5; background: white; min-width: 160px; box-shadow: 0 3px 12px #0003; } +.account-menu a { display: block; padding: .6em; text-decoration: none; color: inherit; } +.account-menu button { + border: 0; + background: white; + color: inherit; + padding: .6em; + cursor: pointer; + width: 100%; + text-align: left; +} +.account-menu a:is(:hover,:focus-visible), .account-menu button:is(:hover,:focus-visible) { background: #0000000a; } +.app-layout { display: flex; flex: 1; min-height: 0; } +.side-menu { flex: 0 0 220px; display: flex; flex-direction: column; justify-content: space-between; background: white; border-right: 1px solid #ddd; overflow-y: auto; } +.side-menu a { display: flex; align-items: center; gap: 16px; color: #555; text-decoration: none; padding: 1em 1.5em; } +.side-menu a[aria-current] { box-shadow: inset 4px 0 var(--blue); background: #f2f6f8; } +.side-menu a:is(:hover,:focus-visible) { background: #0000000a; } +.side-menu p { padding: .5em; text-align: center; font-size: .85em; overflow-wrap: anywhere; } +.page-column { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; } +main.ui-content { max-width: none; width: auto; padding: 0; margin: 0; flex: 1; min-width: 0; } +.page-column > footer { text-align: center; font-size: .85em; padding: 1.2em; line-height: 1.6; } +.disclaimer { background: #ffffff80; text-align: center; padding: .5em 1em; } +.hero { background: linear-gradient(#0005,#0005),url('background.jpg') center/cover; color: white; text-align: center; padding: 5em 2em; } +.hero h1 { font-size: clamp(2em,4vw,3em); margin-top: 0; text-shadow: 0 2px 8px #0008; } +.hero p { font-size: 1.25em; max-width: 850px; margin: 1em auto 2em; text-shadow: 0 1px 4px #0009; } +.hero .button { background: #0005; border: 2px solid white; font-weight: bold; } +.hero .button:is(:hover,:focus-visible) { background: #0009; border-color: white; } +.landing-body { background: white; padding: 1em clamp(1em,5vw,5em) 3em; } +.landing-body h3 { font-weight: 300; text-transform: uppercase; margin-bottom: 0; } +.landing-body h2 { margin-top: 0; margin-bottom: 2em; } +.card-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1em; } +.card { position: relative; background: #e7e7e7; border-radius: 12px; padding: 1.5em; color: inherit; text-decoration: none; } +.resource:is(:hover,:focus-visible) { background: #ddd; box-shadow: 0 2px 6px #0002; } +.open-icon { position: absolute; top: 14px; right: 14px; opacity: .7; } +.open-icon .material-icon { width: 18px; height: 18px; } +.resource:is(:hover,:focus-visible) .open-icon { opacity: 1; } +.card h4 { margin-top: .5em; margin-bottom: .5em; } +.card p { line-height: 1.5; } +.workflow { padding: 0; list-style: none; } +.workflow li { display: flex; gap: 1.5em; margin: 1.5em 0; } +.workflow li > span { font-size: 2.75em; color: #0004; font-weight: 800; min-width: 1.5em; line-height: 1; } +.workflow li p { margin: .5em 0; } +.faq { border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; } +.faq > summary { display: flex; align-items: center; justify-content: space-between; gap: 1em; font-weight: bold; font-size: 18px; padding: 1.5em 0; list-style: none; } +.faq > summary::-webkit-details-marker,.result-group > summary::-webkit-details-marker,.affiliation-help > summary::-webkit-details-marker { display: none; } +.faq > summary:is(:hover,:focus-visible),.affiliation-help > summary:is(:hover,:focus-visible) { background: #0000000a; } +.faq p { padding-bottom: 1em; line-height: 1.6; } +.dashboard-content { padding: 0; } +.upload-workflow { display: flex; align-items: center; gap: 3em; padding: 2em 0; justify-content: center; } +.upload-panel { + max-width: 300px; + width: 100%; + background-color: #fff; + border-radius: 4px; + box-shadow: 2px 2px 8px #00000080; + padding: 16px; +} +.upload-panel .dropzone { width: 100%; background: #eee; border: 1px solid #ddd; min-height: 200px; max-height: 200px; overflow: auto; text-align: center; box-sizing: border-box; } +.upload-panel .dropzone:hover,.upload-panel .dropzone.dz-drag-hover { background: #f4f4f4; } +.upload-panel .dz-image { display: none; } +.upload-panel .dz-details { width: auto; position: inherit; padding: 0; } +.upload-panel .dz-preview { border: 1px solid #aaa; width: 75%; padding: 1em; background: #ddd; } +.upload-panel .dz-progress { display: none; } +.upload-panel .upload-icon { display: block; opacity: .5; } +.upload-icon .material-icon { width: 3em; height: 3em; } +.upload-actions { display: flex; gap: .5em; padding-top: .7em; } +.upload-panel progress { width: 100%; margin-top: .7em; } +.instructions { max-width: 370px; padding-left: 1.3em; line-height: 1.6; } +.instructions li { padding: .7em; } +.table-toolbar { min-height: 50px; display: flex; gap: 1em; align-items: center; } +.table-scroll { overflow-x: auto; } +.dashboard-table { background: white; font-size: 14px; } +.dashboard-table th { background: #e4eaee; padding: 1em .7em; text-align: left; } +.dashboard-table td { padding: .9em .7em; border-bottom: 1px solid #ddd; } +.dashboard-table th:nth-child(n+3):nth-child(-n+6),.dashboard-table td:nth-child(n+3):nth-child(-n+6) { text-align: center; } +.dashboard-table tr:has(input[name=selected]:checked), +.table-toolbar { + background: #e8f0fb; +} +.dashboard-table tr:hover { background: #f1f7fb; } +.dashboard-table .icon-button { box-shadow: 2px 2px 3px rgba(0,0,0,.1); } +.dashboard-table .icon-button:not(:disabled):is(:hover,:focus-visible) { box-shadow: 2px 2px 3px rgba(0,0,0,.3); } +.status-symbol { display: inline-flex; width: 24px; height: 24px; vertical-align: middle; color: #aaa; } +.status-symbol svg { width: 24px; height: 24px; fill: currentColor; } +.status-symbol[data-status=v],.header-status.valid { color: #2ab672; } +.status-symbol[data-status=i] { color: #d32f2f; } +.status-symbol[data-status=w],.header-status.warning { color: #ed6c02; } +.header-status { color: var(--blue); } +.signature-status { margin-left: .5em; } +.signature-status[data-status=v] { color: #2ab672; } +.signature-status[data-status=i] { color: #d32f2f; } +.pdf-download { color: var(--blue); } +.header-warning { color: #ed6c02; margin-left: 8px; } +.header-warning .material-icon { margin-left: 0; } +.dashboard-pagination { display: flex; justify-content: end; align-items: center; gap: 1em; padding: 1em 0; } +.dashboard-pagination svg { width: 24px; height: 24px; fill: currentColor; } +.dashboard-pagination button { border: 0; background: transparent; } +.pagination a,.pagination button,.dashboard-pagination > a,.dashboard-pagination > button { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0; border-radius: 50%; text-decoration: none; } +.pagination a:is(:hover,:focus-visible),.pagination button:not(:disabled):is(:hover,:focus-visible),.dashboard-pagination > a:is(:hover,:focus-visible) { background: #0000000a; } +.result-group > summary { list-style: none; } +.result-group > summary:is(:hover,:focus-visible) { background: #0000000a; } +.tree-toggle { vertical-align: middle; margin-right: 4px; } +.copy .material-icon { width: 20px; height: 20px; } +.affiliation-help > summary { list-style: none; color: var(--blue); } +.affiliation-help .material-icon { margin-right: .4em; } +.empty-state .material-icon { width: 35px; height: 35px; color: #0004; } +.validation-progress { display: inline-flex; align-items: center; gap: .5em; } +.validation-progress progress { width: 50px; } +.report-content { max-width: 850px; margin: 1em auto; padding: 0 1em; } +.report-content > h2 { text-align: center; } +.paper { background: white; padding: 2em; border-radius: 6px; margin: 2em auto; max-width: 950px; } +.prose { max-width: 850px; line-height: 1.6; } +.prose img { max-width: 100%; } +.prose figure { text-align: center; margin: 2em 0; } +.prose figcaption { font-size: .85em; } +.allowlist article { margin-top: 2em; } +.allowlist th,.allowlist td { padding: .5em; text-align: left; border: 1px solid #ddd; } +.allowlist code { white-space: pre-wrap; overflow-wrap: anywhere; } +.error,#request-error { background: #fbe4e4; color: #8d1515; padding: 1em; } +#request-error { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; } +dialog { max-width: 750px; width: calc(100% - 4em); border: 0; border-radius: 8px; padding: 2em; box-shadow: 0 2px 20px #0004; } +dialog::backdrop { background: #0007; } +dialog label { display: block; padding: .6em 0; } +dialog details { margin: 1em 0; } +@media (max-width: 850px) { .side-menu { flex-basis: 160px; } .upload-workflow { gap: 1em; } } +@media (max-width: 600px) { .side-menu { display: none; } .brand { height: 95px; } .card-grid { grid-template-columns: 1fr; } .upload-workflow { flex-direction: column; } .dashboard-pagination { flex-wrap: wrap; } .paper { margin: 1em; padding: 1em; } } +select { + background: #0000; + border: solid 1px #0003; + border-radius: 4px; +} +.upload-actions button { + margin: 0 auto; +} +ol.instructions li::before { + content: counter(list-item); + background: rgb(25, 118, 210); + color: white; + border-radius: 50%; + display: inline-block; + width: 1.5em; + height: 1.5em; + text-align: center; + line-height: 1.5em; + margin-right: 1em; +} +ol.instructions li { list-style: none; } + +.report-section .group-contents th { + font-weight: bold; +} \ No newline at end of file diff --git a/backend/apps/ifc_validation_bff/static/ui/ui.js b/backend/apps/ifc_validation_bff/static/ui/ui.js new file mode 100644 index 00000000..af9eb7be --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/ui/ui.js @@ -0,0 +1,114 @@ +// Browser mechanics only. Validation status, permissions, paging and row content are Python-owned. +function initializeUI() { + document.querySelectorAll('dialog[data-required]').forEach((dialog) => { + if (!dialog.open) dialog.showModal(); + dialog.addEventListener('cancel', (event) => event.preventDefault()); + }); + updateSelection(); + initializeUpload(); +} + +function initializeUpload() { + const form = document.getElementById('ifc_dropzone'); + if (!form || form.dropzone) return; + const panel = form.closest('#upload-panel'); + const progress = form.querySelector('progress'); + const errors = panel.querySelector('[data-upload-errors]'); + const buttons = panel.querySelectorAll('.upload-actions button'); + const showError = (message) => { + const alert = document.createElement('p'); + alert.className = 'error'; + alert.setAttribute('role', 'alert'); + alert.textContent = message; + errors.replaceChildren(alert); + }; + // Same queue and acceptance options as React's Dz.js; limits come from UploadPolicy. + const dz = new Dropzone(form, { + uploadMultiple: true, + acceptedFiles: '.ifc', + parallelUploads: 100, + maxFiles: Number(form.dataset.maxFiles), + maxFilesize: Number(form.dataset.maxSize), + autoProcessQueue: false, + addRemoveLinks: true, + withCredentials: true, + headers: { 'X-CSRFToken': form.elements.csrfmiddlewaretoken.value, 'HX-Request': 'true' }, + // Django's existing multipart endpoint accepts repeated `file` fields. + paramName: () => 'file', + }); + dz.hiddenFileInput.setAttribute('aria-label', 'Select IFC files'); + dz.on('addedfile', () => errors.replaceChildren()); + dz.on('totaluploadprogress', (value) => { progress.value = value; }); + dz.on('sendingmultiple', () => { + progress.hidden = false; + buttons.forEach((button) => { button.disabled = true; }); + }); + dz.on('queuecomplete', () => buttons.forEach((button) => { button.disabled = false; })); + dz.on('successmultiple', (files) => { + const redirect = files[0].xhr.getResponseHeader('HX-Redirect'); + if (redirect) window.location.assign(redirect); + }); + dz.on('error', (file, message, xhr) => { + if (xhr) { + const document = new DOMParser().parseFromString(xhr.responseText, 'text/html'); + const messages = [...document.querySelectorAll('[data-upload-errors] [role=alert]')]; + message = messages.map((item) => item.textContent).join(' ') || 'We could not upload this file. Please try again.'; + } + file.previewElement.querySelector('[data-dz-errormessage]').textContent = message; + if (!xhr && file.size > dz.options.maxFilesize * 1024 * 1024) { + dz.removeFile(file); + showError(`Oops! File Size Limit Reached. You've attempted to upload a file larger than ${dz.options.maxFilesize} MB. Need assistance with larger files? Contact our support team for tailored solutions.`); + } else { + showError(message); + } + }); + form.addEventListener('submit', (event) => { + event.preventDefault(); + if (dz.getQueuedFiles().length) dz.processQueue(); + else showError('Select at least one IFC file to validate.'); + }); + form.addEventListener('reset', () => { + dz.removeAllFiles(); + errors.replaceChildren(); + progress.hidden = true; + progress.value = 0; + }); +} + +function updateSelection() { + const form = document.getElementById('dashboard-form'); + if (!form) return; + const choices = [...form.querySelectorAll('input[type=checkbox][name=selected]:not(:disabled)')]; + const selected = form.querySelectorAll('input[name=selected]:checked, input[type=hidden][name=selected]').length; + form.querySelector('[data-selection-count]').textContent = selected ? `${selected} selected` : ''; + form.querySelector('[data-delete-selected]').disabled = !selected; + form.querySelector('.table-toolbar').style.visibility = selected ? 'visible' : 'hidden'; + const all = form.querySelector('[data-select-all]'); + all.checked = choices.length > 0 && choices.every((input) => input.checked); + all.indeterminate = choices.some((input) => input.checked) && !all.checked; +} + +document.addEventListener('DOMContentLoaded', initializeUI); +document.addEventListener('htmx:afterSwap', initializeUI); + +document.addEventListener('change', (event) => { + if (event.target.matches('[data-select-all]')) { + document.querySelectorAll('#dashboard-form input[type=checkbox][name=selected]:not(:disabled)').forEach((input) => { input.checked = event.target.checked; }); + } + if (event.target.matches('[name=selected], [data-select-all]')) updateSelection(); +}); + +document.addEventListener('click', (event) => { + const row = event.target.closest('[data-select-row]'); + if (!row || event.target.closest('a,button,input,label')) return; + const input = row.querySelector('input[name=selected]'); + if (!input.disabled) { input.checked = !input.checked; updateSelection(); } +}); + +for (const name of ['htmx:responseError', 'htmx:sendError']) { + document.addEventListener(name, () => { + const error = document.getElementById('request-error'); + error.textContent = 'We could not complete this request. Please try again.'; + error.hidden = false; + }); +} diff --git a/backend/apps/ifc_validation_bff/static/ui/vendor/dropzone/LICENSE b/backend/apps/ifc_validation_bff/static/ui/vendor/dropzone/LICENSE new file mode 100644 index 00000000..cb460d23 --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/ui/vendor/dropzone/LICENSE @@ -0,0 +1,23 @@ +LICENSE + +(The MIT License) + +Copyright (c) 2021 Matias Meno +Logo (c) 2015 "1910" www.weare1910.com + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/backend/apps/ifc_validation_bff/static/ui/vendor/dropzone/dropzone.min.css b/backend/apps/ifc_validation_bff/static/ui/vendor/dropzone/dropzone.min.css new file mode 100644 index 00000000..e8f4be41 --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/ui/vendor/dropzone/dropzone.min.css @@ -0,0 +1 @@ +@-webkit-keyframes passing-through{0%{opacity:0;-webkit-transform:translateY(40px);-moz-transform:translateY(40px);-ms-transform:translateY(40px);-o-transform:translateY(40px);transform:translateY(40px)}30%,70%{opacity:1;-webkit-transform:translateY(0px);-moz-transform:translateY(0px);-ms-transform:translateY(0px);-o-transform:translateY(0px);transform:translateY(0px)}100%{opacity:0;-webkit-transform:translateY(-40px);-moz-transform:translateY(-40px);-ms-transform:translateY(-40px);-o-transform:translateY(-40px);transform:translateY(-40px)}}@-moz-keyframes passing-through{0%{opacity:0;-webkit-transform:translateY(40px);-moz-transform:translateY(40px);-ms-transform:translateY(40px);-o-transform:translateY(40px);transform:translateY(40px)}30%,70%{opacity:1;-webkit-transform:translateY(0px);-moz-transform:translateY(0px);-ms-transform:translateY(0px);-o-transform:translateY(0px);transform:translateY(0px)}100%{opacity:0;-webkit-transform:translateY(-40px);-moz-transform:translateY(-40px);-ms-transform:translateY(-40px);-o-transform:translateY(-40px);transform:translateY(-40px)}}@keyframes passing-through{0%{opacity:0;-webkit-transform:translateY(40px);-moz-transform:translateY(40px);-ms-transform:translateY(40px);-o-transform:translateY(40px);transform:translateY(40px)}30%,70%{opacity:1;-webkit-transform:translateY(0px);-moz-transform:translateY(0px);-ms-transform:translateY(0px);-o-transform:translateY(0px);transform:translateY(0px)}100%{opacity:0;-webkit-transform:translateY(-40px);-moz-transform:translateY(-40px);-ms-transform:translateY(-40px);-o-transform:translateY(-40px);transform:translateY(-40px)}}@-webkit-keyframes slide-in{0%{opacity:0;-webkit-transform:translateY(40px);-moz-transform:translateY(40px);-ms-transform:translateY(40px);-o-transform:translateY(40px);transform:translateY(40px)}30%{opacity:1;-webkit-transform:translateY(0px);-moz-transform:translateY(0px);-ms-transform:translateY(0px);-o-transform:translateY(0px);transform:translateY(0px)}}@-moz-keyframes slide-in{0%{opacity:0;-webkit-transform:translateY(40px);-moz-transform:translateY(40px);-ms-transform:translateY(40px);-o-transform:translateY(40px);transform:translateY(40px)}30%{opacity:1;-webkit-transform:translateY(0px);-moz-transform:translateY(0px);-ms-transform:translateY(0px);-o-transform:translateY(0px);transform:translateY(0px)}}@keyframes slide-in{0%{opacity:0;-webkit-transform:translateY(40px);-moz-transform:translateY(40px);-ms-transform:translateY(40px);-o-transform:translateY(40px);transform:translateY(40px)}30%{opacity:1;-webkit-transform:translateY(0px);-moz-transform:translateY(0px);-ms-transform:translateY(0px);-o-transform:translateY(0px);transform:translateY(0px)}}@-webkit-keyframes pulse{0%{-webkit-transform:scale(1);-moz-transform:scale(1);-ms-transform:scale(1);-o-transform:scale(1);transform:scale(1)}10%{-webkit-transform:scale(1.1);-moz-transform:scale(1.1);-ms-transform:scale(1.1);-o-transform:scale(1.1);transform:scale(1.1)}20%{-webkit-transform:scale(1);-moz-transform:scale(1);-ms-transform:scale(1);-o-transform:scale(1);transform:scale(1)}}@-moz-keyframes pulse{0%{-webkit-transform:scale(1);-moz-transform:scale(1);-ms-transform:scale(1);-o-transform:scale(1);transform:scale(1)}10%{-webkit-transform:scale(1.1);-moz-transform:scale(1.1);-ms-transform:scale(1.1);-o-transform:scale(1.1);transform:scale(1.1)}20%{-webkit-transform:scale(1);-moz-transform:scale(1);-ms-transform:scale(1);-o-transform:scale(1);transform:scale(1)}}@keyframes pulse{0%{-webkit-transform:scale(1);-moz-transform:scale(1);-ms-transform:scale(1);-o-transform:scale(1);transform:scale(1)}10%{-webkit-transform:scale(1.1);-moz-transform:scale(1.1);-ms-transform:scale(1.1);-o-transform:scale(1.1);transform:scale(1.1)}20%{-webkit-transform:scale(1);-moz-transform:scale(1);-ms-transform:scale(1);-o-transform:scale(1);transform:scale(1)}}.dropzone,.dropzone *{box-sizing:border-box}.dropzone{min-height:150px;border:2px solid rgba(0,0,0,.3);background:#fff;padding:20px 20px}.dropzone.dz-clickable{cursor:pointer}.dropzone.dz-clickable *{cursor:default}.dropzone.dz-clickable .dz-message,.dropzone.dz-clickable .dz-message *{cursor:pointer}.dropzone.dz-started .dz-message{display:none}.dropzone.dz-drag-hover{border-style:solid}.dropzone.dz-drag-hover .dz-message{opacity:.5}.dropzone .dz-message{text-align:center;margin:2em 0}.dropzone .dz-message .dz-button{background:none;color:inherit;border:none;padding:0;font:inherit;cursor:pointer;outline:inherit}.dropzone .dz-preview{position:relative;display:inline-block;vertical-align:top;margin:16px;min-height:100px}.dropzone .dz-preview:hover{z-index:1000}.dropzone .dz-preview:hover .dz-details{opacity:1}.dropzone .dz-preview.dz-file-preview .dz-image{border-radius:20px;background:#999;background:linear-gradient(to bottom, #eee, #ddd)}.dropzone .dz-preview.dz-file-preview .dz-details{opacity:1}.dropzone .dz-preview.dz-image-preview{background:#fff}.dropzone .dz-preview.dz-image-preview .dz-details{-webkit-transition:opacity 0.2s linear;-moz-transition:opacity 0.2s linear;-ms-transition:opacity 0.2s linear;-o-transition:opacity 0.2s linear;transition:opacity 0.2s linear}.dropzone .dz-preview .dz-remove{font-size:14px;text-align:center;display:block;cursor:pointer;border:none}.dropzone .dz-preview .dz-remove:hover{text-decoration:underline}.dropzone .dz-preview:hover .dz-details{opacity:1}.dropzone .dz-preview .dz-details{z-index:20;position:absolute;top:0;left:0;opacity:0;font-size:13px;min-width:100%;max-width:100%;padding:2em 1em;text-align:center;color:rgba(0,0,0,.9);line-height:150%}.dropzone .dz-preview .dz-details .dz-size{margin-bottom:1em;font-size:16px}.dropzone .dz-preview .dz-details .dz-filename{white-space:nowrap}.dropzone .dz-preview .dz-details .dz-filename:hover span{border:1px solid rgba(200,200,200,.8);background-color:rgba(255,255,255,.8)}.dropzone .dz-preview .dz-details .dz-filename:not(:hover){overflow:hidden;text-overflow:ellipsis}.dropzone .dz-preview .dz-details .dz-filename:not(:hover) span{border:1px solid transparent}.dropzone .dz-preview .dz-details .dz-filename span,.dropzone .dz-preview .dz-details .dz-size span{background-color:rgba(255,255,255,.4);padding:0 .4em;border-radius:3px}.dropzone .dz-preview:hover .dz-image img{-webkit-transform:scale(1.05, 1.05);-moz-transform:scale(1.05, 1.05);-ms-transform:scale(1.05, 1.05);-o-transform:scale(1.05, 1.05);transform:scale(1.05, 1.05);-webkit-filter:blur(8px);filter:blur(8px)}.dropzone .dz-preview .dz-image{border-radius:20px;overflow:hidden;width:120px;height:120px;position:relative;display:block;z-index:10}.dropzone .dz-preview .dz-image img{display:block}.dropzone .dz-preview.dz-success .dz-success-mark{-webkit-animation:passing-through 3s cubic-bezier(0.77, 0, 0.175, 1);-moz-animation:passing-through 3s cubic-bezier(0.77, 0, 0.175, 1);-ms-animation:passing-through 3s cubic-bezier(0.77, 0, 0.175, 1);-o-animation:passing-through 3s cubic-bezier(0.77, 0, 0.175, 1);animation:passing-through 3s cubic-bezier(0.77, 0, 0.175, 1)}.dropzone .dz-preview.dz-error .dz-error-mark{opacity:1;-webkit-animation:slide-in 3s cubic-bezier(0.77, 0, 0.175, 1);-moz-animation:slide-in 3s cubic-bezier(0.77, 0, 0.175, 1);-ms-animation:slide-in 3s cubic-bezier(0.77, 0, 0.175, 1);-o-animation:slide-in 3s cubic-bezier(0.77, 0, 0.175, 1);animation:slide-in 3s cubic-bezier(0.77, 0, 0.175, 1)}.dropzone .dz-preview .dz-success-mark,.dropzone .dz-preview .dz-error-mark{pointer-events:none;opacity:0;z-index:500;position:absolute;display:block;top:50%;left:50%;margin-left:-27px;margin-top:-27px}.dropzone .dz-preview .dz-success-mark svg,.dropzone .dz-preview .dz-error-mark svg{display:block;width:54px;height:54px}.dropzone .dz-preview.dz-processing .dz-progress{opacity:1;-webkit-transition:all 0.2s linear;-moz-transition:all 0.2s linear;-ms-transition:all 0.2s linear;-o-transition:all 0.2s linear;transition:all 0.2s linear}.dropzone .dz-preview.dz-complete .dz-progress{opacity:0;-webkit-transition:opacity 0.4s ease-in;-moz-transition:opacity 0.4s ease-in;-ms-transition:opacity 0.4s ease-in;-o-transition:opacity 0.4s ease-in;transition:opacity 0.4s ease-in}.dropzone .dz-preview:not(.dz-processing) .dz-progress{-webkit-animation:pulse 6s ease infinite;-moz-animation:pulse 6s ease infinite;-ms-animation:pulse 6s ease infinite;-o-animation:pulse 6s ease infinite;animation:pulse 6s ease infinite}.dropzone .dz-preview .dz-progress{opacity:1;z-index:1000;pointer-events:none;position:absolute;height:16px;left:50%;top:50%;margin-top:-8px;width:80px;margin-left:-40px;background:rgba(255,255,255,.9);-webkit-transform:scale(1);border-radius:8px;overflow:hidden}.dropzone .dz-preview .dz-progress .dz-upload{background:#333;background:linear-gradient(to bottom, #666, #444);position:absolute;top:0;left:0;bottom:0;width:0;-webkit-transition:width 300ms ease-in-out;-moz-transition:width 300ms ease-in-out;-ms-transition:width 300ms ease-in-out;-o-transition:width 300ms ease-in-out;transition:width 300ms ease-in-out}.dropzone .dz-preview.dz-error .dz-error-message{display:block}.dropzone .dz-preview.dz-error:hover .dz-error-message{opacity:1;pointer-events:auto}.dropzone .dz-preview .dz-error-message{pointer-events:none;z-index:1000;position:absolute;display:block;display:none;opacity:0;-webkit-transition:opacity 0.3s ease;-moz-transition:opacity 0.3s ease;-ms-transition:opacity 0.3s ease;-o-transition:opacity 0.3s ease;transition:opacity 0.3s ease;border-radius:8px;font-size:13px;top:130px;left:-10px;width:140px;background:#be2626;background:linear-gradient(to bottom, #be2626, #a92222);padding:.5em 1.2em;color:#fff}.dropzone .dz-preview .dz-error-message:after{content:"";position:absolute;top:-6px;left:64px;width:0;height:0;border-left:6px solid transparent;border-right:6px solid transparent;border-bottom:6px solid #be2626} \ No newline at end of file diff --git a/backend/apps/ifc_validation_bff/static/ui/vendor/dropzone/dropzone.min.js b/backend/apps/ifc_validation_bff/static/ui/vendor/dropzone/dropzone.min.js new file mode 100644 index 00000000..94e32e39 --- /dev/null +++ b/backend/apps/ifc_validation_bff/static/ui/vendor/dropzone/dropzone.min.js @@ -0,0 +1 @@ +!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(self,(function(){return function(){var e={3099:function(e){e.exports=function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function");return e}},6077:function(e,t,n){var r=n(111);e.exports=function(e){if(!r(e)&&null!==e)throw TypeError("Can't set "+String(e)+" as a prototype");return e}},1223:function(e,t,n){var r=n(5112),i=n(30),o=n(3070),a=r("unscopables"),u=Array.prototype;null==u[a]&&o.f(u,a,{configurable:!0,value:i(null)}),e.exports=function(e){u[a][e]=!0}},1530:function(e,t,n){"use strict";var r=n(8710).charAt;e.exports=function(e,t,n){return t+(n?r(e,t).length:1)}},5787:function(e){e.exports=function(e,t,n){if(!(e instanceof t))throw TypeError("Incorrect "+(n?n+" ":"")+"invocation");return e}},9670:function(e,t,n){var r=n(111);e.exports=function(e){if(!r(e))throw TypeError(String(e)+" is not an object");return e}},4019:function(e){e.exports="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView},260:function(e,t,n){"use strict";var r,i=n(4019),o=n(9781),a=n(7854),u=n(111),s=n(6656),l=n(648),c=n(8880),f=n(1320),p=n(3070).f,h=n(9518),d=n(7674),v=n(5112),y=n(9711),g=a.Int8Array,m=g&&g.prototype,b=a.Uint8ClampedArray,x=b&&b.prototype,w=g&&h(g),E=m&&h(m),k=Object.prototype,A=k.isPrototypeOf,S=v("toStringTag"),F=y("TYPED_ARRAY_TAG"),T=i&&!!d&&"Opera"!==l(a.opera),C=!1,L={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},R={BigInt64Array:8,BigUint64Array:8},I=function(e){if(!u(e))return!1;var t=l(e);return s(L,t)||s(R,t)};for(r in L)a[r]||(T=!1);if((!T||"function"!=typeof w||w===Function.prototype)&&(w=function(){throw TypeError("Incorrect invocation")},T))for(r in L)a[r]&&d(a[r],w);if((!T||!E||E===k)&&(E=w.prototype,T))for(r in L)a[r]&&d(a[r].prototype,E);if(T&&h(x)!==E&&d(x,E),o&&!s(E,S))for(r in C=!0,p(E,S,{get:function(){return u(this)?this[F]:void 0}}),L)a[r]&&c(a[r],F,r);e.exports={NATIVE_ARRAY_BUFFER_VIEWS:T,TYPED_ARRAY_TAG:C&&F,aTypedArray:function(e){if(I(e))return e;throw TypeError("Target is not a typed array")},aTypedArrayConstructor:function(e){if(d){if(A.call(w,e))return e}else for(var t in L)if(s(L,r)){var n=a[t];if(n&&(e===n||A.call(n,e)))return e}throw TypeError("Target is not a typed array constructor")},exportTypedArrayMethod:function(e,t,n){if(o){if(n)for(var r in L){var i=a[r];i&&s(i.prototype,e)&&delete i.prototype[e]}E[e]&&!n||f(E,e,n?t:T&&m[e]||t)}},exportTypedArrayStaticMethod:function(e,t,n){var r,i;if(o){if(d){if(n)for(r in L)(i=a[r])&&s(i,e)&&delete i[e];if(w[e]&&!n)return;try{return f(w,e,n?t:T&&g[e]||t)}catch(e){}}for(r in L)!(i=a[r])||i[e]&&!n||f(i,e,t)}},isView:function(e){if(!u(e))return!1;var t=l(e);return"DataView"===t||s(L,t)||s(R,t)},isTypedArray:I,TypedArray:w,TypedArrayPrototype:E}},3331:function(e,t,n){"use strict";var r=n(7854),i=n(9781),o=n(4019),a=n(8880),u=n(2248),s=n(7293),l=n(5787),c=n(9958),f=n(7466),p=n(7067),h=n(1179),d=n(9518),v=n(7674),y=n(8006).f,g=n(3070).f,m=n(1285),b=n(8003),x=n(9909),w=x.get,E=x.set,k="ArrayBuffer",A="DataView",S="Wrong index",F=r.ArrayBuffer,T=F,C=r.DataView,L=C&&C.prototype,R=Object.prototype,I=r.RangeError,U=h.pack,O=h.unpack,_=function(e){return[255&e]},M=function(e){return[255&e,e>>8&255]},z=function(e){return[255&e,e>>8&255,e>>16&255,e>>24&255]},P=function(e){return e[3]<<24|e[2]<<16|e[1]<<8|e[0]},j=function(e){return U(e,23,4)},D=function(e){return U(e,52,8)},N=function(e,t){g(e.prototype,t,{get:function(){return w(this)[t]}})},B=function(e,t,n,r){var i=p(n),o=w(e);if(i+t>o.byteLength)throw I(S);var a=w(o.buffer).bytes,u=i+o.byteOffset,s=a.slice(u,u+t);return r?s:s.reverse()},q=function(e,t,n,r,i,o){var a=p(n),u=w(e);if(a+t>u.byteLength)throw I(S);for(var s=w(u.buffer).bytes,l=a+u.byteOffset,c=r(+i),f=0;fG;)(W=Y[G++])in T||a(T,W,F[W]);H.constructor=T}v&&d(L)!==R&&v(L,R);var Q=new C(new T(2)),$=L.setInt8;Q.setInt8(0,2147483648),Q.setInt8(1,2147483649),!Q.getInt8(0)&&Q.getInt8(1)||u(L,{setInt8:function(e,t){$.call(this,e,t<<24>>24)},setUint8:function(e,t){$.call(this,e,t<<24>>24)}},{unsafe:!0})}else T=function(e){l(this,T,k);var t=p(e);E(this,{bytes:m.call(new Array(t),0),byteLength:t}),i||(this.byteLength=t)},C=function(e,t,n){l(this,C,A),l(e,T,A);var r=w(e).byteLength,o=c(t);if(o<0||o>r)throw I("Wrong offset");if(o+(n=void 0===n?r-o:f(n))>r)throw I("Wrong length");E(this,{buffer:e,byteLength:n,byteOffset:o}),i||(this.buffer=e,this.byteLength=n,this.byteOffset=o)},i&&(N(T,"byteLength"),N(C,"buffer"),N(C,"byteLength"),N(C,"byteOffset")),u(C.prototype,{getInt8:function(e){return B(this,1,e)[0]<<24>>24},getUint8:function(e){return B(this,1,e)[0]},getInt16:function(e){var t=B(this,2,e,arguments.length>1?arguments[1]:void 0);return(t[1]<<8|t[0])<<16>>16},getUint16:function(e){var t=B(this,2,e,arguments.length>1?arguments[1]:void 0);return t[1]<<8|t[0]},getInt32:function(e){return P(B(this,4,e,arguments.length>1?arguments[1]:void 0))},getUint32:function(e){return P(B(this,4,e,arguments.length>1?arguments[1]:void 0))>>>0},getFloat32:function(e){return O(B(this,4,e,arguments.length>1?arguments[1]:void 0),23)},getFloat64:function(e){return O(B(this,8,e,arguments.length>1?arguments[1]:void 0),52)},setInt8:function(e,t){q(this,1,e,_,t)},setUint8:function(e,t){q(this,1,e,_,t)},setInt16:function(e,t){q(this,2,e,M,t,arguments.length>2?arguments[2]:void 0)},setUint16:function(e,t){q(this,2,e,M,t,arguments.length>2?arguments[2]:void 0)},setInt32:function(e,t){q(this,4,e,z,t,arguments.length>2?arguments[2]:void 0)},setUint32:function(e,t){q(this,4,e,z,t,arguments.length>2?arguments[2]:void 0)},setFloat32:function(e,t){q(this,4,e,j,t,arguments.length>2?arguments[2]:void 0)},setFloat64:function(e,t){q(this,8,e,D,t,arguments.length>2?arguments[2]:void 0)}});b(T,k),b(C,A),e.exports={ArrayBuffer:T,DataView:C}},1048:function(e,t,n){"use strict";var r=n(7908),i=n(1400),o=n(7466),a=Math.min;e.exports=[].copyWithin||function(e,t){var n=r(this),u=o(n.length),s=i(e,u),l=i(t,u),c=arguments.length>2?arguments[2]:void 0,f=a((void 0===c?u:i(c,u))-l,u-s),p=1;for(l0;)l in n?n[s]=n[l]:delete n[s],s+=p,l+=p;return n}},1285:function(e,t,n){"use strict";var r=n(7908),i=n(1400),o=n(7466);e.exports=function(e){for(var t=r(this),n=o(t.length),a=arguments.length,u=i(a>1?arguments[1]:void 0,n),s=a>2?arguments[2]:void 0,l=void 0===s?n:i(s,n);l>u;)t[u++]=e;return t}},8533:function(e,t,n){"use strict";var r=n(2092).forEach,i=n(9341)("forEach");e.exports=i?[].forEach:function(e){return r(this,e,arguments.length>1?arguments[1]:void 0)}},8457:function(e,t,n){"use strict";var r=n(9974),i=n(7908),o=n(3411),a=n(7659),u=n(7466),s=n(6135),l=n(1246);e.exports=function(e){var t,n,c,f,p,h,d=i(e),v="function"==typeof this?this:Array,y=arguments.length,g=y>1?arguments[1]:void 0,m=void 0!==g,b=l(d),x=0;if(m&&(g=r(g,y>2?arguments[2]:void 0,2)),null==b||v==Array&&a(b))for(n=new v(t=u(d.length));t>x;x++)h=m?g(d[x],x):d[x],s(n,x,h);else for(p=(f=b.call(d)).next,n=new v;!(c=p.call(f)).done;x++)h=m?o(f,g,[c.value,x],!0):c.value,s(n,x,h);return n.length=x,n}},1318:function(e,t,n){var r=n(5656),i=n(7466),o=n(1400),a=function(e){return function(t,n,a){var u,s=r(t),l=i(s.length),c=o(a,l);if(e&&n!=n){for(;l>c;)if((u=s[c++])!=u)return!0}else for(;l>c;c++)if((e||c in s)&&s[c]===n)return e||c||0;return!e&&-1}};e.exports={includes:a(!0),indexOf:a(!1)}},2092:function(e,t,n){var r=n(9974),i=n(8361),o=n(7908),a=n(7466),u=n(5417),s=[].push,l=function(e){var t=1==e,n=2==e,l=3==e,c=4==e,f=6==e,p=7==e,h=5==e||f;return function(d,v,y,g){for(var m,b,x=o(d),w=i(x),E=r(v,y,3),k=a(w.length),A=0,S=g||u,F=t?S(d,k):n||p?S(d,0):void 0;k>A;A++)if((h||A in w)&&(b=E(m=w[A],A,x),e))if(t)F[A]=b;else if(b)switch(e){case 3:return!0;case 5:return m;case 6:return A;case 2:s.call(F,m)}else switch(e){case 4:return!1;case 7:s.call(F,m)}return f?-1:l||c?c:F}};e.exports={forEach:l(0),map:l(1),filter:l(2),some:l(3),every:l(4),find:l(5),findIndex:l(6),filterOut:l(7)}},6583:function(e,t,n){"use strict";var r=n(5656),i=n(9958),o=n(7466),a=n(9341),u=Math.min,s=[].lastIndexOf,l=!!s&&1/[1].lastIndexOf(1,-0)<0,c=a("lastIndexOf"),f=l||!c;e.exports=f?function(e){if(l)return s.apply(this,arguments)||0;var t=r(this),n=o(t.length),a=n-1;for(arguments.length>1&&(a=u(a,i(arguments[1]))),a<0&&(a=n+a);a>=0;a--)if(a in t&&t[a]===e)return a||0;return-1}:s},1194:function(e,t,n){var r=n(7293),i=n(5112),o=n(7392),a=i("species");e.exports=function(e){return o>=51||!r((function(){var t=[];return(t.constructor={})[a]=function(){return{foo:1}},1!==t[e](Boolean).foo}))}},9341:function(e,t,n){"use strict";var r=n(7293);e.exports=function(e,t){var n=[][e];return!!n&&r((function(){n.call(null,t||function(){throw 1},1)}))}},3671:function(e,t,n){var r=n(3099),i=n(7908),o=n(8361),a=n(7466),u=function(e){return function(t,n,u,s){r(n);var l=i(t),c=o(l),f=a(l.length),p=e?f-1:0,h=e?-1:1;if(u<2)for(;;){if(p in c){s=c[p],p+=h;break}if(p+=h,e?p<0:f<=p)throw TypeError("Reduce of empty array with no initial value")}for(;e?p>=0:f>p;p+=h)p in c&&(s=n(s,c[p],p,l));return s}};e.exports={left:u(!1),right:u(!0)}},5417:function(e,t,n){var r=n(111),i=n(3157),o=n(5112)("species");e.exports=function(e,t){var n;return i(e)&&("function"!=typeof(n=e.constructor)||n!==Array&&!i(n.prototype)?r(n)&&null===(n=n[o])&&(n=void 0):n=void 0),new(void 0===n?Array:n)(0===t?0:t)}},3411:function(e,t,n){var r=n(9670),i=n(9212);e.exports=function(e,t,n,o){try{return o?t(r(n)[0],n[1]):t(n)}catch(t){throw i(e),t}}},7072:function(e,t,n){var r=n(5112)("iterator"),i=!1;try{var o=0,a={next:function(){return{done:!!o++}},return:function(){i=!0}};a[r]=function(){return this},Array.from(a,(function(){throw 2}))}catch(e){}e.exports=function(e,t){if(!t&&!i)return!1;var n=!1;try{var o={};o[r]=function(){return{next:function(){return{done:n=!0}}}},e(o)}catch(e){}return n}},4326:function(e){var t={}.toString;e.exports=function(e){return t.call(e).slice(8,-1)}},648:function(e,t,n){var r=n(1694),i=n(4326),o=n(5112)("toStringTag"),a="Arguments"==i(function(){return arguments}());e.exports=r?i:function(e){var t,n,r;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(n=function(e,t){try{return e[t]}catch(e){}}(t=Object(e),o))?n:a?i(t):"Object"==(r=i(t))&&"function"==typeof t.callee?"Arguments":r}},9920:function(e,t,n){var r=n(6656),i=n(3887),o=n(1236),a=n(3070);e.exports=function(e,t){for(var n=i(t),u=a.f,s=o.f,l=0;l=74)&&(r=a.match(/Chrome\/(\d+)/))&&(i=r[1]),e.exports=i&&+i},748:function(e){e.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},2109:function(e,t,n){var r=n(7854),i=n(1236).f,o=n(8880),a=n(1320),u=n(3505),s=n(9920),l=n(4705);e.exports=function(e,t){var n,c,f,p,h,d=e.target,v=e.global,y=e.stat;if(n=v?r:y?r[d]||u(d,{}):(r[d]||{}).prototype)for(c in t){if(p=t[c],f=e.noTargetGet?(h=i(n,c))&&h.value:n[c],!l(v?c:d+(y?".":"#")+c,e.forced)&&void 0!==f){if(typeof p==typeof f)continue;s(p,f)}(e.sham||f&&f.sham)&&o(p,"sham",!0),a(n,c,p,e)}}},7293:function(e){e.exports=function(e){try{return!!e()}catch(e){return!0}}},7007:function(e,t,n){"use strict";n(4916);var r=n(1320),i=n(7293),o=n(5112),a=n(2261),u=n(8880),s=o("species"),l=!i((function(){var e=/./;return e.exec=function(){var e=[];return e.groups={a:"7"},e},"7"!=="".replace(e,"$")})),c="$0"==="a".replace(/./,"$0"),f=o("replace"),p=!!/./[f]&&""===/./[f]("a","$0"),h=!i((function(){var e=/(?:)/,t=e.exec;e.exec=function(){return t.apply(this,arguments)};var n="ab".split(e);return 2!==n.length||"a"!==n[0]||"b"!==n[1]}));e.exports=function(e,t,n,f){var d=o(e),v=!i((function(){var t={};return t[d]=function(){return 7},7!=""[e](t)})),y=v&&!i((function(){var t=!1,n=/a/;return"split"===e&&((n={}).constructor={},n.constructor[s]=function(){return n},n.flags="",n[d]=/./[d]),n.exec=function(){return t=!0,null},n[d](""),!t}));if(!v||!y||"replace"===e&&(!l||!c||p)||"split"===e&&!h){var g=/./[d],m=n(d,""[e],(function(e,t,n,r,i){return t.exec===a?v&&!i?{done:!0,value:g.call(t,n,r)}:{done:!0,value:e.call(n,t,r)}:{done:!1}}),{REPLACE_KEEPS_$0:c,REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE:p}),b=m[0],x=m[1];r(String.prototype,e,b),r(RegExp.prototype,d,2==t?function(e,t){return x.call(e,this,t)}:function(e){return x.call(e,this)})}f&&u(RegExp.prototype[d],"sham",!0)}},9974:function(e,t,n){var r=n(3099);e.exports=function(e,t,n){if(r(e),void 0===t)return e;switch(n){case 0:return function(){return e.call(t)};case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}}},5005:function(e,t,n){var r=n(857),i=n(7854),o=function(e){return"function"==typeof e?e:void 0};e.exports=function(e,t){return arguments.length<2?o(r[e])||o(i[e]):r[e]&&r[e][t]||i[e]&&i[e][t]}},1246:function(e,t,n){var r=n(648),i=n(7497),o=n(5112)("iterator");e.exports=function(e){if(null!=e)return e[o]||e["@@iterator"]||i[r(e)]}},8554:function(e,t,n){var r=n(9670),i=n(1246);e.exports=function(e){var t=i(e);if("function"!=typeof t)throw TypeError(String(e)+" is not iterable");return r(t.call(e))}},647:function(e,t,n){var r=n(7908),i=Math.floor,o="".replace,a=/\$([$&'`]|\d\d?|<[^>]*>)/g,u=/\$([$&'`]|\d\d?)/g;e.exports=function(e,t,n,s,l,c){var f=n+e.length,p=s.length,h=u;return void 0!==l&&(l=r(l),h=a),o.call(c,h,(function(r,o){var a;switch(o.charAt(0)){case"$":return"$";case"&":return e;case"`":return t.slice(0,n);case"'":return t.slice(f);case"<":a=l[o.slice(1,-1)];break;default:var u=+o;if(0===u)return r;if(u>p){var c=i(u/10);return 0===c?r:c<=p?void 0===s[c-1]?o.charAt(1):s[c-1]+o.charAt(1):r}a=s[u-1]}return void 0===a?"":a}))}},7854:function(e,t,n){var r=function(e){return e&&e.Math==Math&&e};e.exports=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof n.g&&n.g)||function(){return this}()||Function("return this")()},6656:function(e){var t={}.hasOwnProperty;e.exports=function(e,n){return t.call(e,n)}},3501:function(e){e.exports={}},490:function(e,t,n){var r=n(5005);e.exports=r("document","documentElement")},4664:function(e,t,n){var r=n(9781),i=n(7293),o=n(317);e.exports=!r&&!i((function(){return 7!=Object.defineProperty(o("div"),"a",{get:function(){return 7}}).a}))},1179:function(e){var t=Math.abs,n=Math.pow,r=Math.floor,i=Math.log,o=Math.LN2;e.exports={pack:function(e,a,u){var s,l,c,f=new Array(u),p=8*u-a-1,h=(1<>1,v=23===a?n(2,-24)-n(2,-77):0,y=e<0||0===e&&1/e<0?1:0,g=0;for((e=t(e))!=e||e===1/0?(l=e!=e?1:0,s=h):(s=r(i(e)/o),e*(c=n(2,-s))<1&&(s--,c*=2),(e+=s+d>=1?v/c:v*n(2,1-d))*c>=2&&(s++,c/=2),s+d>=h?(l=0,s=h):s+d>=1?(l=(e*c-1)*n(2,a),s+=d):(l=e*n(2,d-1)*n(2,a),s=0));a>=8;f[g++]=255&l,l/=256,a-=8);for(s=s<0;f[g++]=255&s,s/=256,p-=8);return f[--g]|=128*y,f},unpack:function(e,t){var r,i=e.length,o=8*i-t-1,a=(1<>1,s=o-7,l=i-1,c=e[l--],f=127&c;for(c>>=7;s>0;f=256*f+e[l],l--,s-=8);for(r=f&(1<<-s)-1,f>>=-s,s+=t;s>0;r=256*r+e[l],l--,s-=8);if(0===f)f=1-u;else{if(f===a)return r?NaN:c?-1/0:1/0;r+=n(2,t),f-=u}return(c?-1:1)*r*n(2,f-t)}}},8361:function(e,t,n){var r=n(7293),i=n(4326),o="".split;e.exports=r((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==i(e)?o.call(e,""):Object(e)}:Object},9587:function(e,t,n){var r=n(111),i=n(7674);e.exports=function(e,t,n){var o,a;return i&&"function"==typeof(o=t.constructor)&&o!==n&&r(a=o.prototype)&&a!==n.prototype&&i(e,a),e}},2788:function(e,t,n){var r=n(5465),i=Function.toString;"function"!=typeof r.inspectSource&&(r.inspectSource=function(e){return i.call(e)}),e.exports=r.inspectSource},9909:function(e,t,n){var r,i,o,a=n(8536),u=n(7854),s=n(111),l=n(8880),c=n(6656),f=n(5465),p=n(6200),h=n(3501),d=u.WeakMap;if(a){var v=f.state||(f.state=new d),y=v.get,g=v.has,m=v.set;r=function(e,t){return t.facade=e,m.call(v,e,t),t},i=function(e){return y.call(v,e)||{}},o=function(e){return g.call(v,e)}}else{var b=p("state");h[b]=!0,r=function(e,t){return t.facade=e,l(e,b,t),t},i=function(e){return c(e,b)?e[b]:{}},o=function(e){return c(e,b)}}e.exports={set:r,get:i,has:o,enforce:function(e){return o(e)?i(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!s(t)||(n=i(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return n}}}},7659:function(e,t,n){var r=n(5112),i=n(7497),o=r("iterator"),a=Array.prototype;e.exports=function(e){return void 0!==e&&(i.Array===e||a[o]===e)}},3157:function(e,t,n){var r=n(4326);e.exports=Array.isArray||function(e){return"Array"==r(e)}},4705:function(e,t,n){var r=n(7293),i=/#|\.prototype\./,o=function(e,t){var n=u[a(e)];return n==l||n!=s&&("function"==typeof t?r(t):!!t)},a=o.normalize=function(e){return String(e).replace(i,".").toLowerCase()},u=o.data={},s=o.NATIVE="N",l=o.POLYFILL="P";e.exports=o},111:function(e){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},1913:function(e){e.exports=!1},7850:function(e,t,n){var r=n(111),i=n(4326),o=n(5112)("match");e.exports=function(e){var t;return r(e)&&(void 0!==(t=e[o])?!!t:"RegExp"==i(e))}},9212:function(e,t,n){var r=n(9670);e.exports=function(e){var t=e.return;if(void 0!==t)return r(t.call(e)).value}},3383:function(e,t,n){"use strict";var r,i,o,a=n(7293),u=n(9518),s=n(8880),l=n(6656),c=n(5112),f=n(1913),p=c("iterator"),h=!1;[].keys&&("next"in(o=[].keys())?(i=u(u(o)))!==Object.prototype&&(r=i):h=!0);var d=null==r||a((function(){var e={};return r[p].call(e)!==e}));d&&(r={}),f&&!d||l(r,p)||s(r,p,(function(){return this})),e.exports={IteratorPrototype:r,BUGGY_SAFARI_ITERATORS:h}},7497:function(e){e.exports={}},133:function(e,t,n){var r=n(7293);e.exports=!!Object.getOwnPropertySymbols&&!r((function(){return!String(Symbol())}))},590:function(e,t,n){var r=n(7293),i=n(5112),o=n(1913),a=i("iterator");e.exports=!r((function(){var e=new URL("b?a=1&b=2&c=3","http://a"),t=e.searchParams,n="";return e.pathname="c%20d",t.forEach((function(e,r){t.delete("b"),n+=r+e})),o&&!e.toJSON||!t.sort||"http://a/c%20d?a=1&c=3"!==e.href||"3"!==t.get("c")||"a=1"!==String(new URLSearchParams("?a=1"))||!t[a]||"a"!==new URL("https://a@b").username||"b"!==new URLSearchParams(new URLSearchParams("a=b")).get("a")||"xn--e1aybc"!==new URL("http://тест").host||"#%D0%B1"!==new URL("http://a#б").hash||"a1c3"!==n||"x"!==new URL("http://x",void 0).host}))},8536:function(e,t,n){var r=n(7854),i=n(2788),o=r.WeakMap;e.exports="function"==typeof o&&/native code/.test(i(o))},1574:function(e,t,n){"use strict";var r=n(9781),i=n(7293),o=n(1956),a=n(5181),u=n(5296),s=n(7908),l=n(8361),c=Object.assign,f=Object.defineProperty;e.exports=!c||i((function(){if(r&&1!==c({b:1},c(f({},"a",{enumerable:!0,get:function(){f(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var e={},t={},n=Symbol(),i="abcdefghijklmnopqrst";return e[n]=7,i.split("").forEach((function(e){t[e]=e})),7!=c({},e)[n]||o(c({},t)).join("")!=i}))?function(e,t){for(var n=s(e),i=arguments.length,c=1,f=a.f,p=u.f;i>c;)for(var h,d=l(arguments[c++]),v=f?o(d).concat(f(d)):o(d),y=v.length,g=0;y>g;)h=v[g++],r&&!p.call(d,h)||(n[h]=d[h]);return n}:c},30:function(e,t,n){var r,i=n(9670),o=n(6048),a=n(748),u=n(3501),s=n(490),l=n(317),c=n(6200)("IE_PROTO"),f=function(){},p=function(e){return" + {# ui.js owns Dropzone initialization, including after HTMX swaps. #} + + + + + + +
+ + Validation Service - Logo + + +
+ +
+ {% if shell.viewer %} + + {% endif %} + +
+ {% block disclaimer %} + {% if shell.active_page == 'dashboard' or shell.active_page == 'report' %} +
+ Let us know what we're getting right and what we can improve at + validate@buildingsmart.org +
+ {% endif %} + {% endblock %} + +
+ {% block content %}{% endblock %} +
+ {% include 'ui/footer.html' %} +
+
+ + + {% if shell.viewer %} +
+
+ + {% endif %} + {% if shell.viewer.needs_affiliation_declaration %} + {% include 'ui/affiliation.html' %} + {% endif %} + + diff --git a/backend/apps/ifc_validation_bff/templates/ui/check.html b/backend/apps/ifc_validation_bff/templates/ui/check.html new file mode 100644 index 00000000..8c96beff --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/check.html @@ -0,0 +1,15 @@ +{% load ui_tags %} + +{% if status == 'v' or status == 'i' or status == 'w' %} + + {% include 'ui/status.html' with icon=status|check_icon %} + +{% else %} + {% include 'ui/status.html' with icon=status|check_icon %} +{% endif %} diff --git a/backend/apps/ifc_validation_bff/templates/ui/dashboard.html b/backend/apps/ifc_validation_bff/templates/ui/dashboard.html new file mode 100644 index 00000000..1b26a198 --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/dashboard.html @@ -0,0 +1,8 @@ +{% extends 'ui/base.html' %} + +{% block content %} +
+ {% include 'ui/upload_workflow.html' %} + {% include 'ui/dashboard_panel.html' %} +
+{% endblock %} diff --git a/backend/apps/ifc_validation_bff/templates/ui/dashboard_panel.html b/backend/apps/ifc_validation_bff/templates/ui/dashboard_panel.html new file mode 100644 index 00000000..950fe7af --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/dashboard_panel.html @@ -0,0 +1,230 @@ +{% load ui_tags %} + +{# Polls yield to user actions so an older response cannot restore stale rows or pagination. #} +
+ {% for error in dashboard.errors %} + + {% endfor %} + +
+ {% csrf_token %} + + + {# Preserve selected requests that are not on the currently visible page. #} + {% for id in dashboard.off_page_selected %} + + {% endfor %} + + + +
+ + + + + + + + + + + + + + + + {% for entry in dashboard.entries %} + + + + + + + + + + + + {% empty %} + + + + {% endfor %} + +
File NameSTEP Syntax ⓘIFC Schema ⓘNormative IFC Rules ⓘIndustry Practices ⓘDateReport
+ + + {{ entry.file_name }} + + {% if entry.header_status == 'i' or entry.header_errors %} + {% material_icon 'Warning' %} + {% else %} + {% material_icon 'Info' %} + {% endif %} + + {% if entry.signatures_status == 'v' or entry.signatures_status == 'i' %} + + {% material_icon 'MailLock' %} + + {% endif %} + {% include 'ui/check.html' with status=entry.syntax_status label='STEP Syntax' report_route='ui:report-syntax' request_id=entry.request_id only %}{% include 'ui/check.html' with status=entry.schema_status label='IFC Schema' report_route='ui:report-schema' request_id=entry.request_id only %}{% include 'ui/check.html' with status=entry.normative_status label='Normative IFC Rules' report_route='ui:report-rules' request_id=entry.request_id only %}{% include 'ui/check.html' with status=entry.industry_status label='Industry Practices' report_route='ui:report-industry' request_id=entry.request_id only %} + {% include 'ui/progress.html' with entry=entry only %} + + {# Individual deletion includes paging and CSRF, but deliberately excludes bulk-selection ids. #} + + ⓘ + + {% if entry.pdf_ready %} + + {% material_icon 'FileDownload' %} + + {% else %} + + {% endif %} +
No IFC files have been uploaded yet.
+
+
+ +
+
+ + +
+ + {{ dashboard.first }}–{{ dashboard.last }} of {{ dashboard.total }} + {% if dashboard.previous_page %} + + {% include 'report/previous_icon.html' %} + + {% else %} + + {% endif %} + + {% if dashboard.next_page %} + + {% include 'report/next_icon.html' %} + + {% else %} + + {% endif %} +
+
diff --git a/backend/apps/ifc_validation_bff/templates/ui/footer.html b/backend/apps/ifc_validation_bff/templates/ui/footer.html new file mode 100644 index 00000000..647b432f --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/footer.html @@ -0,0 +1,11 @@ +
+ buildingSMART Validation Service | Copyright © {% now 'Y' %} buildingSMART All Rights Reserved | + Privacy and Cookie Statement | + Terms and Conditions | + {% if shell.active_page == 'report' %} +
+ This validation report is generated by bSI Validation Service based on the input + IFC model | bSI assumes no responsability or liability for the content of this report +
+ {% endif %} +
diff --git a/backend/apps/ifc_validation_bff/templates/ui/home.html b/backend/apps/ifc_validation_bff/templates/ui/home.html new file mode 100644 index 00000000..a433613c --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/home.html @@ -0,0 +1,94 @@ +{% extends 'ui/base.html' %} +{% load ui_tags %} + +{% block content %} +
+
+

IFC Validation Service

+

+ A free, open platform by buildingSMART for checking IFC file conformity against + STEP syntax, IFC schema, and normative specification rules. +

+ {% if shell.viewer %} + Go to dashboard → + {% else %} + Sign in to start validating → + {% endif %} +
+ +
+ {% if shell.viewer %} + {% include 'ui/upload_workflow.html' %} + View past validations → + {% endif %} + +
+

How it checks

+

Four layers of validation

+
+ {% for layer in landing.layers %} +
+ {% if forloop.counter == 1 %} + {% material_icon 'DataObjectOutlined' %} + {% elif forloop.counter == 2 %} + {% material_icon 'DescriptionOutlined' %} + {% elif forloop.counter == 3 %} + {% material_icon 'CheckOutlined' %} + {% else %} + {% material_icon 'StarOutlineOutlined' %} + {% endif %} +

{{ layer.title }}

+

{{ layer.description }}

+
+ {% endfor %} +
+
+ +
+

How it works

+

Three simple steps

+
    + {% for step in landing.steps %} +
  1. + {{ step.number }} +
    + {{ step.title }} +

    {{ step.description }}

    +
    +
  2. + {% endfor %} +
+
+ +
+

FAQ

+

Common questions

+ {% for faq in landing.faqs %} +
+ + {{ faq.question }} + {% material_icon 'Add' %} + {% material_icon 'Remove' %} + +

{{ faq.answer }}

+
+ {% endfor %} +
+ +
+

Resources

+

Go deeper

+ +
+
+
+{% endblock %} diff --git a/backend/apps/ifc_validation_bff/templates/ui/icon.html b/backend/apps/ifc_validation_bff/templates/ui/icon.html new file mode 100644 index 00000000..0ba5e4b2 --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/icon.html @@ -0,0 +1,11 @@ +{% load static %} + + diff --git a/backend/apps/ifc_validation_bff/templates/ui/logout.html b/backend/apps/ifc_validation_bff/templates/ui/logout.html new file mode 100644 index 00000000..e4d8d05b --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/logout.html @@ -0,0 +1,12 @@ +{% extends 'ui/base.html' %} + +{% block content %} +
+

Logout

+
+ {% csrf_token %} + +
+ Home +
+{% endblock %} diff --git a/backend/apps/ifc_validation_bff/templates/ui/not_found.html b/backend/apps/ifc_validation_bff/templates/ui/not_found.html new file mode 100644 index 00000000..99d2cf8d --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/not_found.html @@ -0,0 +1,11 @@ +{% extends 'ui/base.html' %} +{% load ui_tags %} + +{% block content %} +
+

404

+

Not Found

+

{% material_icon 'SearchOffOutlined' %}

+ {% material_icon 'Home' %}Home +
+{% endblock %} diff --git a/backend/apps/ifc_validation_bff/templates/ui/progress.html b/backend/apps/ifc_validation_bff/templates/ui/progress.html new file mode 100644 index 00000000..9e7a6942 --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/progress.html @@ -0,0 +1,16 @@ +{% load ui_tags tz %} + +{% if entry.status == 'PENDING' %} + in queue +{% elif entry.status == 'FAILED' %} + an error occured +{% elif entry.progress == 100 %} + {% localtime off %} + + {% endlocaltime %} +{% else %} + + + {{ entry.progress|default_if_none:0 }}% + +{% endif %} diff --git a/backend/apps/ifc_validation_bff/templates/ui/scorecards.html b/backend/apps/ifc_validation_bff/templates/ui/scorecards.html new file mode 100644 index 00000000..45f2f0a8 --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/scorecards.html @@ -0,0 +1,53 @@ +{% extends 'ui/base.html' %} +{% load static ui_tags %} + +{% block content %} +
+

Scorecards Service

+ +

What is the Scorecards Service?

+

+ The Scorecards Service is an online platform developed and operated by buildingSMART. + It provides an overview of the extent to which various software applications support + the IFC standard. +

+
+ Screenshot of the buildingSMART Scorecards Service +
Screenshot of the buildingSMART Scorecards Service
+
+ +

How does it work?

+

+ The Scorecards Service analyzes the validation outcomes of IFC files that users check + through the IFC Validation Service. Based on these results, it generates and aggregates + metrics to evaluate each tool used to create the IFC files. The criteria and methodology + used to generate the scorecards are outlined in the Process & Principles section below. +

+ +

Who is this service intended for?

+

+ The Scorecards Service is designed for anyone who wants to understand which parts of + the IFC standard are supported by a specific version of a particular tool. +

+ ! IMPORTANT ! +

+ The scorecards approach is not intended to criticize tools or vendors. + Instead, this free, transparent service aims to help improve the quality of IFC files + and, ultimately, to support vendors in enhancing their implementations of the standard + for the parts they choose to support. +

+ +

Still under construction {% material_icon 'Construction' %}

+

+ The Scorecards Service is currently under development. A prototype was presented to + software vendors at the end of 2024, for their feedback. +

+

+ buildingSMART is working to finalize the service and make it open and available to all in 2025. +

+
+{% endblock %} diff --git a/backend/apps/ifc_validation_bff/templates/ui/status.html b/backend/apps/ifc_validation_bff/templates/ui/status.html new file mode 100644 index 00000000..e3df5f93 --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/status.html @@ -0,0 +1,12 @@ +{% load ui_tags %} + + + {% material_icon icon|cut:'Icon' %} + diff --git a/backend/apps/ifc_validation_bff/templates/ui/upload.html b/backend/apps/ifc_validation_bff/templates/ui/upload.html new file mode 100644 index 00000000..27663f5c --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/upload.html @@ -0,0 +1,36 @@ +{% load ui_tags %} + +
+
+ {% for error in upload.errors %} + + {% endfor %} +
+ +
+ {% csrf_token %} + +
+ {% material_icon 'FileUpload' %} + Click or drop files here to upload for validation +
+ {# Dropzone removes this native input when it initializes; the form still works without JavaScript. #} +
+ +
+
+ + {#Maximum {{ upload.policy.max_size_mb }} MB per file; {{ upload.policy.max_files }} files per upload.#} +
+ + {##} +
+
diff --git a/backend/apps/ifc_validation_bff/templates/ui/upload_page.html b/backend/apps/ifc_validation_bff/templates/ui/upload_page.html new file mode 100644 index 00000000..7decd71c --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/upload_page.html @@ -0,0 +1,6 @@ +{% extends 'ui/base.html' %} + +{% block content %} +

Upload IFC files

+ {% include 'ui/upload.html' %} +{% endblock %} diff --git a/backend/apps/ifc_validation_bff/templates/ui/upload_workflow.html b/backend/apps/ifc_validation_bff/templates/ui/upload_workflow.html new file mode 100644 index 00000000..61bb861b --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/upload_workflow.html @@ -0,0 +1,8 @@ +
+ {% include 'ui/upload.html' %} +
    +
  1. Select the IFC file(s) you want to validate
  2. +
  3. Click on "Upload & Validate"
  4. +
  5. Check the detailed results by clicking on the icons{% if shell.active_page == 'home' %} on the subsequent page{% endif %}
  6. +
+
diff --git a/backend/apps/ifc_validation_bff/templates/ui/waiting_zone.html b/backend/apps/ifc_validation_bff/templates/ui/waiting_zone.html new file mode 100644 index 00000000..13a5d495 --- /dev/null +++ b/backend/apps/ifc_validation_bff/templates/ui/waiting_zone.html @@ -0,0 +1,10 @@ +{% extends 'ui/base.html' %} +{% load ui_tags %} + +{% block content %} +
+

Awaiting User Activation

+

Thank you! We will review your request to activate your account soon.

+ {% material_icon 'Home' %}Home +
+{% endblock %} diff --git a/backend/apps/ifc_validation_bff/templatetags/__init__.py b/backend/apps/ifc_validation_bff/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/apps/ifc_validation_bff/templatetags/report_tags.py b/backend/apps/ifc_validation_bff/templatetags/report_tags.py new file mode 100644 index 00000000..715f8fe5 --- /dev/null +++ b/backend/apps/ifc_validation_bff/templatetags/report_tags.py @@ -0,0 +1,94 @@ +"""HTML presentation only: labels, fixed metadata rows and rule-value markup.""" +import json + +from django import template +from django.template.loader import render_to_string + +from ..datamodel.report import ( + AlignmentMeasurement, AllowedValues, AttributeValue, EntityReference, GuidCharacters, + GuidLength, InstanceReference, SchemaIdentifier, UnrecognizedValue, +) + +register = template.Library() + + +@register.filter +def severity_label(value): + return {0: "N/A", 1: "Applicable", 2: "Passed", 3: "Warning", 4: "Error"}[value] + + +@register.filter +def status_label(value): + return {"v": "Valid", "i": "Invalid", "n": "N/A", "w": "Warning", "p": "Pending...", "-": "N/A"}[value] + + +@register.filter +def pdf_status_label(value): + return {"v": "Valid", "i": "Invalid", "n": "Not validated", "w": "Warning", "p": "Pending", "-": "Not applicable"}[value] + + +@register.filter +def conformance_label(value): + return {'v': 'No issues recorded', 'i': 'Errors found', 'w': 'Warnings recorded', 'n': 'Validation incomplete'}[value] + + +@register.filter +def signature_label(value): + return {'invalid': 'Invalid signature', 'valid_unknown_cert': 'Valid signature · unknown certificate', + 'valid_known_cert': 'Valid signature · known certificate'}.get(value, value.replace('_', ' ').capitalize()) + + +@register.simple_tag +def rule_value(value): + templates = { + AttributeValue: "attribute", AllowedValues: "choices", EntityReference: "entity", + InstanceReference: "instance", SchemaIdentifier: "schema", GuidCharacters: "guid_characters", + GuidLength: "guid_length", AlignmentMeasurement: "measurement", UnrecognizedValue: "unknown", + } + name = templates.get(type(value), "literal") + literal_text = json.dumps(value) if isinstance(value, (bool, int, float)) else None + return render_to_string(f"report/values/{name}.html", {"value": value, "literal_text": literal_text}) + + +@register.filter +def scalar_text(value): + # React does not print boolean children, even inside an AttributeValue. + return "" if isinstance(value, bool) else str(value) + + +@register.inclusion_tag("report/header_row.html", takes_context=True) +def header_row(context, header, field, label, value, tooltip=""): + return dict(label=label, value=value, tooltip=tooltip, invalid=field in header.invalid_fields, + pdf=context.get('pdf', False), + url=f"https://github.com/buildingSMART/IFC4.x-IF/tree/main/docs/IFC-file-header#{field}") + + +@register.inclusion_tag("report/signature_row.html") +def signature_row(label, value): + return {"label": label, "value": value} + + +@register.simple_tag +def rule_export(group): + """Text export uses the same value templates and selected rows as the table.""" + from html import unescape + from django.utils.html import strip_tags + + def text(value): + if isinstance(value, AllowedValues): + return ", ".join(value.values) + return unescape(strip_tags(rule_value(value))).strip() + + columns = ["Severity", "Id", "Entity", "Expected", "Observed"] + if group.show_source: + columns.extend(("Line", "Source")) + rows = [group.title, "", "\t".join(columns)] + for result in group.results: + instance = result.instance + row = [severity_label(result.severity_after_whitelisting), f"#{instance.step_id}" if instance else "-", + instance.entity if instance else "-", text(result.expected), text(result.observed)] + if group.show_source: + source = instance.source if instance else None + row.extend((str(source.line_number) if source else "-", source.statement if source else "-")) + rows.append("\t".join(row)) + return "\n".join(rows) diff --git a/backend/apps/ifc_validation_bff/templatetags/ui_tags.py b/backend/apps/ifc_validation_bff/templatetags/ui_tags.py new file mode 100644 index 00000000..95a8c8ab --- /dev/null +++ b/backend/apps/ifc_validation_bff/templatetags/ui_tags.py @@ -0,0 +1,32 @@ +from django import template +from django.utils import timezone + +register = template.Library() + + +@register.inclusion_tag("ui/icon.html") +def material_icon(name): + return {"name": name} + + +@register.filter +def check_label(status): + return {"v": "Valid", "i": "Invalid", "w": "Warning", "n": "Not validated", "p": "Pending", "-": "N/A"}[status] + + +@register.filter +def check_icon(status): + return {"v": "CheckCircleIcon", "i": "ErrorIcon", "w": "WarningIcon", "p": "HourglassBottomIcon", "n": "BrowserNotSupportedIcon", "-": "BlockIcon"}[status] + + +@register.filter +def dashboard_date(created, now=None): + """Keep the dashboard's single-unit relative dates and eight-day cutoff.""" + seconds = ((now or timezone.now()) - created).total_seconds() + if seconds > 8 * 86400: + return created.strftime("%Y-%m-%d %H:%M:%S") + for divisor, unit in ((7 * 86400, "week"), (86400, "day"), (3600, "hour"), (60, "minute"), (1, "second")): + if seconds > divisor: + amount = int(seconds // divisor) + return f"{amount} {unit}{'' if amount == 1 else 's'} ago" + return "" diff --git a/backend/apps/ifc_validation_bff/tests/report_cases.py b/backend/apps/ifc_validation_bff/tests/report_cases.py new file mode 100644 index 00000000..0ac1b6fa --- /dev/null +++ b/backend/apps/ifc_validation_bff/tests/report_cases.py @@ -0,0 +1,340 @@ +""" +Representative syntax, schema, rule, header and signature reports as model data. + +Shared by the typed report tests and the real Django server used by Playwright +to compare v1 React with the HTMX templates. +""" + +HEADER_PASS = { + "mvd": "Alignment-basedView", + "name": "Header example2.ifc", + "author": ["Evandro Alfieri"], + "organization": ["buildingSMART Int."], + "company_name": "Company", + "application_name": "Application", + "version": "26.0.0.0", + "authorization": "none", + "schema_identifier": "IFC4X3_ADD2", + "originating_system": "Company - Application - 26.0.0.0", + "preprocessor_version": "IFC Motor 1.0", + "validation_errors": [], +} + +IFC101 = { + "feature": "IFC101 - Only official IFC versions allowed", + "feature_version": 1, + "severity": 1, + "outcome_code": "X00040", +} + +SCHEMA_PASSED = dict(type="SCHEMA", status="COMPLETED", status_reason="No IFC schema errors.", + outcomes=[dict(feature='{"type": "schema", "attribute": "SomeAttribute"}', + severity=2, outcome_code="P00010")]) + +SCHEMA_SKIPPED = dict(type="SCHEMA", status="SKIPPED", + status_reason="Skipped due to fail in blocking tasks: SYNTAX", outcomes=[]) + +_SIGNATURE_PAYLOAD = "MIIGZQYJKoZIhvcNAQcCoIIGVjCCBlICAQExDTALBglghkgBZQMEAgEwCwYJKoZIhvcNAQcBoIID3TCCA9kwggHBAhQfhA1Gsyaylmk5LNR9teQdvZMp2zANBgkqhkiG9w0BAQsFADAmMQswCQYDVQQGEwJOTDEXMBUGA1UECgwOQWNtZSBJbmMuIHJvb3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDy4lyACmsdcF1F7COYIOHTDhamVwe0plQUWYXjyK+Hex1MqKFEtpS0GiQjM/RKSoSsgl/FJZYye0IUOJwpQlyhgs95IGb+zJ3/BmnF119x/ILK5iELplIpU9unH14NIyEviOyBKMCLa7aXsZkuxVVOApmJue3m7Ub9nUAbESWgyPHOSz+k2riwZGiHXoOw28Ug3m9UwdAHcsnex23h+RPkHltstTe2nZ244vV4YKWnDxa6XJnXpj2AzU5a5XGthmeIKxiBBYIENbmazbADh4fkCVSBw4KbRKMK+GnUAOvYi23VL8KmXInS8jIEHV/zPejFYsp8Vv3+SZHbVHL1SS1BAgMBAAEwDQYJKoZIhvcNAQELBQADggIBAGYBo6sgi+N1+oGpZDlyqpArY5S58rmiSfp8BFL+M7y2dXhMcBe30lXyBtjGMP0cKtpkThrS3AzZ7nz3cVdPcHLuEBE+lYyjqbnKPgMCOedNjqUFD46e93ycNqGTkdIQcF4ordrooPSsWbUtjQFiyP6lFxcUYDNfUpVXqSP1JlPSAGjcLLCvrPvtGlsfeBspM4ilfyA0W1RNMT82NMHP5nj6MDpGe9aWhQDwfNAkaKobIgenZfV0PuvC22OFCod1H0NMRcOqp/0QG860kFI4RUThrLEQdwVSl/IPytKfzM5qVet/Kow07yCpWZDW0neiXPJe/uvcasMNaC1Z1ovBLIeV7Rd9gRl/yS5lvSPfIYocIM10Fm+ZTatXTWOXO57wHx/7LRvKMZteSPlNAMqUbGRaL5h/NpdxP05Y5lFeMKNsDy6EDMmtCtIjCGLwL+iGbpxfnYd5TYKnLCSjhydz0jN2mIoyhYG/wA5+K8Pzt02wSQTYkr8/jUcjJbfvq+Wou5KGSk6NF1nI1XWAW2u2nslePXcscV73sZdGOH/pAjVl87b6KDLuH6qvWoRkl92pxy/Ui/+0lxWKzK6CLhuPlc1nmJvmKdU60YBX9F9t6Ako98NzT0mU3PtsMjFiarc4P12plWboNjNMn0cYxiHghjmhMZ7R0aEDbX69BG/Y9iukMYICTjCCAkoCAQEwPjAmMQswCQYDVQQGEwJOTDEXMBUGA1UECgwOQWNtZSBJbmMuIHJvb3QCFB+EDUazJrKWaTks1H215B29kynbMAsGCWCGSAFlAwQCAaCB5DAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcB" + +SIGNATURE_CERT = { + "issuer": "C=NL,O=Acme Inc. root", + "subject": "C=NL,O=Acme Inc. end-entity", + "signature_hash_algorithm_name": "sha256", + "rsa_key_size": 2048, + "not_valid_after": "2035-05-06 12:01:07+00:00", + "not_valid_before": "2025-05-08 12:01:07+00:00", + "fingerprint_hex": "3D:D2:DE:16:D8:8C:B6:C3:97:31:72:C0:55:5D:C6:74:A8:B2:B7:55:66:1E:BE:1A:A1:6C:5D:3E:7C:45:44:9F:A1", + "payload": _SIGNATURE_PAYLOAD, + "signature": "valid_known_cert", +} + +def gherkin(feature: str, *, severity: int, version: int = 1, instance: str | None = None, + expected=None, observed=None, outcome_code: str = "E00020") -> dict: + return dict(feature=feature, feature_version=version, severity=severity, outcome_code=outcome_code, + expected=expected, observed=observed, instance=instance) + + +CASES: list[dict] = [ + + # ---------------------------------------------------------------- Case 1 + dict(name="case01-syntax-step", kind="syntax", public_id="r119954039", + file_name="fail_double_semi.ifc", size=1172, + model=dict( + schema="IFC4", mvd="CoordinationView", + status_syntax="i", status_header_syntax="v", status_header="i", status_prereq="v", + header_validation={ + "mvd": "CoordinationView", "name": "", "schema_identifier": "IFC4", + "originating_system": "IfcOpenShell-0.7.0", "preprocessor_version": "IfcOpenShell-0.7.0", + "validation_errors": ["originating_system", "company_name", "application_name", "description"], + }, + ), + instances=[], + tasks=[ + dict(type="HEADER_SYNTAX", status="COMPLETED", status_reason="No IFC syntax error(s).", + outcomes=[dict(severity=2, outcome_code="P00010")]), + dict(type="SYNTAX", status="COMPLETED", + status_reason="Found IFC syntax errors:\nOn line 27 column 66: Unexpected semicolon (';') ...", + outcomes=[dict(severity=4, outcome_code="E00001", observed=( + "On line 27 column 66:\n" + "Unexpected semicolon (';')\n" + "Expecting ENDSEC\n" + "00027 | #20=IFCPROJECT('2AyG2X0sb16Bjd4gQc07yZ',#5,'',$,$,$,$,(#11),#19);;\n" + " ^" + ))]), + dict(type="PREREQ", status="COMPLETED", status_reason="agg_status = Valid", + outcomes=[IFC101]), + SCHEMA_SKIPPED, + ]), + + # ---------------------------------------------------------------- Case 2 + dict(name="case02-syntax-duplicate-name", kind="syntax", public_id="r503400730", + file_name="fail-duplicate-name.ifc", size=396, + model=dict( + schema="IFC4X3_ADD2", mvd="Alignment-basedView", + status_syntax="i", status_header_syntax="v", status_header="v", status_prereq="v", + header_validation=dict(HEADER_PASS, name="Header example2.ifc"), + ), + instances=[], + tasks=[ + dict(type="HEADER_SYNTAX", status="COMPLETED", status_reason="No IFC syntax error(s).", + outcomes=[dict(severity=2, outcome_code="P00010")]), + dict(type="SYNTAX", status="COMPLETED", + status_reason="Found IFC syntax errors:\nOn line 9: Duplicate instance name #1 ...", + outcomes=[dict(severity=4, outcome_code="E00001", observed=( + "On line 9:\n" + "Duplicate instance name #1\n" + "00009 | #1=IFCPERSON($,$,'',$,$,$,$,$);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" + ))]), + dict(type="PREREQ", status="COMPLETED", status_reason="agg_status = Valid", outcomes=[IFC101]), + SCHEMA_SKIPPED, + ]), + + # ---------------------------------------------------------------- Case 3 + dict(name="case03-schema-ifc101", kind="schema", public_id="r886847421", + file_name="fail-ifc101-IFC4X3.ifc", size=1306, + model=dict( + schema="IFC4X3", mvd="ReferenceView", + status_syntax="v", status_header="v", status_header_syntax="v", status_prereq="i", + header_validation={ + "mvd": "ReferenceView", "name": "fail-ifc101-IFC4X3.ifc", + "company_name": "IfcOpenShell contributors", "application_name": "IfcOpenShell", + "version": "v0.7.0+6c9e130ca", "schema_identifier": "IFC4X3", + "originating_system": "IfcOpenShell contributors - IfcOpenShell - v0.7.0+6c9e130ca", + "preprocessor_version": "", "validation_errors": ["description"], + }, + ), + instances=[], + tasks=[ + dict(type="PREREQ", status="COMPLETED", status_reason="agg_status = Invalid", + outcomes=[gherkin("IFC101 - Only official IFC versions allowed", severity=4, + expected={"oneOf": ["IFC2X3", "IFC4", "IFC4X3_ADD2"]}, + observed={"schema_identifier": "IFC4X3"})]), + dict(type="SCHEMA", status="SKIPPED", + status_reason="Skipped due to fail in blocking tasks: PREREQ", outcomes=[]), + ]), + + # ---------------------------------------------------------------- Case 4 + dict(name="case04-schema-attribute", kind="schema", public_id="r104761022", + file_name="fail-selected-simple-type-as-literal.ifc", size=340, + model=dict( + schema="IFC2X3", mvd="DesignTransferView", + status_syntax="v", status_header_syntax="v", status_header="v", status_prereq="v", + header_validation={ + "mvd": "DesignTransferView", "name": "qset.ifc", "authorization": "Nobody", + "schema_identifier": "IFC2X3", "originating_system": "Bonsai 0.8.1-alpha241113-d3333fe", + "preprocessor_version": "IfcOpenShell 0.0.0", + "validation_errors": ["originating_system", "company_name", "application_name", "description"], + }, + ), + instances=[dict(stepfile_id=1, ifc_type="IfcPropertySingleValue")], + tasks=[ + dict(type="SCHEMA", status="COMPLETED", status_reason="No IFC schema errors.", + outcomes=[dict(feature='{"type": "schema", "attribute": "NominalValue"}', + severity=4, outcome_code="E00002", instance=1, observed=( + "With attribute:\n" + " > | … | >)> " + "| > " + "| > | > | > " + "| > | > | >)>)>>\n" + "Value:\n" + " 0.2\n" + "Not valid\n" + ))]), + ]), + + # ---------------------------------------------------------------- Case 5 + dict(name="case05-schema-rule", kind="schema", public_id="r653740803", + file_name="fail-axis2-anti-parallel-axes.ifc", size=420, + model=dict( + schema="IFC2X3", mvd="CoordinationView", + status_syntax="v", status_header_syntax="v", status_header="i", status_prereq="v", + header_validation={ + "mvd": "CoordinationView", "name": "", "schema_identifier": "IFC2X3", + "originating_system": "IfcOpenShell", "preprocessor_version": "IfcOpenShell", + "validation_errors": ["originating_system", "company_name", "application_name", "description"], + }, + ), + instances=[dict(stepfile_id=4, ifc_type="IfcAxis2Placement3D")], + tasks=[ + dict(type="SCHEMA", status="COMPLETED", status_reason="No IFC schema errors.", + outcomes=[dict(feature='{"type": "entity_rule", "attribute": "IfcAxis2Placement3D.WR4"}', + severity=4, outcome_code="E00002", instance=4, observed=( + "(not exists(axis) or not exists(refdirection) or IfcCrossProduct(axis, refdirection).Magnitude > 0.0)\n" + "\nViolated by:\n" + " ((not True or not True or 0.0 > 0.0))\n" + " + where True = exists(#2=IfcDirection((0.,0.,1.)))\n" + " + and True = exists(#3=IfcDirection((0.,0.,-1.)))\n" + " + and 0.0 = #0=IfcVector(#2,0.).Magnitude\n" + " + where #0=IfcVector(#2,0.) = IfcCrossProduct(#2=IfcDirection((0.,0.,1.)), #3=IfcDirection((0.,0.,-1.)))\n" + "\nOn instance:\n" + " #4=IfcAxis2Placement3D(#1,#2,#3)\n" + ))]), + dict(type="PREREQ", status="COMPLETED", status_reason="agg_status = Valid", outcomes=[IFC101]), + ]), + + # ---------------------------------------------------------------- Case 6 + dict(name="case06-normative", kind="normative", public_id="r721314331", + file_name="fail-blt001-scenario02-door_type_own_operation_type.ifc", size=1510, + model=dict( + schema="IFC4X3_ADD2", mvd="ReferenceView", + status_syntax="v", status_header_syntax="v", status_header="v", status_prereq="v", + header_validation={ + "mvd": "ReferenceView", "name": "fail-blt001-scenario02-door_type_own_operation_type.ifc", + "company_name": "IfcOpenShell contributors", "application_name": "IfcOpenShell", + "version": "v0.7.0+fa6bbf2d", "schema_identifier": "IFC4X3_ADD2", + "originating_system": "IfcOpenShell contributors - IfcOpenShell - v0.7.0+fa6bbf2d", + "preprocessor_version": "", "validation_errors": [], + }, + ), + instances=[dict(stepfile_id=22, ifc_type="IfcDoor"), dict(stepfile_id=21, ifc_type="IfcDoorType")], + tasks=[ + dict(type="NORMATIVE_IA", status="COMPLETED", status_reason="agg_status = Invalid", outcomes=[ + gherkin("BLT001 - Correct use of operation type attributes for doors", severity=4, instance=22, + expected={"schema_identifier": "empty"}, + observed={"schema_identifier": "SLIDING_TO_RIGHT"}), + gherkin("SPS005 - Simultaneous spatial relationships", severity=4, version=2, instance=22, + expected="^Exactly^ 1 of the following relationships must be non-empty: 'Nests', 'Decomposes', " + "'ContainedInStructure', 'AdheresToElement', 'VoidsElements'", + observed={"value": 0}), + gherkin("SPS007 - Spatial Containment", severity=4, version=6, instance=22, + expected="a *required* relationship .IfcRelContainedInSpatialStructure. to .IfcElement. " + "from .IfcSpatialStructureElement."), + ]), + ]), + + # ---------------------------------------------------------------- Case 7 + dict(name="case07-industry", kind="industry", public_id="r420634185", + file_name="fail-blt003-scenario01-IfcStair-aggregating-IfcBeam.ifc", size=1453, + model=dict( + schema="IFC4X3_ADD2", mvd="ReferenceView", + status_syntax="v", status_header_syntax="v", status_header="v", status_prereq="v", + header_validation=dict(HEADER_PASS, name="fail-blt003-scenario01-IfcStair-aggregating-IfcBeam.ifc"), + ), + instances=[dict(stepfile_id=21, ifc_type="IfcStair"), + dict(stepfile_id=11, ifc_type="IfcGeometricRepresentationContext")], + tasks=[ + dict(type="INDUSTRY", status="COMPLETED", status_reason="agg_status = Warning", outcomes=[ + gherkin("BLT003 - Stair decomposition", severity=3, version=2, instance=21, + expected={"oneOf": ["IfcRailing", "IfcSlab", "IfcStairFlight"], + "context": "to be the whole that is decomposed by"}, + observed={"instance": "IfcBeam(#22)"}), + gherkin("GEM052 - Correct geometric subcontexts", severity=3, version=2, instance=11, + expected={"schema_identifier": "not empty"}, + observed={"schema_identifier": "empty"}), + ]), + ]), + + # ---------------------------------------------------------------- Case 8 + dict(name="case08-signatures-pass", kind="file", public_id="r804080876", + file_name="pass_multiple_signatures.ifc", size=4971, + model=dict( + schema="IFC4", mvd="ReferenceView_V1.2", + status_syntax="v", status_header_syntax="v", status_header="v", status_prereq="v", + header_validation={ + "mvd": "ReferenceView_V1.2", "name": "na_no_signature.ifc", "author": ["jdoe"], + "organization": ["Acme Inc."], "company_name": "Acme Inc.", "application_name": "MyFabTool", + "version": "2025.1", "authorization": "IFC4 model", "schema_identifier": "IFC4", + "preprocessor_version": "ABC rel. 0.1.2", + "originating_system": "Acme Inc. - MyFabTool - 2025.1", "validation_errors": [], + }, + ), + instances=[], + tasks=[ + dict(type="DIGITAL_SIGNATURES", status="COMPLETED", status_reason="Digital signature check completed", + outcomes=[ + dict(severity=2, outcome_code="P00010", observed=dict(SIGNATURE_CERT, start="383", end="2592")), + dict(severity=2, outcome_code="P00010", observed=dict(SIGNATURE_CERT, start="2592", end="4801")), + ]), + ]), + + # ---------------------------------------------------------------- Case 9 + dict(name="case09-signatures-fail", kind="file", public_id="r187527567", + file_name="fail_invalid_signature.ifc", size=2686, + model=dict( + schema="IFC4", mvd="ReferenceView_V1.2", + status_syntax="v", status_header_syntax="v", status_header="v", status_prereq="v", + header_validation={ + "mvd": "ReferenceView_V1.2", "name": "na_no_signature.ifc", "author": ["jdoe"], + "organization": ["Acme Inc."], "company_name": "Acme Inc.", "application_name": "MyFabTool", + "version": "2025.1", "authorization": "IFC4 model", "schema_identifier": "IFC4", + "preprocessor_version": "ABC rel. 0.1.2", + "originating_system": "Acme Inc. - MyFabTool - 2025.1", "validation_errors": [], + }, + ), + instances=[], + tasks=[ + dict(type="DIGITAL_SIGNATURES", status="COMPLETED", status_reason="Digital signature check completed", + outcomes=[dict(severity=4, outcome_code="E00020", observed={ + "signature": "invalid", "start": "383", "end": "2592", "payload": _SIGNATURE_PAYLOAD, + })]), + ]), + + # ---------------------------------------------------------------- Case 10 + dict(name="case10-header-pass", kind="file", public_id="r570974258", + file_name="passing_header.ifc", size=1342, + model=dict( + schema="IFC4X3_ADD2", mvd="Alignment-basedView", + status_syntax="v", status_header_syntax="v", status_header="v", status_prereq="v", + header_validation=dict(HEADER_PASS), + ), + instances=[], + tasks=[ + dict(type="HEADER", status="COMPLETED", status_reason="agg_status = Valid", outcomes=[]), + ]), + + # ---------------------------------------------------------------- Case 11 + dict(name="case11-header-fail", kind="file", public_id="r954420949", + file_name="blank_company_name.ifc", size=1337, + model=dict( + schema="IFC4X3_ADD2", mvd="Alignment-basedView", + status_syntax="v", status_header_syntax="v", status_header="i", status_prereq="v", + header_validation=dict(HEADER_PASS, company_name=" ", + originating_system=" - Application - 26.0.0.0", + validation_errors=["company_name"]), + ), + instances=[], + tasks=[ + dict(type="HEADER", status="COMPLETED", status_reason="agg_status = Invalid", outcomes=[]), + ]), + + # ---------------------------------------------------------------- Case 12 + dict(name="case12-many-errors", kind="schema", public_id="r337867640", + file_name="fail-many-errors.ifc", size=976, + model=dict( + schema="IFC4X3_ADD2", mvd="Alignment-basedView", + status_syntax="v", status_header_syntax="v", status_header="v", status_prereq="v", + header_validation=dict(HEADER_PASS, name="Header example2.ifc"), + ), + instances=[dict(stepfile_id=i, ifc_type="IfcPerson") for i in range(1, 20)], + tasks=[ + dict(type="SCHEMA", status="COMPLETED", status_reason="No IFC schema errors.", + outcomes=[dict(feature='{"type": "schema", "attribute": "GivenName"}', severity=4, + outcome_code="E00002", instance=i, + observed="With attribute:\n >>\n" + f"Value:\n {i}\nNot valid\n") + for i in range(1, 20)]), + dict(type="PREREQ", status="COMPLETED", status_reason="agg_status = Valid", outcomes=[IFC101]), + ]), +] diff --git a/backend/apps/ifc_validation_bff/tests/report_factory.py b/backend/apps/ifc_validation_bff/tests/report_factory.py new file mode 100644 index 00000000..432551ef --- /dev/null +++ b/backend/apps/ifc_validation_bff/tests/report_factory.py @@ -0,0 +1,21 @@ +"""Persist representative validation reports for backend and browser tests.""" +from apps.ifc_validation_models.models import Model, ModelInstance, ValidationOutcome, ValidationRequest, ValidationTask + + +def create_case(case, user): + model = Model.objects.create(file_name=case["file_name"], file=case["file_name"], size=case["size"], + uploaded_by=user, **case["model"]) + request = ValidationRequest.objects.create(file_name=case["file_name"], file=case["file_name"], size=case["size"], + model=model, status="COMPLETED", progress=100) + instances = {spec["stepfile_id"]: ModelInstance.objects.create(model=model, **spec) for spec in case["instances"]} + for task in case["tasks"]: + validation_task = ValidationTask.objects.create(request=request, type=task["type"], status=task.get("status", "COMPLETED"), + progress=100, status_reason=task.get("status_reason", "")) + for outcome in task.get("outcomes", []): + ValidationOutcome.objects.create( + validation_task=validation_task, instance=instances.get(outcome.get("instance")), + severity_in_db=outcome["severity"], outcome_code=outcome.get("outcome_code", "E00020"), + feature=outcome.get("feature"), feature_version=outcome.get("feature_version"), + expected=outcome.get("expected"), observed=outcome.get("observed"), + ) + return request diff --git a/backend/apps/ifc_validation_bff/tests/report_parity_settings.py b/backend/apps/ifc_validation_bff/tests/report_parity_settings.py new file mode 100644 index 00000000..5f51ba56 --- /dev/null +++ b/backend/apps/ifc_validation_bff/tests/report_parity_settings.py @@ -0,0 +1,15 @@ +"""Isolated browser-test settings; never connect the parity suite to a user's DB.""" +import os +from .test_settings import * # noqa: F403 + +DEBUG = True +FRONTEND_MODE = os.environ.get("FRONTEND_MODE", "react") +ALLOWED_HOSTS = ["localhost", "127.0.0.1"] +INSTALLED_APPS = [*INSTALLED_APPS, "django.contrib.staticfiles"] # noqa: F405 +ROOT_URLCONF = "apps.ifc_validation_bff.tests.report_parity_urls" +DATABASES = {"default": { + "ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:", + "OPTIONS": {"transaction_mode": "IMMEDIATE"}, +}} +MEDIA_ROOT = os.environ["REPORT_PARITY_MEDIA"] +MIDDLEWARE = [*MIDDLEWARE, "django.middleware.csrf.CsrfViewMiddleware"] # noqa: F405 diff --git a/backend/apps/ifc_validation_bff/tests/report_parity_urls.py b/backend/apps/ifc_validation_bff/tests/report_parity_urls.py new file mode 100644 index 00000000..6c56fbb2 --- /dev/null +++ b/backend/apps/ifc_validation_bff/tests/report_parity_urls.py @@ -0,0 +1,5 @@ +from django.urls import include, path +from django.conf import settings + +urlpatterns = [path("bff/", include("apps.ifc_validation_bff.urls")), + path("" if settings.FRONTEND_MODE == "htmx" else "v2/", include("apps.ifc_validation_bff.ui.urls"))] diff --git a/backend/apps/ifc_validation_bff/tests/serve_report_parity.py b/backend/apps/ifc_validation_bff/tests/serve_report_parity.py new file mode 100644 index 00000000..f67f5fe5 --- /dev/null +++ b/backend/apps/ifc_validation_bff/tests/serve_report_parity.py @@ -0,0 +1,138 @@ +"""Serve deterministic real Django reports to Playwright, using a temporary SQLite DB. + +Run from backend: python -m apps.ifc_validation_bff.tests.serve_report_parity +No validator, Celery worker, development database or API token is used. +""" +import argparse +import json +import os +import tempfile +from pathlib import Path + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--port", type=int, default=8765) + parser.add_argument("--manifest", default="../e2e/test-results/report-parity.json") + args = parser.parse_args() + with tempfile.TemporaryDirectory(prefix="ifc-report-parity-") as directory: + os.environ["REPORT_PARITY_MEDIA"] = directory + os.environ["DJANGO_SETTINGS_MODULE"] = "apps.ifc_validation_bff.tests.report_parity_settings" + import django + from django.conf import settings + # Configure the owned database before app initialization opens connections. + settings.DATABASES["default"]["NAME"] = str(Path(directory, "reports.sqlite3")) + django.setup() + from django.core.management import call_command + from django.contrib.auth.models import Group, User + from django.contrib.sessions.backends.db import SessionStore + from apps.ifc_validation_models.models import UserAdditionalInfo, ValidationTask, WhiteListEntry, WhiteListQueryFragment, set_user_context + from .report_factory import create_case + from .report_cases import CASES + from unittest.mock import patch + from apps.ifc_validation_bff import views_legacy + views_legacy.DEVELOPMENT = views_legacy.PREVIEW = False # anonymous browser tests must not auto-login + + call_command("migrate", run_syncdb=True, verbosity=0, interactive=False) + # Browser polling reads while uploads write. WAL keeps those reads from + # blocking commits in this SQLite-only fixture server. + from django.db import connection + with connection.cursor() as cursor: + cursor.execute("PRAGMA journal_mode=WAL") + users = [User.objects.create(username=f"{name}@test.org", email=f"{name}@test.org", first_name=name, + last_name="Tester", is_active=True) for name in ("reader", "source-reader")] + source_group = Group.objects.create(name="step-line-viewers") + users[1].groups.add(source_group) + cookies = [] + for user in users: + set_user_context(user) + UserAdditionalInfo.objects.create(user=user, is_vendor_self_declared=False) + session = SessionStore() + session["user"] = {"email": user.email} + session.save() + cookies.append({"name": settings.SESSION_COOKIE_NAME, "value": session.session_key, + "domain": "localhost", "path": "/"}) + + set_user_context(users[0]) + reports = [] + for case in CASES: + request = create_case(case, users[0]) + if case["kind"] == "schema": + for task_type in ("SCHEMA", "PREREQ"): + ValidationTask.objects.get_or_create(request=request, type=task_type, defaults={"status": "SKIPPED"}) + # Both selected normative task types exist in actual pipeline requests. + if case["kind"] == "normative": + for task_type in ("NORMATIVE_IA", "NORMATIVE_IP"): + ValidationTask.objects.get_or_create(request=request, type=task_type, defaults={"status": "SKIPPED"}) + declarations = [f"#{i['stepfile_id']}={i['ifc_type'].upper()}($);" for i in case["instances"]] + Path(directory, case["file_name"]).write_text("/* report parity source */\n" + "\n".join(declarations)) + reports.append({"name": case["name"], "kind": case["kind"], "id": request.public_id, + "file_name": case["file_name"]}) + + # A separate request exercises actual pagination without expanding individual rules. + from copy import deepcopy + pagination_case = deepcopy(CASES[5]) + pagination_case["tasks"][0]["outcomes"] = [dict(feature=f"ZZZ{i:03} - Rule", severity=4, + expected="expected", observed={"value": i}) for i in range(23)] + pagination = create_case(pagination_case, users[0]) + ValidationTask.objects.create(request=pagination, type="NORMATIVE_IP", status="SKIPPED") + + def rule_report(values): + case = deepcopy(CASES[5]) + case["tasks"][0]["outcomes"] = [dict(feature=feature, severity=4, instance=22, expected=expected, + observed=observed) for feature, expected, observed in values] + request = create_case(case, users[0]) + ValidationTask.objects.create(request=request, type="NORMATIVE_IP", status="SKIPPED") + return {"kind": "normative", "id": request.public_id} + + allowlisted = rule_report([("ALW001 - Known exception", {"value": 0}, {"value": False})]) + entry = WhiteListEntry.objects.create(description="Browser parity known exception") + WhiteListQueryFragment.objects.create(whitelist_entry=entry, column="feature", operation="EQUALS", + right_hand_side="ALW001 - Known exception") + rich_values = rule_report([ + ("VAL001 - Entity", {"entity": "IfcBeam(#22)"}, 1), + ("VAL002 - GUID characters", {"invalid_guid_chars": "0-9", "expected_or_observed": "expected"}, + {"invalid_guid_chars": ["!", "?"], "expected_or_observed": "observed", "inst": "bad!?"}), + ("VAL003 - GUID length", {"length": 22, "expected_or_observed": "expected"}, + {"length": 3, "expected_or_observed": "observed", "inst": "bad"}), + ("VAL004 - Measurement", {"num_digits": 4, "context": "direction", "expected": 0.0001}, + {"num_digits": 4, "context": "position", "observed": [1, 2]}), + ("VAL005 - Unknown shapes", {"unknown": "shape"}, [1, "two"]), + ]) + + # A real stored PDF exercises dashboard readiness and authenticated download. + from apps.ifc_validation_bff.report.pdf import generate_pdf + from apps.ifc_validation_models.models import ValidationRequest + generate_pdf(ValidationRequest.to_private_id(rich_values['id'])) + + from apps.ifc_validation_models.models import ValidationRequest + for name, status, progress in (("dashboard-pending.ifc", "PENDING", 0), ("dashboard-running.ifc", "INITIATED", 35)): + ValidationRequest.objects.create(file_name=name, file=name, size=10, status=status, progress=progress) + + account_cookies = {} + for name, active, affiliation in (("declaration", True, None), ("inactive", False, False)): + user = User.objects.create(username=f"{name}@test.org", email=f"{name}@test.org", first_name=name, + last_name="Tester", is_active=active) + set_user_context(user) + UserAdditionalInfo.objects.create(user=user, is_vendor_self_declared=affiliation) + session = SessionStore() + session["user"] = {"email": user.email} + session.save() + account_cookies[name] = {"name": settings.SESSION_COOKIE_NAME, "value": session.session_key, + "domain": "localhost", "path": "/"} + + # Source reader must have the same access as the owner without an ownership bypass. + # Staff access is already a supported report policy; source access still needs its group. + users[1].is_staff = True + users[1].save() + manifest = Path(args.manifest) + manifest.parent.mkdir(parents=True, exist_ok=True) + manifest.write_text(json.dumps({"reports": reports, "cookies": cookies, "pagination": pagination.public_id, + "allowlisted": allowlisted, "rich_values": rich_values, "accounts": account_cookies})) + print(f"Report parity fixtures ready at http://localhost:{args.port}/bff/", flush=True) + with patch("apps.ifc_validation_bff.ui.actions.enqueue_validation"): + call_command("runserver", f"0.0.0.0:{args.port}", use_reloader=False, verbosity=0) + + +if __name__ == "__main__": + main() diff --git a/backend/apps/ifc_validation_bff/tests/test_settings.py b/backend/apps/ifc_validation_bff/tests/test_settings.py index 958098d4..4773a612 100644 --- a/backend/apps/ifc_validation_bff/tests/test_settings.py +++ b/backend/apps/ifc_validation_bff/tests/test_settings.py @@ -17,7 +17,7 @@ "django.middleware.common.CommonMiddleware", ] -ROOT_URLCONF = "apps.ifc_validation_bff.urls" +ROOT_URLCONF = "apps.ifc_validation_bff.tests.urls" DB_SQLITE = "sqlite" @@ -34,3 +34,11 @@ MEDIA_ROOT = "./apps/ifc_validation/fixtures" USE_TZ = True SECRET_KEY = "insecure-test-only-secret-key" + +STATIC_URL = "/static/" +MAX_OUTCOMES_PER_RULE = 10 +TEMPLATES = [{ + "BACKEND": "django.template.backends.django.DjangoTemplates", + "APP_DIRS": True, + "OPTIONS": {"context_processors": ["django.template.context_processors.request"]}, +}] diff --git a/backend/apps/ifc_validation_bff/tests/tests_model_summary.py b/backend/apps/ifc_validation_bff/tests/tests_model_summary.py new file mode 100644 index 00000000..411fb982 --- /dev/null +++ b/backend/apps/ifc_validation_bff/tests/tests_model_summary.py @@ -0,0 +1,103 @@ +from unittest.mock import patch + +from django.contrib.auth.models import User +from django.test import TestCase + +from apps.ifc_validation_models.models import ValidationRequest, set_user_context +from apps.ifc_validation_bff.datamodel.load import load_dashboard, load_model_summary, load_report +from apps.ifc_validation_bff.datamodel.model_summary import ModelSummary +from apps.ifc_validation_bff.datamodel.ui import DashboardOptions +from apps.ifc_validation_bff.report.pdf import load_full_report +from apps.ifc_validation_bff.views_legacy import format_request +from .report_cases import CASES +from .report_factory import create_case + + +class ModelSummaryTests(TestCase): + @classmethod + def setUpTestData(cls): + cls.user = User.objects.create(username="summary@test.org", email="summary@test.org") + set_user_context(cls.user) + cls.requests = [create_case(case, cls.user) for case in CASES] + + def assert_legacy_statuses(self, request, summary): + legacy = format_request(request) + for field, key in ( + ("header_status", "status_header"), + ("signatures_status", "status_signatures"), + ("security_status", "status_magic_clamav"), + ("syntax_status", "status_syntax"), + ("schema_status", "status_schema"), + ("normative_status", "status_rules"), + ("industry_status", "status_ind"), + ): + with self.subTest(field=field): + self.assertEqual(getattr(summary, field), legacy[key]) + + def test_fixture_metadata_and_statuses_preserve_existing_behavior(self): + for request in self.requests: + for state in ("PENDING", "INITIATED", "FAILED", "COMPLETED"): + with self.subTest(request=request.file_name, state=state): + request.status = state + summary = load_model_summary(request) + self.assertIsInstance(summary, ModelSummary) + self.assertEqual(summary.request_id, request.public_id) + self.assertEqual(summary.created, request.created) + self.assertEqual(summary.file_name, request.file_name) + self.assertEqual(summary.size_bytes, request.size) + self.assertEqual(summary.progress, request.progress) + self.assertEqual(summary.header, request.model.header_validation or {}) + self.assert_legacy_statuses(request, summary) + + def test_request_without_model_stays_pending(self): + set_user_context(self.user) + request = ValidationRequest.objects.create(file_name="pending.ifc", file="pending.ifc", size=1, progress=0) + summary = load_model_summary(request) + self.assertEqual(summary.header, {}) + self.assertEqual(summary.schema_status, "p") + self.assertEqual(summary.normative_status, "p") + self.assertEqual(summary.syntax_status, "p") + self.assert_legacy_statuses(request, summary) + + def test_progress_100_does_not_hide_unfinished_checks(self): + request = self.requests[0] + request.status, request.progress = "INITIATED", 100 + request.model.status_prereq = "v" + request.model.status_syntax = "v" + request.model.status_header_syntax = "n" + request.model._latest_task_status_by_type = {"SCHEMA": "n", "NORMATIVE_IA": "n", "NORMATIVE_IP": "v"} + summary = load_model_summary(request) + self.assertEqual(summary.schema_status, "p") + self.assertEqual(summary.normative_status, "p") + self.assertEqual(summary.syntax_status, "n") + self.assert_legacy_statuses(request, summary) + + request.status = "COMPLETED" + completed = load_model_summary(request) + self.assertEqual(completed.schema_status, "n") + self.assertEqual(completed.normative_status, "n") + self.assertEqual(completed.syntax_status, "v") + + def test_sibling_errors_and_warnings_remain_visible(self): + request = self.requests[0] + request.status = "INITIATED" + request.model.status_prereq = "i" + request.model._latest_task_status_by_type = {"SCHEMA": "n", "NORMATIVE_IA": "n", "NORMATIVE_IP": "w"} + summary = load_model_summary(request) + self.assertEqual(summary.schema_status, "i") + self.assertEqual(summary.normative_status, "w") + self.assert_legacy_statuses(request, summary) + + def test_v2_consumers_do_not_call_legacy_projection(self): + request = self.requests[5] + with patch("apps.ifc_validation_bff.views_legacy.format_request", side_effect=AssertionError("v1 projection called")): + summary = load_model_summary(request) + report = load_report(request, "normative") + dashboard = load_dashboard(self.user, DashboardOptions()) + document = load_full_report(request) + self.assertEqual(report.status, summary.normative_status) + self.assertTrue(dashboard.entries) + self.assertEqual(document.signature_status, summary.signatures_status) + with self.assertNumQueries(0): + self.assertEqual(summary.file_name, request.file_name) + self.assertIsInstance(summary.header, dict) diff --git a/backend/apps/ifc_validation_bff/tests/tests_report_html.py b/backend/apps/ifc_validation_bff/tests/tests_report_html.py new file mode 100644 index 00000000..61fbfef6 --- /dev/null +++ b/backend/apps/ifc_validation_bff/tests/tests_report_html.py @@ -0,0 +1,264 @@ +import tempfile +from copy import deepcopy +from dataclasses import replace +from pathlib import Path +from unittest.mock import patch + +from django.conf import settings +from django.contrib.auth.models import Group, User +from django.test import TestCase, override_settings +from django.template.loader import render_to_string +from django.db import connection +from django.test.utils import CaptureQueriesContext + +from apps.ifc_validation_models.models import ValidationOutcome, ValidationRequest, ValidationTask, WhiteListEntry, WhiteListQueryFragment, set_user_context +from apps.ifc_validation_bff.report.build import build_report +from apps.ifc_validation_bff.datamodel.report import OutcomeSeverity, ReportOptions, GherkinResult, HeaderFinding, SourceLocation +from apps.ifc_validation_bff.datamodel.load import load_report +from apps.ifc_validation_bff.report.value_formatting import interpret_rule_value +from .report_factory import create_case +from .report_cases import CASES + + +class ReportHTMLTests(TestCase): + @classmethod + def setUpTestData(cls): + cls.alice = User.objects.create(username="alice@test.org", email="alice@test.org", is_active=True) + cls.bob = User.objects.create(username="bob@test.org", email="bob@test.org", is_active=True) + cls.staff = User.objects.create(username="staff@test.org", email="staff@test.org", is_staff=True) + set_user_context(cls.alice) + cls.requests = [create_case(case, cls.alice) for case in CASES] + + def login_as(self, user): + session = self.client.session + session["user"] = {"email": user.email} + session.save() + self.client.cookies[settings.SESSION_COOKIE_NAME] = session.session_key + + def get_report(self, index=0, query="", **headers): + request = self.requests[index] + segment = 'rules' if CASES[index]['kind'] == 'normative' else CASES[index]['kind'] + return self.client.get(f"/v2/report_{segment}/{request.public_id}?{query.lstrip('&')}", **headers) + + def test_all_mapping_cases_render_as_html(self): + self.login_as(self.alice) + for index, case in enumerate(CASES): + with self.subTest(case=case["name"]): + response = self.get_report(index, "&include_all=1") + self.assertEqual(response.status_code, 200) + self.assertContains(response, case["file_name"]) + self.assertContains(response, 'data-testid="report-content"') + + def test_projection_and_rendering_do_no_database_work(self): + inputs = load_report(self.requests[5], "normative", self.alice) + with self.assertNumQueries(0): + data, pagination = inputs.outcomes_grouped().outcome_groups_paginated("normative", ReportOptions(include_all=True)) + report = build_report(data, "normative") + page = pagination.with_report(report) + html = render_to_string("report/page.html", {"report": page.report, "page": page}) + self.assertIn("SLIDING_TO_RIGHT", html) + self.assertIsInstance(report.section.items[0].results[0], GherkinResult) + + def test_metadata_header_and_signatures_have_named_fields(self): + report = build_report(load_report(self.requests[7], "file", self.alice), "file") + self.assertEqual(report.metadata.file_name, CASES[7]["file_name"]) + self.assertEqual(report.signatures[0].rsa_key_size, 2048) + self.assertEqual(len(report.signatures[0].payload), 64) + report = build_report(load_report(self.requests[10], "file", self.alice), "file") + self.assertEqual(report.header.company_name, "□") + self.assertIn("company_name", report.header.invalid_fields) + + def test_header_policy_groups_expected_and_observed_per_field(self): + from apps.ifc_validation_bff.report.pdf import load_full_report + model = self.requests[10].model + model.header_validation = dict(model.header_validation, validation_details=[ + {"field": "originating_system", "expected": "Company - Application - Version", "observed": " - App - 26"}, + {"field": "description", "expected": "Exactly one base MVD", "observed": "ReferenceView, DesignTransferView"}, + {"field": "description", "expected": "An MVD valid for IFC4X3_ADD2", "observed": "DesignTransferView"}, + {"field": "author", "expected": "A value of type LIST", "observed": None}]) + model.save() + groups = build_report(load_report(self.requests[10], "file", self.alice), "file").header_policy + self.assertEqual([(g.label, len(g.findings)) for g in groups], [("MVD(s)", 2), ("Originating System", 1), ("Author", 1)]) + self.assertEqual(groups[1].findings[0].observed, "□□- App - 26") + self.login_as(self.alice) + response = self.get_report(10) + self.assertContains(response, "(occurred 2 times)", count=1) + self.assertContains(response, "Exactly one base MVD", html=True) + self.assertContains(response, "missing", html=True) + document = load_full_report(self.requests[10]) + self.assertIn("

Header Policy

", render_to_string("report/page.html", {"pdf": True, "document": document, "report": document.file})) + self.assertNotContains(self.get_report(9), 'id="header-policy"') # no findings + + def test_header_policy_falls_back_to_field_names_of_older_reports(self): + groups = build_report(load_report(self.requests[10], "file", self.alice), "file").header_policy + self.assertEqual([(g.label, g.findings) for g in groups], [("Company Name", (HeaderFinding(None, "□"),))]) + self.login_as(self.alice) + self.assertContains(self.get_report(10), "See header policy") + + def test_report_loads_the_first_outcomes_per_rule_and_severity_but_counts_all(self): + case = deepcopy(CASES[5]) + case["tasks"] = [dict(type="NORMATIVE_IA", outcomes=[ + dict(feature="CAP001 - Many", severity=4 if i < 25 else 2, expected="e", observed=f"o{i}") for i in range(28)])] + data = load_report(create_case(case, self.alice), "normative", self.alice) + self.assertEqual([o.observed for o in data.outcomes], [f"o{i}" for i in (*range(10), 25, 26, 27)]) + group = build_report(data, "normative").section.items[0] + self.assertEqual((len(group.results), group.occurrence_count), (10, 28)) + + def test_original_and_effective_severity_are_explicit(self): + set_user_context(self.alice) + entry = WhiteListEntry.objects.create(description="Test known schema exception") + WhiteListQueryFragment.objects.create(whitelist_entry=entry, column="instance__ifc_type", + operation="EQUALS", right_hand_side="IfcPropertySingleValue") + data = load_report(self.requests[3], "schema", self.alice) + result = build_report(data, "schema").section.items[0].results[0] + self.assertEqual(result.severity_in_db, OutcomeSeverity.ERROR) + self.assertEqual(result.severity_after_whitelisting, OutcomeSeverity.PASSED) + self.assertTrue(result.allowlisted) + selected, pagination = data.outcomes_grouped().outcome_groups_paginated("schema", ReportOptions()) + self.assertFalse(build_report(selected, "schema", include_all=False).section.items) + selected, pagination = data.outcomes_grouped().outcome_groups_paginated("schema", ReportOptions(include_all=True)) + report = build_report(selected, "schema") + page = pagination.with_report(report) + html = render_to_string("report/section.html", {"report": page.report, "page": page}) + self.assertIn("ⓘ Allowlisted", html) + self.assertIn('data-severity-in-db="4"', html) + self.assertIn('data-severity-after-whitelisting="2"', html) + + def test_filter_fragment_and_ten_result_limit(self): + self.login_as(self.alice) + response = self.get_report(11, HTTP_HX_REQUEST="true") + self.assertNotContains(response, "alert("file").ifc' + request.save() + response = self.get_report() + self.assertNotContains(response, '") + WhiteListQueryFragment.objects.create(whitelist_entry=entry, column="instance__ifc_type", operation="EQUALS", right_hand_side="IfcWall") + response = self.client.get("/v2/allowlist") + pattern = next(item for item in response.context["allowlist"].entries if item.id == entry.id).patterns[0] + self.assertEqual(pattern.field, "type") + self.assertEqual(pattern.value, "IfcWall") + self.assertContains(response, "<script>") + self.assertNotContains(response, "