From 1c087fae322a1b07bb7bd554ee10ff473c47c727 Mon Sep 17 00:00:00 2001
From: Fin Reinhard <fin.reinhard@icloud.com>
Date: Tue, 22 Jan 2019 20:51:03 +0000
Subject: [PATCH] Merge branch 'master' into feature/15-archive-view-url

---
 borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx |   97 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx b/borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx
index 84f0e2d..eff23c4 100644
--- a/borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx
+++ b/borgbutler-webapp/src/components/views/config/ConfigurationServerTab.jsx
@@ -1,10 +1,20 @@
 import React from 'react';
-import {FormButton, FormCheckbox, FormLabelField, FormLabelInputField} from '../../general/forms/FormComponents';
+import {Alert} from 'reactstrap';
+import {
+    FormCheckbox,
+    FormField,
+    FormGroup,
+    FormInput,
+    FormLabel,
+    FormLabelField,
+    FormLabelInputField,
+    FormOption,
+    FormSelect
+} from '../../general/forms/FormComponents';
 import {getRestServiceUrl} from '../../../utilities/global';
 import I18n from '../../general/translation/I18n';
 import ErrorAlertGenericRestFailure from '../../general/ErrorAlertGenericRestFailure';
 import Loading from '../../general/Loading';
-import ConfirmModal from '../../general/modal/ConfirmModal';
 
 class ConfigServerTab extends React.Component {
     loadConfig = () => {
@@ -25,6 +35,8 @@
             .then((data) => {
                 this.setState({
                     loading: false,
+                    borgBinary: data.borgVersion.borgBinary,
+                    borgCommand: data.borgVersion.borgCommand,
                     ...data
                 })
             })
@@ -48,13 +60,13 @@
             showDemoRepos: true,
             maxArchiveContentCacheCapacityMb: 100,
             redirect: false,
-            confirmModal: false
+            borgCommand: null,
+            borgBinary: null
         };
 
         this.handleTextChange = this.handleTextChange.bind(this);
         this.handleCheckboxChange = this.handleCheckboxChange.bind(this);
         this.loadConfig = this.loadConfig.bind(this);
-        this.toggleModal = this.toggleModal.bind(this);
     }
 
     componentDidMount() {
@@ -73,9 +85,13 @@
     save() {
         var config = {
             port: this.state.port,
-            maxArchiveContentCacheCapacityMb : this.state.maxArchiveContentCacheCapacityMb,
+            maxArchiveContentCacheCapacityMb: this.state.maxArchiveContentCacheCapacityMb,
             webDevelopmentMode: this.state.webDevelopmentMode,
-            showDemoRepos: this.state.showDemoRepos
+            showDemoRepos: this.state.showDemoRepos,
+            borgVersion: {
+                borgCommand: this.state.borgCommand,
+                borgBinary: this.state.borgBinary
+            }
         };
         return fetch(getRestServiceUrl("configuration/config"), {
             method: 'POST',
@@ -96,12 +112,6 @@
         })
     }
 
-    toggleModal() {
-        this.setState({
-            confirmModal: !this.state.confirmModal
-        })
-    }
-
     render() {
         if (this.state.loading) {
             return <Loading/>;
@@ -110,30 +120,47 @@
         if (this.state.failed) {
             return <ErrorAlertGenericRestFailure handleClick={this.loadConfig}/>;
         }
-
+        const borgVersion = this.state.borgVersion;
+        let borgInfoColor = 'success';
+        let borgInfoMessage = `Borg version '${borgVersion.version}' is OK.`;
+        if (!borgVersion.versionOK) {
+            borgInfoColor = 'danger';
+            borgInfoMessage = borgVersion.statusMessage;
+        }
         return (
-            <div>
-                <ConfirmModal
-                    onConfirm={ConfigServerTab.clearAllCaches}
-                    title={'Are you sure?'}
-                    toggle={this.toggleModal}
-                    open={this.state.confirmModal}
-                >
-                    Do you really want to clear all caches? All Archive file lists and caches for repo and archive
-                    information will be cleared.
-                    <br/>
-                    This is a safe option but it may take some time to re-fill the caches (on demand) again.
-                </ConfirmModal>
+            <React.Fragment>
                 <form>
-                    <FormLabelField>
-                        <FormButton id={'clearAllCaches'} onClick={this.toggleModal}> Clear all caches
-                        </FormButton>
-                    </FormLabelField>
+                    <FormGroup>
+                        <FormLabel>{'Borg command'}</FormLabel>
+                        <FormField length={2}>
+                            <FormSelect
+                                value={this.state.borgBinary}
+                                name={'borgBinary'}
+                                onChange={this.handleTextChange}
+                                hint={`Choose your OS and BorgButler will download and use a ready to run borg binary from ${borgVersion.binariesDownloadUrl} or choose a manual installed version.`}
+                            >
+                                {borgVersion.borgBinaries
+                                    .map((binary, index) => <FormOption label={binary[1]} value={binary[0]}
+                                                                        key={index}/>)}
+                                <FormOption label={'Manual'} value={'manual'}/>
+                            </FormSelect>
+                        </FormField>
+                        <FormInput fieldLength={8} name={'borgCommand'} value={this.state.borgCommand}
+                                   onChange={this.handleTextChange}
+                                   placeholder="Enter path of borg command"
+                                   disabled={this.state.borgBinary !== "manual"}/>
+                    </FormGroup>
+                    <FormGroup>
+                        <FormField length={4}/>
+                        <Alert className={'col-sm-8'} color={borgInfoColor}>
+                            {borgInfoMessage}
+                        </Alert>
+                    </FormGroup>
                     <FormLabelInputField label={'Port'} fieldLength={2} type="number" min={0} max={65535}
                                          step={1}
                                          name={'port'} value={this.state.port}
                                          onChange={this.handleTextChange}
-                                         placeholder="Enter port" />
+                                         placeholder="Enter port"/>
                     <FormLabelInputField label={'Maximum disc capacity (MB)'} fieldLength={2} type="number" min={50}
                                          max={10000}
                                          step={50}
@@ -141,21 +168,21 @@
                                          value={this.state.maxArchiveContentCacheCapacityMb}
                                          onChange={this.handleTextChange}
                                          placeholder="Enter maximum Capacity"
-                                         hint={`Limits the cache size of archive file lists in the local cache directory: ${this.state.cacheDir}`} />
+                                         hint={`Limits the cache size of archive file lists in the local cache directory: ${this.state.cacheDir}`}/>
                     <FormLabelField label={'Show demo repositories'} fieldLength={2}>
                         <FormCheckbox checked={this.state.showDemoRepos}
                                       hint={'If true, some demo repositories are shown for testing the functionality of BorgButler without any further configuration and running borg backups.'}
                                       name="showDemoRepos"
-                                      onChange={this.handleCheckboxChange} />
+                                      onChange={this.handleCheckboxChange}/>
                     </FormLabelField>
-                    <FormLabelField label={<I18n name={'configuration.webDevelopmentMode'} />} fieldLength={2}>
+                    <FormLabelField label={<I18n name={'configuration.webDevelopmentMode'}/>} fieldLength={2}>
                         <FormCheckbox checked={this.state.webDevelopmentMode}
                                       hintKey={'configuration.webDevelopmentMode.hint'}
                                       name="webDevelopmentMode"
-                                      onChange={this.handleCheckboxChange} />
+                                      onChange={this.handleCheckboxChange}/>
                     </FormLabelField>
                 </form>
-            </div>
+            </React.Fragment>
         );
     }
 }

--
Gitblit v1.10.0