-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02d9677
commit 6fa59bc
Showing
7 changed files
with
134 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ API_URL= | |
ID_URL= | ||
AUXD_SECRET= | ||
USE_LOCAL_DISPLAY_JSONLD=false | ||
HOLDING_STATUS_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 65 additions & 10 deletions
75
lxl-web/src/routes/(app)/[[lang=lang]]/[fnurgel=fnurgel]/HoldingStatus.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,71 @@ | ||
<script lang="ts"> | ||
// import { onMount } from "svelte"; | ||
import { type HoldingStatus } from '$lib/types/api'; | ||
import { relativizeUrl } from '$lib/utils/http'; | ||
export let data; | ||
export let bibId; | ||
// export let data; | ||
let loading = false; | ||
let statusData: HoldingStatus | null = null; | ||
let error: string | null = null; | ||
const sigel = data?.heldBy?.sigel; | ||
const instanceId = relativizeUrl(bibId)?.replace('resourcebib', ''); // TODO better! (is there an existing lxljs util for this?) | ||
// onMount(() => { | ||
// console.log('mounted!', data) | ||
// }) | ||
async function getHoldingStatus() { | ||
if (!sigel || !instanceId) { | ||
error = 'could not retrieve data'; | ||
} else if (!statusData) { | ||
loading = true; | ||
const res = await fetch(`/api/holdingstatus?sigel=${sigel}&bib_id=${instanceId}`); | ||
const resJson = await res.json(); | ||
// async function getHolddingStatus(){ | ||
// console.log(data); | ||
// } | ||
if (resJson.item_information.error) { | ||
error = resJson.item_information.error; | ||
} else { | ||
statusData = resJson; | ||
} | ||
loading = false; | ||
} | ||
} | ||
</script> | ||
|
||
<slot /> | ||
<div>Hello</div> | ||
<details on:toggle={getHoldingStatus}> | ||
<slot /> | ||
<div class="my-4"> | ||
{#if loading} | ||
<span>Laddar....</span> | ||
{/if} | ||
{#if error} | ||
{error} | ||
{/if} | ||
{#if statusData && statusData.item_information.items.length > 0} | ||
<!-- TODO properly --> | ||
<!-- ripped from https://github.com/libris/search4/blob/09180a39077619b2e4f4ba0887f9474679b40489/src/views/ProductPage/Work/Holding.vue#L124 --> | ||
{#each statusData.item_information.items as item} | ||
<table class="my-2"> | ||
<tbody> | ||
<tr> | ||
<th>Placering</th> | ||
<td>{item.Location}</td> | ||
</tr> | ||
<tr> | ||
<th>Hylla</th> | ||
<td>{item.Call_No}</td> | ||
</tr> | ||
<tr> | ||
<th>Lånepolitik</th> | ||
<td>{item.Loan_Policy}</td> | ||
</tr> | ||
<tr> | ||
<th>Status</th> | ||
<td>{item.Status}</td> | ||
</tr> | ||
<tr> | ||
<th>Datum</th> | ||
<td>{item.Status_Date}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
{/each} | ||
{/if} | ||
</div> | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { env } from '$env/dynamic/private'; | ||
import type { HoldingStatus } from '$lib/types/api'; | ||
import { json } from '@sveltejs/kit'; | ||
|
||
export async function GET({ url }) { | ||
const sigel = url.searchParams.get('sigel'); | ||
const bib_id = url.searchParams.get('bib_id'); | ||
const res = await fetch(`${env.HOLDING_STATUS_URL}?output=json&sigel=${sigel}&bib_id=${bib_id}`); | ||
|
||
// TODO error handling, map statuses | ||
// see https://github.com/libris/search4/blob/09180a39077619b2e4f4ba0887f9474679b40489/src/views/ProductPage/Work/Holding.vue#L64 | ||
|
||
const data = (await res.json()) as HoldingStatus; | ||
|
||
return json(data); | ||
} |