Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed Sep 13, 2024
2 parents 75af533 + 50911c6 commit b350c0e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 96 deletions.
2 changes: 1 addition & 1 deletion frontend/src/lib/components/ModelTable/ModelTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
export let identifierField = 'id';
export let deleteForm: SuperValidated<AnyZodObject> | undefined = undefined;
export let URLModel: urlModel | undefined = undefined;
export let detailQueryParameter: string | undefined;
export let detailQueryParameter: string | undefined = undefined;
detailQueryParameter = detailQueryParameter ? `?${detailQueryParameter}` : '';
export let hideFilters = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import { goto } from '$app/navigation';
import * as m from '$paraglide/messages.js';
import { breadcrumbObject } from '$lib/utils/stores';
import { safeTranslate } from '$lib/utils/i18n.js';
import { toCamelCase } from '$lib/utils/locales.js';
import type { TableSource } from '$lib/components/ModelTable/types';
import ModelTable from '$lib/components/ModelTable/ModelTable.svelte';
export let data;
Expand All @@ -20,19 +21,30 @@
return map[status] ?? 'bg-gray-200';
};
const measureStatusColorMap = (treatment: string) => {
const map: Record<string, string> = {
undefined: 'bg-gray-200',
to_do: 'bg-blue-200',
deprecated: 'bg-red-200',
active: 'bg-green-200'
const APPLIED_CONTROL_FIELDS = [
'name',
'description',
'category',
'csf_function',
'reference_control',
'eta',
'effort',
'cost',
'link',
'status'
];
function makeSourceFromAppliedControls(appliedControls): TableSource {
const fields = APPLIED_CONTROL_FIELDS;
const head = Object.fromEntries(fields.map((field) => [field, toCamelCase(field)]));
return {
head: head,
body: appliedControls.map((appliedControl) =>
Object.fromEntries(fields.map((field) => [field, appliedControl[field]]))
),
meta: appliedControls
};
if (treatment !== null) {
return map[treatment.toLowerCase()];
} else {
return 'bg-gray-200';
}
};
}
</script>

<div class="bg-white p-2 m-2 shadow rounded-lg space-x-2 flex flex-row justify-center">
Expand All @@ -56,86 +68,40 @@

<p class="p-2 m-2 text-lg font-semibold">{m.associatedRiskScenarios()}:</p>

<div class="bg-white p-2 m-2 shadow overflow-hidden rounded-lg flex">
<table class="w-full p-2 mt-2">
<thead />
<tbody>
{#each data.risk_assessment.risk_scenarios as scenario}
<tr class="bg-gray-100">
<td class="text-lg p-3" colspan="9">
<a
class="unstyled text-primary-500 hover:text-primary-700"
href="/risk-scenarios/{scenario.id}">{scenario.name}</a
>
<span class="badge {scenarioTreatmentColorMap(scenario.treatment)}"
>{safeTranslate(scenario.treatment)}</span
>
</td>
</tr>
{#if scenario.existing_controls}
<tr>
<td class="text-md pl-6 pb-3 font-medium" colspan="9"> {m.existingControls()}: </td>
</tr>
<tr>
<td class="text-sm pl-6 pb-3" colspan="9"> {scenario.existing_controls} </td>
</tr>
{/if}

{#if scenario.applied_controls.length > 0}
<tr>
<td class="text-md pl-6 pb-3 font-medium" colspan="9"> {m.additionalMeasures()}: </td>
</tr>
<tr class="text-sm uppercase">
<td class="px-2 text-center">#</td>
<td class="px-2 font-semibold">{m.name()}</td>
<td class="px-2 font-semibold">{m.description()}</td>
<td class="px-2 font-semibold">{m.category()}</td>
<td class="px-2 font-semibold">{m.csfFunction()}</td>
<td class="px-2 font-semibold">{m.referenceControl()}</td>
<td class="px-2 font-semibold">{m.eta()}</td>
<td class="px-2 font-semibold">{m.effort()}</td>
<td class="px-2 font-semibold">{m.cost()}</td>
<td class="px-2 font-semibold text-center">{m.link()}</td>
<td class="px-2 font-semibold text-center">{m.status()}</td>
</tr>
{#each scenario.applied_controls as measure, index}
<tr
class="hover:text-primary-500 border-b cursor-pointer hover:scale-[0.99] duration-200"
on:click={(_) => goto(`/applied-controls/${measure.id}`)}
>
<td class="px-2 py-3 text-center pl-4">M.{index + 1}</td>
<td class="px-2 py-3">{measure.name ?? '--'}</td>
<td class="px-2 py-3 max-w-md">{measure.description ?? '--'}</td>
<td class="px-2 py-3">{measure.category ?? '--'}</td>
<td class="px-2 py-3">{measure.csf_function ?? '--'}</td>
<td class="px-2 py-3"
>{measure.reference_control ? measure.reference_control.str : '--'}</td
>
<td class="px-2 py-3">{measure.eta ?? '--'}</td>
<td class="px-2 py-3">{measure.effort ?? '--'}</td>
<td class="px-2 py-3">{measure.cost ?? '--'}</td>
<td class="px-2 py-3 text-center">{measure.link ?? '--'} </td>
<td class="text-center"
><span
class="text-xs text-gray-900 whitespace-nowrap text-center p-1 mx-1 rounded {measureStatusColorMap(
measure.status
)}"
>{safeTranslate(toCamelCase(measure.status))}
</span></td
>
</tr>
{/each}
{/if}

{#if !scenario.existing_controls && !(scenario.applied_controls.length > 0)}
<tr>
<td colspan="9" class="p-2 text-left">
<i class="fas fa-exclamation-circle" />
{m.noAppliedControlYet()}
</td>
</tr>
{/if}
{/each}
</tbody>
</table>
<div class="bg-white p-2 m-2 shadow overflow-hidden rounded-lg flex flex-col">
{#each data.risk_assessment.risk_scenarios as scenario}
<tr class="bg-gray-100">
<td class="text-lg p-3" colspan="9">
<a
class="unstyled text-primary-500 hover:text-primary-700"
href="/risk-scenarios/{scenario.id}">{scenario.name}</a
>
<span class="badge {scenarioTreatmentColorMap(scenario.treatment)}"
>{safeTranslate(scenario.treatment)}</span
>
</td>
</tr>
{#if scenario.existing_controls}
<tr>
<td class="text-md pl-6 pb-3 font-medium" colspan="9"> {m.existingControls()}: </td>
</tr>
<tr>
<td class="text-sm pl-6 pb-3" colspan="9"> {scenario.existing_controls} </td>
</tr>
{/if}
{#if scenario.applied_controls.length > 0}
<ModelTable
source={makeSourceFromAppliedControls(scenario.applied_controls)}
URLModel="applied-controls"
/>
{/if}
{#if !scenario.existing_controls && !(scenario.applied_controls.length > 0)}
<tr>
<td colspan="9" class="p-2 text-left">
<i class="fas fa-exclamation-circle" />
{m.noAppliedControlYet()}
</td>
</tr>
{/if}
{/each}
</div>

0 comments on commit b350c0e

Please sign in to comment.