Skip to content

Commit e0b7193

Browse files
author
Francois Suter
committed
[FEATURE] Add grouping by rows
Option is switchable with a checkbox. Change-Id: Ib9855641ed0ffb96ebe35f2008f91d9cb383f0bb Resolves: #78058 Releases: 3.0 Reviewed-on: https://review.typo3.org/50456 Reviewed-by: Francois Suter <[email protected]> Tested-by: Francois Suter <[email protected]>
1 parent 8d4746e commit e0b7193

File tree

7 files changed

+85
-6
lines changed

7 files changed

+85
-6
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2016-10-31 Francois Suter <[email protected]>
2+
3+
* Added an option to visually group rows by run, resolves #78058
4+
15
2016-10-30 Francois Suter <[email protected]>
26

37
* Restored and improved log clearing feature, resolves #76972

Classes/Utility/Logger.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ public function __construct()
6161
// Read the extension configuration
6262
$this->extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
6363

64-
// Use microtime as unique ID (in format "sec.msec")
65-
$microtimeParts = explode(' ', microtime());
66-
$this->runId = $microtimeParts[1] . $microtimeParts[0];
64+
// Generate a unique ID, including the global timestamp
65+
$this->runId = $GLOBALS['EXEC_TIME'] . uniqid('.', true);
6766

6867
// Create a list of instances of each available log writer
6968
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['devlog']['writers'] as $logWriterClass) {

Resources/Private/Language/JavaScript.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
<trans-unit id="1year" xml:space="preserve">
4848
<source>1 year</source>
4949
</trans-unit>
50+
<trans-unit id="run_start" xml:space="preserve">
51+
<source>Run started at %s</source>
52+
</trans-unit>
5053
<trans-unit id="clear_confirm_title" xml:space="preserve">
5154
<source>Are you sure?</source>
5255
</trans-unit>

Resources/Private/Language/locallang.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<trans-unit id="autoReload" xml:space="preserve">
4343
<source>Automatic reload</source>
4444
</trans-unit>
45+
<trans-unit id="groupRuns" xml:space="preserve">
46+
<source>Group runs</source>
47+
</trans-unit>
4548
<trans-unit id="log_time" xml:space="preserve">
4649
<source>Log time</source>
4750
</trans-unit>

Resources/Private/Templates/ListModule/Index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ <h1><f:translate id="title" /></h1>
2626
</label>
2727
</div>
2828
</div>
29+
<div class="form-group">
30+
<div class="checkbox">
31+
<label>
32+
<input type="checkbox" name="groupruns" id="tx_devlog_groupruns" value="groupruns">
33+
<f:translate id="groupRuns" />
34+
</label>
35+
</div>
36+
</div>
2937
</div>
3038
</form>
3139
<div class="clearfix"></div>
@@ -98,6 +106,7 @@ <h1><f:translate id="title" /></h1>
98106
<f:translate id="extraData" />
99107
<span id="tx_devlog_expand_all_icon"><core:icon identifier="actions-view-list-expand" /></span>
100108
</th>
109+
<th class="entry-id hidden">&nbsp;</th>
101110
</tr>
102111
</thead>
103112
</table>

Resources/Public/JavaScript/ListModule.js

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ define(['jquery',
4848
noEntriesMessage: null,
4949
lastUpdateTime: null,
5050
intervalID: 0,
51+
groupRuns: false,
5152
// List columns to avoid hard-coding numbers all over the code
5253
columns: {
54+
crdate: 0,
5355
severity: 1,
5456
key: 2,
5557
ip: 5,
5658
page: 6,
57-
user: 7
59+
user: 7,
60+
id: 9
5861
},
5962
filters: []
6063
};
@@ -122,9 +125,10 @@ define(['jquery',
122125
DevlogListModule.table = DevlogListModule.tableView.DataTable({
123126
data: data,
124127
dom: 'tp',
125-
// Default ordering is "crdate" column
128+
// Default ordering is "run_id" and "crdate" columns
126129
order: [
127-
[0, 'desc']
130+
[DevlogListModule.columns.id, 'desc'],
131+
[DevlogListModule.columns.crdate, 'desc']
128132
],
129133
mark: true,
130134
columnDefs: [
@@ -201,12 +205,40 @@ define(['jquery',
201205
return data;
202206
}
203207
}
208+
},
209+
{
210+
targets: 'entry-id',
211+
data: 'run_id',
212+
visible: false
204213
}
205214
],
215+
// Group rows according to runs (reference: https://datatables.net/examples/advanced_init/row_grouping.html)
216+
drawCallback: function() {
217+
// Act only if runs should be grouped
218+
if (!DevlogListModule.groupRuns) {
219+
return;
220+
}
221+
var api = this.api();
222+
var rows = api.rows({page: 'current'}).nodes();
223+
var last = null;
224+
// Grouping is performed on the column which contains the run id (and is hidden)
225+
api.column(DevlogListModule.columns.id, {page: 'current'}).data().each(function(runId, i) {
226+
if (last !== runId) {
227+
var groupParts = runId.split('.');
228+
var runDate = moment.unix(groupParts[0]);
229+
var label = TYPO3.lang['run_start'].replace('%s', runDate.format('YYYY-MM-DD HH:mm:ss'));
230+
$(rows).eq(i).before(
231+
'<tr class="group"><td colspan="9">' + label + '</td></tr>'
232+
);
233+
}
234+
last = runId;
235+
});
236+
},
206237
initComplete: function() {
207238
DevlogListModule.initializeSearchField();
208239
DevlogListModule.initializeExtraDataToggle();
209240
DevlogListModule.initializeReloadControls();
241+
DevlogListModule.initializeGroupRunsButton();
210242
DevlogListModule.initializeFilters();
211243
DevlogListModule.initializeClearLogMenu();
212244
DevlogListModule.toggleLoadingMask();
@@ -304,6 +336,29 @@ define(['jquery',
304336
});
305337
};
306338

339+
/**
340+
* Activates the "group runs" button.
341+
* Also activates the group rows for restoring groups after sorting.
342+
*/
343+
DevlogListModule.initializeGroupRunsButton = function () {
344+
// Activate the group runs button
345+
$('#tx_devlog_groupruns').on('click', function () {
346+
DevlogListModule.groupRuns = $(this).prop('checked');
347+
DevlogListModule.table.draw();
348+
});
349+
// Activate the group rows in order to restore grouping after sorting operations
350+
DevlogListModule.tableView.on('click', 'tr.group', function () {
351+
var currentOrder = DevlogListModule.table.order()[0];
352+
// If already grouped, change ordering
353+
if (currentOrder[0] === DevlogListModule.columns.id && currentOrder[1] === 'desc') {
354+
DevlogListModule.table.order([DevlogListModule.columns.id, 'asc']).draw();
355+
// Default ordering is descending
356+
} else {
357+
DevlogListModule.table.order([DevlogListModule.columns.id, 'desc']).draw();
358+
}
359+
});
360+
};
361+
307362
/**
308363
* Initializes all filter selectors and set their options list.
309364
*/

Resources/Public/StyleSheet/Devlog.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ a.next {
3535
margin-bottom: 15px;
3636
}
3737

38+
.group td {
39+
background-color: #bbbbbb;
40+
color: #ffffff;
41+
font-style: italic;
42+
}
43+
3844
mark {
3945
background-color: #e8a33d;
4046
color: #ffffff;

0 commit comments

Comments
 (0)