-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
133 additions
and
81 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
58 changes: 58 additions & 0 deletions
58
arches_lingo/src/arches_lingo/components/header/PageHeader.vue
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,58 @@ | ||
<script setup lang="ts"> | ||
import { ref } from "vue"; | ||
import { useGettext } from "vue3-gettext"; | ||
import Button from 'primevue/button'; | ||
import Menubar from 'primevue/menubar'; | ||
import { routeNames } from "@/arches_lingo/routes.ts"; | ||
import UserInteraction from "@/arches_lingo/components/user/UserInteraction.vue"; | ||
const { $gettext } = useGettext(); | ||
const items = ref([ | ||
{ | ||
label: $gettext('Search'), | ||
icon: 'fa fa-search', | ||
name: routeNames.search | ||
}, | ||
{ | ||
label: $gettext('Advanced Search'), | ||
icon: 'fa fa-file', | ||
name: routeNames.advancedSearch | ||
}, | ||
]); | ||
</script> | ||
|
||
<template> | ||
<Menubar :model="items" style="height: 3rem;"> | ||
<template #start> | ||
<RouterLink | ||
class="router-link" | ||
:to="{ name: routeNames.root }" | ||
style="text-decoration: none; color: inherit" | ||
> | ||
<h2>{{ $gettext("Arches Lingo") }}</h2> | ||
</RouterLink> | ||
</template> | ||
<template #item="{ item }"> | ||
<RouterLink | ||
class="router-link" | ||
:to="{ name: item.name }" | ||
> | ||
<Button v-ripple> | ||
<i :class="item.icon"></i> | ||
<span>{{ item.label }}</span> | ||
</Button> | ||
</RouterLink> | ||
</template> | ||
<template #end> | ||
<UserInteraction /> | ||
</template> | ||
</Menubar> | ||
</template> | ||
|
||
<style scoped> | ||
</style> |
60 changes: 60 additions & 0 deletions
60
arches_lingo/src/arches_lingo/components/user/UserInteraction.vue
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,60 @@ | ||
<script setup lang="ts"> | ||
import { computed, inject, ref } from "vue"; | ||
import { useRouter } from "vue-router"; | ||
import { useGettext } from "vue3-gettext"; | ||
import { useToast } from "primevue/usetoast"; | ||
import Button from "primevue/button"; | ||
import { logout } from "@/arches_lingo/api.ts"; | ||
import { | ||
DEFAULT_ERROR_TOAST_LIFE, | ||
ERROR, | ||
userKey, | ||
} from "@/arches_lingo/constants.ts"; | ||
import { routeNames } from "@/arches_lingo/routes.ts"; | ||
const { user, setUser } = inject(userKey, { | ||
user: ref(null), | ||
setUser: () => {}, | ||
}); | ||
const { $gettext } = useGettext(); | ||
const toast = useToast(); | ||
const router = useRouter(); | ||
const issueLogout = async () => { | ||
try { | ||
await logout(); | ||
setUser(null); | ||
router.push({ name: routeNames.login }); | ||
} catch (error) { | ||
toast.add({ | ||
severity: ERROR, | ||
life: DEFAULT_ERROR_TOAST_LIFE, | ||
summary: $gettext("Sign out failed."), | ||
detail: error instanceof Error ? error.message : undefined, | ||
}); | ||
} | ||
}; | ||
const bestName = computed(() => { | ||
if (!user.value) { | ||
return ""; | ||
} | ||
// TODO: determine appropriate i18n for this. | ||
if (user.value.first_name && user.value.last_name) { | ||
return user.value.first_name + " " + user.value.last_name; | ||
} | ||
return user.value.username; | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div style="display: flex; align-items: center;"> | ||
<span>{{ $gettext("Hello %{bestName}", { bestName }) }}</span> | ||
<Button style="margin-left: 1rem;" @click="issueLogout"> | ||
{{ $gettext("Sign out") }} | ||
</Button> | ||
</div> | ||
</template> |
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,78 +1 @@ | ||
<script setup lang="ts"> | ||
import { computed, inject, ref } from "vue"; | ||
import { useRouter } from "vue-router"; | ||
import { useGettext } from "vue3-gettext"; | ||
import { useToast } from "primevue/usetoast"; | ||
import Button from "primevue/button"; | ||
import { logout } from "@/arches_lingo/api.ts"; | ||
import { | ||
DEFAULT_ERROR_TOAST_LIFE, | ||
ERROR, | ||
userKey, | ||
} from "@/arches_lingo/constants.ts"; | ||
import { routeNames } from "@/arches_lingo/routes.ts"; | ||
const { user, setUser } = inject(userKey, { | ||
user: ref(null), | ||
setUser: () => {}, | ||
}); | ||
const { $gettext } = useGettext(); | ||
const toast = useToast(); | ||
const router = useRouter(); | ||
const issueLogout = async () => { | ||
try { | ||
await logout(); | ||
setUser(null); | ||
router.push({ name: routeNames.login }); | ||
} catch (error) { | ||
toast.add({ | ||
severity: ERROR, | ||
life: DEFAULT_ERROR_TOAST_LIFE, | ||
summary: $gettext("Sign out failed."), | ||
detail: error instanceof Error ? error.message : undefined, | ||
}); | ||
} | ||
}; | ||
const bestName = computed(() => { | ||
if (!user.value) { | ||
return ""; | ||
} | ||
// TODO: determine appropriate i18n for this. | ||
if (user.value.first_name && user.value.last_name) { | ||
return user.value.first_name + " " + user.value.last_name; | ||
} | ||
return user.value.username; | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div style="display: flex; justify-content: space-between"> | ||
<h1>{{ $gettext("LINGO") }}</h1> | ||
<span>{{ $gettext("Hello %{bestName}", { bestName }) }}</span> | ||
<Button @click="issueLogout"> | ||
{{ $gettext("Sign out") }} | ||
</Button> | ||
</div> | ||
<nav> | ||
<RouterLink :to="{ name: routeNames.root }"> | ||
{{ $gettext("Go to Root") }} | ||
</RouterLink> | ||
<br /> | ||
<RouterLink :to="{ name: routeNames.schemes }"> | ||
{{ $gettext("Go to Schemes") }} | ||
</RouterLink> | ||
<br /> | ||
<RouterLink :to="{ name: routeNames.search }"> | ||
{{ $gettext("Go to Search") }} | ||
</RouterLink> | ||
<br /> | ||
<RouterLink :to="{ name: routeNames.advancedSearch }"> | ||
{{ $gettext("Go to Advanced Search") }} | ||
</RouterLink> | ||
</nav> | ||
</template> | ||
<template>HomePage placeholder</template> |
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