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);
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 (ticket_id == "") {
78 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
83 if (response_id < 1) {
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.ticketsel.el.get_child().get_style_context().remove_class("warning");
145 var name = RooTicket.singleton().usernameLocal();
146 var ticket = RooTicket.singleton().getById(tid);
147 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
149 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
151 _this.view.loadTicket(tid);
155 public class Xcls_Box2 : Object
158 private NewBranch _this;
164 public Xcls_Box2(NewBranch _owner )
167 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
171 // set gobject values
172 var child_0 = new Xcls_Table3( _this );
174 this.el.pack_start ( child_0.el , false,false,0 );
175 var child_1 = new Xcls_scrolled_window( _this );
177 this.el.add ( child_1.el );
180 // user defined functions
182 public class Xcls_Table3 : Object
185 private NewBranch _this;
191 public Xcls_Table3(NewBranch _owner )
194 this.el = new Gtk.Table( 5, 5, true );
198 // set gobject values
199 this.el.expand = false;
201 this.el.column_spacing = 4;
202 this.el.vexpand = false;
203 var child_0 = new Xcls_Label4( _this );
205 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
206 var child_1 = new Xcls_Label5( _this );
208 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
209 var child_2 = new Xcls_projectsel( _this );
211 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
212 var child_3 = new Xcls_ticketsel( _this );
214 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
215 var child_4 = new Xcls_Button12( _this );
217 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
218 var child_5 = new Xcls_Label13( _this );
220 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
221 var child_6 = new Xcls_name( _this );
223 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
224 var child_7 = new Xcls_Button15( _this );
226 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
227 var child_8 = new Xcls_Box16( _this );
229 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
232 // user defined functions
234 public class Xcls_Label4 : Object
237 private NewBranch _this;
243 public Xcls_Label4(NewBranch _owner )
246 this.el = new Gtk.Label( "Project" );
250 // set gobject values
251 this.el.halign = Gtk.Align.START;
252 this.el.justify = Gtk.Justification.RIGHT;
253 this.el.visible = true;
256 // user defined functions
259 public class Xcls_Label5 : Object
262 private NewBranch _this;
268 public Xcls_Label5(NewBranch _owner )
271 this.el = new Gtk.Label( "Ticket" );
275 // set gobject values
276 this.el.halign = Gtk.Align.START;
277 this.el.visible = true;
280 // user defined functions
283 public class Xcls_projectsel : Object
285 public Gtk.ComboBox el;
286 private NewBranch _this;
293 public Xcls_projectsel(NewBranch _owner )
296 _this.projectsel = this;
297 this.el = new Gtk.ComboBox.with_entry();
300 this.loading = false;
302 // set gobject values
303 var child_0 = new Xcls_prcellrenderer( _this );
305 this.el.pack_start ( child_0.el , true );
306 var child_1 = new Xcls_prmodel( _this );
308 this.el.set_model ( child_1.el );
312 this.el.set_entry_text_column(1);
315 this.el.changed.connect( () => {
319 var project_id = this.selectedProjectId();
320 _this.dbmodel.loadTickets(project_id);
323 /*if (this.loading) {
326 var ticket_id = this.selectedTicketId();
328 var name = RooTicket.singleton().usernameLocal();
330 if (ticket_id == "" || ticket_id == null) {
332 var dt = new DateTime.now_local();
333 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
338 var ticket = RooTicket.singleton().getById(ticket_id);
340 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
342 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
347 // user defined functions
348 public string selectedProjectId () {
353 this.el.get_active_iter (out iter);
354 _this.prmodel.el.get_value (iter, 0, out val1);
357 return (string) val1;
364 public class Xcls_prcellrenderer : Object
366 public Gtk.CellRendererText el;
367 private NewBranch _this;
373 public Xcls_prcellrenderer(NewBranch _owner )
376 _this.prcellrenderer = this;
377 this.el = new Gtk.CellRendererText();
381 // set gobject values
384 // user defined functions
387 public class Xcls_prmodel : Object
389 public Gtk.ListStore el;
390 private NewBranch _this;
396 public Xcls_prmodel(NewBranch _owner )
399 _this.prmodel = this;
400 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
404 // set gobject values
407 // user defined functions
408 public void loadProjects (string id) {
412 _this.projectsel.loading = true;
421 el.set_value(iter, 0, "");
422 el.set_value(iter, 1, "-- select a project --");
424 _this.projectsel.el.set_active_iter(iter);
427 foreach(var project in RooProject.projects()) {
431 el.set_value(iter, 0, project.id);
432 el.set_value(iter, 1, project.name );
433 if (id == project.id) {
434 _this.projectsel.el.set_active_iter(iter);
439 _this.projectsel.loading = false;
440 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
446 public class Xcls_ticketsel : Object
448 public Gtk.ComboBox el;
449 private NewBranch _this;
456 public Xcls_ticketsel(NewBranch _owner )
459 _this.ticketsel = this;
460 this.el = new Gtk.ComboBox.with_entry();
463 this.loading = false;
465 // set gobject values
466 var child_0 = new Xcls_dbcellrenderer( _this );
468 this.el.pack_start ( child_0.el , true );
469 var child_1 = new Xcls_dbmodel( _this );
471 this.el.set_model ( child_1.el );
475 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
476 this.el.set_entry_text_column(1);
477 this.el.get_child().set_sensitive(false);
480 this.el.changed.connect( () => {
484 var ticket_id = this.selectedTicketId();
486 var name = RooTicket.singleton().usernameLocal();
488 this.el.get_child().get_style_context().remove_class("warning");
489 if (ticket_id == "" || ticket_id == null) {
491 var dt = new DateTime.now_local();
492 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
493 _this.view.loadTicket("");
495 this.el.get_child().get_style_context().add_class("warning");
501 var ticket = RooTicket.singleton().getById(ticket_id);
503 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
504 _this.scrolled_window.el.show();
506 _this.view.loadTicket(ticket.id);
507 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
511 // user defined functions
512 public string selectedTicketId () {
517 this.el.get_active_iter (out iter);
518 _this.dbmodel.el.get_value (iter, 0, out val1);
521 return (string) val1;
528 public class Xcls_dbcellrenderer : Object
530 public Gtk.CellRendererText el;
531 private NewBranch _this;
537 public Xcls_dbcellrenderer(NewBranch _owner )
540 _this.dbcellrenderer = this;
541 this.el = new Gtk.CellRendererText();
545 // set gobject values
548 // user defined functions
551 public class Xcls_dbmodel : Object
553 public Gtk.ListStore el;
554 private NewBranch _this;
560 public Xcls_dbmodel(NewBranch _owner )
563 _this.dbmodel = this;
564 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
568 // set gobject values
571 // user defined functions
572 public void loadTickets (string project_id , string tid = "") {
576 // fixme .. get project id from selection..
578 RooTicket.singleton().loadTickets(
580 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
581 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
584 _this.ticketsel.loading = true;
593 el.set_value(iter, 0, "");
594 el.set_value(iter, 1, "-- select a ticket --");
596 _this.ticketsel.el.set_active_iter(iter);
597 var tickets = RooTicket.singleton().tickets;
598 foreach(var ticket in tickets) {
602 el.set_value(iter, 0, ticket.id);
603 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
605 if (ticket.id == tid) {
606 _this.ticketsel.el.set_active_iter(iter);
611 _this.ticketsel.loading = false;
612 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
618 public class Xcls_Button12 : Object
620 public Gtk.Button el;
621 private NewBranch _this;
627 public Xcls_Button12(NewBranch _owner )
630 this.el = new Gtk.Button();
634 // set gobject values
635 this.el.expand = false;
636 this.el.label = "New Ticket";
639 this.el.clicked.connect( () => {
640 _this.el.response(-1);
641 Ticket.singleton().show(_this.repo);
646 // user defined functions
649 public class Xcls_Label13 : Object
652 private NewBranch _this;
658 public Xcls_Label13(NewBranch _owner )
661 this.el = new Gtk.Label( "Use this as branch name" );
665 // set gobject values
666 this.el.halign = Gtk.Align.START;
667 this.el.justify = Gtk.Justification.RIGHT;
668 this.el.xalign = 0.900000f;
671 // user defined functions
674 public class Xcls_name : Object
677 private NewBranch _this;
683 public Xcls_name(NewBranch _owner )
687 this.el = new Gtk.Entry();
691 // set gobject values
692 this.el.visible = true;
695 // user defined functions
698 public class Xcls_Button15 : Object
700 public Gtk.Button el;
701 private NewBranch _this;
707 public Xcls_Button15(NewBranch _owner )
710 this.el = new Gtk.Button();
714 // set gobject values
715 this.el.label = "Create Branch";
720 this.el.get_style_context().add_class("suggested-action");
724 this.el.clicked.connect( () => {
725 GLib.debug("fire response = 1");
726 _this.el.response(1);
730 // user defined functions
733 public class Xcls_Box16 : Object
736 private NewBranch _this;
742 public Xcls_Box16(NewBranch _owner )
745 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
749 // set gobject values
750 var child_0 = new Xcls_btn_not_me( _this );
752 this.el.add ( child_0.el );
753 var child_1 = new Xcls_btn_closed( _this );
755 this.el.add ( child_1.el );
756 var child_2 = new Xcls_Label19( _this );
758 this.el.add ( child_2.el );
761 // user defined functions
763 public class Xcls_btn_not_me : Object
765 public Gtk.CheckButton el;
766 private NewBranch _this;
772 public Xcls_btn_not_me(NewBranch _owner )
775 _this.btn_not_me = this;
776 this.el = new Gtk.CheckButton();
780 // set gobject values
781 this.el.label = "Show tickets not assigned to me";
784 this.el.toggled.connect( () => {
785 var project_id = _this.projectsel.selectedProjectId();
786 _this.dbmodel.loadTickets(project_id);
790 // user defined functions
793 public class Xcls_btn_closed : Object
795 public Gtk.CheckButton el;
796 private NewBranch _this;
802 public Xcls_btn_closed(NewBranch _owner )
805 _this.btn_closed = this;
806 this.el = new Gtk.CheckButton();
810 // set gobject values
811 this.el.label = "Show closed Tickets";
814 this.el.toggled.connect( () => {
815 var project_id = _this.projectsel.selectedProjectId();
816 _this.dbmodel.loadTickets(project_id);
821 // user defined functions
824 public class Xcls_Label19 : Object
827 private NewBranch _this;
833 public Xcls_Label19(NewBranch _owner )
836 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
840 // set gobject values
841 this.el.halign = Gtk.Align.END;
842 this.el.hexpand = true;
843 this.el.use_markup = true;
846 this.el.activate_link.connect( (uri) => {
847 if (uri == "refresh") {
849 var curproj = RooProject.getProjectByRepo(_this.repo);
850 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
852 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
858 // user defined functions
863 public class Xcls_scrolled_window : Object
865 public Gtk.ScrolledWindow el;
866 private NewBranch _this;
872 public Xcls_scrolled_window(NewBranch _owner )
875 _this.scrolled_window = this;
876 this.el = new Gtk.ScrolledWindow( null, null );
880 // set gobject values
881 this.el.height_request = 500;
882 this.el.vexpand = true;
883 var child_0 = new Xcls_view( _this );
885 this.el.add ( child_0.el );
890 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
894 // user defined functions
896 public class Xcls_view : Object
898 public WebKit.WebView el;
899 private NewBranch _this;
905 public Xcls_view(NewBranch _owner )
909 this.el = new WebKit.WebView();
913 // set gobject values
916 // user defined functions
917 public void loadTicket (string tid) {
919 _this.el.get_size(out w, out h);
922 _this.scrolled_window.el.hide();
923 _this.el.resize(w, 150);
925 _this.scrolled_window.el.show();
926 _this.el.resize(w, 800);
929 var rs = RooTicket.singleton();
930 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
931 var hd = uri.get_http_headers();
932 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
933 hd.append("Authorization", "Basic %s".printf(authCode));
935 this.el.load_request(uri);