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