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;
31 public Gee.ArrayList<GitMonitorQueue> queue;
37 this.el = new Gtk.Dialog();
45 this.el.title = "Create a working branch ";
46 this.el.default_height = 500;
47 this.el.default_width = 500;
48 this.el.deletable = true;
50 var child_0 = new Xcls_Box2( _this );
52 this.el.get_content_area().add ( child_0.el );
55 this.el.delete_event.connect( (self, event) => {
60 this.el.response.connect( (self, response_id) => {
62 GLib.debug("got %d", (int) response_id);
67 // have they selected a ticket..
68 // make that the current active ticket?
69 // we really need to store locally what ticket is being worked on..
70 // in theory we could be working on multiple project and not merging..
71 // -- each repo would have their active ticket (only one per repo)
72 // -- so we could just store that in there
73 // -- initial load can check the contents of the ticket files on first scan.
76 if (response_id < 1) {
82 var ticket_id = _this.ticketsel.selectedTicketId();
84 if (this.repo != null) {
85 var bn = _this.name.el.get_text();
87 var res = this.repo.setActiveTicket(
88 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
91 // start the monitoring..
92 GitMonitor.gitmonitor.start();
108 // user defined functions
109 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
111 // this.el.set_gravity(Gdk.Gravity.NORTH);
112 if (this.running) { // should not happen!!
113 GLib.error("new branch show called, when already being displayed?");
118 GitMonitor.gitmonitor.stop();
124 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
125 this.el.set_default_size( 500,200); // not sure why it grows..
126 GLib.debug("Loading tickets");
130 this.el.set_keep_above(true);
133 var curproj = RooProject.getProjectByRepo(this.repo);
134 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
136 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
137 _this.createbtn.updateState();
139 _this.ticketsel.el.get_child().get_style_context().remove_class("warning");
141 var name = RooTicket.singleton().usernameLocal();
142 var ticket = RooTicket.singleton().getById(tid);
143 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
145 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
147 _this.view.loadTicket(tid);
151 public class Xcls_Box2 : Object
154 private NewBranch _this;
160 public Xcls_Box2(NewBranch _owner )
163 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
167 // set gobject values
168 var child_0 = new Xcls_Table3( _this );
170 this.el.pack_start ( child_0.el , false,false,0 );
171 var child_1 = new Xcls_scrolled_window( _this );
173 this.el.add ( child_1.el );
176 // user defined functions
178 public class Xcls_Table3 : Object
181 private NewBranch _this;
187 public Xcls_Table3(NewBranch _owner )
190 this.el = new Gtk.Table( 5, 5, true );
194 // set gobject values
195 this.el.expand = false;
197 this.el.column_spacing = 4;
198 this.el.vexpand = false;
199 var child_0 = new Xcls_Label4( _this );
201 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
202 var child_1 = new Xcls_Label5( _this );
204 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
205 var child_2 = new Xcls_projectsel( _this );
207 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
208 var child_3 = new Xcls_ticketsel( _this );
210 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
211 var child_4 = new Xcls_Button12( _this );
213 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
214 var child_5 = new Xcls_Label13( _this );
216 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
217 var child_6 = new Xcls_name( _this );
219 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
220 var child_7 = new Xcls_createbtn( _this );
222 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
223 var child_8 = new Xcls_Box16( _this );
225 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
228 // user defined functions
230 public class Xcls_Label4 : Object
233 private NewBranch _this;
239 public Xcls_Label4(NewBranch _owner )
242 this.el = new Gtk.Label( "Project" );
246 // set gobject values
247 this.el.halign = Gtk.Align.START;
248 this.el.justify = Gtk.Justification.RIGHT;
249 this.el.visible = true;
252 // user defined functions
255 public class Xcls_Label5 : Object
258 private NewBranch _this;
264 public Xcls_Label5(NewBranch _owner )
267 this.el = new Gtk.Label( "Ticket" );
271 // set gobject values
272 this.el.halign = Gtk.Align.START;
273 this.el.visible = true;
276 // user defined functions
279 public class Xcls_projectsel : Object
281 public Gtk.ComboBox el;
282 private NewBranch _this;
289 public Xcls_projectsel(NewBranch _owner )
292 _this.projectsel = this;
293 this.el = new Gtk.ComboBox.with_entry();
296 this.loading = false;
298 // set gobject values
299 var child_0 = new Xcls_prcellrenderer( _this );
301 this.el.pack_start ( child_0.el , true );
302 var child_1 = new Xcls_prmodel( _this );
304 this.el.set_model ( child_1.el );
308 this.el.set_entry_text_column(1);
311 this.el.changed.connect( () => {
315 var project_id = this.selectedProjectId();
316 _this.dbmodel.loadTickets(project_id);
319 /*if (this.loading) {
322 var ticket_id = this.selectedTicketId();
324 var name = RooTicket.singleton().usernameLocal();
326 if (ticket_id == "" || ticket_id == null) {
328 var dt = new DateTime.now_local();
329 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
334 var ticket = RooTicket.singleton().getById(ticket_id);
336 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
338 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
343 // user defined functions
344 public string selectedProjectId () {
349 this.el.get_active_iter (out iter);
350 _this.prmodel.el.get_value (iter, 0, out val1);
353 return (string) val1;
360 public class Xcls_prcellrenderer : Object
362 public Gtk.CellRendererText el;
363 private NewBranch _this;
369 public Xcls_prcellrenderer(NewBranch _owner )
372 _this.prcellrenderer = this;
373 this.el = new Gtk.CellRendererText();
377 // set gobject values
380 // user defined functions
383 public class Xcls_prmodel : Object
385 public Gtk.ListStore el;
386 private NewBranch _this;
392 public Xcls_prmodel(NewBranch _owner )
395 _this.prmodel = this;
396 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
400 // set gobject values
403 // user defined functions
404 public void loadProjects (string id) {
408 _this.projectsel.loading = true;
417 el.set_value(iter, 0, "");
418 el.set_value(iter, 1, "-- select a project --");
420 _this.projectsel.el.set_active_iter(iter);
423 foreach(var project in RooProject.projects()) {
427 el.set_value(iter, 0, project.id);
428 el.set_value(iter, 1, project.name );
429 if (id == project.id) {
430 _this.projectsel.el.set_active_iter(iter);
435 _this.projectsel.loading = false;
436 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
442 public class Xcls_ticketsel : Object
444 public Gtk.ComboBox el;
445 private NewBranch _this;
452 public Xcls_ticketsel(NewBranch _owner )
455 _this.ticketsel = this;
456 this.el = new Gtk.ComboBox.with_entry();
459 this.loading = false;
461 // set gobject values
462 var child_0 = new Xcls_dbcellrenderer( _this );
464 this.el.pack_start ( child_0.el , true );
465 var child_1 = new Xcls_dbmodel( _this );
467 this.el.set_model ( child_1.el );
471 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
472 this.el.set_entry_text_column(1);
473 this.el.get_child().set_sensitive(false);
476 this.el.changed.connect( () => {
480 var ticket_id = this.selectedTicketId();
482 var name = RooTicket.singleton().usernameLocal();
484 this.el.get_child().get_style_context().remove_class("warning");
485 if (ticket_id == "" || ticket_id == null) {
487 var dt = new DateTime.now_local();
488 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
489 _this.view.loadTicket("");
491 this.el.get_child().get_style_context().add_class("warning");
492 _this.createbtn.updateState();
497 var ticket = RooTicket.singleton().getById(ticket_id);
499 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
500 _this.scrolled_window.el.show();
502 _this.view.loadTicket(ticket.id);
503 _this.createbtn.updateState();
505 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
509 // user defined functions
510 public string selectedTicketId () {
515 this.el.get_active_iter (out iter);
516 _this.dbmodel.el.get_value (iter, 0, out val1);
519 return (string) val1;
526 public class Xcls_dbcellrenderer : Object
528 public Gtk.CellRendererText el;
529 private NewBranch _this;
535 public Xcls_dbcellrenderer(NewBranch _owner )
538 _this.dbcellrenderer = this;
539 this.el = new Gtk.CellRendererText();
543 // set gobject values
546 // user defined functions
549 public class Xcls_dbmodel : Object
551 public Gtk.ListStore el;
552 private NewBranch _this;
558 public Xcls_dbmodel(NewBranch _owner )
561 _this.dbmodel = this;
562 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
566 // set gobject values
569 // user defined functions
570 public void loadTickets (string project_id , string tid = "") {
574 // fixme .. get project id from selection..
576 RooTicket.singleton().loadTickets(
578 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
579 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
582 _this.ticketsel.loading = true;
591 el.set_value(iter, 0, "");
592 el.set_value(iter, 1, "-- select a ticket --");
594 _this.ticketsel.el.set_active_iter(iter);
595 var tickets = RooTicket.singleton().tickets;
596 foreach(var ticket in tickets) {
600 el.set_value(iter, 0, ticket.id);
601 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
603 if (ticket.id == tid) {
604 _this.ticketsel.el.set_active_iter(iter);
609 _this.ticketsel.loading = false;
610 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
616 public class Xcls_Button12 : Object
618 public Gtk.Button el;
619 private NewBranch _this;
625 public Xcls_Button12(NewBranch _owner )
628 this.el = new Gtk.Button();
632 // set gobject values
633 this.el.expand = false;
634 this.el.label = "New Ticket";
637 this.el.clicked.connect( () => {
638 _this.el.response(-1);
639 Ticket.singleton().show(_this.repo);
644 // user defined functions
647 public class Xcls_Label13 : Object
650 private NewBranch _this;
656 public Xcls_Label13(NewBranch _owner )
659 this.el = new Gtk.Label( "Use this as branch name" );
663 // set gobject values
664 this.el.halign = Gtk.Align.START;
665 this.el.justify = Gtk.Justification.RIGHT;
666 this.el.xalign = 0.900000f;
669 // user defined functions
672 public class Xcls_name : Object
675 private NewBranch _this;
681 public Xcls_name(NewBranch _owner )
685 this.el = new Gtk.Entry();
689 // set gobject values
690 this.el.visible = true;
693 // user defined functions
696 public class Xcls_createbtn : Object
698 public Gtk.Button el;
699 private NewBranch _this;
705 public Xcls_createbtn(NewBranch _owner )
708 _this.createbtn = this;
709 this.el = new Gtk.Button();
713 // set gobject values
714 this.el.label = "Create Branch";
719 this.el.get_style_context().add_class("suggested-action");
723 this.el.clicked.connect( () => {
725 GLib.debug("fire response = 1");
727 var ticket_id = _this.ticketsel.selectedTicketId();
729 if (ticket_id == "") {
730 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
734 _this.el.response(1);
738 // user defined functions
739 public void updateState () {
741 var ticket_id = _this.ticketsel.selectedTicketId();
743 if (ticket_id == "") {
744 this.el.set_sensitive(false);
748 this.el.set_sensitive(true);
753 public class Xcls_Box16 : Object
756 private NewBranch _this;
762 public Xcls_Box16(NewBranch _owner )
765 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
769 // set gobject values
770 var child_0 = new Xcls_btn_not_me( _this );
772 this.el.add ( child_0.el );
773 var child_1 = new Xcls_btn_closed( _this );
775 this.el.add ( child_1.el );
776 var child_2 = new Xcls_Label19( _this );
778 this.el.add ( child_2.el );
781 // user defined functions
783 public class Xcls_btn_not_me : Object
785 public Gtk.CheckButton el;
786 private NewBranch _this;
792 public Xcls_btn_not_me(NewBranch _owner )
795 _this.btn_not_me = this;
796 this.el = new Gtk.CheckButton();
800 // set gobject values
801 this.el.label = "Show tickets not assigned to me";
804 this.el.toggled.connect( () => {
805 var project_id = _this.projectsel.selectedProjectId();
806 _this.dbmodel.loadTickets(project_id);
810 // user defined functions
813 public class Xcls_btn_closed : Object
815 public Gtk.CheckButton el;
816 private NewBranch _this;
822 public Xcls_btn_closed(NewBranch _owner )
825 _this.btn_closed = this;
826 this.el = new Gtk.CheckButton();
830 // set gobject values
831 this.el.label = "Show closed Tickets";
834 this.el.toggled.connect( () => {
835 var project_id = _this.projectsel.selectedProjectId();
836 _this.dbmodel.loadTickets(project_id);
841 // user defined functions
844 public class Xcls_Label19 : Object
847 private NewBranch _this;
853 public Xcls_Label19(NewBranch _owner )
856 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
860 // set gobject values
861 this.el.halign = Gtk.Align.END;
862 this.el.hexpand = true;
863 this.el.use_markup = true;
866 this.el.activate_link.connect( (uri) => {
867 if (uri == "refresh") {
869 var curproj = RooProject.getProjectByRepo(_this.repo);
870 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
872 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
878 // user defined functions
883 public class Xcls_scrolled_window : Object
885 public Gtk.ScrolledWindow el;
886 private NewBranch _this;
892 public Xcls_scrolled_window(NewBranch _owner )
895 _this.scrolled_window = this;
896 this.el = new Gtk.ScrolledWindow( null, null );
900 // set gobject values
901 this.el.height_request = 500;
902 this.el.vexpand = true;
903 var child_0 = new Xcls_view( _this );
905 this.el.add ( child_0.el );
910 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
914 // user defined functions
916 public class Xcls_view : Object
918 public WebKit.WebView el;
919 private NewBranch _this;
925 public Xcls_view(NewBranch _owner )
929 this.el = new WebKit.WebView();
933 // set gobject values
936 // user defined functions
937 public void loadTicket (string tid) {
939 _this.el.get_size(out w, out h);
942 _this.scrolled_window.el.hide();
943 _this.el.resize(w, 150);
945 _this.scrolled_window.el.show();
946 _this.el.resize(w, 800);
949 var rs = RooTicket.singleton();
950 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
951 var hd = uri.get_http_headers();
952 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
953 hd.append("Authorization", "Basic %s".printf(authCode));
955 this.el.load_request(uri);