Skip to content

Instantly share code, notes, and snippets.

@OvisMaximus
Created June 4, 2014 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OvisMaximus/d259d38545e1652d97d1 to your computer and use it in GitHub Desktop.
Save OvisMaximus/d259d38545e1652d97d1 to your computer and use it in GitHub Desktop.
User-Script for printout of Jira story cards for magic estimates
// ==UserScript==
// @name JIRA Issue Selection Mass Stroy Card Printer
// @namespace http://ismscp.softcoture.de/
// @version 0.1
// @description to print Story Cards from Jira Issue selection e.g. for Magic Estimate of the whole backlog
// @include http*://jira.actano.de/issues/?*
// @match https://jira.actano.de/issues/?*
// @copyright 2014+, me
// @require http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (s) {
return this.slice(0, s.length) == s;
};
}
if (typeof String.prototype.contains != 'function') {
String.prototype.contains = function (s) {
return this.indexOf(s) != -1;
};
}
if (typeof String.prototype.endsWith != 'function') {
String.prototype.endsWith = function (s) {
return this.length >= s.length && this.substr(this.length - s.length) == s;
};
}
this.$ = this.jQuery = jQuery.noConflict(true);
$(document).ready(function () {
$.fn.setupAgileCardPrinter = function () {
return this.each(function () { _agileCardPrinter(this); });
};
var _agileCardPrinter = window.agileCardPrinter = function (elm) {
if (elm.jQuery) {
return _agileCardPrinter(elm[0]);
}
if (elm.agileCardPrinter) {
return elm.agileCardPrinter;
}
else {
return new _agileCardPrinter.fn.init(elm);
}
};
_agileCardPrinter.fn = _agileCardPrinter.prototype = {
init: function (elm) {
this._class_noPrint = 'noprint';
this._id_printWrapper = 'agileCardPrintWrapper';
this._mediaQuery = this.getPrintMediaQuery();
this._printWrapper = this.getPrintWrapper();
this._printerIcon = this.getPrinterIcon();
elm.agileCardPrinter = this;
this.renderPrintButton();
},
getPrintMediaQuery: function () {
return $('<style type="text/css"> @media print { .' + this._class_noPrint + ' { display: none; } #' + this._id_printWrapper + ' { display: block } .page-break { display: block; page-break-before: always; } div.quadrant { float: left; width: 32em; height: 21em; margin: 0; padding: .5em; border-style: solid; border-color: black; } div#onepoint2 { border-width: 0 0 1px 1px; margin: 0 0 -1px -1px; } div#twopoint1 { border-width: 1px 1px 0 0; margin: -1px -1px 0 0; clear: left; } </style> ');
},
getPrintWrapper: function () {
return $('<div id="' + this._id_printWrapper + '"></div>');
},
getPrinterIcon: function () {
return $('<img style="margin-left:12px;" alt="print" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAACwUlEQVR42mKsbpvEAAP//v1j+PP7N8O3f4wMR5hVbHWVJCcxMjCwXb3/PNfi9519XEz/GFjZ2BiYmJjgegACiIWREcL5+/cPg5Agv6+mqlLxn/8MP735hczEBPkF/jMyMnzQ5Fv/57PYSRYmBraLV2/1vn3/YTMrKysDA1AOIIBYfv/6AaSB9jAyM4gICxpbmurbMwENZWL4D7SJkYGZmZmBVUGcj4WV1RVk0bOXbw68fvdh87s3Lxl+/fzJABBALAd3rGX4/5+BQVFDj0FDTYnh16/fYAOZgc5kAWr+z/if4f+fvwz//oMMZAY7/+Gd6wx3rp4F6vvPABBATL9//WT48f0r482Lp5hePn3AzcHBwQByHhizsQBpFgY2VgjNwsLM8OLJA+4bl04x//3zhxnkIoAAYhYREWEwMTENiouLPf73P4ONqpoGM8hkoKPALvsHwkDiLxD/ASq4dPmyiaO9bSXQgud37tw5BxBALCDFnh4eadw8PHwXrtxkWLh4GQMjIpDBgBFKgwx8+/YNm4yRLoOrq2vKwYMHFwAEEIuQkJC0mrq6xfr16xkunDnOwISuGw38+/+PgeHXV4bU1FQDUVFRNYAAYhEUFNQQExPjf//+PcPz5y+A/mTBa8CvX78YZGRkGYAWswP1aQEEEIuUlJQ6Dw8PQ3p6OoOXlxckSvG5AJjYgHoYODk5QbQKQACBXCALihoFBQUGJSUlBmIAyBAQEBAQEAYIIFAgsr569YrhJzBRgAKUEIC5kJ2dHeRddoAAAsfCb2D6//LlC9hkYrwACieQq//+/fsPIIBYYBnjz58/DMrKygxswMyCyyUgw0EuvX79OgMvLy/IkH8AAcQCtPkTKBBBrgAZAvMfLgAyHOh3Bn5+fobPnz9/AQggRiBDy93dPRqYhPlBTiPkBZABQKeDY3T37t1LAAIMAOn7AwO6vXONAAAAAElFTkSuQmCC"/>');
},
getPage: function() {
return $('<div class="quadrant" id="onepoint1"><div><div class="quadrant" id="onepoint2"></div><div class="quadrant" id="twopoint1"></div><div class="quadrant" id="twopoint2"></div><div class="page-break"></div>');
},
getPrintButton: function () {
var printButton = $('<a>', {
href: 'javascript:void(0)',
title: 'Print all items of search result as story card',
html: this.getPrinterIcon(),
class: 'jismscp_print_button'
});
var printProxy = $.proxy(this.print, this);
printButton.click(function () {
printProxy();
});
return printButton;
},
getAgileCardTitleRow: function () {
return $('<tr><td></td></tr>');
},
getAgileCardSummaryRow: function () {
return $('<tr><td><span></span></td></tr>');
},
getAgileCardDescriptionRow: function () {
return $('<tr><td></td></tr>');
},
hasPrintMediaQuery: function () {
return $(document).find(this._mediaQuery).length > 0;
},
addPrintMediaQuery: function () {
if (!this.hasPrintMediaQuery()) {
$(document).find('head').append(this._mediaQuery);
}
},
removePrintMediaQuery: function () {
if (this.hasPrintMediaQuery()) {
this._mediaQuery.remove();
}
},
getPageElement: function () {
return $('div#page');
},
setupPrintWrapper: function () {
this.getPageElement().addClass(this._class_noPrint);
this._printWrapper.appendTo('body');
},
disposePrintWrapper: function () {
this.getPageElement().removeClass(this._class_noPrint);
this._printWrapper.remove();
},
renderAgileCard: function (row) {
var titleRow = this.getAgileCardTitleRow();
var summaryRow = this.getAgileCardSummaryRow();
var descriptionRow = this.getAgileCardDescriptionRow();
titleRow.height(25);
titleRow.find('td').html($(row).find('td.issuekey a').text());
summaryRow.find('td span').html($(row).find('td.summary p a').html());
descriptionRow.find('td').html($(row).find('td.description').html());
var storyTable = $('<table>');
storyTable.append(titleRow).append(summaryRow).append(descriptionRow);
storyTable.width(532);
storyTable.height(288);
storyTable.find('td').css({ 'padding':'0.5em'});
storyTable.find('tr > td > span').css('font-weight', 'bold');
return storyTable;
},
renderAllCards: function () {
var wrapper = this._printWrapper;
var that = this;
wrapper.html('');
var page = this.getPage();
$('table.navigator-results tbody tr.issuerow').each(function (i, row) {
log("page " + (i/4) + " q " + i%4);
var curCard = that.renderAgileCard(row);
page.find('div:nth-child(' + (i%4 + 1) + ')').html(curCard.html()).html();
if ((i + 1)%4 == 0) {
wrapper.append(page);
page = that.getPage();
}
});
wrapper.append(page);
},
renderPrintButton: function () {
log("append print button");
$('div.saved-search-operations ul').append(this.getPrintButton());
},
print: function () {
this.addPrintMediaQuery();
this.setupPrintWrapper();
this.renderAllCards();
window.print();
this.dispose();
},
dispose: function () {
this.disposePrintWrapper();
this.removePrintMediaQuery();
}
};
function log(text) {
console.dir(new Date().toLocaleTimeString() + " " + text);
}
log("mass story card printer ininitalisation");
_agileCardPrinter.fn.init.prototype = _agileCardPrinter.fn;
$(document).setupAgileCardPrinter();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment