Skip to content

Commit

Permalink
get task times
Browse files Browse the repository at this point in the history
  • Loading branch information
okunishinishi committed Jan 2, 2013
1 parent 4bdc514 commit ee349bc
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 13 deletions.
24 changes: 23 additions & 1 deletion agent/agn.redmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,32 @@ RedmineAgent.prototype.getVersions = function (project_identifier, callback) {
});
};

RedmineAgent.prototype.getTimeTrack = function (version_id, callback) {
var s = this,
url = [conf.url.base, 'versions/show', version_id].join('/');
s.get(url, function (res, body, $) {
try {
if (res.statusCode === 404) throw new Error(404);
var table = $('#version-summary').find('fieldset').eq(0).find('table'),
tr = table.find('tr');

var extractNumber = util.string.extractNumber;
var data = {
estimated:extractNumber(tr.eq(0).find('td').eq(1).text()) || 0,
spent:extractNumber(tr.eq(1).find('td').eq(1).text()) || 0
};
callback && callback.call(s, true, data);
} catch (e) {
console.error(e);
callback && callback.call(s, false);
}
});
};
//
//
//new RedmineAgent().login(conf.admin, function(){
// var s = this;
// s.getTrackers(function(){
// s.getTimeTrack(1, function(){
// console.log(arguments);
// });
//});
14 changes: 12 additions & 2 deletions public/javascripts/view.daily.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
return Math.random() > 0.5;
});
};

Number.prototype.toDigitString = function(digit){
var s = this,
string = s.toString();
while(string.length < digit){
string = "0" + string;
}
return string;
};

$.extend({
});

Expand Down Expand Up @@ -110,8 +120,8 @@
var display = $(this);

var html = template({
month:date.getMonth() + 1,
date:date.getDate()
month:(date.getMonth() + 1).toDigitString(2),
date:(date.getDate()).toDigitString(2)
});

display.html(html);
Expand Down
54 changes: 45 additions & 9 deletions routes/rt.sprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ var RedmineAgent = require('../agent')['Redmine'],
Team = db.models['Team'],
Sprint = db.models['Sprint'];

function getTimeTracks(versions, callback){
var result = {
consumed:0,
spent:0
};
var agentReqCount = 0,
abort = false;
if(!versions.length){
callback(true, result);
}
versions.forEach(function(version){
agentReqCount++;
RedmineAgent.admin.getTimeTrack(version.id, function(success, data){
if (abort) return;
if (!success) {
abort = true;
callback(false);
return;
}
result.consumed += data.consumed;
result.spent += data.spent;
agentReqCount--;
if (agentReqCount == 0) {
callback(true, result);
}
});
});

}

/* get issues from redmine */
function getIssues(trackers, versions, callback) {
var result = [];
Expand All @@ -24,9 +54,9 @@ function getIssues(trackers, versions, callback) {
fixed_version_id:version.id,
status_id:'*',
tracker_id:tracker_id
}, function (sucess, issues) {
}, function (success, issues) {
if (abort) return;
if (!sucess) {
if (!success) {
abort = true;
callback(false);
return;
Expand Down Expand Up @@ -131,8 +161,8 @@ exports.task_time = function (req, res) {
}
var data = {
estimated:0,
remain:0,
consumed:0
consumed:0,
remain:0
};
getTasks(team_id, sprint, function (sucess, tasks, team) {
if (!sucess) {
Expand All @@ -142,12 +172,18 @@ exports.task_time = function (req, res) {
tasks.forEach(function (task) {
data.estimated += (task.estimated_hours || 0);
});
res.json({
success:true,
estimated:130,
remain:80,
consumed:80

getTimeTracks(versions, function(success, timeTrack){
if(!success){
failJson(res);
return;
}
data.consumed = timeTrack.spent;
data.success = true;
data.remain = data.estimated; //TODO
res.json(data);
});

});
};

Expand Down
14 changes: 13 additions & 1 deletion test/util/mch.utl.string.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,20 @@ describe('utl.string', function(){
});

it('escapeRegex', function(done){
console.log(util.escapeRegex("http://example.com/"));
util.escapeRegex("http://example.com/").should.equal("http:\/\/example\\\.com\/");
done();
});

it('extractNumber', function(done){
util.extractNumber("123").should.equal(123);
util.extractNumber("abc123").should.equal(123);
util.extractNumber("abc123def").should.equal(123);
util.extractNumber("123def").should.equal(123);
should.not.exist(util.extractNumber("abc"));
should.not.exist(util.extractNumber(""));
should.not.exist(util.extractNumber(null));
should.not.exist(util.extractNumber(undefined));

done();
});
});
7 changes: 7 additions & 0 deletions util/utl.string.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ exports.underscore2Camel = function(str){
/* 正規表現をエスケープする */
exports.escapeRegex = function(str){
return str && str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1") || '';
};

/* 数字を抜き出す */
exports.extractNumber = function(str){
if(!str) return null;
var match = str.match(/\d+/);
return match?parseInt(match[0], 10):null;
};

0 comments on commit ee349bc

Please sign in to comment.