From 4879313d9a4fffaa84198dc31c5aba384614bc15 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Tue, 18 Dec 2018 13:00:34 +0800 Subject: [PATCH] Fix #5613 - gitlive - view tickets --- Makefile.am | 4 +- NewBranch.bjs | 27 +++++++++++-- NewBranch.vala | 104 ++++++++++++++++++++++++++++++++++++++++++++---- config1.builder | 3 +- configure.ac | 3 +- 5 files changed, 126 insertions(+), 15 deletions(-) diff --git a/Makefile.am b/Makefile.am index 3556ac92..1395b0d5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,9 @@ Gitlive_PKGS = \ --pkg libcanberra \ --pkg libsoup-2.4 \ --pkg json-glib-1.0 \ - --pkg gtksourceview-3.0 + --pkg gtksourceview-3.0 \ + --pkg webkit2gtk-4.0 + Gitlive_SOURCES = \ Gitlive.vala \ diff --git a/NewBranch.bjs b/NewBranch.bjs index 3874f1cb..a5b845f2 100644 --- a/NewBranch.bjs +++ b/NewBranch.bjs @@ -17,17 +17,18 @@ "title" : "Create a working branch ", "xtype" : "Dialog", "# GitRepo? repo" : "null", - "| void show" : "( GitRepo repo, Gee.ArrayList queue, string tid = \"\" ) \n{\n // this.el.set_gravity(Gdk.Gravity.NORTH);\n if (this.running) { // should not happen!!\n \tGLib.error(\"new branch show called, when already being displayed?\");\n\t}\n\tthis.queue = queue;\n\t\n\tthis.running = true;\n\tGitMonitor.gitmonitor.stop();\n\t\n this.repo = repo;\n \n \n \n\tthis.el.move((Gdk.Screen.width() / 2)- 250 ,0);\n\tthis.el.set_default_size( 500,200); // not sure why it grows..\n GLib.debug(\"Loading tickets\"); \n \n\n this.el.show_all();\n this.el.set_keep_above(true);\n \n \n var curproj = RooTicket.singleton().getProjectByRepo(this.repo);\n _this.prmodel.loadProjects(curproj == null ? \"\" : curproj.id);\n \n \t_this.dbmodel.loadTickets(curproj == null ? \"\": curproj.id, tid);\n \tif (tid != \"\") {\n\t \tvar name = RooTicket.singleton().usernameLocal();\n \t\tvar ticket = RooTicket.singleton().getById(tid);\n\t\t_this.name.el.set_text(\"wip_%s_T%s_%s\".printf(name,ticket.id, ticket.summaryToBranchName()));\n\t}\n\n \tthis.el.run();\n\n}", - "default_height" : 200, + "| void show" : "( GitRepo repo, Gee.ArrayList queue, string tid = \"\" ) \n{\n // this.el.set_gravity(Gdk.Gravity.NORTH);\n if (this.running) { // should not happen!!\n \tGLib.error(\"new branch show called, when already being displayed?\");\n\t}\n\tthis.queue = queue;\n\t\n\tthis.running = true;\n\tGitMonitor.gitmonitor.stop();\n\t\n this.repo = repo;\n \n \n \n\tthis.el.move((Gdk.Screen.width() / 2)- 250 ,0);\n\tthis.el.set_default_size( 500,200); // not sure why it grows..\n GLib.debug(\"Loading tickets\"); \n \n\n this.el.show_all();\n this.el.set_keep_above(true);\n \n \n var curproj = RooTicket.singleton().getProjectByRepo(this.repo);\n _this.prmodel.loadProjects(curproj == null ? \"\" : curproj.id);\n \n \t_this.dbmodel.loadTickets(curproj == null ? \"\": curproj.id, tid);\n\n \tif (tid != \"\") {\n\t \tvar name = RooTicket.singleton().usernameLocal();\n \t\tvar ticket = RooTicket.singleton().getById(tid);\n\t\t_this.name.el.set_text(\"wip_%s_T%s_%s\".printf(name,ticket.id, ticket.summaryToBranchName()));\n\n\n\t}\n _this.view.loadTicket(tid);\n \tthis.el.run();\n\n}", + "default_height" : 500, "$ xns" : "Gtk", "# bool running" : false, "# Gee.ArrayList queue" : "null", "bool modal" : true, "items" : [ { - "xtype" : "VBox", + "xtype" : "Box", "$ pack" : "get_content_area().add", "$ xns" : "Gtk", + "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL", "items" : [ { "bool homogeneous" : true, @@ -92,7 +93,7 @@ }, { "listeners" : { - "changed" : "() => {\n\tif (this.loading) {\n\t\treturn;\n\t}\n\tvar ticket_id = this.selectedTicketId();\n\t\n\tvar name = RooTicket.singleton().usernameLocal();\n\t\n\tif (ticket_id == \"\" || ticket_id == null) {\n\t\n\t\tvar dt = new DateTime.now_local();\n\t\t_this.name.el.set_text(\"wip_%s_%s\".printf(name,dt.format(\"%Y_%b_%d\")));\n\t\treturn;\n\t}\n\t\n\t\n\tvar ticket = RooTicket.singleton().getById(ticket_id);\n \n\t_this.name.el.set_text(\"wip_%s_T%s_%s\".printf(name,ticket.id, ticket.summaryToBranchName()));\n\t\n\t//GLib.debug (//\"Selection: %s, %s\\n\", (string) val1, (string) val2);\n}" + "changed" : "() => {\n\tif (this.loading) {\n\t\treturn;\n\t}\n\tvar ticket_id = this.selectedTicketId();\n\t\n\tvar name = RooTicket.singleton().usernameLocal();\n\t\n\tif (ticket_id == \"\" || ticket_id == null) {\n\t\n\t\tvar dt = new DateTime.now_local();\n\t\t_this.name.el.set_text(\"wip_%s_%s\".printf(name,dt.format(\"%Y_%b_%d\")));\n\t\t_this.view.loadTicket(\"\");\t\t\n\t\treturn;\n\t}\n\t\n\t\n\tvar ticket = RooTicket.singleton().getById(ticket_id);\n \n\t_this.name.el.set_text(\"wip_%s_T%s_%s\".printf(name,ticket.id, ticket.summaryToBranchName()));\n\t_this.scrolled_window.el.show();\n\t \n\t_this.view.loadTicket(ticket.id);\n\t//GLib.debug (//\"Selection: %s, %s\\n\", (string) val1, (string) val2);\n}" }, "* ctor" : "new Gtk.ComboBox.with_entry()", "id" : "ticketsel", @@ -198,6 +199,24 @@ ] } ] + }, + { + "int height_request" : 500, + "id" : "scrolled_window", + "* init" : "{\n\tthis.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);\n}\n", + "* pack" : "add", + "xtype" : "ScrolledWindow", + "$ xns" : "Gtk", + "bool vexpand" : true, + "items" : [ + { + "id" : "view", + "* pack" : "add", + "xtype" : "WebView", + "$ xns" : "WebKit", + "| void loadTicket" : "(string tid) {\n\tint h,w;\n\t_this.el.get_size(out w, out h);\n\t\n\tif (tid == \"\") {\n\t\t_this.scrolled_window.el.hide();\n\t\t_this.el.resize(w, 150);\n\t} else {\n\t\t_this.scrolled_window.el.show();\n\t\t_this.el.resize(w, 800);\n\t}\n\t\n\tvar rs = RooTicket.singleton();\t\t\n\tvar uri = new WebKit.URIRequest(\"https://roojs.com/admin.php/MTrack/View/\" + tid);\n\tvar hd = uri.get_http_headers();\n\tvar authCode = Base64.encode (\"%s:%s\".printf(rs.username, rs.password).data);\n\thd.append(\"Authorization\", \"Basic %s\".printf(authCode));\n\t\n\t this.el.load_request(uri);\n}\n" + } + ] } ] } diff --git a/NewBranch.vala b/NewBranch.vala index c9bff826..9183007d 100644 --- a/NewBranch.vala +++ b/NewBranch.vala @@ -21,6 +21,8 @@ public class NewBranch : Object public Xcls_name name; public Xcls_btn_not_me btn_not_me; public Xcls_btn_closed btn_closed; + public Xcls_scrolled_window scrolled_window; + public Xcls_view view; // my vars (def) public GitRepo? repo; @@ -40,11 +42,11 @@ public class NewBranch : Object // set gobject values this.el.title = "Create a working branch "; - this.el.default_height = 200; + this.el.default_height = 500; this.el.default_width = 500; this.el.deletable = true; this.el.modal = true; - var child_0 = new Xcls_VBox2( _this ); + var child_0 = new Xcls_Box2( _this ); child_0.ref(); this.el.get_content_area().add ( child_0.el ); @@ -125,28 +127,31 @@ public class NewBranch : Object _this.prmodel.loadProjects(curproj == null ? "" : curproj.id); _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid); + if (tid != "") { var name = RooTicket.singleton().usernameLocal(); var ticket = RooTicket.singleton().getById(tid); _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName())); - } + + } + _this.view.loadTicket(tid); this.el.run(); } - public class Xcls_VBox2 : Object + public class Xcls_Box2 : Object { - public Gtk.VBox el; + public Gtk.Box el; private NewBranch _this; // my vars (def) // ctor - public Xcls_VBox2(NewBranch _owner ) + public Xcls_Box2(NewBranch _owner ) { _this = _owner; - this.el = new Gtk.VBox( true, 0 ); + this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 ); // my vars (dec) @@ -154,6 +159,9 @@ public class NewBranch : Object var child_0 = new Xcls_Table3( _this ); child_0.ref(); this.el.pack_start ( child_0.el , false,false,0 ); + var child_1 = new Xcls_scrolled_window( _this ); + child_1.ref(); + this.el.add ( child_1.el ); } // user defined functions @@ -468,6 +476,7 @@ public class NewBranch : Object var dt = new DateTime.now_local(); _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d"))); + _this.view.loadTicket(""); return; } @@ -475,7 +484,9 @@ public class NewBranch : Object var ticket = RooTicket.singleton().getById(ticket_id); _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName())); - + _this.scrolled_window.el.show(); + + _this.view.loadTicket(ticket.id); //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2); }); } @@ -831,5 +842,82 @@ public class NewBranch : Object + public class Xcls_scrolled_window : Object + { + public Gtk.ScrolledWindow el; + private NewBranch _this; + + + // my vars (def) + + // ctor + public Xcls_scrolled_window(NewBranch _owner ) + { + _this = _owner; + _this.scrolled_window = this; + this.el = new Gtk.ScrolledWindow( null, null ); + + // my vars (dec) + + // set gobject values + this.el.height_request = 500; + this.el.vexpand = true; + var child_0 = new Xcls_view( _this ); + child_0.ref(); + this.el.add ( child_0.el ); + + // init method + + { + this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); + } + } + + // user defined functions + } + public class Xcls_view : Object + { + public WebKit.WebView el; + private NewBranch _this; + + + // my vars (def) + + // ctor + public Xcls_view(NewBranch _owner ) + { + _this = _owner; + _this.view = this; + this.el = new WebKit.WebView(); + + // my vars (dec) + + // set gobject values + } + + // user defined functions + public void loadTicket (string tid) { + int h,w; + _this.el.get_size(out w, out h); + + if (tid == "") { + _this.scrolled_window.el.hide(); + _this.el.resize(w, 150); + } else { + _this.scrolled_window.el.show(); + _this.el.resize(w, 800); + } + + var rs = RooTicket.singleton(); + var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid); + var hd = uri.get_http_headers(); + var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data); + hd.append("Authorization", "Basic %s".printf(authCode)); + + this.el.load_request(uri); + } + } + + } diff --git a/config1.builder b/config1.builder index 572b90f0..3e98e73e 100644 --- a/config1.builder +++ b/config1.builder @@ -45,7 +45,8 @@ "gtk+-3.0", "json-glib-1.0", "libsoup-2.4", - "gtksourceview-3.0" + "gtksourceview-3.0", + "webkit2gtk-4.0" ] } ] \ No newline at end of file diff --git a/configure.ac b/configure.ac index 11ab1335..935d4c05 100644 --- a/configure.ac +++ b/configure.ac @@ -29,8 +29,9 @@ PKG_CHECK_MODULES(GITLIVE, [ gtksourceview-3.0 libnotify libwnck-3.0 + webkit2gtk-4.0 libcanberra - libsoup-2.4 >= 2.56.0 + libsoup-2.4 >= 2.56.0 json-glib-1.0 ]) -- 2.39.2