ngs-doo / TemplaterExamples

Creating reports in .NET and Java
https://templater.info
The Unlicense
48 stars 27 forks source link

Data inconsistencies #31

Closed tecxx closed 3 years ago

tecxx commented 3 years ago

Hello, i'm very interested to put this library into our inhouse management software, but before we decide to go ahead and buy a license we'd like to get some basic tests working.

this is the word template: image

and this is the result: image

here's the simplified data model:

    public class ReportingRootObject
    {
        public Reporting_PlaceholderData Data;
        public List<Reporting_ScopeContainerChecks> checksInScope { get; set; }
    }
    public class Reporting_ScopeContainerChecks
    {
        public string scopeName;
        public List<Reporting_CheckInScope> scopeData { get; set; }
    }
    public class Reporting_CheckInScope
    {
        public string group;
        public string category;
        public string id;
        public string title;
        public string reasoning;
        public List<string> referenceUrls;
        public List<string> referenceUrlsMitre;
        public int rating;
        public int findingsCount;
        public List<Reporting_CheckTask> checkTasks { get; set; }
        public List<Reporting_Finding> findings { get; set; }
        public List<Reporting_Measure> measures { get; set; }
    }

and here's the debugger, to prove the data model is correct: image

edit: just remembered, this project is on .net 5 rc2. is this supported?

zapov commented 3 years ago

Hi @tecxx

It should work fine on latest .NET

Can you please upload the template. And it would be very helpful to provide some code to recreate the data, or JSON representing the same data.

tecxx commented 3 years ago

here is the stripped down template, removed all but the relevant parts https://web.tresorit.com/l/zT5AQ#1HNFzKegL9t1EIqENW8D5Q for code&json i try to provide a sample project in the coming days

zapov commented 3 years ago

Tnx. I took a look at your example... and there are two main issues: 1) you probably want to put checksInScope.scopeData.findings in something resizable, like a list (or nested table) 2) there is a bug with .Count handling in checksInScope.scopeData.findings which I'll fix in next version, but you can work around it like you did, or via some other plugin.

So the main problem in 1) is that when there are 0 findings, resize(tags, 0) gets called, which deletes the whole row. You probably want to remove only the part related to finding listing, but for that to work as expected you need to put it into a nested resizable object

The problem 2) looks like a bad handling of resize 0 and property of a list. You can actually make a workaround by using {{checksInScope.scopeData.findings}:count} to avoid adding the extra findingsCount property on a list... by registering a formater which will return number of elements in a collection

zapov commented 3 years ago

Also, instead of using different nesting element, you can put the entire findings in second row, merge cells in other columns and setup borders on table/cells. TemplatePentestReport.docx

I've tested with this JSON:

{"checksInScope":{"scopeData":[
    {"id":"1","title":"t1","findingsCount":2,"findings":[
        {"id":"f1","title":"ft1","rating":"fr1"},
        {"id":"f2","title":"ft2","rating":"fr2"}
    ]},
    {"id":"2","title":"t2","findingsCount":0,"findings":[
    ]},
    {"id":"3","title":"t3","findingsCount":3,"findings":[
        {"id":"f5","title":"ft5","rating":"fr5"},
        {"id":"f6","title":"ft6","rating":"fr6"},
        {"id":"f7","title":"ft7","rating":"fr7"}
    ]},
]}}
tecxx commented 3 years ago

thanks for your prompt reply. adding a table for findings worked (and now also .Count shows the correct result). now i understand what you mean in your documentation with "table without borders", so in case something repeats we should simply add a "dummy" table as a repeating element?

regarding your second reply, i tried that as well and understand what you suggest. could you check the file that you uploaded though? it contains just my original table, was that your intention?

thanks again - i will close this and continue some more tests.

zapov commented 3 years ago

Yes, I removed everything else, just to showcase that part

tecxx commented 3 years ago

i'm still not over the basics, could you be so kind and answer me one more question.

i am trying to show "no data" when a collection is empty. based on the documentation i should use [[tag]:empty(string)] while this works when the collection is actually empty ("no data" is shown), it displays a very strange output when data exists:

image

image

zapov commented 3 years ago

Its calling to string on the object. You need to put additional metadata on it (or write your own instead of empty) - eg: hide There is an example here: https://github.com/ngs-doo/TemplaterExamples/tree/master/Intermediate/CollapseRegion

tecxx commented 3 years ago

thanks, i could solve it!