Tasks.js
[gitlive] / Tasks.js
1
2 XObject = imports.XObject.XObject;
3 XMLHttpRequest = imports.XMLHttpRequest.XMLHttpRequest;
4 Netrc = imports.Netrc.Netrc;
5 Date = imports.Date.Date;
6 /**
7  *
8  * Tasks
9  *
10  *  Flow
11  *
12  *    Commit
13  *      => Tasks.notify(commit)
14  *
15  *
16  *
17  *
18  */
19
20 Tasks = {
21     
22     curTask : false,
23     commitRepo : false, // the DB version of repo info..
24     lastCommit : false,
25     
26     
27     notifyIdle : function()
28     {
29         
30     },
31     
32     notify : function(commit)
33     {
34         if (this.inQuery && this.inQuery > (new Date())) {
35             // ignore the notification.. we are currently checking what the current
36             // status is.
37             
38             // we need to handle a WTF situation where something below failed... so
39             
40             return; 
41         }
42         this.inQuery = (new Date()).add(Date.MINUTE, 5);
43         this.lastCommit = commit;
44         this.commitRepo = false;
45         this.curTask = false;
46         this.fetchTask();
47     },
48     
49     
50     
51     fetchTask: function()
52     {
53         // have we got the status in the last 15 mins..
54         // we should not need to get it again... - it's probably not changed.
55         if (this.curTask && !this.curTask.hasExpired()) {
56             this.fetchRepo();
57         }
58         _this = this;
59         // do the request to get the task..
60         var r = new XMLHttpRequest({
61             onreadystatechange : function() {
62                 print("Got result.");
63                 if (this.status != 4) {
64                     return;
65                 }
66                 
67                   
68                 var res = JSON.parse(this.responseText);
69                 
70                 //print(JSON.stringify(res,null,4))
71                 //print([ res.success , res.data.length ]);
72                 _this.curTask = (res.success && res.data.length) ? (new Task(res.data[0])) : false;
73                 print(JSON.stringify(_this.curTask,null,4));
74                 _this.fetchRepo();
75             }
76             
77         });
78         var netrc  = Netrc.forHost('git.roojs.com');
79         
80         r.open('GET',
81                "http://roojs.com/admin.php/Roo/cash_invoice_entry?_current_task=1"
82                ,true, netrc.login, netrc.password  );
83         //print("SEding request");        
84         r.send();
85         
86     },
87     
88     verifyCommit : function()
89     {
90         // using curTask + lastCommit decide what to do.
91         
92         //tests:::
93         this.verifyTaskTime();
94         this.verifyTaskProject();
95           
96         
97         this.inQuery = 0;
98         
99     },
100     
101     verifyTaskTime : function()
102     {
103         // check to see if current task is being planned for too long..
104         // you should only enter task, and allow it to span over an hour.
105         // if you do the whole day on a task, then it will need to verify with you every so often that you
106         // need to confirm that you are still working on it..
107         
108         
109         
110         
111     },
112     
113     
114     fetchRepo: function()
115     {
116         
117         var repo = this.lastCommit.repo;
118         
119          _this = this;
120         var r = new XMLHttpRequest({
121             onreadystatechange : function() {
122                 print("Got result.");
123                 if (this.status != 4) {
124                     return;
125                 }
126                 
127                   
128                 var res = JSON.parse(this.responseText);
129                 
130                 print(JSON.stringify(res,null,4))
131                 //print([ res.success , res.data.length ]);
132                 _this.commitRepo = (res.success && res.data.length) ? res.data[0] : false;
133                 print(JSON.stringify(_this.commitRepo))
134                 _this.verifyCommit();
135             }
136             
137         });
138         var netrc  = Netrc.forHost('git.roojs.com');
139         
140         r.open('GET',
141                "http://roojs.com/admin.php/Roo/mtrack_repos?shortname=" + repo.name
142                ,true, netrc.login, netrc.password  );
143         //print("SEding request");        
144         r.send();
145         
146         
147     }
148     
149     
150     
151     
152     
153     
154 };
155
156
157
158
159
160 Task = XObject.define(
161     function(cfg) {
162         // cal parent?
163         if (typeof(cfg) != 'object') {
164             print("CFG not oboject?");
165             return;
166         } 
167         XObject.extend(this,cfg);
168  
169         // fix up the values.
170         this.action_datetime = Date.parseDate(this.action_dt,'Y-m-d H:i:s');
171       // print("ACT DT: " + this.action_dt);
172         
173     },
174     Object,
175     {
176         /**
177          * This is similar to the cash_invoice_entry data..
178          * 
179          */
180         action_dt: '', //"2012-11-23 11:00:00"
181         description: '', //"QA on new site"
182         qtyvalue: 0, //"2.25"
183         
184         hasExpired : function()
185         {
186             
187             var exp = this.action_datetime.add(Date.HOUR, this.qtyvalue);
188             return (new Date()) > exp;  
189             
190         }
191     }
192 );
193
194
195
196
197
198
199
200
201
202
203 //-------------- testing
204 Gtk = imports.gi.Gtk;
205 Gtk.init(Seed.argv);
206 Tasks.notify( { repo : imports.Scm.Repo.Repo.get('gitlive') } );
207 Gtk.main();