X-Git-Url: http://git.roojs.org/?p=gitlive;a=blobdiff_plain;f=RooTicket.vala;h=5d3c357c8ff5d6330ffb0c70518f913c4acd0630;hp=d675621c7e2816fcd023a8bac5a84838a8263af3;hb=424eebf8a96c11d28b3da871c3e1560638d3511f;hpb=2ac46b7e5e54b5382df0c55b865e47a9937e15f8 diff --git a/RooTicket.vala b/RooTicket.vala index d675621c..5d3c357c 100644 --- a/RooTicket.vala +++ b/RooTicket.vala @@ -1,4 +1,4 @@ -/** +/** code to fetch ticket info... @@ -13,10 +13,27 @@ public class RooRepo : Object public string project_id; public string description; public string shortname; + +} + +public class RooOption : Object +{ + + public string id; // not really important that they are numbers.. + public string name; + public string display_name; + + public RooOption (string id, string name, string display_name) + { + this.id = id; + this.name = name; + this.display_name = name; + } } + public class RooProject : Object { public string id; // not really important that they are numbers.. @@ -58,6 +75,14 @@ public class RooTicket : Object public Gee.ArrayList tickets; // only available for singletonn. public Gee.ArrayList projects; // only available for singletonn. public Gee.ArrayList repos; // only available for singletonn. + + public Gee.ArrayList milestones; + public Gee.ArrayList priorities; + public Gee.ArrayList serverities; + public Gee.ArrayList classifications; + public Gee.ArrayList developers; + + public string username = ""; // only available for singletonn. public string password = ""; // only available for singletonn. @@ -89,6 +114,20 @@ public class RooTicket : Object } + public Gee.ArrayList readJsonArray(Json.Array a) + { + var ret = new Gee.ArrayList(); + for(var i = 0; i < a.get_length(); i++) { + var t = a.get_object_element(i); + ret.add(new RooOption( + t.get_string_member("id"), + t.get_string_member("name"), + t.get_string_member("display_name") + )); + } + return ret; + + } public RooTicket addTicket(Json.Object t) { @@ -412,7 +451,73 @@ public class RooTicket : Object } } - + public void loadProjectOptions(string pid) + { + var rt = RooTicket.singleton(); + rt.milestones = new Gee.ArrayList(); + rt.priorities = new Gee.ArrayList(); + rt.serverities = new Gee.ArrayList(); + rt.classifications = new Gee.ArrayList(); + rt.developers = new Gee.ArrayList(); + + if (pid == "") { + return; + } + + + + var table = new GLib.HashTable(str_hash, str_equal); + + table.insert("_options_for",pid); + + var params = Soup.Form.encode_hash(table); + + var url = "%s/%s?%s" . printf(roourl, "mtrack_ticket", params); + + GLib.debug("request %s", url); + + var session = new Soup.Session (); + session.timeout = 0; + var message = new Soup.Message ("GET", url); + + + RooTicket.setAuth(message); + + session.send_message (message); + + var data = (string) message.response_body.flatten().data; + //GLib.debug("got %s", data); + try { + var parser = new Json.Parser (); + parser.load_from_data (data, -1); + + var response = parser.get_root().get_object(); + var status = response.get_boolean_member("success"); + + if(!status){ + GLib.error(response.get_string_member("errorMsg")); + return; + } + var rd = response.get_object_member ("data"); + + rt.milestones = this.readJsonArray( rd.get_array_member("milestone")); + rt.priorities = this.readJsonArray( rd.get_array_member("priority")); + rt.serverities = this.readJsonArray( rd.get_array_member("severity")); + rt.classifications = this.readJsonArray( rd.get_array_member("classification")); + rt.developers = this.readJsonArray( rd.get_array_member("developer")); + + + + + // got a valid result... + + + } catch (Error e) { + GLib.error(e.message); + return; + } + + } public static void setAuth(Soup.Message message) { @@ -490,7 +595,64 @@ public class RooTicket : Object } } + public string createTicket( + string project_id, + string milestone_id, + string priority_id, + string classification_id, + string developer_id, + string summary, + string description + ) + { + + var table = new GLib.HashTable(str_hash, str_equal); + + table.insert("project_id", project_id); + table.insert("milestone_id", milestone_id); + table.insert("priority_id", priority_id); + table.insert("classification_id", classification_id); + table.insert("developer_id", developer_id); + table.insert("summary", summary); + table.insert("description", description); + + var params = Soup.Form.encode_hash(table); + + GLib.debug("request POST %s / %s", roourl, id); + + var session = new Soup.Session (); + session.timeout = 0; + var message = new Soup.Message ("POST", roourl + "/mtrack_ticket"); + RooTicket.setAuth(message); + message.set_request ("application/x-www-form-urlencoded", Soup.MemoryUse.STATIC, params.data); + session.send_message (message); + + + var data = (string) message.response_body.flatten().data; + GLib.debug("got %s", data); + try { + var parser = new Json.Parser (); + parser.load_from_data (data, -1); + + var response = parser.get_root().get_object(); + var status = response.get_boolean_member("success"); + + if(!status){ + GLib.error(response.get_string_member("errorMsg")); + return "" ; + } + var rd = response.get_object_member ("data"); + return rd.get_string_member("id"); + + + + } catch (Error e) { + GLib.error(e.message); + return ""; + } + + } }