Группы: цвет филиала на карточке группы
This commit is contained in:
+27
-1
@@ -112,6 +112,21 @@ async function loadGroups() {
|
||||
renderGroups();
|
||||
}
|
||||
|
||||
function hexToRgb(hex) {
|
||||
const m = /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/.exec(hex);
|
||||
return m ? [parseInt(m[1], 16), parseInt(m[2], 16), parseInt(m[3], 16)] : null;
|
||||
}
|
||||
|
||||
function branchColor(value) {
|
||||
const raw = String(value || '').trim();
|
||||
return /^#[0-9a-fA-F]{6}$/.test(raw) ? raw.toLowerCase() : null;
|
||||
}
|
||||
|
||||
function branchBorderColor(value) {
|
||||
const c = hexToRgb(branchColor(value));
|
||||
return c ? `rgba(${c[0]},${c[1]},${c[2]},0.35)` : null;
|
||||
}
|
||||
|
||||
function renderGroups() {
|
||||
const list = document.getElementById('groupList');
|
||||
const groups = allGroups.filter(groupMatchesFilters);
|
||||
@@ -125,8 +140,19 @@ function renderGroups() {
|
||||
const canDelete = admin || (currentUser && Number(g.tutor_id) === Number(currentUser.id));
|
||||
const schedSet = g.day_of_week != null && g.time_start && g.time_end;
|
||||
const hidden = !!g.hidden;
|
||||
const branch = branchesCache.find(b => b.id === g.branch_id);
|
||||
const borderColor = branch ? branchBorderColor(branch.color) : null;
|
||||
const topColor = branch ? branchColor(branch.color) : null;
|
||||
const styleParts = [];
|
||||
if (hidden) styleParts.push('opacity:.55');
|
||||
if (borderColor) styleParts.push(`border-color:${borderColor}`);
|
||||
if (topColor) {
|
||||
styleParts.push(`border-top-color:${topColor}`);
|
||||
styleParts.push('border-top-width:2px');
|
||||
}
|
||||
const styleAttr = styleParts.length ? ` style="${styleParts.join('; ')}"` : '';
|
||||
return `
|
||||
<div class="group-card${hidden ? ' group-hidden' : ''}" data-group-id="${g.id}"${hidden ? ' style="opacity:.55"' : ''}>
|
||||
<div class="group-card${hidden ? ' group-hidden' : ''}" data-group-id="${g.id}"${styleAttr}>
|
||||
${g.cover_path
|
||||
? `<img class="group-cover" src="${thumbSrc(g.cover_path)}" data-img="${API}${g.cover_path}" loading="lazy" decoding="async" alt="">`
|
||||
: `<div class="group-cover empty-cover">📷</div>`}
|
||||
|
||||
Reference in New Issue
Block a user