From e94ff6aac3b8c837a7151d76009f0272dd48d90b Mon Sep 17 00:00:00 2001 From: DamCoder Date: Tue, 19 Nov 2024 13:49:19 -0600 Subject: [PATCH] fix: match View in Jira button styling with preview Updated the View in Jira button in the generated HTML to match the preview exactly: - Use same blue color scheme (bg-blue-600/700) - Same text color (text-white) - Same padding and border styles - Same hover and focus states - Same shadow and rounded corners --- src/main.js | 458 +++++++++++----------------------------------------- 1 file changed, 94 insertions(+), 364 deletions(-) diff --git a/src/main.js b/src/main.js index b1f7783..8780a93 100644 --- a/src/main.js +++ b/src/main.js @@ -567,7 +567,7 @@ function generateTemplate(templateType, data, showComments) {
-
${comment.author}
+
${comment.author}
Created: ${comment.created} @@ -693,403 +693,133 @@ function generateTemplate(templateType, data, showComments) { // Function to generate email template HTML function generateEmailTemplate(templateType, data, showComments) { + let template = ''; + + // Ensure comments is an array and filter it + let comments = []; + if (showComments) { + if (Array.isArray(data.comments)) { + comments = getFilteredComments(data.comments); + } else if (showSmartValues) { + comments = ['{{comment.body.html}}']; + } + } + const issueTemplate = ` -
-
- ${data.summary} +
+
+
+ ${data.issueKey} + ${data.type} +
+

+ + ${data.summary} + +

-
+
${templateType === 'full' ? ` -
- Description: ${data.description} +
+
${data.description}
` : ''} -
- Key: ${data.issueKey} -
-
- Status: ${data.status} -
-
- Priority: ${data.priority} +
+ ${generateFields()}
-
- Assignee: ${data.assignee} -
- ${templateType === 'full' ? ` -
- Reporter: ${data.reporter} -
-
- Created: ${data.created} -
-
- Updated: ${data.updated} -
- ${data.components && data.components.length > 0 ? ` -
- Components: ${Array.isArray(data.components) ? data.components.join(', ') : data.components} + + ${currentProduct === 'software' ? ` +
+
Components
+
+ ${Array.isArray(data.components) ? data.components.map(comp => ` + + ${comp} + + `).join('') : ''}
- ` : ''} - ${data.labels && data.labels.length > 0 ? ` -
- Labels: ${Array.isArray(data.labels) ? data.labels.join(', ') : data.labels} +
+ +
+
Labels
+
+ ${Array.isArray(data.labels) ? data.labels.map(label => ` + + ${label} + + `).join('') : ''}
- ` : ''} +
` : ''}
`; const commentsTemplate = showComments && data.comments && data.comments.length > 0 ? ` -
-
+
+
Comments
-
+
${Array.isArray(data.comments) ? getFilteredComments(data.comments).map(comment => ` -
-
Author: ${comment.author}
-
Comment:
-
${comment.content}
-
Posted: ${comment.created}
+
+
+ ${comment.author} + ${comment.created} +
+
${comment.content}
`).join('') : ''}
` : ''; - const signature = ` -
Thank you,
-
Your Jira Automation
- `; - - return `${issueTemplate}${commentsTemplate}${signature}`; -} - -// Function to generate minified HTML -function generateHTML() { - // Always use smart values for the minified output - const data = templateData[currentProduct].smart; - - // Generate fields based on product type - const generateFields = () => { - let fields = ''; - - // Common fields - fields += ` -
-
Status
-
{{issue.status.name}}
-
-
-
Priority
-
{{issue.priority}}
-
-
-
Assignee
-
{{issue.assignee}}
-
-
-
Reporter
-
{{issue.reporter}}
-
-
-
Created
-
{{issue.created}}
-
-
-
Updated
-
{{issue.updated}}
-
- `; - - // Product specific fields - if (currentProduct === 'software') { - fields += ` -
-
Sprint
-
{{issue.sprint}}
-
-
-
Story Points
-
{{issue.storyPoints}}
-
- `; - } else if (currentProduct === 'servicedesk') { - fields += ` -
-
Request Type
-
{{issue.requestType}}
-
-
-
Impact
-
{{issue.impact}}
-
-
-
SLA
-
{{issue.sla}}
-
- `; - } else if (currentProduct === 'core') { - fields += ` -
-
Due Date
-
{{issue.dueDate}}
-
-
-
Category
-
{{issue.category}}
-
- `; - } - - return fields; - }; - - // Function to generate the comments section for preview - function generatePreviewComments() { - if (!showComments) return ''; - - const commentContent = Array.isArray(data.comments) ? getFilteredComments(data.comments).map(comment => ` -
-
- {{author.displayName}} - {{created.format("yyyy-MM-dd HH:mm")}} -
-
{{body.html}}
-
- `).join('') : (showSmartValues ? ` -
-
- {{author.displayName}} - {{created.format("yyyy-MM-dd HH:mm")}} -
-
{{body.html}}
-
- ` : ''); - - return ` -
-
- Comments -
-
- {{#issue.comments}} - ${commentContent} - {{/issue.comments}} -
-
- `; - } - - // Function to generate the comments section for minified output - function generateMinifiedComments() { - if (!showComments) return ''; - - return ` -
-
- Comments -
-
- {{#issue.comments}} -
-
- {{author.displayName}} - {{created.format("yyyy-MM-dd HH:mm")}} -
-
{{body.html}}
-
- {{/issue.comments}} -
-
- `; - } - - const template = `
-
-
- {{issue.key}} - {{issue.type}} -
-
-
-
-

- - {{issue.summary}} - -

-
{{issue.description}}
-
- -
- ${generateFields()} -
- - ${currentProduct === 'software' ? ` -
-
Components
-
- {{#issue.components}} - - {{.}} - - {{/issue.components}} -
-
- -
-
Labels
-
- {{#issue.labels}} - - {{.}} - - {{/issue.labels}} -
-
- ` : ''} -
-
- ${generatePreviewComments()} -`; - - const minifiedTemplate = `
-
-
- {{issue.key}} - {{issue.type}} -
-
-
-
-

- - {{issue.summary}} - -

-
{{issue.description}}
-
- -
- ${generateFields()} -
- - ${currentProduct === 'software' ? ` -
-
Components
-
- {{#issue.components}} - - {{.}} - - {{/issue.components}} -
-
- -
-
Labels
-
- {{#issue.labels}} - - {{.}} - - {{/issue.labels}} -
-
- ` : ''} + const viewInJiraButton = ` + -
- ${generateMinifiedComments()} -`; + `; - const fullHTML = ` - + return ` + - - Jira Notification - - - ${minifiedTemplate} + + ${issueTemplate} + ${commentsTemplate} + ${viewInJiraButton} `; +} - // Get the minified HTML - const minifiedHTML = fullHTML - .replace(/\s+/g, ' ') // Replace multiple whitespace with single space - .replace(/>\s+<') // Remove whitespace between tags - .replace(//g, '') // Remove comments - .trim(); // Remove leading/trailing whitespace - +// Function to generate HTML for copying +function generateHTML() { + // Always use smart values for the minified output + const previousSmartValue = showSmartValues; + showSmartValues = true; + + // Generate the template with current settings + const template = generateEmailTemplate('full', templateData[currentProduct].smart, showComments); + + // Reset smart values to previous state + showSmartValues = previousSmartValue; + + // Minify the HTML by removing unnecessary whitespace and line breaks + const minifiedTemplate = template + .replace(/\s+/g, ' ') // Replace multiple spaces with a single space + .replace(/>\s+<') // Remove spaces between tags + .replace(/\n/g, '') // Remove line breaks + .trim(); // Remove leading/trailing whitespace + // Update the output - document.getElementById("htmlOutput").textContent = minifiedHTML; + document.getElementById("htmlOutput").value = minifiedTemplate; } // Function to change template type