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

Kai Reinhard
17.59.2021 c6e77f6fa462e292db5f693a33e7c483b5a6e19e
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import React from 'react'
import {Nav, NavLink, TabContent, Table, TabPane} from 'reactstrap';
import {PageHeader} from '../../general/BootstrapComponents';
import {getRestServiceUrl, humanFileSize, humanSeconds} from '../../../utilities/global';
import ErrorAlert from '../../general/ErrorAlert';
import {IconRefresh} from '../../general/IconComponents';
import classNames from 'classnames';
import FileListPanel from './FileListPanel';
import JobMonitorPanel from '../jobs/JobMonitorPanel';
import {Link} from "react-router-dom";
import ConfirmModal from '../../general/modal/ConfirmModal';
 
class ArchiveView extends React.Component {
 
    componentDidMount = () => {
        this.fetchArchive();
    };
 
 
    fetchArchive = (force) => {
        this.setState({
            isFetching: true,
            failed: false
        });
        fetch(getRestServiceUrl('archives', {
            repo: this.state.repoId,
            archiveId: this.state.archiveId,
            force: force === true
        }), {
            method: 'GET',
            headers: {
                'Accept': 'application/json'
            }
        })
            .then(response => response.json())
            .then(json => {
                this.setState({
                    isFetching: false,
                    archive: json
                })
            })
            .catch(() => this.setState({isFetching: false, failed: true}));
    };
 
    toggleTab = tab => () => {
        this.setState({
            activeTab: tab
        })
    };
 
    toggleModal() {
        this.setState({
            confirmModal: !this.state.confirmModal
        })
    }
 
    render = () => {
        let content = undefined;
        let archive = this.state.archive;
        let pageHeader = '';
 
        if (this.state.isFetching) {
            content = <JobMonitorPanel repo={this.state.repoId}/>;
        } else if (this.state.failed) {
            content = <ErrorAlert
                title={'Cannot load Repositories'}
                description={'Something went wrong during contacting the rest api.'}
                action={{
                    handleClick: this.fetchArchive,
                    title: 'Try again'
                }}
            />;
        } else if (this.state.archive) {
            pageHeader = <React.Fragment>
                <Link to={'/repos'}> Repositories</Link> -
                <Link
                    to={`/repoArchives/${this.state.repoId}/${archive.repoDisplayName}`}> {archive.repoDisplayName}</Link> - {archive.name}
                <div
                    className={'btn btn-outline-primary refresh-button-right'}
                    onClick={this.toggleModal}
                >
                    <IconRefresh/>
                </div>
            </React.Fragment>;
            let stats = null;
            if (archive.stats) {
                stats = <tr>
                    <td>Stats</td>
                    <td>
                        <table className="inline">
                            <tbody>
                            <tr>
                                <td>Compressed size</td>
                                <td>{humanFileSize(archive.stats.compressed_size)}</td>
                            </tr>
                            <tr>
                                <td>Deduplicated size</td>
                                <td>{humanFileSize(archive.stats.deduplicated_size)}</td>
                            </tr>
                            <tr>
                                <td>Original size</td>
                                <td>{humanFileSize(archive.stats.original_size)}</td>
                            </tr>
                            <tr>
                                <td>Number of files</td>
                                <td>{Number(archive.stats.nfiles).toLocaleString()}</td>
                            </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
            }
            content = <React.Fragment>
                <Nav tabs>
                    <NavLink
                        className={classNames({active: this.state.activeTab === '1'})}
                        onClick={this.toggleTab('1')}
                    >
                        File list
                    </NavLink>
                    <NavLink
                        className={classNames({active: this.state.activeTab === '2'})}
                        onClick={this.toggleTab('2')}
                    >
                        Information
                    </NavLink>
                </Nav>
                <TabContent activeTab={this.state.activeTab}>
                    <TabPane tabId={'1'}>
                        <FileListPanel
                            repoId={this.state.repoId}
                            archive={archive}
                            archiveShortInfoList={archive.archiveShortInfoList}
                        />
                    </TabPane>
                    <TabPane tabId={'2'}>
                        <Table striped bordered hover>
                            <tbody>
                            <tr>
                                <td>Archive</td>
                                <td>{archive.name}</td>
                            </tr>
                            <tr>
                                <td>Start - end</td>
                                <td>{archive.start} - {archive.end} (Duration: {humanSeconds(archive.duration)}s)</td>
                            </tr>
                            <tr>
                                <td>Id</td>
                                <td>{archive.id}</td>
                            </tr>
                            {stats}
                            <tr>
                                <td>Comment</td>
                                <td>{archive.comment}</td>
                            </tr>
                            <tr>
                                <td>Command line</td>
                                <td>{archive.commandLine ? archive.commandLine.join(' ') : ''}</td>
                            </tr>
                            <tr>
                                <td>Host name</td>
                                <td>{archive.hostname}</td>
                            </tr>
                            <tr>
                                <td>User name</td>
                                <td>{archive.username}</td>
                            </tr>
                            <tr>
                                <td>Chunker params</td>
                                <td>{archive.chunkerParams ? archive.chunkerParams.join(', ') : ''}</td>
                            </tr>
                            <tr>
                                <td>Limits</td>
                                <td>
                                    <table className="inline">
                                        <tbody>
                                        <tr>
                                            <td>max_archive_size</td>
                                            <td>{archive.limit ? archive.limits.max_archive_size : ''}</td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                            </tbody>
                        </Table>
                    </TabPane>
                </TabContent>
                <ConfirmModal
                    onConfirm={() => this.fetchArchive(true)}
                    title={'Are you sure?'}
                    toggle={this.toggleModal}
                    open={this.state.confirmModal}
                >
                    Are you sure you want to reload the archive info and the file system list (if already cached)?
                    <br/>
                    This is a safe option but it may take some time to re-fill the caches (on demand) again.
                </ConfirmModal>
            </React.Fragment>;
 
        }
        return <React.Fragment>
            <PageHeader>
                {pageHeader}
            </PageHeader>
            {content}
        </React.Fragment>;
    };
 
    constructor(props) {
        super(props);
 
        this.state = {
            repoId: this.props.match.params.repoId,
            archiveId: this.props.match.params.archiveId,
            isFetching: false,
            activeTab: '1',
            confirmModal: false
        };
 
 
        this.fetchArchive = this.fetchArchive.bind(this);
        this.toggleModal = this.toggleModal.bind(this);
    }
}
 
export default ArchiveView;