From 26dfdeb127fec6cf1a617f07e6dfd8e2741c1831 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 1 Nov 2024 15:09:44 +0000 Subject: [PATCH] Improve filtering non nodes when categories selected --- lib/view.js | 6 +++++- public/js/utils.js | 24 +++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/view.js b/lib/view.js index 269ded8..301c9c0 100644 --- a/lib/view.js +++ b/lib/view.js @@ -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 } diff --git a/public/js/utils.js b/public/js/utils.js index 88b2164..fad060c 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -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) && @@ -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)