Skip to content

Commit

Permalink
Improve filtering non nodes when categories selected
Browse files Browse the repository at this point in the history
  • Loading branch information
knolleary committed Nov 1, 2024
1 parent d79471e commit 26dfdeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,23 @@ module.exports = {
collectionOwners = data[0].gitOwners
collectionItems = data[0].items || []
} else {
let includeCategories = true
if (query.type) {
if (typeof query.type === 'string' && query.type !== 'all') {
findQuery.type = query.type
includeCategories = (findQuery.type === 'node')
} else if (Array.isArray(query.type)) {
if (query.type.length === 1) {
findQuery.type = query.type[0]
includeCategories = (findQuery.type === 'node')
} else if (query.type.length === 2) {
findQuery.type = { $in: query.type }
includeCategories = query.type.includes('node')
}// if length === 0 or 3, that is the same as 'all'
}
}
// const typeNode = !findQuery.type || findQuery.type === 'node' || (Array.isArray(query.type) && query.type.indexOf('node') > -1)
if (query.category) {
if (includeCategories && query.category) {
const categories = Array.isArray(query.category) ? query.category : [query.category]
findQuery.categories = { $in: categories }
countQuery.categories = { $in: categories }
Expand Down
24 changes: 13 additions & 11 deletions public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const utils = (function () {
if (!thingUrl) {
thingUrl = '/things'
let query = thingList.find('form').serialize()
console.log(query)
// console.log(query)
let components = query.split('&')
components = components.filter(function (part) {
return !/(ignoreQueryParams|seedType|seedSort)/.test(part) &&
Expand All @@ -102,17 +102,19 @@ const utils = (function () {
if (updateUrl) {
if (history.pushState) {
let historyUrl = thingUrl.split('?')[1]
// Need to remove username=xyz/collection=xyz/category=xyz if present
// If collection is present, remove type= as well
if (/collection=/.test(historyUrl)) {
historyUrl = historyUrl.replace(/&?type=[^&]+/g, '')
if (historyUrl) {
// Need to remove username=xyz/collection=xyz/category=xyz if present
// If collection is present, remove type= as well
if (/collection=/.test(historyUrl)) {
historyUrl = historyUrl.replace(/&?type=[^&]+/g, '')
}
historyUrl = historyUrl.replace(/&?(username|collection)=[^&]+/g, '').replace(/^&/, '')
if (historyUrl === 'page=1') {
historyUrl = ''
}
historyUrl = location.pathname + (historyUrl.length > 0 ? ('?' + historyUrl) : '')
window.history.pushState({}, '', historyUrl)
}
historyUrl = historyUrl.replace(/&?(username|collection)=[^&]+/g, '').replace(/^&/, '')
if (historyUrl === 'page=1') {
historyUrl = ''
}
historyUrl = location.pathname + (historyUrl.length > 0 ? ('?' + historyUrl) : '')
window.history.pushState({}, '', historyUrl)
}
}
$(list).children(':not(.gistbox-placeholder)').css('opacity', 0.3)
Expand Down

0 comments on commit 26dfdeb

Please # to comment.