2015-05-15 16:27:35 +02:00
|
|
|
(function() {
|
2015-11-27 11:35:07 +01:00
|
|
|
// Public Instances
|
|
|
|
|
// Jira: https://connect.atlassian.net/browse/NERDS-33286
|
|
|
|
|
// PivotTracker: https://www.pivotaltracker.com/n/projects/510733
|
|
|
|
|
// Trello: https://trello.com/b/8zlPSh70/spike
|
|
|
|
|
// YouTrack: http://qoomon.myjetbrains.com/youtrack/dashboard
|
2015-06-07 13:39:29 +02:00
|
|
|
var global = {};
|
2015-12-11 11:16:50 +01:00
|
|
|
global.version = "4.3.6";
|
2015-11-25 12:17:08 +01:00
|
|
|
global.issueTrackingUrl = "https://github.com/qoomon/Jira-Issue-Card-Printer";
|
2015-11-25 08:51:24 +01:00
|
|
|
global.isDev = document.currentScript == null;
|
2015-06-07 13:39:29 +02:00
|
|
|
global.isProd = !global.isDev;
|
|
|
|
|
|
|
|
|
|
window.addEventListener("error", function(event) {
|
|
|
|
|
var error = event.error;
|
|
|
|
|
console.log("ERROR: " + error.stack);
|
|
|
|
|
if (global.isProd) {
|
|
|
|
|
ga('send', 'exception', {
|
|
|
|
|
'exDescription': error.message,
|
|
|
|
|
'exFatal': true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-12-16 18:44:22 +01:00
|
|
|
init().then(function(){
|
|
|
|
|
return main();
|
|
|
|
|
}).catch(function(cause){
|
|
|
|
|
console.log("ERROR " + cause.stack);
|
|
|
|
|
alert("Sorry something went wrong.\n\nPlease create an issue at " + global.issueTrackingUrl + "\n\n" + cause.stack);
|
2015-06-07 13:39:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function main() {
|
2015-11-27 07:52:48 +01:00
|
|
|
var promises = [];
|
|
|
|
|
|
2015-11-25 08:45:13 +01:00
|
|
|
console.log("Run...")
|
2015-06-07 13:39:29 +02:00
|
|
|
// determine application
|
|
|
|
|
if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) {
|
|
|
|
|
console.log("App: " + "Jira");
|
|
|
|
|
global.appFunctions = jiraFunctions;
|
|
|
|
|
} else if (/.*pivotaltracker.com\/.*/g.test(document.URL)) {
|
|
|
|
|
console.log("App: " + "PivotalTracker");
|
|
|
|
|
global.appFunctions = pivotalTrackerFunctions;
|
|
|
|
|
} else if (/.*trello.com\/.*/g.test(document.URL)) {
|
|
|
|
|
console.log("App: " + "Trello");
|
|
|
|
|
global.appFunctions = trelloFunctions;
|
2015-12-16 18:50:00 +01:00
|
|
|
} else if (/.*myjetbrains.com\/youtrack\/.*/g.test(document.URL) || /.*youtrack.jetbrains.com\/.*/g.test(document.URL) ) {
|
2015-06-07 13:39:29 +02:00
|
|
|
console.log("App: " + "YouTrack");
|
|
|
|
|
global.appFunctions = youTrackFunctions;
|
|
|
|
|
} else {
|
2015-11-25 12:17:08 +01:00
|
|
|
alert("Unsupported app. Please create an issue at " + global.issueTrackingUrl);
|
2015-06-07 13:39:29 +02:00
|
|
|
return;
|
2015-05-12 12:04:40 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// collect selcted issues
|
|
|
|
|
var issueKeyList = global.appFunctions.getSelectedIssueKeyList();
|
|
|
|
|
if (issueKeyList.length <= 0) {
|
|
|
|
|
alert("Please select at least one issue.");
|
|
|
|
|
return;
|
2015-12-11 11:30:09 +01:00
|
|
|
} else if (issueKeyList.length > 30) {
|
2015-11-27 07:52:48 +01:00
|
|
|
confirm("Are you sure you want select " + issueKeyList.length + " issues?");
|
|
|
|
|
return;
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-05-17 02:21:14 +02:00
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
//preconditions
|
|
|
|
|
if (jQuery("#card-printer-iframe").length > 0) {
|
|
|
|
|
alert("Card Printer already opened!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create iFrame
|
|
|
|
|
var appFrame = document.createElement('iframe');
|
|
|
|
|
appFrame.id = "card-printer-iframe";
|
|
|
|
|
jQuery(appFrame).css({
|
|
|
|
|
'position': 'fixed',
|
|
|
|
|
'height': '100%',
|
|
|
|
|
'width': '100%',
|
|
|
|
|
'top': '0',
|
|
|
|
|
'left': '0',
|
|
|
|
|
'background': 'rgba(0, 0, 0, 0.5)',
|
|
|
|
|
'boxSizing': 'border-box',
|
|
|
|
|
'wordWrap': 'break-word',
|
|
|
|
|
'zIndex': '99999'
|
|
|
|
|
});
|
|
|
|
|
jQuery("body").append(appFrame);
|
|
|
|
|
appFrame.window = appFrame.contentWindow;
|
|
|
|
|
appFrame.document = appFrame.window.document;
|
|
|
|
|
global.appFrame = appFrame;
|
|
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// open print preview
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("head", appFrame.document).prepend(printPreviewElementStyle());
|
|
|
|
|
jQuery("body", appFrame.document).append(printPreviewElement());
|
|
|
|
|
|
|
|
|
|
var printFrame = jQuery("#card-print-dialog-content-iframe", appFrame.document)[0];
|
|
|
|
|
printFrame.window = printFrame.contentWindow;
|
|
|
|
|
printFrame.document = printFrame.window.document;
|
|
|
|
|
global.printFrame = printFrame;
|
|
|
|
|
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
printFrame.contentWindow.addEventListener("resize", function() {
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
|
|
|
|
});
|
2015-12-16 18:21:30 +01:00
|
|
|
printFrame.contentWindow.matchMedia("print").addListener(function() {
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
|
|
|
|
});
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-11-27 14:06:46 +01:00
|
|
|
var settings = global.settings;
|
|
|
|
|
|
|
|
|
|
// restore UI state
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("#scaleRange", appFrame.document).val(settings.scale);
|
|
|
|
|
jQuery("#scaleRange", appFrame.document).parent().find("output").val(settings.scale);
|
|
|
|
|
jQuery("#rowCount", appFrame.document).val(settings.rowCount);
|
|
|
|
|
jQuery("#columnCount", appFrame.document).val(settings.colCount);
|
|
|
|
|
|
|
|
|
|
jQuery("#single-card-page-checkbox", appFrame.document).attr('checked', settings.singleCardPage );
|
|
|
|
|
jQuery("#description-checkbox", appFrame.document).attr('checked', !settings.hideDescription );
|
|
|
|
|
jQuery("#assignee-checkbox", appFrame.document).attr('checked', !settings.hideAssignee );
|
|
|
|
|
jQuery("#due-date-checkbox", appFrame.document).attr('checked', !settings.hideDueDate );
|
|
|
|
|
jQuery("#qr-code-checkbox", appFrame.document).attr('checked', !settings.hideQrCode );
|
|
|
|
|
|
|
|
|
|
jQuery("#card-print-dialog-title", appFrame.document).text("Card Printer " + global.version + " - Loading issues...");
|
2015-11-27 07:52:48 +01:00
|
|
|
promises.push(renderCards(issueKeyList).then(function() {
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("#card-print-dialog-title", appFrame.document).text("Card Printer " + global.version);
|
2015-11-27 07:52:48 +01:00
|
|
|
}));
|
2015-06-01 16:20:12 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
if (global.isProd) {
|
|
|
|
|
ga('send', 'pageview');
|
2015-06-01 16:20:12 +02:00
|
|
|
}
|
2015-11-27 11:35:07 +01:00
|
|
|
|
2015-11-27 07:52:48 +01:00
|
|
|
return Promise.all(promises);
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-06-01 16:20:12 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
function init() {
|
2015-11-25 12:01:42 +01:00
|
|
|
var promises = [];
|
|
|
|
|
|
2015-11-25 08:45:13 +01:00
|
|
|
console.log("Init...")
|
2015-06-07 13:39:29 +02:00
|
|
|
addStringFunctions();
|
2015-06-01 16:20:12 +02:00
|
|
|
|
2015-11-27 14:06:46 +01:00
|
|
|
loadSettings();
|
|
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
global.hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/";
|
|
|
|
|
if (global.isDev) {
|
|
|
|
|
console.log("DEVELOPMENT");
|
|
|
|
|
global.hostOrigin = "https://rawgit.com/qoomon/Jira-Issue-Card-Printer/develop/";
|
2015-05-12 12:04:40 +02:00
|
|
|
}
|
2015-06-07 13:39:29 +02:00
|
|
|
global.resourceOrigin = global.hostOrigin + "resources/";
|
2015-05-12 12:04:40 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
if (global.isProd) {
|
|
|
|
|
initGoogleAnalytics();
|
|
|
|
|
}
|
2015-11-25 12:01:42 +01:00
|
|
|
|
2015-11-26 19:52:35 +01:00
|
|
|
promises.push(httpGetCORS(global.hostOrigin + "card.html").then(function(data){
|
2015-11-25 08:45:13 +01:00
|
|
|
global.cardHtml = data;
|
|
|
|
|
}));
|
2015-11-25 12:09:32 +01:00
|
|
|
|
2015-11-26 19:52:35 +01:00
|
|
|
promises.push(httpGetCORS(global.hostOrigin + "card.css").then(function(data){
|
2015-11-25 12:09:32 +01:00
|
|
|
global.cardCss = data.replace(/https:\/\/qoomon.github.io\/Jira-Issue-Card-Printer\/resources/g, global.resourceOrigin);
|
|
|
|
|
}));
|
|
|
|
|
|
2015-11-26 19:52:35 +01:00
|
|
|
promises.push(httpGetCORS(global.hostOrigin + "printPreview.html").then(function(data){
|
2015-11-25 12:56:03 +01:00
|
|
|
global.printPreviewHtml = data
|
|
|
|
|
}));
|
|
|
|
|
|
2015-11-26 19:52:35 +01:00
|
|
|
promises.push(httpGetCORS(global.hostOrigin + "printPreview.css").then(function(data){
|
2015-11-25 12:56:03 +01:00
|
|
|
global.printPreviewCss = data.replace(/https:\/\/qoomon.github.io\/Jira-Issue-Card-Printer\/resources/g, global.resourceOrigin);
|
|
|
|
|
}));
|
|
|
|
|
|
2015-11-25 08:45:13 +01:00
|
|
|
return Promise.all(promises);
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-06-03 08:36:28 +02:00
|
|
|
|
2015-11-27 14:06:46 +01:00
|
|
|
function saveSettings(){
|
|
|
|
|
var settings = global.settings;
|
2015-11-30 13:26:37 +01:00
|
|
|
writeCookie("card_printer_scale", settings.scale);
|
|
|
|
|
writeCookie("card_printer_row_count", settings.rowCount);
|
|
|
|
|
writeCookie("card_printer_column_count", settings.colCount);
|
|
|
|
|
|
2015-11-27 14:06:46 +01:00
|
|
|
writeCookie("card_printer_single_card_page", settings.singleCardPage);
|
|
|
|
|
writeCookie("card_printer_hide_description", settings.hideDescription);
|
|
|
|
|
writeCookie("card_printer_hide_assignee", settings.hideAssignee);
|
|
|
|
|
writeCookie("card_printer_hide_due_date", settings.hideDueDate);
|
2015-12-10 14:15:05 +01:00
|
|
|
writeCookie("card_printer_hide_qr_code", settings.hideQrCode);
|
2015-11-27 14:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadSettings(){
|
|
|
|
|
var settings = global.settings = global.settings || {};
|
2015-11-30 17:06:49 +01:00
|
|
|
settings.scale = parseFloat(readCookie("card_printer_scale")) || 0.0;
|
2015-11-27 15:02:05 +01:00
|
|
|
settings.rowCount = parseInt(readCookie("card_printer_row_count2")) || 2;
|
|
|
|
|
settings.colCount = parseInt(readCookie("card_printer_column_count")) || 1;
|
|
|
|
|
|
|
|
|
|
settings.singleCardPage = parseBool(readCookie("card_printer_single_card_page"), true );
|
|
|
|
|
settings.hideDescription = parseBool(readCookie("card_printer_hide_description"), false);
|
|
|
|
|
settings.hideAssignee = parseBool(readCookie("card_printer_hide_assignee"), false);
|
|
|
|
|
settings.hideDueDate = parseBool(readCookie("card_printer_hide_due_date"), false);
|
2015-12-10 14:15:05 +01:00
|
|
|
settings.hideQrCode = parseBool(readCookie("card_printer_hide_qr_code"), false);
|
2015-11-27 14:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
function print() {
|
|
|
|
|
if (global.isProd) {
|
2015-12-16 18:21:30 +01:00
|
|
|
ga('send', 'event', 'button', 'click', 'print', jQuery(".card", global.printFrame.contentWindow.document).length);
|
2015-05-12 12:04:40 +02:00
|
|
|
}
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
global.printFrame.contentWindow.print();
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-05-12 13:19:43 +02:00
|
|
|
|
2015-11-25 12:01:42 +01:00
|
|
|
function renderCards(issueKeyList) {
|
2015-11-25 12:56:03 +01:00
|
|
|
var promises = [];
|
2015-06-02 14:16:40 +02:00
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
var printFrame = global.printFrame;
|
2015-06-02 14:16:40 +02:00
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
printFrame.document.open();
|
|
|
|
|
printFrame.document.write("<head/><body></body>");
|
2015-06-02 14:16:40 +02:00
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("head", printFrame.document).append(cardElementStyle());
|
|
|
|
|
jQuery("body", printFrame.document).append("<div id='preload'/>");
|
|
|
|
|
jQuery("#preload", printFrame.document).append("<div class='zigzag'/>");
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
console.log("load " + issueKeyList.length + " issues...");
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
jQuery.each(issueKeyList, function(index, issueKey) {
|
2015-11-25 08:45:13 +01:00
|
|
|
var card = cardElement(issueKey);
|
|
|
|
|
card.attr("index", index);
|
|
|
|
|
card.hide();
|
|
|
|
|
card.find('.issue-id').text(issueKey);
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("body", printFrame.document).append(card);
|
2015-11-25 12:01:42 +01:00
|
|
|
|
|
|
|
|
promises.push(global.appFunctions.getCardData(issueKey).then(function(cardData) {
|
2015-11-26 19:52:35 +01:00
|
|
|
console.log("cardData: " + JSON.stringify(cardData,2,2));
|
2015-06-07 13:39:29 +02:00
|
|
|
if (global.isProd) {
|
|
|
|
|
ga('send', 'event', 'card', 'generate', cardData.type);
|
|
|
|
|
}
|
2015-11-25 08:45:13 +01:00
|
|
|
fillCard(card, cardData);
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
2015-11-25 12:56:03 +01:00
|
|
|
card.show();
|
2015-11-25 12:01:42 +01:00
|
|
|
}));
|
2015-06-07 13:39:29 +02:00
|
|
|
});
|
|
|
|
|
|
2015-11-25 12:56:03 +01:00
|
|
|
console.log("wait for issues loaded...");
|
2015-11-25 12:01:42 +01:00
|
|
|
return Promise.all(promises).then(function() {
|
2015-06-07 13:39:29 +02:00
|
|
|
console.log("...all issues loaded.");
|
2015-11-25 12:01:42 +01:00
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery(printFrame.window).load(function() {
|
2015-06-07 13:39:29 +02:00
|
|
|
console.log("...all resources loaded.");
|
2015-11-25 12:01:42 +01:00
|
|
|
});
|
2015-06-07 13:39:29 +02:00
|
|
|
console.log("wait for resources loaded...");
|
2015-12-16 18:21:30 +01:00
|
|
|
printFrame.document.close();
|
2015-12-11 11:30:09 +01:00
|
|
|
redrawCards();
|
2015-11-27 07:52:48 +01:00
|
|
|
});
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
function redrawCards() {
|
|
|
|
|
styleCards();
|
|
|
|
|
scaleCards();
|
|
|
|
|
cropCards();
|
2015-12-16 18:21:30 +01:00
|
|
|
resizeIframe(global.printFrame);
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-05-12 11:35:23 +02:00
|
|
|
|
|
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
function fillCard(card, data) {
|
|
|
|
|
//Key
|
|
|
|
|
card.find('.issue-id').text(data.key);
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//Type
|
|
|
|
|
card.find(".issue-icon").attr("type", data.type);
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//Summary
|
|
|
|
|
card.find('.issue-summary').text(data.summary);
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//Description
|
|
|
|
|
if (data.description) {
|
|
|
|
|
card.find('.issue-description').html(data.description);
|
|
|
|
|
} else {
|
|
|
|
|
card.find(".issue-description").addClass("hidden");
|
|
|
|
|
}
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//Assignee
|
|
|
|
|
if (data.assignee) {
|
|
|
|
|
if (data.avatarUrl) {
|
|
|
|
|
card.find(".issue-assignee").css("background-image", "url('" + data.avatarUrl + "')");
|
|
|
|
|
} else {
|
|
|
|
|
card.find(".issue-assignee").text(data.assignee[0].toUpperCase());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-12-10 14:15:05 +01:00
|
|
|
card.find(".issue-assignee").remove();
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//Due-Date
|
|
|
|
|
if (data.dueDate) {
|
|
|
|
|
card.find(".issue-due-date").text(data.dueDate);
|
|
|
|
|
} else {
|
2015-12-10 14:15:05 +01:00
|
|
|
card.find(".issue-due-box").remove();
|
2015-05-12 12:04:40 +02:00
|
|
|
}
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//Attachment
|
|
|
|
|
if (data.hasAttachment) {} else {
|
2015-12-10 14:15:05 +01:00
|
|
|
card.find('.issue-attachment').remove();
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//Story Points
|
|
|
|
|
if (data.storyPoints) {
|
|
|
|
|
card.find(".issue-estimate").text(data.storyPoints);
|
|
|
|
|
} else {
|
2015-12-10 14:15:05 +01:00
|
|
|
card.find(".issue-estimate").remove();
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-06-02 14:16:40 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//Epic
|
2015-11-26 19:52:35 +01:00
|
|
|
if (data.superIssue) {
|
|
|
|
|
card.find(".issue-epic-id").text(data.superIssue.key);
|
|
|
|
|
card.find(".issue-epic-name").text(data.superIssue.summary);
|
2015-06-07 13:39:29 +02:00
|
|
|
} else {
|
2015-12-10 14:15:05 +01:00
|
|
|
card.find(".issue-epic-box").remove();
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-06-02 22:36:36 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//QR-Code
|
|
|
|
|
var qrCodeUrl = 'https://chart.googleapis.com/chart?cht=qr&chs=256x256&chld=L|1&chl=' + encodeURIComponent(data.url);
|
|
|
|
|
card.find(".issue-qr-code").css("background-image", "url('" + qrCodeUrl + "')");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function styleCards() {
|
2015-11-27 14:06:46 +01:00
|
|
|
var settings = global.settings;
|
2015-12-16 18:21:30 +01:00
|
|
|
var printFrame = global.printFrame
|
2015-06-07 13:39:29 +02:00
|
|
|
|
|
|
|
|
// hide/show description
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery(".issue-description", printFrame.document).toggle(!settings.hideDescription);
|
2015-06-07 13:39:29 +02:00
|
|
|
// hide/show assignee
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery(".issue-assignee", printFrame.document).toggle(!settings.hideAssignee);
|
2015-06-07 13:39:29 +02:00
|
|
|
// hide/show assignee
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery(".issue-due-box", printFrame.document).toggle(!settings.hideDueDate);
|
2015-12-10 14:15:05 +01:00
|
|
|
// hide/show cr code
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery(".issue-qr-code", printFrame.document).toggle(!settings.hideQrCode);
|
2015-06-02 22:36:36 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// enable/disable single card page
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery(".card", printFrame.document).css({ 'page-break-after' : '', 'float' : '', 'margin-bottom': '' });
|
2015-11-27 14:06:46 +01:00
|
|
|
if (settings.singleCardPage) {
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery(".card", printFrame.document).css({ 'page-break-after': 'always', 'float': 'none', 'margin-bottom': '10px' });
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scaleCards() {
|
2015-11-27 14:06:46 +01:00
|
|
|
var settings = global.settings;
|
2015-12-16 18:21:30 +01:00
|
|
|
var printFrame = global.printFrame;
|
2015-11-27 17:59:38 +01:00
|
|
|
|
2015-11-30 13:31:06 +01:00
|
|
|
var scaleValue = settings.scale * 2.0;
|
2015-11-27 17:59:38 +01:00
|
|
|
var scaleRoot;
|
2015-11-30 13:29:00 +01:00
|
|
|
if(scaleValue < 0) {
|
|
|
|
|
scaleRoot = 1.0 / (1.0 - scaleValue);
|
2015-11-27 17:59:38 +01:00
|
|
|
} else {
|
2015-11-30 13:29:00 +01:00
|
|
|
scaleRoot = 1.0 * (1.0 + scaleValue);
|
2015-11-27 17:59:38 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-27 14:06:46 +01:00
|
|
|
var rowCount = settings.rowCount;
|
|
|
|
|
var columnCount = settings.colCount;
|
2015-06-07 13:39:29 +02:00
|
|
|
|
|
|
|
|
// scale
|
|
|
|
|
|
2015-11-24 09:44:23 +01:00
|
|
|
// reset scale
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("html", printFrame.document).css("font-size", scaleRoot + "cm");
|
|
|
|
|
jQuery("#styleColumnCount", printFrame.document).remove();
|
|
|
|
|
jQuery("#styleRowCount", printFrame.document).remove();
|
2015-06-07 13:39:29 +02:00
|
|
|
|
2015-11-27 16:35:19 +01:00
|
|
|
// calculate scale
|
|
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
var bodyElement = jQuery("body", printFrame.document);
|
2015-11-27 16:35:19 +01:00
|
|
|
var cardMaxWidth = Math.floor(bodyElement.outerWidth() / columnCount);
|
|
|
|
|
var cardMaxHeight = Math.floor(bodyElement.outerHeight() / rowCount);
|
2015-06-07 13:39:29 +02:00
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
var cardElement = jQuery(".card", printFrame.document);
|
2015-11-27 16:35:19 +01:00
|
|
|
var cardMinWidth = cardElement.css("min-width").replace("px", "");
|
|
|
|
|
var cardMinHeight = cardElement.css("min-height").replace("px", "");
|
2015-06-07 13:39:29 +02:00
|
|
|
|
2015-11-27 16:35:19 +01:00
|
|
|
var scaleWidth = cardMaxWidth / cardMinWidth ;
|
|
|
|
|
var scaleHeight = cardMaxHeight / cardMinHeight ;
|
2015-11-27 07:52:48 +01:00
|
|
|
var scale = Math.min(scaleWidth, scaleHeight, 1);
|
2015-11-27 16:35:19 +01:00
|
|
|
|
2015-11-27 17:12:33 +01:00
|
|
|
// scale
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("html", printFrame.document).css("font-size", ( scaleRoot * scale ) + "cm");
|
2015-11-27 17:12:33 +01:00
|
|
|
|
2015-11-24 09:02:18 +01:00
|
|
|
// size
|
|
|
|
|
|
|
|
|
|
// size horizontal
|
|
|
|
|
var style = document.createElement('style');
|
|
|
|
|
style.id = 'styleColumnCount';
|
|
|
|
|
style.type = 'text/css';
|
2015-11-27 17:59:38 +01:00
|
|
|
style.innerHTML = ".card { width: calc( 100% / " + columnCount + " ); }"
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("head", printFrame.document).append(style);
|
2015-11-24 09:02:18 +01:00
|
|
|
|
|
|
|
|
// size horizontal
|
|
|
|
|
var style = document.createElement('style');
|
|
|
|
|
style.id = 'styleRowCount';
|
|
|
|
|
style.type = 'text/css';
|
2015-11-27 17:59:38 +01:00
|
|
|
style.innerHTML = ".card { height: calc( 100% / " + rowCount + " ); }"
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("head", printFrame.document).append(style);
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cropCards() {
|
2015-12-16 18:21:30 +01:00
|
|
|
var cardElements = global.printFrame.document.querySelectorAll(".card");
|
2015-06-07 13:39:29 +02:00
|
|
|
forEach(cardElements, function(cardElement) {
|
|
|
|
|
var cardContent = cardElement.querySelectorAll(".card-body")[0];
|
|
|
|
|
if (cardContent.scrollHeight > cardContent.offsetHeight) {
|
|
|
|
|
cardContent.classList.add("zigzag");
|
|
|
|
|
} else {
|
|
|
|
|
cardContent.classList.remove("zigzag");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
function forEach(array, callback) {
|
|
|
|
|
for (i = 0; i < array.length; i++) {
|
|
|
|
|
callback(array[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closePrintPreview() {
|
2015-12-16 18:21:30 +01:00
|
|
|
jQuery("#card-printer-iframe").remove();
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
|
|
|
|
|
// http://www.cssdesk.com/T9hXg
|
|
|
|
|
|
2015-11-25 12:56:03 +01:00
|
|
|
function printPreviewElement() {
|
|
|
|
|
var result = jQuery('<div/>').html(global.printPreviewHtml).contents();
|
2015-06-07 13:39:29 +02:00
|
|
|
|
|
|
|
|
// info
|
|
|
|
|
result.find("#report-issue").click(function(event) {
|
|
|
|
|
window.open('https://github.com/qoomon/Jira-Issue-Card-Printer/issues');
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
result.find("#about").click(function(event) {
|
|
|
|
|
window.open('http://qoomon.blogspot.de/2014/01/jira-issue-card-printer-bookmarklet.html');
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2015-06-02 22:36:36 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// enable single card page
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
result.find("#single-card-page-checkbox").click(function() {
|
2015-11-27 14:06:46 +01:00
|
|
|
global.settings.singleCardPage = this.checked;
|
|
|
|
|
saveSettings();
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// hide description
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-12-11 11:16:50 +01:00
|
|
|
result.find("#description-checkbox").click(function() {
|
|
|
|
|
global.settings.hideDescription = !this.checked;
|
2015-11-27 14:06:46 +01:00
|
|
|
saveSettings();
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2015-06-02 13:42:42 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// show assignee
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-12-11 11:16:50 +01:00
|
|
|
result.find("#assignee-checkbox").click(function() {
|
|
|
|
|
global.settings.hideAssignee = !this.checked;
|
2015-11-27 14:06:46 +01:00
|
|
|
saveSettings();
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// show due date
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-12-11 11:16:50 +01:00
|
|
|
result.find("#due-date-checkbox").click(function() {
|
|
|
|
|
global.settings.hideDueDate = !this.checked;
|
2015-11-27 14:06:46 +01:00
|
|
|
saveSettings();
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-12-10 14:15:05 +01:00
|
|
|
// show QR Code
|
|
|
|
|
|
2015-12-11 11:16:50 +01:00
|
|
|
result.find("#qr-code-checkbox").click(function() {
|
2015-12-11 11:30:09 +01:00
|
|
|
global.settings.hideQrCode = !this.checked;
|
2015-12-10 14:15:05 +01:00
|
|
|
saveSettings();
|
|
|
|
|
redrawCards();
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// scale font
|
2015-05-31 21:55:14 +02:00
|
|
|
|
2015-11-30 13:26:37 +01:00
|
|
|
result.find("#scaleRange").on("input", function() {
|
2015-11-27 07:52:48 +01:00
|
|
|
global.settings.scale = jQuery(this).val();
|
2015-11-27 14:06:46 +01:00
|
|
|
saveSettings();
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
|
|
|
|
});
|
2015-06-02 14:16:40 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// grid
|
2015-05-31 21:55:14 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
result.find("#rowCount").on("input", function() {
|
2015-11-27 07:52:48 +01:00
|
|
|
global.settings.rowCount = jQuery(this).val();
|
2015-11-27 14:06:46 +01:00
|
|
|
saveSettings();
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
|
|
|
|
});
|
|
|
|
|
result.find("#rowCount").click(function() {
|
|
|
|
|
this.select();
|
|
|
|
|
});
|
2015-05-31 21:55:14 +02:00
|
|
|
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
result.find("#columnCount").on("input", function() {
|
2015-11-27 07:52:48 +01:00
|
|
|
global.settings.colCount = jQuery(this).val();
|
2015-11-27 14:06:46 +01:00
|
|
|
saveSettings();
|
2015-06-07 13:39:29 +02:00
|
|
|
redrawCards();
|
|
|
|
|
});
|
|
|
|
|
result.find("#columnCount").click(function() {
|
|
|
|
|
this.select();
|
|
|
|
|
});
|
2015-04-18 01:34:10 +02:00
|
|
|
|
|
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// print
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
result.find("#card-print-dialog-print")
|
|
|
|
|
.click(function(event) {
|
|
|
|
|
print();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2015-05-12 11:35:23 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// closePrintPreview
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
result.find("#card-print-dialog-cancel")
|
|
|
|
|
.click(function(event) {
|
|
|
|
|
closePrintPreview();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
result.click(function(event) {
|
2015-11-25 12:56:03 +01:00
|
|
|
if (event.target == this) {
|
|
|
|
|
closePrintPreview();
|
|
|
|
|
}
|
2015-06-07 13:39:29 +02:00
|
|
|
return true;
|
|
|
|
|
});
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
jQuery(document).keyup(function(e) {
|
2015-11-25 12:56:03 +01:00
|
|
|
if (e.keyCode == 27) { // ESC
|
2015-06-07 13:39:29 +02:00
|
|
|
closePrintPreview();
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// prevent background scrolling
|
|
|
|
|
result.scroll(function(event) {
|
2015-11-25 12:56:03 +01:00
|
|
|
return false;
|
2015-06-07 13:39:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 18:21:30 +01:00
|
|
|
function printPreviewElementStyle() {
|
2015-06-07 13:39:29 +02:00
|
|
|
var result = jQuery(document.createElement('style'))
|
|
|
|
|
.attr("type", "text/css")
|
2015-11-25 12:56:03 +01:00
|
|
|
.html(global.printPreviewCss);
|
2015-06-07 13:39:29 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-24 08:31:30 +01:00
|
|
|
// card layout: http://jsfiddle.net/qoomon/ykbLb2pw/76
|
2015-11-25 12:01:42 +01:00
|
|
|
|
2015-11-25 08:45:13 +01:00
|
|
|
function cardElement(issueKey) {
|
2015-11-25 12:56:03 +01:00
|
|
|
var result = jQuery('<div/>').html(global.cardHtml).contents()
|
2015-06-07 13:39:29 +02:00
|
|
|
.attr("id", issueKey)
|
2015-11-25 12:56:03 +01:00
|
|
|
return result;
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-25 12:56:03 +01:00
|
|
|
function cardElementStyle() {
|
2015-06-07 13:39:29 +02:00
|
|
|
var result = jQuery(document.createElement('style'))
|
|
|
|
|
.attr("type", "text/css")
|
2015-11-25 12:09:32 +01:00
|
|
|
.html(global.cardCss);
|
2015-06-07 13:39:29 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
|
|
|
|
|
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-11-27 15:02:05 +01:00
|
|
|
function parseBool(text, def){
|
|
|
|
|
if(text == 'true') return true;
|
|
|
|
|
else if ( text == 'false') return false;
|
|
|
|
|
else return def;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function appendScript(url, callback) {
|
|
|
|
|
|
|
|
|
|
var head = document.getElementsByTagName('head')[0];
|
|
|
|
|
var script = document.createElement('script');
|
|
|
|
|
script.src = url;
|
|
|
|
|
|
|
|
|
|
// Then bind the event to the callback function.
|
|
|
|
|
// There are several events for cross browser compatibility.
|
|
|
|
|
script.onreadystatechange = callback;
|
|
|
|
|
script.onload = callback;
|
|
|
|
|
|
|
|
|
|
head.appendChild(script);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function readCookie(name) {
|
2015-06-07 13:39:29 +02:00
|
|
|
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];
|
2015-05-30 01:34:05 +02:00
|
|
|
}
|
2015-11-27 15:02:05 +01:00
|
|
|
return null;
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function writeCookie(name, value) {
|
|
|
|
|
document.cookie = name + "=" + value;
|
|
|
|
|
}
|
2015-11-27 15:02:05 +01:00
|
|
|
|
2015-12-17 10:14:38 +01:00
|
|
|
function httpGetCORS(){
|
2015-12-17 19:42:44 +01:00
|
|
|
arguments[0] = 'https://jsonp.afeld.me/?url=' + arguments[0];
|
2015-12-17 10:34:25 +01:00
|
|
|
//arguments[0] = 'http://cors.io/?u=' + arguments[0];
|
2015-12-17 19:42:44 +01:00
|
|
|
//arguments[0] = 'https://crossorigin.me/' + arguments[0];
|
2015-12-17 10:14:38 +01:00
|
|
|
return httpGet.apply(this, arguments);
|
2015-11-27 15:02:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function httpGet(){
|
|
|
|
|
return Promise.resolve(jQuery.get.apply(this, arguments));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function httpGetJSON(){
|
|
|
|
|
return Promise.resolve(jQuery.getJSON.apply(this, arguments));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function multilineString(commentFunction) {
|
|
|
|
|
return commentFunction.toString()
|
|
|
|
|
.replace(/^[^\/]+\/\*!?/, '')
|
|
|
|
|
.replace(/\*\/[^\/]+$/, '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resizeIframe(iframe) {
|
2015-12-16 18:21:30 +01:00
|
|
|
iframe = jQuery(iframe);
|
2015-11-27 15:02:05 +01:00
|
|
|
iframe.height(iframe[0].contentWindow.document.body.height);
|
|
|
|
|
}
|
2015-06-07 13:39:29 +02:00
|
|
|
//############################################################################################################################
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
|
|
|
|
|
function addStringFunctions() {
|
|
|
|
|
|
|
|
|
|
//trim string - remove leading and trailing whitespaces
|
|
|
|
|
if (!String.prototype.trim) {
|
|
|
|
|
String.prototype.trim = function() {
|
|
|
|
|
return this.replace(/^\s+|\s+$/g, '');
|
|
|
|
|
};
|
2015-05-30 01:34:05 +02:00
|
|
|
}
|
2015-06-07 13:39:29 +02:00
|
|
|
|
|
|
|
|
if (!String.prototype.startsWith) {
|
|
|
|
|
String.prototype.startsWith = function(str) {
|
|
|
|
|
return this.slice(0, str.length) == str;
|
|
|
|
|
};
|
2015-05-30 01:34:05 +02:00
|
|
|
}
|
2015-05-31 21:55:14 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
if (!String.prototype.endsWith) {
|
|
|
|
|
String.prototype.endsWith = function(str) {
|
|
|
|
|
return this.slice(-str.length) == str;
|
|
|
|
|
};
|
2015-05-30 01:34:05 +02:00
|
|
|
}
|
2015-06-07 13:39:29 +02:00
|
|
|
|
|
|
|
|
if (!String.prototype.toCamelCase) {
|
|
|
|
|
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-05-30 01:34:05 +02:00
|
|
|
}
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-27 15:02:05 +01:00
|
|
|
function formatDate(date) {
|
|
|
|
|
var shortMonths = {'Jan': 1, 'Feb':2, 'Mar':3, 'Apr':4, 'May':5, 'Jun':6, 'Jul':7, 'Aug':8, 'Sep':9, 'Oct':10, 'Nov':11, 'Dec':12 };
|
|
|
|
|
var dateSplit = date.toString().split(" ");
|
|
|
|
|
// Mo 28.11.
|
|
|
|
|
return dateSplit[0] + " " + dateSplit[2] + "." + shortMonths[dateSplit[1]] + ".";
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// APP Specific Functions
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
//############################################################################################################################
|
|
|
|
|
|
|
|
|
|
var jiraFunctions = (function(module) {
|
|
|
|
|
|
|
|
|
|
module.getSelectedIssueKeyList = function() {
|
2015-10-27 13:01:44 +01:00
|
|
|
|
2015-11-09 18:03:41 +01:00
|
|
|
//Issues
|
|
|
|
|
if (/.*\/issues\/\?jql=.*/g.test(document.URL)) {
|
2015-10-27 13:01:44 +01:00
|
|
|
var jql = document.URL.replace(/.*\?jql=(.*)/, '$1');
|
|
|
|
|
var jqlIssues = [];
|
2015-11-27 07:52:48 +01:00
|
|
|
var url = '/rest/api/2/search?jql=' + jql + "&maxResults=500&fields=key";
|
2015-10-27 13:01:44 +01:00
|
|
|
console.log("IssueUrl: " + url);
|
|
|
|
|
//console.log("Issue: " + issueKey + " Loading...");
|
|
|
|
|
jQuery.ajax({
|
|
|
|
|
type: 'GET',
|
|
|
|
|
url: url,
|
|
|
|
|
data: {},
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
async: false,
|
|
|
|
|
success: function(responseData) {
|
|
|
|
|
console.log("responseData: " + responseData.issues);
|
2015-11-25 12:01:42 +01:00
|
|
|
|
2015-10-27 13:01:44 +01:00
|
|
|
jQuery.each(responseData.issues, function(key, value) {
|
|
|
|
|
jqlIssues.push(value.key);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
console.log("jqlIssues: " + jqlIssues);
|
|
|
|
|
return jqlIssues;
|
|
|
|
|
}
|
2015-11-25 12:01:42 +01:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//Browse
|
|
|
|
|
if (/.*\/browse\/.*/g.test(document.URL)) {
|
|
|
|
|
return [document.URL.replace(/.*\/browse\/([^?]*).*/, '$1')];
|
|
|
|
|
}
|
2015-11-25 12:01:42 +01:00
|
|
|
|
2015-11-09 17:53:47 +01:00
|
|
|
//Project
|
|
|
|
|
if (/.*\/projects\/.*/g.test(document.URL)) {
|
|
|
|
|
return [document.URL.replace(/.*\/projects\/[^\/]*\/[^\/]*\/([^?]*).*/, '$1')];
|
|
|
|
|
}
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// 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');
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
return [];
|
|
|
|
|
};
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-11-25 12:01:42 +01:00
|
|
|
module.getCardData = function(issueKey) {
|
|
|
|
|
var promises = [];
|
|
|
|
|
var issueData = {};
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-11-25 12:01:42 +01:00
|
|
|
promises.push(module.getIssueData(issueKey).then(function(data) {
|
2015-11-26 19:52:35 +01:00
|
|
|
var promises = [];
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.key = data.key;
|
|
|
|
|
issueData.type = data.fields.issuetype.name.toLowerCase();
|
|
|
|
|
issueData.summary = data.fields.summary;
|
2015-07-01 22:14:46 +02:00
|
|
|
issueData.description = data.renderedFields.description;
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
if (data.fields.duedate) {
|
2015-11-27 15:02:05 +01:00
|
|
|
issueData.dueDate = formatDate(new Date(data.fields.duedate));
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-05-17 02:21:14 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.hasAttachment = data.fields.attachment.length > 0;
|
|
|
|
|
issueData.storyPoints = data.fields.storyPoints;
|
2015-11-25 12:01:42 +01:00
|
|
|
|
2015-11-26 19:52:35 +01:00
|
|
|
if (data.fields.parent) {
|
|
|
|
|
promises.push(module.getIssueData(data.fields.parent.key).then(function(data) {
|
|
|
|
|
issueData.superIssue = {};
|
|
|
|
|
issueData.superIssue.key = data.key;
|
|
|
|
|
issueData.superIssue.summary = data.fields.summary;
|
|
|
|
|
}));
|
|
|
|
|
} else if (data.fields.epicLink) {
|
|
|
|
|
promises.push(module.getIssueData(data.fields.epicLink).then(function(data) {
|
|
|
|
|
issueData.superIssue = {};
|
|
|
|
|
issueData.superIssue.key = data.key;
|
|
|
|
|
issueData.superIssue.summary = data.fields.epicName;
|
2015-11-25 12:01:42 +01:00
|
|
|
}));
|
2015-01-27 22:49:37 +01:00
|
|
|
}
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.url = window.location.origin + "/browse/" + issueData.key;
|
2015-04-18 01:34:10 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
//LRS Specific field mapping
|
|
|
|
|
if (true) {
|
|
|
|
|
//Desired-Date
|
|
|
|
|
if (data.fields.desiredDate) {
|
2015-11-27 15:02:05 +01:00
|
|
|
issueData.dueDate = formatDate(new Date(data.fields.desiredDate));
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-02-09 18:16:15 +01:00
|
|
|
}
|
2015-11-26 19:52:35 +01:00
|
|
|
|
|
|
|
|
return Promise.all(promises);
|
2015-11-25 12:01:42 +01:00
|
|
|
}));
|
2015-04-30 02:35:46 +02:00
|
|
|
|
2015-11-26 19:52:35 +01:00
|
|
|
return Promise.all(promises).then(function(results){return issueData;});
|
2015-06-07 13:39:29 +02:00
|
|
|
};
|
|
|
|
|
|
2015-11-25 12:01:42 +01:00
|
|
|
module.getIssueData = function(issueKey) {
|
2015-06-07 13:39:29 +02:00
|
|
|
//https://docs.atlassian.com/jira/REST/latest/
|
|
|
|
|
var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names';
|
|
|
|
|
console.log("IssueUrl: " + url);
|
|
|
|
|
//console.log("Issue: " + issueKey + " Loading...");
|
2015-11-26 19:52:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
return httpGetJSON(url).then(function(responseData) {
|
2015-11-25 12:01:42 +01:00
|
|
|
//console.log("Issue: " + issueKey + " Loaded!");
|
|
|
|
|
// add custom fields with field names
|
|
|
|
|
jQuery.each(responseData.names, function(key, value) {
|
|
|
|
|
if (key.startsWith("customfield_")) {
|
|
|
|
|
var fieldName = value.toCamelCase();
|
|
|
|
|
//console.log("add new field: " + fieldName + " with value from " + key);
|
|
|
|
|
responseData.fields[fieldName] = responseData.fields[key];
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-11-26 19:52:35 +01:00
|
|
|
return responseData;
|
2015-06-07 13:39:29 +02:00
|
|
|
});
|
|
|
|
|
};
|
2015-04-30 02:35:46 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
return module;
|
|
|
|
|
}({}));
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
var youTrackFunctions = (function(module) {
|
2015-04-19 13:15:26 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
module.getSelectedIssueKeyList = function() {
|
|
|
|
|
//Detail View
|
|
|
|
|
if (/.*\/issue\/.*/g.test(document.URL)) {
|
|
|
|
|
return [document.URL.replace(/.*\/issue\/([^?]*).*/, '$1')];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Agile Board
|
|
|
|
|
if (/.*\/rest\/agile.*/g.test(document.URL)) {
|
|
|
|
|
return jQuery('div.sb-task-focused').map(function() {
|
|
|
|
|
return jQuery(this).attr('id');
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
return [];
|
|
|
|
|
};
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-11-25 12:01:42 +01:00
|
|
|
module.getCardData = function(issueKey) {
|
|
|
|
|
var promises = [];
|
|
|
|
|
var issueData = {};
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-11-27 11:35:07 +01:00
|
|
|
promises.push(module.getIssueData(issueKey).then(function(data) {
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.key = data.id;
|
|
|
|
|
issueData.type = data.field.type[0];
|
|
|
|
|
issueData.summary = data.field.summary;
|
|
|
|
|
issueData.description = data.field.description;
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
if (data.field.assignee) {
|
|
|
|
|
issueData.assignee = data.field.assignee[0].fullName;
|
|
|
|
|
}
|
2015-11-26 19:52:35 +01:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
if (data.field.attachments) {
|
|
|
|
|
issueData.hasAttachment = data.field.attachments.length > 0;
|
|
|
|
|
}
|
2015-11-26 19:52:35 +01:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.url = window.location.origin + "/youtrack/issue/" + issueData.key;
|
2015-11-27 11:35:07 +01:00
|
|
|
|
|
|
|
|
|
2015-11-25 12:01:42 +01:00
|
|
|
}));
|
2015-06-07 13:39:29 +02:00
|
|
|
|
2015-11-27 07:52:48 +01:00
|
|
|
return Promise.all(promises).then(function(results){return issueData;});
|
2015-06-07 13:39:29 +02:00
|
|
|
};
|
|
|
|
|
|
2015-11-25 12:01:42 +01:00
|
|
|
module.getIssueData = function(issueKey) {
|
2015-06-07 13:39:29 +02:00
|
|
|
var url = '/youtrack/rest/issue/' + issueKey + '?';
|
|
|
|
|
console.log("IssueUrl: " + url);
|
|
|
|
|
//console.log("Issue: " + issueKey + " Loading...");
|
2015-11-27 11:35:07 +01:00
|
|
|
return httpGetJSON(url).then(function(responseData) {
|
2015-11-25 12:01:42 +01:00
|
|
|
//console.log("Issue: " + issueKey + " Loaded!");
|
|
|
|
|
jQuery.each(responseData.field, function(key, value) {
|
|
|
|
|
// add fields with field names
|
|
|
|
|
var fieldName = value.name.toCamelCase();
|
|
|
|
|
//console.log("add new field: " + newFieldId + " with value from " + fieldName);
|
|
|
|
|
responseData.field[fieldName] = value.value;
|
|
|
|
|
});
|
2015-11-26 19:52:35 +01:00
|
|
|
return responseData;
|
2015-06-07 13:39:29 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return module;
|
|
|
|
|
}({}));
|
|
|
|
|
|
|
|
|
|
var pivotalTrackerFunctions = (function(module) {
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
module.getSelectedIssueKeyList = function() {
|
|
|
|
|
//Single Story
|
|
|
|
|
if (/.*\/stories\/.*/g.test(document.URL)) {
|
|
|
|
|
return [document.URL.replace(/.*\/stories\/([^?]*).*/, '$1')];
|
|
|
|
|
}
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-06-07 13:39:29 +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-06-07 13:39:29 +02:00
|
|
|
return [];
|
|
|
|
|
};
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-11-25 12:01:42 +01:00
|
|
|
module.getCardData = function(issueKey) {
|
|
|
|
|
var promises = [];
|
|
|
|
|
var issueData = {};
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-11-27 11:35:07 +01:00
|
|
|
promises.push(module.getIssueData(issueKey).then(function(data) {
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.key = data.id;
|
|
|
|
|
issueData.type = data.kind.toLowerCase();
|
|
|
|
|
issueData.summary = data.name;
|
|
|
|
|
issueData.description = data.description;
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
if (data.owned_by && data.owned_by.length > 0) {
|
|
|
|
|
issueData.assignee = data.owner_ids[0].name;
|
|
|
|
|
}
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
if (data.deadline) {
|
2015-11-27 15:02:05 +01:00
|
|
|
issueData.dueDate = formatDate(new Date(data.deadline));
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// TODO
|
|
|
|
|
issueData.hasAttachment = false;
|
|
|
|
|
issueData.storyPoints = data.estimate;
|
2015-05-15 16:27:35 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.url = data.url;
|
2015-11-25 12:01:42 +01:00
|
|
|
}));
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-11-27 07:52:48 +01:00
|
|
|
return Promise.all(promises).then(function(results){return issueData;});
|
2015-06-07 13:39:29 +02:00
|
|
|
};
|
|
|
|
|
|
2015-11-27 11:35:07 +01:00
|
|
|
module.getIssueData = function(issueKey) {
|
2015-06-07 13:39:29 +02:00
|
|
|
//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";
|
|
|
|
|
console.log("IssueUrl: " + url);
|
|
|
|
|
//console.log("Issue: " + issueKey + " Loading...");
|
2015-11-26 19:52:35 +01:00
|
|
|
return httpGetJSON(url);
|
2015-06-07 13:39:29 +02:00
|
|
|
};
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
return module;
|
|
|
|
|
}({}));
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
var trelloFunctions = (function(module) {
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
module.getSelectedIssueKeyList = function() {
|
|
|
|
|
//Card View
|
|
|
|
|
if (/.*\/c\/.*/g.test(document.URL)) {
|
|
|
|
|
return [document.URL.replace(/.*\/c\/([^/]*).*/g, '$1')];
|
|
|
|
|
}
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
return [];
|
|
|
|
|
};
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
module.getCardData = function(issueKey, callback) {
|
2015-11-25 12:01:42 +01:00
|
|
|
var promises = [];
|
|
|
|
|
var issueData = {};
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-11-27 11:35:07 +01:00
|
|
|
promises.push(module.getIssueData(issueKey).then(function(data) {
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.key = data.idShort;
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
// TODO get kind from label name
|
|
|
|
|
// issueData.type = data.kind.toLowerCase();
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.summary = data.name;
|
|
|
|
|
issueData.description = data.desc;
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
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";
|
|
|
|
|
}
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
if (data.due) {
|
2015-11-27 15:02:05 +01:00
|
|
|
issueData.dueDate = formatDate(new Date(data.due));
|
2015-06-07 13:39:29 +02:00
|
|
|
}
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
issueData.hasAttachment = data.attachments > 0;
|
|
|
|
|
issueData.url = data.shortUrl;
|
2015-11-25 12:01:42 +01:00
|
|
|
}));
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-11-27 07:52:48 +01:00
|
|
|
return Promise.all(promises).then(function(results){return issueData;});
|
2015-06-07 13:39:29 +02:00
|
|
|
};
|
|
|
|
|
|
2015-11-27 11:35:07 +01:00
|
|
|
module.getIssueData = function(issueKey) {
|
2015-06-07 13:39:29 +02:00
|
|
|
var url = "https://trello.com/1/cards/" + issueKey + "?members=true";
|
|
|
|
|
console.log("IssueUrl: " + url);
|
|
|
|
|
//console.log("Issue: " + issueKey + " Loading...");
|
2015-11-26 19:52:35 +01:00
|
|
|
return httpGetJSON(url);
|
2015-06-07 13:39:29 +02:00
|
|
|
};
|
2015-05-20 08:05:08 +02:00
|
|
|
|
2015-06-07 13:39:29 +02:00
|
|
|
return module;
|
|
|
|
|
}({}));
|
2015-05-15 16:27:35 +02:00
|
|
|
})();
|