-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathby-type.mjs
More file actions
235 lines (203 loc) · 8.56 KB
/
by-type.mjs
File metadata and controls
235 lines (203 loc) · 8.56 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import {
fetchRepositoryData,
getContrastColor,
showError,
escapeHtml,
formatReactions,
getTotalReactions,
getRepoColor,
setupCommonUI,
setupLoadButton,
setupAutoLoad,
setupAdBanner,
setupHelpPanel,
setupAnalyticsConsent,
formatMarkdown,
formatDate,
renderIssueDetails
} from './shared.mjs';
// Initialize the application
document.addEventListener('DOMContentLoaded', () => {
setupCommonUI();
setupAdBanner();
setupHelpPanel();
setupAnalyticsConsent();
setupLoadButton(loadAllRepositories);
// Auto-load on page load with initial repos
setupAutoLoad(loadAllRepositories);
// Setup issue detail panel handlers
const iframePanel = document.getElementById('iframePanel');
const closeIframe = document.getElementById('closeIframe');
closeIframe.addEventListener('click', () => {
iframePanel.classList.remove('open');
});
// Handle clicks on issue cards
document.addEventListener('click', async (e) => {
// Check if clicked on item card or its children (but not the external link)
const item = e.target.closest('.item');
const link = e.target.closest('a.item-title');
if (item && !link) {
e.preventDefault();
const issueData = JSON.parse(item.dataset.issue);
const iframeTitle = document.getElementById('iframeTitle');
const detailsContent = document.getElementById('detailsContent');
const detailsLoading = document.getElementById('detailsLoading');
// Show in detail panel
iframeTitle.textContent = 'Loading...';
iframePanel.classList.add('open');
detailsContent.innerHTML = '';
detailsLoading.style.display = 'block';
try {
loadIssueDetails(issueData, iframeTitle, detailsContent);
} catch (error) {
detailsContent.innerHTML = `<div class="error">Failed to load issue details: ${error.message}</div>`;
} finally {
detailsLoading.style.display = 'none';
}
}
});
});
/**
* Load all repositories and display them grouped by type
*/
async function loadAllRepositories(repos, openOnly = true) {
const loadingEl = document.getElementById('loading');
const swimlanesEl = document.getElementById('swimlanes');
const errorContainer = document.getElementById('error-container');
// Clear previous data
swimlanesEl.innerHTML = '';
errorContainer.innerHTML = '';
loadingEl.style.display = 'block';
try {
// Fetch all repositories
const results = await Promise.all(
repos.map(repo => fetchRepositoryData(repo, openOnly))
);
loadingEl.style.display = 'none';
// Show errors for failed repositories
const failed = results.filter(r => !r.success);
if (failed.length > 0) {
const errorMessages = failed.map(r => `${r.repo}: ${r.error}`).join('<br>');
showError(`Failed to load some repositories:<br>${errorMessages}`);
}
// Display successful repositories
const successful = results.filter(r => r.success);
if (successful.length === 0) {
swimlanesEl.innerHTML = '<div class="empty-state">No repositories loaded successfully</div>';
return;
}
// Aggregate all issues by type (excluding PRs)
const allIssues = successful.flatMap(r => r.issues);
const allPRs = successful.flatMap(r => r.pullRequests);
// Group by type
const byType = {
bug: allIssues.filter(item => item.type === 'bug'),
feature: allIssues.filter(item => item.type === 'feature'),
task: allIssues.filter(item => item.type === 'task'),
other: allIssues.filter(item => item.type === 'other')
};
// Render swimlanes for each type
const typeOrder = [
{ key: 'bug', label: '🐛 Bugs', icon: '🐛' },
{ key: 'prs', label: '🔀 Pull Requests', icon: '🔀', items: allPRs },
{ key: 'feature', label: '✨ Features', icon: '✨' },
{ key: 'task', label: '📋 Tasks', icon: '📋' },
{ key: 'other', label: '❓ Other', icon: '❓' }
];
typeOrder.forEach(({ key, label, icon, items }) => {
const itemsToRender = items || byType[key];
if (itemsToRender && itemsToRender.length > 0) {
renderTypeSwimlane(label, itemsToRender);
}
});
if (allIssues.length === 0 && allPRs.length === 0) {
swimlanesEl.innerHTML = '<div class="empty-state">No issues or PRs found</div>';
}
} catch (error) {
loadingEl.style.display = 'none';
showError(`Error loading repositories: ${error.message}`);
}
}
/**
* Render a swimlane for a type
*/
function renderTypeSwimlane(typeLabel, items) {
const swimlanesEl = document.getElementById('swimlanes');
const swimlane = document.createElement('div');
swimlane.className = 'swimlane collapsed';
// Count repositories
const repos = [...new Set(items.map(item => item.repoName))];
swimlane.innerHTML = `
<div class="swimlane-header">
<div class="swimlane-title">
<div class="swimlane-title-main">
<span class="collapse-icon">▼</span>
<span>${typeLabel}</span>
</div>
</div>
<div class="swimlane-stats">
<span>Issues: ${items.length}</span>
<span>📂 Repos: ${repos.length}</span>
</div>
</div>
<div class="swimlane-content">
${renderItems(items)}
</div>
`;
// Add click handler for collapsing
const header = swimlane.querySelector('.swimlane-header');
header.addEventListener('click', () => {
swimlane.classList.toggle('collapsed');
});
swimlanesEl.appendChild(swimlane);
}
/**
* Render a list of items
*/
function renderItems(items) {
if (items.length === 0) {
return '<div class="empty-state">No items found</div>';
}
// Sort by reactions count (descending)
const sortedItems = [...items].sort((a, b) => {
return getTotalReactions(b.reactions) - getTotalReactions(a.reactions);
});
return sortedItems.map(item => {
const stateIcon = item.state === 'open' ? '🟢' : '🔴';
const milestone = item.milestone ? `<span class="milestone">🎯 ${escapeHtml(item.milestone.title)}</span>` : '';
const createdDate = formatDate(item.created_at);
const updatedDate = formatDate(item.updated_at);
return `
<div class="item" data-issue='${JSON.stringify(item).replace(/'/g, "'")}'>
<div class="item-header">
<span class="item-number">#${item.number}</span>
<span class="item-title-text">
${escapeHtml(item.title)}
</span>
<a href="${item.html_url}" class="item-title-link" target="_blank" rel="noopener noreferrer" onclick="event.stopPropagation();">↗️</a>
</div>
<div class="item-meta">
<span class="label repo-badge" style="--repo-bg: ${getRepoColor(item.repoName)}">${escapeHtml(item.repoName)}</span>
<span class="item-state">${stateIcon} ${item.state}</span>
<span class="item-dates">📅 ${createdDate} • 🔄 ${updatedDate}</span>
${milestone}
${item.comments > 0 ? `<span class="interaction-metric" title="comments">💬 ${item.comments}</span>` : ''}
${formatReactions(item.reactions)}
${item.labels.slice(0, 3).map(label => {
const labelName = typeof label === 'string' ? label : label.name;
const labelColor = typeof label === 'object' && label.color ?
`#${label.color}` : '#6e7681';
const textColor = getContrastColor(labelColor);
return `<span class="label" style="--label-bg: ${labelColor}; --label-color: ${textColor}">${escapeHtml(labelName)}</span>`;
}).join('')}
</div>
</div>
`;
}).join('');
}
/**
* Load and display issue details
*/
function loadIssueDetails(issue, iframeTitle, detailsContent) {
renderIssueDetails(issue, issue.html_url, iframeTitle, detailsContent);
}