Laravel 9 Calculate minute difference same_id all the data in the table individually - laravel-9

I had already opened a discussion about this and I was given a solution only that the solution calculates everything continuous without interrupting every different same_id, I should finish counting when same_id changes and start counting again, does anyone have ideas to help me solve this problem?
<table>
<thead>
<tr>
<th>id</th>
<th>timestamp</th>
<th>states</th>
<th>same_id</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2023-01-11 15:26:23</td>
<td>NotAvailable</td>
<td>80</td>
<td>2</td>
<td>2023-01-11 15:26:55</td>
<td>ToBeAssigned</td>
<td>80</td>
<td>3</td>
<td>2023-01-11 15:27:06</td>
<td>Assigned</td>
<td>80</td>
<td>3</td>
<td>2023-01-11 15:27:19</td>
<td>TakingCharge</td>
<td>80</td>
<td>4</td>
<td>2023-01-11 15:29:05</td>
<td>Closed</td>
<td>80</td>
</tr>
</tbody>
</table>
the solution that was proposed to me and it works is this but it doesn't stop counting when the same_id changes and I should do this
<table>
<thead>
<tr>
<th>id</th>
<th>timestamp</th>
<th>states</th>
<th>delay</th>
</tr>
</thead>
<tbody>
#foreach((array)$tickets_logs as $i => $ticket_log)
<tr>
<td>{{ $ticket_log['id'] }}</td>
<td>{{ __($ticket_log['states']) }}</td>
<td>{{ $ticket_log['time_stamp'] }}</td>
<td>
#if(!$loop->first)
{{ (new Carbon\Carbon($tickets_logs[$i - 1]['time_stamp']))->diffInMinutes((new Carbon\Carbon($ticket_log['time_stamp']))) }}
#else
-
#endif
</td>
</tr>
#endforeach
</tbody>
</table>

Related

Custom widgets: The equivalent of Mako's <%def> in Jinja2 or Django templates

I am quite proficient with Mako, but never actually used Jinja or Django templates.
What is Jinja/Django equivalent of Mako <%def name="..."> definition?
Following is a simplified example of my actual use case. I need to define a simple table and use it repeatedly on the page:
<%def name="temperature_table(north, east, south, west)">
<table>
<tr>
<td>North:</td>
<td>${north}</td>
</tr>
<tr>
<td>East:</td>
<td>${east}</td>
</tr>
<tr>
<td>South:</td>
<td>${south}</td>
</tr>
<tr>
<td>West:</td>
<td>${west}</td>
</tr>
</table>
</%def>
<h2>Morning</h2>
${weather_table(20, 21, 22, 23)}
<h2>Afternoon</h2>
${weather_table(22, 22, 25, 24)}
<h2>Night</h2>
${weather_table(17, 16, 17, 18)}
From what I gleaned from various articles, it could seem that blocks are used for this purpose in Jinja/Django. But blocks would introduce inheritance even to simple templates where a custom widget would be sufficient. Other authors suggest creating a custom tag, but, in my opinion, this would require to write custom parsing, rendering, and probably even custom cache managing functions. Am I missing something?
You can use a macro for that.
As described in the manual:
Macros are comparable with functions in regular programming languages. They are useful to put often used idioms into reusable functions to not repeat yourself (“DRY”).
Source: https://jinja.palletsprojects.com/en/3.0.x/templates/#macros
So, given:
{% macro weather_table(north, east, south, west) -%}
<table>
<tr>
<td>North:</td>
<td>{{ north }}</td>
</tr>
<tr>
<td>East:</td>
<td>{{ east }}</td>
</tr>
<tr>
<td>South:</td>
<td>{{ south }}</td>
</tr>
<tr>
<td>West:</td>
<td>{{ west }}</td>
</tr>
</table>
{%- endmacro %}
<h2>Morning</h2>
{{ weather_table(20, 21, 22, 23) }}
<h2>Afternoon</h2>
{{ weather_table(22, 22, 25, 24) }}
<h2>Night</h2>
{{ weather_table(17, 16, 17, 18) }}
It renders your expected tables.
<h2>Morning</h2>
<table>
<tr>
<td>North:</td>
<td>20</td>
</tr>
<tr>
<td>East:</td>
<td>21</td>
</tr>
<tr>
<td>South:</td>
<td>22</td>
</tr>
<tr>
<td>West:</td>
<td>23</td>
</tr>
</table>
<h2>Afternoon</h2>
<table>
<tr>
<td>North:</td>
<td>22</td>
</tr>
<tr>
<td>East:</td>
<td>22</td>
</tr>
<tr>
<td>South:</td>
<td>25</td>
</tr>
<tr>
<td>West:</td>
<td>24</td>
</tr>
</table>
<h2>Night</h2>
<table>
<tr>
<td>North:</td>
<td>17</td>
</tr>
<tr>
<td>East:</td>
<td>16</td>
</tr>
<tr>
<td>South:</td>
<td>17</td>
</tr>
<tr>
<td>West:</td>
<td>18</td>
</tr>
</table>

angular table header widths dont line up after making the header a component

So this is a basic table
<table class="table table-striped">
<thead>
<th scope="col">Name</th>
<th scope="col">City</th>
<th scope="col">State</th>
</thead>
<tbody>
<tr *ngFor="let data of Array">
<td>{{ data.name }}</td>
<td>{{ data.city }}</td>
<td>{{ data.state }}</td>
</tr>
</tbody>
</table>
But when I take the header and put it into a component the widths of the headers dont match the width of the table columns
<table class="table table-striped">
<thead>
<app-tableheader></app-tableheader>
</thead>
<tbody>
<tr *ngFor="let data of Array">
<td>{{ data.name }}</td>
<td>{{ data.city }}</td>
<td>{{ data.state }}</td>
</tr>
</tbody>
</table>
and here is the component now with the same html
<tr>
<th scope="col">Name</th>
<th scope="col">City</th>
<th scope="col">State</th>
</tr>
So I dont quite understand what I'm missing here. New to componetizing angular.

rowSpan hides rows

<table>
<tr> <td rowspan="2">1</td> <td>2</td> </tr>
<tr> <td rowspan="2">3</td> </tr>
<tr> <td>4</td> </tr>
</table>
seemingly only displays two rows:
The reason for hiding the second row [1 3] is, that the cells with text 1 and 3 are reduced in height. Is there a way to ensure, that the second row is visible in the display (not only in DOM)?
The problem gets clearer, if you look at the same table with an additional column:
<table>
<tr> <td rowspan="2">1</td> <td>2</td> <td>0</td> </tr>
<tr> <td rowspan="2">3</td> <td>0</td> </tr>
<tr> <td>4</td> <td>0</td> </tr>
</table>
which is displayed like:
You can add a height property to the row:
<table border=1>
<tr>
<td rowspan="2">1</td>
<td>2</td>
</tr>
<tr style="height: 1.5em">
<td rowspan="2">3</td>
</tr>
<tr>
<td>4</td>
</tr>
</table>
One suboptimal option could be to add an empty column:
<table>
<tr> <td rowspan="2">1</td> <td>2</td> <td class="void"></td> </tr>
<tr> <td rowspan="2">3</td> <td class="void"></td> </tr>
<tr> <td>4</td> <td class="void"></td> </tr>
</table>
CSS:
table,td {border:1px solid}
.void {height:1em;padding:0;border:0}
However, the spacing between columns leads to unnecessary space for the added column:
As this problem could be solved with padding-left for TD and a cellspacing of 0 for the table, this solution would not be general enough, so I'm still waiting for a good idea.

Move the content, not text, of a table's cell to the right

I have a series of nested tables, below I created a jsfiddle structure.
I was using the arab notation, ( direction: rtl ) which is obviously wrong. I can not find the right css that moves the content to the right.
I wish to recreate the same structure.
Without using direction: rtl; because this makes the text reversed too. Borders are only to highlight it better.
Thanks to anyone who can help me
https://jsfiddle.net/wo77wgL5/
<table width = "800px" border=3 class="centralTable">
<tr>
<th></th>
<th></th>
<th>header 1</th>
<th>header 2</th>
<th>header 3</th>
<th>header 4</th>
</tr>
<tbody>
<tr>
<td> </td>
<td> </td>
<td>Text 1</td>
<td>Text 2</td>
<td>Text 3</td>
<td>Text 4</td>
</tr>
<tr>
<td colspan=6 style= "direction:rtl;">
<table width = "500px" border=1 class="toTheRight">
<tr>
<th></th>
<th></th>
<th>header 11</th>
<th>header 22</th>
<th>header 33</th>
<th>header 44</th>
</tr>
<tbody>
<tr>
<td> </td>
<td> </td>
<td>Text 11</td>
<td>Text 22</td>
<td>Text 33</td>
<td>Text 44</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
You can use <td align="right">
https://jsfiddle.net/msp5m4k9

Nested tables with related parent content

Having a semantics issue. I have a basic table with a standard header and footer. Each row contains an order, beneath each row I need to display another table, that will contain a break down of costs relating to that order. Additionally, these inner tables will be displayed with a jQuery accordion to hide and show when required (but I'm just concentrating on the HTML for now)
How can I semantically approach this in HTML?
<table>
<thead>
<th>Package number</th>
<th>Date placed</th>
<th>Placed by</th>
<th>Total cost</th>
</thead>
<tr>
<td>1</td>
<td>Weds</td>
<td>Jonno</td>
<td>£15</td>
</tr>
<tr>
<td colspan="4">
<table>
<thead>
<th>Part number</th>
<th>Description</th>
<th>Qty shipped</th>
<th>Weight</th>
</thead>
<tbody>
<td>18293</td>
<td>Blah blah blah</td>
<td>72</td>
<td>20Kg</td>
</tbody>
</table>
</td>
</tr>
<tr>
<td>2</td>
<td>Thurs</td>
<td>Jonno</td>
<td>£1</td>
</tr>
<tr>
<td>3</td>
<td>Fri</td>
<td>Jonno</td>
<td>£7</td>
</tr>
</table>
Here's a fiddle: http://jsfiddle.net/yuW7f/ - The problem here is that the row containing the inner table, is totally unrelated to the order row
If you are looking for a parent element you can use to group related rows, you can use <tbody> elements. A table can have multiple <tbody> elements:
<table>
<thead>
<tr>
<th>Package number</th>
<th>Date placed</th>
<th>Placed by</th>
<th>Total cost</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Weds</td>
<td>Jonno</td>
<td>£15</td>
</tr>
<tr>
<td colspan="4">
<table>
<thead>
<tr>
<th>Part number</th>
<th>Description</th>
<th>Qty shipped</th>
<th>Weight</th>
</tr>
</thead>
<tbody>
<tr>
<td>18293</td>
<td>Blah blah blah</td>
<td>72</td>
<td>20Kg</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
<tr>
<td>2</td>
<td>Thurs</td>
<td>Jonno</td>
<td>£1</td>
</tr>
<tr>
<td>3</td>
<td>Fri</td>
<td>Jonno</td>
<td>£7</td>
</tr>
</table>
Whether or not that makes your code more semantically correct is debatable. You could also give your rows classes to indicate whether the row is a summary row or a detail row, or attributes to indicate relationships to other rows. Semantically, it seems fine as it is to me.
By the way, you are missing some <tr> elements. A <tbody>, <thead>, or <tfoot> element does not replace a <tr> element.