Redmine Status Highlighter Extended

Highlight issue status etc. in redmine issue list and details. It's based on the 'Redmine Status Highlighter' v0.2.1 of cbaoth (see https://greasyfork.org/de/scripts/8752-redmine-status-highlighter).

当前为 2017-10-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Redmine Status Highlighter Extended
  3. // @namespace http://deeagle.de
  4. // @version 0.3.0
  5. // @description Highlight issue status etc. in redmine issue list and details. It's based on the 'Redmine Status Highlighter' v0.2.1 of cbaoth (see https://greasyfork.org/de/scripts/8752-redmine-status-highlighter).
  6. //
  7. // Change "mydomain" or path "/redmine/" if needed:
  8. // @match *://*/*/issues*
  9. // @match *://*/issues/*
  10. // @match *://*/redmine/*/issues*
  11. // @match *://*/redmine/issues/*
  12. //
  13. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  14. // @copyright 2017, code@deeagle.de
  15. // ==/UserScript==
  16.  
  17. // Basis: http://userscripts.org/scripts/source/177488.user.js
  18.  
  19. // Change the colors as desired (examples below)
  20.  
  21. // prevent jQuery version conflicts (with page)
  22. this.$ = this.jQuery = jQuery.noConflict(true);
  23.  
  24. // CONFIG
  25. /** to enable/disable the debug option (to console.log) */
  26. var DEBUG = false;
  27. /** highlight priority */
  28. var ENABLE_PRIORITY = true;
  29. /** highlight status (and custome fields) */
  30. var ENABLE_STATUS = true;
  31. /** highlight in issue list */
  32. var ENABLE_IN_LIST = true;
  33. /** highlight in issue detail view */
  34. var ENABLE_IN_DETAILS = true;
  35. /** just highlight things that could be dev todos */
  36. var DEV_TODO_ONLY = false;
  37. /** for 'assigned to' highlighting */
  38. var MY_NAME = "Heroic Horst";
  39. /** Highlights the name on all pages */
  40. var FULL_NAME_HIGHLIGHT = true;
  41.  
  42. // Redmine element labels
  43. var REDMINE_PRIO_IMMEDIATE = "Immediate";
  44. var REDMINE_PRIO_URGENT = "Urgent";
  45. var REDMINE_PRIO_HIGH = "High";
  46. var REDMINE_PRIO_NORMAL = "Normal";
  47. var REDMINE_PRIO_LOW = "Low";
  48.  
  49. var REDMINE_STATE_NEW = "New";
  50. var REDMINE_STATE_FEEDBACK = "Feedback";
  51. var REDMINE_STATE_IN_PROGRESS = "In Progress";
  52. var REDMINE_STATE_RESOLVED = "Resolved";
  53. var REDMINE_STATE_CLOSED = "Closed";
  54. var REDMINE_STATE_REJECTED = "Rejected";
  55.  
  56. var COLOR_RED = "#FBA";
  57. var COLOR_PINK = "#FBF";
  58. var COLOR_GOLD = "#FE8";
  59. var COLOR_LIGHT_MINT = "#DFE";
  60. var COLOR_GREY = "#DDD";
  61. var COLOR_ORANGE = "#FB9";
  62. var COLOR_LIGHT_BLUE = "#Dff7FF";
  63.  
  64.  
  65. /**
  66. * Main
  67. */
  68. (function () {
  69.  
  70. // which screen are we in
  71. var screen = 0;
  72. if (/\/issues\//.test(window.location.pathname)) {
  73. screen = 2; // detail screen
  74. } else {
  75. screen = 1; // list screen
  76. }
  77. // not enabled for current screen?
  78. if ((screen === 1 && !ENABLE_IN_LIST) || (screen === 2 && !ENABLE_IN_DETAILS)) {
  79. return;
  80. } else
  81. {
  82. _log("you are on page " + screen);
  83. }
  84.  
  85. // -- PRIORITY ----------------------------------------------------------------
  86. if (ENABLE_PRIORITY) {
  87. var priorityList = $('.priority');
  88. highlightPriority(priorityList);
  89. }
  90.  
  91. // -- STATUS ------------------------------------------------------------------
  92. // we have to show for this on sub pages $('td.subject').next()
  93. if (ENABLE_STATUS) {
  94. _log("[INFO] Status highlight enabled");
  95. var taskOverviewList = $('td.subject').next();
  96. // if (taskOverviewList.length === 0)
  97. // {
  98. // //console.log("[INFO] is not an overview task");
  99. // var statusList = $('.status');
  100. // highlightStates(statusList);
  101. // } else
  102. {
  103. _log("[INFO] is an overview task!");
  104. highlightStates(taskOverviewList);
  105. var statusList = $('td.status');
  106. highlightStates(statusList);
  107. }
  108. }
  109.  
  110. // Assigned To
  111. var assignedTo = $('.assigned_to');
  112. if (FULL_NAME_HIGHLIGHT)
  113. {
  114. if (assignedTo.length === 0)
  115. {
  116. assignedTo = $('.user');
  117. }
  118. }
  119. highlightAuthor(assignedTo);
  120. })();
  121.  
  122.  
  123. /**
  124. * Prints the given msg to {@code console.log} (if {@code DEBUG} is enabled).
  125. *
  126. * @param {String} msg
  127. */
  128. function _log(msg)
  129. {
  130. if (msg !== undefined)
  131. {
  132. if (DEBUG)
  133. {
  134. console.log("[DEBUG] " + msg);
  135. }
  136. }
  137. }
  138.  
  139.  
  140. /**
  141. * Highlights the redmine states in the given page elements.
  142. *
  143. * @param {type} elements
  144. */
  145. function highlightStates(elements)
  146. {
  147. if (elements === undefined)
  148. {
  149. _log("[highlightStates] elements must not be undefined");
  150. return;
  151. }
  152.  
  153. jQuery.each(elements, function (i, elem) {
  154. text = $(elem).text().trim();
  155. _log("[INFO] elem test is: " + text);
  156. if (text === REDMINE_STATE_NEW)
  157. $(elem).css("background-color", COLOR_RED);
  158. if (text === REDMINE_STATE_FEEDBACK)
  159. $(elem).css("background-color", COLOR_PINK);
  160. if (text === REDMINE_STATE_IN_PROGRESS)
  161. $(elem).css("background-color", COLOR_GOLD);
  162. if (!DEV_TODO_ONLY) { // ignore the following (not critical for devs)
  163. if (text === REDMINE_STATE_RESOLVED)
  164. $(elem).css("background-color", COLOR_LIGHT_MINT);
  165. if (text === REDMINE_STATE_CLOSED)
  166. $(elem).css("background-color", COLOR_GREY);
  167. if (text === REDMINE_STATE_REJECTED)
  168. $(elem).css("background-color", COLOR_ORANGE);
  169. }
  170. });
  171. }
  172.  
  173.  
  174. /**
  175. * Highlights the redmine priority in the given page elements.
  176. *
  177. * @param {type} elements
  178. */
  179. function highlightPriority(elements)
  180. {
  181. if (elements === undefined)
  182. {
  183. _log("[highlightPrioriy] elements must not be undefined");
  184. return;
  185. }
  186.  
  187. jQuery.each(elements, function (i, elem) {
  188. text = $(elem).text().trim();
  189. if (text === REDMINE_PRIO_IMMEDIATE)
  190. $(elem).css("background-color", COLOR_RED);
  191. if (text === REDMINE_PRIO_URGENT)
  192. $(elem).css("background-color", COLOR_ORANGE);
  193. if (text === REDMINE_PRIO_HIGH)
  194. $(elem).css("background-color", COLOR_GOLD);
  195. if (text === REDMINE_PRIO_NORMAL)
  196. $(elem).css("background-color", COLOR_LIGHT_BLUE);
  197. if (text === REDMINE_PRIO_LOW)
  198. $(elem).css("background-color", COLOR_LIGHT_MINT);
  199. });
  200. }
  201.  
  202.  
  203. /**
  204. * Highlights the author in the given page elements.
  205. * @param {type} elements
  206. */
  207. function highlightAuthor(elements)
  208. {
  209. if (elements === undefined)
  210. {
  211. _log("[highlightAuthor] elements must not be undefined");
  212. return;
  213. }
  214.  
  215. jQuery.each(elements, function (i, elem) {
  216. text = $(elem).text().trim();
  217. if (text === MY_NAME)
  218. $(elem).css("background-color", COLOR_GOLD);
  219. });
  220. }