JiraRoboScript

Jira helper to preselect some fields when creating dialog is shown

Version vom 11.04.2020. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
	}

})();