Doctrine2 Nested Set rendering as a table with indentation - doctrine-orm

I have categories structure (using Gedmo Nested Tree extension for Doctrine2) like in the example:
https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md#tree-entity-example
The question is how to display all the tree as a table like this:
<table>
<tr>
<td>Category-1 name</td>
<td>Category-1 other data</td>
</tr>
<tr>
<td>Category-2 name</td>
<td>Category-2 other data</td>
</tr>
<tr>
<td><span class="indent">---</span>Subcategory-2-1 name</td>
<td>Subcategory-2-1 other data</td>
</tr>
<tr>
<td><span class="indent">---</span><span class="indent">---</span>Subcategory-2-1-1 name</td>
<td>Subcategory-2-1-1 other data</td>
</tr>
<tr>
<td>Category-3 name</td>
<td>Category-3 other data</td>
</tr>
</table>
Another words, I need to get the tree as a plain list with Level param in 1 query.
I found a way to get the list only as array (getNodesHierarchy), but I need to have it as a collection like if I called findAll()

Found the solution:
class CategoryRepository extends NestedTreeRepository
{
public function getTreeList()
{
return $this->getNodesHierarchyQuery()->getResult();
}
}

Related

Jinja2 Repeats Table Rows When Reloading Page

I have a 'dashboard' page that comes up after a user selects a project that they'd like to inspect the details on. Some of these details are displayed in a table format. Below is a portion of the Jinja2 template:
`
{% if release_container.nreleases > 0 %}
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Date Created</th>
<th scope="col">Status</th>
<th scope="col">Date Released</th>
</tr>
</thead>
<tbody>
{% for rh in release_container.release_history %}
<tr>
<td>{{rh.name}}</td>
<td>{{rh.creation_date}}</td>
<td>{{rh.status}}</td>
<td>{{rh.release_date}}</td>
</tr>
{% endfor %}
</tbody>
</table><!--ends table-->
{% endif %}
`
If I reload the page, or click on a link and then come back to the page, the same data will get appended. As an example, here's the HTML from a 'fresh' load, which is what I should look like after a reload as well:
`
<tbody>
<tr>
<td>v0.1</td>
<td>2022-11-10</td>
<td>False</td>
<td>2022-11-10</td>
</tr>
<tr>
<td>v0.2</td>
<td>2022-11-17</td>
<td>False</td>
<td>2022-11-17</td>
</tr>
</tbody>
`
But this is what it looks like when the page is reloaded:
`
<tbody>
<tr>
<td>v0.1</td>
<td>2022-11-10</td>
<td>False</td>
<td>2022-11-10</td>
</tr>
<tr>
<td>v0.2</td>
<td>2022-11-17</td>
<td>False</td>
<td>2022-11-17</td>
</tr>
<tr>
<td>v0.1</td>
<td>2022-11-10</td>
<td>False</td>
<td>2022-11-10</td>
</tr>
<tr>
<td>v0.2</td>
<td>2022-11-17</td>
<td>False</td>
<td>2022-11-17</td>
</tr>
</tbody>
`
What do I need to do in order to stop this from happening? I presume this is some kind of cache setting?
Thank you in advance for any assistance.
I've debugged the code by printing out the lengths of the various arrays to see if they change on reload, thinking that the data was being appended to the array, but the length remains '2', even though 4 different entries are rendered.
EDIT
A commenter asked to see the view code. At this point in time, it's a huge function that generates the containers that get passed to the template (which is just one template amongst half a dozen that gets passed), and I'll be refactoring that code shortly into more palatable bites, but hopefully the snippet below provides more context:
for release in releases:
rhistory_container = ProjectDashboardReleaseHistoryContainer()
rhistory_container.rid = release.id
rhistory_container.name = release.name
rhistory_container.creation_date = release.created
rhistory_container.status = release.is_active
release_container.release_history.append(rhistory_container)
"""
"""
return render_template('project_home.html',parent_container=parent_container,release_container=release_container,testing_container=testing_container,reqs_container=reqs_container,sw_container=sw_container,hw_container=hw_container)

Openoffice Calc VLOOKUP with multiple sheets

I am working with this data in Apache OpenOffice 4.1.2 with the goal of a vlookup that allows for cross sheet lookup of data in Sheet1 being added to Sheet2 base on the column pn. Here is the equation I have now but its not lining up right now. Any suggestions/corrections welcome.
In Sheet 2 using this.
=VLOOKUP(A2; Sheet1.A2:Sheet1.C500; 2; 1)
From What I understand Im expecting the code to return the information in the name column from Sheet1 based on the match of the pn column across all 500 rows.
Sheet1<br>
<table>
<thead>
<tr>
|<th>code</th>|
|<th>name</th>|
|<th>pn</th>|
</tr>
</thead>
<br>
<tbody>
<tr>
|<td>111</td>|
|<td>one</td>|
|<td>101</td>|
</tr>
<br>
<tr>
|<td>112</td>|
|<td>two</td>|
|<td>102</td>|
</tr>
</table>
<br>
Sheet2<br>
<table>
<thead>
<tr>
|<th>pn</th>|
|<th>qty</th>|
|<th>cur</th>|
</tr>
</thead>
<br>
<tbody>
<tr>
|<td>102</td>|
|<td>200</td>|
|<td> $ </td>|
</tr>
<br>
<tr>
|<td>101</td>|
|<td>150</td>|
|<td> $ </td>|
</tr>
</table>

How to get date input from table created using for loop in django?

So I have passed a context from views.py to my html template.
I have created a html table using 'For Loop' in the following way and also added a column with input date field.
<table class="table">
<thead style="background-color:DodgerBlue;color:White;">
<tr>
<th scope="col">Barcode</th>
<th scope="col">Owner</th>
<th scope="col">Mobile</th>
<th scope="col">Address</th>
<th scope="col">Asset Type</th>
<th scope="col">Schhedule Date</th>
<th scope="col">Approve Asset Request</th>
</tr>
</thead>
<tbody>
{% for i in deliverylist %}
<tr>
<td class="barcode">{{i.barcode}}</td>
<td class="owner">{{i.owner}}</td>
<td class="mobile">{{i.mobile}}</td>
<td class="address">{{i.address}}</td>
<td class="atype">{{i.atype}}</td>
<td class="deliverydate"><input type="date"></td>
<td><button id="schedulebutton" onclick="schedule({{forloop.counter0}})" style="background-color:#288233; color:white;" class="btn btn-indigo btn-sm m-0">Schedule Date</button></td>
</tr>
{% endfor %}
</tbody>
Now I would like to get that date element value in javascript, but its proving difficult since I am assigning a class instead of id(as multiple elements cant have same id).
I tried in the following way but its not working. The console log shows no value in that variable.
<script> //i is the iteration number passed in function call using forloop.counter0
function schedule(i){
var deldate = document.getElementsByClassName("deliverydate");
deldate2 = deldate[i].innerText;
console.log(deldate2); //log shows no value/empty
console.log(i); //log shows iteration number
</script>

Multidimensional list in Thymeleaf (Java) - List<List<Object>>

Have anyone of you any suggestion, how to iterate through a multidimensional list in Thymeleaf?
My multidimensional list looks as follow:
#Override
public List<List<PreferredZone>> findZonesByPosition(List<Position> positionList) {
List <PreferredZone> prefZone = new ArrayList<>();
List<List<PreferredZone>> listPrefZone = new ArrayList<>();
long positionId = 0;
for (int i = 0; i < positionList.size(); i++) {
positionId = positionList.get(i).getPositionId();
prefZone = prefZoneDAO.findFilteredZone(positionId);
listPrefZone.add(prefZone);
}
return listPrefZone;
}
In my controller as attribute:
List<List<PreferredZone>> prefZoneList = prefZoneService.findZonesByPosition(positionList);
model.addAllAttributes(prefZoneList);
Finally I try to iterate this two dimensional list in a HTML table:
<table th:each="prefList :#{prefZoneList}" class="table table-striped display hover">
<thead>
<tr>
<th>ISO</th>
<th>Name</th>
<th>Ausschluss</th>
</tr>
</thead>
<!-- Loop für die Daten -->
<tr th:each="row, iterState :${prefList}" class="clickable-row">
<td th:text="${row[__${iterState.index}__]}.zoneIso"></td>
<td th:text="${row[__${iterState.index}__]}.zoneName"></td>
<td style="text-align:center;">
<input type="checkbox" th:value="${${row[__${iterState.index}__]}.zoneId}" id="zone" class="checkbox-round" />
</td>
</tr>
</table>
It doesn't work however. I don't have any other idea how to solve this.
I have to have a multidimensional list, because I have got a table with multiple records and each record contains a button to open a modal window. Each of this windows contains either a HTML table where I have to display the records.
Have you got any suggestion for me?
You have a mistake in #{prefZoneList} and (as noted in comments) in using iterState.index
Try it:
<table th:each="prefList : ${prefZoneList}" class="table table-striped display hover">
<thead>
<tr>
<th>ISO</th>
<th>Name</th>
<th>Ausschluss</th>
</tr>
</thead>
<tr th:each="row : ${prefList}" class="clickable-row">
<td th:text="${row.zoneIso}"></td>
<td th:text="${row.zoneName}"></td>
<td style="text-align:center;">
<input type="checkbox" th:value="${row.zoneId}" id="zone" class="checkbox-round" />
</td>
</tr>
</table>
Syntax #{...} - a message Expressions
iterState.index is the current iteration index, starting with 0, using like ${prefList[__${iterState.index}__].element} where element - filed in prefList.

Validating html-style table data with XSLT

I need to be able to check xml with html-style table data to ensure that it's "rectangular". For example this is rectangular (2x2)
<table>
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
</tr>
</table>
This is not
<table>
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
<tr>
<td>Baz</td>
</tr>
</table>
This is complicated by row and column spans and the fact that I need to accept two styles of markup, either where spanned cells are included as empty td or where span cells are omitted.
<!-- good (3x2), spanned cells included -->
<table>
<tr>
<td colspan="2">Foo</td>
<td/>
<td rowspan="2">Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
<td/>
</tr>
</table>
<!-- also good (3x2), spanned cells omitted -->
<table>
<tr>
<td colspan="2">Foo</td>
<td rowspan="2">Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
</tr>
</table>
Here are a bunch of examples of bad tables where it's ambiguous how to deal with them
<!-- bad, looks like spanned cells are included but more cells in row 1 than 2 -->
<table>
<tr>
<td colspan="2">Foo</td>
<td/>
<td rowspan="2">Bar</td>
<td>BAD</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
<td/>
</tr>
</table>
<!-- bad, looks like spanned cells are omitted but more cells in row 1 than 2 -->
<table>
<tr>
<td colspan="2">Foo</td>
<td rowspan="2">Bar</td>
<td>BAD</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
</tr>
</table>
<!-- bad, can't tell if spanned cells are included or omitted -->
<table>
<tr>
<td colspan="2">Foo</td>
<td rowspan="2">Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
<td/>
</tr>
</table>
<!-- bad, looks like spanned cells are omitted but a non-emtpy cell is overspanned -->
<table>
<tr>
<td colspan="2">Foo</td>
<td rowspan="2">Bar</td>
</tr>
<tr>
<td>Baz</td>
<td>Qux</td>
<td>BAD</td>
</tr>
</table>
I already have a working XSLT 2.0 solution for this problem that involves normalizing the data to the "spanned cells included" style then validating, however, my solution is cumbersome and starts to perform poorly for tables with an area of greater than 1000 cells. My normalization and validation routines involve iterating sequentially over the cells and passing along a param of cells that should be created by spans and inserting them when I pass their coordinates in the table. I'm not happy with either of them.
I'm looking for suggestions about cleverer ways in which to achieve this validation that hopefully would have better performance profiles on large tables. I need to account for th and td but omitted th from the examples for sake of simplicity, they can be included or ignored in any answers. I'm not checking to see if thead, tbody, and/or tfoot have the same width, this can also be included or omitted. I'm currently using XSLT 2.0 but I'd be interested in 3.0 solutions if they were significantly better than a solution implemented in 2.0.
I don't think this kind of problem is suited for XSLT - especially if you have to process very large tables.
I'd suggest to develop a solution using a procedural languge - maybe using XSLT to pre- or post- process the XML.