2 XObject = imports.XObject.XObject;
3 XMLHttpRequest = imports.XMLHttpRequest.XMLHttpRequest;
4 Netrc = imports.Netrc.Netrc;
5 Date = imports.Date.Date;
13 * => Tasks.notify(commit)
23 commitRepo : false, // the DB version of repo info..
26 nextPrompt : false, // time when the system last prompted a confirmation that a task is being worked on.
29 notifyIdle : function()
34 notify : function(commit)
36 if (this.inQuery && this.inQuery > (new Date())) {
37 // ignore the notification.. we are currently checking what the current
40 // we need to handle a WTF situation where something below failed... so
44 this.inQuery = (new Date()).add(Date.MINUTE, 5);
45 this.lastCommit = commit;
46 this.commitRepo = false;
55 // have we got the status in the last 15 mins..
56 // we should not need to get it again... - it's probably not changed.
57 if (this.curTask && !this.curTask.hasExpired()) {
61 // do the request to get the task..
62 var r = new XMLHttpRequest({
63 onreadystatechange : function() {
65 if (this.status != 4) {
70 var res = JSON.parse(this.responseText);
72 //print(JSON.stringify(res,null,4))
73 //print([ res.success , res.data.length ]);
74 _this.curTask = (res.success && res.data.length) ? (new Task(res.data[0])) : false;
76 print("Current task:" + JSON.stringify(_this.curTask,null,4));
81 var netrc = Netrc.forHost('git.roojs.com');
84 "http://roojs.com/admin.php/Roo/cash_invoice_entry?_current_task=1"
85 ,true, netrc.login, netrc.password );
86 print("Getting current task: " + "http://roojs.com/admin.php/Roo/cash_invoice_entry?_current_task=1");
93 list: function(repo, callback)
95 // have we got the status in the last 15 mins..
96 // we should not need to get it again... - it's probably not changed.
99 this.query({repo_shortname : repo.name }, callback);
103 query : function(params , callback)
107 // do the request to get the task..
108 var r = new XMLHttpRequest({
109 onreadystatechange : function() {
110 print("Got result.");
111 if (this.status != 4) {
116 var res = JSON.parse(this.responseText);
118 //print(JSON.stringify(res,null,4))
119 //print([ res.success , res.data.length ]);
120 if (!res.success || !res.data.length) {
121 print("NO tasks returned");
126 //print("Current task:" + JSON.stringify(_this.curTask,null,4));
131 var netrc = Netrc.forHost('git.roojs.com');
136 "http://roojs.com/admin.php/Roo/mtrack_ticket?" + r.urlEncode(params)
137 ,true, netrc.login, netrc.password );
138 print("Getting current task: " +
140 "http://roojs.com/admin.php/Roo/mtrack_ticket?" + r.urlEncode(params));
148 fetchRepo: function()
151 var repo = this.lastCommit.repo;
154 var r = new XMLHttpRequest({
155 onreadystatechange : function() {
156 print("Got result.");
157 if (this.status != 4) {
162 var res = JSON.parse(this.responseText);
164 print(JSON.stringify(res,null,4))
165 //print([ res.success , res.data.length ]);
166 _this.commitRepo = (res.success && res.data.length) ? res.data[0] : false;
167 print(JSON.stringify(_this.commitRepo))
168 _this.verifyCommit();
172 var netrc = Netrc.forHost('git.roojs.com');
175 "http://roojs.com/admin.php/Roo/mtrack_repos?shortname=" + repo.name
176 ,true, netrc.login, netrc.password );
177 //print("SEding request");
183 //---------- end fetching - now verifying..
187 verifyCommit : function()
189 // using curTask + lastCommit decide what to do.
193 // check to see if current task is being planned for too long..
194 // you should only enter task, and allow it to span over an hour.
195 // if you do the whole day on a task, then it will need to verify with you every so often that you
196 // need to confirm that you are still working on it..
202 Start at 10am, marked working on it till 3pm.
205 at 11am, the system will pop up a warning - are you still working on it?
206 -> if yes pressed, then next warning will be at 11pm
211 if (!this.currTask) {
212 this.promptForTask();
216 if (!this.currTask.project_id) {
217 this.promptForTask();
221 // are we working on the same project!!!!
222 if (this.currTask.project_id != this.commitRepo.project_id) {
223 this.promptForTask();
227 // has the ticket been closed...
229 var is_project= this.curTask.project_id_code[0] != '*' ;
230 // is there a ticket?
231 if (is_project && !this.currTask.ticket_id) {
232 this.promptForTask();
235 if (is_project && this.currTask.ticket_status) {
236 //TODO - if status is closed.. then we need to prompt..
242 // we now working on same project..
245 var now = new Date();
247 print(JSON.stringify(this.curTask));
249 var endoftask = this.curTask.action_datetime.add(Date.HOUR, this.curTask.qtyvalue);
250 print("END OF TASK: " + endoftask);
252 var max_stretch = now.add(Date.HOUR, 1);
253 print("Max stretch: " + max_stretch);
254 if (endoftask > max_stretch) {
255 this.fixEndCurrTask(); //
258 // still needs to be verified..
265 if (!this.nextPrompt && this.curTask) {
266 //var use_start = this.curTask.action_datetime < now ? now :
267 // if we have a task, then the next verification should be 1 hour after it started.
268 // even if we have only just seen it.. so we could already need verification.
269 this.nextPrompt = this.curTask.action_datetime; // the start time recorded in the database.
273 if (!this.nextPrompt || (this.nextPrompt < (new Date()))) {
275 this.promptForTask();
280 // ok verified basic time...
281 //let's check to see if project matches..'
291 //---------- end verifying - now prompting..
294 fixEndCurrTask: function()
296 // set the end time of the current task to be now + 1 hours at most...
297 var now = new Date();
298 var eot = now.add(Date.HOUR, 1);
299 // now round it down to nearest 15 minutes..
300 var min = Math.round((eot.format('i')*1) / 15) * 15;
301 var reot = Date.parseDate(eot.format('Y-m-d H:') + (min ? min : '00') + ':00', 'Y-m-d H:i:s');
303 print("REAL END TIME" + reot.format('Y-m-d H:i:s'))
304 print("Current start time" + this.curTask.action_datetime.format('Y-m-d H:i:s'))
306 // how long between start and reot...
307 var hours = (reot - this.curTask.action_datetime) / (60*60 * 1000 );
308 var rounded = Math.round(hours * 4) / 4.0;
309 print("Rounded : " + rounded);
311 this.updateTask({ qtyvalue : rounded });
312 this.curTask.qtyvalue = rounded;
316 promptForTask : function()
319 this.nextPrompt = (new Date()).add(Date.MINUTE, 60);
324 updateTask: function(setv)
327 XObject.extend(args,setv);
328 args.id = _this.curTask.id;
331 //print(JSON.stringify(args));
336 // do the request to get the task..
337 var r = new XMLHttpRequest({
338 onreadystatechange : function() {
339 print("Got result.");
340 if (this.status != 4) {
344 print( this.responseText)
346 var res = JSON.parse(this.responseText);
348 print(JSON.stringify(res,null,4))
349 //print([ res.success , res.data.length ]);
353 var netrc = Netrc.forHost('git.roojs.com');
356 "http://roojs.com/admin.php/Roo/cash_invoice_entry?_current_task=1"
357 ,true, netrc.login, netrc.password );
358 //print("SEding request");
372 Task = XObject.define(
375 if (typeof(cfg) != 'object') {
376 print("CFG not oboject?");
379 XObject.extend(this,cfg);
381 // fix up the values.
382 this.action_datetime = Date.parseDate(this.action_dt,'Y-m-d H:i:s');
383 // print("ACT DT: " + this.action_dt);
389 * This is similar to the cash_invoice_entry data..
392 action_dt: '', //"2012-11-23 11:00:00"
393 description: '', //"QA on new site"
394 qtyvalue: 0, //"2.25"
396 hasExpired : function()
399 var exp = this.action_datetime.add(Date.HOUR, this.qtyvalue);
400 return (new Date()) > exp;
415 //-------------- testing
417 Gtk = imports.gi.Gtk;
419 Tasks.notify( { repo : imports.Scm.Repo.Repo.get('gitlive') } );