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_btn_not_me btn_not_me;
23 public Xcls_btn_closed btn_closed;
24 public Xcls_scrolled_window scrolled_window;
25 public Xcls_view view;
30 public Gee.ArrayList<GitMonitorQueue> queue;
36 this.el = new Gtk.Dialog();
44 this.el.title = "Create a working branch ";
45 this.el.default_height = 500;
46 this.el.default_width = 500;
47 this.el.deletable = true;
49 var child_0 = new Xcls_Box2( _this );
51 this.el.get_content_area().add ( child_0.el );
54 this.el.delete_event.connect( (self, event) => {
59 this.el.response.connect( (self, response_id) => {
61 GLib.debug("got %d", (int) response_id);
62 if (response_id < 1) {
68 // have they selected a ticket..
69 // make that the current active ticket?
70 // we really need to store locally what ticket is being worked on..
71 // in theory we could be working on multiple project and not merging..
72 // -- each repo would have their active ticket (only one per repo)
73 // -- so we could just store that in there
74 // -- initial load can check the contents of the ticket files on first scan.
75 var ticket_id = _this.ticketsel.selectedTicketId();
77 if (this.repo != null) {
78 var bn = _this.name.el.get_text();
80 var res = this.repo.setActiveTicket(
81 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
84 // start the monitoring..
85 GitMonitor.gitmonitor.start();
101 // user defined functions
102 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
104 // this.el.set_gravity(Gdk.Gravity.NORTH);
105 if (this.running) { // should not happen!!
106 GLib.error("new branch show called, when already being displayed?");
111 GitMonitor.gitmonitor.stop();
117 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
118 this.el.set_default_size( 500,200); // not sure why it grows..
119 GLib.debug("Loading tickets");
123 this.el.set_keep_above(true);
126 var curproj = RooProject.getProjectByRepo(this.repo);
127 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
129 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
132 var name = RooTicket.singleton().usernameLocal();
133 var ticket = RooTicket.singleton().getById(tid);
134 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
138 _this.view.loadTicket(tid);
142 public class Xcls_Box2 : Object
145 private NewBranch _this;
151 public Xcls_Box2(NewBranch _owner )
154 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
158 // set gobject values
159 var child_0 = new Xcls_Table3( _this );
161 this.el.pack_start ( child_0.el , false,false,0 );
162 var child_1 = new Xcls_scrolled_window( _this );
164 this.el.add ( child_1.el );
167 // user defined functions
169 public class Xcls_Table3 : Object
172 private NewBranch _this;
178 public Xcls_Table3(NewBranch _owner )
181 this.el = new Gtk.Table( 5, 5, true );
185 // set gobject values
186 this.el.expand = false;
188 this.el.column_spacing = 4;
189 this.el.vexpand = false;
190 var child_0 = new Xcls_Label4( _this );
192 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
193 var child_1 = new Xcls_Label5( _this );
195 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
196 var child_2 = new Xcls_projectsel( _this );
198 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
199 var child_3 = new Xcls_ticketsel( _this );
201 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
202 var child_4 = new Xcls_Button12( _this );
204 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
205 var child_5 = new Xcls_Label13( _this );
207 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
208 var child_6 = new Xcls_name( _this );
210 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
211 var child_7 = new Xcls_Button15( _this );
213 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
214 var child_8 = new Xcls_Box16( _this );
216 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
219 // user defined functions
221 public class Xcls_Label4 : Object
224 private NewBranch _this;
230 public Xcls_Label4(NewBranch _owner )
233 this.el = new Gtk.Label( "Project" );
237 // set gobject values
238 this.el.halign = Gtk.Align.START;
239 this.el.justify = Gtk.Justification.RIGHT;
240 this.el.visible = true;
243 // user defined functions
246 public class Xcls_Label5 : Object
249 private NewBranch _this;
255 public Xcls_Label5(NewBranch _owner )
258 this.el = new Gtk.Label( "Ticket" );
262 // set gobject values
263 this.el.halign = Gtk.Align.START;
264 this.el.visible = true;
267 // user defined functions
270 public class Xcls_projectsel : Object
272 public Gtk.ComboBox el;
273 private NewBranch _this;
280 public Xcls_projectsel(NewBranch _owner )
283 _this.projectsel = this;
284 this.el = new Gtk.ComboBox.with_entry();
287 this.loading = false;
289 // set gobject values
290 var child_0 = new Xcls_prcellrenderer( _this );
292 this.el.pack_start ( child_0.el , true );
293 var child_1 = new Xcls_prmodel( _this );
295 this.el.set_model ( child_1.el );
299 this.el.set_entry_text_column(1);
302 this.el.changed.connect( () => {
306 var project_id = this.selectedProjectId();
307 _this.dbmodel.loadTickets(project_id);
310 /*if (this.loading) {
313 var ticket_id = this.selectedTicketId();
315 var name = RooTicket.singleton().usernameLocal();
317 if (ticket_id == "" || ticket_id == null) {
319 var dt = new DateTime.now_local();
320 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
325 var ticket = RooTicket.singleton().getById(ticket_id);
327 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
329 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
334 // user defined functions
335 public string selectedProjectId () {
340 this.el.get_active_iter (out iter);
341 _this.prmodel.el.get_value (iter, 0, out val1);
344 return (string) val1;
351 public class Xcls_prcellrenderer : Object
353 public Gtk.CellRendererText el;
354 private NewBranch _this;
360 public Xcls_prcellrenderer(NewBranch _owner )
363 _this.prcellrenderer = this;
364 this.el = new Gtk.CellRendererText();
368 // set gobject values
371 // user defined functions
374 public class Xcls_prmodel : Object
376 public Gtk.ListStore el;
377 private NewBranch _this;
383 public Xcls_prmodel(NewBranch _owner )
386 _this.prmodel = this;
387 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
391 // set gobject values
394 // user defined functions
395 public void loadProjects (string id) {
399 _this.projectsel.loading = true;
408 el.set_value(iter, 0, "");
409 el.set_value(iter, 1, "-- select a project --");
411 _this.projectsel.el.set_active_iter(iter);
414 foreach(var project in RooProject.projects()) {
418 el.set_value(iter, 0, project.id);
419 el.set_value(iter, 1, project.name );
420 if (id == project.id) {
421 _this.projectsel.el.set_active_iter(iter);
426 _this.projectsel.loading = false;
427 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
433 public class Xcls_ticketsel : Object
435 public Gtk.ComboBox el;
436 private NewBranch _this;
443 public Xcls_ticketsel(NewBranch _owner )
446 _this.ticketsel = this;
447 this.el = new Gtk.ComboBox.with_entry();
450 this.loading = false;
452 // set gobject values
453 var child_0 = new Xcls_dbcellrenderer( _this );
455 this.el.pack_start ( child_0.el , true );
456 var child_1 = new Xcls_dbmodel( _this );
458 this.el.set_model ( child_1.el );
462 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
463 this.el.set_entry_text_column(1);
466 this.el.changed.connect( () => {
470 var ticket_id = this.selectedTicketId();
472 var name = RooTicket.singleton().usernameLocal();
474 if (ticket_id == "" || ticket_id == null) {
476 var dt = new DateTime.now_local();
477 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
478 _this.view.loadTicket("");
483 var ticket = RooTicket.singleton().getById(ticket_id);
485 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
486 _this.scrolled_window.el.show();
488 _this.view.loadTicket(ticket.id);
489 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
493 // user defined functions
494 public string selectedTicketId () {
499 this.el.get_active_iter (out iter);
500 _this.dbmodel.el.get_value (iter, 0, out val1);
503 return (string) val1;
510 public class Xcls_dbcellrenderer : Object
512 public Gtk.CellRendererText el;
513 private NewBranch _this;
519 public Xcls_dbcellrenderer(NewBranch _owner )
522 _this.dbcellrenderer = this;
523 this.el = new Gtk.CellRendererText();
527 // set gobject values
530 // user defined functions
533 public class Xcls_dbmodel : Object
535 public Gtk.ListStore el;
536 private NewBranch _this;
542 public Xcls_dbmodel(NewBranch _owner )
545 _this.dbmodel = this;
546 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
550 // set gobject values
553 // user defined functions
554 public void loadTickets (string project_id , string tid = "") {
558 // fixme .. get project id from selection..
560 RooTicket.singleton().loadTickets(
562 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
563 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
566 _this.ticketsel.loading = true;
575 el.set_value(iter, 0, "");
576 el.set_value(iter, 1, "-- select a ticket --");
578 _this.ticketsel.el.set_active_iter(iter);
579 var tickets = RooTicket.singleton().tickets;
580 foreach(var ticket in tickets) {
584 el.set_value(iter, 0, ticket.id);
585 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
587 if (ticket.id == tid) {
588 _this.ticketsel.el.set_active_iter(iter);
593 _this.ticketsel.loading = false;
594 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
600 public class Xcls_Button12 : Object
602 public Gtk.Button el;
603 private NewBranch _this;
609 public Xcls_Button12(NewBranch _owner )
612 this.el = new Gtk.Button();
616 // set gobject values
617 this.el.expand = false;
618 this.el.label = "New Ticket";
621 this.el.clicked.connect( () => {
622 _this.el.response(-1);
623 Ticket.singleton().show(_this.repo);
628 // user defined functions
631 public class Xcls_Label13 : Object
634 private NewBranch _this;
640 public Xcls_Label13(NewBranch _owner )
643 this.el = new Gtk.Label( "Use this as branch name" );
647 // set gobject values
648 this.el.halign = Gtk.Align.START;
649 this.el.justify = Gtk.Justification.RIGHT;
650 this.el.xalign = 0.900000f;
653 // user defined functions
656 public class Xcls_name : Object
659 private NewBranch _this;
665 public Xcls_name(NewBranch _owner )
669 this.el = new Gtk.Entry();
673 // set gobject values
674 this.el.visible = true;
677 // user defined functions
680 public class Xcls_Button15 : Object
682 public Gtk.Button el;
683 private NewBranch _this;
689 public Xcls_Button15(NewBranch _owner )
692 this.el = new Gtk.Button();
696 // set gobject values
697 this.el.label = "Create Branch";
702 this.el.get_style_context().add_class("suggested-action");
706 this.el.clicked.connect( () => {
707 GLib.debug("fire response = 1");
708 _this.el.response(1);
712 // user defined functions
715 public class Xcls_Box16 : Object
718 private NewBranch _this;
724 public Xcls_Box16(NewBranch _owner )
727 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
731 // set gobject values
732 var child_0 = new Xcls_btn_not_me( _this );
734 this.el.add ( child_0.el );
735 var child_1 = new Xcls_btn_closed( _this );
737 this.el.add ( child_1.el );
738 var child_2 = new Xcls_Label19( _this );
740 this.el.add ( child_2.el );
743 // user defined functions
745 public class Xcls_btn_not_me : Object
747 public Gtk.CheckButton el;
748 private NewBranch _this;
754 public Xcls_btn_not_me(NewBranch _owner )
757 _this.btn_not_me = this;
758 this.el = new Gtk.CheckButton();
762 // set gobject values
763 this.el.label = "Show tickets not assigned to me";
766 this.el.toggled.connect( () => {
767 var project_id = _this.projectsel.selectedProjectId();
768 _this.dbmodel.loadTickets(project_id);
772 // user defined functions
775 public class Xcls_btn_closed : Object
777 public Gtk.CheckButton el;
778 private NewBranch _this;
784 public Xcls_btn_closed(NewBranch _owner )
787 _this.btn_closed = this;
788 this.el = new Gtk.CheckButton();
792 // set gobject values
793 this.el.label = "Show closed Tickets";
796 this.el.toggled.connect( () => {
797 var project_id = _this.projectsel.selectedProjectId();
798 _this.dbmodel.loadTickets(project_id);
803 // user defined functions
806 public class Xcls_Label19 : Object
809 private NewBranch _this;
815 public Xcls_Label19(NewBranch _owner )
818 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
822 // set gobject values
823 this.el.halign = Gtk.Align.END;
824 this.el.hexpand = true;
825 this.el.use_markup = true;
828 this.el.activate_link.connect( (uri) => {
829 if (uri == "refresh") {
831 var curproj = RooProject.getProjectByRepo(_this.repo);
832 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
834 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
840 // user defined functions
845 public class Xcls_scrolled_window : Object
847 public Gtk.ScrolledWindow el;
848 private NewBranch _this;
854 public Xcls_scrolled_window(NewBranch _owner )
857 _this.scrolled_window = this;
858 this.el = new Gtk.ScrolledWindow( null, null );
862 // set gobject values
863 this.el.height_request = 500;
864 this.el.vexpand = true;
865 var child_0 = new Xcls_view( _this );
867 this.el.add ( child_0.el );
872 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
876 // user defined functions
878 public class Xcls_view : Object
880 public WebKit.WebView el;
881 private NewBranch _this;
887 public Xcls_view(NewBranch _owner )
891 this.el = new WebKit.WebView();
895 // set gobject values
898 // user defined functions
899 public void loadTicket (string tid) {
901 _this.el.get_size(out w, out h);
904 _this.scrolled_window.el.hide();
905 _this.el.resize(w, 150);
907 _this.scrolled_window.el.show();
908 _this.el.resize(w, 800);
911 var rs = RooTicket.singleton();
912 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
913 var hd = uri.get_http_headers();
914 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
915 hd.append("Authorization", "Basic %s".printf(authCode));
917 this.el.load_request(uri);