wip quad layout

This commit is contained in:
Bengt Brodersen 2015-05-15 17:20:26 +02:00
parent 77f8f19fae
commit ca41bae99d

View File

@ -2,37 +2,23 @@
var version = "3.5.0"; var version = "3.5.0";
console.log("Version: " + version); console.log("Version: " + version);
try {
var isDev = /.*jira.atlassian.com\/secure\/RapidBoard.jspa\?.*projectKey=ANERDS.*/g.test(document.URL) // Jira var isDev = /.*jira.atlassian.com\/secure\/RapidBoard.jspa\?.*projectKey=ANERDS.*/g.test(document.URL) // Jira
|| /.*pivotaltracker.com\/n\/projects\/510733.*/g.test(document.URL); // PivotTracker || /.*pivotaltracker.com\/n\/projects\/510733.*/g.test(document.URL); // PivotTracker
var isProd = !isDev;
if (isProd){
//cors = "https://cors-anywhere.herokuapp.com/";
//$("#card").load("https://cors-anywhere.herokuapp.com/"+"https://qoomon.github.io/Jira-Issue-Card-Printer/card.html");
initGoogleAnalytics();
}
var hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/"; var hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/";
if (isDev) { if (isDev) {
console.log("DEVELOPMENT"); console.log("DEVELOPMENT");
hostOrigin = "https://rawgit.com/qoomon/Jira-Issue-Card-Printer/develop/"; hostOrigin = "https://rawgit.com/qoomon/Jira-Issue-Card-Printer/develop/";
} else {
//cors = "https://cors-anywhere.herokuapp.com/";
//$("#card").load("https://cors-anywhere.herokuapp.com/"+"https://qoomon.github.io/Jira-Issue-Card-Printer/card.html");
// <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');
} }
try {
// load jQuery // load jQuery
if (window.jQuery === undefined) { if (window.jQuery === undefined) {
appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'); appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js');
@ -43,9 +29,10 @@
init(); init();
main(); main();
}); });
} catch (err) { } catch (err) {
console.log(err.message); console.log(err.message);
if (!isDev) { if (isProd) {
ga('send', 'exception', { ga('send', 'exception', {
'exDescription': err.message, 'exDescription': err.message,
'exFatal': true 'exFatal': true
@ -54,18 +41,14 @@
} }
function init() { function init() {
addJQueryFunctions();
addConsoleFunctions();
addStringFunctions(); addStringFunctions();
addDateFunctions(); addDateFunctions();
printScopeDeviderToken = "<b>Attachment</b>"; var printScopeDeviderToken = "<b>Attachment</b>";
console.logLevel = console.INFO; var resourceOrigin = hostOrigin + "resources/";
resourceOrigin = hostOrigin + "resources/"; var appFunctions = {};
appFunctions = {};
if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) { if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) {
appFunctions = jiraFunctions; appFunctions = jiraFunctions;
} else if (/.*\pivotaltracker.com\/.*/g.test(document.URL)) { } else if (/.*\pivotaltracker.com\/.*/g.test(document.URL)) {
@ -91,7 +74,7 @@
jQuery("body").append(printOverlayHTML); jQuery("body").append(printOverlayHTML);
jQuery("#card-print-overlay").prepend(printOverlayStyle); jQuery("#card-print-overlay").prepend(printOverlayStyle);
if (!isDev) { if (isProd) {
ga('send', 'pageview'); ga('send', 'pageview');
} }
@ -106,7 +89,7 @@
var printFrame = jQuery("#card-print-dialog-content-iframe"); var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow; var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document; var printDocument = printWindow.document;
if (!isDev) { if (isProd) {
ga('send', 'event', 'button', 'click', 'print', jQuery(".card", printDocument).length); ga('send', 'event', 'button', 'click', 'print', jQuery(".card", printDocument).length);
} }
@ -116,7 +99,19 @@
// jQuery("head",printDocument).append(orientationCSS); // jQuery("head",printDocument).append(orientationCSS);
printWindow.matchMedia("print").addListener(function() { printWindow.matchMedia("print").addListener(function() {
var htmlWidth = jQuery("html", printDocument).css("font-size").replace("cm", "") * jQuery("html", printDocument).width() / 2;
var cardMinWidth = jQuery(".card", printDocument).css("min-width").replace("px", "");
var cardScale = htmlWidth / cardMinWidth;
console.log("htmlWidth: " + htmlWidth);
console.log("cardMinWidth: " + cardMinWidth);
console.log("cardScale: " + cardScale);
jQuery("html", printDocument).css("font-size",cardScale+"cm");
jQuery(".page", printDocument).each(function(position, page) { jQuery(".page", printDocument).each(function(position, page) {
jQuery(page).css("width", "calc( 50% - 1cm )"); jQuery(page).css("width", "calc( 50% - 1cm )");
jQuery(page).css("height", "calc( 50% - 1cm )"); jQuery(page).css("height", "calc( 50% - 1cm )");
jQuery(page).css("float", "left"); jQuery(page).css("float", "left");
@ -136,7 +131,6 @@
jQuery(".page:nth-child(4n+3)", printDocument).each(function(position, page) { jQuery(".page:nth-child(4n+3)", printDocument).each(function(position, page) {
jQuery(page).css("margin-top", "2cm"); jQuery(page).css("margin-top", "2cm");
}); });
jQuery(".page:nth-child(4n+4)", printDocument).each(function(position, page) { jQuery(".page:nth-child(4n+4)", printDocument).each(function(position, page) {
jQuery(page).css("margin-top", "2cm"); jQuery(page).css("margin-top", "2cm");
}); });
@ -180,7 +174,7 @@
jQuery("head", printDocument).append(printPanelPageCSS()); jQuery("head", printDocument).append(printPanelPageCSS());
jQuery("head", printDocument).append(printPanelCardCSS()); jQuery("head", printDocument).append(printPanelCardCSS());
console.logInfo("load " + issueKeyList.length + " issues..."); console.log("load " + issueKeyList.length + " issues...");
var deferredList = []; var deferredList = [];
jQuery.each(issueKeyList, function(index, issueKey) { jQuery.each(issueKeyList, function(index, issueKey) {
@ -191,8 +185,8 @@
jQuery("body", printDocument).append(page); jQuery("body", printDocument).append(page);
var deferred = addDeferred(deferredList); var deferred = addDeferred(deferredList);
appFunctions.getCardData(issueKey, function(cardData) { appFunctions.getCardData(issueKey, function(cardData) {
console.logDebug("cardData: " + cardData); //console.log("cardData: " + cardData);
if (!isDev) { if (isProd) {
ga('send', 'event', 'task', 'generate', 'card', cardData.type); ga('send', 'event', 'task', 'generate', 'card', cardData.type);
} }
fillCard(page, cardData); fillCard(page, cardData);
@ -201,16 +195,16 @@
deferred.resolve(); deferred.resolve();
}); });
}); });
console.logInfo("wait for issues loaded..."); console.log("wait for issues loaded...");
applyDeferred(deferredList, function() { applyDeferred(deferredList, function() {
console.logInfo("...all issues loaded."); console.log("...all issues loaded.");
jQuery(printWindow).load(function() { jQuery(printWindow).load(function() {
console.logInfo("...all resources loaded."); console.log("...all resources loaded.");
callback(); callback();
}) })
printDocument.close(); printDocument.close();
console.logInfo("wait for resources loaded..."); console.log("wait for resources loaded...");
}); });
} }
@ -908,6 +902,26 @@
head.appendChild(script); head.appendChild(script);
} }
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');
}
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
@ -926,56 +940,6 @@
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
function addJQueryFunctions() {
//jQuery Extention
jQuery.expr[':']['is'] = function(node, index, props) {
return node.textContent == props[3];
}
}
function addConsoleFunctions() {
console.ERROR = 0;
console.WARN = 1;
console.INFO = 2;
console.DEBUG = 3;
console.TRACE = 4;
console.logLevel = console.INFO;
console.logError = function(msg) {
if (console.logLevel >= console.ERROR) {
console.log("ERROR: " + msg);
}
}
console.logWarn = function(msg) {
if (console.logLevel >= console.WARN) {
console.log("WARN: " + msg);
}
}
console.logInfo = function(msg) {
if (console.logLevel >= console.INFO) {
console.log("INFO: " + msg);
}
}
console.logDebug = function(msg) {
if (console.logLevel >= console.DEBUG) {
console.log("DEBUG: " + msg);
}
}
console.logTrace = function(msg) {
if (console.logLevel >= console.TRACE) {
console.log("TRACE: " + msg);
}
}
}
function addStringFunctions() { function addStringFunctions() {
//trim string - remove leading and trailing whitespaces //trim string - remove leading and trailing whitespaces
@ -1262,9 +1226,8 @@
issueData.url = window.location.origin + "/browse/" + issueData.key; issueData.url = window.location.origin + "/browse/" + issueData.key;
//check for lrs //LRS Specific field mapping
if (true) { if (true) {
console.logInfo("Apply LRS Specifics");
//Desired-Date //Desired-Date
if (data.fields.desiredDate) { if (data.fields.desiredDate) {
issueData.dueDate = new Date(data.fields.desiredDate).format('D d.m.'); issueData.dueDate = new Date(data.fields.desiredDate).format('D d.m.');
@ -1279,8 +1242,8 @@
async = typeof async !== 'undefined' ? async : true; async = typeof async !== 'undefined' ? async : true;
//https://docs.atlassian.com/jira/REST/latest/ //https://docs.atlassian.com/jira/REST/latest/
var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names'; var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names';
console.logDebug("IssueUrl: " + url); console.log("IssueUrl: " + url);
console.logDebug("Issue: " + issueKey + " Loading..."); //console.log("Issue: " + issueKey + " Loading...");
jQuery.ajax({ jQuery.ajax({
type: 'GET', type: 'GET',
url: url, url: url,
@ -1288,12 +1251,12 @@
dataType: 'json', dataType: 'json',
async: async, async: async,
success: function(responseData) { success: function(responseData) {
console.logDebug("Issue: " + issueKey + " Loaded!"); //console.log("Issue: " + issueKey + " Loaded!");
// add custom fields with field names // add custom fields with field names
jQuery.each(responseData.names, function(key, value) { jQuery.each(responseData.names, function(key, value) {
if (key.startsWith("customfield_")) { if (key.startsWith("customfield_")) {
var newFieldId = value.toCamelCase(); var newFieldId = value.toCamelCase();
console.logTrace("add new field: " + newFieldId + " with value from " + key); //console.log("add new field: " + newFieldId + " with value from " + key);
responseData.fields[value.toCamelCase()] = responseData.fields[key]; responseData.fields[value.toCamelCase()] = responseData.fields[key];
} }
}); });
@ -1374,8 +1337,8 @@
async = typeof async !== 'undefined' ? async : true; async = typeof async !== 'undefined' ? async : true;
//http://www.pivotaltracker.com/help/api //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"; 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.logDebug("IssueUrl: " + url); console.log("IssueUrl: " + url);
console.logDebug("Issue: " + issueKey + " Loading..."); //console.log("Issue: " + issueKey + " Loading...");
jQuery.ajax({ jQuery.ajax({
type: 'GET', type: 'GET',
url: url, url: url,
@ -1383,13 +1346,10 @@
dataType: 'json', dataType: 'json',
async: async, async: async,
success: function(responseData) { success: function(responseData) {
console.logDebug("Issue: " + issueKey + " Loaded!"); //console.log("Issue: " + issueKey + " Loaded!");
callback(responseData); callback(responseData);
}, },
}); });
} }
} }
})(); })();