From ed57c386db34d8693ca75311972d0929ebe5f488 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 01 Jun 2026 22:23:19 +0000
Subject: [PATCH] =Added some more Schema classes, allowed for override of  array in outputSchema for complex schema, as for timeline post types

---
 src/feed/view.js |   91 +++++++++++++++++++++++++++------------------
 1 files changed, 55 insertions(+), 36 deletions(-)

diff --git a/src/feed/view.js b/src/feed/view.js
index 87e79b9..5abe47d 100644
--- a/src/feed/view.js
+++ b/src/feed/view.js
@@ -9,7 +9,7 @@
 		this.templates = window.jvbTemplates;
 
 		this.config = {
-			source: '',
+			contextId: '',
 			context: '',
 			highlight: null,
 			gallery: false,
@@ -53,10 +53,13 @@
 			filterTrigger: '[data-filter]',
 			filters: {
 				actions: 	'.filter-actions .toggle-text',
-				container:	'.filters',
+				container:	'.all-filters',
+				showing:	'.all-filters summary .current',
 				content: 	'[data-filter="content"]',
+				ordering:	'.ordering',
 				orderby: 	'[data-filter="orderby"]',
 				order: 		'[data-filter="order"]',
+				orderWrap:  '.order-direction',
 				match: 		'[data-filter="match"]',
 				favourites: '[data-filter="favourites"]',
 				taxonomy: 	'[data-filter^="taxonomy"]',
@@ -74,29 +77,41 @@
 		this.ui.buttons.refresh = document.querySelector(this.selectors.buttons.refresh);
 
 		//Add content and taxonomies
-		this.ui.content = this.ui.filters.container.querySelectorAll('[name="content"]');
-		if (this.ui.content.length === 0) this.ui.content = false;
-		this.ui.taxonomies = this.ui.filters.container.querySelectorAll('[data-taxonomy]');
-		if (this.ui.taxonomies.length === 0) this.ui.taxonomies = false;
-		this.ui.orderbyWrap = this.ui.filters.container.querySelector('[data-for-order]');
-		if (this.ui.orderbyWrap.length === 0) this.ui.orderbyWrap = false;
-		this.ui.order = this.ui.filters.container.querySelectorAll('[data-filter="order"]');
-		if (this.ui.order.length === 0) this.ui.order = false;
-		this.ui.orderby = this.ui.filters.container.querySelectorAll('[data-filter="orderby"]');
-		if (this.ui.orderby.length === 0) this.ui.orderby = false;
+		let getAll = ['content','orderby','order','taxonomy'];
+		getAll.forEach(item => {
+			let items = this.ui.filters.container.querySelectorAll(this.selectors.filters[item]);
+			this.ui[item] = Array.from(items);
+		});
 
-		this.orderbyFilters = (this.ui.orderby)
-			? Array.from(this.ui.orderby).map(o => o.value)
-			: [];
-
-		this.contentTypes = (this.ui.content)
-			? Array.from(this.ui.content).map(c => c.value)
+		this.contentTypes = (this.ui.content.length > 0)
+			? this.ui.content.map(c => c.value)
 			: [this.container.dataset.content];
 		this.taxonomies = (this.ui.taxonomies?.length > 0)
 			? Array.from(this.ui.taxonomies).map(t => t.dataset.taxonomy)
 			: [];
 	}
 
+	/**
+	 *
+	 * @param {string} item
+	 */
+	getChecked(item) {
+		if (!['content', 'orderby','order'].includes(item)) {
+			console.log('Invalid item to check: ', item);
+		}
+
+		let items = this.ui[item];
+		if (!items) {
+			return;
+		}
+
+		let checked = items.filter(i => i.checked);
+		if (item === 'content' && checked.length > 0) {
+			this.updateContentFor(checked[0].value);
+		}
+		return checked.length === 0 ? items[0].value : checked[0].value;
+	}
+
 	initListeners() {
 		this.popStateHandler	= this.handlePopState.bind(this);
 		this.clickHandler		= this.handleClick.bind(this);
@@ -110,15 +125,16 @@
 	initFilters() {
 		this.allowedFilters = ['content', 'order', 'orderby', 'favourites', 'match'];
 		let defaults = {
-			content:	this.contentTypes[0],
-			orderby:	'date',
-			order:		'desc',
+			content:	this.getChecked('content'),
+			orderby:	this.getChecked('orderby'),
+			order:		this.getChecked('order'),
 			page:		1,
 		};
 		if (this.config.context) defaults.context = this.config.context;
-		if (this.config.source) defaults.source = this.config.source;
+		if (this.config.contextId) defaults.contextId = this.config.contextId;
 
 		this.filters = defaults;
+
 		this.defaults = {...defaults};
 	}
 	updateFilterUI() {
@@ -247,7 +263,7 @@
 	}
 
 	getFieldId(taxonomy) {
-		return this.selector.getFieldId(Array.from(this.ui.taxonomies).filter(tax => tax.dataset.taxonomy === taxonomy)[0]??null);
+		return this.selector.getFieldId(this.ui.taxonomies.filter(tax => tax.dataset.taxonomy === taxonomy)[0]??null);
 	}
 	removeSelectedTerm(button) {
 		const termId = parseInt(button.dataset.id);
@@ -282,6 +298,8 @@
 			this.ui.taxonomies,
 			this.ui.orderby
 		];
+
+		this.ui.filters.showing.textContent = this.ui.content.filter(c => c.value === content)[0].dataset.label;
 		checkIt.forEach(check => {
 			if (!check) return;
 			check.forEach(button => {
@@ -294,19 +312,19 @@
 		});
 	}
 	updateOrderOptions(order) {
-		if (this.ui.orderbyWrap) {
-			let options = this.ui.orderbyWrap.dataset.forOrder.split(',')??[];
-			this.ui.orderbyWrap.hidden = !options.includes(order);
+		if (this.ui.filters.orderWrap) {
+			let options = this.ui.filters.orderWrap.dataset.forOrder.split(',')??[];
+			this.ui.filters.orderWrap.hidden = !options.includes(order);
 		}
 	}
 
 	updateFilterControls() {
-		const isHidden = Object.keys(this.taxFilters).length === 0;
+		const keys = Object.keys(this.taxFilters);
 		if (this.ui.buttons.clearFilters) {
-			this.ui.buttons.clearFilters.hidden = isHidden;
+			this.ui.buttons.clearFilters.hidden = keys.length === 0;
 		}
 		if (this.ui.filters.actions) {
-			this.ui.filters.actions.hidden = isHidden;
+			this.ui.filters.actions.hidden = keys.length <= 1;
 		}
 	}
 
@@ -338,7 +356,7 @@
 		this.updateFilterControls();
 	}
 	getTaxonomyIcon(taxonomy) {
-		let iconButton = Array.from(this.ui.taxonomies)
+		let iconButton = this.ui.taxonomies
 			.find(t => t.dataset.taxonomy === taxonomy);
 		return iconButton?.dataset.icon.trim() || 'tag';
 	}
@@ -353,7 +371,7 @@
 
 	processCachedFilters() {
 		Object.keys(this.filters).forEach(filter => {
-			let cached = this.cache.get(`${this.config.source}_${this.config.context}_${filter}`);
+			let cached = this.cache.get(`${this.config.contextId}_${this.config.context}_${filter}`);
 			if (cached && cached !== this.filters[filter]) {
 				this.filters[filter] = cached;
 			}
@@ -415,7 +433,7 @@
 
 	saveToCacheFilters() {
 		Object.keys(this.store.filters).forEach(filter => {
-			const cacheKey = `${this.config.source}_${this.config.context}_${filter}`;
+			const cacheKey = `${this.config.contextId}_${this.config.context}_${filter}`;
 
 			if (this.store.filters[filter] !== this.defaults[filter]) {
 				this.cache.set(cacheKey, this.store.filters[filter]);
@@ -424,7 +442,7 @@
 			}
 		});
 
-		const taxCacheKey = `${this.config.source}_${this.config.context}_taxonomy`;
+		const taxCacheKey = `${this.config.contextId}_${this.config.context}_taxonomy`;
 		if (Object.keys(this.taxFilters).length > 0) {
 			this.cache.set(taxCacheKey, this.taxFilters);
 		} else {
@@ -443,10 +461,11 @@
 		}
 	}
 	initStore() {
-		let extraOrderby = this.orderbyFilters.filter(v => !['date','modified','title','random'].includes(v));
+		let extraOrderby = this.ui.orderby.filter(v => !['date','date_modified','title','random'].includes(v.value));
+
 		let extraIndexes = [];
 		extraOrderby.forEach(orderby =>{
-			extraIndexes.push({name:orderby, keyPath: orderby});
+			extraIndexes.push({name:orderby.value, keyPath: orderby.value});
 		});
 		const store = window.jvbStore.register(
 			'feed',
@@ -672,7 +691,7 @@
 			setup({el, refs, manyRefs, data}) {
 				el.dataset.id = data.id;
 				el.dataset.taxonomy = data.taxonomy;
-				if (refs.icon) refs.icon.className = `icon icon=${data.icon}`;
+				if (refs.icon) refs.icon.className = `icon icon-${data.icon}`;
 				if (refs.span) refs.span.textContent = window.decodeHTMLEntities(data.name);
 			}
 		});

--
Gitblit v1.10.0