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