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

Kai Reinhard
09.38.2019 4a1a26482ecb02d8f320ee44e6263a7a71317160
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
import React from 'react';
import {
    FormButton,
    FormField,
    FormGroup,
    FormInput,
    FormLabel,
    FormLabelInputField
} from "../../general/forms/FormComponents";
import PropTypes from "prop-types";
import I18n from '../../general/translation/I18n';
import {getRestServiceUrl} from "../../../utilities/global";
 
class RepoConfigBasePanel extends React.Component {
 
    render() {
        let repoPlaceHolder = 'Enter the repo used by Borg.';
        if (this.props.remote) {
            repoPlaceHolder = 'Enter the remote path of the repo, such as user@hostname:backup.';
        }
        let repoFieldLength = 10;
        let browseButton = null;
        if (!this.props.remote) {
            repoFieldLength = 9;
            browseButton = <FormButton onClick={this.browseDirectory}
                                       hint={'Browse local backup directory. (experimental!)'}><I18n
                name={'common.browse'}/>
            </FormButton>;
            repoPlaceHolder = 'Enter or browse the local path of the repo home dir used by Borg.';
        }
        return (
            <React.Fragment>
                <FormLabelInputField label={'Display name'} fieldLength={12}
                                     name={'displayName'} value={this.props.repoConfig.displayName}
                                     onChange={this.props.handleRepoConfigChange}
                                     placeholder="Enter display name (only for displaying purposes)."/>
                <FormGroup>
                    <FormLabel length={2}>{'Repo'}</FormLabel>
                    <FormField length={repoFieldLength}>
                        <FormInput
                            id={'repo'}
                            name={'repo'}
                            type={'text'}
                            value={this.props.repoConfig.repo}
                            onChange={this.props.handleRepoConfigChange}
                            placeholder={repoPlaceHolder}
                        />
                    </FormField>
                    {browseButton}
                </FormGroup>
                <FormLabelInputField label={'RSH'} fieldLength={12}
                                     name={'rsh'} value={this.props.repoConfig.rsh}
                                     onChange={this.props.handleRepoConfigChange}
                                     placeholder="Enter the rsh value (ssh command) for remote repository."
                                     className={!this.props.remote ? 'hidden' : null}/>
            </React.Fragment>
        );
    }
 
    browseDirectory = () => {
        const current = "&current=" + encodeURIComponent(this.props.repoConfig.repo);
        fetch(getRestServiceUrl("files/browse-local-filesystem?type=dir" + current), {
            method: "GET",
            dataType: "JSON",
            headers: {
                "Content-Type": "text/plain; charset=utf-8",
            }
        })
            .then((resp) => {
                return resp.json()
            })
            .then((data) => {
                if (data.directory) {
                    this.props.setRepoValue('repo', data.directory);
                }
            })
            .catch((error) => {
                console.log(error, "Oups, what's happened?")
            })
    }
}
 
 
RepoConfigBasePanel.propTypes = {
    handleRepoConfigChange: PropTypes.func.isRequired,
    setRepoValue: PropTypes.func.isRequired,
    repoConfig: PropTypes.object.isRequired,
    remote: PropTypes.bool
};
 
RepoConfigBasePanel.defaultProps = {
    remote: true
};
 
export default RepoConfigBasePanel;