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

Kai Reinhard
14.35.2018 9dd2e96f71e5be99337af45d4ff9e039dd2c1098
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
import React from 'react';
import {Button} from 'reactstrap';
import {getRestServiceUrl} from "../../utilities/global";
 
class OpenLocalFile extends React.Component {
    openFile() {
        fetch(getRestServiceUrl('files/open-local-file', {filepath: this.props.filepath}), {
            method: "GET",
            dataType: "text",
            headers: {
                "Content-Type": "text/plain; charset=utf-8"
            }
        })
            .then(response => response.text())
            .then((text) => {
                if (text !== 'OK') {
                    alert(text);
                }
            })
            .catch((error) => {
                alert("Can't open file on local file system :-(")
            })
    }
    render() {
        const service = this.props.service;
        const params = this.props.params;
        var url;
        if (params) {
            if (service === 'files/browse-local-filesystem') {
                url = getRestServiceUrl(service) + '?' + params;
            } else {
                url = getRestServiceUrl(service) + '?prettyPrinter=true&' + params;
            }
        } else {
            url = getRestServiceUrl(service) + '?prettyPrinter=true';
        }
        return (
            <Button color="link" onClick={() => this.openFile()}>{this.props.filepath}</Button>
        )
    }
 
    constructor(props) {
        super(props);
        this.openFile = this.openFile.bind(this);
    }
}
export default OpenLocalFile;