jira-card-printer/bookmarklet.js

1405 lines
48 KiB
JavaScript
Raw Normal View History

2015-05-15 16:27:35 +02:00
(function() {
var version = "3.5.0";
2015-04-19 13:15:26 +02:00
console.log("Version: " + version);
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
try {
// load jQuery
if (window.jQuery === undefined) {
appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js');
}
2015-05-15 17:20:26 +02:00
var isDev = /.*jira.atlassian.com\/secure\/RapidBoard.jspa\?.*projectKey=ANERDS.*/g.test(document.URL) // Jira
2015-05-20 08:05:08 +02:00
|| /.*pivotaltracker.com\/n\/projects\/510733.*/g.test(document.URL) // PivotTracker
|| ( /.*trello.com\/.*/g.test(document.URL) && jQuery("span.js-member-name").text() =='Bengt Brodersen'); // Trello
2015-05-15 17:20:26 +02:00
var isProd = !isDev;
var hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/";
if (isDev) {
console.log("DEVELOPMENT");
hostOrigin = "https://rawgit.com/qoomon/Jira-Issue-Card-Printer/develop/";
}
var resourceOrigin = hostOrigin + "resources/";
2015-04-18 01:34:10 +02:00
2015-05-30 01:34:05 +02:00
var appFunctions = null;
2015-05-15 16:27:35 +02:00
// wait untill all scripts loaded
appendScript('https://qoomon.github.io/void', function() {
2015-05-30 01:34:05 +02:00
try {
main();
} catch (err) {
console.log(err.message);
if (isProd) {
ga('send', 'exception', {
'exDescription': err.message,
'exFatal': true
});
}
}
});
2015-05-15 17:20:26 +02:00
2015-05-15 16:27:35 +02:00
} catch (err) {
console.log(err.message);
2015-05-15 17:20:26 +02:00
if (isProd) {
2015-05-15 16:27:35 +02:00
ga('send', 'exception', {
'exDescription': err.message,
'exFatal': true
});
}
}
2015-05-15 16:27:35 +02:00
function init() {
2015-05-15 16:27:35 +02:00
addStringFunctions();
addDateFunctions();
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) {
2015-05-20 08:05:08 +02:00
console.log("App: " + "Jira");
2015-05-15 16:27:35 +02:00
appFunctions = jiraFunctions;
2015-05-20 08:05:08 +02:00
} else if (/.*pivotaltracker.com\/.*/g.test(document.URL)) {
console.log("App: " + "PivotalTracker");
appFunctions = pivotalTrackerFunctions;
} else if (/.*trello.com\/.*/g.test(document.URL)) {
console.log("App: " + "Trello");
appFunctions = trelloFunctions;
} else {
2015-05-30 01:34:05 +02:00
alert("Unsupported app.Please create an issue at https://github.com/qoomon/Jira-Issue-Card-Printer");
return;
2015-05-15 16:27:35 +02:00
}
if (isProd){
initGoogleAnalytics();
}
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function main() {
init();
2015-05-15 16:27:35 +02:00
//preconditions
if (jQuery("#card-print-overlay").length > 0) {
alert("Print Card already opened!");
return;
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
var issueKeyList = appFunctions.getSelectedIssueKeyList();
if (issueKeyList.length <= 0) {
alert("Please select at least one issue.");
return;
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
// open print preview
jQuery("body").append(printOverlayHTML);
jQuery("#card-print-overlay").prepend(printOverlayStyle);
2015-04-18 01:34:10 +02:00
jQuery("#rowCount").val(readCookie("card_printer_row_count",2));
jQuery("#columnCount").val(readCookie("card_printer_column_count",1));
jQuery("#card-scale-range").val(readCookie("card_printer_card_scale",1));
jQuery("#multi-card-page-checkbox").attr('checked',readCookie("card_printer_multi_card_page",false) != 'false');
jQuery("#hide-description-checkbox").attr('checked',readCookie("card_printer_hide_description",false) != 'false');
2015-05-15 17:20:26 +02:00
if (isProd) {
2015-05-15 16:27:35 +02:00
ga('send', 'pageview');
}
2015-05-12 22:00:40 +02:00
2015-05-15 16:27:35 +02:00
jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues...");
renderCards(issueKeyList, function() {
jQuery("#card-print-dialog-title").text("Card Print");
2015-05-20 08:05:08 +02:00
//print();
2015-02-09 18:16:15 +01:00
});
}
2015-05-15 16:27:35 +02:00
function print() {
var rowCount = jQuery("#rowCount").val();
var columnCount = jQuery("#columnCount").val();
var scale = jQuery("#card-scale-range").val();
var multiCard = jQuery("#multi-card-page-checkbox").is(':checked');
var hideDescription = jQuery("#hide-description-checkbox").is(':checked');
writeCookie("card_printer_row_count", rowCount);
writeCookie("card_printer_column_count",columnCount);
writeCookie("card_printer_card_scale",scale);
writeCookie("card_printer_multi_card_page",multiCard);
writeCookie("card_printer_hide_description",hideDescription);
2015-05-15 16:27:35 +02:00
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
2015-05-15 17:20:26 +02:00
if (isProd) {
2015-05-15 16:27:35 +02:00
ga('send', 'event', 'button', 'click', 'print', jQuery(".card", printDocument).length);
}
var currentScale = jQuery("html", printDocument).css("font-size").replace("px", "");
2015-05-15 16:27:35 +02:00
printWindow.matchMedia("print").addListener(function() {
2015-05-15 17:20:26 +02:00
2015-05-30 01:34:05 +02:00
jQuery(".card", printDocument).css("height", "calc( 100% / " + rowCount + " )");
jQuery(".card", printDocument).css("width", "calc( 100% / " + columnCount + " )");
var pageWidth = jQuery("body", printDocument).outerWidth();
var cardWidth = jQuery(".card", printDocument).outerWidth();
2015-05-15 17:20:26 +02:00
var newScale = currentScale * pageWidth / cardWidth;
2015-05-15 17:20:26 +02:00
2015-05-30 01:34:05 +02:00
//jQuery("html", printDocument).css("font-size",newScale +"px");
});
/////////////////////////////////////////
2015-05-15 17:20:26 +02:00
2015-05-30 01:34:05 +02:00
printWindow.addEventListener("resize", refreshCard);
printWindow.matchMedia("print").addListener(refreshCard);
2015-04-18 01:34:10 +02:00
2015-05-30 01:34:05 +02:00
function refreshCard() {
var cardElements = printDocument.querySelectorAll(".card");
forEach(cardElements, function (cardElement) {
var cardContent = cardElement.querySelectorAll(".card-content")[0];
if (cardContent.scrollHeight > cardContent.offsetHeight) {
cardContent.classList.add("zigzag");
} else {
cardContent.classList.remove("zigzag");
}
2015-05-15 16:27:35 +02:00
});
2015-05-30 01:34:05 +02:00
}
function forEach(array, callback) {
for (i = 0; i < array.length; i++) {
callback(array[i]);
}
}
/////////////////////////////////////////
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
printWindow.print();
jQuery("html", printDocument).css("font-size",currentScale +"px");
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function hideDescription(hide) {
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
if (hide) {
jQuery(".description", printDocument).hide();
} else {
jQuery(".description", printDocument).show();
}
2015-05-15 16:27:35 +02:00
resizeIframe(printFrame);
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function endableMultiCardPage(enable) {
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
if (enable) {
jQuery(".page", printDocument).addClass("multiCardPage");
} else {
jQuery(".page", printDocument).removeClass("multiCardPage");
}
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function renderCards(issueKeyList, callback) {
2015-05-12 13:19:43 +02:00
2015-05-15 16:27:35 +02:00
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
printDocument.open();
printDocument.write("<head/><body/>");
2015-05-30 01:34:05 +02:00
jQuery("head", printDocument).append(cardCss());
// jQuery("head", printDocument).append(cardJavaScript()); // NOT WORKING
2015-05-15 16:27:35 +02:00
2015-05-15 17:20:26 +02:00
console.log("load " + issueKeyList.length + " issues...");
2015-05-15 16:27:35 +02:00
var deferredList = [];
jQuery.each(issueKeyList, function(index, issueKey) {
2015-05-30 01:34:05 +02:00
var page = cardHtml(issueKey);
2015-05-15 16:27:35 +02:00
page.attr("index", index);
page.hide();
2015-05-30 01:34:05 +02:00
page.find('.issue-id').text(issueKey);
2015-05-15 16:27:35 +02:00
jQuery("body", printDocument).append(page);
var deferred = addDeferred(deferredList);
appFunctions.getCardData(issueKey, function(cardData) {
2015-05-15 17:20:26 +02:00
//console.log("cardData: " + cardData);
if (isProd) {
2015-05-15 16:27:35 +02:00
ga('send', 'event', 'task', 'generate', 'card', cardData.type);
}
fillCard(page, cardData);
page.show();
resizeIframe(printFrame);
deferred.resolve();
});
});
2015-05-15 17:20:26 +02:00
console.log("wait for issues loaded...");
2015-05-15 16:27:35 +02:00
applyDeferred(deferredList, function() {
2015-05-15 17:20:26 +02:00
console.log("...all issues loaded.");
2015-05-15 16:27:35 +02:00
jQuery(printWindow).load(function() {
2015-05-15 17:20:26 +02:00
console.log("...all resources loaded.");
2015-05-15 16:27:35 +02:00
callback();
})
printDocument.close();
2015-05-15 17:20:26 +02:00
console.log("wait for resources loaded...");
2015-05-12 13:19:43 +02:00
});
}
2015-05-15 16:27:35 +02:00
function closePrintPreview() {
jQuery("#card-print-overlay").remove();
jQuery("#card-print-overlay-style").remove();
2015-05-12 13:19:43 +02:00
}
function fillCard(card, data) {
2015-05-15 16:27:35 +02:00
//Key
2015-05-30 01:34:05 +02:00
card.find('.issue-id').text(data.key);
2015-05-15 16:27:35 +02:00
//Type
2015-05-30 01:34:05 +02:00
card.find(".issue-icon").attr("type", data.type);
2015-05-15 16:27:35 +02:00
//Summary
2015-05-30 01:34:05 +02:00
card.find('.issue-summary').text(data.summary);
2015-05-15 16:27:35 +02:00
//Description
2015-05-20 08:05:08 +02:00
if (data.description) {
2015-05-30 01:34:05 +02:00
card.find('.issue-description').html(data.description);
2015-05-20 08:05:08 +02:00
} else {
2015-05-30 01:34:05 +02:00
card.find(".issue-description").addClass("hidden");
2015-05-20 08:05:08 +02:00
}
2015-05-15 16:27:35 +02:00
//Assignee
if (data.assignee) {
if (data.avatarUrl) {
2015-05-30 01:34:05 +02:00
card.find(".issue-assignee").css("background-image", "url('" + data.avatarUrl + "')");
2015-05-15 16:27:35 +02:00
} else {
2015-05-30 01:34:05 +02:00
card.find(".issue-assignee").text(data.assignee[0].toUpperCase());
2015-05-15 16:27:35 +02:00
}
} else {
2015-05-30 01:34:05 +02:00
card.find(".issue-assignee").addClass("hidden");
2015-04-19 13:15:26 +02:00
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
//Due-Date
if (data.dueDate) {
2015-05-30 01:34:05 +02:00
card.find(".issue-due-date").text(data.dueDate);
2015-05-15 16:27:35 +02:00
} else {
2015-05-30 01:34:05 +02:00
card.find(".issue-due-box").addClass("hidden");
2015-05-15 16:27:35 +02:00
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
//Attachment
if (data.hasAttachment) {} else {
2015-05-30 01:34:05 +02:00
card.find('.issue-attachment').addClass('hidden');
2015-05-15 16:27:35 +02:00
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
//Story Points
if (data.storyPoints) {
2015-05-30 01:34:05 +02:00
card.find(".issue-estimate").text(data.storyPoints);
2015-05-15 16:27:35 +02:00
} else {
2015-05-30 01:34:05 +02:00
card.find(".issue-estimate").addClass("hidden");
2015-05-15 16:27:35 +02:00
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
//Epic
if (data.epicKey) {
2015-05-30 01:34:05 +02:00
card.find(".issue-epic-id").text(data.epicKey);
card.find(".issue-epic-name").text(data.epicName);
2015-05-15 16:27:35 +02:00
} else {
2015-05-30 01:34:05 +02:00
card.find(".issue-epic-box").addClass("hidden");
2015-05-15 16:27:35 +02:00
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
//QR-Code
var qrCodeUrl = 'https://chart.googleapis.com/chart?cht=qr&chs=256x256&chld=L|1&chl=' + encodeURIComponent(data.url);
2015-05-30 01:34:05 +02:00
card.find(".issue-qr-code").css("background-image", "url('" + qrCodeUrl + "')");
}
2015-04-18 01:34:10 +02:00
//############################################################################################################################
2015-05-15 16:27:35 +02:00
//############################################################################################################################
//############################################################################################################################
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
// http://www.cssdesk.com/T9hXg
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function printOverlayHTML() {
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
var result = jQuery(document.createElement('div'))
2015-05-15 16:27:35 +02:00
.attr("id", "card-print-overlay")
.html(multilineString(function() {
/*!
<div id="card-print-dialog">
<div id="card-print-dialog-header">
<div id="card-print-dialog-title">Card Print</div>
<div id="info">
<input id="report-issue" type="button" class="aui-button" value="Report Issues" />
<input id="about" type="button" class="aui-button" value="About" />
</div>
</div>
<div id="card-print-dialog-content">
<iframe id="card-print-dialog-content-iframe"></iframe>
</div>
<div id="card-print-dialog-footer">
<div class="buttons">
<label style="margin-right:10px"><input id="card-scale-range" type="range" min="0.4" max="1.6" step="0.1" value="1.0" />Scale</label>
2015-05-15 16:27:35 +02:00
<label style="margin-right:10px"><input id="multi-card-page-checkbox" type="checkbox"/>Multi Card Page</label>
<label style="margin-right:10px;"><input id="rowCount" type="text" class="text" maxlength="1" style="width: 10px;" value="2"/>Row Count</label>
<label style="margin-right:10px;"><input id="columnCount" type="text" class="text" maxlength="1" style="width: 10px;" value="1"/>Column Count</label>
<label style="margin-right:10px"><input id="hide-description-checkbox" type="checkbox"/>Hide Description</label>
2015-05-15 16:27:35 +02:00
<input id="card-print-dialog-print" type="button" class="aui-button aui-button-primary" value="Print" />
<a id="card-print-dialog-cancel" title="Cancel" class="cancel">Cancel</a>
</div>
</div>
</div>
*/
}));
2015-04-19 13:15:26 +02:00
// info
result.find("#report-issue")
2015-05-15 16:27:35 +02:00
.click(function(event) {
window.open('https://github.com/qoomon/Jira-Issue-Card-Printer/issues');
return false;
});
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
result.find("#about")
2015-05-15 16:27:35 +02:00
.click(function(event) {
window.open('http://qoomon.blogspot.de/2014/01/jira-issue-card-printer-bookmarklet.html');
return false;
});
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
// enable multe card page
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
result.find("#multi-card-page-checkbox")
2015-05-15 16:27:35 +02:00
.click(function() {
endableMultiCardPage(this.checked);
return true;
});
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
// hide description
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
result.find("#hide-description-checkbox")
2015-05-15 16:27:35 +02:00
.click(function() {
hideDescription(this.checked);
return true;
});
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
// scale card
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
result.find("#card-scale-range").on("input", function() {
2015-05-15 16:27:35 +02:00
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
jQuery("html", printDocument).css("font-size", jQuery(this).val() + "cm");
resizeIframe(printFrame);
2015-04-19 13:15:26 +02:00
});
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
// print
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
result.find("#card-print-dialog-print")
2015-05-15 16:27:35 +02:00
.click(function(event) {
print();
return false;
});
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
// closePrintPreview
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
result.find("#card-print-dialog-cancel")
2015-05-15 16:27:35 +02:00
.click(function(event) {
closePrintPreview();
return false;
});
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
result.click(function(event) {
2015-05-15 16:27:35 +02:00
if (event.target == this) {
closePrintPreview();
}
return true;
2015-04-19 13:15:26 +02:00
});
2015-04-19 13:15:26 +02:00
jQuery(document).keyup(function(e) {
2015-05-15 16:27:35 +02:00
if (e.keyCode == 27) { // esc
closePrintPreview();
}
2015-04-19 13:15:26 +02:00
});
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
// prevent background scrolling
result.scroll(function(event) {
2015-05-15 16:27:35 +02:00
return false;
2015-04-19 13:15:26 +02:00
});
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
return result;
2015-05-15 16:27:35 +02:00
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function printOverlayStyle() {
var result = jQuery(document.createElement('style'))
.attr("id", "card-print-overlay-style")
.attr("type", "text/css")
.html(multilineString(function() {
/*!
#card-print-overlay {
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
background:rgba(0, 0, 0, 0.5);
box-sizing: border-box;
word-wrap:break-word;
z-index: 99999;
}
#card-print-dialog {
position: relative;
top: 60px;
right:0px;
left:0px;
height: calc(100% - 120px);
width: 1000px;
margin: auto;
border-style: solid;
border-color: #cccccc;
border-width: 1px;
-webkit-border-radius: 4px;
border-radius: 4px;
overflow: hidden;
}
#card-print-dialog-header {
position: relative;
background: #f0f0f0;
height: 25px;
border-bottom: 1px solid #cccccc;
padding: 15px 20px 15px 20px;
}
#card-print-dialog-content {
position: relative;
background: white;
height: calc(100% - 106px);
width: 100%;
2015-05-30 01:34:05 +02:00
overflow: hidden;
2015-05-15 16:27:35 +02:00
}
#card-print-dialog-content-iframe {
position: relative;
height: 100%;
width: 100%;
2015-05-30 01:34:05 +02:00
overflow: hidden;
2015-05-15 16:27:35 +02:00
border:none;
}
#card-print-dialog-footer {
position: relative;
background: #f0f0f0;
border-top: 1px solid #cccccc;
height: 30px;
padding: 10px;
text-align: right;
}
#buttons {
position: relative;
float: right;
display: inline-block;
height 30px;
}
#info {
position: relative;
float: right;
display: inline-block;
height 30px;
}
#card-print-dialog-title{
position: relative;
float: left;
color: rgb(51, 51, 51);
display: block;
font-family: Arial, sans-serif;
font-size: 20px;
font-weight: normal;
height: 30px;
line-height: 30px;
}
.cancel{
cursor: pointer;
font-size: 14px;
display: inline-block;
padding: 5px 10px;
vertical-align: baseline;
}
*/
}));
return result;
}
2015-04-18 01:34:10 +02:00
2015-05-30 01:34:05 +02:00
// card layout: http://jsfiddle.net/qoomon/ykbLb2pw/
function cardHtml(issueKey) {
var page = jQuery(document.createElement('div'))
.attr("id", issueKey)
.addClass("card")
.html(multilineString(function() {
/*!
<div class="card-body">
<div class="card-content shadow">
<div class="issue-summary"></div>
<div class="issue-description"></div>
</div>
<div class="card-header">
<div class="issue-id badge"></div>
<div class="issue-icon badge" type="story"></div>
<div class="issue-estimate badge"></div>
<div class="issue-due-box">
<div class="issue-due-date badge"></div>
<div class="issue-due-icon badge"></div>
</div>
</div>
<div class="card-footer">
<div class="issue-qr-code badge"></div>
<div class="issue-attachment badge"></div>
<div class="issue-assignee badge"></div>
<div class="issue-epic-box badge">
<span class="issue-epic-id"></span>
<span class="issue-epic-name"></span>
</div>
</div>
</div>
<div class="author">© qoomon.com Bengt Brodersen</div>
*/
}));
return page;
}
2015-04-18 01:34:10 +02:00
2015-05-30 01:34:05 +02:00
function cardCss() {
2015-05-15 16:27:35 +02:00
var result = jQuery(document.createElement('style'))
.attr("type", "text/css")
.html(multilineString(function() {
/*!
* {
2015-05-30 01:34:05 +02:00
box-sizing: border-box;
overflow: hidden;
2015-05-15 16:27:35 +02:00
}
2015-05-30 01:34:05 +02:00
html, body {
2015-04-18 01:34:10 +02:00
2015-05-30 01:34:05 +02:00
background: WHITE;
padding: 0px;
margin: 0px;
font-size: 0.9cm;
2015-04-18 01:34:10 +02:00
2015-05-30 01:34:05 +02:00
overflow: scroll;
}
.author {
position: absolute;
top:0.6rem;
left:calc(50% - 3rem);
font-size: 0.5rem;
}
.card {
position: relative;
float:left;
height: 100%; height: 12rem;
width: 100%;
padding: 0.5rem;
padding-top: 0.6rem;
min-width:21.0rem;
min-height:10.0rem;
border-color: light-grey;
border-style: dashed;
border-width: 1.0px;
2015-05-30 01:34:05 +02:00
}
.card-body {
position: relative;
height: 100%;
// find .card-header;
padding-top: 2rem;
// find .card-footer;
padding-bottom: 1.3rem;
}
.card-content {
position: relative;
height: 100%;
margin-left: 0.4rem;
margin-right: 0.4rem;
padding-top: 1.2rem;
padding-bottom: 1.1rem;
padding-left: 0.4rem;
padding-right: 0.4rem;
background: WHITE;
}
.card-header {
position: absolute;
top: 0rem;
height: 4.2rem;
width: 100%;
}
.card-footer {
position: absolute;
bottom: 0rem;
height: 2.2rem;
width: 100%;
}
.issue-summary {
font-weight: bold;
display: -webkit-box;
//-webkit-line-clamp: 2;
//-webkit-box-orient: vertical;
}
.issue-description {
margin-top: 0.4rem;
display: block;
font-size: 0.6rem;
line-height: 0.6rem;
overflow: hidden;
}
.issue-id {
position: absolute;
left: 1rem;
top: 1.2rem;
height: 1.5rem;
max-width: 10rem;
min-width: 5rem;
padding-left: 2.4rem;
padding-right: 0.4rem;
background-color: WHITESMOKE;
line-height: 1.3rem;
font-size: 0.8rem;
font-weight: bold;
text-align: center;
white-space: nowrap;
text-overflow: ellipsis;
}
.issue-icon {
position: absolute;
left: 0rem;
top: 0rem;
height: 3.2rem;
width: 3.2rem;
border-radius: 50% !important;
background-color: GREENYELLOW !important;
background-image: url(https://qoomon.github.io/Jira-Issue-Card-Printer/resources/icons/Objects.png);
background-repeat: no-repeat;
background-position: center;
background-size: 70%;
}
.issue-icon[type="story"] {
background-color: GOLD !important;
background-image: url(https://qoomon.github.io/Jira-Issue-Card-Printer/resources/icons/Bulb.png);
}
.issue-icon[type="bug"] {
background-color: CRIMSON !important;
background-image: url(https://qoomon.github.io/Jira-Issue-Card-Printer/resources/icons/Bug.png);
}
.issue-icon[type="epic"] {
background-color: ROYALBLUE !important;
background-image: url(https://qoomon.github.io/Jira-Issue-Card-Printer/resources/icons/Flash.png);
}
.issue-estimate {
position: absolute;
left: 2.5rem;
top: 0.0rem;
height: 1.6rem;
width: 1.6rem;
border-radius: 49.5% !important;
background-color: WHITESMOKE;
line-height: 1.4rem;
font-size: 0.9rem;
font-weight: bold;
text-align: center;
}
.issue-qr-code {
position: absolute;
left:0rem;
top: 0rem;
width: 2.2rem;
height: 2.2rem;
background-image: url(https://chart.googleapis.com/chart?cht=qr&chs=256x256&chld=L|1&chl=blog.qoomon.com);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
.issue-attachment {
position: absolute;
left:2.8rem;
top: 0rem;
width: 2.0rem;
height: 2.0rem;
border-radius: 50% !important;
background-color: LIGHTSKYBLUE !important;
background-image: url(https://qoomon.github.io/Jira-Issue-Card-Printer/resources/icons/Attachment.png);
background-repeat: no-repeat;
background-position: center;
background-size: 70%;
}
.issue-assignee {
position: absolute;
top:0rem;
right:0rem;
width: 2.2rem;
height: 2.2rem;
border-radius: 50% !important;
background-color: WHITESMOKE;
//background-image: url(https://qoomon.github.io/Jira-Issue-Card-Printer/resources/icons/Person.png);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
//-webkit-filter: contrast(200%) grayscale(100%);
//filter: contrast(200%) grayscale(100%);
text-align: center;
font-weight: bold;
font-size: 1.4rem;
line-height: 1.8rem;
}
.issue-epic-box {
position: absolute;
right:3.0rem;
top: 0rem;
width: auto;
min-width: 6rem;
width: auto;
max-width: 10rem;
2015-05-15 16:27:35 +02:00
height: auto;
2015-05-30 01:34:05 +02:00
max-height: 2.2rem;
padding-top: 0.1rem;
padding-bottom: 0.2rem;
padding-left: 0.3rem;
padding-right: 0.3rem;
text-align: left;
font-size: 0.6rem;
line-height: 0.8rem;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
2015-05-15 16:27:35 +02:00
}
2015-05-30 01:34:05 +02:00
.issue-epic-id {
font-size: 0.5rem;
font-weight: bold;
2015-05-15 16:27:35 +02:00
}
2015-05-30 01:34:05 +02:00
.issue-epic-name {
margin-left: 0.1rem;
font-size: 0.6rem;
font-weight: bold;
}
.issue-due-date-box {
position: absolute;
right: 0rem;
top: 0rem;
overflow: visible !important;
}
.issue-due-date {
position: absolute;
top: 1.3rem;
right: 1rem;
width: 5.3rem;
min-width: 2.8rem;
height: 1.3rem;
padding-left: 0.2rem;
padding-right: 1.4rem;
text-align: center;
font-weight: bold;
font-size: 0.7rem;
line-height: 1.0rem;
}
.issue-due-icon {
position: absolute;
top: 0.5rem;
right: 0rem;
width: 2.5rem;
height: 2.5rem;
border-radius: 50% !important;
background-color: ORCHID !important;
background-image: url(https://qoomon.github.io/Jira-Issue-Card-Printer/resources/icons/AlarmClock.png);
background-repeat: no-repeat;
background-position: center;
background-size: 65%;
}
.badge, .shadow {
border-style: solid;
border-color: #555;
border-top-width: 0.12rem;
border-left-width: 0.12rem;
border-bottom-width: 0.21rem;
border-right-width: 0.21rem;
border-radius: 0.25rem;
}
.badge {
// WHITESMOKE, GAINSBOROM;
background-color: WHITESMOKE;
}
.hidden {
display: none;
}
.zigzag {
border-bottom-width: 0rem;
}
.zigzag::after {
position: absolute;
bottom: -0.04rem;
left:-0.07rem;
content:"";
width: 100%;
border-bottom-width: 0.8rem;
border-image: url(https://qoomon.github.io/Jira-Issue-Card-Printer/resources/ZigZag.png) 0 0 56 fill round repeat;
}
@media print {
@page {
margin: 0.0cm;
padding: 0.0cm;
}
html {
-webkit-print-color-adjust:exact;
print-color-adjust: exact;
}
.pageBreak {
page-break-after: always;
float: none;
}
.card {
height: 100%;
}
}
2015-05-15 16:27:35 +02:00
}
*/
}).replace(/{RESOURCE_ORIGIN}/g, resourceOrigin));
2015-04-19 13:15:26 +02:00
return result;
2015-05-15 16:27:35 +02:00
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
//############################################################################################################################
//############################################################################################################################
//############################################################################################################################
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function appendScript(url, callback) {
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = url;
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
// Then bind the event to the callback function.
// There are several events for cross browser compatibility.
script.onreadystatechange = callback;
script.onload = callback;
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
head.appendChild(script);
2015-05-15 16:27:35 +02:00
}
2015-04-18 01:34:10 +02:00
2015-05-15 17:20:26 +02:00
function initGoogleAnalytics(){
// <GoogleAnalytics>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-50840116-3', {
'alwaysSendReferrer': true
});
ga('set', 'page', '/cardprinter');
}
2015-05-15 16:27:35 +02:00
//############################################################################################################################
//############################################################################################################################
//############################################################################################################################
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function addDeferred(deferredList) {
2015-04-19 13:15:26 +02:00
var deferred = new jQuery.Deferred()
deferredList.push(deferred);
return deferred;
2015-05-15 16:27:35 +02:00
}
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function applyDeferred(deferredList, callback) {
2015-04-19 13:15:26 +02:00
jQuery.when.apply(jQuery, deferredList).done(callback);
2015-05-15 16:27:35 +02:00
}
2015-04-18 01:34:10 +02:00
function readCookie(name, defaultValue){
var cookies = document.cookie.split('; ');
for(var i = 0; i<cookies.length; i++){
var cookie = cookies[i].split('=');
if(cookie[0] == name) return cookie[1];
}
return defaultValue
}
function writeCookie(name, value){
document.cookie=name+"=" +value;
}
2015-05-15 16:27:35 +02:00
//############################################################################################################################
//############################################################################################################################
//############################################################################################################################
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
function addStringFunctions() {
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
//trim string - remove leading and trailing whitespaces
if (!String.prototype.trim) {
2015-05-15 16:27:35 +02:00
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
};
2015-01-27 22:49:37 +01:00
}
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
if (!String.prototype.startsWith) {
2015-05-15 16:27:35 +02:00
String.prototype.startsWith = function(str) {
return this.slice(0, str.length) == str;
};
2015-04-19 13:15:26 +02:00
}
2015-04-18 01:34:10 +02:00
2015-04-19 13:15:26 +02:00
if (!String.prototype.endsWith) {
2015-05-15 16:27:35 +02:00
String.prototype.endsWith = function(str) {
return this.slice(-str.length) == str;
};
2015-02-09 18:16:15 +01:00
}
2015-04-19 13:15:26 +02:00
if (!String.prototype.toCamelCase) {
2015-05-15 16:27:35 +02:00
String.prototype.toCamelCase = function() {
// remove all characters that should not be in a variable name
// as well underscores an numbers from the beginning of the string
var s = this.replace(/([^a-zA-Z0-9_\- ])|^[_0-9]+/g, "").trim().toLowerCase();
// uppercase letters preceeded by a hyphen or a space
s = s.replace(/([ -]+)([a-zA-Z0-9])/g, function(a, b, c) {
return c.toUpperCase();
});
// uppercase letters following numbers
s = s.replace(/([0-9]+)([a-zA-Z])/g, function(a, b, c) {
return b + c.toUpperCase();
});
return s;
}
2015-02-09 18:16:15 +01:00
}
2015-05-15 16:27:35 +02:00
}
2015-05-15 16:27:35 +02:00
function addDateFunctions() {
2015-04-19 13:15:26 +02:00
Date.prototype.format = function(format) {
2015-05-15 16:27:35 +02:00
var returnStr = '';
var replace = Date.replaceChars;
for (var i = 0; i < format.length; i++) {
var curChar = format.charAt(i);
if (i - 1 >= 0 && format.charAt(i - 1) == "\\") {
returnStr += curChar;
} else if (replace[curChar]) {
returnStr += replace[curChar].call(this);
} else if (curChar != "\\") {
returnStr += curChar;
}
2015-04-19 13:15:26 +02:00
}
2015-05-15 16:27:35 +02:00
return returnStr;
2015-04-19 13:15:26 +02:00
};
2015-04-18 01:34:10 +02:00
2015-05-15 16:27:35 +02:00
Date.replaceChars = {
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
// Day
d: function() {
return (this.getDate() < 10 ? '0' : '') + this.getDate();
},
D: function() {
return Date.replaceChars.shortDays[this.getDay()];
},
j: function() {
return this.getDate();
},
l: function() {
return Date.replaceChars.longDays[this.getDay()];
},
N: function() {
return this.getDay() + 1;
},
S: function() {
return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th')));
},
w: function() {
return this.getDay();
},
z: function() {
var d = new Date(this.getFullYear(), 0, 1);
return Math.ceil((this - d) / 86400000);
}, // Fixed now
// Week
W: function() {
var d = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this - d) / 86400000) + d.getDay() + 1) / 7);
}, // Fixed now
// Month
F: function() {
return Date.replaceChars.longMonths[this.getMonth()];
},
m: function() {
return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1);
},
M: function() {
return Date.replaceChars.shortMonths[this.getMonth()];
},
n: function() {
return this.getMonth() + 1;
},
t: function() {
var d = new Date();
return new Date(d.getFullYear(), d.getMonth(), 0).getDate()
}, // Fixed now, gets #days of date
// Year
L: function() {
var year = this.getFullYear();
return (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0));
}, // Fixed now
o: function() {
var d = new Date(this.valueOf());
d.setDate(d.getDate() - ((this.getDay() + 6) % 7) + 3);
return d.getFullYear();
}, //Fixed now
Y: function() {
return this.getFullYear();
},
y: function() {
return ('' + this.getFullYear()).substr(2);
},
// Time
a: function() {
return this.getHours() < 12 ? 'am' : 'pm';
},
A: function() {
return this.getHours() < 12 ? 'AM' : 'PM';
},
B: function() {
return Math.floor((((this.getUTCHours() + 1) % 24) + this.getUTreminutes() / 60 + this.getUTCSeconds() / 3600) * 1000 / 24);
}, // Fixed now
g: function() {
return this.getHours() % 12 || 12;
},
G: function() {
return this.getHours();
},
h: function() {
return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12);
},
H: function() {
return (this.getHours() < 10 ? '0' : '') + this.getHours();
},
i: function() {
return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes();
},
s: function() {
return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds();
},
u: function() {
var m = this.getMilliseconds();
return (m < 10 ? '00' : (m < 100 ? '0' : '')) + m;
},
// Timezone
e: function() {
return "Not Yet Supported";
},
I: function() {
var DST = null;
for (var i = 0; i < 12; ++i) {
var d = new Date(this.getFullYear(), i, 1);
var offset = d.getTimezoneOffset();
if (DST === null) DST = offset;
else if (offset < DST) {
DST = offset;
break;
} else if (offset > DST) break;
}
return (this.getTimezoneOffset() == DST) | 0;
},
O: function() {
return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + '00';
},
P: function() {
return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + ':00';
}, // Fixed now
T: function() {
var m = this.getMonth();
this.setMonth(0);
var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1');
this.setMonth(m);
return result;
},
Z: function() {
return -this.getTimezoneOffset() * 60;
},
// Full Date/Time
c: function() {
return this.format("Y-m-d\\TH:i:sP");
}, // Fixed now
r: function() {
return this.toString();
},
U: function() {
return this.getTimep() / 1000;
}
};
}
function multilineString(commentFunction) {
2015-04-19 13:15:26 +02:00
return commentFunction.toString()
2015-05-15 16:27:35 +02:00
.replace(/^[^\/]+\/\*!?/, '')
.replace(/\*\/[^\/]+$/, '');
}
2015-04-19 13:15:26 +02:00
2015-05-15 16:27:35 +02:00
function resizeIframe(iframe) {
2015-05-30 01:34:05 +02:00
iframe.height(iframe[0].contentWindow.document.body.height);
2015-05-15 16:27:35 +02:00
}
// APP Specific Functions
//############################################################################################################################
//############################################################################################################################
//############################################################################################################################
2015-05-20 08:05:08 +02:00
var jiraFunctions = (function (module) {
2015-05-15 16:27:35 +02:00
2015-05-20 08:05:08 +02:00
module.getSelectedIssueKeyList = function() {
2015-05-15 16:27:35 +02:00
//Browse
if (/.*\/browse\/.*/g.test(document.URL)) {
return jQuery("a[data-issue-key][id='key-val']").map(function() {
return jQuery(this).attr('data-issue-key');
});
}
// RapidBoard
if (/.*\/secure\/RapidBoard.jspa.*/g.test(document.URL)) {
return jQuery('div[data-issue-key].ghx-selected').map(function() {
return jQuery(this).attr('data-issue-key');
});
}
return [];
2015-05-20 08:05:08 +02:00
};
2015-05-15 16:27:35 +02:00
2015-05-20 08:05:08 +02:00
module.getCardData= function(issueKey, callback) {
module.getIssueData(issueKey, function(data) {
2015-05-15 16:27:35 +02:00
var issueData = {};
issueData.key = data.key;
issueData.type = data.fields.issuetype.name.toLowerCase();
issueData.summary = data.fields.summary;
issueData.description = data.renderedFields.description.replace(/<p>/, "");
2015-05-15 16:27:35 +02:00
if (data.fields.assignee) {
issueData.assignee = data.fields.assignee.displayName;
var avatarUrl = data.fields.assignee.avatarUrls['48x48'];
if (avatarUrl.indexOf("ownerId=") >= 0) {
issueData.avatarUrl = avatarUrl;
}
}
if (data.fields.duedate) {
issueData.dueDate = new Date(data.fields.duedate).format('D d.m.');
}
issueData.hasAttachment = data.fields.attachment.length > 0;
issueData.storyPoints = data.fields.storyPoints;
issueData.epicKey = data.fields.epicLink;
if (issueData.epicKey) {
2015-05-15 17:20:26 +02:00
jiraFunctions.getIssueData(issueData.epicKey, function(data) {
2015-05-15 16:27:35 +02:00
issueData.epicName = data.fields.epicName;
}, false);
}
issueData.url = window.location.origin + "/browse/" + issueData.key;
2015-05-15 17:20:26 +02:00
//LRS Specific field mapping
2015-05-15 16:27:35 +02:00
if (true) {
//Desired-Date
if (data.fields.desiredDate) {
issueData.dueDate = new Date(data.fields.desiredDate).format('D d.m.');
}
}
callback(issueData);
});
2015-05-20 08:05:08 +02:00
};
2015-05-15 16:27:35 +02:00
2015-05-20 08:05:08 +02:00
module.getIssueData = function(issueKey, callback, async) {
2015-05-15 16:27:35 +02:00
async = typeof async !== 'undefined' ? async : true;
//https://docs.atlassian.com/jira/REST/latest/
var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names';
2015-05-15 17:20:26 +02:00
console.log("IssueUrl: " + url);
//console.log("Issue: " + issueKey + " Loading...");
2015-05-15 16:27:35 +02:00
jQuery.ajax({
type: 'GET',
url: url,
data: {},
dataType: 'json',
async: async,
success: function(responseData) {
2015-05-15 17:20:26 +02:00
//console.log("Issue: " + issueKey + " Loaded!");
2015-05-15 16:27:35 +02:00
// add custom fields with field names
jQuery.each(responseData.names, function(key, value) {
if (key.startsWith("customfield_")) {
var newFieldId = value.toCamelCase();
2015-05-15 17:20:26 +02:00
//console.log("add new field: " + newFieldId + " with value from " + key);
2015-05-15 16:27:35 +02:00
responseData.fields[value.toCamelCase()] = responseData.fields[key];
}
});
callback(responseData);
},
});
2015-05-20 08:05:08 +02:00
};
2015-05-15 16:27:35 +02:00
2015-05-20 08:05:08 +02:00
return module;
}({}));
2015-05-15 16:27:35 +02:00
2015-05-20 08:05:08 +02:00
var pivotalTrackerFunctions = (function (module) {
module.getSelectedIssueKeyList = function() {
2015-05-15 17:20:26 +02:00
//Single Story
if (/.*\/stories\/.*/g.test(document.URL)) {
2015-05-20 08:05:08 +02:00
return [document.URL.replace(/.*\/stories\/([^?]*).*/, '$1')]; // TODO
2015-05-15 17:20:26 +02:00
}
2015-05-15 16:27:35 +02:00
2015-05-15 17:20:26 +02:00
// Board
if (/.*\/projects\/.*/g.test(document.URL)) {
return jQuery('.story[data-id]:has(.selected)').map(function() {
return jQuery(this).attr('data-id');
});
}
2015-05-15 16:27:35 +02:00
2015-05-15 17:20:26 +02:00
return [];
2015-05-20 08:05:08 +02:00
};
2015-05-15 16:27:35 +02:00
2015-05-20 08:05:08 +02:00
module.getCardData = function(issueKey, callback) {
module.getIssueData(issueKey, function(data) {
2015-05-15 16:27:35 +02:00
var issueData = {};
issueData.key = data.id;
issueData.type = data.kind.toLowerCase();
issueData.summary = data.name;
issueData.description = data.description;
if (data.owned_by && data.owned_by.length > 0) {
issueData.assignee = data.owner_ids[0].name;
}
if (data.deadline) {
issueData.dueDate = new Date(data.deadline).format('D d.m.');
}
2015-05-30 01:34:05 +02:00
// TODO
2015-05-15 16:27:35 +02:00
issueData.hasAttachment = false;
issueData.storyPoints = data.estimate;
// TODO
// issueData.epicKey = data.fields.epicLink;
// if ( issueData.epicKey ) {
// getIssueDataPivotalTracker(issueData.epicKey , function(data) {
// issueData.epicName = data.fields.epicName;
// }, false);
// }
issueData.url = data.url;
callback(issueData);
});
2015-05-20 08:05:08 +02:00
};
2015-05-15 16:27:35 +02:00
2015-05-20 08:05:08 +02:00
module.getIssueData = function(issueKey, callback, async) {
2015-05-15 16:27:35 +02:00
async = typeof async !== 'undefined' ? async : true;
//http://www.pivotaltracker.com/help/api
var url = 'https://www.pivotaltracker.com/services/v5/stories/' + issueKey + "?fields=name,kind,description,story_type,owned_by(name),comments(file_attachments(kind)),estimate,deadline";
2015-05-15 17:20:26 +02:00
console.log("IssueUrl: " + url);
//console.log("Issue: " + issueKey + " Loading...");
2015-05-15 16:27:35 +02:00
jQuery.ajax({
type: 'GET',
url: url,
data: {},
dataType: 'json',
async: async,
success: function(responseData) {
2015-05-15 17:20:26 +02:00
//console.log("Issue: " + issueKey + " Loaded!");
2015-05-15 16:27:35 +02:00
callback(responseData);
},
});
2015-05-20 08:05:08 +02:00
};
return module;
}({}));
var trelloFunctions = (function (module) {
module.getSelectedIssueKeyList = function() {
//Card View
if (/.*\/c\/.*/g.test(document.URL)) {
return [document.URL.replace(/.*\/c\/([^/]*).*/g, '$1')];
}
return [];
};
module.getCardData = function(issueKey, callback) {
module.getIssueData(issueKey, function(data) {
var issueData = {};
issueData.key = data.idShort;
// TODO get kind from label name
// issueData.type = data.kind.toLowerCase();
issueData.summary = data.name;
issueData.description = data.desc;
if (data.members && data.members.length > 0) {
issueData.assignee = data.members[0].fullName;
issueData.avatarUrl = "https://trello-avatars.s3.amazonaws.com/"+data.members[0].avatarHash+"/170.png";
}
if (data.due) {
issueData.dueDate = new Date(data.due).format('D d.m.');
}
issueData.hasAttachment = data.attachments > 0;
issueData.url = data.shortUrl;
callback(issueData);
});
};
module.getIssueData = function(issueKey, callback, async) {
async = typeof async !== 'undefined' ? async : true;
//http://www.pivotaltracker.com/help/api
var url = "https://trello.com/1/cards/" + issueKey + "?members=true";
console.log("IssueUrl: " + url);
//console.log("Issue: " + issueKey + " Loading...");
jQuery.ajax({
type: 'GET',
url: url,
data: {},
dataType: 'json',
async: async,
success: function(responseData) {
//console.log("Issue: " + issueKey + " Loaded!");
callback(responseData);
},
});
};
return module;
}({}));
2015-05-15 16:27:35 +02:00
})();