Skip to content

Commit 3451eed

Browse files
committed
fix: issue with column sort while loading new data.
1 parent 13c0534 commit 3451eed

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

php-error-log-viewer.php

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class Pelv_Log_Handler {
6262
'vscode_links' => true, // Stack trace references files. link them to your repo (https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls).
6363
'vscode_path_search' => '', // This is needed if you develop on a vm. like '/srv/www/...'.
6464
'vscode_path_replace' => '', // The local path to your repo. like 'c:/users/...'.
65-
// 'password' => '',
6665
);
6766

6867
public function __construct( $settings ) {
@@ -172,7 +171,8 @@ public function vscode_link_filter( $matches ) {
172171
*
173172
* @param array $arr
174173
* looks like that:
175-
* array ( 0 => [01-Jun-2016 09:24:02 UTC] PHP Fatal error: Allowed memory size of 456 bytes exhausted (tried to allocate 27 bytes) in ...
174+
* array (
175+
* 0 => [01-Jun-2016 09:24:02 UTC] PHP Fatal error: Allowed memory size of 456 bytes exhausted (tried to allocate 27 bytes) in ...
176176
* 1 => [01-Jun-2016 09:24:02 UTC]
177177
* 2 => PHP Fatal error: Allowed memory size of 56 bytes exhausted (tried to allocate 15627 bytes) in ... *
178178
* )
@@ -184,7 +184,7 @@ public function replace_callback( $arr ) {
184184
$this->content[ $err_id ] = array();
185185
$this->content[ $err_id ]['id'] = $err_id; // err_id.
186186
$this->content[ $err_id ]['cnt'] = 1; // counter.
187-
$this->index[] = $err_id;
187+
$this->index[] = $err_id;
188188
} else { // we already have that error...
189189
$this->content[ $err_id ]['cnt']++; // counter.
190190
}
@@ -265,17 +265,16 @@ public function ajax_filesize() {
265265
<body>
266266
<div id="app">
267267
<div class="loader" v-bind:class="{'visible': loading }">
268-
<md-progress-bar md-mode="query"></md-progress-bar>
268+
<md-progress-bar md-mode="query"></md-progress-bar>
269269
</div>
270-
<md-table v-model="searched" md-sort="cnt" md-sort-order="asc" md-card md-fixed-header>
270+
<md-table v-model="rowsDisplay" :md-sort.sync="currentSort" :md-sort-order.sync="currentSortOrder"ref="mytable" md-card md-fixed-header>
271271
<md-chip v-if="filesize">{{ readableFilesize() }}<!--needed for the inner filesize container to update--></md-chip>
272272
<md-table-toolbar>
273273
<h1 class="md-title" >Debug.log <md-chip v-if="filesize">{{ readableFilesize() }}</md-chip></h1>
274-
275274
<div class="md-toolbar-section-start">
276275
</div>
277276
<md-field md-clearable class="md-toolbar-section-end">
278-
<md-input placeholder="Filter Rows (Regex)" v-model="search" @input="searchOnTable" />
277+
<md-input placeholder="Filter Rows (Regex)" v-model="search" @input="searchTable" />
279278
</md-field>
280279
<div class="md-toolbar-section-end">
281280
<md-switch v-model="autoreload" class="md-primary">Autoreload</md-switch>
@@ -287,7 +286,7 @@ public function ajax_filesize() {
287286
</md-table-toolbar>
288287
<md-table-empty-state v-if="filesize && search"
289288
md-label="Nothing found"
290-
:md-description="`Nothing found for this '${search}' query. Try a different search term or create a matching error ;)`">
289+
:md-description="`No results for your search: '${search}'. Try a different search term or create a matching error ;)`">
291290
</md-table-empty-state>
292291
<md-table-empty-state v-if="!filesize"
293292
md-label="Nothing found"
@@ -326,9 +325,11 @@ public function ajax_filesize() {
326325
var app = new Vue({
327326
el: '#app',
328327
data: () => ({
328+
currentSort: 'time',
329+
currentSortOrder: 'desc',
329330
search: null,
330-
searched: [],
331-
entries: [],
331+
rowsRaw: [],
332+
rowsDisplay: [],
332333
filesize: 0,
333334
loading: false,
334335
delete: '',
@@ -352,26 +353,44 @@ public function ajax_filesize() {
352353
} else {
353354
return (Math.round(this.filesize /102 ) /10) + ' KB';
354355
}
355-
356356
},
357357
readableDateTime( dateTimeString ){
358358
let date = new Date(dateTimeString);
359359
return isNaN( date ) ? dateTimeString : date.toLocaleString();
360360
},
361-
searchOnTable () {
361+
filterSearch(){
362362
if ( this.search == "" ){
363-
this.searched = this.entries
363+
return this.rowsRaw
364364
} else {
365-
this.searched = searchByName(this.entries, this.search)
365+
return searchByName(this.rowsRaw, this.search)
366+
}
367+
},
368+
searchTable () {
369+
this.rowsDisplay = this.filterSearch();
370+
},
371+
compareEntries() {
372+
const sortBy = this.currentSort
373+
const multiplier = this.currentSortOrder === 'desc' ? -1 : 1;
374+
return ( a, b ) => {
375+
const aAttr = a[sortBy];
376+
const bAttr = b[sortBy];
377+
if (aAttr === bAttr) {
378+
return 0
379+
}
380+
else if (typeof aAttr === 'number' && typeof bAttr === 'number') {
381+
return (aAttr - bAttr) * multiplier // numerical compare, negate if descending
382+
}
383+
return String(aAttr).localeCompare(String(bAttr)) * multiplier;
366384
}
367385
},
368-
handleErrors(response){
369-
this.entries = response.data
386+
setNewData(response){
387+
this.rowsRaw = response.data
370388
this.loading = false
371-
this.searchOnTable()
389+
this.rowsDisplay = this.filterSearch();
390+
this.rowsDisplay.sort( this.compareEntries() );
372391
},
373392
getLog(comp){
374-
axios.get('?get_log').then( response => (comp.handleErrors(response)))
393+
axios.get('?get_log').then( response => (comp.setNewData(response)))
375394
},
376395
update(comp){
377396
if ( ! comp.autoreload | comp.documentHidden ){
@@ -387,7 +406,7 @@ public function ajax_filesize() {
387406
let size = response.data
388407
if ( typeof response.data == 'string'){
389408
console.log('something went wrong...')
390-
comp.searched = [];
409+
comp.rowsDisplay = [];
391410
comp.error = true
392411
comp.errorMessage = response.data;
393412
comp.loading = false
@@ -411,7 +430,7 @@ public function ajax_filesize() {
411430
})
412431
},
413432
deleteLog(){
414-
this.searched = [];
433+
this.rowsDisplay = [];
415434
this.filesize = 0;
416435
axios.get('?delete_log').then(response => (this.delete.data = response))
417436
}

0 commit comments

Comments
 (0)