StatCards - fetch real data from API

ref #10
This commit is contained in:
Philipp Dormann 2020-12-31 16:19:58 +01:00
parent e9a6637eb9
commit 3d93b04264

View File

@ -1,96 +1,122 @@
<script> <script>
import { _ } from "svelte-i18n"; import { _ } from "svelte-i18n";
import { TrackService, StatsService } from "@odit/lfk-client-js";
const stats_promise = StatsService.statsControllerGet();
stats_promise.then((res) => {
console.log(res);
});
</script> </script>
<div <!-- -->
class="flex flex-col lg:flex-row w-full lg:space-x-2 space-y-2 lg:space-y-0 mb-2 lg:mb-4"> <h1>Allgemeine Statistiken</h1>
<div class="w-full lg:w-1/4"> {#await stats_promise}
<div <div
class="widget w-full p-4 rounded-lg bg-white border border-grey-100 dark:bg-grey-895 dark:border-grey-890"> class="bg-teal-lightest border-t-4 border-teal rounded-b text-teal-darkest px-4 py-3 shadow-md my-2"
<div class="flex flex-row items-center justify-between"> role="alert">
<div class="flex flex-col"> <p class="font-bold">stats are being loaded...</p>
<div class="text-xs uppercase font-light text-grey-500"> <p class="text-sm">This might take a moment 👀</p>
{$_('runners')}
</div>
<div class="text-xl font-bold">69</div>
</div><svg
stroke="currentColor"
fill="none"
stroke-width="2"
viewBox="0 0 24 24"
stroke-linecap="round"
stroke-linejoin="round"
size="24"
class="stroke-current text-grey-500"
height="24"
width="24"
xmlns="http://www.w3.org/2000/svg"><path
d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2" />
<circle cx="9" cy="7" r="4" />
<path d="M23 21v-2a4 4 0 0 0-3-3.87" />
<path d="M16 3.13a4 4 0 0 1 0 7.75" /></svg>
</div>
</div>
</div> </div>
<div class="w-full lg:w-1/4"> {:then stats}
<div <div
class="widget w-full p-4 rounded-lg bg-white border border-grey-100 dark:bg-grey-895 dark:border-grey-890"> class="flex flex-col lg:flex-row w-full lg:space-x-2 space-y-2 lg:space-y-0 mb-2 lg:mb-4">
<div class="flex flex-row items-center justify-between"> <div class="w-full lg:w-1/4">
<div class="flex flex-col"> <div
<div class="text-xs uppercase font-light text-grey-500"> class="widget w-full p-4 rounded-lg bg-white border border-grey-100 dark:bg-grey-895 dark:border-grey-890">
{$_('total-scans')} <div class="flex flex-row items-center justify-between">
</div> <div class="flex flex-col">
<div class="text-xl font-bold">1500</div> <div class="text-xs uppercase font-light text-grey-500">
</div><svg {$_('runners')}
stroke="currentColor" </div>
fill="none" <div class="text-xl font-bold">{stats.total_runners}</div>
stroke-width="2" </div><svg
viewBox="0 0 24 24" stroke="currentColor"
stroke-linecap="round" fill="none"
stroke-linejoin="round" stroke-width="2"
size="24" viewBox="0 0 24 24"
class="stroke-current text-grey-500" stroke-linecap="round"
height="24" stroke-linejoin="round"
width="24" size="24"
xmlns="http://www.w3.org/2000/svg"><polyline class="stroke-current text-grey-500"
points="22 12 18 12 15 21 9 3 6 12 2 12" /></svg> height="24"
</div> width="24"
</div> xmlns="http://www.w3.org/2000/svg"><path
</div> d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2" />
<div class="w-full lg:w-1/4"> <circle cx="9" cy="7" r="4" />
<div <path d="M23 21v-2a4 4 0 0 0-3-3.87" />
class="widget w-full p-4 rounded-lg bg-white border border-grey-100 dark:bg-grey-895 dark:border-grey-890"> <path d="M16 3.13a4 4 0 0 1 0 7.75" /></svg>
<div class="flex flex-row items-center justify-between"> </div>
<div class="flex flex-col"> </div>
<div class="text-xs uppercase font-light text-grey-500"> </div>
{$_('total-donations')} <div class="w-full lg:w-1/4">
</div> <div
<div class="text-xl font-bold">5000,00 €</div> class="widget w-full p-4 rounded-lg bg-white border border-grey-100 dark:bg-grey-895 dark:border-grey-890">
</div><svg <div class="flex flex-row items-center justify-between">
xmlns="http://www.w3.org/2000/svg" <div class="flex flex-col">
height="24" <div class="text-xs uppercase font-light text-grey-500">
width="24"><path d="M0 0h24v24H0z" fill="none" /> {$_('total-scans')}
<path </div>
d="M15 18.5A6.48 6.48 0 019.24 15H15v-2H8.58c-.05-.33-.08-.66-.08-1s.03-.67.08-1H15V9H9.24A6.491 6.491 0 0115 5.5c1.61 0 3.09.59 4.23 1.57L21 5.3A8.955 8.955 0 0015 3c-3.92 0-7.24 2.51-8.48 6H3v2h3.06a8.262 8.262 0 000 2H3v2h3.52c1.24 3.49 4.56 6 8.48 6 2.31 0 4.41-.87 6-2.3l-1.78-1.77c-1.13.98-2.6 1.57-4.22 1.57z" /></svg> <div class="text-xl font-bold">{stats.total_scans}</div>
</div> </div><svg
</div> stroke="currentColor"
</div> fill="none"
<div class="w-full lg:w-1/4"> stroke-width="2"
<div viewBox="0 0 24 24"
class="widget w-full p-4 rounded-lg bg-white border border-grey-100 dark:bg-grey-895 dark:border-grey-890"> stroke-linecap="round"
<div class="flex flex-row items-center justify-between"> stroke-linejoin="round"
<div class="flex flex-col"> size="24"
<div class="text-xs uppercase font-light text-grey-500"> class="stroke-current text-grey-500"
{$_('total-distance')} height="24"
</div> width="24"
<div class="text-xl font-bold">100.0 km</div> xmlns="http://www.w3.org/2000/svg"><polyline
points="22 12 18 12 15 21 9 3 6 12 2 12" /></svg>
</div>
</div>
</div>
<div class="w-full lg:w-1/4">
<div
class="widget w-full p-4 rounded-lg bg-white border border-grey-100 dark:bg-grey-895 dark:border-grey-890">
<div class="flex flex-row items-center justify-between">
<div class="flex flex-col">
<div class="text-xs uppercase font-light text-grey-500">
{$_('total-donations')}
</div>
<div class="text-xl font-bold">{stats.total_donation}</div>
</div><svg
xmlns="http://www.w3.org/2000/svg"
height="24"
width="24"><path d="M0 0h24v24H0z" fill="none" />
<path
d="M15 18.5A6.48 6.48 0 019.24 15H15v-2H8.58c-.05-.33-.08-.66-.08-1s.03-.67.08-1H15V9H9.24A6.491 6.491 0 0115 5.5c1.61 0 3.09.59 4.23 1.57L21 5.3A8.955 8.955 0 0015 3c-3.92 0-7.24 2.51-8.48 6H3v2h3.06a8.262 8.262 0 000 2H3v2h3.52c1.24 3.49 4.56 6 8.48 6 2.31 0 4.41-.87 6-2.3l-1.78-1.77c-1.13.98-2.6 1.57-4.22 1.57z" /></svg>
</div>
</div>
</div>
<div class="w-full lg:w-1/4">
<div
class="widget w-full p-4 rounded-lg bg-white border border-grey-100 dark:bg-grey-895 dark:border-grey-890">
<div class="flex flex-row items-center justify-between">
<div class="flex flex-col">
<div class="text-xs uppercase font-light text-grey-500">
{$_('total-distance')}
</div>
<div class="text-xl font-bold">
{stats.total_distance / 1000}
km
</div>
</div>
<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path
d="M0 0h24v24H0z"
fill="none" />
<path
d="M21 6H3c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 10H3V8h2v4h2V8h2v4h2V8h2v4h2V8h2v4h2V8h2v8z" /></svg>
</div> </div>
<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path
d="M0 0h24v24H0z"
fill="none" />
<path
d="M21 6H3c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 10H3V8h2v4h2V8h2v4h2V8h2v4h2V8h2v4h2V8h2v8z" /></svg>
</div> </div>
</div> </div>
</div> </div>
</div> {:catch error}
<div class="text-white px-6 py-4 border-0 rounded relative mb-4 bg-red-500">
<span class="inline-block align-middle mr-8">
<b class="capitalize">😢 Error</b>
{error}
</span>
</div>
{/await}