2020-06-25 20:43:26 +00:00
|
|
|
import React from "react";
|
2020-07-12 22:44:16 +00:00
|
|
|
import {Button, Col, Form} from "react-bootstrap";
|
2020-07-08 17:33:23 +00:00
|
|
|
import style from "./GeneralSettings.module.css"
|
2020-07-27 19:14:56 +00:00
|
|
|
import StaticInfos from "../../GlobalInfos";
|
2020-06-25 20:43:26 +00:00
|
|
|
|
|
|
|
class GeneralSettings extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2020-07-02 22:20:11 +00:00
|
|
|
this.state = {
|
2020-07-09 23:18:23 +00:00
|
|
|
passwordsupport: false,
|
2020-07-17 23:10:04 +00:00
|
|
|
tmdbsupport: null,
|
2020-07-09 23:18:23 +00:00
|
|
|
|
2020-07-02 22:20:11 +00:00
|
|
|
videopath: "",
|
2020-07-09 23:18:23 +00:00
|
|
|
tvshowpath: "",
|
|
|
|
mediacentername: "",
|
|
|
|
password: ""
|
2020-07-02 22:20:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const updateRequest = new FormData();
|
2020-07-03 22:45:18 +00:00
|
|
|
updateRequest.append('action', 'loadGeneralSettings');
|
2020-07-02 22:20:11 +00:00
|
|
|
|
2020-07-09 23:18:23 +00:00
|
|
|
fetch('/api/Settings.php', {method: 'POST', body: updateRequest})
|
2020-07-02 22:20:11 +00:00
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
2020-07-17 23:10:04 +00:00
|
|
|
console.log(result);
|
2020-07-09 23:18:23 +00:00
|
|
|
this.setState({
|
|
|
|
videopath: result.video_path,
|
|
|
|
tvshowpath: result.episode_path,
|
|
|
|
mediacentername: result.mediacenter_name,
|
|
|
|
password: result.password,
|
2020-07-17 23:10:04 +00:00
|
|
|
passwordsupport: result.passwordEnabled,
|
|
|
|
tmdbsupport: result.TMDB_grabbing
|
2020-07-09 23:18:23 +00:00
|
|
|
});
|
2020-07-02 22:20:11 +00:00
|
|
|
}));
|
2020-06-25 20:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-08-03 23:31:43 +00:00
|
|
|
const themeStyle = StaticInfos.getThemeStyle();
|
2020-06-25 20:43:26 +00:00
|
|
|
return (
|
|
|
|
<>
|
2020-07-27 19:14:56 +00:00
|
|
|
<div className={style.GeneralForm + ' ' + themeStyle.subtextcolor}>
|
2020-07-12 11:12:13 +00:00
|
|
|
<Form data-testid='mainformsettings' onSubmit={(e) => {
|
2020-07-03 22:45:18 +00:00
|
|
|
e.preventDefault();
|
|
|
|
this.saveSettings();
|
|
|
|
}}>
|
2020-06-29 19:34:43 +00:00
|
|
|
<Form.Row>
|
2020-07-12 22:44:16 +00:00
|
|
|
<Form.Group as={Col} data-testid="videpathform">
|
2020-06-29 19:34:43 +00:00
|
|
|
<Form.Label>Video Path</Form.Label>
|
2020-07-09 23:18:23 +00:00
|
|
|
<Form.Control type="text" placeholder="/var/www/html/video" value={this.state.videopath}
|
|
|
|
onChange={(ee) => this.setState({videopath: ee.target.value})}/>
|
2020-06-29 19:34:43 +00:00
|
|
|
</Form.Group>
|
|
|
|
|
2020-07-12 22:44:16 +00:00
|
|
|
<Form.Group as={Col} data-testid="tvshowpath">
|
2020-07-02 22:20:11 +00:00
|
|
|
<Form.Label>TV Show Path</Form.Label>
|
2020-07-09 23:18:23 +00:00
|
|
|
<Form.Control type='text' placeholder="/var/www/html/tvshow"
|
|
|
|
value={this.state.tvshowpath}
|
|
|
|
onChange={(e) => this.setState({tvshowpath: e.target.value})}/>
|
2020-06-29 19:34:43 +00:00
|
|
|
</Form.Group>
|
|
|
|
</Form.Row>
|
|
|
|
|
2020-07-02 22:20:11 +00:00
|
|
|
<Form.Check
|
|
|
|
type="switch"
|
|
|
|
id="custom-switch"
|
2020-07-12 22:44:16 +00:00
|
|
|
data-testid='passwordswitch'
|
2020-07-02 22:20:11 +00:00
|
|
|
label="Enable Password support"
|
2020-07-09 23:18:23 +00:00
|
|
|
checked={this.state.passwordsupport}
|
2020-07-02 22:20:11 +00:00
|
|
|
onChange={() => {
|
2020-07-09 23:18:23 +00:00
|
|
|
this.setState({passwordsupport: !this.state.passwordsupport})
|
2020-07-02 22:20:11 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
2020-07-28 16:17:17 +00:00
|
|
|
{this.state.passwordsupport ?
|
|
|
|
<Form.Group data-testid="passwordfield">
|
|
|
|
<Form.Label>Password</Form.Label>
|
|
|
|
<Form.Control type="password" placeholder="**********" value={this.state.password}
|
|
|
|
onChange={(e) => this.setState({password: e.target.value})}/>
|
|
|
|
</Form.Group> : null
|
|
|
|
}
|
|
|
|
|
2020-07-17 23:10:04 +00:00
|
|
|
<Form.Check
|
|
|
|
type="switch"
|
|
|
|
id="custom-switch-2"
|
|
|
|
data-testid='tmdb-switch'
|
|
|
|
label="Enable TMDB video grabbing support"
|
|
|
|
checked={this.state.tmdbsupport}
|
|
|
|
onChange={() => {
|
|
|
|
this.setState({tmdbsupport: !this.state.tmdbsupport})
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
2020-07-28 16:17:17 +00:00
|
|
|
<Form.Check
|
|
|
|
type="switch"
|
|
|
|
id="custom-switch-3"
|
|
|
|
data-testid='darktheme-switch'
|
|
|
|
label="Enable Dark-Theme"
|
|
|
|
checked={StaticInfos.isDarkTheme()}
|
|
|
|
onChange={() => {
|
|
|
|
StaticInfos.enableDarkTheme(!StaticInfos.isDarkTheme());
|
|
|
|
this.forceUpdate();
|
|
|
|
// todo initiate rerender
|
|
|
|
}}
|
|
|
|
/>
|
2020-07-02 22:20:11 +00:00
|
|
|
|
2020-07-12 22:44:16 +00:00
|
|
|
<Form.Group className={style.mediacenternameform} data-testid="nameform">
|
2020-07-08 17:33:23 +00:00
|
|
|
<Form.Label>The name of the Mediacenter</Form.Label>
|
2020-07-09 23:18:23 +00:00
|
|
|
<Form.Control type="text" placeholder="Mediacentername" value={this.state.mediacentername}
|
|
|
|
onChange={(e) => this.setState({mediacentername: e.target.value})}/>
|
2020-07-08 17:33:23 +00:00
|
|
|
</Form.Group>
|
2020-06-29 19:34:43 +00:00
|
|
|
|
|
|
|
<Button variant="primary" type="submit">
|
|
|
|
Submit
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
</div>
|
2020-06-25 20:43:26 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2020-07-03 22:45:18 +00:00
|
|
|
|
|
|
|
saveSettings() {
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'saveGeneralSettings');
|
|
|
|
|
2020-07-10 17:13:40 +00:00
|
|
|
updateRequest.append('password', this.state.passwordsupport ? this.state.password : "-1");
|
|
|
|
updateRequest.append('videopath', this.state.videopath);
|
|
|
|
updateRequest.append('tvshowpath', this.state.tvshowpath);
|
|
|
|
updateRequest.append('mediacentername', this.state.mediacentername);
|
2020-07-17 23:10:04 +00:00
|
|
|
updateRequest.append("tmdbsupport", this.state.tmdbsupport);
|
2020-07-29 21:00:37 +00:00
|
|
|
updateRequest.append("darkmodeenabled", StaticInfos.isDarkTheme());
|
2020-07-10 17:13:40 +00:00
|
|
|
|
|
|
|
fetch('/api/Settings.php', {method: 'POST', body: updateRequest})
|
2020-07-03 22:45:18 +00:00
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
2020-07-10 17:13:40 +00:00
|
|
|
if (result.success) {
|
2020-07-12 11:12:13 +00:00
|
|
|
console.log("successfully saved settings");
|
2020-07-10 17:13:40 +00:00
|
|
|
// todo 2020-07-10: popup success
|
|
|
|
} else {
|
2020-07-12 11:12:13 +00:00
|
|
|
console.log("failed to save settings");
|
2020-07-10 17:13:40 +00:00
|
|
|
// todo 2020-07-10: popup error
|
|
|
|
}
|
2020-07-03 22:45:18 +00:00
|
|
|
}));
|
|
|
|
}
|
2020-06-25 20:43:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 17:33:23 +00:00
|
|
|
export default GeneralSettings;
|