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");
95 var repo = this.lastCommit.repo;
98 var r = new XMLHttpRequest({
99 onreadystatechange : function() {
100 print("Got result.");
101 if (this.status != 4) {
106 var res = JSON.parse(this.responseText);
108 print(JSON.stringify(res,null,4))
109 //print([ res.success , res.data.length ]);
110 _this.commitRepo = (res.success && res.data.length) ? res.data[0] : false;
111 print(JSON.stringify(_this.commitRepo))
112 _this.verifyCommit();
116 var netrc = Netrc.forHost('git.roojs.com');
119 "http://roojs.com/admin.php/Roo/mtrack_repos?shortname=" + repo.name
120 ,true, netrc.login, netrc.password );
121 //print("SEding request");
127 //---------- end fetching - now verifying..
131 verifyCommit : function()
133 // using curTask + lastCommit decide what to do.
136 this.verifyTaskTime();
137 this.verifyTaskProject();
144 verifyTaskTime : function()
146 // check to see if current task is being planned for too long..
147 // you should only enter task, and allow it to span over an hour.
148 // if you do the whole day on a task, then it will need to verify with you every so often that you
149 // need to confirm that you are still working on it..
155 Start at 10am, marked working on it till 3pm.
158 at 11am, the system will pop up a warning - are you still working on it?
159 -> if yes pressed, then next warning will be at 11pm
163 var now = new Date();
165 print(JSON.stringify(this.curTask));
167 var endoftask = this.curTask.action_datetime.add(Date.HOUR, this.curTask.qtyvalue);
168 print("END OF TASK: " + endoftask);
170 var max_stretch = now.add(Date.HOUR, 1);
171 print("Max stretch: " + max_stretch);
172 if (endoftask > max_stretch) {
173 this.fixEndCurrTask(); //
185 if (!this.nextPrompt && this.curTask) {
186 //var use_start = this.curTask.action_datetime < now ? now :
187 // if we have a task, then the next verification should be 1 hour after it started.
188 // even if we have only just seen it.. so we could already need verification.
189 this.nextPrompt = this.curTask.action_datetime; // the start time recorded in the database.
193 if (!this.nextPrompt || (this.nextPrompt < (new Date()))) {
195 this.promptForTask();
205 //---------- end verifying - now prompting..
208 fixEndCurrTask: function()
210 // set the end time of the current task to be now + 1 hours at most...
211 var now = new Date();
212 var eot = now.add(Date.HOUR, 1);
213 // now round it down to nearest 15 minutes..
214 var min = Math.round((eot.format('i')*1) / 15) * 15;
215 var reot = Date.parseDate(eot.format('Y-m-d H:') + (min ? min : '00') + ':00', 'Y-m-d H:i:s');
217 // how long between start and reot...
218 var hours = (reot - this.curTask.action_datetime) / (60*60 * 1000 );
219 var rounded = Math.round(hours * 4) / 4.0;
220 print("Rounded : " + rounded);
221 this.updateTask({ qtyvalue : rounded });
226 promptForTask : function()
229 this.nextPrompt = (new Date()).add(Date.MINUTE, 60);
234 updateTask: function(setv)
237 XObject.extend(args,setv);
238 args.id = _this.curTask.id;
241 // do the request to get the task..
242 var r = new XMLHttpRequest({
243 onreadystatechange : function() {
244 print("Got result.");
245 if (this.status != 4) {
250 var res = JSON.parse(this.responseText);
252 print(JSON.stringify(res,null,4))
253 //print([ res.success , res.data.length ]);
254 _this.curTask = (res.success && res.data.length) ? (new Task(res.data[0])) : false;
255 print(JSON.stringify(_this.curTask,null,4));
260 var netrc = Netrc.forHost('git.roojs.com');
263 "http://roojs.com/admin.php/Roo/cash_invoice_entry?_current_task=1"
264 ,true, netrc.login, netrc.password );
265 //print("SEding request");
279 Task = XObject.define(
282 if (typeof(cfg) != 'object') {
283 print("CFG not oboject?");
286 XObject.extend(this,cfg);
288 // fix up the values.
289 this.action_datetime = Date.parseDate(this.action_dt,'Y-m-d H:i:s');
290 // print("ACT DT: " + this.action_dt);
296 * This is similar to the cash_invoice_entry data..
299 action_dt: '', //"2012-11-23 11:00:00"
300 description: '', //"QA on new site"
301 qtyvalue: 0, //"2.25"
303 hasExpired : function()
306 var exp = this.action_datetime.add(Date.HOUR, this.qtyvalue);
307 return (new Date()) > exp;
322 //-------------- testing
323 Gtk = imports.gi.Gtk;
325 Tasks.notify( { repo : imports.Scm.Repo.Repo.get('gitlive') } );