fix(admin): replicate reference advanced-filter settings page 1:1
- Rewrite post_list/filter schema (PHP + JS) with the reference theme's
field set, order, defaults and dependencies; topics fields excluded
(no topics taxonomy), AKSRT private filter_* toggles dropped
- Support dynamic checkbox options in AksField (options as formData key)
so cat_custom_filter.custom_filters lists the custom_filter dimensions
- Map PostDisplay filter settings to the new keys without legacy fallback;
cat_custom_filter now carries lists/dropdown fieldsets and array filters
- Wire the archive chain to reference semantics: cat_custom_filter
overrides per-category filter projects, custom_filter_show gates the
default display, dimension chip groups render on category/tag archives
- Filter archive queries (main query + AJAX endpoint) by _aksrt_cf_{key}
meta with exact-quoted LIKE matching
- Add advanced-filter settings reference contract test
This commit is contained in:
1 parent
4d6b2c6045
commit
a8060fa71d
16 files changed
+635
-154
No files matched your search
@@ -22,6 +22,7 @@
|
||||
var state = {
|
||||
filter_cat: "",
|
||||
filter_tag: "",
|
||||
custom: {},
|
||||
sort: "date",
|
||||
page: 1
|
||||
};
|
||||
@@ -32,6 +33,14 @@
|
||||
if (activeTag) state.filter_tag = activeTag.dataset.filterTag || "";
|
||||
var activeSort = bar.querySelector("[data-filter-sort].is-active");
|
||||
if (activeSort) state.sort = activeSort.dataset.filterSort || "date";
|
||||
// 自定义高级筛选维度:以当前 URL 参数为准(SSR active 状态与 URL 一致)。
|
||||
if (bar.querySelector("[data-filter-dim]")) {
|
||||
new URLSearchParams(window.location.search).forEach(function (value, key) {
|
||||
if (bar.querySelector('[data-filter-dim="' + key + '"]')) {
|
||||
state.custom[key] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildUrl() {
|
||||
var params = new URLSearchParams();
|
||||
@@ -39,6 +48,7 @@
|
||||
params.set("term_id", String(termId));
|
||||
if (state.filter_cat) params.set("filter_cat", state.filter_cat);
|
||||
if (state.filter_tag) params.set("filter_tag", state.filter_tag);
|
||||
if (Object.keys(state.custom).length) params.set("custom_filter", JSON.stringify(state.custom));
|
||||
|
||||
params.set("sort", state.sort || "date");
|
||||
params.set("page", String(state.page));
|
||||
@@ -55,6 +65,10 @@
|
||||
bar.querySelectorAll("[data-filter-sort]").forEach(function (el) {
|
||||
el.classList.toggle("is-active", (el.dataset.filterSort || "date") === state.sort);
|
||||
});
|
||||
bar.querySelectorAll("[data-filter-dim]").forEach(function (el) {
|
||||
var current = state.custom[el.dataset.filterDim] || "";
|
||||
el.classList.toggle("is-active", (el.dataset.filterDimValue || "") !== "" && (el.dataset.filterDimValue || "") === current);
|
||||
});
|
||||
}
|
||||
|
||||
function showLoading() {
|
||||
@@ -110,8 +124,14 @@
|
||||
url.searchParams.delete("paged");
|
||||
url.searchParams.delete("aksrt_filter_cat");
|
||||
url.searchParams.delete("aksrt_filter_tag");
|
||||
bar.querySelectorAll("[data-filter-dim]").forEach(function (el) {
|
||||
url.searchParams.delete(el.dataset.filterDim);
|
||||
});
|
||||
if (state.filter_cat) url.searchParams.set("aksrt_filter_cat", state.filter_cat);
|
||||
if (state.filter_tag) url.searchParams.set("aksrt_filter_tag", state.filter_tag);
|
||||
Object.keys(state.custom).forEach(function (key) {
|
||||
url.searchParams.set(key, state.custom[key]);
|
||||
});
|
||||
if (state.sort) url.searchParams.set("orderby", state.sort);
|
||||
if (state.page > 1) url.searchParams.set("paged", String(state.page));
|
||||
history.pushState({ aksrtArchive: true, state: Object.assign({}, state) }, "", url.toString());
|
||||
@@ -123,7 +143,7 @@
|
||||
}
|
||||
|
||||
bar.addEventListener("click", function (e) {
|
||||
var chip = e.target.closest("[data-filter-cat], [data-filter-tag], [data-filter-sort]");
|
||||
var chip = e.target.closest("[data-filter-cat], [data-filter-tag], [data-filter-sort], [data-filter-dim]");
|
||||
if (!chip) return;
|
||||
e.preventDefault();
|
||||
|
||||
@@ -149,6 +169,18 @@
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (chip.dataset.filterDim !== undefined) {
|
||||
var dimKey = chip.dataset.filterDim;
|
||||
var dimValue = chip.dataset.filterDimValue || "";
|
||||
if (dimValue !== (state.custom[dimKey] || "")) {
|
||||
if (dimValue === "") {
|
||||
delete state.custom[dimKey];
|
||||
} else {
|
||||
state.custom[dimKey] = dimValue;
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
state.page = 1;
|
||||
|
||||
Reference in new issue
Block a user