From 1b2969a1eb3587c35447417241d4074fe124428c Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 6 Jan 2020 08:26:13 +0100 Subject: [PATCH] Added use of projects tree. Split page builder code. --- .../april/agirstatool/core/AgirStatool.java | 63 ++++++++++++++----- .../pages/ProjectsGroupedPageBuilder.java | 4 +- .../core/pages/ProjectsRawPageBuilder.java | 4 +- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/org/april/agirstatool/core/AgirStatool.java b/src/org/april/agirstatool/core/AgirStatool.java index d6f9ead..a996a70 100644 --- a/src/org/april/agirstatool/core/AgirStatool.java +++ b/src/org/april/agirstatool/core/AgirStatool.java @@ -183,24 +183,11 @@ public class AgirStatool { try { + // Copy CSS file. FileUtils.copyURLToFile(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/agirstatool.css"), new File(this.targetDirectory, "agirstatool.css")); - Projects projects = listProjectsWithSubStats(); - - // Add parent projects with alone statistics. - for (Project project : listProjectsWithRawStats()) - { - if (project.hasChild()) - { - project.setName("#" + project.getName()); - project.setParentId(project.getId()); - project.setChildCount(0); - projects.add(project); - } - } - - Project all = getRootProject(); - projects.add(all); + // + Projects projects = listProjectsFullFull(); // Create welcome page. String lines = ProjectsRawPageBuilder.build(projects); @@ -384,6 +371,50 @@ public class AgirStatool return result; } + public Projects listProjectsFullFull() throws AgirStatoolException + { + Projects result; + + result = new Projects(); + + // + Projects projects = listProjectsWithSubStats(); + + // Add parent projects with alone statistics. + for (Project project : listProjectsWithRawStats()) + { + if (project.hasChild()) + { + project.setName("#" + project.getName()); + project.setParentId(project.getId()); + project.setChildCount(0); + projects.add(project); + } + } + + // Create a root project. + Project all = getRootProject(); + projects.add(all); + + // Transform as tree. + for (Project project : projects) + { + if ((project.hasChild()) || (project.getId() == 0)) + { + result.add(project); + + Projects subProjects = projects.getByParent(project.getId()); + subProjects.sortByName(); + project.subProjects().addAll(subProjects); + } + } + + result.sortByName(); + + // + return result; + } + /** * List projects extended. * diff --git a/src/org/april/agirstatool/core/pages/ProjectsGroupedPageBuilder.java b/src/org/april/agirstatool/core/pages/ProjectsGroupedPageBuilder.java index 072d8f1..13e5b7a 100644 --- a/src/org/april/agirstatool/core/pages/ProjectsGroupedPageBuilder.java +++ b/src/org/april/agirstatool/core/pages/ProjectsGroupedPageBuilder.java @@ -56,8 +56,6 @@ public class ProjectsGroupedPageBuilder { System.out.println("Building welcome page (2)…"); - projects.sortByName(); - TagDataManager data = new TagDataManager(); int index = 0; for (Project project : projects) @@ -85,7 +83,7 @@ public class ProjectsGroupedPageBuilder if (project.hasChild()) { - for (Project subProject : projects.getByParent(project.getId()).sortByName()) + for (Project subProject : project.subProjects()) { data.setContent("projectLine", index, "projectId", subProject.getId()); data.setAttribute("projectLine", index, "projectName", "style", "padding-left: 25px;"); diff --git a/src/org/april/agirstatool/core/pages/ProjectsRawPageBuilder.java b/src/org/april/agirstatool/core/pages/ProjectsRawPageBuilder.java index 470e6a1..295c138 100644 --- a/src/org/april/agirstatool/core/pages/ProjectsRawPageBuilder.java +++ b/src/org/april/agirstatool/core/pages/ProjectsRawPageBuilder.java @@ -54,8 +54,6 @@ public class ProjectsRawPageBuilder { System.out.println("Building welcome page…"); - projects.sortByName(); - TagDataManager data = new TagDataManager(); int index = 0; for (Project project : projects) @@ -91,7 +89,7 @@ public class ProjectsRawPageBuilder if (project.hasChild()) { - for (Project subProject : projects.getByParent(project.getId()).sortByName()) + for (Project subProject : project.subProjects()) { data.setContent("projectLine", index, "projectId", subProject.getId()); data.setAttribute("projectLine", index, "projectName", "style", "padding-left: 25px;");