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 );
53 var child_1 = new Xcls_Notebook22( _this );
55 this.el.add ( child_1.el );
58 this.el.delete_event.connect( (self, event) => {
63 this.el.response.connect( (self, response_id) => {
65 GLib.debug("got %d", (int) response_id);
70 // have they selected a ticket..
71 // make that the current active ticket?
72 // we really need to store locally what ticket is being worked on..
73 // in theory we could be working on multiple project and not merging..
74 // -- each repo would have their active ticket (only one per repo)
75 // -- so we could just store that in there
76 // -- initial load can check the contents of the ticket files on first scan.
79 if (response_id < 1) {
85 var ticket_id = _this.ticketsel.selectedTicketId();
87 if (this.repo != null) {
88 var bn = _this.name.el.get_text();
90 var res = this.repo.setActiveTicket(
91 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
94 // start the monitoring..
95 GitMonitor.gitmonitor.start();
101 this.running = false;
111 // user defined functions
112 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
114 // this.el.set_gravity(Gdk.Gravity.NORTH);
115 if (this.running) { // should not happen!!
116 GLib.error("new branch show called, when already being displayed?");
121 GitMonitor.gitmonitor.stop();
127 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
128 this.el.set_default_size( 500,200); // not sure why it grows..
129 GLib.debug("Loading tickets");
133 this.el.set_keep_above(true);
136 var curproj = RooProject.getProjectByRepo(this.repo);
137 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
139 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
140 _this.createbtn.updateState();
142 _this.ticketsel.el.get_child().get_style_context().remove_class("warning");
144 var name = RooTicket.singleton().usernameLocal();
145 var ticket = RooTicket.singleton().getById(tid);
146 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
148 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
150 _this.view.loadTicket(tid);
154 public class Xcls_Box2 : Object
157 private NewBranch _this;
163 public Xcls_Box2(NewBranch _owner )
166 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
170 // set gobject values
171 var child_0 = new Xcls_Table3( _this );
173 this.el.pack_start ( child_0.el , false,false,0 );
174 var child_1 = new Xcls_scrolled_window( _this );
176 this.el.add ( child_1.el );
179 // user defined functions
181 public class Xcls_Table3 : Object
184 private NewBranch _this;
190 public Xcls_Table3(NewBranch _owner )
193 this.el = new Gtk.Table( 5, 5, true );
197 // set gobject values
198 this.el.expand = false;
200 this.el.column_spacing = 4;
201 this.el.vexpand = false;
202 var child_0 = new Xcls_Label4( _this );
204 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
205 var child_1 = new Xcls_Label5( _this );
207 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
208 var child_2 = new Xcls_projectsel( _this );
210 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
211 var child_3 = new Xcls_ticketsel( _this );
213 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
214 var child_4 = new Xcls_Button12( _this );
216 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
217 var child_5 = new Xcls_Label13( _this );
219 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
220 var child_6 = new Xcls_name( _this );
222 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
223 var child_7 = new Xcls_createbtn( _this );
225 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
226 var child_8 = new Xcls_Box16( _this );
228 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
231 // user defined functions
233 public class Xcls_Label4 : Object
236 private NewBranch _this;
242 public Xcls_Label4(NewBranch _owner )
245 this.el = new Gtk.Label( "Project" );
249 // set gobject values
250 this.el.halign = Gtk.Align.START;
251 this.el.justify = Gtk.Justification.RIGHT;
252 this.el.visible = true;
255 // user defined functions
258 public class Xcls_Label5 : Object
261 private NewBranch _this;
267 public Xcls_Label5(NewBranch _owner )
270 this.el = new Gtk.Label( "Ticket" );
274 // set gobject values
275 this.el.halign = Gtk.Align.START;
276 this.el.visible = true;
279 // user defined functions
282 public class Xcls_projectsel : Object
284 public Gtk.ComboBox el;
285 private NewBranch _this;
292 public Xcls_projectsel(NewBranch _owner )
295 _this.projectsel = this;
296 this.el = new Gtk.ComboBox.with_entry();
299 this.loading = false;
301 // set gobject values
302 var child_0 = new Xcls_prcellrenderer( _this );
304 this.el.pack_start ( child_0.el , true );
305 var child_1 = new Xcls_prmodel( _this );
307 this.el.set_model ( child_1.el );
311 this.el.set_entry_text_column(1);
314 this.el.changed.connect( () => {
318 var project_id = this.selectedProjectId();
319 _this.dbmodel.loadTickets(project_id);
322 /*if (this.loading) {
325 var ticket_id = this.selectedTicketId();
327 var name = RooTicket.singleton().usernameLocal();
329 if (ticket_id == "" || ticket_id == null) {
331 var dt = new DateTime.now_local();
332 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
337 var ticket = RooTicket.singleton().getById(ticket_id);
339 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
341 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
346 // user defined functions
347 public string selectedProjectId () {
352 this.el.get_active_iter (out iter);
353 _this.prmodel.el.get_value (iter, 0, out val1);
356 return (string) val1;
363 public class Xcls_prcellrenderer : Object
365 public Gtk.CellRendererText el;
366 private NewBranch _this;
372 public Xcls_prcellrenderer(NewBranch _owner )
375 _this.prcellrenderer = this;
376 this.el = new Gtk.CellRendererText();
380 // set gobject values
383 // user defined functions
386 public class Xcls_prmodel : Object
388 public Gtk.ListStore el;
389 private NewBranch _this;
395 public Xcls_prmodel(NewBranch _owner )
398 _this.prmodel = this;
399 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
403 // set gobject values
406 // user defined functions
407 public void loadProjects (string id) {
411 _this.projectsel.loading = true;
420 el.set_value(iter, 0, "");
421 el.set_value(iter, 1, "-- select a project --");
423 _this.projectsel.el.set_active_iter(iter);
426 foreach(var project in RooProject.projects()) {
430 el.set_value(iter, 0, project.id);
431 el.set_value(iter, 1, project.name );
432 if (id == project.id) {
433 _this.projectsel.el.set_active_iter(iter);
438 _this.projectsel.loading = false;
439 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
445 public class Xcls_ticketsel : Object
447 public Gtk.ComboBox el;
448 private NewBranch _this;
455 public Xcls_ticketsel(NewBranch _owner )
458 _this.ticketsel = this;
459 this.el = new Gtk.ComboBox.with_entry();
462 this.loading = false;
464 // set gobject values
465 var child_0 = new Xcls_dbcellrenderer( _this );
467 this.el.pack_start ( child_0.el , true );
468 var child_1 = new Xcls_dbmodel( _this );
470 this.el.set_model ( child_1.el );
474 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
475 this.el.set_entry_text_column(1);
476 this.el.get_child().set_sensitive(false);
479 this.el.changed.connect( () => {
483 var ticket_id = this.selectedTicketId();
485 var name = RooTicket.singleton().usernameLocal();
487 this.el.get_child().get_style_context().remove_class("warning");
488 if (ticket_id == "" || ticket_id == null) {
490 var dt = new DateTime.now_local();
491 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
492 _this.view.loadTicket("");
494 this.el.get_child().get_style_context().add_class("warning");
495 _this.createbtn.updateState();
500 var ticket = RooTicket.singleton().getById(ticket_id);
502 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
503 _this.scrolled_window.el.show();
505 _this.view.loadTicket(ticket.id);
506 _this.createbtn.updateState();
508 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
512 // user defined functions
513 public string selectedTicketId () {
518 this.el.get_active_iter (out iter);
519 _this.dbmodel.el.get_value (iter, 0, out val1);
522 return (string) val1;
529 public class Xcls_dbcellrenderer : Object
531 public Gtk.CellRendererText el;
532 private NewBranch _this;
538 public Xcls_dbcellrenderer(NewBranch _owner )
541 _this.dbcellrenderer = this;
542 this.el = new Gtk.CellRendererText();
546 // set gobject values
549 // user defined functions
552 public class Xcls_dbmodel : Object
554 public Gtk.ListStore el;
555 private NewBranch _this;
561 public Xcls_dbmodel(NewBranch _owner )
564 _this.dbmodel = this;
565 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
569 // set gobject values
572 // user defined functions
573 public void loadTickets (string project_id , string tid = "") {
577 // fixme .. get project id from selection..
579 RooTicket.singleton().loadTickets(
581 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
582 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
585 _this.ticketsel.loading = true;
594 el.set_value(iter, 0, "");
595 el.set_value(iter, 1, "-- select a ticket --");
597 _this.ticketsel.el.set_active_iter(iter);
598 var tickets = RooTicket.singleton().tickets;
599 foreach(var ticket in tickets) {
603 el.set_value(iter, 0, ticket.id);
604 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
606 if (ticket.id == tid) {
607 _this.ticketsel.el.set_active_iter(iter);
612 _this.ticketsel.loading = false;
613 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
619 public class Xcls_Button12 : Object
621 public Gtk.Button el;
622 private NewBranch _this;
628 public Xcls_Button12(NewBranch _owner )
631 this.el = new Gtk.Button();
635 // set gobject values
636 this.el.expand = false;
637 this.el.label = "New Ticket";
640 this.el.clicked.connect( () => {
641 _this.el.response(-1);
642 Ticket.singleton().show(_this.repo);
647 // user defined functions
650 public class Xcls_Label13 : Object
653 private NewBranch _this;
659 public Xcls_Label13(NewBranch _owner )
662 this.el = new Gtk.Label( "Use this as branch name" );
666 // set gobject values
667 this.el.halign = Gtk.Align.START;
668 this.el.justify = Gtk.Justification.RIGHT;
669 this.el.xalign = 0.900000f;
672 // user defined functions
675 public class Xcls_name : Object
678 private NewBranch _this;
684 public Xcls_name(NewBranch _owner )
688 this.el = new Gtk.Entry();
692 // set gobject values
693 this.el.visible = true;
696 // user defined functions
699 public class Xcls_createbtn : Object
701 public Gtk.Button el;
702 private NewBranch _this;
708 public Xcls_createbtn(NewBranch _owner )
711 _this.createbtn = this;
712 this.el = new Gtk.Button();
716 // set gobject values
717 this.el.label = "Create Branch";
722 this.el.get_style_context().add_class("suggested-action");
726 this.el.clicked.connect( () => {
728 GLib.debug("fire response = 1");
730 var ticket_id = _this.ticketsel.selectedTicketId();
732 if (ticket_id == "") {
733 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
737 _this.el.response(1);
741 // user defined functions
742 public void updateState () {
744 var ticket_id = _this.ticketsel.selectedTicketId();
746 if (ticket_id == "") {
747 this.el.set_sensitive(false);
751 this.el.set_sensitive(true);
756 public class Xcls_Box16 : Object
759 private NewBranch _this;
765 public Xcls_Box16(NewBranch _owner )
768 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
772 // set gobject values
773 var child_0 = new Xcls_btn_not_me( _this );
775 this.el.add ( child_0.el );
776 var child_1 = new Xcls_btn_closed( _this );
778 this.el.add ( child_1.el );
779 var child_2 = new Xcls_Label19( _this );
781 this.el.add ( child_2.el );
784 // user defined functions
786 public class Xcls_btn_not_me : Object
788 public Gtk.CheckButton el;
789 private NewBranch _this;
795 public Xcls_btn_not_me(NewBranch _owner )
798 _this.btn_not_me = this;
799 this.el = new Gtk.CheckButton();
803 // set gobject values
804 this.el.label = "Show tickets not assigned to me";
807 this.el.toggled.connect( () => {
808 var project_id = _this.projectsel.selectedProjectId();
809 _this.dbmodel.loadTickets(project_id);
813 // user defined functions
816 public class Xcls_btn_closed : Object
818 public Gtk.CheckButton el;
819 private NewBranch _this;
825 public Xcls_btn_closed(NewBranch _owner )
828 _this.btn_closed = this;
829 this.el = new Gtk.CheckButton();
833 // set gobject values
834 this.el.label = "Show closed Tickets";
837 this.el.toggled.connect( () => {
838 var project_id = _this.projectsel.selectedProjectId();
839 _this.dbmodel.loadTickets(project_id);
844 // user defined functions
847 public class Xcls_Label19 : Object
850 private NewBranch _this;
856 public Xcls_Label19(NewBranch _owner )
859 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
863 // set gobject values
864 this.el.halign = Gtk.Align.END;
865 this.el.hexpand = true;
866 this.el.use_markup = true;
869 this.el.activate_link.connect( (uri) => {
870 if (uri == "refresh") {
872 var curproj = RooProject.getProjectByRepo(_this.repo);
873 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
875 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
881 // user defined functions
886 public class Xcls_scrolled_window : Object
888 public Gtk.ScrolledWindow el;
889 private NewBranch _this;
895 public Xcls_scrolled_window(NewBranch _owner )
898 _this.scrolled_window = this;
899 this.el = new Gtk.ScrolledWindow( null, null );
903 // set gobject values
904 this.el.height_request = 500;
905 this.el.vexpand = true;
906 var child_0 = new Xcls_view( _this );
908 this.el.add ( child_0.el );
913 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
917 // user defined functions
919 public class Xcls_view : Object
921 public WebKit.WebView el;
922 private NewBranch _this;
928 public Xcls_view(NewBranch _owner )
932 this.el = new WebKit.WebView();
936 // set gobject values
939 // user defined functions
940 public void loadTicket (string tid) {
942 _this.el.get_size(out w, out h);
945 _this.scrolled_window.el.hide();
946 _this.el.resize(w, 150);
948 _this.scrolled_window.el.show();
949 _this.el.resize(w, 800);
952 var rs = RooTicket.singleton();
953 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
954 var hd = uri.get_http_headers();
955 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
956 hd.append("Authorization", "Basic %s".printf(authCode));
958 this.el.load_request(uri);
964 public class Xcls_Notebook22 : Object
966 public Gtk.Notebook el;
967 private NewBranch _this;
973 public Xcls_Notebook22(NewBranch _owner )
976 this.el = new Gtk.Notebook();
980 // set gobject values
981 this.el.vexpand = true;
982 var child_0 = new Xcls_Label23( _this );
984 this.el.get_path_for_child ( child_0.el );
987 // user defined functions
989 public class Xcls_Label23 : Object
992 private NewBranch _this;
998 public Xcls_Label23(NewBranch _owner )
1001 this.el = new Gtk.Label( null );
1005 // set gobject values
1008 // user defined functions