Skip to content

Commit

Permalink
Add first implementation of sending pica data to backend endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Nov 26, 2024
1 parent 1cbe393 commit 5bbe06e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/client/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const initPromise = useInit()
import { useLogin } from "@/composables/login.js"
const { loginConfigured } = useLogin()
const { loggedIn, user } = inject("login-refs")
const { loggedIn, user, token } = inject("login-refs")
import { useGoToTop } from "./composables/go-to-top.js"
const { showGoToTopButton, goToTop } = useGoToTop()
import { version, name, showWhenExistsKey, examples, allowedUsers } from "@/config.js"
import { version, name, baseUrl, showWhenExistsKey, examples, allowedUsers } from "@/config.js"
const hasBackendAccess = computed(() => allowedUsers.includes(user.value?.uri))
Expand Down Expand Up @@ -212,8 +212,27 @@ watch(() => state.ppn, async (ppn) => {
console.timeEnd(`Load PPN ${ppn}`)
})
function submitEnrichments() {
alert("Funktion nicht implementiert.")
async function submitEnrichments(ppn, suggestions) {
const pica = suggestionsToPica({ ppn, suggestions })
const options = {
method: "post",
headers: token ? {
Authorization: `Bearer ${token.value}`,
} : {},
body: pica,
}
// TODO: Improve error handling further.
try {
const response = await fetch(baseUrl + "submit", options)
const data = await response.json()
if (response.status === 201) {
alert("Success")
} else {
alert(`${data.error}: ${jskos.prefLabel(data) || data.message}`)
}
} catch (error) {
alert(`${error.name}: ${error.message}`)
}
}
</script>
Expand Down Expand Up @@ -382,7 +401,7 @@ function submitEnrichments() {
<button
class="button"
:disabled="selectedSuggestions.length === 0"
@click="submitEnrichments">
@click="submitEnrichments(state.ppn, selectedSuggestions)">
{{ selectedSuggestions.length }} {{ selectedSuggestions.length === 1 ? "Vorschlag" : "Vorschläge" }} in Datenbank eintragen
</button>
</p>
Expand Down
2 changes: 2 additions & 0 deletions src/client/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ export const loginServerUrl = loginServer && loginServer.replace(/https?:\/\//,
export const loginServerSsl = loginServer && loginServer.startsWith("https://")

export const allowedUsers = (import.meta.env.VITE_ALLOWED_USERS || "").split(",").filter(Boolean).map(uri => uri.trim())

export const baseUrl = import.meta.env.BASE_URL || "/"

0 comments on commit 5bbe06e

Please sign in to comment.