1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-28 08:03:07 +03:00
guide/front/client/components/Categories.vue

129 lines
3.4 KiB
Vue
Raw Normal View History

<template>
2018-09-12 23:09:34 +03:00
<v-container grid-list-md>
<v-layout
row
wrap
justify-space-between
>
<v-flex
class="mr-3 mt-3"
2018-09-12 23:09:34 +03:00
column
xs12
sm5
md3
lg3
xl1
v-for="(groupCategories, groupName, index) in groups"
:key="index"
>
2018-09-12 23:09:34 +03:00
<div class="category-group">
2018-09-16 17:51:10 +03:00
<h4 class="mb-2 display-1 font-weight-black">
{{ groupName }}
</h4>
2018-09-13 23:26:52 +03:00
<a-link
2018-09-12 23:09:34 +03:00
class="category-title"
2018-09-13 23:26:52 +03:00
openInNewTab
2018-09-16 16:32:35 +03:00
v-for="category in groupCategories[CategoryStatus.finished]"
:key="category.uid"
:url="`https://guide.aelve.com/haskell/${getCategoryUrl(category)}`"
>
<h6
class="ml-2 subheading font-weight-bold"
>
{{ category.title }}
</h6>
</a-link>
2018-09-16 17:51:10 +03:00
2018-09-16 16:32:35 +03:00
<h6
class="ml-2 body-2 font-weight-bold"
v-if="groupCategories[CategoryStatus.inProgress]"
>
In progress
</h6>
<a-link
class="category-title ml-3"
openInNewTab
v-for="category in groupCategories[CategoryStatus.inProgress]"
:key="category.uid"
:url="`https://guide.aelve.com/haskell/${getCategoryUrl(category)}`"
>
<h6
class="ml-2 subheading font-weight-bold"
>
{{ category.title }}
</h6>
</a-link>
2018-09-16 17:51:10 +03:00
2018-09-16 16:32:35 +03:00
<h6
class="ml-2 body-2 font-weight-bold"
v-if="groupCategories[CategoryStatus.toBeWritten]"
2018-09-16 16:32:35 +03:00
>
To be written
</h6>
<a-link
class="category-title ml-3"
openInNewTab
v-for="category in groupCategories[CategoryStatus.toBeWritten]"
:key="category.uid"
2018-09-13 23:26:52 +03:00
:url="`https://guide.aelve.com/haskell/${getCategoryUrl(category)}`"
2018-09-12 23:09:34 +03:00
>
<h6
class="ml-2 subheading font-weight-bold"
>
{{ category.title }}
2018-09-12 23:09:34 +03:00
</h6>
2018-09-13 23:26:52 +03:00
</a-link>
</div>
</v-flex>
</v-layout>
</v-container>
</template>
<script lang="ts">
import _groupBy from 'lodash/groupBy'
2018-09-12 23:23:07 +03:00
import _toKebabCase from 'lodash/kebabCase'
import Vue from 'vue'
import Component from 'vue-class-component'
2018-09-16 16:32:35 +03:00
import { ICategory, CategoryStatus } from 'client/service/Category'
@Component
2018-09-12 23:09:34 +03:00
export default class Categories extends Vue {
2018-09-16 16:32:35 +03:00
CategoryStatus = CategoryStatus
2018-09-12 23:09:34 +03:00
// TODO add type for store
async asyncData({ store }) {
return store.dispatch('category/loadCategoryList')
}
// TODO create state getter and replace to it
get categories() {
return this.$store.state.category.categoryList
}
2018-09-12 23:09:34 +03:00
get groups() {
2018-09-16 16:57:45 +03:00
const groupedByGroupName: object = _groupBy(this.categories, 'group')
2018-09-16 16:32:35 +03:00
Object.entries(groupedByGroupName).forEach(([key, value]: [string, ICategory[]]) => {
groupedByGroupName[key] = this.groupByCategoriesByStatus(value)
})
return groupedByGroupName
}
groupByCategoriesByStatus(categories: ICategory[]): object {
return _groupBy(categories, 'status')
}
2018-09-12 23:23:07 +03:00
getCategoryUrl(category: ICategory): string {
return `${_toKebabCase(category.title)}-${category.uid}`
}
}
</script>
2018-09-12 23:09:34 +03:00
<style scoped>
.category-group {
text-align: left;
}
2018-09-12 23:09:34 +03:00
.category-title {
2018-09-12 23:51:13 +03:00
display: block;
line-height: 1.2;
2018-09-12 23:09:34 +03:00
}
2018-09-13 23:26:52 +03:00
.category-title:not(:last-child) {
margin-bottom: 5px;
2018-09-12 23:09:34 +03:00
}
</style>