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