fix #489: add vpd target filtering

This commit is contained in:
devmrko
2026-06-26 10:13:45 +09:00
parent a906dd0128
commit f39cc49021
4 changed files with 274 additions and 3 deletions

View File

@@ -492,9 +492,138 @@ function initPermissionWizard() {
activatePermissionWizardStep(wizard, Number(wizard.dataset.currentStep || '1'));
}
const backofficeSupportObjectPatterns = [
/^CB_APP_/,
/^CB_PERMISSION(_|$)/,
/^CB_PROTECTED_/,
/^CB_USER_/,
/^CB_GROUP_/,
/^CB_ORDS_/,
/^CB_AGENT_BEARER_/,
/^CB_BACKOFFICE_/,
/^APP_(GROUP|ROLE|USER)$/,
/^DB_SOURCE$/,
/^PERMISSION$/,
/^USER_GROUP$/
];
function isBackofficeSupportObject(objectName) {
const normalized = (objectName || '').trim().toUpperCase();
return backofficeSupportObjectPatterns.some((pattern) => pattern.test(normalized));
}
function initVpdTargetFilters() {
const controls = document.querySelector('[data-vpd-target-controls]');
const body = document.querySelector('[data-vpd-target-body]');
if (!controls || !body) {
return;
}
const rows = Array.from(body.querySelectorAll('[data-vpd-target-row]')).map((row) => ({
row,
detail: row.nextElementSibling?.matches('[data-vpd-target-detail]') ? row.nextElementSibling : null,
object: (row.dataset.object || '').toUpperCase(),
objectName: (row.dataset.objectName || '').toUpperCase(),
objectType: (row.dataset.objectType || '').toUpperCase(),
vpdApplied: row.dataset.vpdApplied || 'false',
protectedObject: row.dataset.protectedObject || 'false'
}));
const search = controls.querySelector('[data-vpd-target-search]');
const type = controls.querySelector('[data-vpd-target-type]');
const vpd = controls.querySelector('[data-vpd-target-vpd]');
const protectedObject = controls.querySelector('[data-vpd-target-protected]');
const includeSupport = controls.querySelector('[data-vpd-target-include-support]');
const pageSize = controls.querySelector('[data-vpd-target-page-size]');
const visibleCount = controls.querySelector('[data-vpd-target-visible]');
const matchedCount = controls.querySelector('[data-vpd-target-matched]');
const totalCount = controls.querySelector('[data-vpd-target-total]');
const reset = controls.querySelector('[data-vpd-target-reset]');
const empty = document.createElement('tr');
empty.className = 'vpd-target-empty-runtime';
empty.innerHTML = '<td colspan="7" class="text-muted">필터 조건에 맞는 TABLE/VIEW가 없습니다.</td>';
body.appendChild(empty);
const matchesFilters = (entry) => {
const query = (search?.value || '').trim().toUpperCase();
if (query && !entry.object.includes(query)) {
return false;
}
if (type?.value && entry.objectType !== type.value) {
return false;
}
if (vpd?.value && entry.vpdApplied !== vpd.value) {
return false;
}
if (protectedObject?.value && entry.protectedObject !== protectedObject.value) {
return false;
}
if (!includeSupport?.checked && isBackofficeSupportObject(entry.objectName)) {
return false;
}
return true;
};
const applyFilters = () => {
const maxRows = pageSize?.value === 'ALL' ? Number.POSITIVE_INFINITY : Number(pageSize?.value || 50);
let matched = 0;
let visible = 0;
rows.forEach((entry) => {
const matchedRow = matchesFilters(entry);
if (matchedRow) {
matched += 1;
}
const show = matchedRow && visible < maxRows;
if (show) {
visible += 1;
}
entry.row.hidden = !show;
if (entry.detail) {
entry.detail.hidden = !show;
}
});
empty.hidden = matched !== 0;
if (visibleCount) {
visibleCount.textContent = String(visible);
}
if (matchedCount) {
matchedCount.textContent = String(matched);
}
if (totalCount) {
totalCount.textContent = String(rows.length);
}
};
[search, type, vpd, protectedObject, includeSupport, pageSize].forEach((control) => {
control?.addEventListener(control === search ? 'input' : 'change', applyFilters);
});
reset?.addEventListener('click', () => {
if (search) {
search.value = '';
}
if (type) {
type.value = '';
}
if (vpd) {
vpd.value = '';
}
if (protectedObject) {
protectedObject.value = '';
}
if (includeSupport) {
includeSupport.checked = false;
}
if (pageSize) {
pageSize.value = '50';
}
applyFilters();
search?.focus();
});
applyFilters();
}
document.addEventListener('DOMContentLoaded', () => {
initPersistentMenus();
renderMarkdownViews();
initVpdTargetFilters();
const master = document.getElementById('userRoleMaster');
if (master) {
master.addEventListener('change', filterUserRoleDetail);