|
4 | 4 | import { error, success } from "$src/modules/utils/toast.svelte"; |
5 | 5 | import * as Tooltip from "$src/lib/components/ui/tooltip"; |
6 | 6 | import type { AuditReport, AuditReportData } from "$src/types/report"; |
7 | | - import type { DocumentState, IdsDocument } from "$src/types/ids"; |
| 7 | + import type { DocumentState, IdsDocument, Specification } from "$src/types/ids"; |
8 | 8 |
|
9 | 9 | let activeDocument = $derived( |
10 | 10 | IDS.Module.activeDocument ? (IDS.Module.documents[IDS.Module.activeDocument] as IdsDocument) : null |
|
19 | 19 | let expandedRequirements = $state(new Set<string>()); |
20 | 20 | let allExpanded = $state(false); |
21 | 21 |
|
| 22 | + type SpecificationStatus = boolean | 'skipped' | null; |
| 23 | +
|
22 | 24 | // Open Editor mode and jump to a specific specification |
23 | 25 | function editSpecification(index: number) { |
24 | 26 | if (IDS.Module.activeDocument) { |
|
55 | 57 | } |
56 | 58 | } |
57 | 59 |
|
58 | | - function getSpecificationStatus(specIndex: number, auditData: AuditReportData) { |
| 60 | + function getSpecificationStatus(specIndex: number, auditData: AuditReportData): SpecificationStatus { |
59 | 61 | const spec = auditData.specifications[specIndex]; |
60 | 62 | if (!spec) return null; |
61 | 63 | return spec.is_skipped ? 'skipped' : spec.status; |
|
98 | 100 | return null; // No reason needed for passed specifications |
99 | 101 | } |
100 | 102 |
|
| 103 | + function getDocumentSpecificationUsage(spec: Specification) { |
| 104 | + return IDS.getSpecUsage(spec); |
| 105 | + } |
| 106 | +
|
101 | 107 | async function handleDownloadReport() { |
102 | 108 | if (!auditReport) return; |
103 | 109 | |
|
223 | 229 | </button> |
224 | 230 | </div> |
225 | 231 | {#each activeDocument.specifications.specification as spec, index} |
| 232 | + {@const usage = getDocumentSpecificationUsage(spec)} |
226 | 233 | <div class="specification-card {auditReport ? 'with-audit' : ''} {auditReport && getSpecificationStatus(index, auditReport.data) !== null ? (getSpecificationStatus(index, auditReport.data) === 'skipped' ? 'spec-skipped' : (getSpecificationStatus(index, auditReport.data) ? 'spec-pass' : 'spec-fail')) : ''}"> |
227 | 234 | <div |
228 | 235 | class="spec-card-header" |
|
260 | 267 | <p class="spec-description">{spec["@description"]}</p> |
261 | 268 | {/if} |
262 | 269 | <div class="spec-stats"> |
263 | | - {#if spec.applicability["@minOccurs"] === 1 && spec.applicability["@maxOccurs"] === 'unbounded'} |
| 270 | + {#if usage === 'required'} |
264 | 271 | <span class="stat-item">Required</span> |
265 | 272 | {/if} |
266 | | - {#if spec.applicability["@minOccurs"] === 0 && spec.applicability["@maxOccurs"] === 'unbounded'} |
| 273 | + {#if usage === 'optional'} |
267 | 274 | <span class="stat-item">Optional</span> |
268 | 275 | {/if} |
269 | | - {#if spec.applicability["@minOccurs"] === 0 && spec.applicability["@maxOccurs"] === 0} |
| 276 | + {#if usage === 'prohibited'} |
270 | 277 | <span class="stat-item">Prohibited</span> |
271 | 278 | {/if} |
272 | 279 | {#if auditReport} |
273 | 280 | {@const stats = getSpecificationStats(index, auditReport.data)} |
274 | 281 | {@const status = getSpecificationStatus(index, auditReport.data)} |
275 | | - {#if stats && spec.applicability["@maxOccurs"] !== 0 && status !== 'skipped'} |
| 282 | + {#if stats && usage !== 'prohibited' && status !== 'skipped'} |
276 | 283 | <span class="stat-item">Checks: {stats.checksPassed}/{stats.checksTotal}</span> |
277 | 284 | <span class="stat-item">Requirements: {stats.requirementsPassed}/{stats.requirements}</span> |
278 | 285 | {/if} |
|
325 | 332 |
|
326 | 333 | {#if auditReport} |
327 | 334 | {@const status = getSpecificationStatus(index, auditReport.data)} |
328 | | - {#if ! status && spec.applicability["@maxOccurs"] == 0} |
| 335 | + {#if status === false && usage === 'prohibited'} |
329 | 336 | {@const specReport = auditReport.data.specifications[index]} |
| 337 | + {@const applicableEntities = specReport.applicable_entities ?? []} |
330 | 338 | <div class="entity-tables"> |
331 | | - {#if specReport.applicable_entities && specReport.applicable_entities.length > 0} |
| 339 | + {#if applicableEntities.length > 0} |
332 | 340 | <div class="entity-table-section fail"> |
333 | | - <h4>Failed Elements ({specReport.applicable_entities.length})</h4> |
| 341 | + <h4>Failed Elements ({applicableEntities.length})</h4> |
334 | 342 | <div class="entity-table-container"> |
335 | 343 | <Tooltip.Provider> |
336 | 344 | <table class="entity-table"> |
|
346 | 354 | </tr> |
347 | 355 | </thead> |
348 | 356 | <tbody> |
349 | | - {#each specReport.applicable_entities.slice(0, 10) as entity} |
| 357 | + {#each applicableEntities.slice(0, 10) as entity} |
350 | 358 | <tr> |
351 | 359 | <td>{entity.class}</td> |
352 | 360 | <td>{entity.predefined_type || '-'}</td> |
|
402 | 410 | </td> |
403 | 411 | </tr> |
404 | 412 | {/each} |
405 | | - {#if specReport.applicable_entities.length > 10} |
| 413 | + {#if applicableEntities.length > 10} |
406 | 414 | <tr class="more-row"> |
407 | | - <td colspan="7">... {specReport.applicable_entities.length - 10} more failing elements not shown ...</td> |
| 415 | + <td colspan="7">... {applicableEntities.length - 10} more failing elements not shown ...</td> |
408 | 416 | </tr> |
409 | 417 | {/if} |
410 | 418 | </tbody> |
|
0 commit comments