2020-10-25 18:48:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
import style from './MovieSettings.module.css';
|
2021-01-29 22:15:17 +00:00
|
|
|
import {APINode, callAPI} from '../../utils/Api';
|
2021-01-22 21:05:21 +00:00
|
|
|
import {GeneralSuccess} from '../../types/GeneralTypes';
|
|
|
|
import {SettingsTypes} from '../../types/ApiTypes';
|
|
|
|
|
|
|
|
interface state {
|
|
|
|
text: string[]
|
|
|
|
startbtnDisabled: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
interface props {}
|
2020-06-25 22:43:26 +02:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* Component for MovieSettings on Settingspage
|
|
|
|
* handles settings concerning to movies in general
|
|
|
|
*/
|
2021-01-22 21:05:21 +00:00
|
|
|
class MovieSettings extends React.Component<props, state> {
|
|
|
|
myinterval: number = -1;
|
|
|
|
|
|
|
|
constructor(props: props) {
|
2020-06-25 22:43:26 +02:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2020-07-08 19:33:23 +02:00
|
|
|
text: [],
|
|
|
|
startbtnDisabled: false
|
2020-06-25 22:43:26 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
componentDidMount(): void {
|
|
|
|
this.myinterval = window.setInterval(this.updateStatus, 1000);
|
2020-06-25 22:43:26 +02:00
|
|
|
}
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
componentWillUnmount(): void {
|
|
|
|
if (this.myinterval !== -1)
|
|
|
|
clearInterval(this.myinterval);
|
2020-06-25 22:43:26 +02:00
|
|
|
}
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
render(): JSX.Element {
|
2020-06-25 22:43:26 +02:00
|
|
|
return (
|
|
|
|
<>
|
2020-10-21 19:14:45 +00:00
|
|
|
<button disabled={this.state.startbtnDisabled}
|
|
|
|
className='btn btn-success'
|
2021-01-22 21:05:21 +00:00
|
|
|
onClick={(): void => {this.startReindex();}}>Reindex Movie
|
2020-10-21 19:14:45 +00:00
|
|
|
</button>
|
|
|
|
<button className='btn btn-warning'
|
2021-01-22 21:05:21 +00:00
|
|
|
onClick={(): void => {this.cleanupGravity();}}>Cleanup Gravity
|
2020-06-25 22:43:26 +02:00
|
|
|
</button>
|
2020-07-08 19:33:23 +02:00
|
|
|
<div className={style.indextextarea}>{this.state.text.map(m => (
|
2021-02-06 22:18:48 +00:00
|
|
|
<div key={m} className='textarea-element'>{m}</div>
|
2020-06-25 22:43:26 +02:00
|
|
|
))}</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* starts the reindex process of the videos in the specified folder
|
|
|
|
*/
|
2021-01-22 21:05:21 +00:00
|
|
|
startReindex(): void {
|
2020-07-07 19:21:14 +02:00
|
|
|
// clear output text before start
|
|
|
|
this.setState({text: []});
|
|
|
|
|
2020-07-08 19:33:23 +02:00
|
|
|
this.setState({startbtnDisabled: true});
|
2020-07-07 19:21:14 +02:00
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
console.log('starting');
|
2020-12-17 20:53:22 +00:00
|
|
|
|
2021-01-29 22:15:17 +00:00
|
|
|
callAPI(APINode.Settings, {action: 'startReindex'}, (result: GeneralSuccess): void => {
|
2020-12-17 20:53:22 +00:00
|
|
|
console.log(result);
|
2021-01-22 21:05:21 +00:00
|
|
|
if (result.result === 'success') {
|
2020-12-17 20:53:22 +00:00
|
|
|
console.log('started successfully');
|
|
|
|
} else {
|
|
|
|
console.log('error, reindex already running');
|
|
|
|
this.setState({startbtnDisabled: true});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
if (this.myinterval !== -1) {
|
2020-06-25 22:43:26 +02:00
|
|
|
clearInterval(this.myinterval);
|
|
|
|
}
|
2021-01-22 21:05:21 +00:00
|
|
|
this.myinterval = window.setInterval(this.updateStatus, 1000);
|
2020-06-25 22:43:26 +02:00
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* This interval function reloads the current status of reindexing from backend
|
|
|
|
*/
|
2021-01-22 21:05:21 +00:00
|
|
|
updateStatus = (): void => {
|
2021-01-29 22:15:17 +00:00
|
|
|
callAPI(APINode.Settings, {action: 'getStatusMessage'}, (result: SettingsTypes.getStatusMessageType) => {
|
2021-02-06 22:18:48 +00:00
|
|
|
if (result.contentAvailable) {
|
|
|
|
// ignore if message is empty
|
2020-12-17 20:53:22 +00:00
|
|
|
console.log(result);
|
2021-02-06 22:18:48 +00:00
|
|
|
if(result.message === '') return;
|
|
|
|
|
2020-12-17 20:53:22 +00:00
|
|
|
// todo 2020-07-4: scroll to bottom of div here
|
|
|
|
this.setState({
|
|
|
|
// insert a string for each line
|
|
|
|
text: [...result.message.split('\n'),
|
|
|
|
...this.state.text]
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// clear refresh interval if no content available
|
|
|
|
clearInterval(this.myinterval);
|
2020-10-21 19:14:45 +00:00
|
|
|
|
2020-12-17 20:53:22 +00:00
|
|
|
this.setState({startbtnDisabled: false});
|
|
|
|
}
|
|
|
|
});
|
2020-06-25 22:43:26 +02:00
|
|
|
};
|
2020-10-21 19:14:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* send request to cleanup db gravity
|
|
|
|
*/
|
2021-01-22 21:05:21 +00:00
|
|
|
cleanupGravity(): void {
|
2021-01-29 22:15:17 +00:00
|
|
|
callAPI(APINode.Settings, {action: 'cleanupGravity'}, (result) => {
|
2020-12-17 20:53:22 +00:00
|
|
|
this.setState({
|
|
|
|
text: ['successfully cleaned up gravity!']
|
2020-10-21 19:14:45 +00:00
|
|
|
});
|
2020-12-17 20:53:22 +00:00
|
|
|
});
|
2020-10-21 19:14:45 +00:00
|
|
|
}
|
2020-06-25 22:43:26 +02:00
|
|
|
}
|
|
|
|
|
2020-07-08 19:33:23 +02:00
|
|
|
export default MovieSettings;
|