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