фикс статистики
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
dv 2026-04-15 10:24:10 +03:00
parent 621c6407fe
commit 1ea444791b
2 changed files with 19 additions and 12 deletions

View file

@ -1,7 +1,8 @@
{
"permissions": {
"allow": [
"Bash(node -e ':*)"
"Bash(node -e ':*)",
"Bash(grep -n \"allData\\\\s*=\\\\|allData\\\\.push\\\\|task:.*lastComment\\\\|{task,\\\\|{ task,\" /c/Users/Professional/Documents/VSCode/intra_git/intradesk-monitor/public/js/ui.js)"
]
}
}

View file

@ -839,18 +839,24 @@ function renderClientUsersCard() {
const wrap = document.getElementById('stats-client-users-wrap');
if (!wrap) return;
// Собираем: клиент → { total, users: { username → count } }
// _clientname — организация (из справочника по clientid)
// clientname — сырое поле API: имя контакта/заявителя когда _clientname задан,
// либо имя организации если clientid не задан
// Собираем: организация → { total, users: { contactName → count } }
const cMap = {};
// Сначала добавляем всех клиентов, которые есть в allData, с нулями
allData.forEach(({task: t}) => {
const name = t._clientname || t.clientname || 'Неизвестно';
if (!cMap[name]) cMap[name] = { total: 0, users: {} };
});
allData.forEach(({task: t}) => {
const name = t._clientname || t.clientname || 'Неизвестно';
cMap[name].total++;
const user = t.username || '—';
cMap[name].users[user] = (cMap[name].users[user] || 0) + 1;
allData.forEach((item) => {
const t = item.task;
const org = t._clientname || t.clientname || 'Неизвестно';
// Контакт: clientname когда есть отдельное _clientname (org), иначе lastComment автор
let contact;
if (t._clientname && t.clientname && t._clientname !== t.clientname) {
contact = t.clientname;
} else {
contact = item.lastComment?.username || t.updatedby || '—';
}
if (!cMap[org]) cMap[org] = { total: 0, users: {} };
cMap[org].total++;
cMap[org].users[contact] = (cMap[org].users[contact] || 0) + 1;
});
const entries = Object.entries(cMap).sort((a, b) => b[1].total - a[1].total);