add search filters to LibraryList and LibraryMap
This commit is contained in:
@@ -20,7 +20,8 @@ export default {
|
||||
nodeDepartId: undefined,
|
||||
trees: {},
|
||||
mode: undefined,
|
||||
nodebook: undefined
|
||||
nodebook: undefined,
|
||||
search: ''
|
||||
},
|
||||
|
||||
mutations: {
|
||||
@@ -67,6 +68,10 @@ export default {
|
||||
|
||||
'SET_NODE_DEPART_ID' (state, id) {
|
||||
state.nodeDepartId = id
|
||||
},
|
||||
|
||||
'SET_SEARCH' (state, str) {
|
||||
state.search = str
|
||||
}
|
||||
},
|
||||
|
||||
@@ -165,7 +170,9 @@ export default {
|
||||
},
|
||||
|
||||
getters: {
|
||||
mode: (state) => state.mode,
|
||||
mode: state => state.mode,
|
||||
nodeDepartId: state => state.nodeDepartId,
|
||||
search: state => state.search,
|
||||
|
||||
nodebook: (state, getters, rootState) => {
|
||||
if (!state.nodebook) return []
|
||||
|
||||
@@ -28,6 +28,8 @@ export const VARIANT_IDS = Object.fromEntries(
|
||||
Object.entries(ID_VARIANTS).map(([key, value]) => [value, key])
|
||||
)
|
||||
|
||||
export const SEARCH_KEYS = ['content', 'title', 'preTitle', 'authors']
|
||||
|
||||
|
||||
export function parseNodesQueryParams ({ mode, nodes = [] }) {
|
||||
let nodebook = typeof nodes === 'string' ? [nodes] : nodes
|
||||
@@ -112,3 +114,20 @@ export function buildTree (treeData, nodesData) {
|
||||
links
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function searchInNode (search, node) {
|
||||
if (!search) return true
|
||||
for (const key of SEARCH_KEYS) {
|
||||
if (!node[key]) continue
|
||||
let match = false
|
||||
if (key === 'authors') {
|
||||
match = node[key].some(author => author.name.toLowerCase().includes(search))
|
||||
} else {
|
||||
console.log(node[key].toLowerCase(), search)
|
||||
match = node[key].toLowerCase().includes(search)
|
||||
}
|
||||
if (match) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user