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();
81 if (ticket_id == "") {
82 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
86 if (this.repo != null) {
87 var bn = _this.name.el.get_text();
89 var res = this.repo.setActiveTicket(
90 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
93 // start the monitoring..
94 GitMonitor.gitmonitor.start();
100 this.running = false;
110 // user defined functions
111 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
113 // this.el.set_gravity(Gdk.Gravity.NORTH);
114 if (this.running) { // should not happen!!
115 GLib.error("new branch show called, when already being displayed?");
120 GitMonitor.gitmonitor.stop();
126 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
127 this.el.set_default_size( 500,200); // not sure why it grows..
128 GLib.debug("Loading tickets");
132 this.el.set_keep_above(true);
135 var curproj = RooProject.getProjectByRepo(this.repo);
136 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
138 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
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_Button15( _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");
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 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
507 // user defined functions
508 public string selectedTicketId () {
513 this.el.get_active_iter (out iter);
514 _this.dbmodel.el.get_value (iter, 0, out val1);
517 return (string) val1;
524 public class Xcls_dbcellrenderer : Object
526 public Gtk.CellRendererText el;
527 private NewBranch _this;
533 public Xcls_dbcellrenderer(NewBranch _owner )
536 _this.dbcellrenderer = this;
537 this.el = new Gtk.CellRendererText();
541 // set gobject values
544 // user defined functions
547 public class Xcls_dbmodel : Object
549 public Gtk.ListStore el;
550 private NewBranch _this;
556 public Xcls_dbmodel(NewBranch _owner )
559 _this.dbmodel = this;
560 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
564 // set gobject values
567 // user defined functions
568 public void loadTickets (string project_id , string tid = "") {
572 // fixme .. get project id from selection..
574 RooTicket.singleton().loadTickets(
576 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
577 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
580 _this.ticketsel.loading = true;
589 el.set_value(iter, 0, "");
590 el.set_value(iter, 1, "-- select a ticket --");
592 _this.ticketsel.el.set_active_iter(iter);
593 var tickets = RooTicket.singleton().tickets;
594 foreach(var ticket in tickets) {
598 el.set_value(iter, 0, ticket.id);
599 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
601 if (ticket.id == tid) {
602 _this.ticketsel.el.set_active_iter(iter);
607 _this.ticketsel.loading = false;
608 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
614 public class Xcls_Button12 : Object
616 public Gtk.Button el;
617 private NewBranch _this;
623 public Xcls_Button12(NewBranch _owner )
626 this.el = new Gtk.Button();
630 // set gobject values
631 this.el.expand = false;
632 this.el.label = "New Ticket";
635 this.el.clicked.connect( () => {
636 _this.el.response(-1);
637 Ticket.singleton().show(_this.repo);
642 // user defined functions
645 public class Xcls_Label13 : Object
648 private NewBranch _this;
654 public Xcls_Label13(NewBranch _owner )
657 this.el = new Gtk.Label( "Use this as branch name" );
661 // set gobject values
662 this.el.halign = Gtk.Align.START;
663 this.el.justify = Gtk.Justification.RIGHT;
664 this.el.xalign = 0.900000f;
667 // user defined functions
670 public class Xcls_name : Object
673 private NewBranch _this;
679 public Xcls_name(NewBranch _owner )
683 this.el = new Gtk.Entry();
687 // set gobject values
688 this.el.visible = true;
691 // user defined functions
694 public class Xcls_Button15 : Object
696 public Gtk.Button el;
697 private NewBranch _this;
703 public Xcls_Button15(NewBranch _owner )
706 this.el = new Gtk.Button();
710 // set gobject values
711 this.el.label = "Create Branch";
716 this.el.get_style_context().add_class("suggested-action");
720 this.el.clicked.connect( () => {
721 GLib.debug("fire response = 1");
722 _this.el.response(1);
726 // user defined functions
729 public class Xcls_Box16 : Object
732 private NewBranch _this;
738 public Xcls_Box16(NewBranch _owner )
741 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
745 // set gobject values
746 var child_0 = new Xcls_btn_not_me( _this );
748 this.el.add ( child_0.el );
749 var child_1 = new Xcls_btn_closed( _this );
751 this.el.add ( child_1.el );
752 var child_2 = new Xcls_Label19( _this );
754 this.el.add ( child_2.el );
757 // user defined functions
759 public class Xcls_btn_not_me : Object
761 public Gtk.CheckButton el;
762 private NewBranch _this;
768 public Xcls_btn_not_me(NewBranch _owner )
771 _this.btn_not_me = this;
772 this.el = new Gtk.CheckButton();
776 // set gobject values
777 this.el.label = "Show tickets not assigned to me";
780 this.el.toggled.connect( () => {
781 var project_id = _this.projectsel.selectedProjectId();
782 _this.dbmodel.loadTickets(project_id);
786 // user defined functions
789 public class Xcls_btn_closed : Object
791 public Gtk.CheckButton el;
792 private NewBranch _this;
798 public Xcls_btn_closed(NewBranch _owner )
801 _this.btn_closed = this;
802 this.el = new Gtk.CheckButton();
806 // set gobject values
807 this.el.label = "Show closed Tickets";
810 this.el.toggled.connect( () => {
811 var project_id = _this.projectsel.selectedProjectId();
812 _this.dbmodel.loadTickets(project_id);
817 // user defined functions
820 public class Xcls_Label19 : Object
823 private NewBranch _this;
829 public Xcls_Label19(NewBranch _owner )
832 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
836 // set gobject values
837 this.el.halign = Gtk.Align.END;
838 this.el.hexpand = true;
839 this.el.use_markup = true;
842 this.el.activate_link.connect( (uri) => {
843 if (uri == "refresh") {
845 var curproj = RooProject.getProjectByRepo(_this.repo);
846 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
848 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
854 // user defined functions
859 public class Xcls_scrolled_window : Object
861 public Gtk.ScrolledWindow el;
862 private NewBranch _this;
868 public Xcls_scrolled_window(NewBranch _owner )
871 _this.scrolled_window = this;
872 this.el = new Gtk.ScrolledWindow( null, null );
876 // set gobject values
877 this.el.height_request = 500;
878 this.el.vexpand = true;
879 var child_0 = new Xcls_view( _this );
881 this.el.add ( child_0.el );
886 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
890 // user defined functions
892 public class Xcls_view : Object
894 public WebKit.WebView el;
895 private NewBranch _this;
901 public Xcls_view(NewBranch _owner )
905 this.el = new WebKit.WebView();
909 // set gobject values
912 // user defined functions
913 public void loadTicket (string tid) {
915 _this.el.get_size(out w, out h);
918 _this.scrolled_window.el.hide();
919 _this.el.resize(w, 150);
921 _this.scrolled_window.el.show();
922 _this.el.resize(w, 800);
925 var rs = RooTicket.singleton();
926 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
927 var hd = uri.get_http_headers();
928 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
929 hd.append("Authorization", "Basic %s".printf(authCode));
931 this.el.load_request(uri);