Add the ability to get badges for packages

This commit is contained in:
Elara 2023-05-16 12:42:36 -07:00
parent b5672f2e05
commit 8c023ab05c
1 changed files with 155 additions and 108 deletions

View File

@ -1,123 +1,170 @@
<script> <script>
import { page } from '$app/stores'; import { page } from '$app/stores';
import { client } from 'twirpscript'; import { client } from 'twirpscript';
import { GetPkg } from '$lib/lure.pb'; import { GetPkg } from '$lib/lure.pb';
import { LURE_WEB_API_URL } from '$env/static/public'; import { LURE_WEB_API_URL } from '$env/static/public';
import { DoubleBounce } from 'svelte-loading-spinners'; import { DoubleBounce } from 'svelte-loading-spinners';
import Header from "../../../header.svelte"; import Header from '../../../header.svelte';
import Footer from "../../../footer.svelte"; import Footer from '../../../footer.svelte';
import Icon from '@iconify/svelte'; import Icon from '@iconify/svelte';
import { onMount } from 'svelte';
client.baseURL = LURE_WEB_API_URL client.baseURL = LURE_WEB_API_URL;
client.prefix = "" client.prefix = '';
function fullVer(pkg) { let currentURL = ``;
let ver = `${pkg.version}-${pkg.release}`; onMount(() => (currentURL = window.location.href));
if (pkg.epoch != 0) {
ver = `${pkg.epoch}:${ver}`
}
return ver
}
function objToMap(o) { function fullVer(pkg) {
return new Map(Object.entries(o)) let ver = `${pkg.version}-${pkg.release}`;
} if (pkg.epoch != 0) {
ver = `${pkg.epoch}:${ver}`;
}
return ver;
}
function objToMap(o) {
return new Map(Object.entries(o));
}
let modalActive = false;
function showModal() {
modalActive = true;
}
function hideModal() {
modalActive = false;
}
</script> </script>
<svelte:head> <svelte:head>
<title>{$page.params.name} Package | LURE Web</title> <title>{$page.params.name} Package | LURE Web</title>
<meta name="description" content="Information about the {$page.params.name} LURE package."> <meta name="description" content="Information about the {$page.params.name} LURE package." />
</svelte:head> </svelte:head>
<Header/> <Header />
<section class="container"> <section class="container">
<a href="/pkgs"><Icon icon="material-symbols:arrow-back-rounded" inline=true/> Back</a> <a href="/pkgs"><Icon icon="material-symbols:arrow-back-rounded" inline="true" /> Back</a>
{#await GetPkg({name: $page.params.name, repository: $page.params.repo})} {#await GetPkg({ name: $page.params.name, repository: $page.params.repo })}
<center><DoubleBounce color="#375a7f" /></center> <center><DoubleBounce color="#375a7f" /></center>
{:then pkg} {:then pkg}
<p class="title">{pkg.name}</p> <div class="modal {modalActive ? 'is-active' : ''}">
<p class="subtitle mb-3">{fullVer(pkg)}</p> <div class="modal-background"/>
<a href="/pkg/{pkg.repository}/{pkg.name}/lure.sh" class="button is-primary mb-5">View lure.sh</a> <div class="modal-card">
<div class="box"> <header class="modal-card-head">
<table class="table is-hoverable is-fullwidth"> <p class="modal-card-title">Badge</p>
<tbody> <button class="delete" aria-label="close" on:click={hideModal}/>
{#if pkg.description != ""} </header>
<tr> <section class="modal-card-body">
<th>Description:</th> <img
<td>{pkg.description}</td> src="{LURE_WEB_API_URL}/badge/{$page.params.repo}/{$page.params.name}"
</tr> alt="badge for {$page.params.name} package"
{/if} />
{#if pkg.homepage != ""}
<tr> <p>Markdown</p>
<th>Homepage:</th> <input
<td><a href="{pkg.homepage}">{pkg.homepage}</a></td> class="input"
</tr> value="[![LURE badge for {$page.params.name} package]({LURE_WEB_API_URL}/badge/{$page.params.repo}/{$page.params.name})]({currentURL})"
{/if} readonly
{#if pkg.maintainer != ""} />
<tr> <p>HTML</p>
<th>Maintainer:</th> <input
<td>{pkg.maintainer}</td> class="input"
</tr> value='<a href="{currentURL}"><img src="{LURE_WEB_API_URL}/badge/{$page.params.repo}/{$page.params.name}" alt="LURE badge for {$page.params.name} package"></a>'
{/if} readonly
{#if pkg.licenses.length != 0} />
<tr> </section>
<th>Licenses:</th> <footer class="modal-card-foot">
<td> <button class="button is-primary" on:click={hideModal}>Close</button>
{#each pkg.licenses as license, index} </footer>
{#if license.startsWith('custom')} </div>
{license}{#if index+1 < pkg.licenses.length},&nbsp{/if} </div>
{:else} <p class="title">{pkg.name}</p>
<a href="https://spdx.org/licenses/{license}.html">{license}</a>{#if index+1 < pkg.licenses.length},&nbsp;{/if} <p class="subtitle mb-3">{fullVer(pkg)}</p>
{/if} <a href="/pkg/{pkg.repository}/{pkg.name}/lure.sh" class="button is-primary mb-5">View lure.sh</a>
{/each} <button href="/pkg/{pkg.repository}/{pkg.name}/lure.sh" class="button is-success mb-5 ml-1" on:click={showModal}>View badge</button>
</td> <div class="box">
</tr> <table class="table is-hoverable is-fullwidth">
{/if} <tbody>
{#if pkg.architectures.length != 0} {#if pkg.description != ''}
<tr> <tr>
<th>Architectures:</th> <th>Description:</th>
<td>{pkg.architectures.join(', ')}</td> <td>{pkg.description}</td>
</tr> </tr>
{/if} {/if}
{#if pkg.conflicts.length != 0} {#if pkg.homepage != ''}
<tr> <tr>
<th>Conflicts:</th> <th>Homepage:</th>
<td>{pkg.conflicts.join(', ')}</td> <td><a href={pkg.homepage}>{pkg.homepage}</a></td>
</tr> </tr>
{/if} {/if}
{#if pkg.provides.length != 0} {#if pkg.maintainer != ''}
<tr> <tr>
<th>Provides:</th> <th>Maintainer:</th>
<td>{pkg.provides.join(', ')}</td> <td>{pkg.maintainer}</td>
</tr> </tr>
{/if} {/if}
{#each [...objToMap(pkg.depends)] as [override, pkgList]} {#if pkg.licenses.length != 0}
<tr> <tr>
<th>Depends ({override == "" ? "default" : override}):</th> <th>Licenses:</th>
<td>{pkgList.entries.join(', ')}</td> <td>
</tr> {#each pkg.licenses as license, index}
{/each} {#if license.startsWith('custom')}
{#each [...objToMap(pkg.buildDepends)] as [override, pkgList]} {license}{#if index + 1 < pkg.licenses.length},&nbsp{/if}
<tr> {:else}
<th>Build Depends ({override != "" ? override : "default"}):</th> <a href="https://spdx.org/licenses/{license}.html">{license}</a
<td>{pkgList.entries.join(', ')}</td> >{#if index + 1 < pkg.licenses.length},&nbsp;{/if}
</tr> {/if}
{/each} {/each}
<tr> </td>
<th>Repository:</th> </tr>
<td>{pkg.repository}</td> {/if}
</tr> {#if pkg.architectures.length != 0}
</tbody> <tr>
</table> <th>Architectures:</th>
</div> <td>{pkg.architectures.join(', ')}</td>
{:catch err} </tr>
<div class="notification is-danger my-3"> {/if}
Error: {err.msg} {#if pkg.conflicts.length != 0}
</div> <tr>
{/await} <th>Conflicts:</th>
<td>{pkg.conflicts.join(', ')}</td>
</tr>
{/if}
{#if pkg.provides.length != 0}
<tr>
<th>Provides:</th>
<td>{pkg.provides.join(', ')}</td>
</tr>
{/if}
{#each [...objToMap(pkg.depends)] as [override, pkgList]}
<tr>
<th>Depends ({override == '' ? 'default' : override}):</th>
<td>{pkgList.entries.join(', ')}</td>
</tr>
{/each}
{#each [...objToMap(pkg.buildDepends)] as [override, pkgList]}
<tr>
<th>Build Depends ({override != '' ? override : 'default'}):</th>
<td>{pkgList.entries.join(', ')}</td>
</tr>
{/each}
<tr>
<th>Repository:</th>
<td>{pkg.repository}</td>
</tr>
</tbody>
</table>
</div>
{:catch err}
<div class="notification is-danger my-3">
Error: {err.msg}
</div>
{/await}
</section> </section>
<Footer/> <Footer />