2020-10-25 18:48:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
import {Button, Col, Form} from 'react-bootstrap';
|
|
|
|
import style from './GeneralSettings.module.css';
|
2020-12-17 20:53:22 +00:00
|
|
|
import GlobalInfos from '../../utils/GlobalInfos';
|
2020-10-25 18:48:23 +00:00
|
|
|
import InfoHeaderItem from '../../elements/InfoHeaderItem/InfoHeaderItem';
|
|
|
|
import {faArchive, faBalanceScaleLeft, faRulerVertical} from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import {faAddressCard} from '@fortawesome/free-regular-svg-icons';
|
2020-11-13 22:52:38 +00:00
|
|
|
import {version} from '../../../package.json';
|
2021-01-29 22:15:17 +00:00
|
|
|
import {APINode, callAPI, setCustomBackendDomain} from '../../utils/Api';
|
2021-01-22 21:05:21 +00:00
|
|
|
import {SettingsTypes} from '../../types/ApiTypes';
|
|
|
|
import {GeneralSuccess} from '../../types/GeneralTypes';
|
|
|
|
|
|
|
|
interface state {
|
2021-02-23 16:01:29 +00:00
|
|
|
customapi: boolean
|
|
|
|
apipath: string
|
|
|
|
generalSettings: SettingsTypes.loadGeneralSettingsType
|
2021-01-22 21:05:21 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 16:01:29 +00:00
|
|
|
interface props {
|
|
|
|
}
|
2020-06-25 20:43:26 +00:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* Component for Generalsettings tag on Settingspage
|
|
|
|
* handles general settings of mediacenter which concerns to all pages
|
|
|
|
*/
|
2021-01-22 21:05:21 +00:00
|
|
|
class GeneralSettings extends React.Component<props, state> {
|
|
|
|
constructor(props: props) {
|
2020-06-25 20:43:26 +00:00
|
|
|
super(props);
|
|
|
|
|
2020-07-02 22:20:11 +00:00
|
|
|
this.state = {
|
2020-12-17 20:53:22 +00:00
|
|
|
customapi: false,
|
2021-01-22 21:05:21 +00:00
|
|
|
apipath: '',
|
2021-02-23 16:01:29 +00:00
|
|
|
generalSettings: {
|
|
|
|
DarkMode: true,
|
|
|
|
DBSize: 0,
|
|
|
|
DifferentTags: 0,
|
|
|
|
EpisodePath: "",
|
|
|
|
MediacenterName: "",
|
|
|
|
Password: "",
|
|
|
|
PasswordEnabled: false,
|
|
|
|
TagsAdded: 0,
|
|
|
|
TMDBGrabbing: false,
|
|
|
|
VideoNr: 0,
|
|
|
|
VideoPath: ""
|
|
|
|
}
|
2020-07-02 22:20:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
componentDidMount(): void {
|
2020-08-12 17:50:25 +00:00
|
|
|
this.loadSettings();
|
2020-06-25 20:43:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
render(): JSX.Element {
|
2020-08-05 20:00:55 +00:00
|
|
|
const themeStyle = GlobalInfos.getThemeStyle();
|
2020-06-25 20:43:26 +00:00
|
|
|
return (
|
|
|
|
<>
|
2020-10-19 21:12:07 +00:00
|
|
|
<div className={style.infoheader}>
|
|
|
|
<InfoHeaderItem backColor='lightblue'
|
2021-02-23 16:01:29 +00:00
|
|
|
text={this.state.generalSettings.VideoNr}
|
2020-10-19 21:12:07 +00:00
|
|
|
subtext='Videos in Gravity'
|
|
|
|
icon={faArchive}/>
|
|
|
|
<InfoHeaderItem backColor='yellow'
|
2021-02-23 16:01:29 +00:00
|
|
|
text={this.state.generalSettings.DBSize + ' MB'}
|
2020-10-19 21:12:07 +00:00
|
|
|
subtext='Database size'
|
|
|
|
icon={faRulerVertical}/>
|
|
|
|
<InfoHeaderItem backColor='green'
|
2021-02-23 16:01:29 +00:00
|
|
|
text={this.state.generalSettings.DifferentTags}
|
2020-10-19 21:12:07 +00:00
|
|
|
subtext='different Tags'
|
|
|
|
icon={faAddressCard}/>
|
|
|
|
<InfoHeaderItem backColor='orange'
|
2021-02-23 16:01:29 +00:00
|
|
|
text={this.state.generalSettings.TagsAdded}
|
2020-10-19 21:12:07 +00:00
|
|
|
subtext='tags added'
|
|
|
|
icon={faBalanceScaleLeft}/>
|
|
|
|
</div>
|
2020-07-27 19:14:56 +00:00
|
|
|
<div className={style.GeneralForm + ' ' + themeStyle.subtextcolor}>
|
2021-01-22 21:05:21 +00:00
|
|
|
<Form data-testid='mainformsettings' onSubmit={(e): void => {
|
2020-07-03 22:45:18 +00:00
|
|
|
e.preventDefault();
|
|
|
|
this.saveSettings();
|
|
|
|
}}>
|
2020-06-29 19:34:43 +00:00
|
|
|
<Form.Row>
|
2020-10-19 21:12:07 +00:00
|
|
|
<Form.Group as={Col} data-testid='videpathform'>
|
2020-06-29 19:34:43 +00:00
|
|
|
<Form.Label>Video Path</Form.Label>
|
2021-02-23 16:01:29 +00:00
|
|
|
<Form.Control type='text' placeholder='/var/www/html/video'
|
|
|
|
value={this.state.generalSettings.VideoPath}
|
|
|
|
onChange={(ee): void => this.setState({
|
|
|
|
generalSettings: {
|
|
|
|
...this.state.generalSettings,
|
|
|
|
VideoPath: ee.target.value
|
|
|
|
}
|
|
|
|
})}/>
|
2020-06-29 19:34:43 +00:00
|
|
|
</Form.Group>
|
|
|
|
|
2020-10-19 21:12:07 +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-10-19 21:12:07 +00:00
|
|
|
<Form.Control type='text' placeholder='/var/www/html/tvshow'
|
2021-02-23 16:01:29 +00:00
|
|
|
value={this.state.generalSettings.EpisodePath}
|
|
|
|
onChange={(e): void => this.setState({
|
|
|
|
generalSettings: {
|
|
|
|
...this.state.generalSettings,
|
|
|
|
EpisodePath: e.target.value
|
|
|
|
}
|
|
|
|
})}/>
|
2020-06-29 19:34:43 +00:00
|
|
|
</Form.Group>
|
|
|
|
</Form.Row>
|
|
|
|
|
2020-12-17 20:53:22 +00:00
|
|
|
<Form.Check
|
|
|
|
type='switch'
|
|
|
|
id='custom-switch-api'
|
|
|
|
label='Use custom API url'
|
|
|
|
checked={this.state.customapi}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(): void => {
|
2020-12-17 20:53:22 +00:00
|
|
|
if (this.state.customapi) {
|
|
|
|
setCustomBackendDomain('');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({customapi: !this.state.customapi});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{this.state.customapi ?
|
|
|
|
<Form.Group className={style.customapiform} data-testid='apipath'>
|
|
|
|
<Form.Label>API Backend url</Form.Label>
|
|
|
|
<Form.Control type='text' placeholder='https://127.0.0.1'
|
|
|
|
value={this.state.apipath}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(e): void => {
|
2020-12-17 20:53:22 +00:00
|
|
|
this.setState({apipath: e.target.value});
|
|
|
|
setCustomBackendDomain(e.target.value);
|
|
|
|
}}/>
|
|
|
|
</Form.Group> : null}
|
|
|
|
|
|
|
|
|
2020-07-02 22:20:11 +00:00
|
|
|
<Form.Check
|
2020-10-19 21:12:07 +00:00
|
|
|
type='switch'
|
|
|
|
id='custom-switch'
|
2020-07-12 22:44:16 +00:00
|
|
|
data-testid='passwordswitch'
|
2020-10-19 21:12:07 +00:00
|
|
|
label='Enable Password support'
|
2021-02-23 16:01:29 +00:00
|
|
|
checked={this.state.generalSettings.PasswordEnabled}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(): void => {
|
2021-02-23 16:01:29 +00:00
|
|
|
this.setState({
|
|
|
|
generalSettings: {
|
|
|
|
...this.state.generalSettings,
|
|
|
|
PasswordEnabled: !this.state.generalSettings.PasswordEnabled
|
|
|
|
}
|
|
|
|
});
|
2020-07-02 22:20:11 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
2021-02-23 16:01:29 +00:00
|
|
|
{this.state.generalSettings.PasswordEnabled ?
|
2020-10-19 21:12:07 +00:00
|
|
|
<Form.Group data-testid='passwordfield'>
|
2020-07-28 16:17:17 +00:00
|
|
|
<Form.Label>Password</Form.Label>
|
2021-02-23 16:01:29 +00:00
|
|
|
<Form.Control type='password' placeholder='**********'
|
|
|
|
value={this.state.generalSettings.Password}
|
|
|
|
onChange={(e): void => this.setState({
|
|
|
|
generalSettings: {
|
|
|
|
...this.state.generalSettings,
|
|
|
|
Password: e.target.value
|
|
|
|
}
|
|
|
|
})}/>
|
2020-07-28 16:17:17 +00:00
|
|
|
</Form.Group> : null
|
|
|
|
}
|
|
|
|
|
2020-07-17 23:10:04 +00:00
|
|
|
<Form.Check
|
2020-10-19 21:12:07 +00:00
|
|
|
type='switch'
|
|
|
|
id='custom-switch-2'
|
2020-07-17 23:10:04 +00:00
|
|
|
data-testid='tmdb-switch'
|
2020-10-19 21:12:07 +00:00
|
|
|
label='Enable TMDB video grabbing support'
|
2021-02-23 16:01:29 +00:00
|
|
|
checked={this.state.generalSettings.TMDBGrabbing}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(): void => {
|
2021-02-23 16:01:29 +00:00
|
|
|
this.setState({
|
|
|
|
generalSettings: {
|
|
|
|
...this.state.generalSettings,
|
|
|
|
TMDBGrabbing: !this.state.generalSettings.TMDBGrabbing
|
|
|
|
}
|
|
|
|
});
|
2020-07-17 23:10:04 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
2020-07-28 16:17:17 +00:00
|
|
|
<Form.Check
|
2020-10-19 21:12:07 +00:00
|
|
|
type='switch'
|
|
|
|
id='custom-switch-3'
|
2020-07-28 16:17:17 +00:00
|
|
|
data-testid='darktheme-switch'
|
2020-10-19 21:12:07 +00:00
|
|
|
label='Enable Dark-Theme'
|
2020-08-05 20:00:55 +00:00
|
|
|
checked={GlobalInfos.isDarkTheme()}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(): void => {
|
2020-08-05 20:00:55 +00:00
|
|
|
GlobalInfos.enableDarkTheme(!GlobalInfos.isDarkTheme());
|
2020-07-28 16:17:17 +00:00
|
|
|
this.forceUpdate();
|
|
|
|
// todo initiate rerender
|
|
|
|
}}
|
|
|
|
/>
|
2020-07-02 22:20:11 +00:00
|
|
|
|
2020-10-19 21:12:07 +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>
|
2021-02-23 16:01:29 +00:00
|
|
|
<Form.Control type='text' placeholder='Mediacentername'
|
|
|
|
value={this.state.generalSettings.MediacenterName}
|
|
|
|
onChange={(e): void => this.setState({
|
|
|
|
generalSettings: {
|
|
|
|
...this.state.generalSettings,
|
|
|
|
MediacenterName: e.target.value
|
|
|
|
}
|
|
|
|
})}/>
|
2020-07-08 17:33:23 +00:00
|
|
|
</Form.Group>
|
2020-06-29 19:34:43 +00:00
|
|
|
|
2020-10-19 21:12:07 +00:00
|
|
|
<Button variant='primary' type='submit'>
|
2020-06-29 19:34:43 +00:00
|
|
|
Submit
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
</div>
|
2020-11-13 22:52:38 +00:00
|
|
|
<div className={style.footer}>
|
|
|
|
Version: {version}
|
|
|
|
</div>
|
2020-06-25 20:43:26 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2020-07-03 22:45:18 +00:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* inital load of already specified settings from backend
|
|
|
|
*/
|
2021-01-22 21:05:21 +00:00
|
|
|
loadSettings(): void {
|
2021-01-29 22:15:17 +00:00
|
|
|
callAPI(APINode.Settings, {action: 'loadGeneralSettings'}, (result: SettingsTypes.loadGeneralSettingsType) => {
|
2021-02-23 16:01:29 +00:00
|
|
|
this.setState({generalSettings: result});
|
2020-12-17 20:53:22 +00:00
|
|
|
});
|
2020-08-12 17:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* save the selected and typed settings to the backend
|
|
|
|
*/
|
2021-01-22 21:05:21 +00:00
|
|
|
saveSettings(): void {
|
2021-02-23 16:01:29 +00:00
|
|
|
let settings = this.state.generalSettings;
|
|
|
|
if(!this.state.generalSettings.PasswordEnabled){
|
|
|
|
settings.Password = '-1';
|
|
|
|
}
|
|
|
|
settings.DarkMode = GlobalInfos.isDarkTheme()
|
|
|
|
|
2021-01-29 22:15:17 +00:00
|
|
|
callAPI(APINode.Settings, {
|
2020-12-17 20:53:22 +00:00
|
|
|
action: 'saveGeneralSettings',
|
2021-02-23 16:01:29 +00:00
|
|
|
Settings: settings
|
2021-01-22 21:05:21 +00:00
|
|
|
}, (result: GeneralSuccess) => {
|
|
|
|
if (result.result) {
|
2020-12-17 20:53:22 +00:00
|
|
|
console.log('successfully saved settings');
|
|
|
|
// todo 2020-07-10: popup success
|
|
|
|
} else {
|
|
|
|
console.log('failed to save settings');
|
|
|
|
// 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;
|