+/**
+This a mostly a static class that manages an array of it'self...
+*/
static RooProject _RooProject;
public class RooProject : Object
{
- public static RooProject singleton()
- {
-
- _RooProject = new RooProject();
- RooTicket.projects = new Gee.ArrayList<RooProject>();
- RooTicket.loadProjects();
-
- }
- return _RooTicket;
- }
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<RooProject> _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;
+ RooProject.loadProjects();
+
+ }
+ return _RooProject;
+ }
+
+
public static Gee.ArrayList<RooProject> projects()
{
RooProject.singleton();
return RooProject._projects;
}
- static public RooProject addProject(Json.Object t)
+
+ 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...
var add = new RooProject();
GLib.debug("ADD project %s : %s : %s", add.id, add.code, add.name);
return add;
}
-
+
+ public static void reload() /// has to be called on singleton..
+ {
+ RooProject.loadcount = 0;
+ RooProject.singleton();
+ if (RooProject.loadcount == 0 ) {
+ RooProject.loadProjects();
+ }
+ }
static void loadProjects() // called from singleton...
{
- RooTicket.singleton().projects = new Gee.ArrayList<RooProject>();
+ RooProject._projects = new Gee.ArrayList<RooProject>();
-
+ RooProject.loadcount ++;
var table = new GLib.HashTable<string, string>(str_hash, str_equal);
table.insert("query[project_filter]","P,N,U");
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));
}