2 This a mostly a static class that manages an array of it'self...
6 static RooProject _RooProject;
7 public class RooProject : Object
10 public string id; // not really important that they are numbers..
16 // --- static from here on....
20 static Gee.ArrayList<RooProject> _projects;
21 static int loadcount = 0;
22 const string roourl = "https://roojs.com/admin.php/Roo";
25 static RooProject singleton()
27 if (_RooProject == null) {
28 _RooProject = new RooProject();
29 RooProject.loadcount = 0;
30 RooProject.loadProjects();
37 public static Gee.ArrayList<RooProject> projects()
39 RooProject.singleton();
41 return RooProject._projects;
45 public static RooProject? getProjectByRepo(GitRepo repo)
47 RooProject.singleton();
49 // fixme -- needs to get from rep list..
50 var rt = RooTicket.singleton();
51 if (rt.repos.size < 1) {
57 foreach(var roo_repo in rt.repos) {
58 if (roo_repo.shortname == repo.name) {
59 pid = roo_repo.project_id;
64 GLib.debug("getProjectByRepo: repo has no project");
67 // get project by id...
68 foreach(var roo_project in RooProject.projects()) {
69 if (roo_project.id == pid) {
70 GLib.debug("getProjectByRepo: project_id = %s", pid);
74 GLib.debug("getProjectByRepo: can not find project");
80 public static RooProject addProject(Json.Object t)
82 RooProject.singleton(); // init...
84 var add = new RooProject();
85 add.id = t.get_string_member("id");
86 add.name = t.get_string_member("name");
87 add.type = t.get_string_member("type");
88 add.code = t.get_string_member("code");
89 RooProject._projects.add(add);
90 GLib.debug("ADD project %s : %s : %s", add.id, add.code, add.name);
94 public static void reload() /// has to be called on singleton..
96 RooProject.loadcount = 0;
97 RooProject.singleton();
98 if (RooProject.loadcount == 0 ) {
99 RooProject.loadProjects();
103 static void loadProjects() // called from singleton...
105 RooProject._projects = new Gee.ArrayList<RooProject>();
107 RooProject.loadcount ++;
108 var table = new GLib.HashTable<string, string>(str_hash, str_equal);
110 table.insert("query[project_filter]","P,N,U");
111 table.insert("limit","200");
112 table.insert("sort","name");
113 table.insert("dir","ASC");
115 var params = Soup.Form.encode_hash(table);
117 var url = "%s/%s?%s" . printf(roourl, "core_project", params);
119 GLib.debug("request %s", url);
121 var session = new Soup.Session ();
123 var message = new Soup.Message ("GET", url);
126 RooTicket.setAuth(message);
128 session.send_message (message);
130 var data = (string) message.response_body.flatten().data;
131 //GLib.debug("got %s", data);
133 var parser = new Json.Parser ();
134 parser.load_from_data (data, -1);
136 var response = parser.get_root().get_object();
137 var status = response.get_boolean_member("success");
140 GLib.error(response.get_string_member("errorMsg"));
143 var rd = response.get_array_member ("data");
145 // got a valid result...
147 for(var i = 0; i < rd.get_length(); i++) {
148 RooProject.addProject(rd.get_object_element(i));
153 GLib.error(e.message);