Skip to content

Commit

Permalink
Merge pull request #18 from SlovakNationalGallery/MG-9-work-type-tree
Browse files Browse the repository at this point in the history
Work type tree in item detail
  • Loading branch information
rastislav-chynoransky committed May 23, 2024
2 parents 63f2618 + 644be47 commit ca0a56a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
12 changes: 12 additions & 0 deletions models/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { z } from 'zod'

import BaseModel from '@/models/_BaseModel'

type TreeNode = { label: string; path: string }

export default class Item extends BaseModel {
public static mapping = {}
public static endpoint = 'api/v1/items'
Expand Down Expand Up @@ -97,4 +99,14 @@ export default class Item extends BaseModel {
(image) => `https://img.webumenia.sk/preview/?path=${image}&size=800`
)
}

public get workTypeTrees(): TreeNode[][] {
return this.content.work_type.map((tree: string) => {
const parts: string[] = []
return tree.split('/').map((label: string): TreeNode => {
parts.push(label)
return { label, path: parts.join('/') }
})
})
}
}
22 changes: 13 additions & 9 deletions pages/items/[id]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,21 @@
</div>
</div>
</div>
<div class="flex gap-1 hover:bg-white hover:bg-opacity-40 px-2 py-1">
<div
v-if="item.workTypeTrees.length"
class="flex gap-1 hover:bg-white hover:bg-opacity-40 px-2 py-1"
>
<div class="font-bold w-1/3 shrink-0">výtvarný druh</div>
<div>
<NuxtLink
v-for="link in item.content.work_type"
:key="link"
:to="`/?work_type=${link}`"
class="underline"
>
{{ link }}
</NuxtLink>
<template v-for="(tree, i) in item.workTypeTrees" :key="i">
<template v-for="(node, j) in tree" :key="j">
<NuxtLink :to="`/?work_type=${node.path}`" class="underline">
{{ node.label }}
</NuxtLink>
<span class="px-1" v-if="j < tree.length - 1">›</span>
</template>
<br />
</template>
</div>
</div>
<div
Expand Down

0 comments on commit ca0a56a

Please sign in to comment.