Merge pull request #5481 from christianbeeznest/ofaj-21605

Internal: Refactor link list display - refs BT#21605
pull/5482/head
christianbeeznest 2 years ago committed by GitHub
commit ef0a06943b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      assets/vue/components/links/LinkCategoryCard.vue
  2. 39
      assets/vue/views/links/LinksList.vue

@ -1,12 +1,12 @@
<template> <template>
<BaseCard plain class="bg-white"> <BaseCard plain class="bg-white">
<template #header> <template v-if="showHeader" #header>
<div class="px-4 py-2 -mb-2 bg-gray-15"> <div class="px-4 py-2 -mb-2 bg-gray-15">
<slot name="header"/> <slot name="header"/>
</div> </div>
</template> </template>
<hr class="-mt-2 mb-4 -mx-4"> <hr v-if="showHeader" class="-mt-2 mb-4 -mx-4">
<div> <div>
<slot/> <slot/>
@ -19,4 +19,10 @@ import BaseCard from "../basecomponents/BaseCard.vue"
import {useI18n} from "vue-i18n" import {useI18n} from "vue-i18n"
const {t} = useI18n() const {t} = useI18n()
defineProps({
showHeader: {
type: Boolean,
default: true,
},
});
</script> </script>

@ -28,7 +28,7 @@
</div> </div>
</LinkCategoryCard> </LinkCategoryCard>
<div v-if="!linksWithoutCategory && !categories"> <div v-if="!linksWithoutCategory.length && !categories.length">
<!-- Render the image and create button --> <!-- Render the image and create button -->
<EmptyState <EmptyState
:summary="t('Add your first link to this course')" :summary="t('Add your first link to this course')"
@ -48,10 +48,10 @@
v-if="!isLoading" v-if="!isLoading"
class="flex flex-col gap-4" class="flex flex-col gap-4"
> >
<!-- Render the list of links --> <!-- Render the list of links without a category -->
<LinkCategoryCard v-if="linksWithoutCategory && linksWithoutCategory.length > 0"> <LinkCategoryCard v-if="linksWithoutCategory.length > 0" :showHeader="false">
<template #header> <template #header>
<h5>{{ t("General") }}</h5> <h5>{{ t('General') }}</h5>
</template> </template>
<ul> <ul>
@ -74,9 +74,11 @@
</ul> </ul>
</LinkCategoryCard> </LinkCategoryCard>
<!-- Render the list of categorized links -->
<LinkCategoryCard <LinkCategoryCard
v-for="category in categories" v-for="category in categories"
:key="category.info.id" :key="category.info.id"
:showHeader="true"
> >
<template #header> <template #header>
<div class="flex justify-between"> <div class="flex justify-between">
@ -132,8 +134,8 @@
/> />
</li> </li>
</ul> </ul>
<p v-if="!category.links || category.links === 0"> <p v-if="!category.links || category.links.length === 0">
{{ t("There are no links in this category") }} {{ t('There are no links in this category') }}
</p> </p>
</LinkCategoryCard> </LinkCategoryCard>
</div> </div>
@ -152,7 +154,7 @@
<div v-if="categoryToDelete"> <div v-if="categoryToDelete">
<p class="mb-2 font-semibold">{{ categoryToDelete.info.title }}</p> <p class="mb-2 font-semibold">{{ categoryToDelete.info.title }}</p>
<p> <p>
{{ t("With links") }}: {{ (categoryToDelete.links || []).map((l) => l.title).join(", ") }} {{ t('With links') }}: {{ (categoryToDelete.links || []).map((l) => l.title).join(', ') }}
</p> </p>
</div> </div>
</BaseDialogDelete> </BaseDialogDelete>
@ -187,7 +189,7 @@ const notifications = useNotification()
const isCurrentTeacher = securityStore.isCurrentTeacher const isCurrentTeacher = securityStore.isCurrentTeacher
const linksWithoutCategory = ref([]) const linksWithoutCategory = ref([])
const categories = ref({}) const categories = ref([])
const selectedLink = ref(null) const selectedLink = ref(null)
const selectedCategory = ref(null) const selectedCategory = ref(null)
@ -206,11 +208,11 @@ const categoryToDelete = ref(null)
const isLoading = ref(true) const isLoading = ref(true)
const linkValidationResults = ref({}); const linkValidationResults = ref({})
onMounted(() => { onMounted(() => {
linksWithoutCategory.value = [] linksWithoutCategory.value = []
categories.value = {} categories.value = []
fetchLinks() fetchLinks()
}) })
@ -243,11 +245,14 @@ async function deleteLink() {
async function checkLink(id, url) { async function checkLink(id, url) {
try { try {
const result = await linkService.checkLink(url, id); const result = await linkService.checkLink(url, id)
linkValidationResults.value = { ...linkValidationResults.value, [id]: { isValid: result.isValid } }; linkValidationResults.value = { ...linkValidationResults.value, [id]: { isValid: result.isValid } }
} catch (error) { } catch (error) {
console.error("Error checking link:", error); console.error("Error checking link:", error)
linkValidationResults.value = { ...linkValidationResults.value, [id]: { isValid: false, message: error.message || 'Link validation failed' } }; linkValidationResults.value = {
...linkValidationResults.value,
[id]: { isValid: false, message: error.message || "Link validation failed" }
}
} }
} }
@ -276,8 +281,7 @@ async function moveUp(id, position) {
notifications.showSuccessNotification(t("Link moved up")) notifications.showSuccessNotification(t("Link moved up"))
await fetchLinks() await fetchLinks()
} catch (error) { } catch (error) {
console.error("Error moving link up:", error) notifications.showErrorNotification(t("Could not move link up"))
notifications.showErrorNotification(t("Could not moved link up"))
} }
} }
@ -288,8 +292,7 @@ async function moveDown(id, position) {
notifications.showSuccessNotification(t("Link moved down")) notifications.showSuccessNotification(t("Link moved down"))
await fetchLinks() await fetchLinks()
} catch (error) { } catch (error) {
console.error("Error moving link down:", error) notifications.showErrorNotification(t("Could not move link down"))
notifications.showErrorNotification(t("Could not moved link down"))
} }
} }

Loading…
Cancel
Save