diff --git a/README.md b/README.md index bd7244c..ba40853 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,15 @@ Vous pouvez maintenant modifier les dates directement depuis l'interface et les ``` ### 4. Roadmap Draw.io ⭐ NOUVEAU + +**Regroupement par Epic/Theme :** + +1. Le champ Jira `customfield_10202` est extrait automatiquement, sans configuration supplémentaire. +2. Dans Table, saisissez une seule étiquette de projet, sans espace ni virgule, dans la colonne « Epic/Theme », puis cliquez sur « Update ». Une valeur vide efface les étiquettes du champ. +3. Dans Roadmap, choisissez « By epic theme » : les projets et leurs CR ayant la même étiquette sont regroupés, chacun conservant sa ligne. Les tickets sans étiquette sont regroupés sous « No epic theme ». + +Les tickets comportant déjà plusieurs étiquettes apparaissent sous « Multiple epic themes ». Leur remplacement ou suppression demande une confirmation. Comme pour les autres vues de la roadmap, seuls les tickets ayant au moins une date y apparaissent. L'édition nécessite que le champ soit modifiable dans Jira. + Générez une roadmap visuelle au format Draw.io (.drawio) importable dans draw.io/diagrams.net ! **Contenu de la roadmap :** diff --git a/index.html b/index.html index d996494..e6bd9bf 100644 --- a/index.html +++ b/index.html @@ -61,7 +61,7 @@
- Format : customfield_ID:DisplayName, comma separated + Format: customfield_ID:DisplayName, comma separated. Epic/Theme is extracted automatically.
@@ -114,6 +114,12 @@
+ Group : +
+ + + +
View :
diff --git a/public/js/script.js b/public/js/script.js index 3bbc334..064742c 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -5,6 +5,7 @@ let customFieldsMap = []; let lastUsername = ''; let lastApiToken = ''; let currentGanttView = 'month'; +let currentGanttMode = 'team'; let isGanttExpanded = false; let currentSortCol = null; let isAsc = true; @@ -311,7 +312,7 @@ async function startExtraction() { allTickets = data.tickets; filteredTickets = [...allTickets]; - customFieldsMap = parseCustomFields(custom); + customFieldsMap = data.customFieldsMap || parseCustomFields(custom); lastUsername = user; lastApiToken = token; @@ -361,20 +362,23 @@ function sortTable(colKey) { } // --- TICKET UPDATE --- -async function updateTicket(ticketKey, dueDate, goLiveDate) { +async function updateTicket(ticketKey, dueDate, goLiveDate, epicTheme, refreshTable = true) { if (!lastUsername || !lastApiToken) { showToast('Please extract tickets first.', 'error'); - return; + return false; } const btn = document.querySelector(`[data-ticket="${ticketKey}"]`); const orig = btn ? btn.innerHTML : null; + const wasDisabled = btn ? btn.disabled : true; if (btn) { btn.innerHTML = ''; btn.disabled = true; } - const goLiveField = customFieldsMap.find(cf => cf.label.toLowerCase().includes('go live')); + const goLiveField = getGoLiveField(); + const epicThemeField = getEpicThemeField(); const updates = {}; if (dueDate !== undefined) updates.duedate = dueDate; if (goLiveDate !== undefined && goLiveField) updates[goLiveField.id] = goLiveDate; + if (epicTheme !== undefined && epicThemeField) updates[epicThemeField.id] = epicTheme; try { const resp = await fetch(`${API_BASE}/api/update`, { @@ -391,15 +395,19 @@ async function updateTicket(ticketKey, dueDate, goLiveDate) { if (ticket) { if (updates.duedate !== undefined) ticket.dueDate = updates.duedate; if (goLiveField && updates[goLiveField.id] !== undefined) ticket[goLiveField.label] = updates[goLiveField.id]; + if (epicThemeField && updates[epicThemeField.id] !== undefined) ticket[epicThemeField.label] = updates[epicThemeField.id]; } - renderTable(); + if (refreshTable) renderTable(); renderRoadmap(); + renderJSON(); showToast(`Ticket ${ticketKey} updated!`, 'success'); + return true; } catch (err) { showToast(err.message, 'error'); + return false; } finally { - if (btn) { btn.innerHTML = orig; btn.disabled = false; } + if (btn) { btn.innerHTML = orig; btn.disabled = wasDisabled; } } } @@ -415,7 +423,7 @@ function getCreateIssueContext() { const projectMatch = jql.match(/\bproject\s*=\s*["']?([A-Z][A-Z0-9_-]*)["']?/i); const epicMatch = jql.match(/(?:["']?Epic Link["']?|\bparent|cf\[\d+\])\s*=\s*["']?([A-Z][A-Z0-9_-]*-\d+)["']?/i); const configuredFields = parseCustomFields(document.getElementById('customFields').value.trim()); - const dateField = configuredFields.find(field => /date|go live|production/i.test(field.label)) || configuredFields[0] || null; + const dateField = configuredFields.find(field => /date|go live|production/i.test(field.label)) || configuredFields.find(field => field.id !== 'customfield_10202') || null; return { jql, @@ -508,7 +516,7 @@ function handleUpdateClick(ticketKey, goLiveColName) { const dueInput = document.getElementById(`due-${ticketKey}`); const dueDate = dueInput && dueInput.value ? dueInput.value : null; - let goLiveDate = null; + let goLiveDate; if (goLiveColName) { const goLiveInput = document.getElementById(`gl-${ticketKey}`); goLiveDate = goLiveInput && goLiveInput.value ? goLiveInput.value : null; @@ -516,15 +524,50 @@ function handleUpdateClick(ticketKey, goLiveColName) { updateTicket(ticketKey, dueDate, goLiveDate); } +async function saveEpicTheme(ticketKey) { + const epicThemeInput = document.getElementById(`epic-theme-${ticketKey}`); + const epicThemeField = getEpicThemeField(); + const ticket = allTickets.find(t => t.key === ticketKey); + if (!epicThemeInput || epicThemeInput.disabled || !epicThemeField || !ticket) return; + const existingThemes = Array.isArray(ticket[epicThemeField.label]) ? ticket[epicThemeField.label] : []; + const newEpicTheme = epicThemeInput.value.trim(); + if (newEpicTheme === existingThemes.join(', ')) return; + if (/[\s,]/.test(newEpicTheme)) { + showToast('Epic/Theme must be a single label without spaces or commas.', 'error'); + return; + } + if (existingThemes.length > 1 && !window.confirm(`Replace all existing Epic/Theme labels (${existingThemes.join(', ')}) for ${ticketKey}?`)) { + epicThemeInput.value = existingThemes.join(', '); + return; + } + epicThemeInput.disabled = true; + try { + const saved = await updateTicket(ticketKey, undefined, undefined, newEpicTheme ? [newEpicTheme] : [], false); + if (saved) { + epicThemeInput.value = newEpicTheme; + epicThemeInput.title = 'One project label, without spaces'; + const warning = document.getElementById(`epic-theme-warning-${ticketKey}`); + if (warning) warning.remove(); + } + } finally { + epicThemeInput.disabled = false; + } +} + // --- GANTT DATE EDIT MODAL --- let dateEditContext = { ticketKey: null, goLiveColName: null }; // Detects the real go-live custom field name, ignoring known built-in ticket properties +function getGoLiveField() { + return customFieldsMap.find(field => /go live/i.test(field.label)) || customFieldsMap.find(field => /date|production/i.test(field.label)) || null; +} + function getGoLiveColumnName() { - if (!allTickets.length) return null; - return Object.keys(allTickets[0]).find(key => - !['key','url','summary','description','status','statusCategory','assignee','reporter','priority','issueType','created','updated','dueDate','resolution','resolutionDate','labels','components','fixVersions','projectName'].includes(key) - ) || null; + return getGoLiveField()?.label || null; +} + +function getEpicThemeField() { + return customFieldsMap.find(field => field.id === 'customfield_10202') || null; } function openDateEditModal(ticketKey) { @@ -599,6 +642,7 @@ function fmtDate(d) { if(!d) return '-'; try { r function renderTable() { const goLiveColName = getGoLiveColumnName(); + const epicThemeField = getEpicThemeField(); const colMapping = { 'Ticket': 'key', @@ -615,6 +659,8 @@ function renderTable() { cols.push(goLiveColName); colMapping[goLiveColName] = goLiveColName; } + cols.push('Epic/Theme'); + if (epicThemeField) colMapping['Epic/Theme'] = epicThemeField.label; cols.push('Actions'); document.getElementById('tableHead').innerHTML = '' + cols.map(c => { @@ -649,13 +695,17 @@ function renderTable() { body += ``; } + const epicThemes = epicThemeField && Array.isArray(t[epicThemeField.label]) ? t[epicThemeField.label] : []; + const themeTitle = epicThemes.length > 1 ? 'Multiple labels: changing this value replaces them all' : 'One project label, without spaces'; + body += `${epicThemes.length > 1 ? ` ⚠` : ''}`; + body += ` `; }); - document.getElementById('tableBody').innerHTML = body || 'No results found'; + document.getElementById('tableBody').innerHTML = body || `No results found`; } // --- ROADMAP (GANTT) --- @@ -664,6 +714,26 @@ function setGanttView(view) { renderRoadmap(); } +function setGanttMode(mode) { + currentGanttMode = mode; + document.querySelectorAll('[data-gantt-mode]').forEach(button => { + button.classList.toggle('active', button.dataset.ganttMode === mode); + }); + renderRoadmap(); +} + +function sortTicketsByDueDate(tickets) { + return [...tickets].sort((a, b) => { + const dateA = Date.parse(a.dueDate); + const dateB = Date.parse(b.dueDate); + const orderA = Number.isNaN(dateA) ? Infinity : dateA; + const orderB = Number.isNaN(dateB) ? Infinity : dateB; + + if (orderA !== orderB) return orderA - orderB; + return String(a.key || '').localeCompare(String(b.key || '')); + }); +} + function toggleGanttExpand() { isGanttExpanded = !isGanttExpanded; updateGanttExpandState(); @@ -734,7 +804,7 @@ function renderRoadmap() { return; } - const goLiveColName = Object.keys(filteredTickets[0]).find(k => k.toLowerCase().includes('go live')) || "Go Live Date"; + const goLiveColName = getGoLiveColumnName() || 'Go Live Date'; const leftWidth = 280; let colWidth = 140; @@ -807,12 +877,22 @@ function renderRoadmap() { return leftWidth + (index * colWidth) + (ratio * colWidth); }; + const epicThemeField = getEpicThemeField(); const grouped = ticketsWithDates.reduce((acc, t) => { - const name = t.assignee || "Unassigned"; - if (!acc[name]) acc[name] = []; - acc[name].push(t); + const themes = epicThemeField && Array.isArray(t[epicThemeField.label]) ? t[epicThemeField.label] : []; + const name = currentGanttMode === 'epic' + ? themes.length > 1 ? 'Multiple epic themes' : (themes[0] || 'No epic theme') + : t.assignee || 'Unassigned'; + if (!acc.has(name)) acc.set(name, []); + acc.get(name).push(t); return acc; - }, {}); + }, new Map()); + const roadmapGroups = currentGanttMode === 'global' + ? [{ name: null, tickets: sortTicketsByDueDate(ticketsWithDates) }] + : [...grouped.keys()].sort().map(name => ({ + name, + tickets: sortTicketsByDueDate(grouped.get(name)) + })); let html = `
`; @@ -822,20 +902,21 @@ function renderRoadmap() { html += `
Today
`; } - html += `
Assignee / Ticket (Title)
`; + const rowHeader = currentGanttMode === 'global' ? 'Ticket (Due Date)' : currentGanttMode === 'epic' ? 'Epic Theme / Ticket (Title)' : 'Assignee / Ticket (Title)'; + html += `
${rowHeader}
`; timeScale.forEach(ts => { html += `
${ts.label}
`; }); html += `
`; - Object.keys(grouped).sort().forEach(assignee => { - html += `
-
- ${assignee} -
-
`; - - const sortedTickets = grouped[assignee].sort((a, b) => (new Date(a.dueDate || 0)) - (new Date(b.dueDate || 0))); + roadmapGroups.forEach(({ name, tickets }) => { + if (name !== null) { + html += `
+
+ ${escHtml(name)} +
+
`; + } - sortedTickets.forEach(t => { + tickets.forEach(t => { const dDue = t.dueDate ? new Date(t.dueDate) : null; const dLive = t[goLiveColName] ? new Date(t[goLiveColName]) : null; @@ -975,14 +1056,19 @@ function exportDrawIOXML(mode) { acc[a].push(t); return acc; }, {}); + const exportGroups = currentGanttMode === 'global' + ? [{ name: null, tickets: sortTicketsByDueDate(ticketsWithDates) }] + : Object.keys(groups).sort().map(name => ({ name, tickets: groups[name] })); - Object.keys(groups).sort().forEach(assignee => { - xmlNodes += ` - - `; - currentY += 40; + exportGroups.forEach(({ name, tickets }) => { + if (name !== null) { + xmlNodes += ` + + `; + currentY += 40; + } - groups[assignee].forEach(t => { + tickets.forEach(t => { const { shortTitle, type } = parseTicketSummary(t.summary); const mappedStatus = mapJiraStatus(t.status); const statusDef = STATUS_DEFINITIONS[mappedStatus] || STATUS_DEFINITIONS['Opportunity']; @@ -1007,7 +1093,7 @@ function exportDrawIOXML(mode) { currentY += rowHeight; }); - currentY += 20; + if (name !== null) currentY += 20; }); const finalXml = ` diff --git a/server.js b/server.js index 3b7f6d6..50648b6 100644 --- a/server.js +++ b/server.js @@ -146,11 +146,9 @@ app.post('/api/extract', async (req, res) => { if (id) customFieldsMap.push({ id, label: label || id }); }); } - - const fieldsToRequest = [ - ...standardFields, - ...customFieldsMap.map(cf => cf.id) - ].join(','); + const epicThemeField = customFieldsMap.find(cf => cf.id === 'customfield_10202'); + if (epicThemeField) epicThemeField.label = 'Epic/Theme'; + else customFieldsMap.push({ id: 'customfield_10202', label: 'Epic/Theme' }); const queryJql = jql || `project = "${projectKey}" ORDER BY created DESC`; @@ -161,6 +159,11 @@ app.post('/api/extract', async (req, res) => { try { console.log(`[EXTRACT] Début pour ${projectKey} (JQL: ${queryJql.substring(0, 50)}...)`); + const fieldsToRequest = [ + ...standardFields, + ...customFieldsMap.map(cf => cf.id) + ].join(','); + // Pagination automatique while (true) { const response = await jiraClient.get('/rest/api/2/search', { @@ -212,7 +215,9 @@ app.post('/api/extract', async (req, res) => { // Ajout des champs personnalisés customFieldsMap.forEach(cf => { const val = f[cf.id]; - if (val !== null && val !== undefined) { + if (cf.id === 'customfield_10202') { + ticket[cf.label] = Array.isArray(val) ? val : []; + } else if (val !== null && val !== undefined) { // Pour les dates Jira, formater proprement if (typeof val === 'string' && (val.match(/^\d{4}-\d{2}-\d{2}/) || val.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/))) { ticket[cf.label] = val; @@ -232,7 +237,7 @@ app.post('/api/extract', async (req, res) => { } console.log(`[EXTRACT] Terminé. ${allTickets.length} tickets extraits.`); - res.json({ success: true, total: allTickets.length, tickets: allTickets }); + res.json({ success: true, total: allTickets.length, tickets: allTickets, customFieldsMap }); } catch (error) { console.error('[EXTRACT ERROR]', error.response?.data || error.message); @@ -345,14 +350,14 @@ app.put('/api/update', async (req, res) => { } catch (error) { console.error('[UPDATE ERROR]', error.response?.data || error.message); res.status(error.response?.status || 500).json({ - error: error.response?.data?.errorMessages?.[0] || error.message, + error: error.response?.data?.errorMessages?.[0] || Object.values(error.response?.data?.errors || {})[0] || error.message, details: error.response?.data || null }); } }); // Démarrage -const PORT = config.server?.port || 3000; +const PORT = process.env.PORT || config.server?.port || 3000; app.listen(PORT, '0.0.0.0', () => { console.log(''); console.log('============================================');