parent
bcea4710fd
commit
3c36a2c266
@ -0,0 +1,38 @@ |
||||
<template> |
||||
<div v-if="categories.length" class="grid"> |
||||
<div v-for="category in categories"> |
||||
<div class="text-xl"> |
||||
<v-icon icon="mdi-folder"/> |
||||
{{ category.name }} |
||||
</div> |
||||
<SessionListCategoryWrapper :sessions="getSessionsFromCategory(category)"/> |
||||
</div> |
||||
</div> |
||||
</template> |
||||
<script> |
||||
|
||||
import SessionListCategoryWrapper from '../../components/session/SessionListCategoryWrapper'; |
||||
import {toRefs} from "vue"; |
||||
|
||||
export default { |
||||
name: 'SessionCategoryListWrapper', |
||||
components: { |
||||
SessionListCategoryWrapper |
||||
}, |
||||
props: { |
||||
categories: Array, |
||||
categoryWithSessions: Array |
||||
}, |
||||
setup(props) { |
||||
const {categoryWithSessions} = toRefs(props); |
||||
function getSessionsFromCategory(category) { |
||||
return categoryWithSessions.value[category._id]['sessions']; |
||||
} |
||||
|
||||
return { |
||||
getSessionsFromCategory |
||||
} |
||||
} |
||||
} |
||||
|
||||
</script> |
@ -0,0 +1,96 @@ |
||||
<template> |
||||
<SessionListNoCategoryWrapper :sessions="sessionList"/> |
||||
<SessionCategoryListWrapper :categories="categories" :categoryWithSessions="categoryWithSessions"/> |
||||
</template> |
||||
<script> |
||||
|
||||
import SessionCategoryListWrapper from '../../components/session/SessionCategoryListWrapper'; |
||||
import SessionListNoCategoryWrapper from "../../components/session/SessionListNoCategoryWrapper"; |
||||
|
||||
import isEmpty from "lodash/isEmpty"; |
||||
import {computed, ref, toRefs} from "vue"; |
||||
import {useResult} from "@vue/apollo-composable"; |
||||
|
||||
export default { |
||||
name: 'SessionCategoryView', |
||||
components: { |
||||
SessionCategoryListWrapper, |
||||
SessionListNoCategoryWrapper |
||||
}, |
||||
props: { |
||||
resultSessions: Array, |
||||
}, |
||||
setup(props) { |
||||
const {resultSessions} = toRefs(props); |
||||
|
||||
let sessions = useResult(resultSessions, [], ({sessionRelUsers}) => { |
||||
let sessionList = []; |
||||
sessionRelUsers.edges.map(({node}) => { |
||||
const sessionExists = sessionList.findIndex(suSession => suSession._id === node.session._id) >= 0; |
||||
|
||||
if (!sessionExists) { |
||||
sessionList.push(node.session); |
||||
} |
||||
|
||||
return sessionExists ? null : node.session; |
||||
}); |
||||
return sessionList; |
||||
}); |
||||
|
||||
console.log('sessions'); |
||||
console.log(sessions); |
||||
|
||||
let categories = useResult(resultSessions, [], ({sessionRelUsers}) => { |
||||
let categoryList = []; |
||||
sessionRelUsers.edges.map(({node}) => { |
||||
if (isEmpty(node.session.category)) { |
||||
return; |
||||
} |
||||
const categoryExists = categoryList.findIndex(cat => cat._id === node.session.category._id) >= 0; |
||||
if (!categoryExists) { |
||||
if (!isEmpty(node.session.category)) { |
||||
categoryList.push(node.session.category); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
return categoryList; |
||||
}); |
||||
|
||||
const sessionsInCategory = ref([]); |
||||
|
||||
let sessionList = computed(() => sessions.value.filter(function(session) { |
||||
if (isEmpty(session.category)) { |
||||
//session.category.sessions.push(session.category); |
||||
return session; |
||||
} |
||||
})); |
||||
|
||||
let categoryWithSessions = computed(() => { |
||||
let categoriesIn = []; |
||||
sessions.value.forEach(function(session) { |
||||
if (!isEmpty(session.category)) { |
||||
if (categoriesIn[session.category._id] === undefined) { |
||||
categoriesIn[session.category._id] = []; |
||||
categoriesIn[session.category._id]['sessions'] = []; |
||||
} |
||||
categoriesIn[session.category._id]['sessions'].push(session); |
||||
} |
||||
}); |
||||
|
||||
return categoriesIn; |
||||
}); |
||||
|
||||
console.log(sessionList); |
||||
|
||||
return { |
||||
sessionList, |
||||
sessions, |
||||
sessionsInCategory, |
||||
categoryWithSessions, |
||||
categories |
||||
} |
||||
} |
||||
} |
||||
|
||||
</script> |
@ -0,0 +1,24 @@ |
||||
<template> |
||||
<div class="text-xl"> |
||||
<v-icon icon="mdi-folder"/> |
||||
{{ $t('No category') }} |
||||
</div> |
||||
<SessionListCategoryWrapper :sessions="sessions"/> |
||||
</template> |
||||
<script> |
||||
|
||||
import SessionListCategoryWrapper from '../../components/session/SessionListCategoryWrapper'; |
||||
|
||||
export default { |
||||
name: 'SessionListNoCategoryWrapper', |
||||
components: { |
||||
SessionListCategoryWrapper |
||||
}, |
||||
props: { |
||||
sessions: Array, |
||||
}, |
||||
setup() { |
||||
} |
||||
} |
||||
|
||||
</script> |
Loading…
Reference in new issue