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 : 1200,
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.HPaned,
330                             pack : "add",
331                             items : [
332                                 {
333                                     xtype: Gtk.VBox,
334                                     pack : "add",
335                                     items : [
336                                         {
337                                             xtype: Gtk.HBox,
338                                             pack : "pack_start,false,true,3",
339                                             items : [
340                                                 {
341                                                     xtype: Gtk.Label,
342                                                     label : "I am doing this:",
343                                                     pack : "pack_start,false,true,3"
344                                                 },
345                                                 {
346                                                     xtype: Gtk.Entry,
347                                                     pack : "pack_start,true,true,3"
348                                                 }
349                                             ]
350                                         },
351                                         {
352                                             xtype: Gtk.HBox,
353                                             pack : "pack_start,false,true,3",
354                                             items : [
355                                                 {
356                                                     xtype: Gtk.Label,
357                                                     label : "Since:",
358                                                     pack : "pack_start,false,true,3"
359                                                 },
360                                                 {
361                                                     xtype: Gtk.Entry,
362                                                     pack : "pack_start,false,false,3",
363                                                     width_request : 80
364                                                 },
365                                                 {
366                                                     xtype: Gtk.Label,
367                                                     label : "Until",
368                                                     pack : "pack_start,false,true,3"
369                                                 },
370                                                 {
371                                                     xtype: Gtk.Entry,
372                                                     pack : "pack_start,true,true,3"
373                                                 }
374                                             ]
375                                         },
376                                         {
377                                             xtype: Gtk.ScrolledWindow,
378                                             pack : "add",
379                                             id : "RightEditor",
380                                             items : [
381                                                 {
382                                                     xtype: Gtk.TextView,
383                                                     editable : false,
384                                                     id : "view",
385                                                     indent_width : 4,
386                                                     pack : "add",
387                                                     auto_indent : true,
388                                                     init : function() {
389                                                         XObject.prototype.init.call(this);
390                                                         var description = Pango.font_description_from_string("monospace");
391                                                     
392                                                         description.set_size(8000);
393                                                         this.el.modify_font(description);
394                                                     
395                                                     },
396                                                     load : function(str) {
397                                                     
398                                                     // show the help page for the active node..
399                                                      
400                                                     
401                                                     
402                                                      
403                                                         this.el.get_buffer().set_text(str, str.length);
404                                                      
405                                                         
406                                                          var buf = this.el.get_buffer();
407                                                          
408                                                          
409                                                         
410                                                     },
411                                                     show_line_numbers : true,
412                                                     items : [
413                                                         {
414                                                             xtype: GtkSource.Buffer,
415                                                             listeners : {
416                                                                 changed : function (self) {
417                                                                     /*
418                                                                     var s = new Gtk.TextIter();
419                                                                     var e = new Gtk.TextIter();
420                                                                     this.el.get_start_iter(s);
421                                                                     this.el.get_end_iter(e);
422                                                                     var str = this.el.get_text(s,e,true);
423                                                                     try {
424                                                                         Seed.check_syntax('var e = ' + str);
425                                                                     } catch (e) {
426                                                                         this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
427                                                                             red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
428                                                                            }));
429                                                                         //print("SYNTAX ERROR IN EDITOR");   
430                                                                         //print(e);
431                                                                         //console.dump(e);
432                                                                         return;
433                                                                     }
434                                                                     this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
435                                                                             red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
436                                                                            }));
437                                                                     
438                                                                      this.get('/LeftPanel.model').changed(  str , false);
439                                                                      */
440                                                                 }
441                                                             },
442                                                             pack : "set_buffer"
443                                                         }
444                                                     ]
445                                                 }
446                                             ]
447                                         }
448                                     ]
449                                 },
450                                 {
451                                     xtype: Gtk.VBox,
452                                     pack : "add",
453                                     width_request : 200,
454                                     items : [
455                                         {
456                                             xtype: Gtk.HBox,
457                                             pack : "pack_start,false,true,3",
458                                             items : [
459                                                 {
460                                                     xtype: Gtk.Button,
461                                                     listeners : {
462                                                         clicked : function (self) {
463                                                          
464                                                         }
465                                                     },
466                                                     label : "Next/Back",
467                                                     pack : "pack_end,false,true,3",
468                                                     use_stock : true
469                                                 }
470                                             ]
471                                         },
472                                         {
473                                             xtype: Gtk.ScrolledWindow,
474                                             pack : "pack_end,true,true,3",
475                                             shadow_type : Gtk.ShadowType.IN,
476                                             items : [
477                                                 {
478                                                     xtype: Gtk.TreeView,
479                                                     fixed_height_mode : true,
480                                                     id : "ticket-view",
481                                                     pack : "add",
482                                                     can_focus : true,
483                                                     headers_visible : false,
484                                                     init : function() {
485                                                         XObject.prototype.init.call(this);
486                                                         var description = new Pango.FontDescription.c_new();
487                                                         description.set_size(10000);
488                                                         this.el.modify_font(description);
489                                                     
490                                                         this.selection = this.el.get_selection();
491                                                         this.selection.set_mode( Gtk.SelectionMode.SINGLE);
492                                                         var _t = this;
493                                                     
494                                                         // is this really needed??
495                                                         this.selection.signal['changed'].connect(function() {
496                                                             print('selection changed');
497                                                         
498                                                     
499                                                         });
500                                                     
501                                                     },
502                                                     items : [
503                                                         {
504                                                             xtype: Gtk.ListStore,
505                                                             id : "ticket-store",
506                                                             pack : "set_model",
507                                                             columns : [
508                                                                     GObject.TYPE_STRING, // title 
509                                                                     GObject.TYPE_STRING, // tip
510                                                                     GObject.TYPE_STRING // source..
511                                                             ],
512                                                             init : function() {
513                                                                 XObject.prototype.init.call(this);
514                                                             
515                                                                 this.el.set_column_types ( 2, [
516                                                                     GObject.TYPE_STRING,  // real key
517                                                                     GObject.TYPE_STRING // real type
518                                                                     
519                                                                     
520                                                                 ] );
521                                                             
522                                                             
523                                                                 
524                                                                 // var t = this;
525                                                                 //imports.Projects.Projects.fetch(  function(res) { 
526                                                                 //    t.loadData(res);
527                                                                // });
528                                                                     
529                                                                                             
530                                                             },
531                                                             loadData : function (data) {
532                                                                     print("loading data");
533                                                                                                 
534                                                                 var el = this.el;
535                                                                 this.el.clear();
536                                                                 data.forEach(function(p) {
537                                                                     var ret = {};
538                                                                     el.append(ret);
539                                                                    //print("ADD " + p.name);
540                                                                      
541                                                                     el.set_value(ret.iter, 0, p.id);
542                                                                     el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' + 
543                                                                         '[' + p.status_name + '] <b>'   + p.summary  + "</b>\n"  +
544                                                                          '<span color="#666">' + p.description.split("\n").slice(0,3).join("\n") +
545                                                                          '</span>'
546                                                                          
547                                                                           );
548                                                                     
549                                                                 });
550                                                                           
551                                                                                                  
552                                                             },
553                                                             reload : function() {
554                                                              
555                                                                 var active_id = this.get('/project-select').el.get_active();
556                                                                  
557                                                                 var project_id = this.get('/project-select').raw_data[active_id].id;
558                                                                 
559                                                                 var _t = this;
560                                                                 
561                                                                 imports.Tasks.Tasks.query({
562                                                                     project_id : project_id,
563                                                                     'query[filter]' : 'me'
564                                                                 }, function(res) { 
565                                                                     print(JSON.stringify(res,null,4));
566                                                                     _t.loadData(res);
567                                                                 });
568                                                                  
569                                                                 
570                                                             }
571                                                         },
572                                                         {
573                                                             xtype: Gtk.TreeViewColumn,
574                                                             pack : "append_column",
575                                                             sizing : Gtk.TreeViewColumnSizing.FIXED,
576                                                             init : function() {
577                                                                 XObject.prototype.init.call(this);
578                                                                 this.el.add_attribute(this.items[0].el , 'markup', 1 );
579                                                             },
580                                                             items : [
581                                                                 {
582                                                                     xtype: Gtk.CellRendererText,
583                                                                     pack : "pack_start"
584                                                                 }
585                                                             ]
586                                                         }
587                                                     ]
588                                                 }
589                                             ]
590                                         }
591                                     ]
592                                 }
593                             ]
594                         }
595                     ]
596                 }
597             ]
598         }
599     ]
600 });
601 FixBug.init();
602 XObject.cache['/FixBug'] = FixBug;