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         var r = new XMLHttpRequest({
91         onreadystatechange : function() {
92             print("Got result.");
93             if (this.status != 4) {
94                 return;
95             }
96             
97               
98             var res = JSON.parse(this.responseText);
99             
100             //print(JSON.stringify(res,null,4))
101             //print([ res.success , res.data.length ]);
102             _this.currRepo = (res.success && res.data.length) ? currRepores.data[0] : false;
103             
104             _this.verifyCommit();
105         }
106             
107         });
108         var netrc  = Netrc.forHost('git.roojs.com');
109         
110         r.open('GET',
111                "http://roojs.com/admin.php/Roo/mtrack_repo?name=" + repo.name
112                ,true, netrc.login, netrc.password  );
113         //print("SEding request");        
114         r.send();
115         
116         
117     }
118     
119     
120     
121     
122     
123     
124 };
125
126
127
128
129
130 Task = XObject.define(
131     function(cfg) {
132         // cal parent?
133         if (typeof(cfg) != 'object') {
134             print("CFG not oboject?");
135             return;
136         } 
137         XObject.extend(this,cfg);
138  
139         // fix up the values.
140         this.action_datetime = Date.parseDate(this.action_dt,'Y-m-d H:i:s');
141       // print("ACT DT: " + this.action_dt);
142         
143     },
144     Object,
145     {
146         /**
147          * This is similar to the cash_invoice_entry data..
148          * 
149          */
150         action_dt: '', //"2012-11-23 11:00:00"
151         description: '', //"QA on new site"
152         qtyvalue: 0, //"2.25"
153         
154         hasExpired : function()
155         {
156             
157             var exp = this.action_datetime.add(Date.HOUR, this.qtyvalue);
158             return (new Date()) > exp;  
159             
160         }
161     }
162 );
163
164
165
166
167
168
169
170
171
172
173 //-------------- testing
174 Gtk = imports.gi.Gtk;
175 Gtk.init(Seed.argv);
176 Tasks.notify(1);
177 Gtk.main();