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

Kai Reinhard
19.55.2018 30fb30d4f7502864d61aed6e7f85c65bcbaaf913
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
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";
 
class ArchiveView extends React.Component {
 
    state = {
        repoId: this.props.match.params.repoId,
        archiveId: this.props.match.params.archiveId,
        isFetching: false,
        activeTab: '1',
    };
 
    componentDidMount = () => {
        this.fetchArchive();
    };
 
 
    fetchArchive = (force) => {
        let forceReload = false;
        if (force && window.confirm('Are you sure you want to reload the archive info? This may take some time...')) {
            forceReload = true;
        }
        this.setState({
            isFetching: true,
            failed: false
        });
        fetch(getRestServiceUrl('archives', {
            repo: this.state.repoId,
            archiveId: this.state.archiveId,
            force: forceReload
        }), {
            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
        })
    };
 
    render = () => {
        let content = undefined;
        let archive = this.state.archive;
        let pageHeader = '';
 
        if (this.state.isFetching) {
            content = <i>Loading...</i>;
        } 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>
                {archive.repoDisplayName}
                <div
                    className={'btn btn-outline-primary refresh-button-right'}
                    onClick={this.fetchArchive.bind(this, true)}
                >
                    <IconRefresh/>
                </div>
            </React.Fragment>;
            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
                            archiveId={archive.id}
                            archiveShortInfoList={archive.archiveShortInfoList}
                        />
                    </TabPane>
                    <TabPane tabId={'2'}>
                        <Table 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)})</td>
                            </tr>
                            <tr>
                                <td>Id</td>
                                <td>{archive.id}</td>
                            </tr>
                            <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>
                            <tr>
                                <td>Comment</td>
                                <td>{archive.comment}</td>
                            </tr>
                            <tr>
                                <td>Command line</td>
                                <td>{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.join(', ')}</td>
                            </tr>
                            <tr>
                                <td>Limits</td>
                                <td>
                                    <table className="inline">
                                        <tbody>
                                        <tr>
                                            <td>max_archive_size</td>
                                            <td>{archive.limits.max_archive_size}</td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                            </tbody>
                        </Table>
                    </TabPane>
                </TabContent>
            </React.Fragment>;
 
        }
        return <React.Fragment>
            <PageHeader>
                {pageHeader}
            </PageHeader>
            {content}
        </React.Fragment>;
    };
 
    constructor(props) {
        super(props);
 
        this.fetchArchive = this.fetchArchive.bind(this);
    }
}
 
export default ArchiveView;