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.createbtn.updateState();
138 _this.ticketsel.el.get_child().get_style_context().remove_class("warning");
140 var name = RooTicket.singleton().usernameLocal();
141 var ticket = RooTicket.singleton().getById(tid);
142 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
144 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
146 _this.view.loadTicket(tid);
150 public class Xcls_Box2 : Object
153 private NewBranch _this;
159 public Xcls_Box2(NewBranch _owner )
162 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
166 // set gobject values
167 var child_0 = new Xcls_Table3( _this );
169 this.el.pack_start ( child_0.el , false,false,0 );
170 var child_1 = new Xcls_scrolled_window( _this );
172 this.el.add ( child_1.el );
175 // user defined functions
177 public class Xcls_Table3 : Object
180 private NewBranch _this;
186 public Xcls_Table3(NewBranch _owner )
189 this.el = new Gtk.Table( 5, 5, true );
193 // set gobject values
194 this.el.expand = false;
196 this.el.column_spacing = 4;
197 this.el.vexpand = false;
198 var child_0 = new Xcls_Label4( _this );
200 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
201 var child_1 = new Xcls_Label5( _this );
203 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
204 var child_2 = new Xcls_projectsel( _this );
206 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
207 var child_3 = new Xcls_ticketsel( _this );
209 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
210 var child_4 = new Xcls_Button12( _this );
212 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
213 var child_5 = new Xcls_Label13( _this );
215 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
216 var child_6 = new Xcls_name( _this );
218 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
219 var child_7 = new Xcls_Button15( _this );
221 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
222 var child_8 = new Xcls_Box16( _this );
224 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
227 // user defined functions
229 public class Xcls_Label4 : Object
232 private NewBranch _this;
238 public Xcls_Label4(NewBranch _owner )
241 this.el = new Gtk.Label( "Project" );
245 // set gobject values
246 this.el.halign = Gtk.Align.START;
247 this.el.justify = Gtk.Justification.RIGHT;
248 this.el.visible = true;
251 // user defined functions
254 public class Xcls_Label5 : Object
257 private NewBranch _this;
263 public Xcls_Label5(NewBranch _owner )
266 this.el = new Gtk.Label( "Ticket" );
270 // set gobject values
271 this.el.halign = Gtk.Align.START;
272 this.el.visible = true;
275 // user defined functions
278 public class Xcls_projectsel : Object
280 public Gtk.ComboBox el;
281 private NewBranch _this;
288 public Xcls_projectsel(NewBranch _owner )
291 _this.projectsel = this;
292 this.el = new Gtk.ComboBox.with_entry();
295 this.loading = false;
297 // set gobject values
298 var child_0 = new Xcls_prcellrenderer( _this );
300 this.el.pack_start ( child_0.el , true );
301 var child_1 = new Xcls_prmodel( _this );
303 this.el.set_model ( child_1.el );
307 this.el.set_entry_text_column(1);
310 this.el.changed.connect( () => {
314 var project_id = this.selectedProjectId();
315 _this.dbmodel.loadTickets(project_id);
318 /*if (this.loading) {
321 var ticket_id = this.selectedTicketId();
323 var name = RooTicket.singleton().usernameLocal();
325 if (ticket_id == "" || ticket_id == null) {
327 var dt = new DateTime.now_local();
328 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
333 var ticket = RooTicket.singleton().getById(ticket_id);
335 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
337 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
342 // user defined functions
343 public string selectedProjectId () {
348 this.el.get_active_iter (out iter);
349 _this.prmodel.el.get_value (iter, 0, out val1);
352 return (string) val1;
359 public class Xcls_prcellrenderer : Object
361 public Gtk.CellRendererText el;
362 private NewBranch _this;
368 public Xcls_prcellrenderer(NewBranch _owner )
371 _this.prcellrenderer = this;
372 this.el = new Gtk.CellRendererText();
376 // set gobject values
379 // user defined functions
382 public class Xcls_prmodel : Object
384 public Gtk.ListStore el;
385 private NewBranch _this;
391 public Xcls_prmodel(NewBranch _owner )
394 _this.prmodel = this;
395 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
399 // set gobject values
402 // user defined functions
403 public void loadProjects (string id) {
407 _this.projectsel.loading = true;
416 el.set_value(iter, 0, "");
417 el.set_value(iter, 1, "-- select a project --");
419 _this.projectsel.el.set_active_iter(iter);
422 foreach(var project in RooProject.projects()) {
426 el.set_value(iter, 0, project.id);
427 el.set_value(iter, 1, project.name );
428 if (id == project.id) {
429 _this.projectsel.el.set_active_iter(iter);
434 _this.projectsel.loading = false;
435 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
441 public class Xcls_ticketsel : Object
443 public Gtk.ComboBox el;
444 private NewBranch _this;
451 public Xcls_ticketsel(NewBranch _owner )
454 _this.ticketsel = this;
455 this.el = new Gtk.ComboBox.with_entry();
458 this.loading = false;
460 // set gobject values
461 var child_0 = new Xcls_dbcellrenderer( _this );
463 this.el.pack_start ( child_0.el , true );
464 var child_1 = new Xcls_dbmodel( _this );
466 this.el.set_model ( child_1.el );
470 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
471 this.el.set_entry_text_column(1);
472 this.el.get_child().set_sensitive(false);
475 this.el.changed.connect( () => {
479 var ticket_id = this.selectedTicketId();
481 var name = RooTicket.singleton().usernameLocal();
483 this.el.get_child().get_style_context().remove_class("warning");
484 if (ticket_id == "" || ticket_id == null) {
486 var dt = new DateTime.now_local();
487 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
488 _this.view.loadTicket("");
490 this.el.get_child().get_style_context().add_class("warning");
496 var ticket = RooTicket.singleton().getById(ticket_id);
498 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
499 _this.scrolled_window.el.show();
501 _this.view.loadTicket(ticket.id);
502 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
506 // user defined functions
507 public string selectedTicketId () {
512 this.el.get_active_iter (out iter);
513 _this.dbmodel.el.get_value (iter, 0, out val1);
516 return (string) val1;
523 public class Xcls_dbcellrenderer : Object
525 public Gtk.CellRendererText el;
526 private NewBranch _this;
532 public Xcls_dbcellrenderer(NewBranch _owner )
535 _this.dbcellrenderer = this;
536 this.el = new Gtk.CellRendererText();
540 // set gobject values
543 // user defined functions
546 public class Xcls_dbmodel : Object
548 public Gtk.ListStore el;
549 private NewBranch _this;
555 public Xcls_dbmodel(NewBranch _owner )
558 _this.dbmodel = this;
559 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
563 // set gobject values
566 // user defined functions
567 public void loadTickets (string project_id , string tid = "") {
571 // fixme .. get project id from selection..
573 RooTicket.singleton().loadTickets(
575 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
576 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
579 _this.ticketsel.loading = true;
588 el.set_value(iter, 0, "");
589 el.set_value(iter, 1, "-- select a ticket --");
591 _this.ticketsel.el.set_active_iter(iter);
592 var tickets = RooTicket.singleton().tickets;
593 foreach(var ticket in tickets) {
597 el.set_value(iter, 0, ticket.id);
598 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
600 if (ticket.id == tid) {
601 _this.ticketsel.el.set_active_iter(iter);
606 _this.ticketsel.loading = false;
607 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
613 public class Xcls_Button12 : Object
615 public Gtk.Button el;
616 private NewBranch _this;
622 public Xcls_Button12(NewBranch _owner )
625 this.el = new Gtk.Button();
629 // set gobject values
630 this.el.expand = false;
631 this.el.label = "New Ticket";
634 this.el.clicked.connect( () => {
635 _this.el.response(-1);
636 Ticket.singleton().show(_this.repo);
641 // user defined functions
644 public class Xcls_Label13 : Object
647 private NewBranch _this;
653 public Xcls_Label13(NewBranch _owner )
656 this.el = new Gtk.Label( "Use this as branch name" );
660 // set gobject values
661 this.el.halign = Gtk.Align.START;
662 this.el.justify = Gtk.Justification.RIGHT;
663 this.el.xalign = 0.900000f;
666 // user defined functions
669 public class Xcls_name : Object
672 private NewBranch _this;
678 public Xcls_name(NewBranch _owner )
682 this.el = new Gtk.Entry();
686 // set gobject values
687 this.el.visible = true;
690 // user defined functions
693 public class Xcls_Button15 : Object
695 public Gtk.Button el;
696 private NewBranch _this;
702 public Xcls_Button15(NewBranch _owner )
705 this.el = new Gtk.Button();
709 // set gobject values
710 this.el.label = "Create Branch";
715 this.el.get_style_context().add_class("suggested-action");
719 this.el.clicked.connect( () => {
721 GLib.debug("fire response = 1");
723 var ticket_id = _this.ticketsel.selectedTicketId();
725 if (ticket_id == "") {
726 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
730 _this.el.response(1);
734 // user defined functions
737 public class Xcls_Box16 : Object
740 private NewBranch _this;
746 public Xcls_Box16(NewBranch _owner )
749 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
753 // set gobject values
754 var child_0 = new Xcls_btn_not_me( _this );
756 this.el.add ( child_0.el );
757 var child_1 = new Xcls_btn_closed( _this );
759 this.el.add ( child_1.el );
760 var child_2 = new Xcls_Label19( _this );
762 this.el.add ( child_2.el );
765 // user defined functions
767 public class Xcls_btn_not_me : Object
769 public Gtk.CheckButton el;
770 private NewBranch _this;
776 public Xcls_btn_not_me(NewBranch _owner )
779 _this.btn_not_me = this;
780 this.el = new Gtk.CheckButton();
784 // set gobject values
785 this.el.label = "Show tickets not assigned to me";
788 this.el.toggled.connect( () => {
789 var project_id = _this.projectsel.selectedProjectId();
790 _this.dbmodel.loadTickets(project_id);
794 // user defined functions
797 public class Xcls_btn_closed : Object
799 public Gtk.CheckButton el;
800 private NewBranch _this;
806 public Xcls_btn_closed(NewBranch _owner )
809 _this.btn_closed = this;
810 this.el = new Gtk.CheckButton();
814 // set gobject values
815 this.el.label = "Show closed Tickets";
818 this.el.toggled.connect( () => {
819 var project_id = _this.projectsel.selectedProjectId();
820 _this.dbmodel.loadTickets(project_id);
825 // user defined functions
828 public class Xcls_Label19 : Object
831 private NewBranch _this;
837 public Xcls_Label19(NewBranch _owner )
840 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
844 // set gobject values
845 this.el.halign = Gtk.Align.END;
846 this.el.hexpand = true;
847 this.el.use_markup = true;
850 this.el.activate_link.connect( (uri) => {
851 if (uri == "refresh") {
853 var curproj = RooProject.getProjectByRepo(_this.repo);
854 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
856 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
862 // user defined functions
867 public class Xcls_scrolled_window : Object
869 public Gtk.ScrolledWindow el;
870 private NewBranch _this;
876 public Xcls_scrolled_window(NewBranch _owner )
879 _this.scrolled_window = this;
880 this.el = new Gtk.ScrolledWindow( null, null );
884 // set gobject values
885 this.el.height_request = 500;
886 this.el.vexpand = true;
887 var child_0 = new Xcls_view( _this );
889 this.el.add ( child_0.el );
894 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
898 // user defined functions
900 public class Xcls_view : Object
902 public WebKit.WebView el;
903 private NewBranch _this;
909 public Xcls_view(NewBranch _owner )
913 this.el = new WebKit.WebView();
917 // set gobject values
920 // user defined functions
921 public void loadTicket (string tid) {
923 _this.el.get_size(out w, out h);
926 _this.scrolled_window.el.hide();
927 _this.el.resize(w, 150);
929 _this.scrolled_window.el.show();
930 _this.el.resize(w, 800);
933 var rs = RooTicket.singleton();
934 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
935 var hd = uri.get_http_headers();
936 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
937 hd.append("Authorization", "Basic %s".printf(authCode));
939 this.el.load_request(uri);