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 {
|
|
|
|
passwordsupport: boolean,
|
|
|
|
tmdbsupport: boolean,
|
|
|
|
customapi: boolean,
|
|
|
|
|
|
|
|
videopath: string,
|
|
|
|
tvshowpath: string,
|
|
|
|
mediacentername: string,
|
|
|
|
password: string,
|
|
|
|
apipath: string,
|
|
|
|
|
|
|
|
videonr: number,
|
|
|
|
dbsize: number,
|
|
|
|
difftagnr: number,
|
|
|
|
tagsadded: number
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-09 23:18:23 +00:00
|
|
|
passwordsupport: false,
|
2021-01-22 21:05:21 +00:00
|
|
|
tmdbsupport: false,
|
2020-12-17 20:53:22 +00:00
|
|
|
customapi: false,
|
2020-07-09 23:18:23 +00:00
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
videopath: '',
|
|
|
|
tvshowpath: '',
|
|
|
|
mediacentername: '',
|
|
|
|
password: '',
|
2021-01-22 21:05:21 +00:00
|
|
|
apipath: '',
|
2020-10-19 21:12:07 +00:00
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
videonr: 0,
|
|
|
|
dbsize: 0,
|
|
|
|
difftagnr: 0,
|
|
|
|
tagsadded: 0
|
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'
|
|
|
|
text={this.state.videonr}
|
|
|
|
subtext='Videos in Gravity'
|
|
|
|
icon={faArchive}/>
|
|
|
|
<InfoHeaderItem backColor='yellow'
|
2021-01-22 21:05:21 +00:00
|
|
|
text={this.state.dbsize !== undefined ? this.state.dbsize + ' MB' : ''}
|
2020-10-19 21:12:07 +00:00
|
|
|
subtext='Database size'
|
|
|
|
icon={faRulerVertical}/>
|
|
|
|
<InfoHeaderItem backColor='green'
|
|
|
|
text={this.state.difftagnr}
|
|
|
|
subtext='different Tags'
|
|
|
|
icon={faAddressCard}/>
|
|
|
|
<InfoHeaderItem backColor='orange'
|
|
|
|
text={this.state.tagsadded}
|
|
|
|
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>
|
2020-10-19 21:12:07 +00:00
|
|
|
<Form.Control type='text' placeholder='/var/www/html/video' value={this.state.videopath}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(ee): void => this.setState({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'
|
2020-07-09 23:18:23 +00:00
|
|
|
value={this.state.tvshowpath}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(e): void => this.setState({tvshowpath: 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'
|
2020-07-09 23:18:23 +00:00
|
|
|
checked={this.state.passwordsupport}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(): void => {
|
2020-10-25 18:48: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 ?
|
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>
|
2020-10-19 21:12:07 +00:00
|
|
|
<Form.Control type='password' placeholder='**********' value={this.state.password}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(e): void => this.setState({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'
|
2020-07-17 23:10:04 +00:00
|
|
|
checked={this.state.tmdbsupport}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(): void => {
|
2020-10-25 18:48:23 +00:00
|
|
|
this.setState({tmdbsupport: !this.state.tmdbsupport});
|
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>
|
2020-10-19 21:12:07 +00:00
|
|
|
<Form.Control type='text' placeholder='Mediacentername' value={this.state.mediacentername}
|
2021-01-22 21:05:21 +00:00
|
|
|
onChange={(e): void => this.setState({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) => {
|
2020-12-17 20:53:22 +00:00
|
|
|
this.setState({
|
|
|
|
videopath: result.video_path,
|
|
|
|
tvshowpath: result.episode_path,
|
|
|
|
mediacentername: result.mediacenter_name,
|
|
|
|
password: result.password,
|
|
|
|
passwordsupport: result.passwordEnabled,
|
|
|
|
tmdbsupport: result.TMDB_grabbing,
|
|
|
|
|
|
|
|
videonr: result.videonr,
|
|
|
|
dbsize: result.dbsize,
|
|
|
|
difftagnr: result.difftagnr,
|
|
|
|
tagsadded: result.tagsadded
|
|
|
|
});
|
|
|
|
});
|
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-01-29 22:15:17 +00:00
|
|
|
callAPI(APINode.Settings, {
|
2020-12-17 20:53:22 +00:00
|
|
|
action: 'saveGeneralSettings',
|
|
|
|
password: this.state.passwordsupport ? this.state.password : '-1',
|
|
|
|
videopath: this.state.videopath,
|
|
|
|
tvshowpath: this.state.tvshowpath,
|
|
|
|
mediacentername: this.state.mediacentername,
|
|
|
|
tmdbsupport: this.state.tmdbsupport,
|
|
|
|
darkmodeenabled: GlobalInfos.isDarkTheme().toString()
|
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;
|