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