JiraRoboScript

Jira helper to preselect some fields when creating dialog is shown

Per 11-04-2020. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name         JiraRoboScript
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Jira helper to preselect some fields when creating dialog is shown
// @author       Robo
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// @match        https://pmjira.cz.tmo/*
// @grant        none
// ==/UserScript==

(function () {
	'use strict';
  $.noConflict()

	let bodyMutationObserver = new MutationObserver(function (mutations) {
		for (let i = 0; i < mutations.length; i++) { //faster than forEach
			let mutation = mutations[i];
			//console.log(mutation);
			if (mutation.addedNodes.length > 0
					&& (mutation.addedNodes[0].id === "create-issue-dialog" || mutation.addedNodes[0].id === "create-subtask-dialog")) {
				//add inner dialog mutationObserver
				initializeDialogMutationObserver(mutation.addedNodes[0]);
			}
		}
	});

	// Starts listening for changes in the target HTML element of the page.
	let target = document.getElementById('jira');
	bodyMutationObserver.observe(target, {
		childList: true
	});

	function initializeDialogMutationObserver(dialog) {
		 let dialogMutationObserver = new MutationObserver(function (mutations) {
			for (let i = 0; i < mutations.length; i++) { //faster than forEach
				let mutation = mutations[i];
				//console.log(mutation);
				if (mutation.target.className.includes("jira-dialog-content-ready")) {
					//dialog is ready
					//don't disconnect observer, because changing project type cause reload of inner content and dialog panel class change is triggered
					makeMiracle(mutation.target);
					//createMiracleButton(mutation.target);
				}
			}
		});

		dialogMutationObserver.observe(dialog, {
			attributes: true,
			attributeFilter: ["class"]
		});
	}

	jQuery(document).ready(function () {
		//header buttons
		jQuery("header#header div.aui-header-primary ul.aui-nav").append(
			"<li>" +
			"<a class='aui-button aui-button-primary aui-style' title='Create a new TUS' href='http://www.google.com'>Create TUS</a>" +
			"</li>" +
			"<li>" +
			"<a class='aui-button aui-button-primary aui-style' title='Create a new BUS' href='http://www.google.com'>Create BUS</a>" +
			"</li>");
	});

	/*function createMiracleButton(dialog) {
		let dialogHeader = jQuery(dialog).find(".jira-dialog-heading h2");
		if (dialogHeader.find(".miracleButton").length === 0) {
			let miracleButton = jQuery("<a class='aui-button aui-button-primary aui-style miracleButton' title='Prefil form' href='#' style='margin-left:20px;'>Make miracle</a>");
			dialogHeader.append(miracleButton).one("click", makeMiracle);
		}
	}*/

	function makeMiracle(dialog) {
		let dialogContent = jQuery(dialog).find(".jira-dialog-content");
		//        var dialogContent = jQuery("#create-issue-dialog, #create-subtask-dialog").find(".jira-dialog-content");

		//Project type preselect
		let projectTypeAgile = dialogContent.find("label:contains('Agile')").prev();
		if (projectTypeAgile.prop('checked')) {
			return;
		}
		projectTypeAgile.prop('checked', true);

		//Epic preselect
		dialogContent.find("div.aui-field-labelpicker input[role='combobox']").val("OASK - Generic Epic");

		let teamSelect = dialogContent.find("label:contains('Team')").next();

		//Team deleting
		//         teamSelect.find("option").filter(function () {
		//             var optionText = jQuery.trim(jQuery(this).text());
		//             return optionText != "ST_SK - OneApp" && optionText != "ST_SK - One Shop";
		//         }).remove();

		//Team preselect
		teamSelect.val("16135"); //select only ST_SK - One App

		//Team scroll to selected
		setTimeout(function () {
			let optionTop = teamSelect.find("option:selected").offset().top;
			let selectTop = teamSelect.offset().top;
			teamSelect.scrollTop(teamSelect.scrollTop() + (optionTop - selectTop));
		}, 100);
	}

})();