From c5d00c020d67896dd5b997c1f7b629ab57f6ca14 Mon Sep 17 00:00:00 2001 From: Mustapha Zorgati <15628173+mustaphazorgati@users.noreply.github.com> Date: Thu, 18 Apr 2019 15:14:33 +0200 Subject: [PATCH] TSK-843: moved report structure ajustment from client to rest service. --- .../taskana/impl/report/structure/Report.java | 16 +- .../pro/taskana/report/CategoryReport.java | 2 +- .../taskana/report/ClassificationReport.java | 4 +- .../report/CustomFieldValueReport.java | 2 +- .../pro/taskana/report/TaskStatusReport.java | 2 +- .../pro/taskana/report/TimestampReport.java | 2 +- .../pro/taskana/report/WorkbasketReport.java | 2 +- .../impl/report/structure/ReportTest.java | 7 +- .../src/main/asciidoc/rest-api.adoc | 16 + .../MonitorControllerRestDocumentation.java | 29 +- .../rest/resource/ReportAssembler.java | 75 ++-- .../taskana/rest/resource/ReportResource.java | 100 ++--- .../rest/resource/ReportResourceTest.java | 374 +++++++----------- web/src/app/monitor/models/meta-info-data.ts | 5 +- web/src/app/monitor/models/report-data.ts | 10 +- .../app/monitor/models/report-info-data.ts | 12 - web/src/app/monitor/models/report-row.ts | 7 + web/src/app/monitor/monitor.module.ts | 4 +- .../app/monitor/report/report.component.html | 76 +++- .../app/monitor/report/report.component.scss | 17 + .../app/monitor/report/report.component.ts | 45 ++- .../app/monitor/report/row/row.component.html | 28 -- .../app/monitor/report/row/row.component.scss | 19 - .../app/monitor/report/row/row.component.ts | 81 ---- web/src/app/monitor/tasks/tasks.component.ts | 12 +- 25 files changed, 378 insertions(+), 569 deletions(-) delete mode 100644 web/src/app/monitor/models/report-info-data.ts create mode 100644 web/src/app/monitor/models/report-row.ts delete mode 100644 web/src/app/monitor/report/row/row.component.html delete mode 100644 web/src/app/monitor/report/row/row.component.scss delete mode 100644 web/src/app/monitor/report/row/row.component.ts diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/report/structure/Report.java b/lib/taskana-core/src/main/java/pro/taskana/impl/report/structure/Report.java index 58c26c50e..9bcc12d34 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/report/structure/Report.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/report/structure/Report.java @@ -24,18 +24,12 @@ public abstract class Report columnHeaders; private Map> reportRows = new LinkedHashMap<>(); private Row sumRow; - private String rowDesc; - private String[] expandableHeaders; + private String[] rowDesc; - protected Report(List columnHeaders, String rowDesc, String[] expandableHeaders) { + protected Report(List columnHeaders, String[] rowDesc) { this.rowDesc = rowDesc; sumRow = createRow(columnHeaders.size()); this.columnHeaders = new ArrayList<>(columnHeaders); - this.expandableHeaders = expandableHeaders; - } - - protected Report(List columnHeaders, String rowDesc) { - this(columnHeaders, rowDesc, new String[0]); } public final Map> getRows() { @@ -50,14 +44,10 @@ public abstract class Report getRow(String key) { return reportRows.get(key); } diff --git a/lib/taskana-core/src/main/java/pro/taskana/report/CategoryReport.java b/lib/taskana-core/src/main/java/pro/taskana/report/CategoryReport.java index 16aa89d0d..68a008211 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/report/CategoryReport.java +++ b/lib/taskana-core/src/main/java/pro/taskana/report/CategoryReport.java @@ -19,7 +19,7 @@ import pro.taskana.impl.report.structure.Report; public class CategoryReport extends Report { public CategoryReport(List timeIntervalColumnHeaders) { - super(timeIntervalColumnHeaders, "CLASSIFICATION CATEGORIES"); + super(timeIntervalColumnHeaders, new String[] {"CLASSIFICATION CATEGORIES"}); } /** diff --git a/lib/taskana-core/src/main/java/pro/taskana/report/ClassificationReport.java b/lib/taskana-core/src/main/java/pro/taskana/report/ClassificationReport.java index 64c641313..d5d0426ee 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/report/ClassificationReport.java +++ b/lib/taskana-core/src/main/java/pro/taskana/report/ClassificationReport.java @@ -17,7 +17,7 @@ import pro.taskana.impl.report.structure.Report; public class ClassificationReport extends Report { public ClassificationReport(List timeIntervalColumnHeaders) { - super(timeIntervalColumnHeaders, "CLASSIFICATION KEYS"); + super(timeIntervalColumnHeaders, new String[] {"CLASSIFICATION KEYS"}); } /** @@ -52,7 +52,7 @@ public class ClassificationReport extends Report { public DetailedClassificationReport(List workbasketLevelReportColumnHeaders) { - super(workbasketLevelReportColumnHeaders, "TASK CLASSIFICATION KEYS"); + super(workbasketLevelReportColumnHeaders, new String[] {"TASK CLASSIFICATION KEYS", "ATTACHMENT"}); } @Override diff --git a/lib/taskana-core/src/main/java/pro/taskana/report/CustomFieldValueReport.java b/lib/taskana-core/src/main/java/pro/taskana/report/CustomFieldValueReport.java index f88fe6f36..e590480a9 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/report/CustomFieldValueReport.java +++ b/lib/taskana-core/src/main/java/pro/taskana/report/CustomFieldValueReport.java @@ -19,7 +19,7 @@ import pro.taskana.impl.report.structure.Report; public class CustomFieldValueReport extends Report { public CustomFieldValueReport(List timeIntervalColumnHeaders) { - super(timeIntervalColumnHeaders, "CUSTOM FIELDS"); + super(timeIntervalColumnHeaders, new String[] {"CUSTOM FIELDS"}); } /** diff --git a/lib/taskana-core/src/main/java/pro/taskana/report/TaskStatusReport.java b/lib/taskana-core/src/main/java/pro/taskana/report/TaskStatusReport.java index 36c4bbcb9..6d8a2f3c0 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/report/TaskStatusReport.java +++ b/lib/taskana-core/src/main/java/pro/taskana/report/TaskStatusReport.java @@ -21,7 +21,7 @@ public class TaskStatusReport extends Report filter) { super((filter != null ? filter.stream() : Stream.of(TaskState.values())) .map(TaskStatusColumnHeader::new) - .collect(Collectors.toList()), "DOMAINS"); + .collect(Collectors.toList()), new String[] {"DOMAINS"}); } /** diff --git a/lib/taskana-core/src/main/java/pro/taskana/report/TimestampReport.java b/lib/taskana-core/src/main/java/pro/taskana/report/TimestampReport.java index 6e554f66c..521fdb809 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/report/TimestampReport.java +++ b/lib/taskana-core/src/main/java/pro/taskana/report/TimestampReport.java @@ -15,7 +15,7 @@ import pro.taskana.impl.report.structure.Report; public class TimestampReport extends Report { public TimestampReport(List dates) { - super(dates, "STATES", new String[] {"ORG LEVEL 1", "ORG LEVEL 2", "ORG LEVEL 3", "ORG LEVEL 4"}); + super(dates, new String[] {"STATES", "ORG LEVEL 1", "ORG LEVEL 2", "ORG LEVEL 3", "ORG LEVEL 4"}); } @Override diff --git a/lib/taskana-core/src/main/java/pro/taskana/report/WorkbasketReport.java b/lib/taskana-core/src/main/java/pro/taskana/report/WorkbasketReport.java index c4d2d8d3b..45c0fdc39 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/report/WorkbasketReport.java +++ b/lib/taskana-core/src/main/java/pro/taskana/report/WorkbasketReport.java @@ -22,7 +22,7 @@ import pro.taskana.impl.report.structure.Report; public class WorkbasketReport extends Report { public WorkbasketReport(List timeIntervalColumnHeaders) { - super(timeIntervalColumnHeaders, "WORKBASKET KEYS"); + super(timeIntervalColumnHeaders, new String[] {"WORKBASKET KEYS"}); } /** diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/report/structure/ReportTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/report/structure/ReportTest.java index 326dbfa92..397125c56 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/report/structure/ReportTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/report/structure/ReportTest.java @@ -29,7 +29,7 @@ public class ReportTest { @Before public void before() { - this.report = new Report(HEADERS, "rowDesc") { + this.report = new Report(HEADERS, new String[] {"rowDesc"}) { }; @@ -116,7 +116,8 @@ public class ReportTest { @Test public void testInsertItemWithNoColumnHeaders() { //given - report = new Report(Collections.emptyList(), "rowDesc") { + report = new Report(Collections.emptyList(), + new String[] {"rowDesc"}) { }; @@ -148,7 +149,7 @@ public class ReportTest { //given List headers = new ArrayList<>(HEADERS); headers.add(new TimeIntervalColumnHeader(0, 3)); - report = new Report(headers, "rowDesc") { + report = new Report(headers, new String[] {"rowDesc"}) { }; item.setAgeInDays(2); diff --git a/rest/taskana-rest-spring-test/src/main/asciidoc/rest-api.adoc b/rest/taskana-rest-spring-test/src/main/asciidoc/rest-api.adoc index c2c0d2c7b..ab67f452e 100644 --- a/rest/taskana-rest-spring-test/src/main/asciidoc/rest-api.adoc +++ b/rest/taskana-rest-spring-test/src/main/asciidoc/rest-api.adoc @@ -658,6 +658,22 @@ include::../../../{snippets}/GetTaskClassificationReportDocTest/http-response.ad Same as task status report +=== Get a timestamp report + +A `GET` request is used to get the number of tasks sorted by a task timestamp. + +==== Example Request + +include::../../../{snippets}/GetTimestampReportDocTest/http-request.adoc[] + +==== Example Response + +include::../../../{snippets}/GetTimestampReportDocTest/http-response.adoc[] + +==== Response Structure + +Same as task status report + == Other Resources (using the TaskanaEngineController) These resources are directly connected to the Taskana Engine endpoint. diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/MonitorControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/MonitorControllerRestDocumentation.java index c3e05ef03..5f2fd228c 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/MonitorControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/MonitorControllerRestDocumentation.java @@ -68,17 +68,15 @@ public class MonitorControllerRestDocumentation { fieldWithPath("meta.name").description("Name of the report"), fieldWithPath("meta.date").description("Date of the report creation"), fieldWithPath("meta.header").description("Column-headers of the report"), - fieldWithPath("meta.expHeader").description( - "Expandable Column-headers which match the depth of the foldable rows within the report."), fieldWithPath("meta.rowDesc").description("Descriptions for the rows the report"), - fieldWithPath("meta.totalDesc").description("Description for the report itself"), - subsectionWithPath("rows").description("Object holding the rows of the report.\n" - + "For the exact structure please check the example response above"), - fieldWithPath("sumRow").description("Object holding the sums in the columns over all rows"), - subsectionWithPath("sumRow.cells") - .description("Contains the accumulated numbers over all columns defined in meta.header.\n" - + "For the exact structure please check the example response above"), - fieldWithPath("sumRow.total").description("Total number of tasks"), + fieldWithPath("meta.totalDesc").description("Description for the sum column"), + fieldWithPath("rows").description("Array holding the rows of the report."), + fieldWithPath("rows[].cells").description("Array holding all the cell values of the given row"), + fieldWithPath("rows[].total").description("Sum of all values of the given row"), + fieldWithPath("rows[].depth").description("Depth of the row. If the depth is > 0, then this row is a sub-row of a prior row"), + fieldWithPath("rows[].desc").description("Array containing description of the row."), + fieldWithPath("rows[].display").description("Boolean identifying if the given row should be initially displayed or not."), + subsectionWithPath("sumRow").description("Array holding the sums in the columns over all rows. Structure same as 'rows'"), fieldWithPath("_links.self.href").ignored() }; } @@ -115,4 +113,15 @@ public class MonitorControllerRestDocumentation { .andDo(MockMvcRestDocumentation.document("GetTaskClassificationReportDocTest", responseFields(taskReportFieldDescriptors))); } + + @Test + public void getTimestampReport() throws Exception { + this.mockMvc.perform(RestDocumentationRequestBuilders + .get("http://127.0.0.1:" + port + "/v1/monitor/timestamp-report") + .accept("application/hal+json") + .header("Authorization", "Basic YWRtaW46YWRtaW4=")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo(MockMvcRestDocumentation.document("GetTimestampReportDocTest", + responseFields(taskReportFieldDescriptors))); + } } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportAssembler.java index 9b904feaa..48eb367d0 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportAssembler.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportAssembler.java @@ -4,9 +4,11 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import java.time.Instant; -import java.util.HashMap; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import org.springframework.stereotype.Component; @@ -80,65 +82,52 @@ public class ReportAssembler { report.getClass().getSimpleName(), time.toString(), header, - report.getExpandableHeaders(), report.getRowDesc()); + report.getRowDesc()); // iterate over each Row and transform it to a RowResource while keeping the domain key. - Map rows = report.getRows() + List rows = report.getRows() .entrySet() .stream() - .collect(Collectors.toMap(Map.Entry::getKey, i -> transformRow(i.getValue(), header))); + .sorted(Comparator.comparing(e -> e.getKey().toLowerCase())) + .map(i -> transformRow(i.getValue(), i.getKey(), new String[report.getRowDesc().length], 0)) + .flatMap(Collection::stream) + .collect(Collectors.toList()); - ReportResource.RowResource sumRow = transformRow(report.getSumRow(), header); + List sumRow = transformRow(report.getSumRow(), meta.getTotalDesc(), + new String[report.getRowDesc().length], 0); return new ReportResource(meta, rows, sumRow); } - private ReportResource.RowResource transformRow(Row row, String[] header) { + private List transformRow(Row row, String currentDesc, + String[] desc, int depth) { // This is a very dirty solution.. Personally I'd prefer to use a visitor-like pattern here. // The issue with that: Addition of the visitor code within taskana-core - and having clean code is not // a reason to append code somewhere where it doesn't belong. if (row.getClass() == SingleRow.class) { - return transformSingleRow((SingleRow) row, header); + return Collections.singletonList(transformSingleRow((SingleRow) row, currentDesc, desc, depth)); } - return transformFoldableRow((FoldableRow) row, header); + return transformFoldableRow((FoldableRow) row, currentDesc, desc, depth); } - private ReportResource.SingleRowResource transformSingleRow(SingleRow row, - String[] header) { - Map result = new HashMap<>(); - int[] cells = row.getCells(); - for (int i = 0; i < cells.length; i++) { - result.put(header[i], cells[i]); - } - return new ReportResource.SingleRowResource(result, row.getTotalValue()); + private ReportResource.RowResource transformSingleRow(SingleRow row, String currentDesc, + String[] previousRowDesc, int depth) { + String[] rowDesc = new String[previousRowDesc.length]; + System.arraycopy(previousRowDesc, 0, rowDesc, 0, depth); + rowDesc[depth] = currentDesc; + return new ReportResource.RowResource(row.getCells(), row.getTotalValue(), depth, rowDesc, depth == 0); } - private ReportResource.FoldableRowResource transformFoldableRow(FoldableRow row, - String[] header) { - ReportResource.FoldableRowResource base = new ReportResource.FoldableRowResource( - transformSingleRow(row, header)); + private List transformFoldableRow(FoldableRow row, + String currentDesc, String[] previousRowDesc, int depth) { + ReportResource.RowResource baseRow = transformSingleRow(row, currentDesc, previousRowDesc, depth); + List rowList = new LinkedList<>(); + rowList.add(baseRow); row.getFoldableRowKeySet().stream() - .map(k -> new Pair<>(k, row.getFoldableRow(k))) - .map(p -> new Pair<>(p.key, transformRow(p.value, header))) - .forEachOrdered(p -> base.addRow(p.key, p.value)); - return base; + .sorted(String.CASE_INSENSITIVE_ORDER) + .map(s -> transformRow(row.getFoldableRow(s), s, baseRow.getDesc(), depth + 1)) + .flatMap(Collection::stream) + .forEachOrdered(rowList::add); + return rowList; } - - /** - * Simple Pair (tuple). - * @param key - * @param value - */ - private class Pair { - - private final K key; - private final V value; - - Pair(K key, V value) { - this.key = key; - this.value = value; - } - - } - } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResource.java index 03d182c9d..ae5acba67 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResource.java @@ -1,13 +1,10 @@ package pro.taskana.rest.resource; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; +import java.util.List; import org.springframework.hateoas.ResourceSupport; -import pro.taskana.impl.util.LoggerUtils; - /** * Resource class for {@link pro.taskana.impl.report.structure.Report}. */ @@ -15,11 +12,11 @@ public class ReportResource extends ResourceSupport { private MetaInformation meta; - private Map rows; + private List rows; - private RowResource sumRow; + private List sumRow; - public ReportResource(MetaInformation meta, Map rows, RowResource sumRow) { + public ReportResource(MetaInformation meta, List rows, List sumRow) { this.meta = meta; this.rows = rows; this.sumRow = sumRow; @@ -29,73 +26,62 @@ public class ReportResource extends ResourceSupport { return meta; } - public Map getRows() { + public List getRows() { return rows; } - public RowResource getSumRow() { + public List getSumRow() { return sumRow; } - /** - * Resource Interface for {@link pro.taskana.impl.report.structure.Row}. - */ - public interface RowResource { - - Map getCells(); - - int getTotal(); - } - /** * Resource class for {@link pro.taskana.impl.report.row.SingleRow}. */ - public static class SingleRowResource implements RowResource { + public static class RowResource { - private Map cells; + private int[] cells; private int total; + private int depth; + private String[] desc; + private boolean display; - public SingleRowResource(Map cells, int total) { + public RowResource(int[] cells, int total, int depth, String[] desc, boolean display) { this.cells = cells; this.total = total; + this.depth = depth; + this.desc = desc; + this.display = display; } - @Override - public Map getCells() { + @SuppressWarnings("unused") + public int[] getCells() { return cells; } - @Override + @SuppressWarnings("unused") public int getTotal() { return total; } + @SuppressWarnings("unused") + public int getDepth() { + return depth; + } + + @SuppressWarnings("unused") + public String[] getDesc() { + return desc; + } + + @SuppressWarnings("unused") + public boolean isDisplay() { + return display; + } + @Override public String toString() { - return "SingleRowResource [" - + "rowDesc= " + LoggerUtils.mapToString(this.cells) - + "taskId= " + this.total - + "]"; - } - } - - /** - * Resource class for {@link pro.taskana.impl.report.row.FoldableRow}. - */ - public static class FoldableRowResource extends SingleRowResource { - - private Map foldableRows = new HashMap<>(); - - public FoldableRowResource(SingleRowResource row) { - super(row.getCells(), row.getTotal()); - } - - public void addRow(String desc, RowResource row) { - foldableRows.put(desc, row); - } - - public Map getFoldableRows() { - return foldableRows; + return String.format("RowResourde [cells=%s, total=%d, depth=%d, desc=%s", + Arrays.toString(cells), total, depth, Arrays.toString(desc)); } } @@ -109,14 +95,12 @@ public class ReportResource extends ResourceSupport { private String name; private String date; private String[] header; - private String[] expHeader; - private String rowDesc; + private String[] rowDesc; - public MetaInformation(String name, String date, String[] header, String[] expHeader, String rowDesc) { + public MetaInformation(String name, String date, String[] header, String[] rowDesc) { this.name = name; this.date = date; this.header = header; - this.expHeader = expHeader; this.rowDesc = rowDesc; } @@ -136,18 +120,14 @@ public class ReportResource extends ResourceSupport { return header; } - public String[] getExpHeader() { - return expHeader; - } - - public String getRowDesc() { + public String[] getRowDesc() { return rowDesc; } @Override public String toString() { - return String.format("MetaInformation [name= %s, date= %s, header= %s, expHeader= %s, rowDesc= %s]", - name, date, Arrays.toString(header), Arrays.toString(expHeader), rowDesc); + return String.format("MetaInformation [name= %s, date= %s, header= %s, rowDesc= %s]", + name, date, Arrays.toString(header), Arrays.toString(rowDesc)); } } } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportResourceTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportResourceTest.java index 4b82d879b..43bd41f09 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportResourceTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportResourceTest.java @@ -3,13 +3,13 @@ package pro.taskana.rest.resource; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.temporal.ChronoUnit; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -25,7 +25,6 @@ import pro.taskana.impl.report.header.TimeIntervalColumnHeader; import pro.taskana.impl.report.item.DetailedMonitorQueryItem; import pro.taskana.impl.report.item.MonitorQueryItem; import pro.taskana.report.ClassificationReport; -import pro.taskana.report.TimestampReport; import pro.taskana.report.WorkbasketReport; import pro.taskana.rest.TestConfiguration; @@ -66,24 +65,21 @@ public class ReportResourceTest { ReportResource.MetaInformation meta = resource.getMeta(); assertEquals("WorkbasketReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); - assertEquals("WORKBASKET KEYS", meta.getRowDesc()); + assertArrayEquals(new String[] {"WORKBASKET KEYS"}, meta.getRowDesc()); assertArrayEquals(headers.stream().map(TimeIntervalColumnHeader::getDisplayName).toArray(), meta.getHeader()); - assertArrayEquals(new String[0], meta.getExpHeader()); assertEquals("Total", meta.getTotalDesc()); // rows assertTrue(resource.getRows().isEmpty()); // sumRow - assertEquals(ReportResource.SingleRowResource.class, resource.getSumRow().getClass()); - assertEquals(0, resource.getSumRow().getTotal()); - Map cells = resource.getSumRow().getCells(); - assertEquals(5, cells.size()); - assertEquals(0, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + assertEquals(1, resource.getSumRow().size()); + ReportResource.RowResource sumRow = resource.getSumRow().get(0); + assertArrayEquals(new String[] {"Total"}, sumRow.getDesc()); + assertTrue(sumRow.isDisplay()); + assertEquals(0, sumRow.getDepth()); + assertEquals(0, sumRow.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 0}, sumRow.getCells()); } @Test @@ -103,36 +99,29 @@ public class ReportResourceTest { ReportResource.MetaInformation meta = resource.getMeta(); assertEquals("ClassificationReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); - assertEquals("CLASSIFICATION KEYS", meta.getRowDesc()); + assertArrayEquals(new String[] {"CLASSIFICATION KEYS"}, meta.getRowDesc()); assertArrayEquals(headers.stream().map(TimeIntervalColumnHeader::getDisplayName).toArray(), meta.getHeader()); - assertArrayEquals(new String[0], meta.getExpHeader()); assertEquals("Total", meta.getTotalDesc()); // rows - Map rows = resource.getRows(); + List rows = resource.getRows(); assertEquals(1, rows.size()); - ReportResource.RowResource row = rows.get("key"); - assertEquals(ReportResource.SingleRowResource.class, row.getClass()); + ReportResource.RowResource row = rows.get(0); + assertArrayEquals(new String[] {"key"}, row.getDesc()); + assertEquals(0, row.getDepth()); assertEquals(2, row.getTotal()); - Map cells = row.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + + assertTrue(row.isDisplay()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); // sumRow - ReportResource.RowResource sumRow = resource.getSumRow(); - assertEquals(ReportResource.SingleRowResource.class, sumRow.getClass()); + assertEquals(1, resource.getSumRow().size()); + ReportResource.RowResource sumRow = resource.getSumRow().get(0); + assertArrayEquals(new String[] {"Total"}, sumRow.getDesc()); + assertTrue(sumRow.isDisplay()); + assertEquals(0, sumRow.getDepth()); assertEquals(2, sumRow.getTotal()); - cells = sumRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, sumRow.getCells()); } @@ -155,49 +144,36 @@ public class ReportResourceTest { ReportResource.MetaInformation meta = resource.getMeta(); assertEquals("ClassificationReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); - assertEquals("CLASSIFICATION KEYS", meta.getRowDesc()); + assertArrayEquals(new String[] {"CLASSIFICATION KEYS"}, meta.getRowDesc()); assertArrayEquals(headers.stream().map(TimeIntervalColumnHeader::getDisplayName).toArray(), meta.getHeader()); - assertArrayEquals(new String[0], meta.getExpHeader()); assertEquals("Total", meta.getTotalDesc()); // rows - Map rows = resource.getRows(); + List rows = resource.getRows(); assertEquals(2, rows.size()); - ReportResource.RowResource row = rows.get("key"); - assertEquals(ReportResource.SingleRowResource.class, row.getClass()); + ReportResource.RowResource row = rows.get(0); + assertArrayEquals(new String[] {"key"}, row.getDesc()); + assertEquals(0, row.getDepth()); + assertTrue(row.isDisplay()); assertEquals(2, row.getTotal()); - Map cells = row.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); - row = rows.get("key2"); - assertEquals(ReportResource.SingleRowResource.class, row.getClass()); + row = rows.get(1); + assertArrayEquals(new String[] {"key2"}, row.getDesc()); + assertEquals(0, row.getDepth()); + assertTrue(row.isDisplay()); assertEquals(2, row.getTotal()); - cells = row.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); // sumRow - ReportResource.RowResource sumRow = resource.getSumRow(); - assertEquals(ReportResource.SingleRowResource.class, sumRow.getClass()); + assertEquals(1, resource.getSumRow().size()); + ReportResource.RowResource sumRow = resource.getSumRow().get(0); + assertArrayEquals(new String[] {"Total"}, sumRow.getDesc()); + assertEquals(0, sumRow.getDepth()); + assertTrue(sumRow.isDisplay()); assertEquals(4, sumRow.getTotal()); - cells = sumRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(4, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); - + assertArrayEquals(new int[] {0, 0, 0, 0, 4}, sumRow.getCells()); } @Test @@ -209,7 +185,7 @@ public class ReportResourceTest { item.setAgeInDays(daysDiff - 1); item.setNumberOfTasks(2); item.setKey("key"); - item.setAttachmentKey("attachement"); + item.setAttachmentKey("attachment"); report.addItem(item); item.setAttachmentKey(null); report.addItem(item); @@ -221,82 +197,59 @@ public class ReportResourceTest { ReportResource.MetaInformation meta = resource.getMeta(); assertEquals("DetailedClassificationReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); - assertEquals("TASK CLASSIFICATION KEYS", meta.getRowDesc()); + assertArrayEquals(new String[] {"TASK CLASSIFICATION KEYS", "ATTACHMENT"}, meta.getRowDesc()); assertArrayEquals(headers.stream().map(TimeIntervalColumnHeader::getDisplayName).toArray(), meta.getHeader()); - assertArrayEquals(new String[0], meta.getExpHeader()); assertEquals("Total", meta.getTotalDesc()); // rows - Map rows = resource.getRows(); - assertEquals(1, rows.size()); - assertEquals(ReportResource.FoldableRowResource.class, rows.get("key").getClass()); - ReportResource.FoldableRowResource row = (ReportResource.FoldableRowResource) rows.get("key"); + List rows = resource.getRows(); + assertEquals(1 + 2, rows.size()); + + ReportResource.RowResource row = rows.get(0); + assertArrayEquals(new String[] {"key", null}, row.getDesc()); + assertEquals(0, row.getDepth()); + assertTrue(row.isDisplay()); assertEquals(4, row.getTotal()); - Map cells = row.getCells(); - assertEquals(5, cells.size()); - assertEquals(4, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + assertArrayEquals(new int[] {0, 0, 0, 0, 4}, row.getCells()); - assertEquals(2, row.getFoldableRows().size()); - ReportResource.RowResource foldedRow = row.getFoldableRows().get("attachement"); - assertEquals(ReportResource.SingleRowResource.class, foldedRow.getClass()); - assertEquals(2, foldedRow.getTotal()); - cells = foldedRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + row = rows.get(1); + assertArrayEquals(new String[] {"key", "attachment"}, row.getDesc()); + assertEquals(1, row.getDepth()); + assertFalse(row.isDisplay()); + assertEquals(2, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); - foldedRow = row.getFoldableRows().get("N/A"); - assertEquals(ReportResource.SingleRowResource.class, foldedRow.getClass()); - assertEquals(2, foldedRow.getTotal()); - cells = foldedRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + row = rows.get(2); + assertArrayEquals(new String[] {"key", "N/A"}, row.getDesc()); + assertEquals(1, row.getDepth()); + assertFalse(row.isDisplay()); + assertEquals(2, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); // sumRow - ReportResource.RowResource sumRow = resource.getSumRow(); - assertEquals(ReportResource.FoldableRowResource.class, sumRow.getClass()); + List sumRow = resource.getSumRow(); + assertEquals(1 + 2, sumRow.size()); + + row = sumRow.get(0); + assertArrayEquals(new String[] {"Total", null}, row.getDesc()); + assertEquals(0, row.getDepth()); + assertTrue(row.isDisplay()); assertEquals(4, row.getTotal()); - cells = row.getCells(); - assertEquals(5, cells.size()); - assertEquals(4, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + assertArrayEquals(new int[] {0, 0, 0, 0, 4}, row.getCells()); - assertEquals(2, row.getFoldableRows().size()); - foldedRow = row.getFoldableRows().get("attachement"); - assertEquals(ReportResource.SingleRowResource.class, foldedRow.getClass()); - assertEquals(2, foldedRow.getTotal()); - cells = foldedRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + row = sumRow.get(1); + assertArrayEquals(new String[] {"Total", "attachment"}, row.getDesc()); + assertEquals(1, row.getDepth()); + assertFalse(row.isDisplay()); + assertEquals(2, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); - foldedRow = row.getFoldableRows().get("N/A"); - assertEquals(ReportResource.SingleRowResource.class, foldedRow.getClass()); - assertEquals(2, foldedRow.getTotal()); - cells = foldedRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + row = sumRow.get(2); + assertArrayEquals(new String[] {"Total", "N/A"}, row.getDesc()); + assertEquals(1, row.getDepth()); + assertFalse(row.isDisplay()); + assertEquals(2, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); } @Test @@ -308,7 +261,7 @@ public class ReportResourceTest { item.setAgeInDays(daysDiff - 1); item.setNumberOfTasks(2); item.setKey("key"); - item.setAttachmentKey("attachement"); + item.setAttachmentKey("attachment"); report.addItem(item); item.setAttachmentKey(null); report.addItem(item); @@ -322,122 +275,75 @@ public class ReportResourceTest { ReportResource.MetaInformation meta = resource.getMeta(); assertEquals("DetailedClassificationReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); - assertEquals("TASK CLASSIFICATION KEYS", meta.getRowDesc()); + assertArrayEquals(new String[] {"TASK CLASSIFICATION KEYS", "ATTACHMENT"}, meta.getRowDesc()); assertArrayEquals(headers.stream().map(TimeIntervalColumnHeader::getDisplayName).toArray(), meta.getHeader()); - assertArrayEquals(new String[0], meta.getExpHeader()); assertEquals("Total", meta.getTotalDesc()); // rows - Map rows = resource.getRows(); - assertEquals(2, rows.size()); + List rows = resource.getRows(); + assertEquals((1 + 2) + (1 + 1), rows.size()); - assertEquals(ReportResource.FoldableRowResource.class, rows.get("key").getClass()); - ReportResource.FoldableRowResource row = (ReportResource.FoldableRowResource) rows.get("key"); + ReportResource.RowResource row = rows.get(0); + assertArrayEquals(new String[] {"key", null}, row.getDesc()); + assertEquals(0, row.getDepth()); + assertTrue(row.isDisplay()); assertEquals(4, row.getTotal()); - Map cells = row.getCells(); - assertEquals(5, cells.size()); - assertEquals(4, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + assertArrayEquals(new int[] {0, 0, 0, 0, 4}, row.getCells()); - assertEquals(2, row.getFoldableRows().size()); - ReportResource.RowResource foldedRow = row.getFoldableRows().get("attachement"); - assertEquals(ReportResource.SingleRowResource.class, foldedRow.getClass()); - assertEquals(2, foldedRow.getTotal()); - cells = foldedRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); - - foldedRow = row.getFoldableRows().get("N/A"); - assertEquals(ReportResource.SingleRowResource.class, foldedRow.getClass()); - assertEquals(2, foldedRow.getTotal()); - cells = foldedRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); - - assertEquals(ReportResource.FoldableRowResource.class, rows.get("key2").getClass()); - row = (ReportResource.FoldableRowResource) rows.get("key2"); + row = rows.get(1); + assertArrayEquals(new String[] {"key", "attachment"}, row.getDesc()); + assertEquals(1, row.getDepth()); + assertFalse(row.isDisplay()); assertEquals(2, row.getTotal()); - cells = row.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); - assertEquals(1, row.getFoldableRows().size()); - foldedRow = row.getFoldableRows().get("N/A"); - assertEquals(ReportResource.SingleRowResource.class, foldedRow.getClass()); - assertEquals(2, foldedRow.getTotal()); - cells = foldedRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + row = rows.get(2); + assertArrayEquals(new String[] {"key", "N/A"}, row.getDesc()); + assertEquals(1, row.getDepth()); + assertFalse(row.isDisplay()); + assertEquals(2, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); + + row = rows.get(3); + assertArrayEquals(new String[] {"key2", null}, row.getDesc()); + assertEquals(0, row.getDepth()); + assertTrue(row.isDisplay()); + assertEquals(2, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); + + row = rows.get(4); + assertArrayEquals(new String[] {"key2", "N/A"}, row.getDesc()); + assertEquals(1, row.getDepth()); + assertFalse(row.isDisplay()); + assertEquals(2, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); // sumRow - assertEquals(ReportResource.FoldableRowResource.class, resource.getSumRow().getClass()); - ReportResource.FoldableRowResource sumRow = (ReportResource.FoldableRowResource) resource.getSumRow(); - assertEquals(6, sumRow.getTotal()); - cells = sumRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(6, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); - assertEquals(2, sumRow.getFoldableRows().size()); - foldedRow = sumRow.getFoldableRows().get("attachement"); - assertEquals(ReportResource.SingleRowResource.class, foldedRow.getClass()); - assertEquals(2, foldedRow.getTotal()); - cells = foldedRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(2, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); + List sumRow = resource.getSumRow(); + assertEquals(1 + 2, sumRow.size()); + + row = sumRow.get(0); + assertArrayEquals(new String[] {"Total", null}, row.getDesc()); + assertEquals(0, row.getDepth()); + assertTrue(row.isDisplay()); + assertEquals(6, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 6}, row.getCells()); + + row = sumRow.get(1); + assertArrayEquals(new String[] {"Total", "attachment"}, row.getDesc()); + assertEquals(1, row.getDepth()); + assertFalse(row.isDisplay()); + assertEquals(2, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); + + row = sumRow.get(2); + assertArrayEquals(new String[] {"Total", "N/A"}, row.getDesc()); + assertEquals(1, row.getDepth()); + assertFalse(row.isDisplay()); + assertEquals(4, row.getTotal()); + assertArrayEquals(new int[] {0, 0, 0, 0, 4}, row.getCells()); - foldedRow = sumRow.getFoldableRows().get("N/A"); - assertEquals(ReportResource.SingleRowResource.class, foldedRow.getClass()); - assertEquals(4, foldedRow.getTotal()); - cells = foldedRow.getCells(); - assertEquals(5, cells.size()); - assertEquals(4, cells.get("2019-01-01").intValue()); - assertEquals(0, cells.get("2018-12-31").intValue()); - assertEquals(0, cells.get("2018-12-30").intValue()); - assertEquals(0, cells.get("2018-12-29").intValue()); - assertEquals(0, cells.get("2018-12-28").intValue()); } - @Test - public void testExpandableHeader() { - //given - TimestampReport report = new TimestampReport(headers); - //when - ReportResource resource = reportAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); - //then - ReportResource.MetaInformation meta = resource.getMeta(); - assertEquals("TimestampReport", meta.getName()); - assertEquals("2019-01-02T00:00:00Z", meta.getDate()); - assertEquals("STATES", meta.getRowDesc()); - assertArrayEquals(headers.stream().map(TimeIntervalColumnHeader::getDisplayName).toArray(), meta.getHeader()); - assertArrayEquals(new String[] {"ORG LEVEL 1", "ORG LEVEL 2", "ORG LEVEL 3", "ORG LEVEL 4"}, - meta.getExpHeader()); - assertEquals("Total", meta.getTotalDesc()); - } } diff --git a/web/src/app/monitor/models/meta-info-data.ts b/web/src/app/monitor/models/meta-info-data.ts index 194e3536e..897f61480 100644 --- a/web/src/app/monitor/models/meta-info-data.ts +++ b/web/src/app/monitor/models/meta-info-data.ts @@ -1,8 +1,7 @@ export class MetaInfoData { + name: string; date: string; header: Array; - expHeader: Array; - name: string; - rowDesc: string; + rowDesc: Array; totalDesc: string; } diff --git a/web/src/app/monitor/models/report-data.ts b/web/src/app/monitor/models/report-data.ts index f8789405e..5d66fce40 100644 --- a/web/src/app/monitor/models/report-data.ts +++ b/web/src/app/monitor/models/report-data.ts @@ -1,8 +1,8 @@ -import { ReportInfoData } from './report-info-data'; -import { MetaInfoData } from './meta-info-data'; +import {ReportRow} from './report-row'; +import {MetaInfoData} from './meta-info-data'; export class ReportData { - meta: MetaInfoData; - rows: Map; - sumRow: ReportInfoData; + meta: MetaInfoData; + rows: Array; + sumRow: Array; } diff --git a/web/src/app/monitor/models/report-info-data.ts b/web/src/app/monitor/models/report-info-data.ts deleted file mode 100644 index 19eb2f288..000000000 --- a/web/src/app/monitor/models/report-info-data.ts +++ /dev/null @@ -1,12 +0,0 @@ -export class ReportInfoData { - cells: Map; - foldableRows: Map>; - total: number; -} - -export class ReportInfoDataIterable { - key: string; - val: ReportInfoData; - depth: number; - display = false; -} diff --git a/web/src/app/monitor/models/report-row.ts b/web/src/app/monitor/models/report-row.ts new file mode 100644 index 000000000..0200535fc --- /dev/null +++ b/web/src/app/monitor/models/report-row.ts @@ -0,0 +1,7 @@ +export class ReportRow { + cells: Array; + total: number; + depth: number; + desc: Array; + display = false; +} diff --git a/web/src/app/monitor/monitor.module.ts b/web/src/app/monitor/monitor.module.ts index 0850bb3b6..fcd57630a 100644 --- a/web/src/app/monitor/monitor.module.ts +++ b/web/src/app/monitor/monitor.module.ts @@ -14,7 +14,6 @@ import {MonitorComponent} from './monitor.component'; import {TasksComponent} from './tasks/tasks.component'; import {WorkbasketComponent} from './workbasket/workbasket.component'; import {ClassificationTasksComponent} from './classification-tasks/classification-tasks.component'; -import {ReportRowComponent} from './report/row/row.component'; import {TimestampComponent} from './timestamp/timestamp.component'; import {RestConnectorService} from './services/restConnector/rest-connector.service'; @@ -38,8 +37,7 @@ const DECLARATIONS = [ ReportComponent, MonitorComponent, ClassificationTasksComponent, - TimestampComponent, - ReportRowComponent + TimestampComponent ]; @NgModule({ diff --git a/web/src/app/monitor/report/report.component.html b/web/src/app/monitor/report/report.component.html index 0eb074d74..cd4b16444 100644 --- a/web/src/app/monitor/report/report.component.html +++ b/web/src/app/monitor/report/report.component.html @@ -1,30 +1,64 @@ -
+
-
{{reportData.meta.rowDesc}}
- - -
{{header}}
-
+ +
{{header}}
{{header}}
{{reportData.meta.totalDesc}}
- - +
+ +
+ +
+ {{ canRowCollapse(i) ? "expand_more" : "expand_less"}} + {{header}} +
+
+
+ {{val}} +
+
+ {{row.total}} +
+
+
+
+
diff --git a/web/src/app/monitor/report/report.component.scss b/web/src/app/monitor/report/report.component.scss index 0e0b41ea1..14252e1bd 100644 --- a/web/src/app/monitor/report/report.component.scss +++ b/web/src/app/monitor/report/report.component.scss @@ -1,3 +1,20 @@ .report { margin-top: 20px; } + +.table-cell--clickable { + cursor: pointer; +} + +.table-row--highlight, +.table-row--hover:hover { + background-color: #f9f9f9; +} + +.table-row--highlight > .table-cell { + border-bottom: 2px solid #ddd; +} + +.table-row--white { + background-color: white !important; +} \ No newline at end of file diff --git a/web/src/app/monitor/report/report.component.ts b/web/src/app/monitor/report/report.component.ts index 047037f23..3c50323c8 100644 --- a/web/src/app/monitor/report/report.component.ts +++ b/web/src/app/monitor/report/report.component.ts @@ -1,6 +1,5 @@ import {Component, Input, OnInit} from '@angular/core'; import {ReportData} from 'app/monitor/models/report-data'; -import {ReportInfoDataIterable} from '../models/report-info-data'; @Component({ selector: 'taskana-report', @@ -10,24 +9,10 @@ import {ReportInfoDataIterable} from '../models/report-info-data'; export class ReportComponent implements OnInit { - expHeaders: Array; currentExpHeaders = 0; - _sumRow: ReportInfoDataIterable; - - private _reportData: ReportData; - - get reportData(): ReportData { - return this._reportData; - } @Input() - set reportData(reportData: ReportData) { - this._reportData = reportData; - this.expHeaders = new Array(Object.keys(reportData.rows).length + 1).fill(0); - this._sumRow = new ReportInfoDataIterable(); - this._sumRow.val = reportData.sumRow; - this._sumRow.key = reportData.meta.totalDesc; - } + reportData: ReportData; constructor() { } @@ -35,10 +20,30 @@ export class ReportComponent implements OnInit { ngOnInit(): void { } - expandHeader(depth: number, index: number) { - this.expHeaders[index] = depth; - this.currentExpHeaders = Math.max(...this.expHeaders); + toggleFold(index: number, sumRow: boolean = false) { + const rows = sumRow ? this.reportData.sumRow : this.reportData.rows; + const toggleRow = rows[index++]; + if (toggleRow.depth < this.reportData.meta.rowDesc.length - 1) { + const firstChildRow = rows[index++]; + firstChildRow.display = !firstChildRow.display; + + let end = false; + for (let i = index; i < rows.length && !end; i++) { + const row = rows[i]; + end = row.depth <= toggleRow.depth; + if (!end) { + row.display = firstChildRow.display && row.depth === firstChildRow.depth; + } + } + this.currentExpHeaders = Math.max( + ...this.reportData.rows.filter(r => r.display).map(r => r.depth), + ...this.reportData.sumRow.filter(r => r.display).map(r => r.depth) + ); + } } - + canRowCollapse(index: number, sumRow: boolean = false) { + const rows = sumRow ? this.reportData.sumRow : this.reportData.rows; + return !rows[index + 1].display; + } } diff --git a/web/src/app/monitor/report/row/row.component.html b/web/src/app/monitor/report/row/row.component.html deleted file mode 100644 index bd126e8f1..000000000 --- a/web/src/app/monitor/report/row/row.component.html +++ /dev/null @@ -1,28 +0,0 @@ - - -
-
-
- {{ canRowCollapse(i) ? "expand_more" : "expand_less"}}{{row.key}} -
-
-
- {{row.val.cells[header]}} -
-
- {{row.val.total}} -
-
-
-
\ No newline at end of file diff --git a/web/src/app/monitor/report/row/row.component.scss b/web/src/app/monitor/report/row/row.component.scss deleted file mode 100644 index 5c05b6101..000000000 --- a/web/src/app/monitor/report/row/row.component.scss +++ /dev/null @@ -1,19 +0,0 @@ -@import './src/assets/_colors'; - - -.table-cell--clickable { - cursor: pointer; -} - -.table-row--highlight, -.table-row--hover:hover { - background-color: #f9f9f9; -} - -.table-row--highlight > .table-cell { - border-bottom: 2px solid #ddd; -} - -.table-row--white { - background-color: white; -} \ No newline at end of file diff --git a/web/src/app/monitor/report/row/row.component.ts b/web/src/app/monitor/report/row/row.component.ts deleted file mode 100644 index 898e91206..000000000 --- a/web/src/app/monitor/report/row/row.component.ts +++ /dev/null @@ -1,81 +0,0 @@ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {ReportInfoDataIterable} from '../../models/report-info-data'; -import {MapToIterable} from '../../../shared/pipes/mapToIterable/mapToIterable'; - -@Component({ - selector: 'taskana-report-row', - templateUrl: './row.component.html', - styleUrls: ['./row.component.scss'] -}) -export class ReportRowComponent implements OnInit { - - @Input() - headers: Array; - @Input() - bold = false; - @Input() - maxTableDepth = 0; - @Output() - expandedDepth: EventEmitter = new EventEmitter(); - currentDepth = 0; - maxDepth: number; - flatRows: Array; - - private _row: ReportInfoDataIterable; - - get row(): ReportInfoDataIterable { - return this._row; - } - - @Input() - set row(row: ReportInfoDataIterable) { - this._row = row; - this.flatRows = new Array(); - this.maxDepth = this.flatten(row, 0); - } - - constructor(private mapToIterable: MapToIterable) { - } - - ngOnInit() { - } - - toggleFold(index: number): void { - const toggleRow = this.flatRows[index++]; - if (toggleRow.depth < this.maxDepth) { - const firstChildRow = this.flatRows[index++]; - firstChildRow.display = !firstChildRow.display; - - let end = false; - for (let i = index; i < this.flatRows.length && !end; i++) { - const row = this.flatRows[i]; - end = row.depth <= toggleRow.depth; - if (!end) { - row.display = firstChildRow.display && row.depth === firstChildRow.depth; - } - } - this.currentDepth = Math.max(...this.flatRows.filter(r => r.display).map(r => r.depth)); - this.expandedDepth.emit(this.currentDepth); - } - } - - range(depth: number): Array { - return new Array(Math.max(depth, 0)); - } - - canRowCollapse(index: number) { - return !this.flatRows[index + 1].display; - } - - private flatten(row: ReportInfoDataIterable, depth: number): number { - row.depth = depth; - row.display = depth === 0; - this.flatRows.push(row); - if (row.val.foldableRows) { - depth = Math.max(...this.mapToIterable.transform(row.val.foldableRows) - .sort((a, b) => a.key.localeCompare(b.key)) - .map(r => this.flatten(r, depth + 1))); - } - return depth; - } -} diff --git a/web/src/app/monitor/tasks/tasks.component.ts b/web/src/app/monitor/tasks/tasks.component.ts index 8feb13596..d83743e17 100644 --- a/web/src/app/monitor/tasks/tasks.component.ts +++ b/web/src/app/monitor/tasks/tasks.component.ts @@ -1,6 +1,6 @@ -import { Component, OnInit } from '@angular/core'; -import { RestConnectorService } from '../services/restConnector/rest-connector.service'; -import { ReportData } from 'app/monitor/models/report-data'; +import {Component, OnInit} from '@angular/core'; +import {RestConnectorService} from '../services/restConnector/rest-connector.service'; +import {ReportData} from 'app/monitor/models/report-data'; @Component({ selector: 'taskana-monitor-tasks', @@ -21,10 +21,8 @@ export class TasksComponent implements OnInit { ngOnInit() { this.restConnectorService.getTaskStatusReport().subscribe((data: ReportData) => { this.reportData = data; - this.pieChartLabels = Object.keys(data.sumRow.cells); - Object.keys(data.sumRow.cells).forEach(key => { - this.pieChartData.push(data.sumRow.cells[key]); - }) + this.pieChartLabels = data.meta.header; + data.sumRow[0].cells.forEach(c => this.pieChartData.push(c)); })