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     notify : function(commit)
27     {
28         if (this.inQuery) {
29             // ignore the notification.. we are currently checking what the current
30             // status is.
31             return; 
32         }
33         this.inQuery = 1;
34         this.lastCommit = commit;
35         this.fetchTask();
36         
37         
38     },
39     fetchTask: function()
40     {
41         // have we got the status in the last 15 mins..
42         // we should not need to get it again... - it's probably not changed.
43         if (this.curTask && !this.curTask.hasExpired()) {
44             this.verifyCommit();
45         }
46         _this = this;
47         // do the request to get the task..
48         var r = new XMLHttpRequest({
49             onreadystatechange : function() {
50                 print("Got result.");
51                 if (this.status != 4) {
52                     return;
53                 }
54                 
55                   
56                 var res = JSON.parse(this.responseText);
57                 
58                 //print(JSON.stringify(res,null,4))
59                 //print([ res.success , res.data.length ]);
60                 _this.curTask = (res.success && res.data.length) ? (new Task(res.data[0])) : false;
61                 print(JSON.stringify(_this.curTask,null,4));
62                 _this.repoProject();
63             }
64             
65         });
66         var netrc  = Netrc.forHost('git.roojs.com');
67         
68         r.open('GET',
69                "http://roojs.com/admin.php/Roo/cash_invoice_entry?_current_task=1"
70                ,true, netrc.login, netrc.password  );
71         //print("SEding request");        
72         r.send();
73         
74     },
75     
76     verifyCommit : function()
77     {
78         // using curTask + lastCommit decide what to do.
79         
80         
81         
82         
83         
84         this.inQuery = 0;
85         
86     },
87     
88     repoProject: function(repo)
89     {
90          _this = this;
91         var r = new XMLHttpRequest({
92             onreadystatechange : function() {
93                 print("Got result.");
94                 if (this.status != 4) {
95                     return;
96                 }
97                 
98                   
99                 var res = JSON.parse(this.responseText);
100                 
101                 //print(JSON.stringify(res,null,4))
102                 //print([ res.success , res.data.length ]);
103                 _this.commitRepo = (res.success && res.data.length) ? currRepores.data[0] : false;
104                 print(JSON.stringify(_this.commit))
105                 _this.verifyCommit();
106             }
107             
108         });
109         var netrc  = Netrc.forHost('git.roojs.com');
110         
111         r.open('GET',
112                "http://roojs.com/admin.php/Roo/mtrack_repo?name=" + repo.name
113                ,true, netrc.login, netrc.password  );
114         //print("SEding request");        
115         r.send();
116         
117         
118     }
119     
120     
121     
122     
123     
124     
125 };
126
127
128
129
130
131 Task = XObject.define(
132     function(cfg) {
133         // cal parent?
134         if (typeof(cfg) != 'object') {
135             print("CFG not oboject?");
136             return;
137         } 
138         XObject.extend(this,cfg);
139  
140         // fix up the values.
141         this.action_datetime = Date.parseDate(this.action_dt,'Y-m-d H:i:s');
142       // print("ACT DT: " + this.action_dt);
143         
144     },
145     Object,
146     {
147         /**
148          * This is similar to the cash_invoice_entry data..
149          * 
150          */
151         action_dt: '', //"2012-11-23 11:00:00"
152         description: '', //"QA on new site"
153         qtyvalue: 0, //"2.25"
154         
155         hasExpired : function()
156         {
157             
158             var exp = this.action_datetime.add(Date.HOUR, this.qtyvalue);
159             return (new Date()) > exp;  
160             
161         }
162     }
163 );
164
165
166
167
168
169
170
171
172
173
174 //-------------- testing
175 Gtk = imports.gi.Gtk;
176 Gtk.init(Seed.argv);
177 Tasks.notify(1);
178 Gtk.main();