X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=RooProject.vala;h=b46ee7df5f1a1ccb505a10f4466513c1bf6ed50d;hb=4d807df843e3d8ac131fdb1d6c32870ed4e1b004;hp=97c2c2d2b36e85f2b40f1c65ce055498ad40ed9b;hpb=54b724531b5c5d48eda3eab0ec79a7fddd2f521b;p=gitlive diff --git a/RooProject.vala b/RooProject.vala index 97c2c2d2..b46ee7df 100644 --- a/RooProject.vala +++ b/RooProject.vala @@ -1,25 +1,39 @@ +/** +This a mostly a static class that manages an array of it'self... +*/ static RooProject _RooProject; public class RooProject : Object { - public static RooProject singleton() + + 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"; + + + static RooProject singleton() { if (_RooProject == null) { _RooProject = new RooProject(); RooProject.loadcount = 0; - RooTicket.loadProjects(); + RooProject.loadProjects(); } - return _RooTicket; + return _RooProject; } - public string id; // not really important that they are numbers.. - public string code; - public string name; - public string type; - - static Gee.ArrayList _projects; + public static Gee.ArrayList projects() { RooProject.singleton(); @@ -27,9 +41,44 @@ public class RooProject : Object return RooProject._projects; } - static public RooProject addProject(Json.Object t) + + public static RooProject? getProjectByRepo(GitRepo repo) { + RooProject.singleton(); + // fixme -- needs to get from rep list.. + var rt = RooTicket.singleton(); + if (rt.repos.size < 1) { + rt.loadRepos(); + } + + + var pid = ""; + foreach(var roo_repo in rt.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... var add = new RooProject(); @@ -42,7 +91,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(); @@ -53,7 +102,7 @@ public class RooProject : Object static void loadProjects() // called from singleton... { - RooTicket._projects = new Gee.ArrayList(); + RooProject._projects = new Gee.ArrayList(); RooProject.loadcount ++; var table = new GLib.HashTable(str_hash, str_equal); @@ -94,9 +143,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)); }