1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189import './style.css'
import { areas, people, roleDefinitions } from './data.js'
const container = document.getElementById('raci-container');
const legendContainer = document.getElementById('legend-grid');
const viewToggle = document.getElementById('view-toggle');
const personFilter = document.getElementById('person-filter');
let currentView = 'grid';
let currentPersonFilter = 'all';
function getFilteredAreas() {
const filtered = currentPersonFilter === 'all'
? [...areas]
: areas.filter(area =>
area.r.includes(currentPersonFilter) ||
area.a.includes(currentPersonFilter) ||
area.c.includes(currentPersonFilter) ||
area.i.includes(currentPersonFilter)
);
return filtered.sort((a, b) => a.label.localeCompare(b.label));
}
function render() {
if (currentView === 'grid') renderGrid();
else renderTable();
}
function renderGrid() {
container.className = 'view-grid';
const filtered = getFilteredAreas();
if (filtered.length === 0) {
container.innerHTML = `<div style="grid-column: 1/-1; text-align: center; padding: 4rem; color: var(--text-muted);">No areas found for this person.</div>`;
return;
}
container.innerHTML = filtered.map(area => `
<article class="raci-card">
<h3>${area.label} ${area.tbd ? '<span style="font-size: 0.7rem; vertical-align: middle; background: #e2e8f0; color: #475569; padding: 2px 6px; border-radius: 4px; margin-left: 8px; font-weight: 600;">PENDING</span>' : ''}</h3>
${renderRoleGroup('Responsible', area.r, 'r')}
${renderRoleGroup('Accountable', area.a, 'a')}
${renderRoleGroup('Consulted', area.c, 'c')}
${renderRoleGroup('Informed', area.i, 'i')}
</article>
`).join('');
}
function renderRoleGroup(label, personIds, roleKey) {
if (!personIds || personIds.length === 0) return '';
const names = personIds.map(id => {
const person = people.find(p => p.id === id);
const isFiltered = currentPersonFilter !== 'all' && currentPersonFilter === id;
return `<li class="name-tag ${isFiltered ? 'highlight' : ''}">${person ? person.name : id}</li>`;
}).join('');
return `
<div class="role-group">
<div class="role-label">
${label}
</div>
<ul class="names-list" aria-label="${label} list">${names}</ul>
</div>
`;
}
function renderTable() {
container.className = 'view-table';
const filteredAreas = getFilteredAreas();
// Show all people in table, but maybe highlight the filtered one
const headers = ['Area', ...people.map(p => p.name)];
const rows = filteredAreas.map(area => {
const cells = people.map(person => {
let role = '';
if (area.r.includes(person.id)) role = 'R';
else if (area.a.includes(person.id)) role = 'A';
else if (area.c.includes(person.id)) role = 'C';
else if (area.i.includes(person.id)) role = 'I';
if (!role) return '<td></td>';
const isFiltered = currentPersonFilter !== 'all' && currentPersonFilter === person.id;
return `
<td>
<span class="raci-badge ${isFiltered ? 'glow' : ''}" style="background: var(--accent-${role.toLowerCase()})" aria-label="${roleDefinitions[role].title}">
${role}
</span>
</td>
`;
});
return `
<tr>
<th scope="row" style="font-weight: 600; color: var(--primary); text-align: left; text-transform: none;">${area.label}</th>
${cells.join('')}
</tr>
`;
});
container.innerHTML = `
<table>
<thead>
<tr>
${headers.map((h, index) => {
const person = people.find(p => p.name === h);
const isFiltered = person && currentPersonFilter === person.id;
return `<th scope="col" class="${isFiltered ? 'header-highlight' : ''}">${h}</th>`;
}).join('')}
</tr>
</thead>
<tbody>
${rows.join('')}
</tbody>
</table>
`;
}
function renderLegend() {
legendContainer.innerHTML = Object.entries(roleDefinitions).map(([key, def]) => `
<div class="legend-item">
<h4><div class="circle" style="background: ${def.color}"></div> ${def.title} (${key})</h4>
<p>${def.description}</p>
</div>
`).join('');
}
function populatePersonFilter() {
people.forEach(person => {
const option = document.createElement('option');
option.value = person.id;
option.textContent = person.name;
personFilter.appendChild(option);
});
}
// Event Listeners
viewToggle.addEventListener('click', (e) => {
if (e.target.classList.contains('tab-btn')) {
// Update active tab state
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.classList.remove('active');
btn.setAttribute('aria-selected', 'false');
});
e.target.classList.add('active');
e.target.setAttribute('aria-selected', 'true');
currentView = e.target.dataset.view;
render();
}
});
personFilter.addEventListener('change', (e) => {
currentPersonFilter = e.target.value;
render();
// Announce the change
const count = getFilteredAreas().length;
const personName = e.target.options[e.target.selectedIndex].text;
const message = `Showing ${count} areas for ${personName}`;
const announcer = document.getElementById('a11y-announcer');
if (announcer) {
announcer.textContent = message;
}
});
// Init
function init() {
populatePersonFilter();
// Check for person in URL
const urlParams = new URLSearchParams(window.location.search);
const personParam = urlParams.get('person');
if (personParam && people.some(p => p.id === personParam)) {
currentPersonFilter = personParam;
personFilter.value = personParam;
}
render();
renderLegend();
}
init();