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