Files
bandtoolv2/public/js/admin-live-filters.js
T

84 lines
2.9 KiB
JavaScript

/*! admin-live-filters.js — Vue 3 (CDN) */
(function() {
// Debounce helper
function debounce(fn, delay) {
let t; return function(...args) {
clearTimeout(t); t = setTimeout(() => fn.apply(this, args), delay);
};
}
// Mount for rounds list (index)
const elIndex = document.getElementById('admin-bewerbungen-index');
if (elIndex) {
const dataEl = document.getElementById('admin-bewerbungen-index-data');
const raw = dataEl ? JSON.parse(dataEl.textContent) : { items: [] };
const { createApp, computed, ref, watch } = Vue;
createApp({
setup() {
const q = ref('');
const activeOnly = ref(false);
const items = ref(raw.items || []);
const filtered = computed(() => {
const needle = q.value.trim().toLowerCase();
return items.value.filter(it => {
const text = ((it.name || '') + ' ' + (it.period || '')).toLowerCase();
const okText = !needle || text.includes(needle);
const okActive = !activeOnly.value || !!it.active;
return okText && okActive;
});
});
const clear = () => { q.value = ''; activeOnly.value = false; };
return { q, activeOnly, items, filtered, clear };
}
}).mount('#admin-bewerbungen-index');
}
// Mount for applications table (show)
const elShow = document.getElementById('admin-bewerbungen-show');
if (elShow) {
const dataEl = document.getElementById('admin-bewerbungen-show-data');
const raw = dataEl ? JSON.parse(dataEl.textContent) : { items: [] };
const { createApp, computed, ref } = Vue;
createApp({
setup() {
const q = ref('');
const status = ref('');
const dateFrom = ref('');
const dateTo = ref('');
const items = ref(raw.items || []);
const filtered = computed(() => {
const needle = q.value.trim().toLowerCase();
const from = dateFrom.value ? new Date(dateFrom.value + 'T00:00:00') : null;
const to = dateTo.value ? new Date(dateTo.value + 'T23:59:59') : null;
return items.value.filter(it => {
// text match
const text = ((it.band || '') + ' ' + (it.email || '')).toLowerCase();
const okText = !needle || text.includes(needle);
// status match
const okStatus = !status.value || it.status === status.value;
// date range match (created_at ISO string expected)
const t = it.created_at ? new Date(it.created_at) : null;
const okFrom = !from || (t && t >= from);
const okTo = !to || (t && t <= to);
return okText && okStatus && okFrom && okTo;
});
});
const reset = () => { q.value = ''; status.value=''; dateFrom.value=''; dateTo.value=''; };
return { q, status, dateFrom, dateTo, items, filtered, reset };
}
}).mount('#admin-bewerbungen-show');
}
})();