JiraRoboScript

Jira helper to preselect some fields when creating dialog is shown

Stan na 11-04-2020. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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

})();