Improve Mantis

To customize and improve our a2w-mantis

  1. // ==UserScript==
  2. // @name Improve Mantis
  3. // @namespace com.aforms2web.ds.ujs
  4. // @description To customize and improve our a2w-mantis
  5. // @include http*://tasks.aforms2web.com/view_all_bug_page.php*
  6. // @author dietmar.stoiber@aforms2web.com
  7. // @version 1.2.2
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. // Config Begin
  13.  
  14. var countSelection = true;
  15.  
  16. var xForCurIterationCommit = true;
  17. var xForCurIterationCommitStyle = "padding-left: 1em; font-size: 1.5em; font-weight: smaller; color:#333333;";
  18.  
  19. var grayNotCurrentlyCommited = true;
  20. var grayNotCurrentlyCommitedAll = "font-style: italic;";
  21. var grayNotCurrentlyCommitedLinks = "";
  22.  
  23. var formatDeadline = true;
  24. var formatDeadlineStylePast = "font-weight: bold; color: #dd0000; text-decoration: underline;";
  25. var formatDeadlineStyleToday = "font-weight: bold; color: #cc5500; text-decoration: underline;";
  26. var formatDeadlineStyleTomorrow = "font-weight: bold; bold; color: #cc5500;";
  27. var formatDeadlineStyleThisWeek = "color: #cc5500;";
  28. var formatDeadlineStyleIteration = "color: #008800;";
  29. var formatDeadlineStyleFuture = "";
  30.  
  31. var activateFixedTime = true;
  32. var activateFixedTimeShowByDefault = true;
  33. var activateFixedTimeStyle = "border: 1px solid #646474; border-top-width: 0; border-radius: 0 0 5px 5px; background-color: #c8c8e8; position: fixed; top: 0; padding: 0 3px";
  34.  
  35. var selectionOfAllCommited = true;
  36. var selectionOfAllCommitedExceptWaiting = true;
  37.  
  38. // Hint: xForCurIterationCommit, grayNotCurrentlyCommited and selectionOfAllCommited only works if target-iteration and commited-istaration cols are displayed
  39.  
  40. // Config End
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. var iterationColNr = null;
  52. var deadlineColNr = null;
  53. var commitmentColNr = null;
  54. var stateColNr = null;
  55.  
  56. var hourColNrs = null;
  57. var hourColSum = null;
  58. var hourColTot = null;
  59.  
  60. var fixedTimeIsDisplayed = false;
  61. init();
  62.  
  63. function init(){
  64. var header = document.getElementsByClassName("row-category")[0];
  65. for(var h = 0; h < header.cells.length; h++){
  66. var curHeaderCell = header.cells[h];
  67. var colLinks = curHeaderCell.getElementsByTagName("a");
  68. if(colLinks.length > 0){
  69. var linkLabel = colLinks[0].innerHTML;
  70. if("Zieltermin" == linkLabel){ deadlineColNr = h; }
  71. if("Zieliteration" == linkLabel){ iterationColNr = h; }
  72. if("Status" == linkLabel){ stateColNr = h; }
  73. if("Commitment in" == linkLabel){
  74. commitmentColNr = h;
  75. colLinks[0].setAttribute("style", "white-space: nowrap;");
  76. }
  77. var pos = linkLabel.search(/.+\sh$/);
  78. if(pos > -1){
  79. if(hourColNrs == null){
  80. hourColNrs = new Array();
  81. hourColSum = new Array();
  82. hourColTot = new Array();
  83. }
  84. var nextIndex = hourColNrs.length;
  85. hourColNrs[nextIndex] = h;
  86. hourColSum[nextIndex] = 0;
  87. var matchTime = curHeaderCell.innerHTML.match(/\((.*)\)$/);
  88. if(countSelection && matchTime){
  89. curHeaderCell.innerHTML =
  90. curHeaderCell.innerHTML.substring(0, curHeaderCell.innerHTML.length - RegExp.$1.length - 2) +
  91. "<span id=\"timeOf" + h + "\" style=\"white-space: nowrap; font-weight: normal;\"><span id=\"selectOf" + h + "\">0</span> / " + RegExp.$1 + "</span>";
  92. hourColTot[nextIndex] = RegExp.$1;
  93. }
  94. colLinks[0].setAttribute("style", "white-space: nowrap;");
  95. }
  96. }
  97. }
  98. if(selectionOfAllCommited && iterationColNr != null && commitmentColNr != null){
  99. var selectAllCommits = document.createElement("span");
  100. selectAllCommits.addEventListener ('click', selectAllCommited, true);
  101. selectAllCommits.setAttribute("title", "alle commiteten Tickets selektieren");
  102. selectAllCommits.setAttribute("style", "font-weight: normal; cursor: pointer;");
  103. selectAllCommits.innerHTML = "[x]";
  104. header.cells[0].removeChild(header.cells[0].firstChild);
  105. header.cells[0].appendChild(selectAllCommits);
  106. }
  107.  
  108. var table = document.getElementById("buglist");
  109. for(var r = 0; r < table.rows.length; r++){
  110. var row = table.rows[r];
  111. if(row.getAttribute("bgcolor") != null && row.getAttribute("valign") == "top" && row.getAttribute("border") == "1"){
  112. format(row);
  113. if(countSelection){
  114. var chkbxs = row.getElementsByTagName("input");
  115. for(var i = 0; i < chkbxs.length; i++){
  116. var chkbx = chkbxs[i];
  117. if(chkbx.getAttribute("name") == "bug_arr[]" && chkbx.getAttribute("type") == "checkbox"){
  118. chkbx.addEventListener ('change', changedChkbx, true);
  119. }
  120. }
  121. }
  122. }
  123. }
  124.  
  125. if(countSelection){
  126. var allBugs = document.getElementsByName("all_bugs");
  127. if(allBugs != null && allBugs.length >= 1){
  128. allBugs[0].addEventListener ('change', recalculateChkbxs, true);
  129. }
  130. }
  131.  
  132. if(activateFixedTime){
  133. var showFixed = document.createElement("span");
  134. showFixed.addEventListener ('click', showFixedTime, true);
  135. showFixed.id = "showFixedTime";
  136. showFixed.innerHTML = "Fix positionierte Zeitanzeige aktivieren";
  137. document.body.appendChild(showFixed);
  138. var hideFixed = document.createElement("span");
  139. hideFixed.setAttribute("style", "display: none;");
  140. hideFixed.addEventListener ('click', hideFixedTime, true);
  141. hideFixed.id = "hideFixedTime";
  142. hideFixed.innerHTML = "Fix positionierte Zeitanzeige deaktivieren";
  143. document.body.insertBefore(hideFixed, document.body.firstChild);
  144. var style = document.createElement("style");
  145. style.appendChild(document.createTextNode(""));// WebKit hack
  146. document.head.appendChild(style);
  147. var sheet = style.sheet;
  148. sheet.insertRule(".fixedTime { " + activateFixedTimeStyle + " }", 0);
  149. sheet.insertRule("#showFixedTime, #hideFixedTime { text-decoration: underline; cursor: pointer; }", 0);
  150.  
  151. if(activateFixedTimeShowByDefault){
  152. showFixedTime();
  153. }
  154. }
  155. }
  156.  
  157. function showFixedTime(){
  158. document.getElementById("showFixedTime").setAttribute("style", "display: none;");
  159. document.getElementById("hideFixedTime").setAttribute("style", "display: inline;");
  160. for(i = 0; i < hourColNrs.length; i++){
  161. var newFixed = document.createElement("span");
  162. newFixed.setAttribute ("class", "fixedTime");
  163. newFixed.id = "fixedTime" + hourColNrs[i];
  164. newFixed.innerHTML = "x";
  165. document.body.appendChild(newFixed);
  166. }
  167. fixedTimeIsDisplayed = true;
  168. updateFixedTime();
  169. }
  170.  
  171. function updateFixedTime(){
  172. if(fixedTimeIsDisplayed){
  173. var source; var target;
  174. for(i = 0; i < hourColNrs.length; i++){
  175. source = document.getElementById("timeOf" + hourColNrs[i]);
  176. target = document.getElementById("fixedTime" + hourColNrs[i]);
  177. target.innerHTML = source.innerHTML.replace(/<(?:.|\n)*?>/gm, '');
  178. var rect = source.getBoundingClientRect();
  179. target.setAttribute("style", "left: " + rect.left + "px; width: " + (rect.right-rect.left) + "px;");
  180. }
  181. }
  182. }
  183.  
  184. function hideFixedTime(){
  185. document.getElementById("showFixedTime").setAttribute("style", "display: inline;");
  186. document.getElementById("hideFixedTime").setAttribute("style", "display: none;");
  187. var rmv;
  188. for(i = 0; i < hourColNrs.length; i++){
  189. rmv = document.getElementById("fixedTime" + hourColNrs[i]);
  190. rmv.parentNode.removeChild(rmv);
  191. }
  192. fixedTimeIsDisplayed = false;
  193. }
  194.  
  195. function format(row){
  196. if(deadlineColNr != null && row.cells.length >= deadlineColNr + 1){
  197. var deadline = row.cells[deadlineColNr].innerHTML;
  198. if(formatDeadline && deadline != null && deadline != ""){
  199. var iterationEnd = row.cells[iterationColNr].innerHTML;
  200. var iterationEndParts = iterationEnd.split("-")[1].split(")")[0].split(".");
  201. var iterationEndDate = new Date("20" + iterationEndParts[2], Number(iterationEndParts[1])-1, iterationEndParts[0])
  202. var deadlineParts = deadline.split("-");
  203. var deadlineDate = new Date(deadlineParts[0], Number(deadlineParts[1])-1, deadlineParts[2]);
  204. var today = new Date();
  205. today.setHours(0,0,0,0);
  206. var tomorrow = new Date();
  207. tomorrow.setHours(0,0,0,0);
  208. tomorrow.setDate(tomorrow.getDate() + 1);
  209. var weekend = new Date();
  210. weekend.setHours(0,0,0,0);
  211. weekend.setDate(weekend.getDate() - weekend.getDay() + 7);
  212. if(deadlineDate < today){
  213. row.cells[deadlineColNr].setAttribute("style", formatDeadlineStylePast);
  214. }else if(deadlineDate > iterationEndDate){
  215. row.cells[deadlineColNr].setAttribute("style", formatDeadlineStyleFuture);
  216. }else{
  217. if(+deadlineDate === +today){
  218. row.cells[deadlineColNr].setAttribute("style", formatDeadlineStyleToday);
  219. }else if(+deadlineDate === +tomorrow){
  220. row.cells[deadlineColNr].setAttribute("style", formatDeadlineStyleTomorrow);
  221. }else if(deadlineDate < weekend){
  222. row.cells[deadlineColNr].setAttribute("style", formatDeadlineStyleThisWeek);
  223. }else {
  224. row.cells[deadlineColNr].setAttribute("style", formatDeadlineStyleIteration);
  225. }
  226. }
  227. }
  228. }
  229. if(iterationColNr != null && row.cells.length >= iterationColNr + 1 && commitmentColNr != null && row.cells.length >= commitmentColNr + 1){
  230. var iterationat = row.cells[iterationColNr].innerHTML;
  231. var commitment = row.cells[commitmentColNr].innerHTML;
  232. if(grayNotCurrentlyCommited && iterationat != null && iterationat != "" && commitment != null && commitment != "" && iterationat != commitment){
  233. row.setAttribute("style", grayNotCurrentlyCommitedAll);
  234. for(c = 0; c < row.cells.length; c++){
  235. var links = row.cells[c].getElementsByTagName("a");
  236. for(var a = 0; a < links.length; a++){
  237. links[a].setAttribute("style", grayNotCurrentlyCommitedLinks);
  238. }
  239. }
  240. }else if(xForCurIterationCommit && iterationat != null && iterationat != "" && commitment != null && commitment != "" && iterationat == commitment){
  241. row.cells[commitmentColNr].innerHTML = "<div style=\"" + xForCurIterationCommitStyle + "\">x</div>";
  242. }
  243. }
  244. }
  245.  
  246. function changedChkbx(event) {
  247. event = event || window.event
  248. var target = event.target;
  249. var parRow = target;
  250. while(parRow.nodeName != "TR" && parRow.parentNode != null){
  251. parRow = parRow.parentNode
  252. }
  253. calculateChangedChkbx(parRow, target);
  254. }
  255.  
  256. function calculateChangedChkbx(row, checkbox) {
  257. var curVal;
  258. var sumVal;
  259. var curObj;
  260. var display;
  261. for(i = 0; i < hourColNrs.length; i++){
  262. curVal = row.cells[hourColNrs[i]].innerHTML;
  263. sumVal = hourColSum[i];
  264. if(checkbox.checked){
  265. sumVal = Number(sumVal) + Number(curVal);
  266. }else{
  267. sumVal = sumVal - Number(curVal);
  268. }
  269. display = 0;
  270. if(sumVal > 0){
  271. hourColSum[i] = sumVal.toFixed(2);
  272. display = sumVal.toFixed(2);
  273. if(display != 0){
  274. display = display.replace(/0+$/, "").replace(/\.$/, "");
  275. }
  276. }else{
  277. hourColSum[i] = 0;
  278. }
  279. curObj = document.getElementById("selectOf" + hourColNrs[i]).innerHTML = display;
  280. }
  281. updateFixedTime();
  282. }
  283.  
  284. function recalculateChkbxs() {
  285. var checked = false;
  286. var display;
  287. var allBugs = document.getElementsByName("all_bugs");
  288. if(allBugs != null && allBugs.length >= 1){
  289. checked = allBugs[0].checked;
  290. }
  291. for(i = 0; i < hourColNrs.length; i++){
  292. if(checked){
  293. hourColSum[i] = hourColTot[i];
  294. display = hourColSum[i].replace(/0+$/, "").replace(/\.$/, "");
  295. }else{
  296. hourColSum[i] = 0;
  297. display = 0;
  298. }
  299. document.getElementById("selectOf" + hourColNrs[i]).innerHTML = display;
  300. }
  301. updateFixedTime();
  302. }
  303.  
  304. function selectAllCommited(){
  305. var allBugs = document.getElementsByName("all_bugs");
  306. if(allBugs != null && allBugs.length >= 1){
  307. allBugs[0].checked = false;
  308. }
  309. for(i = 0; i < hourColNrs.length; i++){
  310. hourColSum[i] = 0;
  311. display = 0;
  312. document.getElementById("selectOf" + hourColNrs[i]).innerHTML = display;
  313. }
  314. var table = document.getElementById("buglist");
  315. var iteration;
  316. var commitment;
  317. var checkbox;
  318. var curState
  319. for(var r = 0; r < table.rows.length; r++){
  320. var row = table.rows[r];
  321. if(row.getAttribute("bgcolor") != null && row.getAttribute("valign") == "top" && row.getAttribute("border") == "1"){
  322. if(iterationColNr != null && commitmentColNr != null && row.cells.length >= commitmentColNr + 1){
  323. iteration = row.cells[iterationColNr].innerHTML;
  324. commitment = row.cells[commitmentColNr].innerHTML;
  325. checkbox = row.getElementsByTagName("input");
  326. if(checkbox.length > 0){
  327. checkbox[0].checked = false;
  328. if(iteration != null && iteration != "" && commitment != null && commitment != "" && (iteration == commitment || commitment.indexOf(">x<") > 0)){
  329. if(!selectionOfAllCommitedExceptWaiting || "Warten" != row.cells[stateColNr].getElementsByTagName("span")[0].innerHTML){
  330. checkbox[0].checked = true;
  331. calculateChangedChkbx(row, checkbox[0]);
  332. }
  333. }
  334. }
  335. }
  336. }
  337. }
  338.  
  339.  
  340.  
  341.  
  342. }