@ -22,6 +22,13 @@
type = "black"
@ click = "exportToPDF"
/ >
< BaseButton
: label = "t('Switch to student view')"
icon = "eye-on"
class = "mr-2 mb-2"
type = "black"
@ click = "toggleTeacherStudent"
/ >
< / ButtonToolbar >
< div v-if ="!linksWithoutCategory && !categories" >
@ -43,6 +50,10 @@
< div class = "flex flex-col gap-4" >
<!-- Render the list of links -- >
< LinkCategoryCard v-if ="linksWithoutCategory && linksWithoutCategory.length > 0" >
< template # header >
< h5 > { { t ( 'General' ) } } < / h5 >
< / template >
< ul >
< li v-for ="link in linksWithoutCategory" :key="link.id" class="mb-4" >
< LinkItem
@ -61,7 +72,7 @@
< LinkCategoryCard v-for ="category in categories" :key="category.info.id" >
< template # header >
< div class = "flex justify-between mb-2 " >
< div class = "flex justify-between" >
< div class = "flex items-center" >
< BaseIcon class = "mr-2" icon = "folder-generic" size = "big" / >
< h5 > { { category . info . name } } < / h5 >
@ -75,18 +86,18 @@
@ click = "editCategory(category)"
/ >
< BaseButton
: label = "t('Delete ')"
: label = "t('Change visibility ')"
type = "black"
: icon = "category.info.visible ? 'eye-on' : 'eye-off'"
size = "small"
@ click = "dele teCategory(category)"
@ click = "toggl eCategoryVisibilit y(category)"
/ >
< BaseButton
: label = "t('Delete')"
type = "danger "
type = "black "
icon = "delete"
size = "small"
@ click = "toggleCategoryVisibilit y(category)"
@ click = "deleteCategor y(category)"
/ >
< / div >
< / div >
@ -122,12 +133,11 @@ import {computed, onMounted, ref} from "vue";
import { useStore } from "vuex" ;
import { useRoute , useRouter } from "vue-router" ;
import { useI18n } from "vue-i18n" ;
import axios from "axios" ;
import { ENTRYPOINT } from "../../config/entrypoint" ;
import BaseIcon from "../../components/basecomponents/BaseIcon.vue" ;
import LinkItem from "../../components/links/LinkItem.vue" ;
import { useNotification } from "../../composables/notification" ;
import LinkCategoryCard from "../../components/links/LinkCategoryCard.vue" ;
import linkService from "../../services/linkService" ;
const store = useStore ( ) ;
const route = useRoute ( ) ;
@ -146,6 +156,13 @@ const categories = ref([]);
const selectedLink = ref ( null ) ;
const selectedCategory = ref ( null ) ;
onMounted ( ( ) => {
linksWithoutCategory . value = [ ] ;
categories . value = [ ] ;
fetchLinks ( )
} ) ;
function editLink ( link ) {
selectedLink . value = { ... link } ;
router . push ( {
@ -155,90 +172,63 @@ function editLink(link) {
} ) ;
}
function deleteLink ( id ) {
axios
. delete ( ` ${ ENTRYPOINT } links/ ${ id } ` )
. then ( response => {
console . log ( 'Link deleted:' , response . data ) ;
fetchLinks ( ) ;
} )
. catch ( error => {
console . error ( 'Error deleting link:' , error ) ;
} ) ;
async function deleteLink ( id ) {
try {
await linkService . deleteLink ( id )
notifications . showSuccessNotification ( t ( 'Link deleted' ) )
fetchLinks ( )
} catch ( error ) {
console . error ( 'Error deleting link:' , error ) ;
notifications . showErrorNotification ( t ( 'Could not delete link' ) )
}
}
function checkLink ( id , url ) {
/ / I m p l e m e n t t h e l o g i c t o c h e c k t h e l i n k u s i n g t h e p r o v i d e d i d a n d u r l
}
function toggleVisibility ( link ) {
const makeVisible = ! link . visible ;
const endpoint = ` ${ ENTRYPOINT } links/ ${ link . iid } /toggle_visibility ` ;
axios
. put ( endpoint , { visible : makeVisible } )
. then ( response => {
const updatedLink = response . data ;
notifications . showSuccessNotification ( t ( 'Link visibility updated' ) )
async function toggleVisibility ( link ) {
try {
const makeVisible = ! link . visible ;
await linkService . toggleLinkVisibility ( link . iid , makeVisible )
notifications . showSuccessNotification ( t ( 'Link visibility updated' ) )
fetchLinks ( )
linksWithoutCategory . value . forEach ( ( item ) => {
if ( item . iid === link . iid ) {
item . linkVisible = ! item . linkVisible ;
}
} )
. catch ( error => {
console . error ( 'Error updating link visibility:' , error ) ;
} ) ;
linksWithoutCategory . value . forEach ( ( item ) => {
if ( item . iid === link . iid ) {
item . linkVisible = ! item . linkVisible ;
}
} ) ;
} catch ( error ) {
console . error ( 'Error deleting link:' , error ) ;
notifications . showErrorNotification ( t ( 'Could not change visibility of link' ) )
}
}
function moveUp ( id , position ) {
console . log ( 'linkIndex Down position' , position ) ;
/ / S e n d t h e u p d a t e d p o s i t i o n t o t h e s e r v e r
const endpoint = ` ${ ENTRYPOINT } links/ ${ id } /move ` ;
async function moveUp ( id , position ) {
let newPosition = parseInt ( position ) - 1 ;
if ( newPosition < 0 ) {
newPosition = 0 ;
}
console . log ( 'linkIndex Up newPosition' , newPosition ) ;
axios
. put ( endpoint , { position : newPosition } )
. then ( ( response ) => {
console . log ( "Link moved up:" , response . data ) ;
/ / P e r f o r m a n y a d d i t i o n a l a c t i o n s o r u p d a t e s i f n e e d e d
fetchLinks ( ) ;
} )
. catch ( ( error ) => {
console . error ( "Error moving link up:" , error ) ;
} ) ;
try {
await linkService . moveLink ( id , newPosition )
notifications . showSuccessNotification ( t ( 'Link moved up' ) )
fetchLinks ( )
} catch ( error ) {
console . error ( "Error moving link up:" , error ) ;
notifications . showErrorNotification ( t ( 'Could not moved link up' ) )
}
}
function moveDown ( id , position ) {
console . log ( 'linkIndex Down position' , position ) ;
/ / S e n d t h e u p d a t e d p o s i t i o n t o t h e s e r v e r
const endpoint = ` ${ ENTRYPOINT } links/ ${ id } /move ` ;
async function moveDown ( id , position ) {
const newPosition = parseInt ( position ) + 1 ;
console . log ( 'linkIndex Down newPosition' , newPosition ) ;
axios
. put ( endpoint , { position : newPosition } )
. then ( ( response ) => {
console . log ( "Link moved down:" , response . data ) ;
/ / P e r f o r m a n y a d d i t i o n a l a c t i o n s o r u p d a t e s i f n e e d e d
fetchLinks ( ) ;
} )
. catch ( ( error ) => {
console . error ( "Error moving link down:" , error ) ;
} ) ;
try {
await linkService . moveLink ( id , newPosition )
notifications . showSuccessNotification ( t ( 'Link moved down' ) )
fetchLinks ( )
} catch ( error ) {
console . error ( "Error moving link down:" , error ) ;
notifications . showErrorNotification ( t ( 'Could not moved link down' ) )
}
}
function redirectToCreateLink ( ) {
@ -255,38 +245,7 @@ function redirectToCreateLinkCategory() {
} ) ;
}
function fetchLinks ( ) {
const params = {
'resourceNode.parent' : route . query . parent || null ,
'cid' : route . query . cid || null ,
'sid' : route . query . sid || null
} ;
axios
. get ( ENTRYPOINT + 'links' , { params } )
. then ( response => {
console . log ( 'responsedata:' , response . data ) ;
const data = response . data ;
linksWithoutCategory . value = data . linksWithoutCategory ;
categories . value = data . categories ;
console . log ( 'linksWithoutCategory:' , linksWithoutCategory . value ) ;
console . log ( 'categories:' , categories . value ) ;
} )
. catch ( error => {
console . error ( 'Error fetching links:' , error ) ;
} ) ;
}
onMounted ( ( ) => {
linksWithoutCategory . value = [ ] ;
categories . value = [ ] ;
fetchLinks ( ) ;
} ) ;
function editCategory ( category ) {
console . log ( 'category.info.id' , category . info . id ) ;
selectedCategory . value = { ... category } ;
router . push ( {
name : "UpdateLinkCategory" ,
@ -295,38 +254,51 @@ function editCategory(category) {
} ) ;
}
function deleteCategory ( category ) {
axios
. delete ( ` ${ ENTRYPOINT } link_categories/ ${ category . info . id } ` )
. then ( response => {
console . log ( 'Category deleted:' , response . data ) ;
fetchLinks ( ) ;
} )
. catch ( error => {
console . error ( 'Error deleting category:' , error ) ;
} ) ;
async function deleteCategory ( category ) {
try {
await linkService . deleteCategory ( category . info . id )
notifications . showSuccessNotification ( t ( 'Category deleted' ) )
fetchLinks ( )
} catch ( error ) {
console . error ( 'Error deleting category:' , error ) ;
notifications . showErrorNotification ( t ( 'Could not delete category' ) )
}
}
function toggleCategoryVisibility ( category ) {
const makeVisible = ! category . info . visible ;
const endpoint = ` ${ ENTRYPOINT } link_categories/ ${ category . info . id } /toggle_visibility ` ;
axios
. put ( endpoint , { visible : makeVisible } )
. then ( response => {
const updatedLinkCategory = response . data ;
console . log ( 'Link visibility updated:' , updatedLinkCategory ) ;
category . info . visible = updatedLinkCategory . linkCategoryVisible ;
} )
. catch ( error => {
console . error ( 'Error updating link visibility:' , error ) ;
} ) ;
async function toggleCategoryVisibility ( category ) {
const makeVisible = ! category . info . visible
try {
const updatedLinkCategory = await linkService . toggleCategoryVisibility ( category . info . id , makeVisible )
category . info . visible = updatedLinkCategory . linkCategoryVisible ;
notifications . showSuccessNotification ( t ( 'Visibility of category changed' ) )
} catch ( error ) {
console . error ( 'Error updating link visibility:' , error )
notifications . showErrorNotification ( t ( 'Could not change visibility of category' ) )
}
}
function exportToPDF ( ) {
/ / T O D O
}
function toggleTeacherStudent ( ) {
/ / T O D O
}
async function fetchLinks ( ) {
const params = {
'resourceNode.parent' : route . query . parent || null ,
'cid' : route . query . cid || null ,
'sid' : route . query . sid || null
} ;
try {
const data = await linkService . getLinks ( params )
linksWithoutCategory . value = data . linksWithoutCategory ;
categories . value = data . categories ;
} catch ( error ) {
console . error ( 'Error fetching links:' , error ) ;
notifications . showErrorNotification ( t ( 'Could not retrieve links' ) )
}
}
< / script >