X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=RooProject.vala;h=23fcbfa2f479577f535df297ca61eff75f31013a;hb=a6c214d30b033aadeec72b2532daccacbfadadf8;hp=28221de62e831d9dfe9657bf24ea1777e50f140a;hpb=f5da847b4a5dc43242eb9625d11af73fb8b98195;p=gitlive diff --git a/RooProject.vala b/RooProject.vala index 28221de6..23fcbfa2 100644 --- a/RooProject.vala +++ b/RooProject.vala @@ -1,14 +1,28 @@ +/** +This a mostly a static class that manages an array of it'self... +*/ static RooProject _RooProject; public class RooProject : Object { + + public string id; // not really important that they are numbers.. + public string code; + public string name; + public string type; + + + // --- static from here on.... + + + static Gee.ArrayList _projects; static int loadcount = 0; const string roourl = "https://roojs.com/admin.php/Roo"; - public static RooProject singleton() + static RooProject singleton() { if (_RooProject == null) { _RooProject = new RooProject(); @@ -19,11 +33,6 @@ public class RooProject : Object return _RooProject; } - public string id; // not really important that they are numbers.. - public string code; - public string name; - public string type; - public static Gee.ArrayList projects() { @@ -32,6 +41,37 @@ public class RooProject : Object return RooProject._projects; } + + public static RooProject? getProjectByRepo(GitRepo repo) + { + RooProject.singleton(); // init... + + // fixme -- needs to get from rep list.. + + var pid = ""; + foreach(var roo_repo in RooRepo.repos()) { + if (roo_repo.shortname == repo.name) { + pid = roo_repo.project_id; + break; + } + } + if (pid == "") { + GLib.debug("getProjectByRepo: repo has no project"); + return null; + } + // get project by id... + foreach(var roo_project in RooProject.projects()) { + if (roo_project.id == pid) { + GLib.debug("getProjectByRepo: project_id = %s", pid); + return roo_project; + } + } + GLib.debug("getProjectByRepo: can not find project"); + return null; + + } + + public static RooProject addProject(Json.Object t) { RooProject.singleton(); // init... @@ -46,7 +86,7 @@ public class RooProject : Object return add; } - static void reloadProjects() /// has to be called on singleton.. + public static void reload() /// has to be called on singleton.. { RooProject.loadcount = 0; RooProject.singleton(); @@ -98,9 +138,9 @@ public class RooProject : Object var rd = response.get_array_member ("data"); // got a valid result... - var _this = RooTicket.singleton(); + for(var i = 0; i < rd.get_length(); i++) { - _this.addProject(rd.get_object_element(i)); + RooProject.addProject(rd.get_object_element(i)); }