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
import React from 'react';
import {Button} from 'reactstrap';
import {getRestServiceUrl} from "../../utilities/global";
 
/*
* Link to a file. If Merlin is running both local, the server and the client, the file will be opened (e. g. in Excel).
* For remote clients the desired file will be downloaded.
 */
class LinkFile extends React.Component {
    openFile() {
        fetch(getRestServiceUrl('files/open-local-file', {primaryKey: this.props.primaryKey}), {
            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() {
        return (
            <Button color="link" onClick={() => this.openFile()}>{this.props.filepath}</Button>
        )
    }
 
    constructor(props) {
        super(props);
        this.openFile = this.openFile.bind(this);
    }
}
 
export default LinkFile;