Fix #5615 - gitlive - force all roojs projects to autobranch
[gitlive] / MergeBranch.vala
1 static MergeBranch  _MergeBranch;
2
3 public class MergeBranch : Object
4 {
5     public Gtk.Dialog el;
6     private MergeBranch  _this;
7
8     public static MergeBranch singleton()
9     {
10         if (_MergeBranch == null) {
11             _MergeBranch= new MergeBranch();
12         }
13         return _MergeBranch;
14     }
15     public Xcls_actionsel actionsel;
16     public Xcls_actioncellrenderer actioncellrenderer;
17     public Xcls_actionmodel actionmodel;
18     public Xcls_ticketsel ticketsel;
19     public Xcls_dbcellrenderer dbcellrenderer;
20     public Xcls_dbmodel dbmodel;
21     public Xcls_name name;
22     public Xcls_scrolled_window scrolled_window;
23     public Xcls_view view;
24
25         // my vars (def)
26     public GitRepo repo;
27     public RooTicket? ticket;
28     public bool running;
29
30     // ctor
31     public MergeBranch()
32     {
33         _this = this;
34         this.el = new Gtk.Dialog();
35
36         // my vars (dec)
37         this.ticket = null;
38         this.running = false;
39
40         // set gobject values
41         this.el.title = "Merge Branch";
42         this.el.default_height = 200;
43         this.el.default_width = 500;
44         this.el.deletable = true;
45         this.el.modal = true;
46         var child_0 = new Xcls_Box2( _this );
47         child_0.ref();
48         this.el.get_content_area().add (  child_0.el  );
49         var child_1 = new Xcls_Button16( _this );
50         child_1.ref();
51         this.el.add_action_widget (  child_1.el , 0 );
52         var child_2 = new Xcls_Button17( _this );
53         child_2.ref();
54         this.el.add_action_widget (  child_2.el , 1 );
55
56         //listeners
57         this.el.delete_event.connect( (self, event) => {
58             this.el.hide();
59             return true; 
60             //test  
61         });
62         this.el.response.connect( (self, response_id) =>  { 
63           
64                 GLib.debug("got %d", (int) response_id);
65                 if (response_id == 0) {
66                     _this.el.hide();    
67                     this.running = false; 
68                 GitMonitor.gitmonitor.start();
69                         return;
70                 }
71                  /*
72                 // have they selected a ticket..
73                 // make that the current active ticket?
74                 // we really need to store locally what ticket is being worked on..
75                 // in theory we could be working on multiple project and not merging..
76                 // -- each repo would have their active ticket (only one per repo)
77                 // -- so we could just store that in there
78                 // -- initial load can check the contents of the ticket files on first scan.
79                 var ticket_id = _this.ticketsel.selectedTicketId();
80                 
81             if (this.repo != null) {
82                 var bn = _this.name.el.get_text();
83                 if (ticket_id != "" ) {
84                                 this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);
85                         } else {
86                                 this.repo.createBranchNamed(bn);
87                         }
88             }
89                 */
90                 
91                 if (this.repo != null) {
92                         repo.doMerge(
93                                 _this.actionsel.selectedAction(), 
94                                 _this.ticketsel.selectedTicketId(),
95                                 _this.name.el.get_text()
96                         );
97                 
98                 } else {
99                         GitRepo.doMerges(
100                                 _this.actionsel.selectedAction(), 
101                                 _this.ticketsel.selectedTicketId(),
102                                 _this.name.el.get_text()
103                         );
104                 }
105                 this.running = false; 
106         
107                  
108                 _this.el.hide();        
109                 GitMonitor.gitmonitor.start();
110         
111                  
112         });
113         this.el.show.connect( (self)  => {
114          
115         
116           //test
117         });
118     }
119
120     // user defined functions
121     public   void show (  RooTicket ticket, GitRepo? repo ) 
122     {
123          // this.el.set_gravity(Gdk.Gravity.NORTH);
124         if (this.running) {
125                 return;
126         }
127         GitMonitor.gitmonitor.stop();
128         
129         this.ticket = ticket;
130         this.repo = repo;
131         
132         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
133                 GLib.debug("Loading tickets"); 
134     
135     
136         this.el.show_all();
137         _this.dbmodel.loadTickets();
138         _this.actionmodel.loadActions();
139         _this.view.loadTicket(ticket.id);
140     
141     }
142     public class Xcls_Box2 : Object
143     {
144         public Gtk.Box el;
145         private MergeBranch  _this;
146
147
148             // my vars (def)
149
150         // ctor
151         public Xcls_Box2(MergeBranch _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 MergeBranch  _this;
173
174
175             // my vars (def)
176
177         // ctor
178         public Xcls_Table3(MergeBranch _owner )
179         {
180             _this = _owner;
181             this.el = new Gtk.Table( 2, 2, false );
182
183             // my vars (dec)
184
185             // set gobject values
186             this.el.margin = 2;
187             this.el.column_spacing = 2;
188             this.el.vexpand = false;
189             var child_0 = new Xcls_Label4( _this );
190             child_0.ref();
191             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
192             var child_1 = new Xcls_actionsel( _this );
193             child_1.ref();
194             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
195             var child_2 = new Xcls_Label8( _this );
196             child_2.ref();
197             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
198             var child_3 = new Xcls_ticketsel( _this );
199             child_3.ref();
200             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
201             var child_4 = new Xcls_Label12( _this );
202             child_4.ref();
203             this.el.attach_defaults (  child_4.el , 0,1,2,3 );
204             var child_5 = new Xcls_name( _this );
205             child_5.ref();
206             this.el.attach_defaults (  child_5.el , 1,2,2,3 );
207         }
208
209         // user defined functions
210     }
211     public class Xcls_Label4 : Object
212     {
213         public Gtk.Label el;
214         private MergeBranch  _this;
215
216
217             // my vars (def)
218
219         // ctor
220         public Xcls_Label4(MergeBranch _owner )
221         {
222             _this = _owner;
223             this.el = new Gtk.Label( "Do what?" );
224
225             // my vars (dec)
226
227             // set gobject values
228             this.el.justify = Gtk.Justification.RIGHT;
229             this.el.xalign = 0.900000f;
230             this.el.visible = true;
231         }
232
233         // user defined functions
234     }
235
236     public class Xcls_actionsel : Object
237     {
238         public Gtk.ComboBox el;
239         private MergeBranch  _this;
240
241
242             // my vars (def)
243         public bool loading;
244
245         // ctor
246         public Xcls_actionsel(MergeBranch _owner )
247         {
248             _this = _owner;
249             _this.actionsel = this;
250             this.el = new Gtk.ComboBox();
251
252             // my vars (dec)
253             this.loading = false;
254
255             // set gobject values
256             var child_0 = new Xcls_actioncellrenderer( _this );
257             child_0.ref();
258             this.el.pack_start (  child_0.el , true );
259             var child_1 = new Xcls_actionmodel( _this );
260             child_1.ref();
261             this.el.set_model (  child_1.el  );
262
263             // init method
264
265             this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
266
267             //listeners
268             this.el.changed.connect( () => {
269                 if (this.loading) {
270                         return;
271                 }
272                 _this.name.updateText();
273                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
274             });
275         }
276
277         // user defined functions
278         public string selectedAction () {
279                 Gtk.TreeIter iter;
280                 Value val1;
281          
282                 this.el.get_active_iter (out iter);
283                 _this.actionmodel.el.get_value (iter, 0, out val1);
284         
285                 return  (string) val1;
286         }
287     }
288     public class Xcls_actioncellrenderer : Object
289     {
290         public Gtk.CellRendererText el;
291         private MergeBranch  _this;
292
293
294             // my vars (def)
295
296         // ctor
297         public Xcls_actioncellrenderer(MergeBranch _owner )
298         {
299             _this = _owner;
300             _this.actioncellrenderer = this;
301             this.el = new Gtk.CellRendererText();
302
303             // my vars (dec)
304
305             // set gobject values
306         }
307
308         // user defined functions
309     }
310
311     public class Xcls_actionmodel : Object
312     {
313         public Gtk.ListStore el;
314         private MergeBranch  _this;
315
316
317             // my vars (def)
318
319         // ctor
320         public Xcls_actionmodel(MergeBranch _owner )
321         {
322             _this = _owner;
323             _this.actionmodel = this;
324             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
325
326             // my vars (dec)
327
328             // set gobject values
329         }
330
331         // user defined functions
332         public void loadActions () {
333         
334          
335             
336             _this.actionsel.loading = true;
337         
338             this.el.clear();                                    
339             Gtk.TreeIter iter;
340             var el = this.el;
341             
342             el.append(out iter);
343         
344             
345             el.set_value(iter, 0, "");
346             el.set_value(iter, 1, "-- select action  --");
347             
348             _this.actionsel.el.set_active_iter(iter);
349         
350             el.append(out iter);    
351             el.set_value(iter, 0, "CLOSE");
352             el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
353                 
354                 
355             el.append(out iter);    
356             el.set_value(iter, 0, "LEAVE");
357             el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
358         
359             el.append(out iter);    
360             el.set_value(iter, 0, "MASTER");
361             el.set_value(iter, 1, "Merge changes FROM master into this branch");    
362             
363             el.append(out iter);    
364             el.set_value(iter, 0, "EXIT");
365             el.set_value(iter, 1, "Switch back to MASTER branch - no merge");    
366             
367             
368             
369             _this.actionsel.loading = false;
370              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
371                                              
372         }
373     }
374
375
376     public class Xcls_Label8 : Object
377     {
378         public Gtk.Label el;
379         private MergeBranch  _this;
380
381
382             // my vars (def)
383
384         // ctor
385         public Xcls_Label8(MergeBranch _owner )
386         {
387             _this = _owner;
388             this.el = new Gtk.Label( "Select Ticket" );
389
390             // my vars (dec)
391
392             // set gobject values
393             this.el.justify = Gtk.Justification.RIGHT;
394             this.el.xalign = 0.900000f;
395             this.el.visible = true;
396         }
397
398         // user defined functions
399     }
400
401     public class Xcls_ticketsel : Object
402     {
403         public Gtk.ComboBox el;
404         private MergeBranch  _this;
405
406
407             // my vars (def)
408         public bool loading;
409
410         // ctor
411         public Xcls_ticketsel(MergeBranch _owner )
412         {
413             _this = _owner;
414             _this.ticketsel = this;
415             this.el = new Gtk.ComboBox();
416
417             // my vars (dec)
418             this.loading = true;
419
420             // set gobject values
421             var child_0 = new Xcls_dbcellrenderer( _this );
422             child_0.ref();
423             this.el.pack_start (  child_0.el , true );
424             var child_1 = new Xcls_dbmodel( _this );
425             child_1.ref();
426             this.el.set_model (  child_1.el  );
427
428             // init method
429
430             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
431
432             //listeners
433             this.el.changed.connect( () => {
434                 if (this.loading) {
435                         return;
436                 }
437                 _this.view.loadTicket(this.selectedTicketId());
438                  
439                 _this.name.updateText();
440                 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
441                 
442                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
443             });
444         }
445
446         // user defined functions
447         public string selectedTicketId () {
448         Gtk.TreeIter iter;
449                 Value val1;
450          
451          
452                 this.el.get_active_iter (out iter);
453                 _this.dbmodel.el.get_value (iter, 0, out val1);
454          
455         
456                 return  (string) val1;
457                 
458                 
459                 
460                 
461         }
462     }
463     public class Xcls_dbcellrenderer : Object
464     {
465         public Gtk.CellRendererText el;
466         private MergeBranch  _this;
467
468
469             // my vars (def)
470
471         // ctor
472         public Xcls_dbcellrenderer(MergeBranch _owner )
473         {
474             _this = _owner;
475             _this.dbcellrenderer = this;
476             this.el = new Gtk.CellRendererText();
477
478             // my vars (dec)
479
480             // set gobject values
481         }
482
483         // user defined functions
484     }
485
486     public class Xcls_dbmodel : Object
487     {
488         public Gtk.ListStore el;
489         private MergeBranch  _this;
490
491
492             // my vars (def)
493
494         // ctor
495         public Xcls_dbmodel(MergeBranch _owner )
496         {
497             _this = _owner;
498             _this.dbmodel = this;
499             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
500
501             // my vars (dec)
502
503             // set gobject values
504         }
505
506         // user defined functions
507         public void loadTickets () {
508         
509             RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
510             
511             _this.ticketsel.loading = true;
512         
513             this.el.clear();                                    
514             Gtk.TreeIter iter;
515             var el = this.el;
516             
517             el.append(out iter);
518             el.set_value(iter, 0, "");
519             el.set_value(iter, 1, "-- select a ticket --");
520             
521             _this.ticketsel.el.set_active_iter(iter);
522             
523             if (_this.ticket != null &&  _this.ticket.id == "-1") {
524                         el.append(out iter);
525                         el.set_value(iter, 0, "-1");
526                         el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
527                 _this.ticketsel.el.set_active_iter(iter);       
528             }
529             
530             
531             
532             
533             var tickets = RooTicket.singleton().tickets;
534             foreach(var ticket in tickets) {
535             
536                 el.append(out iter);
537         
538                 el.set_value(iter, 0, ticket.id);
539                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
540                         if (_this.ticket != null && _this.ticket.id == ticket.id) {
541                             _this.ticketsel.el.set_active_iter(iter);
542                     }
543                 
544             }
545             
546             _this.ticketsel.loading = false;
547              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
548                                              
549         }
550     }
551
552
553     public class Xcls_Label12 : Object
554     {
555         public Gtk.Label el;
556         private MergeBranch  _this;
557
558
559             // my vars (def)
560
561         // ctor
562         public Xcls_Label12(MergeBranch _owner )
563         {
564             _this = _owner;
565             this.el = new Gtk.Label( "Use this commit message" );
566
567             // my vars (dec)
568
569             // set gobject values
570             this.el.justify = Gtk.Justification.RIGHT;
571             this.el.xalign = 0.900000f;
572         }
573
574         // user defined functions
575     }
576
577     public class Xcls_name : Object
578     {
579         public Gtk.Entry el;
580         private MergeBranch  _this;
581
582
583             // my vars (def)
584
585         // ctor
586         public Xcls_name(MergeBranch _owner )
587         {
588             _this = _owner;
589             _this.name = this;
590             this.el = new Gtk.Entry();
591
592             // my vars (dec)
593
594             // set gobject values
595             this.el.visible = true;
596         }
597
598         // user defined functions
599         public void updateText () {
600                 var ticket_id = _this.ticketsel.selectedTicketId();
601                 
602                 RooTicket ticket = null;
603                 if (ticket_id.length > 0){
604                         ticket = RooTicket.singleton().getById(ticket_id);
605                 }
606                 
607                 var name = RooTicket.singleton().usernameLocal();
608                 var action = _this.actionsel.selectedAction();
609                 this.el.set_editable(true); 
610                 switch (action) {
611                         case "CLOSE": // merge changes and close..
612                                 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
613                                 break;
614                         case "LEAVE": // partial fix    
615                                 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id,   ticket != null ? ticket.summary : ""));
616                                 break;
617                         case "MASTER": // merge master
618                         case "EXIT": // just switch back...             
619                                 this.el.set_editable(false);
620                                 this.el.set_text(""); // not relivant..                         
621                                 break;
622                         default:
623                         
624                                 break; /// don't fix the text value.
625                 }
626            
627         }
628     }
629
630
631     public class Xcls_scrolled_window : Object
632     {
633         public Gtk.ScrolledWindow el;
634         private MergeBranch  _this;
635
636
637             // my vars (def)
638
639         // ctor
640         public Xcls_scrolled_window(MergeBranch _owner )
641         {
642             _this = _owner;
643             _this.scrolled_window = this;
644             this.el = new Gtk.ScrolledWindow( null, null );
645
646             // my vars (dec)
647
648             // set gobject values
649             this.el.height_request = 500;
650             this.el.vexpand = true;
651             var child_0 = new Xcls_view( _this );
652             child_0.ref();
653             this.el.add (  child_0.el  );
654
655             // init method
656
657             {
658                 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
659             }
660         }
661
662         // user defined functions
663     }
664     public class Xcls_view : Object
665     {
666         public WebKit.WebView el;
667         private MergeBranch  _this;
668
669
670             // my vars (def)
671
672         // ctor
673         public Xcls_view(MergeBranch _owner )
674         {
675             _this = _owner;
676             _this.view = this;
677             this.el = new WebKit.WebView();
678
679             // my vars (dec)
680         }
681
682         // user defined functions
683         public void loadTicket (string tid) {
684                 int h,w;
685                 _this.el.get_size(out w, out h);
686                 
687                 if (tid == "") {
688                         _this.scrolled_window.el.hide();
689                         _this.el.resize(w, 150);
690                 } else {
691                         _this.scrolled_window.el.show();
692                         _this.el.resize(w, 800);
693                 }
694                 
695                 var rs =  RooTicket.singleton();                
696                 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
697                 var hd = uri.get_http_headers();
698                 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
699                 hd.append("Authorization", "Basic %s".printf(authCode));
700                 
701                  this.el.load_request(uri);
702         }
703     }
704
705
706
707     public class Xcls_Button16 : Object
708     {
709         public Gtk.Button el;
710         private MergeBranch  _this;
711
712
713             // my vars (def)
714
715         // ctor
716         public Xcls_Button16(MergeBranch _owner )
717         {
718             _this = _owner;
719             this.el = new Gtk.Button();
720
721             // my vars (dec)
722
723             // set gobject values
724             this.el.relief = Gtk.ReliefStyle.NONE;
725             this.el.label = "Cancel";
726         }
727
728         // user defined functions
729     }
730
731     public class Xcls_Button17 : Object
732     {
733         public Gtk.Button el;
734         private MergeBranch  _this;
735
736
737             // my vars (def)
738
739         // ctor
740         public Xcls_Button17(MergeBranch _owner )
741         {
742             _this = _owner;
743             this.el = new Gtk.Button();
744
745             // my vars (dec)
746
747             // set gobject values
748             this.el.label = "Do Merge";
749         }
750
751         // user defined functions
752     }
753
754 }