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.HPaned,
155                     pack : "pack_end,true,true,3",
156                     items : [
157                         {
158                             xtype: Gtk.VBox,
159                             pack : "add",
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                                             fixed_height_mode : true,
185                                             id : "ticket-view",
186                                             pack : "add",
187                                             can_focus : true,
188                                             headers_visible : false,
189                                             init : function() {
190                                                 XObject.prototype.init.call(this);
191                                                 var description = new Pango.FontDescription.c_new();
192                                                 description.set_size(10000);
193                                                 this.el.modify_font(description);
194                                             
195                                                 this.selection = this.el.get_selection();
196                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
197                                                 var _t = this;
198                                             
199                                                 // is this really needed??
200                                                 this.selection.signal['changed'].connect(function() {
201                                                     print('selection changed');
202                                                 
203                                             
204                                                 });
205                                             
206                                             },
207                                             items : [
208                                                 {
209                                                     xtype: Gtk.ListStore,
210                                                     id : "ticket-store",
211                                                     pack : "set_model",
212                                                     columns : [
213                                                             GObject.TYPE_STRING, // title 
214                                                             GObject.TYPE_STRING, // tip
215                                                             GObject.TYPE_STRING // source..
216                                                     ],
217                                                     init : function() {
218                                                         XObject.prototype.init.call(this);
219                                                     
220                                                         this.el.set_column_types ( 2, [
221                                                             GObject.TYPE_STRING,  // real key
222                                                             GObject.TYPE_STRING // real type
223                                                             
224                                                             
225                                                         ] );
226                                                     
227                                                     
228                                                         
229                                                         // var t = this;
230                                                         //imports.Projects.Projects.fetch(  function(res) { 
231                                                         //    t.loadData(res);
232                                                        // });
233                                                             
234                                                                                     
235                                                     },
236                                                     loadData : function (data) {
237                                                             print("loading data");
238                                                                                         
239                                                         var el = this.el;
240                                                         this.el.clear();
241                                                         data.forEach(function(p) {
242                                                             var ret = {};
243                                                             el.append(ret);
244                                                            //print("ADD " + p.name);
245                                                              
246                                                             el.set_value(ret.iter, 0, p.id);
247                                                             el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' + 
248                                                                 '[' + p.status_name + '] <b>'   + p.summary  + "</b>\n"  +
249                                                                  '<span color="#666">' + p.description.split("\n").slice(0,3).join("\n") +
250                                                                  '</span>'
251                                                                  
252                                                                   );
253                                                             
254                                                         });
255                                                                   
256                                                                                          
257                                                     },
258                                                     reload : function() {
259                                                      
260                                                         var active_id = this.get('/project-select').el.get_active();
261                                                          
262                                                         var project_id = this.get('/project-select').raw_data[active_id].id;
263                                                         
264                                                         var _t = this;
265                                                         
266                                                         imports.Tasks.Tasks.query({
267                                                             project_id : project_id,
268                                                             'query[filter]' : 'me'
269                                                         }, function(res) { 
270                                                             print(JSON.stringify(res,null,4));
271                                                             _t.loadData(res);
272                                                         });
273                                                          
274                                                         
275                                                     }
276                                                 },
277                                                 {
278                                                     xtype: Gtk.TreeViewColumn,
279                                                     sizing : "",
280                                                     init : function() {
281                                                         XObject.prototype.init.call(this);
282                                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
283                                                     },
284                                                     items : [
285                                                         {
286                                                             xtype: Gtk.CellRendererText,
287                                                             pack : "pack_start"
288                                                         }
289                                                     ]
290                                                 }
291                                             ]
292                                         }
293                                     ]
294                                 }
295                             ]
296                         },
297                         {
298                             xtype: Gtk.VBox,
299                             pack : "add",
300                             items : [
301                                 {
302                                     xtype: Gtk.HBox,
303                                     pack : "pack_start,false,true,3",
304                                     items : [
305                                         {
306                                             xtype: Gtk.Label,
307                                             label : "I am doing this:",
308                                             pack : "pack_start,false,true,3"
309                                         },
310                                         {
311                                             xtype: Gtk.Entry,
312                                             pack : "pack_start,true,true,3"
313                                         }
314                                     ]
315                                 },
316                                 {
317                                     xtype: Gtk.HBox,
318                                     pack : "pack_start,false,true,3",
319                                     items : [
320                                         {
321                                             xtype: Gtk.Label,
322                                             label : "Since:",
323                                             pack : "pack_start,false,true,3"
324                                         },
325                                         {
326                                             xtype: Gtk.Entry,
327                                             pack : "pack_start,false,false,3",
328                                             width_request : 80
329                                         },
330                                         {
331                                             xtype: Gtk.Label,
332                                             label : "Until",
333                                             pack : "pack_start,false,true,3"
334                                         },
335                                         {
336                                             xtype: Gtk.Entry,
337                                             pack : "pack_start,true,true,3"
338                                         }
339                                     ]
340                                 },
341                                 {
342                                     xtype: Gtk.ScrolledWindow,
343                                     pack : "add",
344                                     id : "RightEditor",
345                                     items : [
346                                         {
347                                             xtype: Gtk.TextView,
348                                             editable : false,
349                                             id : "view",
350                                             indent_width : 4,
351                                             pack : "add",
352                                             auto_indent : true,
353                                             init : function() {
354                                                 XObject.prototype.init.call(this);
355                                                 var description = Pango.font_description_from_string("monospace");
356                                             
357                                                 description.set_size(8000);
358                                                 this.el.modify_font(description);
359                                             
360                                             },
361                                             load : function(str) {
362                                             
363                                             // show the help page for the active node..
364                                              
365                                             
366                                             
367                                              
368                                                 this.el.get_buffer().set_text(str, str.length);
369                                              
370                                                 
371                                                  var buf = this.el.get_buffer();
372                                                  
373                                                  
374                                                 
375                                             },
376                                             show_line_numbers : true,
377                                             items : [
378                                                 {
379                                                     xtype: GtkSource.Buffer,
380                                                     listeners : {
381                                                         changed : function (self) {
382                                                             /*
383                                                             var s = new Gtk.TextIter();
384                                                             var e = new Gtk.TextIter();
385                                                             this.el.get_start_iter(s);
386                                                             this.el.get_end_iter(e);
387                                                             var str = this.el.get_text(s,e,true);
388                                                             try {
389                                                                 Seed.check_syntax('var e = ' + str);
390                                                             } catch (e) {
391                                                                 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
392                                                                     red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
393                                                                    }));
394                                                                 //print("SYNTAX ERROR IN EDITOR");   
395                                                                 //print(e);
396                                                                 //console.dump(e);
397                                                                 return;
398                                                             }
399                                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
400                                                                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
401                                                                    }));
402                                                             
403                                                              this.get('/LeftPanel.model').changed(  str , false);
404                                                              */
405                                                         }
406                                                     },
407                                                     pack : "set_buffer"
408                                                 }
409                                             ]
410                                         }
411                                     ]
412                                 }
413                             ]
414                         }
415                     ]
416                 }
417             ]
418         }
419     ]
420 });
421 FixBug.init();
422 XObject.cache['/FixBug'] = FixBug;