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-04-02 17:04:15 +00:00
|
|
|
import {APINode, callAPI} from '../../utils/Api';
|
2021-01-22 21:05:21 +00:00
|
|
|
import {SettingsTypes} from '../../types/ApiTypes';
|
|
|
|
import {GeneralSuccess} from '../../types/GeneralTypes';
|
|
|
|
|
|
|
|
interface state {
|
2021-07-11 12:26:10 +00:00
|
|
|
generalSettings: SettingsTypes.SettingsType;
|
|
|
|
sizes: SettingsTypes.SizesType;
|
2021-01-22 21:05:21 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 14:51:53 +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-03-14 14:51:53 +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 = {
|
2021-02-23 16:01:29 +00:00
|
|
|
generalSettings: {
|
|
|
|
DarkMode: true,
|
2021-03-14 14:51:53 +00:00
|
|
|
EpisodePath: '',
|
|
|
|
MediacenterName: '',
|
|
|
|
Password: '',
|
2021-02-23 16:01:29 +00:00
|
|
|
PasswordEnabled: false,
|
|
|
|
TMDBGrabbing: false,
|
2021-03-14 14:51:53 +00:00
|
|
|
VideoPath: ''
|
2021-07-11 12:26:10 +00:00
|
|
|
},
|
|
|
|
sizes: {
|
|
|
|
DBSize: 0,
|
|
|
|
DifferentTags: 0,
|
|
|
|
TagsAdded: 0,
|
|
|
|
VideoNr: 0
|
2021-02-23 16:01:29 +00:00
|
|
|
}
|
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}>
|
2021-03-14 14:51:53 +00:00
|
|
|
<InfoHeaderItem
|
|
|
|
backColor='lightblue'
|
2021-07-11 12:26:10 +00:00
|
|
|
text={this.state.sizes.VideoNr}
|
2021-03-14 14:51:53 +00:00
|
|
|
subtext='Videos in Gravity'
|
|
|
|
icon={faArchive}
|
|
|
|
/>
|
|
|
|
<InfoHeaderItem
|
|
|
|
backColor='yellow'
|
2021-07-11 12:26:10 +00:00
|
|
|
text={this.state.sizes.DBSize + ' MB'}
|
2021-03-14 14:51:53 +00:00
|
|
|
subtext='Database size'
|
|
|
|
icon={faRulerVertical}
|
|
|
|
/>
|
|
|
|
<InfoHeaderItem
|
|
|
|
backColor='green'
|
2021-07-11 12:26:10 +00:00
|
|
|
text={this.state.sizes.DifferentTags}
|
2021-03-14 14:51:53 +00:00
|
|
|
subtext='different Tags'
|
|
|
|
icon={faAddressCard}
|
|
|
|
/>
|
|
|
|
<InfoHeaderItem
|
|
|
|
backColor='orange'
|
2021-07-11 12:26:10 +00:00
|
|
|
text={this.state.sizes.TagsAdded}
|
2021-03-14 14:51:53 +00:00
|
|
|
subtext='tags added'
|
|
|
|
icon={faBalanceScaleLeft}
|
|
|
|
/>
|
2020-10-19 21:12:07 +00:00
|
|
|
</div>
|
2020-07-27 19:14:56 +00:00
|
|
|
<div className={style.GeneralForm + ' ' + themeStyle.subtextcolor}>
|
2021-03-14 14:51:53 +00:00
|
|
|
<Form
|
|
|
|
data-testid='mainformsettings'
|
|
|
|
onSubmit={(e): void => {
|
|
|
|
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-03-14 14:51:53 +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>
|
2021-03-14 14:51:53 +00:00
|
|
|
<Form.Control
|
|
|
|
type='text'
|
|
|
|
placeholder='/var/www/html/tvshow'
|
|
|
|
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-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-03-14 14:51:53 +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-03-14 14:51:53 +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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Form.Group>
|
|
|
|
) : null}
|
2020-07-28 16:17:17 +00:00
|
|
|
|
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
|
|
|
}}
|
|
|
|
/>
|
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-03-14 14:51:53 +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>
|
2021-03-14 14:51:53 +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-07-11 12:26:10 +00:00
|
|
|
interface SettingsResponseType {
|
|
|
|
Settings: SettingsTypes.SettingsType;
|
|
|
|
Sizes: SettingsTypes.SizesType;
|
|
|
|
}
|
|
|
|
|
|
|
|
callAPI(APINode.Settings, {action: 'loadGeneralSettings'}, (result: SettingsResponseType) => {
|
|
|
|
this.setState({
|
|
|
|
generalSettings: result.Settings,
|
|
|
|
sizes: result.Sizes
|
|
|
|
});
|
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;
|
2021-03-14 14:51:53 +00:00
|
|
|
if (!this.state.generalSettings.PasswordEnabled) {
|
2021-02-23 16:01:29 +00:00
|
|
|
settings.Password = '-1';
|
|
|
|
}
|
2021-03-14 14:51:53 +00:00
|
|
|
settings.DarkMode = GlobalInfos.isDarkTheme();
|
|
|
|
|
2021-07-11 12:26:10 +00:00
|
|
|
console.log(settings);
|
2021-03-14 14:51:53 +00:00
|
|
|
callAPI(
|
|
|
|
APINode.Settings,
|
|
|
|
{
|
|
|
|
action: 'saveGeneralSettings',
|
2021-07-11 12:26:10 +00:00
|
|
|
...settings
|
2021-03-14 14:51:53 +00:00
|
|
|
},
|
|
|
|
(result: GeneralSuccess) => {
|
|
|
|
if (result.result) {
|
|
|
|
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-12-17 20:53:22 +00:00
|
|
|
}
|
2021-03-14 14:51:53 +00:00
|
|
|
);
|
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;
|