fix date calc
[gitlive] / Tasks.js
index d9a5420..6eb7893 100644 (file)
--- a/Tasks.js
+++ b/Tasks.js
@@ -89,6 +89,62 @@ Tasks = {
     },
     
     
+   
+    list: function(repo, callback)
+    {
+        // have we got the status in the last 15 mins..
+        // we should not need to get it again... - it's probably not changed.
+         
+         
+        this.query({repo_shortname : repo.name }, callback);
+    },
+                
+         
+    query : function(params , callback)
+    {
+         
+        _this = this;
+        // do the request to get the task..
+        var r = new XMLHttpRequest({
+            onreadystatechange : function() {
+                print("Got result.");
+                if (this.status != 4) {
+                    return;
+                }
+                
+                  
+                var res = JSON.parse(this.responseText);
+                
+                //print(JSON.stringify(res,null,4))
+                //print([ res.success , res.data.length ]);
+                if (!res.success || !res.data.length)  {
+                    print("NO tasks returned");
+                    callback([]);
+                    return;
+                }
+                
+                //print("Current task:" + JSON.stringify(_this.curTask,null,4));
+                callback(res.data);
+            }
+            
+        });
+        var netrc  = Netrc.forHost('git.roojs.com');
+        
+          
+        
+        r.open('GET',
+               "http://roojs.com/admin.php/Roo/mtrack_ticket?" + r.urlEncode(params)
+               ,true, netrc.login, netrc.password  );
+         print("Getting current task: "  +
+               
+               "http://roojs.com/admin.php/Roo/mtrack_ticket?" + r.urlEncode(params));        
+        r.send();
+        
+    },
+    
+    
+    
+    
     fetchRepo: function()
     {
         
@@ -157,26 +213,51 @@ Tasks = {
             return;
         }
         
+         if (!this.currTask.project_id) {
+            this.promptForTask();
+            return;
+        }
         
+        // are we working on the same project!!!!
+        if (this.currTask.project_id != this.commitRepo.project_id) {
+            this.promptForTask();
+            return;
+        }
+  
+        // has the ticket been closed...
         
-        var now = new Date();
-        if ( this.curTask) {
-            print(JSON.stringify(this.curTask));
-            
-            var endoftask = this.curTask.action_datetime.add(Date.HOUR, this.curTask.qtyvalue);
-            print("END OF TASK: " + endoftask);
+        var is_project=  this.curTask.project_id_code[0] != '*' ;
+        // is there a ticket?
+        if (is_project && !this.currTask.ticket_id) {
+            this.promptForTask();
+            return;
+        }
+        if (is_project && this.currTask.ticket_status) {
+            //TODO - if status is closed.. then we need to prompt..
             
-            var max_stretch = now.add(Date.HOUR, 1);
-             print("Max stretch: " + max_stretch);
-            if (endoftask > max_stretch) {
-                this.fixEndCurrTask(); //
-                
-            }
-            // still needs to be verified..
             
         }
         
         
+        // we now working on same project..
+        
+        
+        var now = new Date();
+        
+        print(JSON.stringify(this.curTask));
+        
+        var endoftask = this.curTask.action_datetime.add(Date.HOUR, this.curTask.qtyvalue);
+        print("END OF TASK: " + endoftask);
+        
+        var max_stretch = now.add(Date.HOUR, 1);
+         print("Max stretch: " + max_stretch);
+        if (endoftask > max_stretch) {
+            this.fixEndCurrTask(); //
+            
+        }
+        // still needs to be verified..
+       
+        
         
         
 
@@ -332,7 +413,9 @@ Task = XObject.define(
 
 
 //-------------- testing
+/*
 Gtk = imports.gi.Gtk;
 Gtk.init(Seed.argv);
 Tasks.notify( { repo : imports.Scm.Repo.Repo.get('gitlive') } );
-Gtk.main();
\ No newline at end of file
+Gtk.main();
+*/
\ No newline at end of file