Skip to content

Commit

Permalink
Make import button and progress radial reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche authored and eric-intuitem committed Feb 13, 2024
1 parent 73d1921 commit 8575395
Showing 1 changed file with 35 additions and 55 deletions.
90 changes: 35 additions & 55 deletions frontend/src/routes/(app)/libraries/[id=urn]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
<script lang="ts">
import { enhance } from '$app/forms';
import ModelTable from '$lib/components/ModelTable/ModelTable.svelte';
import type { Library } from '$lib/utils/types.js';
import RiskMatrix from '$lib/components/RiskMatrix/RiskMatrix.svelte';
import Dropdown from '$lib/components/Dropdown/Dropdown.svelte';
import TreeViewItemContent from '../../frameworks/[id=uuid]/TreeViewItemContent.svelte';
export let data;
let loading = false;
const library: Library = data.library;
const showRisks = true;
interface LibraryObjects {
[key: string]: any;
}
const libraryObjects: LibraryObjects = library.objects ?? [];
const libraryObjects: LibraryObjects = data.library.objects ?? [];
const riskMatrices = libraryObjects['risk_matrix'] ?? [];
const securityFunctions = libraryObjects['security_functions'] ?? [];
const threats = libraryObjects['threats'] ?? [];
Expand All @@ -28,15 +25,16 @@
id: id,
content: TreeViewItemContent,
contentProps: node,
// lead: TreeViewItemLead,
children: node.children ? transformToTreeView(Object.entries(node.children)) : []
};
});
}
let treeViewNodes: TreeViewNode[] = transformToTreeView(Object.entries(tree));
import { tableSourceMapper, type TableSource, type TreeViewNode } from '@skeletonlabs/skeleton';
import { ProgressRadial, tableSourceMapper, type TreeViewNode } from '@skeletonlabs/skeleton';
import RecursiveTreeView from '$lib/components/TreeView/RecursiveTreeView.svelte';
import type { TableSource } from '$lib/components/ModelTable/types';
import { enhance } from '$app/forms';
const riskMatricesTable: TableSource = {
head: ['Name', 'Description'],
Expand Down Expand Up @@ -64,72 +62,54 @@
}
return riskMatricesDumps;
}
$: displayImportButton = data.library.id === undefined;
</script>

<div class="card bg-white p-4 shadow space-y-4">
<div class="flex flex-row justify-between w-full">
<div class="flex flex-col space-y-2">
<h1 class="font-medium text-xl">{library.name}</h1>
<div class="space-y-1">
<p class="text-md leading-5 text-gray-700">Description: {library.description}</p>
<p class="text-md leading-5 text-gray-700">Provider: {library.provider}</p>
<p class="text-md leading-5 text-gray-700">Packager: {library.packager}</p>
{#if library.dependencies}
<p class="text-md leading-5 text-gray-700">
Dependendies:
{#each library.dependencies as dependency}
<li>
<a href="/libraries/{dependency}" target="_parent" class="anchor">{dependency}</a>
</li>
{/each}
</p>
{/if}
{#if library.copyright}
<p class="text-sm leading-5 text-gray-500">Copyright: {library.copyright}</p>
{/if}
</div>
</div>
{#if !library.id}
<div class="flex">
{#if loading}
<div class="flex items-center mr-4 cursor-progress" role="status">
<svg
aria-hidden="true"
class="w-5 h-5 text-gray-200 animate-spin dark:text-gray-600 fill-primary-500"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
</div>
{:else}
<span class="text-gray-500 hover:text-primary-500">
<div class="flex flex-col space-y-2">
<span class="w-full flex flex-row justify-between">
<h1 class="font-medium text-xl">{data.library.name}</h1>
<div>
{#if displayImportButton}
{#if loading}
<ProgressRadial width="w-6" meter="stroke-primary-500" />
{:else}
<form
method="post"
use:enhance={() => {
loading = true;
return async ({ update }) => {
loading = false;
update();
};
}}
>
<button type="submit" class="btn text-xl">
<button type="submit" class="p-1 btn text-xl hover:text-primary-500">
<i class="fa-solid fa-file-import" />
</button>
</form>
</span>
{/if}
{/if}
</div>
{/if}
</span>
<div class="space-y-1">
<p class="text-md leading-5 text-gray-700">Description: {data.library.description}</p>
<p class="text-md leading-5 text-gray-700">Provider: {data.library.provider}</p>
<p class="text-md leading-5 text-gray-700">Packager: {data.library.packager}</p>
{#if data.library.dependencies}
<p class="text-md leading-5 text-gray-700">
Dependendies:
{#each data.library.dependencies as dependency}
<li>
<a href="/libraries/{dependency}" target="_parent" class="anchor">{dependency}</a>
</li>
{/each}
</p>
{/if}
{#if data.library.copyright}
<p class="text-sm leading-5 text-gray-500">Copyright: {data.library.copyright}</p>
{/if}
</div>
</div>

{#if riskMatrices.length > 0}
Expand Down

0 comments on commit 8575395

Please sign in to comment.