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) {
72 // have they selected a ticket..
73 // make that the current active ticket?
74 // we really need to store locally what ticket is being worked on..
75 // in theory we could be working on multiple project and not merging..
76 // -- each repo would have their active ticket (only one per repo)
77 // -- so we could just store that in there
78 // -- initial load can check the contents of the ticket files on first scan.
79 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);
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()));
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 if (ticket_id == "" || ticket_id == null) {
483 var dt = new DateTime.now_local();
484 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
485 _this.view.loadTicket("");
490 var ticket = RooTicket.singleton().getById(ticket_id);
492 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
493 _this.scrolled_window.el.show();
495 _this.view.loadTicket(ticket.id);
496 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
500 // user defined functions
501 public string selectedTicketId () {
506 this.el.get_active_iter (out iter);
507 _this.dbmodel.el.get_value (iter, 0, out val1);
510 return (string) val1;
517 public class Xcls_dbcellrenderer : Object
519 public Gtk.CellRendererText el;
520 private NewBranch _this;
526 public Xcls_dbcellrenderer(NewBranch _owner )
529 _this.dbcellrenderer = this;
530 this.el = new Gtk.CellRendererText();
534 // set gobject values
537 // user defined functions
540 public class Xcls_dbmodel : Object
542 public Gtk.ListStore el;
543 private NewBranch _this;
549 public Xcls_dbmodel(NewBranch _owner )
552 _this.dbmodel = this;
553 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
557 // set gobject values
560 // user defined functions
561 public void loadTickets (string project_id , string tid = "") {
565 // fixme .. get project id from selection..
567 RooTicket.singleton().loadTickets(
569 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
570 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
573 _this.ticketsel.loading = true;
582 el.set_value(iter, 0, "");
583 el.set_value(iter, 1, "-- select a ticket --");
585 _this.ticketsel.el.set_active_iter(iter);
586 var tickets = RooTicket.singleton().tickets;
587 foreach(var ticket in tickets) {
591 el.set_value(iter, 0, ticket.id);
592 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
594 if (ticket.id == tid) {
595 _this.ticketsel.el.set_active_iter(iter);
600 _this.ticketsel.loading = false;
601 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
607 public class Xcls_Button12 : Object
609 public Gtk.Button el;
610 private NewBranch _this;
616 public Xcls_Button12(NewBranch _owner )
619 this.el = new Gtk.Button();
623 // set gobject values
624 this.el.expand = false;
625 this.el.label = "New Ticket";
628 this.el.clicked.connect( () => {
629 _this.el.response(-1);
630 Ticket.singleton().show(_this.repo);
635 // user defined functions
638 public class Xcls_Label13 : Object
641 private NewBranch _this;
647 public Xcls_Label13(NewBranch _owner )
650 this.el = new Gtk.Label( "Use this as branch name" );
654 // set gobject values
655 this.el.halign = Gtk.Align.START;
656 this.el.justify = Gtk.Justification.RIGHT;
657 this.el.xalign = 0.900000f;
660 // user defined functions
663 public class Xcls_name : Object
666 private NewBranch _this;
672 public Xcls_name(NewBranch _owner )
676 this.el = new Gtk.Entry();
680 // set gobject values
681 this.el.visible = true;
684 // user defined functions
687 public class Xcls_Button15 : Object
689 public Gtk.Button el;
690 private NewBranch _this;
696 public Xcls_Button15(NewBranch _owner )
699 this.el = new Gtk.Button();
703 // set gobject values
704 this.el.label = "Create Branch";
709 this.el.get_style_context().add_class("suggested-action");
713 this.el.clicked.connect( () => {
714 GLib.debug("fire response = 1");
715 _this.el.response(1);
719 // user defined functions
722 public class Xcls_Box16 : Object
725 private NewBranch _this;
731 public Xcls_Box16(NewBranch _owner )
734 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
738 // set gobject values
739 var child_0 = new Xcls_btn_not_me( _this );
741 this.el.add ( child_0.el );
742 var child_1 = new Xcls_btn_closed( _this );
744 this.el.add ( child_1.el );
745 var child_2 = new Xcls_Label19( _this );
747 this.el.add ( child_2.el );
750 // user defined functions
752 public class Xcls_btn_not_me : Object
754 public Gtk.CheckButton el;
755 private NewBranch _this;
761 public Xcls_btn_not_me(NewBranch _owner )
764 _this.btn_not_me = this;
765 this.el = new Gtk.CheckButton();
769 // set gobject values
770 this.el.label = "Show tickets not assigned to me";
773 this.el.toggled.connect( () => {
774 var project_id = _this.projectsel.selectedProjectId();
775 _this.dbmodel.loadTickets(project_id);
779 // user defined functions
782 public class Xcls_btn_closed : Object
784 public Gtk.CheckButton el;
785 private NewBranch _this;
791 public Xcls_btn_closed(NewBranch _owner )
794 _this.btn_closed = this;
795 this.el = new Gtk.CheckButton();
799 // set gobject values
800 this.el.label = "Show closed Tickets";
803 this.el.toggled.connect( () => {
804 var project_id = _this.projectsel.selectedProjectId();
805 _this.dbmodel.loadTickets(project_id);
810 // user defined functions
813 public class Xcls_Label19 : Object
816 private NewBranch _this;
822 public Xcls_Label19(NewBranch _owner )
825 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
829 // set gobject values
830 this.el.halign = Gtk.Align.END;
831 this.el.hexpand = true;
832 this.el.use_markup = true;
835 this.el.activate_link.connect( (uri) => {
836 if (uri == "refresh") {
838 var curproj = RooProject.getProjectByRepo(_this.repo);
839 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
841 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
847 // user defined functions
852 public class Xcls_scrolled_window : Object
854 public Gtk.ScrolledWindow el;
855 private NewBranch _this;
861 public Xcls_scrolled_window(NewBranch _owner )
864 _this.scrolled_window = this;
865 this.el = new Gtk.ScrolledWindow( null, null );
869 // set gobject values
870 this.el.height_request = 500;
871 this.el.vexpand = true;
872 var child_0 = new Xcls_view( _this );
874 this.el.add ( child_0.el );
879 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
883 // user defined functions
885 public class Xcls_view : Object
887 public WebKit.WebView el;
888 private NewBranch _this;
894 public Xcls_view(NewBranch _owner )
898 this.el = new WebKit.WebView();
902 // set gobject values
905 // user defined functions
906 public void loadTicket (string tid) {
908 _this.el.get_size(out w, out h);
911 _this.scrolled_window.el.hide();
912 _this.el.resize(w, 150);
914 _this.scrolled_window.el.show();
915 _this.el.resize(w, 800);
918 var rs = RooTicket.singleton();
919 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
920 var hd = uri.get_http_headers();
921 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
922 hd.append("Authorization", "Basic %s".printf(authCode));
924 this.el.load_request(uri);