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             this.get('/today-vew').load();
27             
28         }
29     },
30     border_width : 3,
31     default_height : 400,
32     default_width : 1200,
33     title : "Select Active Bug",
34     deletable : true,
35     modal : true,
36     show : function(c) {
37         
38         if (!this.el) {
39             this.init();
40         }
41         var _this = this;
42         /*[ 'xtype'  ].forEach(function(k) {
43             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
44         });
45         // shouild set path..
46         */
47     
48         
49         this.el.show_all();
50        // this.get('/ok_button').el.set_sensitive(false);
51         
52         // block until we return.
53         //    var run_ret = this.el.run();
54         //    if (run_ret < 1 ) {
55         //        return false;
56         //    }
57         //    print("RUN RETURN : " + run_ret);
58         
59         //print(JSON.stringify(this.get('bug').getValue()));
60         //return this.get('bug').getValue();
61         //this.success = c.success;
62     },
63     items : [
64         {
65             xtype: Gtk.VBox,
66             pack : "add",
67             items : [
68                 {
69                     xtype: Gtk.HBox,
70                     pack : "pack_start,false,true,3",
71                     items : [
72                         {
73                             xtype: Gtk.Label,
74                             label : "On this project:"
75                         },
76                         {
77                             xtype: Gtk.ComboBox,
78                             listeners : {
79                                 changed : function (self) {
80                                     print("store: active id = " + this.el.get_active_id());
81                                     this.get('/ticket-store').reload();
82                                     
83                                     
84                                 }
85                             },
86                             id : "project-select",
87                             init : function() {
88                                  this.el = new Gtk.ComboBox.with_entry();
89                                                             
90                                                             
91                                 this.model  = new XObject(this.model);
92                                 this.model.init();
93                                 this.el.set_model(this.model.el);
94                                 this.el.set_entry_text_column (0);
95                                 XObject.prototype.init.call(this);
96                                 
97                                  var t = this;
98                                 imports.Projects.Projects.fetch(  function(res) { 
99                                      t.load(res);
100                                 });
101                             },
102                             load : function(tr) {
103                                   this.model.el.clear();
104                                   this.raw_data = tr;                     
105                                      for(var i =0 ; i < tr.length; i++) {
106                                         var ret = {  };
107                                         this.model.el.append(ret);
108                                         //print(JSON.stringify(ret,null,4));
109                                        
110                                         this.model.el.set_value(ret.iter, 0, '' + tr[i].code + " - " + tr[i].name );
111                                         this.model.el.set_value(ret.iter, 1, '' + tr[i].id  );
112                                  
113                                         
114                                     }     
115                                     
116                             },
117                             model : {
118                                 xtype: Gtk.ListStore,
119                                 id : "project-store",
120                                 init : function() {
121                                     XObject.prototype.init.call(this);
122                                     this.el.set_column_types ( 3, [
123                                            GObject.TYPE_STRING, // file  
124                                           GObject.TYPE_STRING, // added
125                                           GObject.TYPE_STRING, // removed
126                                       ] );
127                                 }
128                             }
129                         },
130                         {
131                             xtype: Gtk.Button,
132                             listeners : {
133                                 button_press_event : function (self, event) {
134                                  
135                                     FixBug.el.hide();
136                                 }
137                             },
138                             height_request : 90,
139                             label : "Not working on Project",
140                             pack : "add"
141                         },
142                         {
143                             xtype: Gtk.Button,
144                             listeners : {
145                                 button_press_event : function (self, event) {
146                                 
147                                    FixBug.el.hide();
148                                 }
149                             },
150                             id : "ok_button",
151                             label : "Working on Selected Ticket",
152                             pack : "add"
153                         }
154                     ]
155                 },
156                 {
157                     xtype: Gtk.HPaned,
158                     pack : "pack_end,true,true,3",
159                     items : [
160                         {
161                             xtype: Gtk.VBox,
162                             pack : "add",
163                             width_request : 400,
164                             items : [
165                                 {
166                                     xtype: Gtk.HBox,
167                                     pack : "pack_start,false,true,3",
168                                     items : [
169                                         {
170                                             xtype: Gtk.Entry,
171                                             listeners : {
172                                                 key_release_event : function (self, event) {
173                                                     if (event.key.keyval == Gdk.KEY_Return) {;
174                                                         // same code as button press..
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                                                         print(str);
182                                                         
183                                                         var _t = this;
184                                                         
185                                                         imports.Tasks.Tasks.query({
186                                                             project_id : project_id,
187                                                             'query[filter]' : 'me',
188                                                             'query[search]' : str
189                                                         }, function(res) { 
190                                                            // print(JSON.stringify(res,null,4));
191                                                             _t.get('/ticket-store').loadData(res);
192                                                         });
193                                                     }
194                                                     return true;
195                                                 }
196                                             },
197                                             id : "search-entry",
198                                             pack : "pack_start,true,true,3"
199                                         },
200                                         {
201                                             xtype: Gtk.Button,
202                                             listeners : {
203                                                 clicked : function (self) {
204                                                     var active_id = this.get('/project-select').el.get_active();
205                                                      
206                                                     var project_id = this.get('/project-select').raw_data[active_id].id;
207                                                     
208                                                     var str = this.get('/search-entry').el.get_text();
209                                                     
210                                                     print(str);
211                                                     
212                                                     var _t = this;
213                                                     
214                                                     imports.Tasks.Tasks.query({
215                                                         project_id : project_id,
216                                                         'query[filter]' : 'me',
217                                                         'query[search]' : str
218                                                     }, function(res) { 
219                                                        // print(JSON.stringify(res,null,4));
220                                                         _t.get('/ticket-store').loadData(res);
221                                                     });
222                                                 }
223                                             },
224                                             label : "Search",
225                                             pack : "pack_end,false,true,3",
226                                             use_stock : true
227                                         }
228                                     ]
229                                 },
230                                 {
231                                     xtype: Gtk.ScrolledWindow,
232                                     pack : "pack_end,true,true,3",
233                                     shadow_type : Gtk.ShadowType.IN,
234                                     items : [
235                                         {
236                                             xtype: Gtk.TreeView,
237                                             listeners : {
238                                                 cursor_changed : function (self) {
239                                                     
240                                                     var ret = {};
241                                                     this.selection.get_selected(ret);
242                                                 
243                                                     // var val = "";
244                                                     var value = ''+ret.model.get_value(ret.iter, 0).value.get_string();
245                                                     
246                                                     print(value);
247                                                     
248                                                     
249                                                 
250                                                 }
251                                             },
252                                             id : "ticket-view",
253                                             pack : "add",
254                                             can_focus : true,
255                                             fixed_height_mode : false,
256                                             headers_visible : false,
257                                             init : function() {
258                                                 XObject.prototype.init.call(this);
259                                                 var description = new Pango.FontDescription.c_new();
260                                                 description.set_size(10000);
261                                                 this.el.modify_font(description);
262                                             
263                                                 this.selection = this.el.get_selection();
264                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
265                                                 var _t = this;
266                                             
267                                                 // is this really needed??
268                                                 this.selection.signal['changed'].connect(function() {
269                                                     print('selection changed');
270                                                 
271                                             
272                                                 });
273                                             
274                                             },
275                                             items : [
276                                                 {
277                                                     xtype: Gtk.ListStore,
278                                                     id : "ticket-store",
279                                                     pack : "set_model",
280                                                     columns : [
281                                                             GObject.TYPE_STRING, // title 
282                                                             GObject.TYPE_STRING, // tip
283                                                             GObject.TYPE_STRING // source..
284                                                     ],
285                                                     init : function() {
286                                                         XObject.prototype.init.call(this);
287                                                     
288                                                         this.el.set_column_types ( 2, [
289                                                             GObject.TYPE_STRING,  // real key
290                                                             GObject.TYPE_STRING // real type
291                                                             
292                                                             
293                                                         ] );
294                                                     
295                                                     
296                                                         
297                                                         // var t = this;
298                                                         //imports.Projects.Projects.fetch(  function(res) { 
299                                                         //    t.loadData(res);
300                                                        // });
301                                                             
302                                                                                     
303                                                     },
304                                                     loadData : function (data) {
305                                                             print("loading data");
306                                                                                         
307                                                         var el = this.el;
308                                                         this.el.clear();
309                                                         data.forEach(function(p) {
310                                                             var ret = {};
311                                                             el.append(ret);
312                                                            //print("ADD " + p.name);
313                                                              
314                                                            var line =    '[' + p.status_name + '] <b>'   + 
315                                                                  GLib.markup_escape_text(p.summary, p.summary.length)  + "</b>\n"  +
316                                                                  '<span color="#666">' + 
317                                                                  GLib.markup_escape_text(p.description,p.description.length).split("\n").slice(0,3).join("\n") +
318                                                                  '</span>';
319                                                              print(line);
320                                                              
321                                                             el.set_value(ret.iter, 0, p.id);
322                                                             el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' +  line );
323                                                             
324                                                         });
325                                                                   
326                                                                                          
327                                                     },
328                                                     reload : function() {
329                                                      
330                                                         var active_id = this.get('/project-select').el.get_active();
331                                                          
332                                                         var project_id = this.get('/project-select').raw_data[active_id].id;
333                                                         
334                                                         var _t = this;
335                                                         
336                                                         imports.Tasks.Tasks.query({
337                                                             project_id : project_id,
338                                                             'query[filter]' : 'me'
339                                                         }, function(res) { 
340                                                             print(JSON.stringify(res,null,4));
341                                                             _t.loadData(res);
342                                                         });
343                                                          
344                                                         
345                                                     }
346                                                 },
347                                                 {
348                                                     xtype: Gtk.TreeViewColumn,
349                                                     pack : "append_column",
350                                                     init : function() {
351                                                         XObject.prototype.init.call(this);
352                                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
353                                                     },
354                                                     items : [
355                                                         {
356                                                             xtype: Gtk.CellRendererText,
357                                                             pack : "pack_start"
358                                                         }
359                                                     ]
360                                                 }
361                                             ]
362                                         }
363                                     ]
364                                 }
365                             ]
366                         },
367                         {
368                             xtype: Gtk.HPaned,
369                             pack : "add",
370                             items : [
371                                 {
372                                     xtype: Gtk.VBox,
373                                     pack : "pack1,true,true",
374                                     items : [
375                                         {
376                                             xtype: Gtk.HBox,
377                                             pack : "pack_start,false,true,3",
378                                             items : [
379                                                 {
380                                                     xtype: Gtk.Label,
381                                                     label : "I am doing this:",
382                                                     pack : "pack_start,false,true,3"
383                                                 },
384                                                 {
385                                                     xtype: Gtk.Entry,
386                                                     pack : "pack_start,true,true,3"
387                                                 }
388                                             ]
389                                         },
390                                         {
391                                             xtype: Gtk.HBox,
392                                             pack : "pack_start,false,true,3",
393                                             items : [
394                                                 {
395                                                     xtype: Gtk.Label,
396                                                     label : "Since:",
397                                                     pack : "pack_start,false,true,3"
398                                                 },
399                                                 {
400                                                     xtype: Gtk.Entry,
401                                                     pack : "pack_start,false,false,3",
402                                                     width_request : 80
403                                                 },
404                                                 {
405                                                     xtype: Gtk.Label,
406                                                     label : "Until",
407                                                     pack : "pack_start,false,true,3"
408                                                 },
409                                                 {
410                                                     xtype: Gtk.Entry,
411                                                     pack : "pack_start,true,true,3"
412                                                 }
413                                             ]
414                                         },
415                                         {
416                                             xtype: Gtk.ScrolledWindow,
417                                             pack : "add",
418                                             id : "RightEditor",
419                                             items : [
420                                                 {
421                                                     xtype: Gtk.TextView,
422                                                     editable : false,
423                                                     id : "view",
424                                                     indent_width : 4,
425                                                     pack : "add",
426                                                     auto_indent : true,
427                                                     init : function() {
428                                                         XObject.prototype.init.call(this);
429                                                         var description = Pango.font_description_from_string("monospace");
430                                                     
431                                                         description.set_size(8000);
432                                                         this.el.modify_font(description);
433                                                     
434                                                     },
435                                                     load : function(str) {
436                                                     
437                                                     // show the help page for the active node..
438                                                      
439                                                     
440                                                     
441                                                      
442                                                         this.el.get_buffer().set_text(str, str.length);
443                                                      
444                                                         
445                                                          var buf = this.el.get_buffer();
446                                                          
447                                                          
448                                                         
449                                                     },
450                                                     show_line_numbers : true,
451                                                     items : [
452                                                         {
453                                                             xtype: GtkSource.Buffer,
454                                                             listeners : {
455                                                                 changed : function (self) {
456                                                                     /*
457                                                                     var s = new Gtk.TextIter();
458                                                                     var e = new Gtk.TextIter();
459                                                                     this.el.get_start_iter(s);
460                                                                     this.el.get_end_iter(e);
461                                                                     var str = this.el.get_text(s,e,true);
462                                                                     try {
463                                                                         Seed.check_syntax('var e = ' + str);
464                                                                     } catch (e) {
465                                                                         this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
466                                                                             red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
467                                                                            }));
468                                                                         //print("SYNTAX ERROR IN EDITOR");   
469                                                                         //print(e);
470                                                                         //console.dump(e);
471                                                                         return;
472                                                                     }
473                                                                     this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
474                                                                             red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
475                                                                            }));
476                                                                     
477                                                                      this.get('/LeftPanel.model').changed(  str , false);
478                                                                      */
479                                                                 }
480                                                             },
481                                                             pack : "set_buffer"
482                                                         }
483                                                     ]
484                                                 }
485                                             ]
486                                         }
487                                     ]
488                                 },
489                                 {
490                                     xtype: Gtk.VBox,
491                                     pack : "pack2,false,false",
492                                     width_request : 200,
493                                     items : [
494                                         {
495                                             xtype: Gtk.HBox,
496                                             pack : "pack_start,false,true,3",
497                                             items : [
498                                                 {
499                                                     xtype: Gtk.Button,
500                                                     listeners : {
501                                                         clicked : function (self) {
502                                                          
503                                                         }
504                                                     },
505                                                     label : "Next/Back",
506                                                     pack : "pack_end,false,true,3",
507                                                     use_stock : true
508                                                 }
509                                             ]
510                                         },
511                                         {
512                                             xtype: Gtk.ScrolledWindow,
513                                             pack : "pack_end,true,true,3",
514                                             shadow_type : Gtk.ShadowType.IN,
515                                             items : [
516                                                 {
517                                                     xtype: Gtk.TreeView,
518                                                     id : "today-view",
519                                                     pack : "add",
520                                                     can_focus : true,
521                                                     fixed_height_mode : true,
522                                                     headers_visible : false,
523                                                     init : function() {
524                                                         XObject.prototype.init.call(this);
525                                                         var description = new Pango.FontDescription.c_new();
526                                                         description.set_size(10000);
527                                                         this.el.modify_font(description);
528                                                     
529                                                         this.selection = this.el.get_selection();
530                                                         this.selection.set_mode( Gtk.SelectionMode.SINGLE);
531                                                         var _t = this;
532                                                     
533                                                         // is this really needed??
534                                                         this.selection.signal['changed'].connect(function() {
535                                                             print('selection changed');
536                                                         
537                                                     
538                                                         });
539                                                     
540                                                     },
541                                                     items : [
542                                                         {
543                                                             xtype: Gtk.ListStore,
544                                                             id : "today-store",
545                                                             pack : "set_model",
546                                                             columns : [
547                                                                     GObject.TYPE_STRING, // title 
548                                                                     GObject.TYPE_STRING, // tip
549                                                                     GObject.TYPE_STRING // source..
550                                                             ],
551                                                             init : function() {
552                                                                 XObject.prototype.init.call(this);
553                                                             
554                                                                 this.el.set_column_types ( 2, [
555                                                                     GObject.TYPE_STRING,  // real key
556                                                                     GObject.TYPE_STRING // real type
557                                                                     
558                                                                     
559                                                                 ] );
560                                                             
561                                                             
562                                                                 
563                                                                 // var t = this;
564                                                                 //imports.Projects.Projects.fetch(  function(res) { 
565                                                                 //    t.loadData(res);
566                                                                // });
567                                                                     
568                                                                                             
569                                                             },
570                                                             loadData : function (data) {
571                                                                     print("loading data");
572                                                                                                 
573                                                                 var el = this.el;
574                                                                 this.el.clear();
575                                                                 data.forEach(function(p) {
576                                                                     var ret = {};
577                                                                     el.append(ret);
578                                                                    //print("ADD " + p.name);
579                                                                      
580                                                                     el.set_value(ret.iter, 0, p.id);
581                                                                     el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' + 
582                                                                         '[' + p.status_name + '] <b>'   + p.summary  + "</b>\n"  +
583                                                                          '<span color="#666">' + p.description.split("\n").slice(0,3).join("\n") +
584                                                                          '</span>'
585                                                                          
586                                                                           );
587                                                                     
588                                                                 });
589                                                                           
590                                                                                                  
591                                                             },
592                                                             reload : function() {
593                                                              
594                                                                 var active_id = this.get('/project-select').el.get_active();
595                                                                  
596                                                                 var project_id = this.get('/project-select').raw_data[active_id].id;
597                                                                 
598                                                                 var _t = this;
599                                                                  
600                                                                 var DT = imports.Date.Date;
601                                                                 
602                                                                 new imports.Request.Request( {
603                                                                    url : '/cash_invoice_entry',
604                                                                    params : {
605                                                                         'query[action_dt_from]' : (new DT()).format('Y-m-d'),
606                                                                          'query[action_dt_to]' : (new DT()).add(DT.DAY,1).format('Y-m-d'),
607                                                                         limit: 999,
608                                                                         'sort' : 'action_dt',
609                                                                         dir : 'ASC',
610                                                                         action : 'Hours'
611                                                                    },
612                                                                    
613                                                                    success : function(res) {
614                                                                        this.loadData();
615                                                                    },
616                                                                    scope : this
617                                                                     
618                                                                     
619                                                                 });
620                                                                  
621                                                                  
622                                                                 
623                                                             }
624                                                         },
625                                                         {
626                                                             xtype: Gtk.TreeViewColumn,
627                                                             pack : "append_column",
628                                                             sizing : Gtk.TreeViewColumnSizing.FIXED,
629                                                             init : function() {
630                                                                 XObject.prototype.init.call(this);
631                                                                 this.el.add_attribute(this.items[0].el , 'markup', 1 );
632                                                             },
633                                                             items : [
634                                                                 {
635                                                                     xtype: Gtk.CellRendererText,
636                                                                     pack : "pack_start"
637                                                                 }
638                                                             ]
639                                                         }
640                                                     ]
641                                                 }
642                                             ]
643                                         }
644                                     ]
645                                 }
646                             ]
647                         }
648                     ]
649                 }
650             ]
651         }
652     ]
653 });
654 FixBug.init();
655 XObject.cache['/FixBug'] = FixBug;