dupplicates nodes for multiple authors in LibraryList
This commit is contained in:
@@ -1,19 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="library-list">
|
<div class="library-list">
|
||||||
<div class="library-list-container" @click="onContainerClick">
|
<div class="library-list-container" @click="onContainerClick">
|
||||||
<div v-for="(parents, char) in filteredNodes" :key="char">
|
<div v-for="([char, nodes]) in filteredNodes" :key="char">
|
||||||
<h3>{{ char }}</h3>
|
<h3>{{ char }}</h3>
|
||||||
|
|
||||||
<div class="library-list-nodes-group">
|
<div class="library-list-nodes-group">
|
||||||
<node-view
|
<node-view
|
||||||
v-for="parent in parents" :key="parent.id"
|
v-for="node in nodes" :key="char + '-' + node.id"
|
||||||
:node="parent"
|
:node="node"
|
||||||
mode="card"
|
mode="card"
|
||||||
@click.native.capture="previewNode = parent"
|
@click.native.capture="previewNode = node"
|
||||||
:preview="previewNode === parent"
|
:preview="previewNode === node"
|
||||||
@open-node="$emit('open-node', $event)"
|
@open-node="$emit('open-node', $event)"
|
||||||
@open-child="$emit('open-node', { parentId: parent.id, ...$event })"
|
@open-child="$emit('open-node', { parentId: node.id, ...$event })"
|
||||||
:style="`--opacity: ${getStrangenessOpacity(strangeness, parent)};`"
|
:style="`--opacity: ${getStrangenessOpacity(strangeness, node)};`"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -46,14 +46,14 @@ export default {
|
|||||||
|
|
||||||
filteredNodes () {
|
filteredNodes () {
|
||||||
if (!this.orderedTextsDepart) return {}
|
if (!this.orderedTextsDepart) return {}
|
||||||
const nodesGroups = {}
|
const nodesGroups = []
|
||||||
const search = this.search.toLowerCase()
|
const search = this.search.toLowerCase()
|
||||||
Object.entries(this.orderedTextsDepart).forEach(([char, nodes]) => {
|
this.orderedTextsDepart.forEach(([char, nodes]) => {
|
||||||
const filteredNodes = nodes
|
const filteredNodes = nodes
|
||||||
.filter(node => tagsInNode(this.tags, node.tags))
|
.filter(node => tagsInNode(this.tags, node.tags))
|
||||||
.filter(node => searchInNode(search, node))
|
.filter(node => searchInNode(search, node))
|
||||||
if (filteredNodes.length) {
|
if (filteredNodes.length) {
|
||||||
nodesGroups[char] = filteredNodes
|
nodesGroups.push([char, filteredNodes])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return nodesGroups
|
return nodesGroups
|
||||||
|
|||||||
@@ -229,18 +229,28 @@ export default {
|
|||||||
orderedTextsDepart: (state, getters, rootState) => {
|
orderedTextsDepart: (state, getters, rootState) => {
|
||||||
const departIds = rootState.ids.depart
|
const departIds = rootState.ids.depart
|
||||||
if (departIds === undefined || rootState.nodes[departIds[0]] === undefined) return
|
if (departIds === undefined || rootState.nodes[departIds[0]] === undefined) return
|
||||||
return rootState.ids.depart.map(id => rootState.nodes[id]).sort((a, b) => {
|
const nodesDict = {}
|
||||||
if (!b.authors) return -1
|
for (const node of rootState.ids.depart.map(id => rootState.nodes[id])) {
|
||||||
if (!a.authors) return +1
|
if (!node.authors) {
|
||||||
if (a.authors[0].last_name < b.authors[0].last_name) return -1
|
if (!('~' in nodesDict)) nodesDict['~'] = []
|
||||||
if (a.authors[0].last_name > b.authors[0].last_name) return 1
|
nodesDict['~'].push(node)
|
||||||
return 0
|
} else {
|
||||||
}).reduce((dict, text) => {
|
node.authors.forEach((author, i) => {
|
||||||
const firstChar = text.authors ? text.authors[0].last_name[0].toUpperCase() : '~'
|
const firstChar = author.last_name[0].toUpperCase()
|
||||||
if (!(firstChar in dict)) dict[firstChar] = []
|
if (!(firstChar in nodesDict)) nodesDict[firstChar] = []
|
||||||
dict[firstChar].push(text)
|
nodesDict[firstChar].push({ last_name: author.last_name, node })
|
||||||
return dict
|
})
|
||||||
}, {})
|
}
|
||||||
|
}
|
||||||
|
return Object.entries(nodesDict).sort((a, b) => a[0] < b[0] ? -1 : 1).map(group => {
|
||||||
|
if (group[0] === '~') return group
|
||||||
|
return [group[0], group[1].sort((a, b) => {
|
||||||
|
const prev = a.last_name.toLowerCase()
|
||||||
|
const next = b.last_name.toLowerCase()
|
||||||
|
if (prev === next) return 0
|
||||||
|
return prev < next ? -1 : 1
|
||||||
|
}).map(node => node.node)]
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// LibraryTree
|
// LibraryTree
|
||||||
|
|||||||
Reference in New Issue
Block a user