Last active
August 29, 2015 14:27
-
-
Save gtarsia/05a1c14db4e28864bb4f to your computer and use it in GitHub Desktop.
A tampermonkey script to be able to track multiple hours at once in mantis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Mantis ajax | |
// @namespace http://your.homepage/ | |
// @version 0.1 | |
// @description enter something useful | |
// @author You | |
// @match http://mantis.virtualmindsoftware.com/view.php?id=15640#timerecord | |
// ==/UserScript== | |
/* To track hours, you do this: | |
1) Navigate to any mantis issue/bug | |
2) Run the following | |
Definition for t_ is : t_(day, hour, hours, information[, bug_id, year]) | |
For example: | |
_mantisAjaxArray([ | |
_t(1, 8, '02:00', 'I did nothing today', 335), | |
_t(3, 8, '06:00', 'I did more today', 366) | |
]) | |
In that example, I loaded 2 hours for the 1st of August with the label 'I did nothing today', for the bug with id 335. | |
And 6 hours for the 3rd of august with the label 'I did more today', for the bug with id 336. | |
The id of a bug is found in the url: "/view.php?id=16306". | |
The hours are loaded sequentially since each request needs a token for its own. | |
*/ | |
function _mantisAjaxArray(arr) { | |
var length = arr.length; | |
var current = (s_(arr[0])()); | |
for (var i = 1; i < length; i++) { | |
current = current.then(s_(arr[i])); | |
} | |
} | |
function t_(day, month, hours, information, bug_id, year) { | |
if (!bug_id) bug_id = $("[name='bug_id'][type='hidden']").val(); | |
if (!year) year = new Date().getFullYear(); | |
return { | |
bug_id: bug_id, | |
day: day, | |
month: month, | |
year: year, | |
time_value: hours, | |
time_info: information, | |
Add: 'Add' | |
} | |
} | |
function s_(data) { | |
return function() { | |
var token = $("[name='plugin_TimeTracking_add_record_token']").val(); | |
data["plugin_TimeTracking_add_record_token"] = token; | |
return $.post('http://mantis.virtualmindsoftware.com/plugin.php?page=TimeTracking/add_record', data) | |
.then(function(res) { | |
console.log(data); | |
var token = $(res).find("[name='plugin_TimeTracking_add_record_token']").val(); | |
$("[name='plugin_TimeTracking_add_record_token']").val(token); | |
}) | |
.fail(function(res) { console.error(res); }) | |
} | |
} | |
if (unsafeWindow.s_ == undefined) { | |
unsafeWindow.s_ = s_; | |
unsafeWindow.t_ = t_; | |
unsafeWindow._mantisAjaxArray = _mantisAjaxArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment