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                                                     var rec = false;
248                                                     this.get('/ticket-store').data.forEach( function(e) {
249                                                         if (e.id == value) {
250                                                             rec = e;
251                                                             return  false;
252                                                         }
253                                                     });
254                                                     print(rec);
255                                                 
256                                                 }
257                                             },
258                                             id : "ticket-view",
259                                             pack : "add",
260                                             can_focus : true,
261                                             fixed_height_mode : false,
262                                             headers_visible : false,
263                                             init : function() {
264                                                 XObject.prototype.init.call(this);
265                                                 var description = new Pango.FontDescription.c_new();
266                                                 description.set_size(10000);
267                                                 this.el.modify_font(description);
268                                             
269                                                 this.selection = this.el.get_selection();
270                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
271                                                 var _t = this;
272                                             
273                                                 // is this really needed??
274                                                 this.selection.signal['changed'].connect(function() {
275                                                     print('selection changed');
276                                                 
277                                             
278                                                 });
279                                             
280                                             },
281                                             items : [
282                                                 {
283                                                     xtype: Gtk.ListStore,
284                                                     id : "ticket-store",
285                                                     pack : "set_model",
286                                                     columns : [
287                                                             GObject.TYPE_STRING, // title 
288                                                             GObject.TYPE_STRING, // tip
289                                                             GObject.TYPE_STRING // source..
290                                                     ],
291                                                     init : function() {
292                                                         XObject.prototype.init.call(this);
293                                                     
294                                                         this.el.set_column_types ( 2, [
295                                                             GObject.TYPE_STRING,  // real key
296                                                             GObject.TYPE_STRING // real type
297                                                             
298                                                             
299                                                         ] );
300                                                     
301                                                     
302                                                         
303                                                         // var t = this;
304                                                         //imports.Projects.Projects.fetch(  function(res) { 
305                                                         //    t.loadData(res);
306                                                        // });
307                                                             
308                                                                                     
309                                                     },
310                                                     loadData : function (data) {
311                                                             print("loading data");
312                                                         
313                                                         
314                                                         this.data = data;
315                                                                               
316                                                         var el = this.el;
317                                                         this.el.clear();
318                                                         data.forEach(function(p) {
319                                                             var ret = {};
320                                                             el.append(ret);
321                                                            //print("ADD " + p.name);
322                                                              
323                                                            var line =    '[' + p.status_name + '] <b>'   + 
324                                                                  GLib.markup_escape_text(p.summary, p.summary.length)  + "</b>\n"  +
325                                                                  '<span color="#666">' + 
326                                                                  GLib.markup_escape_text(p.description,p.description.length).split("\n").slice(0,3).join("\n") +
327                                                                  '</span>';
328                                                              print(line);
329                                                              
330                                                             el.set_value(ret.iter, 0, p.id);
331                                                             el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' +  line );
332                                                             
333                                                         });
334                                                                   
335                                                                                          
336                                                     },
337                                                     reload : function() {
338                                                      
339                                                         var active_id = this.get('/project-select').el.get_active();
340                                                          
341                                                         var project_id = this.get('/project-select').raw_data[active_id].id;
342                                                         
343                                                         var _t = this;
344                                                         
345                                                         imports.Tasks.Tasks.query({
346                                                             project_id : project_id,
347                                                             'query[filter]' : 'me'
348                                                         }, function(res) { 
349                                                             print(JSON.stringify(res,null,4));
350                                                             _t.loadData(res);
351                                                         });
352                                                          
353                                                         
354                                                     }
355                                                 },
356                                                 {
357                                                     xtype: Gtk.TreeViewColumn,
358                                                     pack : "append_column",
359                                                     init : function() {
360                                                         XObject.prototype.init.call(this);
361                                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
362                                                     },
363                                                     items : [
364                                                         {
365                                                             xtype: Gtk.CellRendererText,
366                                                             pack : "pack_start"
367                                                         }
368                                                     ]
369                                                 }
370                                             ]
371                                         }
372                                     ]
373                                 }
374                             ]
375                         },
376                         {
377                             xtype: Gtk.HPaned,
378                             pack : "add",
379                             items : [
380                                 {
381                                     xtype: Gtk.VBox,
382                                     pack : "pack1,true,true",
383                                     items : [
384                                         {
385                                             xtype: Gtk.HBox,
386                                             pack : "pack_start,false,true,3",
387                                             items : [
388                                                 {
389                                                     xtype: Gtk.Label,
390                                                     label : "I am doing this:",
391                                                     pack : "pack_start,false,true,3"
392                                                 },
393                                                 {
394                                                     xtype: Gtk.Entry,
395                                                     pack : "pack_start,true,true,3"
396                                                 }
397                                             ]
398                                         },
399                                         {
400                                             xtype: Gtk.HBox,
401                                             pack : "pack_start,false,true,3",
402                                             items : [
403                                                 {
404                                                     xtype: Gtk.Label,
405                                                     label : "Since:",
406                                                     pack : "pack_start,false,true,3"
407                                                 },
408                                                 {
409                                                     xtype: Gtk.Entry,
410                                                     pack : "pack_start,false,false,3",
411                                                     width_request : 80
412                                                 },
413                                                 {
414                                                     xtype: Gtk.Label,
415                                                     label : "Until",
416                                                     pack : "pack_start,false,true,3"
417                                                 },
418                                                 {
419                                                     xtype: Gtk.Entry,
420                                                     pack : "pack_start,true,true,3"
421                                                 }
422                                             ]
423                                         },
424                                         {
425                                             xtype: Gtk.ScrolledWindow,
426                                             pack : "add",
427                                             id : "RightEditor",
428                                             items : [
429                                                 {
430                                                     xtype: Gtk.TextView,
431                                                     editable : false,
432                                                     id : "view",
433                                                     indent_width : 4,
434                                                     pack : "add",
435                                                     auto_indent : true,
436                                                     init : function() {
437                                                         XObject.prototype.init.call(this);
438                                                         var description = Pango.font_description_from_string("monospace");
439                                                     
440                                                         description.set_size(8000);
441                                                         this.el.modify_font(description);
442                                                     
443                                                     },
444                                                     load : function(str) {
445                                                     
446                                                     // show the help page for the active node..
447                                                      
448                                                     
449                                                     
450                                                      
451                                                         this.el.get_buffer().set_text(str, str.length);
452                                                      
453                                                         
454                                                          var buf = this.el.get_buffer();
455                                                          
456                                                          
457                                                         
458                                                     },
459                                                     show_line_numbers : true,
460                                                     items : [
461                                                         {
462                                                             xtype: GtkSource.Buffer,
463                                                             listeners : {
464                                                                 changed : function (self) {
465                                                                     /*
466                                                                     var s = new Gtk.TextIter();
467                                                                     var e = new Gtk.TextIter();
468                                                                     this.el.get_start_iter(s);
469                                                                     this.el.get_end_iter(e);
470                                                                     var str = this.el.get_text(s,e,true);
471                                                                     try {
472                                                                         Seed.check_syntax('var e = ' + str);
473                                                                     } catch (e) {
474                                                                         this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
475                                                                             red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
476                                                                            }));
477                                                                         //print("SYNTAX ERROR IN EDITOR");   
478                                                                         //print(e);
479                                                                         //console.dump(e);
480                                                                         return;
481                                                                     }
482                                                                     this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
483                                                                             red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
484                                                                            }));
485                                                                     
486                                                                      this.get('/LeftPanel.model').changed(  str , false);
487                                                                      */
488                                                                 }
489                                                             },
490                                                             pack : "set_buffer"
491                                                         }
492                                                     ]
493                                                 }
494                                             ]
495                                         }
496                                     ]
497                                 },
498                                 {
499                                     xtype: Gtk.VBox,
500                                     pack : "pack2,false,false",
501                                     width_request : 200,
502                                     items : [
503                                         {
504                                             xtype: Gtk.HBox,
505                                             pack : "pack_start,false,true,3",
506                                             items : [
507                                                 {
508                                                     xtype: Gtk.Button,
509                                                     listeners : {
510                                                         clicked : function (self) {
511                                                          
512                                                         }
513                                                     },
514                                                     label : "Next/Back",
515                                                     pack : "pack_end,false,true,3",
516                                                     use_stock : true
517                                                 }
518                                             ]
519                                         },
520                                         {
521                                             xtype: Gtk.ScrolledWindow,
522                                             pack : "pack_end,true,true,3",
523                                             shadow_type : Gtk.ShadowType.IN,
524                                             items : [
525                                                 {
526                                                     xtype: Gtk.TreeView,
527                                                     id : "today-view",
528                                                     pack : "add",
529                                                     can_focus : true,
530                                                     fixed_height_mode : true,
531                                                     headers_visible : false,
532                                                     init : function() {
533                                                         XObject.prototype.init.call(this);
534                                                         var description = new Pango.FontDescription.c_new();
535                                                         description.set_size(10000);
536                                                         this.el.modify_font(description);
537                                                     
538                                                         this.selection = this.el.get_selection();
539                                                         this.selection.set_mode( Gtk.SelectionMode.SINGLE);
540                                                         var _t = this;
541                                                     
542                                                         // is this really needed??
543                                                         this.selection.signal['changed'].connect(function() {
544                                                             print('selection changed');
545                                                         
546                                                     
547                                                         });
548                                                     
549                                                     },
550                                                     items : [
551                                                         {
552                                                             xtype: Gtk.ListStore,
553                                                             id : "today-store",
554                                                             pack : "set_model",
555                                                             columns : [
556                                                                     GObject.TYPE_STRING, // title 
557                                                                     GObject.TYPE_STRING, // tip
558                                                                     GObject.TYPE_STRING // source..
559                                                             ],
560                                                             init : function() {
561                                                                 XObject.prototype.init.call(this);
562                                                             
563                                                                 this.el.set_column_types ( 2, [
564                                                                     GObject.TYPE_STRING,  // real key
565                                                                     GObject.TYPE_STRING // real type
566                                                                     
567                                                                     
568                                                                 ] );
569                                                             
570                                                             
571                                                                 
572                                                                 // var t = this;
573                                                                 //imports.Projects.Projects.fetch(  function(res) { 
574                                                                 //    t.loadData(res);
575                                                                // });
576                                                                     
577                                                                                             
578                                                             },
579                                                             loadData : function (data) {
580                                                                     print("loading data");
581                                                                                                 
582                                                                 var el = this.el;
583                                                                 this.el.clear();
584                                                                 data.forEach(function(p) {
585                                                                     var ret = {};
586                                                                     el.append(ret);
587                                                                    //print("ADD " + p.name);
588                                                                      
589                                                                     el.set_value(ret.iter, 0, p.id);
590                                                                     el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' + 
591                                                                         '[' + p.status_name + '] <b>'   + p.summary  + "</b>\n"  +
592                                                                          '<span color="#666">' + p.description.split("\n").slice(0,3).join("\n") +
593                                                                          '</span>'
594                                                                          
595                                                                           );
596                                                                     
597                                                                 });
598                                                                           
599                                                                                                  
600                                                             },
601                                                             reload : function() {
602                                                              
603                                                                 var active_id = this.get('/project-select').el.get_active();
604                                                                  
605                                                                 var project_id = this.get('/project-select').raw_data[active_id].id;
606                                                                 
607                                                                 var _t = this;
608                                                                  
609                                                                 var DT = imports.Date.Date;
610                                                                 
611                                                                 new imports.Request.Request( {
612                                                                    url : '/cash_invoice_entry',
613                                                                    params : {
614                                                                         'query[action_dt_from]' : (new DT()).format('Y-m-d'),
615                                                                          'query[action_dt_to]' : (new DT()).add(DT.DAY,1).format('Y-m-d'),
616                                                                         limit: 999,
617                                                                         'sort' : 'action_dt',
618                                                                         dir : 'ASC',
619                                                                         action : 'Hours'
620                                                                    },
621                                                                    
622                                                                    success : function(res) {
623                                                                        this.loadData();
624                                                                    },
625                                                                    scope : this
626                                                                     
627                                                                     
628                                                                 });
629                                                                  
630                                                                  
631                                                                 
632                                                             }
633                                                         },
634                                                         {
635                                                             xtype: Gtk.TreeViewColumn,
636                                                             pack : "append_column",
637                                                             sizing : Gtk.TreeViewColumnSizing.FIXED,
638                                                             init : function() {
639                                                                 XObject.prototype.init.call(this);
640                                                                 this.el.add_attribute(this.items[0].el , 'markup', 1 );
641                                                             },
642                                                             items : [
643                                                                 {
644                                                                     xtype: Gtk.CellRendererText,
645                                                                     pack : "pack_start"
646                                                                 }
647                                                             ]
648                                                         }
649                                                     ]
650                                                 }
651                                             ]
652                                         }
653                                     ]
654                                 }
655                             ]
656                         }
657                     ]
658                 }
659             ]
660         }
661     ]
662 });
663 FixBug.init();
664 XObject.cache['/FixBug'] = FixBug;