@@ -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 */
0 commit comments