mirror of https://github.com/micromata/borgbackup-butler.git

doc
Kai Reinhard
14.05.2021 78a0b156a22eca107f02d7271cf990e46387442b
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
import {getRestServiceUrl} from '../utilities/global';
import {LOG_VIEW_CHANGE_FILTER, LOG_VIEW_FAILED_RELOAD, LOG_VIEW_RELOADED, LOG_VIEW_REQUEST_RELOAD} from './types';
 
const requestedLogReload = () => ({
    type: LOG_VIEW_REQUEST_RELOAD
});
 
const reloadedLog = (data) => ({
    type: LOG_VIEW_RELOADED,
    payload: data
});
 
const failedLogReload = () => ({
    type: LOG_VIEW_FAILED_RELOAD
});
 
const changedFilter = (name, value) => ({
    type: LOG_VIEW_CHANGE_FILTER,
    payload: {name, value}
});
 
export const changeFilter = (name, value) => (dispatch) => dispatch(changedFilter(name, value));
 
const loadLog = (dispatch, getState) => {
    dispatch(requestedLogReload());
 
    const {filters} = getState().log;
 
    fetch(getRestServiceUrl('logging/query', {
        search: filters.search,
        treshold: filters.threshold,
        maxSize: filters.maxSize,
        showStackTrace: filters.showStackTrace,
        ascendingOrder: filters.ascendingOrder,
        // TODO ADD lastReceivedOrderNumber
    }), {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json'
        }
    })
        .then(response => response.json())
        .then(json => dispatch(reloadedLog(json.map(entry => ({
            ...entry,
            level: entry.level.toLowerCase()
        })))))
        .catch(() => dispatch(failedLogReload()));
};
 
export const requestLogReload = () => (dispatch, getState) => {
    if (!getState().log.loading) {
        loadLog(dispatch, getState);
    }
};