Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name Jira Service Desk Portal enhancements
// @namespace Nikola Ivanov
// @version 0.1
// @description Fix for JSDSERVER-357
// @author Nikola Ivanov
// @match *://JIRA_URL/servicedesk/customer/user/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @require http://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js
// @grant GM_getResourceText
// @grant GM_addStyle
// @run-at document-end
// ==/UserScript==
(function($) {
'use strict';
var dtCSS = '<link rel="stylesheet" href="//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" type="text/css" media="screen">';
$('head').append(dtCSS);
var rest = '//JIRA_URL/rest/scriptrunner/latest/custom/customerissues?pid=PROJECTKEY';
var location = window.location;
if ("approvals" == location.pathname.split('/')[location.pathname.split('/').length-1]) {
rest += "&sid=Done";
}
var issues;
$.getJSON(rest, function(data) {
issues = data;
if (issues.length == 0) {
return;
}
$('.aui-page-panel-content').append('<table id="customerissues" class="display nowrap"><thead></thead><tbody></tbody></table>');
$('#customerissues').hide();
$('ul.aui-nav').children('li').first().find('ul').append('<li><a href="#" id="customerissuesswitch"><span class="cv-request-nav-text">Switch</span></a></li>');
$('#customerissuesswitch').on('click', function(e) {
if ($('#customerissues').is(':visible')) {
$('.aui-page-panel-content').children().show();
$('#customerissues_wrapper').hide();
}
else {
$('.aui-page-panel-content').children().hide();
$('#customerissues_wrapper').show();
$('#customerissues').show();
}
if (!$('#customerissues').hasClass('dataTable')) {
$('#customerissues').DataTable({
data: issues,
columns: [
{
data: 'type',
title: 'Type',
render: function (data, type, row, meta) {
var content = '<img src="';
switch (data.toLowerCase()) {
// edit to match your request types and avatars
case "new feature":
content += '/servicedesk/customershim/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=11207';
break;
case "bug":
content += '/servicedesk/customershim/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=11239';
break;
case "support":
default:
content += '/servicedesk/customershim/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=11230';
break;
}
content += '" class="vp-rq-icon-medium vp-rq-icon" />';
content += '<span class="hidden">'+ data +'</span>';
return content;
},
className: "dt-body-center"
},
{
data: 'keycode',
title: 'Key',
render: function (data, type, row, meta) {
return '<a href="//JIRA_URL/servicedesk/customer/portal/4/'+ data +'" target="_blank">'+ data +'</a>';
},
className: "dt-body-center"
},
{
data: 'summary',
title: 'Summary'
},
{
data: 'status',
title: 'Status',
render: function (data, type, row, meta) {
var content = '<span class="';
switch (data.toLowerCase()) {
// edit to match your statūs
case "waiting for customer":
case "waiting for approval":
case "work in progress":
content += 'cv-status-lozenge aui-lozenge aui-lozenge-subtle aui-lozenge-current';
break;
case "done":
case "approved":
case "rejected":
content += 'cv-status-lozenge aui-lozenge aui-lozenge-subtle aui-lozenge-success';
break;
case "open":
case "selected for development":
case "reopened":
default:
content += 'cv-status-lozenge aui-lozenge aui-lozenge-subtle aui-lozenge-complete';
break;
}
content += '">'+ data +'</span>';
return content;
},
className: "dt-body-center"
},
{
data: 'component',
title: 'Product'
},
{
data: 'updated',
title: 'Last update',
render: function (data, type, row, meta) {
return data.substring(0,10);
}
}
],
fixedHeader: {
header: true,
footer: false
},
pageLength: 50
});
}
e.preventDefault();
return false;
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.