add option for multiple Column and Rows

This commit is contained in:
Bengt Brodersen 2015-05-17 02:21:14 +02:00
parent ca41bae99d
commit 7916ed7c78

View File

@ -3,30 +3,26 @@
console.log("Version: " + version); console.log("Version: " + version);
try { try {
// load jQuery
if (window.jQuery === undefined) {
appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js');
}
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; var isProd = !isDev;
var appFunctions = null;
if (isProd){ var printScopeDeviderToken = "<b>Attachment</b>";
//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/";
} }
var resourceOrigin = hostOrigin + "resources/";
// load jQuery
if (window.jQuery === undefined) {
appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js');
}
// wait untill all scripts loaded // wait untill all scripts loaded
appendScript('https://qoomon.github.io/void', function() { appendScript('https://qoomon.github.io/void', function() {
init();
main(); main();
}); });
@ -41,22 +37,26 @@
} }
function init() { function init() {
addStringFunctions(); addStringFunctions();
addDateFunctions(); addDateFunctions();
var printScopeDeviderToken = "<b>Attachment</b>";
var resourceOrigin = hostOrigin + "resources/";
var 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)) {
appFunctions = pivotalTrackerFunctions appFunctions = pivotalTrackerFunctions
} }
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();
}
} }
function main() { function main() {
init();
//preconditions //preconditions
if (jQuery("#card-print-overlay").length > 0) { if (jQuery("#card-print-overlay").length > 0) {
alert("Print Card already opened!"); alert("Print Card already opened!");
@ -64,7 +64,6 @@
} }
var issueKeyList = appFunctions.getSelectedIssueKeyList(); var issueKeyList = appFunctions.getSelectedIssueKeyList();
if (issueKeyList.length <= 0) { if (issueKeyList.length <= 0) {
alert("Please select at least one issue."); alert("Please select at least one issue.");
return; return;
@ -74,6 +73,13 @@
jQuery("body").append(printOverlayHTML); jQuery("body").append(printOverlayHTML);
jQuery("#card-print-overlay").prepend(printOverlayStyle); jQuery("#card-print-overlay").prepend(printOverlayStyle);
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');
if (isProd) { if (isProd) {
ga('send', 'pageview'); ga('send', 'pageview');
} }
@ -81,61 +87,55 @@
jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues..."); jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues...");
renderCards(issueKeyList, function() { renderCards(issueKeyList, function() {
jQuery("#card-print-dialog-title").text("Card Print"); jQuery("#card-print-dialog-title").text("Card Print");
print(); // print();
}); });
} }
function print() { 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);
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 (isProd) { if (isProd) {
ga('send', 'event', 'button', 'click', 'print', jQuery(".card", printDocument).length); ga('send', 'event', 'button', 'click', 'print', jQuery(".card", printDocument).length);
} }
var currentScale = jQuery("html", printDocument).css("font-size").replace("px", "");
//jQuery("html", printDocument).css("font-size", + 0.5 +"cm");
var orientationCSS = jQuery('<style type="text/css" media="print">@page{size: landscape;}</style>')
// 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; jQuery("html", printDocument).css("font-size",currentScale +"px");
var cardMinWidth = jQuery(".card", printDocument).css("min-width").replace("px", ""); jQuery(".page", printDocument).css("height", "calc( 100% / " + rowCount + " )");
jQuery(".page", printDocument).css("width", "calc( 100% / " + columnCount + " )");
var cardScale = htmlWidth / cardMinWidth; var pageWidth = jQuery(".page", printDocument).width();
var cardWidth = jQuery(".card", printDocument).width();
console.log("htmlWidth: " + htmlWidth); var newScale = currentScale * pageWidth / cardWidth;
console.log("cardMinWidth: " + cardMinWidth);
console.log("cardScale: " + cardScale);
jQuery("html", printDocument).css("font-size",cardScale+"cm"); jQuery("html", printDocument).css("font-size",newScale +"px");
jQuery(".page", printDocument).each(function(position, page) { jQuery(".card", printDocument).each(function(position, element) {
jQuery(page).css("width", "calc( 50% - 1cm )"); var height = jQuery(element).height()
jQuery(page).css("height", "calc( 50% - 1cm )"); - jQuery(element).find(".card-header").height()
jQuery(page).css("float", "left"); - jQuery(element).find(".card-footer").height()
- jQuery(element).find(".content-header").height()
var height = jQuery(page).height() - jQuery(page).find(".card-header").outerHeight() - jQuery(page).find(".card-footer").outerHeight() - jQuery(page).find(".content-header").outerHeight() - 40; - 40;
jQuery(page).find(".description").css("max-height", height + "px"); jQuery(element).find(".description").css("max-height", height + "px");
var lineHeight = jQuery(page).find(".description").css("line-height");
lineHeight = lineHeight.substring(0, lineHeight.length - 2);
var lineClamp = Math.floor(height / lineHeight);
jQuery(page).find(".description").css("-webkit-line-clamp", lineClamp + "");
}); });
}); });
jQuery(".page:odd", printDocument).each(function(position, page) {
jQuery(page).css("margin-left", "2cm");
});
jQuery(".page:nth-child(4n+3)", printDocument).each(function(position, page) {
jQuery(page).css("margin-top", "2cm");
});
jQuery(".page:nth-child(4n+4)", printDocument).each(function(position, page) {
jQuery(page).css("margin-top", "2cm");
});
printWindow.print(); printWindow.print();
jQuery("html", printDocument).css("font-size",currentScale +"px");
} }
function hideDescription(hide) { function hideDescription(hide) {
@ -273,7 +273,6 @@
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
// http://www.cssdesk.com/T9hXg // http://www.cssdesk.com/T9hXg
function printOverlayHTML() { function printOverlayHTML() {
@ -296,9 +295,11 @@
</div> </div>
<div id="card-print-dialog-footer"> <div id="card-print-dialog-footer">
<div class="buttons"> <div class="buttons">
<label style="margin-right:10px"><input id="card-scale-range" type="range" min="0.2" max="1.6" step="0.1" value="1.0" />Scale</label> <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>
<label style="margin-right:10px"><input id="hide-description-checkbox" type="checkbox"/>Hide Description</label>
<label style="margin-right:10px"><input id="multi-card-page-checkbox" type="checkbox"/>Multi Card Page</label> <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>
<input id="card-print-dialog-print" type="button" class="aui-button aui-button-primary" value="Print" /> <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> <a id="card-print-dialog-cancel" title="Cancel" class="cancel">Cancel</a>
</div> </div>
@ -496,7 +497,6 @@
return result; return result;
} }
function printPanelPageCSS() { function printPanelPageCSS() {
var result = jQuery(document.createElement('style')) var result = jQuery(document.createElement('style'))
@ -504,11 +504,15 @@
.attr("type", "text/css") .attr("type", "text/css")
.html(multilineString(function() { .html(multilineString(function() {
/*! /*!
* {
box-sizing: border-box;
}
HTML { HTML {
font-size: 1.0cm; font-size: 1.0cm;
overflow: hidden; overflow: hidden;
} }
.page { .page {
position: relative; position: relative;
overflow: auto; overflow: auto;
margin-left: auto; margin-left: auto;
@ -516,7 +520,7 @@
padding: 1.0cm; padding: 1.0cm;
margin: 1.0cm; margin: 1.0cm;
width: auto; width: auto;
height: auto; height: 15cm;
page-break-after: always; page-break-after: always;
page-break-inside: avoid; page-break-inside: avoid;
@ -536,10 +540,16 @@
@media print { @media print {
@page {
margin: 0.0cm;
}
.page { .page {
background: white; background: white;
border-style: none; border-color: light-grey;
padding: 0.0cm; border-style: dashed;
border-width: 1.0px;
padding: 0.8cm;
margin: 0.0cm; margin: 0.0cm;
-webkit-box-shadow: none; -webkit-box-shadow: none;
@ -551,14 +561,13 @@
.multiCardPage { .multiCardPage {
height: auto; height: auto;
margin-bottom: 1.0cm;
page-break-after: avoid; page-break-after: avoid;
float: left;
} }
.page:last-of-type { .page:last-of-type {
page-break-after: avoid; page-break-after: avoid;
} }
} }
*/ */
})); }));
@ -566,7 +575,6 @@
return result; return result;
} }
// http://www.cssdesk.com/scHcP // http://www.cssdesk.com/scHcP
function newPage(issueKey) { function newPage(issueKey) {
@ -657,6 +665,7 @@
.card { .card {
position: relative; position: relative;
min-width: 17.0rem; min-width: 17.0rem;
height: 100%;
max-height: 100%; max-height: 100%;
overflow: hidden; overflow: hidden;
} }
@ -690,16 +699,15 @@
top:2.0rem; top:2.0rem;
left:0.4rem; left:0.4rem;
right:0.4rem; right:0.4rem;
height: calc(100% - 4.0rem); height: calc(100% - 3.3rem);
background: #ffffff; background: #ffffff;
} }
.card-header { .card-header {
position: relative; position: relative;
} }
.card-content { .card-content {
position: relative; position: relative;
margin-top: 0.3rem; margin-top: 0.2rem;
margin-left: 1.0rem; margin-left: 1.0rem;
margin-right: 1.1rem; margin-right: 1.1rem;
margin-bottom: 0.2rem; margin-bottom: 0.2rem;
@ -712,33 +720,43 @@
//margin-bottom: 0.6rem; //margin-bottom: 0.6rem;
} }
.card-footer { .card-footer {
position: relative; position: absolute;
bottom: 0rem;
} }
.summary { .summary {
font-weight: bold; font-weight: bold;
} }
.description { .description {
display: block; margin-top: 0.4rem;
display: block;
font-size: 0.6rem; font-size: 0.6rem;
line-height: 0.6rem; line-height: 0.6rem;
overflow: hidden; overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
} }
.description:after {
content: "";
text-align: right;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0.6em;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
}
.key { .key {
position: absolute; position: absolute;
float: left; float: left;
width: auto; width: auto;
min-width: 4.4rem; min-width: 4.4rem;
height: 1.35rem; height: 1.5rem;
left: 3.0rem; left: 2.5rem;
margin-top: 1.2rem; margin-top: 1.2rem;
padding-left: 0.7rem; padding-left: 0.9rem;
padding-right: 0.4rem; padding-right: 0.4rem;
text-align: center; text-align: center;
font-weight: bold; font-weight: bold;
font-size: 1.0rem; font-size: 0.8rem;
line-height: 1.5rem; line-height: 1.2rem;
} }
.type-icon { .type-icon {
position: relative; position: relative;
@ -768,16 +786,17 @@
.estimate { .estimate {
position: relative; position: relative;
float: left; float: left;
left: -0.65rem; left: -0.60rem;
top:-1.5rem; top:-1.5rem;
height: 1.1rem; height: 1.5rem;
width: 1.1rem; width: 1.5rem;
text-align: center; text-align: center;
font-weight: bold; font-weight: bold;
font-size: 0.9rem; font-size: 0.9rem;
line-height: 1.15rem; line-height: 1.15rem;
margin-top:1.5rem; margin-top:1.5rem;
z-index: 999; z-index: 999;
overflow: hidden;
} }
.due { .due {
@ -936,6 +955,18 @@
jQuery.when.apply(jQuery, deferredList).done(callback); jQuery.when.apply(jQuery, deferredList).done(callback);
} }
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;
}
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
@ -1151,7 +1182,6 @@
.replace(/\*\/[^\/]+$/, ''); .replace(/\*\/[^\/]+$/, '');
} }
function resizeIframe(iframe) { function resizeIframe(iframe) {
iframe.height(iframe[0].contentWindow.document.body.scrollHeight); iframe.height(iframe[0].contentWindow.document.body.scrollHeight);
} }
@ -1192,7 +1222,7 @@
issueData.summary = data.fields.summary; issueData.summary = data.fields.summary;
issueData.description = data.renderedFields.description; issueData.description = data.renderedFields.description.replace(/<p>/, "");
if (data.fields.assignee) { if (data.fields.assignee) {
issueData.assignee = data.fields.assignee.displayName; issueData.assignee = data.fields.assignee.displayName;
@ -1297,7 +1327,7 @@
issueData.description = data.description; issueData.description = data.description;
if (issueData.description) { if (issueData.description) {
issueData.description = "<p>" + issueData.description issueData.description = issueData.description
} }
if (data.owned_by && data.owned_by.length > 0) { if (data.owned_by && data.owned_by.length > 0) {