Changed NewBranch.bjsNewBranch.valaRooTicket.valaTicket.bjsTicket.vala
[gitlive] / NewBranch.vala
1 static NewBranch  _NewBranch;
2
3 public class NewBranch : Object
4 {
5     public Gtk.Dialog el;
6     private NewBranch  _this;
7
8     public static NewBranch singleton()
9     {
10         if (_NewBranch == null) {
11             _NewBranch= new NewBranch();
12         }
13         return _NewBranch;
14     }
15     public Xcls_projectsel projectsel;
16     public Xcls_prcellrenderer prcellrenderer;
17     public Xcls_prmodel prmodel;
18     public Xcls_ticketsel ticketsel;
19     public Xcls_dbcellrenderer dbcellrenderer;
20     public Xcls_dbmodel dbmodel;
21     public Xcls_name name;
22     public Xcls_btn_not_me btn_not_me;
23     public Xcls_btn_closed btn_closed;
24     public Xcls_scrolled_window scrolled_window;
25     public Xcls_view view;
26
27         // my vars (def)
28     public GitRepo? repo;
29     public bool running;
30     public Gee.ArrayList<GitMonitorQueue> queue;
31
32     // ctor
33     public NewBranch()
34     {
35         _this = this;
36         this.el = new Gtk.Dialog();
37
38         // my vars (dec)
39         this.repo = null;
40         this.running = false;
41         this.queue = null;
42
43         // set gobject values
44         this.el.title = "Create a working branch ";
45         this.el.default_height = 500;
46         this.el.default_width = 500;
47         this.el.deletable = true;
48         this.el.modal = true;
49         var child_0 = new Xcls_Box2( _this );
50         child_0.ref();
51         this.el.get_content_area().add (  child_0.el  );
52
53         //listeners
54         this.el.delete_event.connect( (self, event) => {
55             this.el.hide();
56             return true; 
57             //test  
58         });
59         this.el.response.connect( (self, response_id) =>  { 
60           
61                 GLib.debug("got %d", (int) response_id);
62                 if (response_id < 1) {
63                     _this.el.hide();    
64                     this.running = false; 
65                         return;
66                 }
67                  
68                 // have they selected a ticket..
69                 // make that the current active ticket?
70                 // we really need to store locally what ticket is being worked on..
71                 // in theory we could be working on multiple project and not merging..
72                 // -- each repo would have their active ticket (only one per repo)
73                 // -- so we could just store that in there
74                 // -- initial load can check the contents of the ticket files on first scan.
75                 var ticket_id = _this.ticketsel.selectedTicketId();
76                 
77             if (this.repo != null) {
78                 var bn = _this.name.el.get_text();
79         
80                         var res = this.repo.setActiveTicket(                    
81                                  RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
82                          );
83                          if (res) {
84                                 // start the monitoring..
85                                  GitMonitor.gitmonitor.start();
86                                  
87                          }
88             }
89             
90         
91             this.running = false; 
92         
93                 this.el.hide();
94                  
95                  
96         
97                  
98         });
99     }
100
101     // user defined functions
102     public   void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" ) 
103     {
104          // this.el.set_gravity(Gdk.Gravity.NORTH);
105         if (this.running) { // should not happen!!
106                 GLib.error("new branch show called, when already being displayed?");
107         }
108         this.queue = queue;
109         
110         this.running  = true;
111         GitMonitor.gitmonitor.stop();
112         
113         this.repo = repo;
114         
115          
116         
117         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
118         this.el.set_default_size( 500,200); // not sure why it grows..
119         GLib.debug("Loading tickets"); 
120          
121     
122         this.el.show_all();
123         this.el.set_keep_above(true);
124        
125         
126         var curproj = RooProject.getProjectByRepo(this.repo);
127          _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
128         
129         _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
130     
131         if (tid != "") {
132                 var name = RooTicket.singleton().usernameLocal();
133                 var ticket = RooTicket.singleton().getById(tid);
134                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
135     
136     
137         }
138         _this.view.loadTicket(tid);
139         this.el.run();
140     
141     }
142     public class Xcls_Box2 : Object
143     {
144         public Gtk.Box el;
145         private NewBranch  _this;
146
147
148             // my vars (def)
149
150         // ctor
151         public Xcls_Box2(NewBranch _owner )
152         {
153             _this = _owner;
154             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
155
156             // my vars (dec)
157
158             // set gobject values
159             var child_0 = new Xcls_Table3( _this );
160             child_0.ref();
161             this.el.pack_start (  child_0.el , false,false,0 );
162             var child_1 = new Xcls_scrolled_window( _this );
163             child_1.ref();
164             this.el.add (  child_1.el  );
165         }
166
167         // user defined functions
168     }
169     public class Xcls_Table3 : Object
170     {
171         public Gtk.Table el;
172         private NewBranch  _this;
173
174
175             // my vars (def)
176
177         // ctor
178         public Xcls_Table3(NewBranch _owner )
179         {
180             _this = _owner;
181             this.el = new Gtk.Table( 5, 5, true );
182
183             // my vars (dec)
184
185             // set gobject values
186             this.el.expand = false;
187             this.el.margin = 2;
188             this.el.column_spacing = 4;
189             this.el.vexpand = false;
190             var child_0 = new Xcls_Label4( _this );
191             child_0.ref();
192             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
193             var child_1 = new Xcls_Label5( _this );
194             child_1.ref();
195             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
196             var child_2 = new Xcls_projectsel( _this );
197             child_2.ref();
198             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
199             var child_3 = new Xcls_ticketsel( _this );
200             child_3.ref();
201             this.el.attach_defaults (  child_3.el , 1,4,1,2 );
202             var child_4 = new Xcls_Button12( _this );
203             child_4.ref();
204             this.el.attach_defaults (  child_4.el , 4,5,1,2 );
205             var child_5 = new Xcls_Label13( _this );
206             child_5.ref();
207             this.el.attach_defaults (  child_5.el , 0,1,3,4 );
208             var child_6 = new Xcls_name( _this );
209             child_6.ref();
210             this.el.attach_defaults (  child_6.el , 0,4,4,5 );
211             var child_7 = new Xcls_Button15( _this );
212             child_7.ref();
213             this.el.attach_defaults (  child_7.el , 4,5,4,5 );
214             var child_8 = new Xcls_Box16( _this );
215             child_8.ref();
216             this.el.attach_defaults (  child_8.el , 0,5,2,3 );
217         }
218
219         // user defined functions
220     }
221     public class Xcls_Label4 : Object
222     {
223         public Gtk.Label el;
224         private NewBranch  _this;
225
226
227             // my vars (def)
228
229         // ctor
230         public Xcls_Label4(NewBranch _owner )
231         {
232             _this = _owner;
233             this.el = new Gtk.Label( "Project" );
234
235             // my vars (dec)
236
237             // set gobject values
238             this.el.halign = Gtk.Align.START;
239             this.el.justify = Gtk.Justification.RIGHT;
240             this.el.visible = true;
241         }
242
243         // user defined functions
244     }
245
246     public class Xcls_Label5 : Object
247     {
248         public Gtk.Label el;
249         private NewBranch  _this;
250
251
252             // my vars (def)
253
254         // ctor
255         public Xcls_Label5(NewBranch _owner )
256         {
257             _this = _owner;
258             this.el = new Gtk.Label( "Ticket" );
259
260             // my vars (dec)
261
262             // set gobject values
263             this.el.halign = Gtk.Align.START;
264             this.el.visible = true;
265         }
266
267         // user defined functions
268     }
269
270     public class Xcls_projectsel : Object
271     {
272         public Gtk.ComboBox el;
273         private NewBranch  _this;
274
275
276             // my vars (def)
277         public bool loading;
278
279         // ctor
280         public Xcls_projectsel(NewBranch _owner )
281         {
282             _this = _owner;
283             _this.projectsel = this;
284             this.el = new Gtk.ComboBox.with_entry();
285
286             // my vars (dec)
287             this.loading = false;
288
289             // set gobject values
290             var child_0 = new Xcls_prcellrenderer( _this );
291             child_0.ref();
292             this.el.pack_start (  child_0.el , true );
293             var child_1 = new Xcls_prmodel( _this );
294             child_1.ref();
295             this.el.set_model (  child_1.el  );
296
297             // init method
298
299             this.el.set_entry_text_column(1);
300
301             //listeners
302             this.el.changed.connect( () => {
303                 if (this.loading) {
304                         return;
305                 }
306                 var project_id = this.selectedProjectId();
307                 _this.dbmodel.loadTickets(project_id);
308                 
309                 
310                 /*if (this.loading) {
311                         return;
312                 }
313                 var ticket_id = this.selectedTicketId();
314                 
315                 var name = RooTicket.singleton().usernameLocal();
316                 
317                 if (ticket_id == "" || ticket_id == null) {
318                 
319                         var dt = new  DateTime.now_local();
320                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
321                         return;
322                 }
323                 
324                 
325                 var ticket = RooTicket.singleton().getById(ticket_id);
326                
327                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
328                 
329                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
330                 */
331             });
332         }
333
334         // user defined functions
335         public string selectedProjectId () {
336                 Gtk.TreeIter iter;
337                 Value val1;
338          
339          
340                 this.el.get_active_iter (out iter);
341                 _this.prmodel.el.get_value (iter, 0, out val1);
342          
343         
344                 return  (string) val1;
345                 
346                 
347                 
348                 
349         }
350     }
351     public class Xcls_prcellrenderer : Object
352     {
353         public Gtk.CellRendererText el;
354         private NewBranch  _this;
355
356
357             // my vars (def)
358
359         // ctor
360         public Xcls_prcellrenderer(NewBranch _owner )
361         {
362             _this = _owner;
363             _this.prcellrenderer = this;
364             this.el = new Gtk.CellRendererText();
365
366             // my vars (dec)
367
368             // set gobject values
369         }
370
371         // user defined functions
372     }
373
374     public class Xcls_prmodel : Object
375     {
376         public Gtk.ListStore el;
377         private NewBranch  _this;
378
379
380             // my vars (def)
381
382         // ctor
383         public Xcls_prmodel(NewBranch _owner )
384         {
385             _this = _owner;
386             _this.prmodel = this;
387             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
388
389             // my vars (dec)
390
391             // set gobject values
392         }
393
394         // user defined functions
395         public void loadProjects (string id) {
396         
397         
398             
399             _this.projectsel.loading = true;
400         
401             this.el.clear();                                    
402             Gtk.TreeIter iter;
403             var el = this.el;
404             
405             el.append(out iter);
406         
407             
408             el.set_value(iter, 0, "");
409             el.set_value(iter, 1, "-- select a project --");
410             if (id == "") {
411                     _this.projectsel.el.set_active_iter(iter);
412             }
413           
414             foreach(var project in RooProject.projects()) {
415             
416                 el.append(out iter);
417                 
418                 el.set_value(iter, 0, project.id);
419                 el.set_value(iter, 1,  project.name );
420                 if (id == project.id) {
421                            _this.projectsel.el.set_active_iter(iter);
422                     }   
423                 
424             }
425             
426             _this.projectsel.loading = false;
427              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
428                                              
429         }
430     }
431
432
433     public class Xcls_ticketsel : Object
434     {
435         public Gtk.ComboBox el;
436         private NewBranch  _this;
437
438
439             // my vars (def)
440         public bool loading;
441
442         // ctor
443         public Xcls_ticketsel(NewBranch _owner )
444         {
445             _this = _owner;
446             _this.ticketsel = this;
447             this.el = new Gtk.ComboBox.with_entry();
448
449             // my vars (dec)
450             this.loading = false;
451
452             // set gobject values
453             var child_0 = new Xcls_dbcellrenderer( _this );
454             child_0.ref();
455             this.el.pack_start (  child_0.el , true );
456             var child_1 = new Xcls_dbmodel( _this );
457             child_1.ref();
458             this.el.set_model (  child_1.el  );
459
460             // init method
461
462             //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
463             this.el.set_entry_text_column(1);
464             this.el.get_child().set_sensitive(false);
465
466             //listeners
467             this.el.changed.connect( () => {
468                 if (this.loading) {
469                         return;
470                 }
471                 var ticket_id = this.selectedTicketId();
472                 
473                 var name = RooTicket.singleton().usernameLocal();
474                 
475                 if (ticket_id == "" || ticket_id == null) {
476                 
477                         var dt = new  DateTime.now_local();
478                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
479                         _this.view.loadTicket("");              
480                         return;
481                 }
482                 
483                 
484                 var ticket = RooTicket.singleton().getById(ticket_id);
485                
486                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
487                 _this.scrolled_window.el.show();
488                  
489                 _this.view.loadTicket(ticket.id);
490                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
491             });
492         }
493
494         // user defined functions
495         public string selectedTicketId () {
496         Gtk.TreeIter iter;
497                 Value val1;
498          
499          
500                 this.el.get_active_iter (out iter);
501                 _this.dbmodel.el.get_value (iter, 0, out val1);
502          
503         
504                 return  (string) val1;
505                 
506                 
507                 
508                 
509         }
510     }
511     public class Xcls_dbcellrenderer : Object
512     {
513         public Gtk.CellRendererText el;
514         private NewBranch  _this;
515
516
517             // my vars (def)
518
519         // ctor
520         public Xcls_dbcellrenderer(NewBranch _owner )
521         {
522             _this = _owner;
523             _this.dbcellrenderer = this;
524             this.el = new Gtk.CellRendererText();
525
526             // my vars (dec)
527
528             // set gobject values
529         }
530
531         // user defined functions
532     }
533
534     public class Xcls_dbmodel : Object
535     {
536         public Gtk.ListStore el;
537         private NewBranch  _this;
538
539
540             // my vars (def)
541
542         // ctor
543         public Xcls_dbmodel(NewBranch _owner )
544         {
545             _this = _owner;
546             _this.dbmodel = this;
547             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
548
549             // my vars (dec)
550
551             // set gobject values
552         }
553
554         // user defined functions
555         public void loadTickets (string project_id , string tid = "") {
556         
557         
558             
559             // fixme .. get project id from selection..
560             
561              RooTicket.singleton().loadTickets(
562                                 project_id,
563                                 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY :  RooTicket.Who.ME,
564                                  _this.btn_closed.el.active ? RooTicket.Status.ALL :  RooTicket.Status.ACTIVE
565                          );
566                 
567             _this.ticketsel.loading = true;
568         
569             this.el.clear();                                    
570             Gtk.TreeIter iter;
571             var el = this.el;
572             
573             el.append(out iter);
574         
575             
576             el.set_value(iter, 0, "");
577             el.set_value(iter, 1, "-- select a ticket --");
578             
579             _this.ticketsel.el.set_active_iter(iter);
580             var tickets = RooTicket.singleton().tickets;
581             foreach(var ticket in tickets) {
582             
583                 el.append(out iter);
584                 
585                 el.set_value(iter, 0, ticket.id);
586                 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
587                 
588                 if (ticket.id == tid) {
589                             _this.ticketsel.el.set_active_iter(iter);
590                 }
591                 
592             }
593             
594             _this.ticketsel.loading = false;
595              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
596                                              
597         }
598     }
599
600
601     public class Xcls_Button12 : Object
602     {
603         public Gtk.Button el;
604         private NewBranch  _this;
605
606
607             // my vars (def)
608
609         // ctor
610         public Xcls_Button12(NewBranch _owner )
611         {
612             _this = _owner;
613             this.el = new Gtk.Button();
614
615             // my vars (dec)
616
617             // set gobject values
618             this.el.expand = false;
619             this.el.label = "New Ticket";
620
621             //listeners
622             this.el.clicked.connect( () => {
623                 _this.el.response(-1);
624                 Ticket.singleton().show(_this.repo);
625             
626             });
627         }
628
629         // user defined functions
630     }
631
632     public class Xcls_Label13 : Object
633     {
634         public Gtk.Label el;
635         private NewBranch  _this;
636
637
638             // my vars (def)
639
640         // ctor
641         public Xcls_Label13(NewBranch _owner )
642         {
643             _this = _owner;
644             this.el = new Gtk.Label( "Use this as branch name" );
645
646             // my vars (dec)
647
648             // set gobject values
649             this.el.halign = Gtk.Align.START;
650             this.el.justify = Gtk.Justification.RIGHT;
651             this.el.xalign = 0.900000f;
652         }
653
654         // user defined functions
655     }
656
657     public class Xcls_name : Object
658     {
659         public Gtk.Entry el;
660         private NewBranch  _this;
661
662
663             // my vars (def)
664
665         // ctor
666         public Xcls_name(NewBranch _owner )
667         {
668             _this = _owner;
669             _this.name = this;
670             this.el = new Gtk.Entry();
671
672             // my vars (dec)
673
674             // set gobject values
675             this.el.visible = true;
676         }
677
678         // user defined functions
679     }
680
681     public class Xcls_Button15 : Object
682     {
683         public Gtk.Button el;
684         private NewBranch  _this;
685
686
687             // my vars (def)
688
689         // ctor
690         public Xcls_Button15(NewBranch _owner )
691         {
692             _this = _owner;
693             this.el = new Gtk.Button();
694
695             // my vars (dec)
696
697             // set gobject values
698             this.el.label = "Create Branch";
699
700             // init method
701
702             {
703                this.el.get_style_context().add_class("suggested-action");
704             }
705
706             //listeners
707             this.el.clicked.connect( () => {
708                 GLib.debug("fire response = 1");
709                 _this.el.response(1);
710             });
711         }
712
713         // user defined functions
714     }
715
716     public class Xcls_Box16 : Object
717     {
718         public Gtk.Box el;
719         private NewBranch  _this;
720
721
722             // my vars (def)
723
724         // ctor
725         public Xcls_Box16(NewBranch _owner )
726         {
727             _this = _owner;
728             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
729
730             // my vars (dec)
731
732             // set gobject values
733             var child_0 = new Xcls_btn_not_me( _this );
734             child_0.ref();
735             this.el.add (  child_0.el  );
736             var child_1 = new Xcls_btn_closed( _this );
737             child_1.ref();
738             this.el.add (  child_1.el  );
739             var child_2 = new Xcls_Label19( _this );
740             child_2.ref();
741             this.el.add (  child_2.el  );
742         }
743
744         // user defined functions
745     }
746     public class Xcls_btn_not_me : Object
747     {
748         public Gtk.CheckButton el;
749         private NewBranch  _this;
750
751
752             // my vars (def)
753
754         // ctor
755         public Xcls_btn_not_me(NewBranch _owner )
756         {
757             _this = _owner;
758             _this.btn_not_me = this;
759             this.el = new Gtk.CheckButton();
760
761             // my vars (dec)
762
763             // set gobject values
764             this.el.label = "Show tickets not assigned to me";
765
766             //listeners
767             this.el.toggled.connect( () => {
768                 var project_id = _this.projectsel.selectedProjectId();
769                 _this.dbmodel.loadTickets(project_id);  
770             });
771         }
772
773         // user defined functions
774     }
775
776     public class Xcls_btn_closed : Object
777     {
778         public Gtk.CheckButton el;
779         private NewBranch  _this;
780
781
782             // my vars (def)
783
784         // ctor
785         public Xcls_btn_closed(NewBranch _owner )
786         {
787             _this = _owner;
788             _this.btn_closed = this;
789             this.el = new Gtk.CheckButton();
790
791             // my vars (dec)
792
793             // set gobject values
794             this.el.label = "Show closed Tickets";
795
796             //listeners
797             this.el.toggled.connect( () => {
798                 var project_id = _this.projectsel.selectedProjectId();
799                 _this.dbmodel.loadTickets(project_id);  
800                  
801             });
802         }
803
804         // user defined functions
805     }
806
807     public class Xcls_Label19 : Object
808     {
809         public Gtk.Label el;
810         private NewBranch  _this;
811
812
813             // my vars (def)
814
815         // ctor
816         public Xcls_Label19(NewBranch _owner )
817         {
818             _this = _owner;
819             this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
820
821             // my vars (dec)
822
823             // set gobject values
824             this.el.halign = Gtk.Align.END;
825             this.el.hexpand = true;
826             this.el.use_markup = true;
827
828             //listeners
829             this.el.activate_link.connect( (uri) => {
830                 if (uri == "refresh") {
831                         RooProject.reload();
832                         var curproj = RooProject.getProjectByRepo(_this.repo);
833                          _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
834             
835                         _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);            
836                 }
837                 return true;
838             });
839         }
840
841         // user defined functions
842     }
843
844
845
846     public class Xcls_scrolled_window : Object
847     {
848         public Gtk.ScrolledWindow el;
849         private NewBranch  _this;
850
851
852             // my vars (def)
853
854         // ctor
855         public Xcls_scrolled_window(NewBranch _owner )
856         {
857             _this = _owner;
858             _this.scrolled_window = this;
859             this.el = new Gtk.ScrolledWindow( null, null );
860
861             // my vars (dec)
862
863             // set gobject values
864             this.el.height_request = 500;
865             this.el.vexpand = true;
866             var child_0 = new Xcls_view( _this );
867             child_0.ref();
868             this.el.add (  child_0.el  );
869
870             // init method
871
872             {
873                 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
874             }
875         }
876
877         // user defined functions
878     }
879     public class Xcls_view : Object
880     {
881         public WebKit.WebView el;
882         private NewBranch  _this;
883
884
885             // my vars (def)
886
887         // ctor
888         public Xcls_view(NewBranch _owner )
889         {
890             _this = _owner;
891             _this.view = this;
892             this.el = new WebKit.WebView();
893
894             // my vars (dec)
895
896             // set gobject values
897         }
898
899         // user defined functions
900         public void loadTicket (string tid) {
901                 int h,w;
902                 _this.el.get_size(out w, out h);
903                 
904                 if (tid == "") {
905                         _this.scrolled_window.el.hide();
906                         _this.el.resize(w, 150);
907                 } else {
908                         _this.scrolled_window.el.show();
909                         _this.el.resize(w, 800);
910                 }
911                 
912                 var rs =  RooTicket.singleton();                
913                 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
914                 var hd = uri.get_http_headers();
915                 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
916                 hd.append("Authorization", "Basic %s".printf(authCode));
917                 
918                  this.el.load_request(uri);
919         }
920     }
921
922
923
924 }