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