1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
import {EventEmitter} from 'events';
export class LogProvider extends EventEmitter {
static levels = ['Debug', 'Info', 'Warning', 'Error', 'Fatal'];
fromFile = false;
cachedEntries = [];
hasMore = true;
constructor (limit = 50) {
super();
this.baseLimit = limit;
this.loading = false;
this.limit = limit;
this.searchQuery = '';
}
reset () {
this.limit = this.baseLimit;
this.cachedEntries = [];
this.loading = false;
}
get entries () {
return cachedEntries;
}
set query (newQuery) {
if (newQuery !== this.searchQuery) {
this.searchQuery = newQuery;
this.reset();
this.load();
}
}
get query () {
return this.searchQuery;
}
async load () {
this.loading = true;
if (this.cachedEntries.length >= this.limit || this.fromFile || !this.hasMore) {
return;
}
var newData = await this.loadEntries(this.cachedEntries.length, this.limit - this.cachedEntries.length);
if(newData.data.length === 0) {
this.hasMore = false;
}
this.cachedEntries = this.cachedEntries.concat(newData.data);
this.loading = false;
this.emit('entries', this.cachedEntries);
}
loadEntries (offset, count = 50) {
if (this.searchQuery) {
return $.get(OC.generateUrl('/apps/logreader/search'), {
offset,
count,
query: this.query
});
} else {
return $.get(OC.generateUrl('/apps/logreader/get'), {
offset,
count
});
}
}
async getLevels() {
const levels = await $.get(OC.generateUrl('/apps/logreader/levels'));
return levels.split('').map(level => level > 0);
}
setLevels(levels) {
const levelsString = levels.map(level => level ? 1 : 0).join('');
return $.ajax({
type: 'PUT',
url: OC.generateUrl('/apps/logreader/levels'),
data: {levels: levelsString}
});
}
}
|