FixBug.bjs
[gitlive] / FixBug.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
12 FixBug=new XObject({
13     xtype: Gtk.Window,
14     listeners : {
15         destroy_event : function (self, event) {
16              this.el.hide();
17                         return false;
18         },
19         show : function (self) {
20         print("ON SHOW!");
21         
22             this.el.fullscreen();
23             this.el.grab_focus();
24             this.el.set_keep_above(true);
25         }
26     },
27     border_width : 3,
28     default_height : 400,
29     default_width : 600,
30     title : "Select Active Bug",
31     deletable : true,
32     modal : true,
33     show : function(c) {
34         
35         if (!this.el) {
36             this.init();
37         }
38         var _this = this;
39         /*[ 'xtype'  ].forEach(function(k) {
40             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
41         });
42         // shouild set path..
43         */
44     
45         
46         this.el.show_all();
47        // this.get('/ok_button').el.set_sensitive(false);
48         
49         // block until we return.
50         //    var run_ret = this.el.run();
51         //    if (run_ret < 1 ) {
52         //        return false;
53         //    }
54         //    print("RUN RETURN : " + run_ret);
55         
56         //print(JSON.stringify(this.get('bug').getValue()));
57         //return this.get('bug').getValue();
58         //this.success = c.success;
59     },
60     items : [
61         {
62             xtype: Gtk.VBox,
63             pack : "add",
64             items : [
65                 {
66                     xtype: Gtk.HBox,
67                     pack : "pack_start,false,true,3",
68                     items : [
69                         {
70                             xtype: Gtk.Label,
71                             label : "On this project:"
72                         },
73                         {
74                             xtype: Gtk.ComboBox,
75                             listeners : {
76                                 changed : function (self) {
77                                     print("store: active id = " + this.el.get_active_id());
78                                     this.get('/ticket-store').reload();
79                                     
80                                     
81                                 }
82                             },
83                             id : "project-select",
84                             init : function() {
85                                  this.el = new Gtk.ComboBox.with_entry();
86                                                             
87                                                             
88                                 this.model  = new XObject(this.model);
89                                 this.model.init();
90                                 this.el.set_model(this.model.el);
91                                 this.el.set_entry_text_column (0);
92                                 XObject.prototype.init.call(this);
93                                 
94                                  var t = this;
95                                 imports.Projects.Projects.fetch(  function(res) { 
96                                      t.load(res);
97                                 });
98                             },
99                             load : function(tr) {
100                                   this.model.el.clear();
101                                   this.raw_data = tr;                     
102                                      for(var i =0 ; i < tr.length; i++) {
103                                         var ret = {  };
104                                         this.model.el.append(ret);
105                                         //print(JSON.stringify(ret,null,4));
106                                        
107                                         this.model.el.set_value(ret.iter, 0, '' + tr[i].code + " - " + tr[i].name );
108                                         this.model.el.set_value(ret.iter, 1, '' + tr[i].id  );
109                                  
110                                         
111                                     }     
112                                     
113                             },
114                             model : {
115                                 xtype: Gtk.ListStore,
116                                 id : "project-store",
117                                 init : function() {
118                                     XObject.prototype.init.call(this);
119                                     this.el.set_column_types ( 3, [
120                                            GObject.TYPE_STRING, // file  
121                                           GObject.TYPE_STRING, // added
122                                           GObject.TYPE_STRING, // removed
123                                       ] );
124                                 }
125                             }
126                         },
127                         {
128                             xtype: Gtk.Button,
129                             listeners : {
130                                 button_press_event : function (self, event) {
131                                  
132                                     FixBug.el.hide();
133                                 }
134                             },
135                             height_request : 90,
136                             label : "Not working on Project",
137                             pack : "add"
138                         },
139                         {
140                             xtype: Gtk.Button,
141                             listeners : {
142                                 button_press_event : function (self, event) {
143                                 
144                                    FixBug.el.hide();
145                                 }
146                             },
147                             id : "ok_button",
148                             label : "Working on Selected Ticket",
149                             pack : "add"
150                         }
151                     ]
152                 },
153                 {
154                     xtype: Gtk.HBox,
155                     pack : "pack_end,true,true,3",
156                     items : [
157                         {
158                             xtype: Gtk.VBox,
159                             pack : "pack_start,false,true,3",
160                             items : [
161                                 {
162                                     xtype: Gtk.HBox,
163                                     pack : "pack_start,false,true,3",
164                                     items : [
165                                         {
166                                             xtype: Gtk.Entry,
167                                             pack : "pack_start,false,true,3"
168                                         },
169                                         {
170                                             xtype: Gtk.Button,
171                                             label : "Search",
172                                             pack : "pack_end,false,true,3",
173                                             use_stock : true
174                                         }
175                                     ]
176                                 },
177                                 {
178                                     xtype: Gtk.ScrolledWindow,
179                                     pack : "pack_end,true,true,3",
180                                     shadow_type : Gtk.ShadowType.IN,
181                                     items : [
182                                         {
183                                             xtype: Gtk.TreeView,
184                                             id : "ticket-view",
185                                             pack : "add",
186                                             headers_visible : false,
187                                             init : function() {
188                                                 XObject.prototype.init.call(this);
189                                                 var description = new Pango.FontDescription.c_new();
190                                                 description.set_size(8000);
191                                                 this.el.modify_font(description);
192                                             
193                                                 this.selection = this.el.get_selection();
194                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
195                                                 var _t = this;
196                                             
197                                                 // is this really needed??
198                                                 this.selection.signal['changed'].connect(function() {
199                                                     print('selection changed');
200                                                 
201                                             
202                                                 });
203                                             
204                                             },
205                                             items : [
206                                                 {
207                                                     xtype: Gtk.ListStore,
208                                                     id : "ticket-store",
209                                                     pack : "set_model",
210                                                     columns : [
211                                                             GObject.TYPE_STRING, // title 
212                                                             GObject.TYPE_STRING, // tip
213                                                             GObject.TYPE_STRING // source..
214                                                     ],
215                                                     init : function() {
216                                                         XObject.prototype.init.call(this);
217                                                     
218                                                         this.el.set_column_types ( 2, [
219                                                             GObject.TYPE_STRING,  // real key
220                                                             GObject.TYPE_STRING // real type
221                                                             
222                                                             
223                                                         ] );
224                                                     
225                                                     
226                                                         
227                                                         // var t = this;
228                                                         //imports.Projects.Projects.fetch(  function(res) { 
229                                                         //    t.loadData(res);
230                                                        // });
231                                                             
232                                                                                     
233                                                     },
234                                                     loadData : function (data) {
235                                                             print("loading data");
236                                                                                         
237                                                         var el = this.el;
238                                                         data.forEach(function(p) {
239                                                             var ret = {};
240                                                             el.append(ret);
241                                                            //print("ADD " + p.name);
242                                                              
243                                                             el.set_value(ret.iter, 0, p.id);
244                                                             el.set_value(ret.iter, 1,   '#' + p.id + 
245                                                                 '[' + p.status_name + '] '   + p.summary  + "\n"  +
246                                                                   p.description.split("\n").slice(0,3).join("\n")
247                                                                   );
248                                                             
249                                                         });
250                                                                   
251                                                                                          
252                                                     },
253                                                     reload : function() {
254                                                      
255                                                         var active_id = this.get('/project-select').el.get_active();
256                                                          
257                                                         var project_id = this.get('/project-select').raw_data[active_id].id;
258                                                         
259                                                         var _t = this;
260                                                         
261                                                         imports.Tasks.Tasks.query({
262                                                             project_id : project_id,
263                                                             'query[filter]' : 'me'
264                                                         }, function(res) { 
265                                                             print(JSON.stringify(res,null,4));
266                                                             _t.loadData(res);
267                                                         });
268                                                          
269                                                         
270                                                     }
271                                                 },
272                                                 {
273                                                     xtype: Gtk.TreeViewColumn,
274                                                     pack : "append_column",
275                                                     init : function() {
276                                                         XObject.prototype.init.call(this);
277                                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
278                                                     },
279                                                     items : [
280                                                         {
281                                                             xtype: Gtk.CellRendererText,
282                                                             pack : "pack_start"
283                                                         }
284                                                     ]
285                                                 }
286                                             ]
287                                         }
288                                     ]
289                                 }
290                             ]
291                         },
292                         {
293                             xtype: Gtk.VBox,
294                             pack : "pack_start,true,true,3",
295                             items : [
296                                 {
297                                     xtype: Gtk.HBox,
298                                     pack : "pack_start,false,true,3",
299                                     items : [
300                                         {
301                                             xtype: Gtk.Label,
302                                             label : "I am doing this:",
303                                             pack : "pack_start,false,true,3"
304                                         },
305                                         {
306                                             xtype: Gtk.Entry,
307                                             pack : "pack_start,true,true,3"
308                                         }
309                                     ]
310                                 },
311                                 {
312                                     xtype: Gtk.HBox,
313                                     pack : "pack_start,false,true,3",
314                                     items : [
315                                         {
316                                             xtype: Gtk.Label,
317                                             label : "Since:",
318                                             pack : "pack_start,false,true,3"
319                                         },
320                                         {
321                                             xtype: Gtk.Entry,
322                                             pack : "pack_start,false,false,3",
323                                             width_request : 80
324                                         },
325                                         {
326                                             xtype: Gtk.Label,
327                                             label : "Until",
328                                             pack : "pack_start,false,true,3"
329                                         },
330                                         {
331                                             xtype: Gtk.Entry,
332                                             pack : "pack_start,true,true,3"
333                                         }
334                                     ]
335                                 },
336                                 {
337                                     xtype: Gtk.ScrolledWindow,
338                                     pack : "add",
339                                     id : "RightEditor",
340                                     items : [
341                                         {
342                                             xtype: Gtk.TextView,
343                                             editable : false,
344                                             id : "view",
345                                             indent_width : 4,
346                                             pack : "add",
347                                             auto_indent : true,
348                                             init : function() {
349                                                 XObject.prototype.init.call(this);
350                                                 var description = Pango.font_description_from_string("monospace");
351                                             
352                                                 description.set_size(8000);
353                                                 this.el.modify_font(description);
354                                             
355                                             },
356                                             load : function(str) {
357                                             
358                                             // show the help page for the active node..
359                                              
360                                             
361                                             
362                                              
363                                                 this.el.get_buffer().set_text(str, str.length);
364                                              
365                                                 
366                                                  var buf = this.el.get_buffer();
367                                                  
368                                                  
369                                                 
370                                             },
371                                             show_line_numbers : true,
372                                             items : [
373                                                 {
374                                                     xtype: GtkSource.Buffer,
375                                                     listeners : {
376                                                         changed : function (self) {
377                                                             /*
378                                                             var s = new Gtk.TextIter();
379                                                             var e = new Gtk.TextIter();
380                                                             this.el.get_start_iter(s);
381                                                             this.el.get_end_iter(e);
382                                                             var str = this.el.get_text(s,e,true);
383                                                             try {
384                                                                 Seed.check_syntax('var e = ' + str);
385                                                             } catch (e) {
386                                                                 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
387                                                                     red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
388                                                                    }));
389                                                                 //print("SYNTAX ERROR IN EDITOR");   
390                                                                 //print(e);
391                                                                 //console.dump(e);
392                                                                 return;
393                                                             }
394                                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
395                                                                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
396                                                                    }));
397                                                             
398                                                              this.get('/LeftPanel.model').changed(  str , false);
399                                                              */
400                                                         }
401                                                     },
402                                                     pack : "set_buffer"
403                                                 }
404                                             ]
405                                         }
406                                     ]
407                                 }
408                             ]
409                         }
410                     ]
411                 }
412             ]
413         }
414     ]
415 });
416 FixBug.init();
417 XObject.cache['/FixBug'] = FixBug;