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 : 900,
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                                             listeners : {
169                                                 key_release_event : function (self, event) {
170                                                     print(JSON.stringify(event,null,4)); //.keyval);
171                                                     return true;
172                                                 }
173                                             },
174                                             id : "search-entry",
175                                             pack : "pack_start,true,true,3"
176                                         },
177                                         {
178                                             xtype: Gtk.Button,
179                                             listeners : {
180                                                 clicked : function (self) {
181                                                     var active_id = this.get('/project-select').el.get_active();
182                                                      
183                                                     var project_id = this.get('/project-select').raw_data[active_id].id;
184                                                     
185                                                     var str = this.get('/search-entry').el.get_text();
186                                                     
187                                                     print(str);
188                                                     
189                                                     var _t = this;
190                                                     
191                                                     imports.Tasks.Tasks.query({
192                                                         project_id : project_id,
193                                                         'query[filter]' : 'me',
194                                                         'query[search]' : str
195                                                     }, function(res) { 
196                                                        // print(JSON.stringify(res,null,4));
197                                                         _t.get('/ticket-store').loadData(res);
198                                                     });
199                                                 }
200                                             },
201                                             label : "Search",
202                                             pack : "pack_end,false,true,3",
203                                             use_stock : true
204                                         }
205                                     ]
206                                 },
207                                 {
208                                     xtype: Gtk.ScrolledWindow,
209                                     pack : "pack_end,true,true,3",
210                                     shadow_type : Gtk.ShadowType.IN,
211                                     items : [
212                                         {
213                                             xtype: Gtk.TreeView,
214                                             fixed_height_mode : true,
215                                             id : "ticket-view",
216                                             pack : "add",
217                                             can_focus : true,
218                                             headers_visible : false,
219                                             init : function() {
220                                                 XObject.prototype.init.call(this);
221                                                 var description = new Pango.FontDescription.c_new();
222                                                 description.set_size(10000);
223                                                 this.el.modify_font(description);
224                                             
225                                                 this.selection = this.el.get_selection();
226                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
227                                                 var _t = this;
228                                             
229                                                 // is this really needed??
230                                                 this.selection.signal['changed'].connect(function() {
231                                                     print('selection changed');
232                                                 
233                                             
234                                                 });
235                                             
236                                             },
237                                             items : [
238                                                 {
239                                                     xtype: Gtk.ListStore,
240                                                     id : "ticket-store",
241                                                     pack : "set_model",
242                                                     columns : [
243                                                             GObject.TYPE_STRING, // title 
244                                                             GObject.TYPE_STRING, // tip
245                                                             GObject.TYPE_STRING // source..
246                                                     ],
247                                                     init : function() {
248                                                         XObject.prototype.init.call(this);
249                                                     
250                                                         this.el.set_column_types ( 2, [
251                                                             GObject.TYPE_STRING,  // real key
252                                                             GObject.TYPE_STRING // real type
253                                                             
254                                                             
255                                                         ] );
256                                                     
257                                                     
258                                                         
259                                                         // var t = this;
260                                                         //imports.Projects.Projects.fetch(  function(res) { 
261                                                         //    t.loadData(res);
262                                                        // });
263                                                             
264                                                                                     
265                                                     },
266                                                     loadData : function (data) {
267                                                             print("loading data");
268                                                                                         
269                                                         var el = this.el;
270                                                         this.el.clear();
271                                                         data.forEach(function(p) {
272                                                             var ret = {};
273                                                             el.append(ret);
274                                                            //print("ADD " + p.name);
275                                                              
276                                                             el.set_value(ret.iter, 0, p.id);
277                                                             el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' + 
278                                                                 '[' + p.status_name + '] <b>'   + p.summary  + "</b>\n"  +
279                                                                  '<span color="#666">' + p.description.split("\n").slice(0,3).join("\n") +
280                                                                  '</span>'
281                                                                  
282                                                                   );
283                                                             
284                                                         });
285                                                                   
286                                                                                          
287                                                     },
288                                                     reload : function() {
289                                                      
290                                                         var active_id = this.get('/project-select').el.get_active();
291                                                          
292                                                         var project_id = this.get('/project-select').raw_data[active_id].id;
293                                                         
294                                                         var _t = this;
295                                                         
296                                                         imports.Tasks.Tasks.query({
297                                                             project_id : project_id,
298                                                             'query[filter]' : 'me'
299                                                         }, function(res) { 
300                                                             print(JSON.stringify(res,null,4));
301                                                             _t.loadData(res);
302                                                         });
303                                                          
304                                                         
305                                                     }
306                                                 },
307                                                 {
308                                                     xtype: Gtk.TreeViewColumn,
309                                                     pack : "append_column",
310                                                     sizing : Gtk.TreeViewColumnSizing.FIXED,
311                                                     init : function() {
312                                                         XObject.prototype.init.call(this);
313                                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
314                                                     },
315                                                     items : [
316                                                         {
317                                                             xtype: Gtk.CellRendererText,
318                                                             pack : "pack_start"
319                                                         }
320                                                     ]
321                                                 }
322                                             ]
323                                         }
324                                     ]
325                                 }
326                             ]
327                         },
328                         {
329                             xtype: Gtk.VBox,
330                             pack : "add",
331                             items : [
332                                 {
333                                     xtype: Gtk.HBox,
334                                     pack : "pack_start,false,true,3",
335                                     items : [
336                                         {
337                                             xtype: Gtk.Label,
338                                             label : "I am doing this:",
339                                             pack : "pack_start,false,true,3"
340                                         },
341                                         {
342                                             xtype: Gtk.Entry,
343                                             pack : "pack_start,true,true,3"
344                                         }
345                                     ]
346                                 },
347                                 {
348                                     xtype: Gtk.HBox,
349                                     pack : "pack_start,false,true,3",
350                                     items : [
351                                         {
352                                             xtype: Gtk.Label,
353                                             label : "Since:",
354                                             pack : "pack_start,false,true,3"
355                                         },
356                                         {
357                                             xtype: Gtk.Entry,
358                                             pack : "pack_start,false,false,3",
359                                             width_request : 80
360                                         },
361                                         {
362                                             xtype: Gtk.Label,
363                                             label : "Until",
364                                             pack : "pack_start,false,true,3"
365                                         },
366                                         {
367                                             xtype: Gtk.Entry,
368                                             pack : "pack_start,true,true,3"
369                                         }
370                                     ]
371                                 },
372                                 {
373                                     xtype: Gtk.ScrolledWindow,
374                                     pack : "add",
375                                     id : "RightEditor",
376                                     items : [
377                                         {
378                                             xtype: Gtk.TextView,
379                                             editable : false,
380                                             id : "view",
381                                             indent_width : 4,
382                                             pack : "add",
383                                             auto_indent : true,
384                                             init : function() {
385                                                 XObject.prototype.init.call(this);
386                                                 var description = Pango.font_description_from_string("monospace");
387                                             
388                                                 description.set_size(8000);
389                                                 this.el.modify_font(description);
390                                             
391                                             },
392                                             load : function(str) {
393                                             
394                                             // show the help page for the active node..
395                                              
396                                             
397                                             
398                                              
399                                                 this.el.get_buffer().set_text(str, str.length);
400                                              
401                                                 
402                                                  var buf = this.el.get_buffer();
403                                                  
404                                                  
405                                                 
406                                             },
407                                             show_line_numbers : true,
408                                             items : [
409                                                 {
410                                                     xtype: GtkSource.Buffer,
411                                                     listeners : {
412                                                         changed : function (self) {
413                                                             /*
414                                                             var s = new Gtk.TextIter();
415                                                             var e = new Gtk.TextIter();
416                                                             this.el.get_start_iter(s);
417                                                             this.el.get_end_iter(e);
418                                                             var str = this.el.get_text(s,e,true);
419                                                             try {
420                                                                 Seed.check_syntax('var e = ' + str);
421                                                             } catch (e) {
422                                                                 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
423                                                                     red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
424                                                                    }));
425                                                                 //print("SYNTAX ERROR IN EDITOR");   
426                                                                 //print(e);
427                                                                 //console.dump(e);
428                                                                 return;
429                                                             }
430                                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
431                                                                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
432                                                                    }));
433                                                             
434                                                              this.get('/LeftPanel.model').changed(  str , false);
435                                                              */
436                                                         }
437                                                     },
438                                                     pack : "set_buffer"
439                                                 }
440                                             ]
441                                         }
442                                     ]
443                                 }
444                             ]
445                         },
446                         {
447                             xtype: Gtk.VBox,
448                             pack : "add",
449                             width_request : 400,
450                             items : [
451                                 {
452                                     xtype: Gtk.HBox,
453                                     pack : "pack_start,false,true,3"
454                                 },
455                                 {
456                                     xtype: Gtk.ScrolledWindow,
457                                     pack : "pack_end,true,true,3",
458                                     shadow_type : Gtk.ShadowType.IN,
459                                     items : [
460                                         {
461                                             xtype: Gtk.TreeView,
462                                             fixed_height_mode : true,
463                                             id : "ticket-view",
464                                             pack : "add",
465                                             can_focus : true,
466                                             headers_visible : false,
467                                             init : function() {
468                                                 XObject.prototype.init.call(this);
469                                                 var description = new Pango.FontDescription.c_new();
470                                                 description.set_size(10000);
471                                                 this.el.modify_font(description);
472                                             
473                                                 this.selection = this.el.get_selection();
474                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
475                                                 var _t = this;
476                                             
477                                                 // is this really needed??
478                                                 this.selection.signal['changed'].connect(function() {
479                                                     print('selection changed');
480                                                 
481                                             
482                                                 });
483                                             
484                                             },
485                                             items : [
486                                                 {
487                                                     xtype: Gtk.ListStore,
488                                                     id : "ticket-store",
489                                                     pack : "set_model",
490                                                     columns : [
491                                                             GObject.TYPE_STRING, // title 
492                                                             GObject.TYPE_STRING, // tip
493                                                             GObject.TYPE_STRING // source..
494                                                     ],
495                                                     init : function() {
496                                                         XObject.prototype.init.call(this);
497                                                     
498                                                         this.el.set_column_types ( 2, [
499                                                             GObject.TYPE_STRING,  // real key
500                                                             GObject.TYPE_STRING // real type
501                                                             
502                                                             
503                                                         ] );
504                                                     
505                                                     
506                                                         
507                                                         // var t = this;
508                                                         //imports.Projects.Projects.fetch(  function(res) { 
509                                                         //    t.loadData(res);
510                                                        // });
511                                                             
512                                                                                     
513                                                     },
514                                                     loadData : function (data) {
515                                                             print("loading data");
516                                                                                         
517                                                         var el = this.el;
518                                                         this.el.clear();
519                                                         data.forEach(function(p) {
520                                                             var ret = {};
521                                                             el.append(ret);
522                                                            //print("ADD " + p.name);
523                                                              
524                                                             el.set_value(ret.iter, 0, p.id);
525                                                             el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' + 
526                                                                 '[' + p.status_name + '] <b>'   + p.summary  + "</b>\n"  +
527                                                                  '<span color="#666">' + p.description.split("\n").slice(0,3).join("\n") +
528                                                                  '</span>'
529                                                                  
530                                                                   );
531                                                             
532                                                         });
533                                                                   
534                                                                                          
535                                                     },
536                                                     reload : function() {
537                                                      
538                                                         var active_id = this.get('/project-select').el.get_active();
539                                                          
540                                                         var project_id = this.get('/project-select').raw_data[active_id].id;
541                                                         
542                                                         var _t = this;
543                                                         
544                                                         imports.Tasks.Tasks.query({
545                                                             project_id : project_id,
546                                                             'query[filter]' : 'me'
547                                                         }, function(res) { 
548                                                             print(JSON.stringify(res,null,4));
549                                                             _t.loadData(res);
550                                                         });
551                                                          
552                                                         
553                                                     }
554                                                 },
555                                                 {
556                                                     xtype: Gtk.TreeViewColumn,
557                                                     pack : "append_column",
558                                                     sizing : Gtk.TreeViewColumnSizing.FIXED,
559                                                     init : function() {
560                                                         XObject.prototype.init.call(this);
561                                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
562                                                     },
563                                                     items : [
564                                                         {
565                                                             xtype: Gtk.CellRendererText,
566                                                             pack : "pack_start"
567                                                         }
568                                                     ]
569                                                 }
570                                             ]
571                                         }
572                                     ]
573                                 }
574                             ]
575                         }
576                     ]
577                 }
578             ]
579         }
580     ]
581 });
582 FixBug.init();
583 XObject.cache['/FixBug'] = FixBug;