1 static NewBranch _NewBranch;
3 public class NewBranch : Object
6 private NewBranch _this;
8 public static NewBranch singleton()
10 if (_NewBranch == null) {
11 _NewBranch= new NewBranch();
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_createbtn createbtn;
23 public Xcls_btn_not_me btn_not_me;
24 public Xcls_btn_closed btn_closed;
25 public Xcls_scrolled_window scrolled_window;
26 public Xcls_view view;
27 public Xcls_label_select_ticket label_select_ticket;
28 public Xcls_label_select_ticket label_select_ticket;
29 public Xcls_label_select_ticket label_select_ticket;
34 public Gee.ArrayList<GitMonitorQueue> queue;
40 this.el = new Gtk.Dialog();
48 this.el.title = "Create a working branch ";
49 this.el.default_height = 500;
50 this.el.default_width = 500;
51 this.el.deletable = true;
53 var child_0 = new Xcls_Box2( _this );
55 this.el.get_content_area().add ( child_0.el );
56 var child_1 = new Xcls_Notebook22( _this );
58 this.el.add ( child_1.el );
61 this.el.delete_event.connect( (self, event) => {
66 this.el.response.connect( (self, response_id) => {
68 GLib.debug("got %d", (int) response_id);
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.
82 if (response_id < 1) {
88 var ticket_id = _this.ticketsel.selectedTicketId();
90 if (this.repo != null) {
91 var bn = _this.name.el.get_text();
93 var res = this.repo.setActiveTicket(
94 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
97 // start the monitoring..
98 GitMonitor.gitmonitor.start();
104 this.running = false;
114 // user defined functions
115 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
117 // this.el.set_gravity(Gdk.Gravity.NORTH);
118 if (this.running) { // should not happen!!
119 GLib.error("new branch show called, when already being displayed?");
124 GitMonitor.gitmonitor.stop();
130 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
131 this.el.set_default_size( 500,200); // not sure why it grows..
132 GLib.debug("Loading tickets");
136 this.el.set_keep_above(true);
139 var curproj = RooProject.getProjectByRepo(this.repo);
140 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
142 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
143 _this.createbtn.updateState();
145 _this.ticketsel.el.get_child().get_style_context().remove_class("warning");
147 var name = RooTicket.singleton().usernameLocal();
148 var ticket = RooTicket.singleton().getById(tid);
149 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
151 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
153 _this.view.loadTicket(tid);
157 public class Xcls_Box2 : Object
160 private NewBranch _this;
166 public Xcls_Box2(NewBranch _owner )
169 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
173 // set gobject values
174 var child_0 = new Xcls_Table3( _this );
176 this.el.pack_start ( child_0.el , false,false,0 );
177 var child_1 = new Xcls_scrolled_window( _this );
179 this.el.add ( child_1.el );
182 // user defined functions
184 public class Xcls_Table3 : Object
187 private NewBranch _this;
193 public Xcls_Table3(NewBranch _owner )
196 this.el = new Gtk.Table( 5, 5, true );
200 // set gobject values
201 this.el.expand = false;
203 this.el.column_spacing = 4;
204 this.el.vexpand = false;
205 var child_0 = new Xcls_Label4( _this );
207 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
208 var child_1 = new Xcls_Label5( _this );
210 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
211 var child_2 = new Xcls_projectsel( _this );
213 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
214 var child_3 = new Xcls_ticketsel( _this );
216 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
217 var child_4 = new Xcls_Button12( _this );
219 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
220 var child_5 = new Xcls_Label13( _this );
222 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
223 var child_6 = new Xcls_name( _this );
225 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
226 var child_7 = new Xcls_createbtn( _this );
228 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
229 var child_8 = new Xcls_Box16( _this );
231 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
234 // user defined functions
236 public class Xcls_Label4 : Object
239 private NewBranch _this;
245 public Xcls_Label4(NewBranch _owner )
248 this.el = new Gtk.Label( "Project" );
252 // set gobject values
253 this.el.halign = Gtk.Align.START;
254 this.el.justify = Gtk.Justification.RIGHT;
255 this.el.visible = true;
258 // user defined functions
261 public class Xcls_Label5 : Object
264 private NewBranch _this;
270 public Xcls_Label5(NewBranch _owner )
273 this.el = new Gtk.Label( "Ticket" );
277 // set gobject values
278 this.el.halign = Gtk.Align.START;
279 this.el.visible = true;
282 // user defined functions
285 public class Xcls_projectsel : Object
287 public Gtk.ComboBox el;
288 private NewBranch _this;
295 public Xcls_projectsel(NewBranch _owner )
298 _this.projectsel = this;
299 this.el = new Gtk.ComboBox.with_entry();
302 this.loading = false;
304 // set gobject values
305 var child_0 = new Xcls_prcellrenderer( _this );
307 this.el.pack_start ( child_0.el , true );
308 var child_1 = new Xcls_prmodel( _this );
310 this.el.set_model ( child_1.el );
314 this.el.set_entry_text_column(1);
317 this.el.changed.connect( () => {
321 var project_id = this.selectedProjectId();
322 _this.dbmodel.loadTickets(project_id);
325 /*if (this.loading) {
328 var ticket_id = this.selectedTicketId();
330 var name = RooTicket.singleton().usernameLocal();
332 if (ticket_id == "" || ticket_id == null) {
334 var dt = new DateTime.now_local();
335 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
340 var ticket = RooTicket.singleton().getById(ticket_id);
342 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
344 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
349 // user defined functions
350 public string selectedProjectId () {
355 this.el.get_active_iter (out iter);
356 _this.prmodel.el.get_value (iter, 0, out val1);
359 return (string) val1;
366 public class Xcls_prcellrenderer : Object
368 public Gtk.CellRendererText el;
369 private NewBranch _this;
375 public Xcls_prcellrenderer(NewBranch _owner )
378 _this.prcellrenderer = this;
379 this.el = new Gtk.CellRendererText();
383 // set gobject values
386 // user defined functions
389 public class Xcls_prmodel : Object
391 public Gtk.ListStore el;
392 private NewBranch _this;
398 public Xcls_prmodel(NewBranch _owner )
401 _this.prmodel = this;
402 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
406 // set gobject values
409 // user defined functions
410 public void loadProjects (string id) {
414 _this.projectsel.loading = true;
423 el.set_value(iter, 0, "");
424 el.set_value(iter, 1, "-- select a project --");
426 _this.projectsel.el.set_active_iter(iter);
429 foreach(var project in RooProject.projects()) {
433 el.set_value(iter, 0, project.id);
434 el.set_value(iter, 1, project.name );
435 if (id == project.id) {
436 _this.projectsel.el.set_active_iter(iter);
441 _this.projectsel.loading = false;
442 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
448 public class Xcls_ticketsel : Object
450 public Gtk.ComboBox el;
451 private NewBranch _this;
458 public Xcls_ticketsel(NewBranch _owner )
461 _this.ticketsel = this;
462 this.el = new Gtk.ComboBox.with_entry();
465 this.loading = false;
467 // set gobject values
468 var child_0 = new Xcls_dbcellrenderer( _this );
470 this.el.pack_start ( child_0.el , true );
471 var child_1 = new Xcls_dbmodel( _this );
473 this.el.set_model ( child_1.el );
477 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
478 this.el.set_entry_text_column(1);
479 this.el.get_child().set_sensitive(false);
482 this.el.changed.connect( () => {
486 var ticket_id = this.selectedTicketId();
488 var name = RooTicket.singleton().usernameLocal();
490 this.el.get_child().get_style_context().remove_class("warning");
491 if (ticket_id == "" || ticket_id == null) {
493 var dt = new DateTime.now_local();
494 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
495 _this.view.loadTicket("");
497 this.el.get_child().get_style_context().add_class("warning");
498 _this.createbtn.updateState();
503 var ticket = RooTicket.singleton().getById(ticket_id);
505 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
506 _this.scrolled_window.el.show();
508 _this.view.loadTicket(ticket.id);
509 _this.createbtn.updateState();
511 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
515 // user defined functions
516 public string selectedTicketId () {
521 this.el.get_active_iter (out iter);
522 _this.dbmodel.el.get_value (iter, 0, out val1);
525 return (string) val1;
532 public class Xcls_dbcellrenderer : Object
534 public Gtk.CellRendererText el;
535 private NewBranch _this;
541 public Xcls_dbcellrenderer(NewBranch _owner )
544 _this.dbcellrenderer = this;
545 this.el = new Gtk.CellRendererText();
549 // set gobject values
552 // user defined functions
555 public class Xcls_dbmodel : Object
557 public Gtk.ListStore el;
558 private NewBranch _this;
564 public Xcls_dbmodel(NewBranch _owner )
567 _this.dbmodel = this;
568 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
572 // set gobject values
575 // user defined functions
576 public void loadTickets (string project_id , string tid = "") {
580 // fixme .. get project id from selection..
582 RooTicket.singleton().loadTickets(
584 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
585 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
588 _this.ticketsel.loading = true;
597 el.set_value(iter, 0, "");
598 el.set_value(iter, 1, "-- select a ticket --");
600 _this.ticketsel.el.set_active_iter(iter);
601 var tickets = RooTicket.singleton().tickets;
602 foreach(var ticket in tickets) {
606 el.set_value(iter, 0, ticket.id);
607 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
609 if (ticket.id == tid) {
610 _this.ticketsel.el.set_active_iter(iter);
615 _this.ticketsel.loading = false;
616 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
622 public class Xcls_Button12 : Object
624 public Gtk.Button el;
625 private NewBranch _this;
631 public Xcls_Button12(NewBranch _owner )
634 this.el = new Gtk.Button();
638 // set gobject values
639 this.el.expand = false;
640 this.el.label = "New Ticket";
643 this.el.clicked.connect( () => {
644 _this.el.response(-1);
645 Ticket.singleton().show(_this.repo);
650 // user defined functions
653 public class Xcls_Label13 : Object
656 private NewBranch _this;
662 public Xcls_Label13(NewBranch _owner )
665 this.el = new Gtk.Label( "Use this as branch name" );
669 // set gobject values
670 this.el.halign = Gtk.Align.START;
671 this.el.justify = Gtk.Justification.RIGHT;
672 this.el.xalign = 0.900000f;
675 // user defined functions
678 public class Xcls_name : Object
681 private NewBranch _this;
687 public Xcls_name(NewBranch _owner )
691 this.el = new Gtk.Entry();
695 // set gobject values
696 this.el.visible = true;
699 // user defined functions
702 public class Xcls_createbtn : Object
704 public Gtk.Button el;
705 private NewBranch _this;
711 public Xcls_createbtn(NewBranch _owner )
714 _this.createbtn = this;
715 this.el = new Gtk.Button();
719 // set gobject values
720 this.el.label = "Create Branch";
725 this.el.get_style_context().add_class("suggested-action");
729 this.el.clicked.connect( () => {
731 GLib.debug("fire response = 1");
733 var ticket_id = _this.ticketsel.selectedTicketId();
735 if (ticket_id == "") {
736 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
740 _this.el.response(1);
744 // user defined functions
745 public void updateState () {
747 var ticket_id = _this.ticketsel.selectedTicketId();
749 if (ticket_id == "") {
750 this.el.set_sensitive(false);
754 this.el.set_sensitive(true);
759 public class Xcls_Box16 : Object
762 private NewBranch _this;
768 public Xcls_Box16(NewBranch _owner )
771 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
775 // set gobject values
776 var child_0 = new Xcls_btn_not_me( _this );
778 this.el.add ( child_0.el );
779 var child_1 = new Xcls_btn_closed( _this );
781 this.el.add ( child_1.el );
782 var child_2 = new Xcls_Label19( _this );
784 this.el.add ( child_2.el );
787 // user defined functions
789 public class Xcls_btn_not_me : Object
791 public Gtk.CheckButton el;
792 private NewBranch _this;
798 public Xcls_btn_not_me(NewBranch _owner )
801 _this.btn_not_me = this;
802 this.el = new Gtk.CheckButton();
806 // set gobject values
807 this.el.label = "Show tickets not assigned to me";
810 this.el.toggled.connect( () => {
811 var project_id = _this.projectsel.selectedProjectId();
812 _this.dbmodel.loadTickets(project_id);
816 // user defined functions
819 public class Xcls_btn_closed : Object
821 public Gtk.CheckButton el;
822 private NewBranch _this;
828 public Xcls_btn_closed(NewBranch _owner )
831 _this.btn_closed = this;
832 this.el = new Gtk.CheckButton();
836 // set gobject values
837 this.el.label = "Show closed Tickets";
840 this.el.toggled.connect( () => {
841 var project_id = _this.projectsel.selectedProjectId();
842 _this.dbmodel.loadTickets(project_id);
847 // user defined functions
850 public class Xcls_Label19 : Object
853 private NewBranch _this;
859 public Xcls_Label19(NewBranch _owner )
862 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
866 // set gobject values
867 this.el.halign = Gtk.Align.END;
868 this.el.hexpand = true;
869 this.el.use_markup = true;
872 this.el.activate_link.connect( (uri) => {
873 if (uri == "refresh") {
875 var curproj = RooProject.getProjectByRepo(_this.repo);
876 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
878 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
884 // user defined functions
889 public class Xcls_scrolled_window : Object
891 public Gtk.ScrolledWindow el;
892 private NewBranch _this;
898 public Xcls_scrolled_window(NewBranch _owner )
901 _this.scrolled_window = this;
902 this.el = new Gtk.ScrolledWindow( null, null );
906 // set gobject values
907 this.el.height_request = 500;
908 this.el.vexpand = true;
909 var child_0 = new Xcls_view( _this );
911 this.el.add ( child_0.el );
916 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
920 // user defined functions
922 public class Xcls_view : Object
924 public WebKit.WebView el;
925 private NewBranch _this;
931 public Xcls_view(NewBranch _owner )
935 this.el = new WebKit.WebView();
939 // set gobject values
942 // user defined functions
943 public void loadTicket (string tid) {
945 _this.el.get_size(out w, out h);
948 _this.scrolled_window.el.hide();
949 _this.el.resize(w, 150);
951 _this.scrolled_window.el.show();
952 _this.el.resize(w, 800);
955 var rs = RooTicket.singleton();
956 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
957 var hd = uri.get_http_headers();
958 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
959 hd.append("Authorization", "Basic %s".printf(authCode));
961 this.el.load_request(uri);
967 public class Xcls_Notebook22 : Object
969 public Gtk.Notebook el;
970 private NewBranch _this;
976 public Xcls_Notebook22(NewBranch _owner )
979 this.el = new Gtk.Notebook();
983 // set gobject values
984 this.el.vexpand = true;
985 var child_0 = new Xcls_label_select_ticket( _this );
987 var child_1 = new Xcls_label_select_ticket( _this );
989 var child_2 = new Xcls_label_select_ticket( _this );
993 // user defined functions
995 public class Xcls_label_select_ticket : Object
998 private NewBranch _this;
1004 public Xcls_label_select_ticket(NewBranch _owner )
1007 _this.label_select_ticket = this;
1008 this.el = new Gtk.Label( "Select Existing Ticket to work on" );
1012 // set gobject values
1015 // user defined functions
1018 public class Xcls_label_select_ticket : Object
1020 public Gtk.Label el;
1021 private NewBranch _this;
1027 public Xcls_label_select_ticket(NewBranch _owner )
1030 _this.label_select_ticket = this;
1031 this.el = new Gtk.Label( "Select Existing Ticket to work on" );
1035 // set gobject values
1038 // user defined functions
1041 public class Xcls_label_select_ticket : Object
1043 public Gtk.Label el;
1044 private NewBranch _this;
1050 public Xcls_label_select_ticket(NewBranch _owner )
1053 _this.label_select_ticket = this;
1054 this.el = new Gtk.Label( "Select Existing Ticket to work on" );
1058 // set gobject values
1061 // user defined functions