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);
66 // have they selected a ticket..
67 // make that the current active ticket?
68 // we really need to store locally what ticket is being worked on..
69 // in theory we could be working on multiple project and not merging..
70 // -- each repo would have their active ticket (only one per repo)
71 // -- so we could just store that in there
72 // -- initial load can check the contents of the ticket files on first scan.
75 if (response_id < 1) {
81 var ticket_id = _this.ticketsel.selectedTicketId();
83 if (this.repo != null) {
84 var bn = _this.name.el.get_text();
86 var res = this.repo.setActiveTicket(
87 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
90 // start the monitoring..
91 GitMonitor.gitmonitor.start();
107 // user defined functions
108 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
110 // this.el.set_gravity(Gdk.Gravity.NORTH);
111 if (this.running) { // should not happen!!
112 GLib.error("new branch show called, when already being displayed?");
117 GitMonitor.gitmonitor.stop();
123 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
124 this.el.set_default_size( 500,200); // not sure why it grows..
125 GLib.debug("Loading tickets");
129 this.el.set_keep_above(true);
132 var curproj = RooProject.getProjectByRepo(this.repo);
133 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
135 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
136 _this.ticketsel.el.get_child().get_style_context().remove_class("warning");
138 var name = RooTicket.singleton().usernameLocal();
139 var ticket = RooTicket.singleton().getById(tid);
140 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
142 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
144 _this.view.loadTicket(tid);
148 public class Xcls_Box2 : Object
151 private NewBranch _this;
157 public Xcls_Box2(NewBranch _owner )
160 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
164 // set gobject values
165 var child_0 = new Xcls_Table3( _this );
167 this.el.pack_start ( child_0.el , false,false,0 );
168 var child_1 = new Xcls_scrolled_window( _this );
170 this.el.add ( child_1.el );
173 // user defined functions
175 public class Xcls_Table3 : Object
178 private NewBranch _this;
184 public Xcls_Table3(NewBranch _owner )
187 this.el = new Gtk.Table( 5, 5, true );
191 // set gobject values
192 this.el.expand = false;
194 this.el.column_spacing = 4;
195 this.el.vexpand = false;
196 var child_0 = new Xcls_Label4( _this );
198 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
199 var child_1 = new Xcls_Label5( _this );
201 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
202 var child_2 = new Xcls_projectsel( _this );
204 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
205 var child_3 = new Xcls_ticketsel( _this );
207 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
208 var child_4 = new Xcls_Button12( _this );
210 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
211 var child_5 = new Xcls_Label13( _this );
213 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
214 var child_6 = new Xcls_name( _this );
216 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
217 var child_7 = new Xcls_Button15( _this );
219 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
220 var child_8 = new Xcls_Box16( _this );
222 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
225 // user defined functions
227 public class Xcls_Label4 : Object
230 private NewBranch _this;
236 public Xcls_Label4(NewBranch _owner )
239 this.el = new Gtk.Label( "Project" );
243 // set gobject values
244 this.el.halign = Gtk.Align.START;
245 this.el.justify = Gtk.Justification.RIGHT;
246 this.el.visible = true;
249 // user defined functions
252 public class Xcls_Label5 : Object
255 private NewBranch _this;
261 public Xcls_Label5(NewBranch _owner )
264 this.el = new Gtk.Label( "Ticket" );
268 // set gobject values
269 this.el.halign = Gtk.Align.START;
270 this.el.visible = true;
273 // user defined functions
276 public class Xcls_projectsel : Object
278 public Gtk.ComboBox el;
279 private NewBranch _this;
286 public Xcls_projectsel(NewBranch _owner )
289 _this.projectsel = this;
290 this.el = new Gtk.ComboBox.with_entry();
293 this.loading = false;
295 // set gobject values
296 var child_0 = new Xcls_prcellrenderer( _this );
298 this.el.pack_start ( child_0.el , true );
299 var child_1 = new Xcls_prmodel( _this );
301 this.el.set_model ( child_1.el );
305 this.el.set_entry_text_column(1);
308 this.el.changed.connect( () => {
312 var project_id = this.selectedProjectId();
313 _this.dbmodel.loadTickets(project_id);
316 /*if (this.loading) {
319 var ticket_id = this.selectedTicketId();
321 var name = RooTicket.singleton().usernameLocal();
323 if (ticket_id == "" || ticket_id == null) {
325 var dt = new DateTime.now_local();
326 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
331 var ticket = RooTicket.singleton().getById(ticket_id);
333 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
335 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
340 // user defined functions
341 public string selectedProjectId () {
346 this.el.get_active_iter (out iter);
347 _this.prmodel.el.get_value (iter, 0, out val1);
350 return (string) val1;
357 public class Xcls_prcellrenderer : Object
359 public Gtk.CellRendererText el;
360 private NewBranch _this;
366 public Xcls_prcellrenderer(NewBranch _owner )
369 _this.prcellrenderer = this;
370 this.el = new Gtk.CellRendererText();
374 // set gobject values
377 // user defined functions
380 public class Xcls_prmodel : Object
382 public Gtk.ListStore el;
383 private NewBranch _this;
389 public Xcls_prmodel(NewBranch _owner )
392 _this.prmodel = this;
393 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
397 // set gobject values
400 // user defined functions
401 public void loadProjects (string id) {
405 _this.projectsel.loading = true;
414 el.set_value(iter, 0, "");
415 el.set_value(iter, 1, "-- select a project --");
417 _this.projectsel.el.set_active_iter(iter);
420 foreach(var project in RooProject.projects()) {
424 el.set_value(iter, 0, project.id);
425 el.set_value(iter, 1, project.name );
426 if (id == project.id) {
427 _this.projectsel.el.set_active_iter(iter);
432 _this.projectsel.loading = false;
433 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
439 public class Xcls_ticketsel : Object
441 public Gtk.ComboBox el;
442 private NewBranch _this;
449 public Xcls_ticketsel(NewBranch _owner )
452 _this.ticketsel = this;
453 this.el = new Gtk.ComboBox.with_entry();
456 this.loading = false;
458 // set gobject values
459 var child_0 = new Xcls_dbcellrenderer( _this );
461 this.el.pack_start ( child_0.el , true );
462 var child_1 = new Xcls_dbmodel( _this );
464 this.el.set_model ( child_1.el );
468 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
469 this.el.set_entry_text_column(1);
470 this.el.get_child().set_sensitive(false);
473 this.el.changed.connect( () => {
477 var ticket_id = this.selectedTicketId();
479 var name = RooTicket.singleton().usernameLocal();
481 this.el.get_child().get_style_context().remove_class("warning");
482 if (ticket_id == "" || ticket_id == null) {
484 var dt = new DateTime.now_local();
485 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
486 _this.view.loadTicket("");
488 this.el.get_child().get_style_context().add_class("warning");
494 var ticket = RooTicket.singleton().getById(ticket_id);
496 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
497 _this.scrolled_window.el.show();
499 _this.view.loadTicket(ticket.id);
500 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
504 // user defined functions
505 public string selectedTicketId () {
510 this.el.get_active_iter (out iter);
511 _this.dbmodel.el.get_value (iter, 0, out val1);
514 return (string) val1;
521 public class Xcls_dbcellrenderer : Object
523 public Gtk.CellRendererText el;
524 private NewBranch _this;
530 public Xcls_dbcellrenderer(NewBranch _owner )
533 _this.dbcellrenderer = this;
534 this.el = new Gtk.CellRendererText();
538 // set gobject values
541 // user defined functions
544 public class Xcls_dbmodel : Object
546 public Gtk.ListStore el;
547 private NewBranch _this;
553 public Xcls_dbmodel(NewBranch _owner )
556 _this.dbmodel = this;
557 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
561 // set gobject values
564 // user defined functions
565 public void loadTickets (string project_id , string tid = "") {
569 // fixme .. get project id from selection..
571 RooTicket.singleton().loadTickets(
573 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
574 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
577 _this.ticketsel.loading = true;
586 el.set_value(iter, 0, "");
587 el.set_value(iter, 1, "-- select a ticket --");
589 _this.ticketsel.el.set_active_iter(iter);
590 var tickets = RooTicket.singleton().tickets;
591 foreach(var ticket in tickets) {
595 el.set_value(iter, 0, ticket.id);
596 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
598 if (ticket.id == tid) {
599 _this.ticketsel.el.set_active_iter(iter);
604 _this.ticketsel.loading = false;
605 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
611 public class Xcls_Button12 : Object
613 public Gtk.Button el;
614 private NewBranch _this;
620 public Xcls_Button12(NewBranch _owner )
623 this.el = new Gtk.Button();
627 // set gobject values
628 this.el.expand = false;
629 this.el.label = "New Ticket";
632 this.el.clicked.connect( () => {
633 _this.el.response(-1);
634 Ticket.singleton().show(_this.repo);
639 // user defined functions
642 public class Xcls_Label13 : Object
645 private NewBranch _this;
651 public Xcls_Label13(NewBranch _owner )
654 this.el = new Gtk.Label( "Use this as branch name" );
658 // set gobject values
659 this.el.halign = Gtk.Align.START;
660 this.el.justify = Gtk.Justification.RIGHT;
661 this.el.xalign = 0.900000f;
664 // user defined functions
667 public class Xcls_name : Object
670 private NewBranch _this;
676 public Xcls_name(NewBranch _owner )
680 this.el = new Gtk.Entry();
684 // set gobject values
685 this.el.visible = true;
688 // user defined functions
691 public class Xcls_Button15 : Object
693 public Gtk.Button el;
694 private NewBranch _this;
700 public Xcls_Button15(NewBranch _owner )
703 this.el = new Gtk.Button();
707 // set gobject values
708 this.el.label = "Create Branch";
713 this.el.get_style_context().add_class("suggested-action");
717 this.el.clicked.connect( () => {
719 GLib.debug("fire response = 1");
721 var ticket_id = _this.ticketsel.selectedTicketId();
723 if (ticket_id == "") {
724 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
728 _this.el.response(1);
732 // user defined functions
735 public class Xcls_Box16 : Object
738 private NewBranch _this;
744 public Xcls_Box16(NewBranch _owner )
747 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
751 // set gobject values
752 var child_0 = new Xcls_btn_not_me( _this );
754 this.el.add ( child_0.el );
755 var child_1 = new Xcls_btn_closed( _this );
757 this.el.add ( child_1.el );
758 var child_2 = new Xcls_Label19( _this );
760 this.el.add ( child_2.el );
763 // user defined functions
765 public class Xcls_btn_not_me : Object
767 public Gtk.CheckButton el;
768 private NewBranch _this;
774 public Xcls_btn_not_me(NewBranch _owner )
777 _this.btn_not_me = this;
778 this.el = new Gtk.CheckButton();
782 // set gobject values
783 this.el.label = "Show tickets not assigned to me";
786 this.el.toggled.connect( () => {
787 var project_id = _this.projectsel.selectedProjectId();
788 _this.dbmodel.loadTickets(project_id);
792 // user defined functions
795 public class Xcls_btn_closed : Object
797 public Gtk.CheckButton el;
798 private NewBranch _this;
804 public Xcls_btn_closed(NewBranch _owner )
807 _this.btn_closed = this;
808 this.el = new Gtk.CheckButton();
812 // set gobject values
813 this.el.label = "Show closed Tickets";
816 this.el.toggled.connect( () => {
817 var project_id = _this.projectsel.selectedProjectId();
818 _this.dbmodel.loadTickets(project_id);
823 // user defined functions
826 public class Xcls_Label19 : Object
829 private NewBranch _this;
835 public Xcls_Label19(NewBranch _owner )
838 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
842 // set gobject values
843 this.el.halign = Gtk.Align.END;
844 this.el.hexpand = true;
845 this.el.use_markup = true;
848 this.el.activate_link.connect( (uri) => {
849 if (uri == "refresh") {
851 var curproj = RooProject.getProjectByRepo(_this.repo);
852 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
854 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
860 // user defined functions
865 public class Xcls_scrolled_window : Object
867 public Gtk.ScrolledWindow el;
868 private NewBranch _this;
874 public Xcls_scrolled_window(NewBranch _owner )
877 _this.scrolled_window = this;
878 this.el = new Gtk.ScrolledWindow( null, null );
882 // set gobject values
883 this.el.height_request = 500;
884 this.el.vexpand = true;
885 var child_0 = new Xcls_view( _this );
887 this.el.add ( child_0.el );
892 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
896 // user defined functions
898 public class Xcls_view : Object
900 public WebKit.WebView el;
901 private NewBranch _this;
907 public Xcls_view(NewBranch _owner )
911 this.el = new WebKit.WebView();
915 // set gobject values
918 // user defined functions
919 public void loadTicket (string tid) {
921 _this.el.get_size(out w, out h);
924 _this.scrolled_window.el.hide();
925 _this.el.resize(w, 150);
927 _this.scrolled_window.el.show();
928 _this.el.resize(w, 800);
931 var rs = RooTicket.singleton();
932 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
933 var hd = uri.get_http_headers();
934 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
935 hd.append("Authorization", "Basic %s".printf(authCode));
937 this.el.load_request(uri);