2020-10-25 18:48:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
import style from './MovieSettings.module.css';
|
2020-12-17 20:53:22 +00:00
|
|
|
import {callAPI} from '../../utils/Api';
|
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
|
|
|
|
*/
|
2020-06-25 22:43:26 +02:00
|
|
|
class MovieSettings extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2020-07-08 19:33:23 +02:00
|
|
|
text: [],
|
|
|
|
startbtnDisabled: false
|
2020-06-25 22:43:26 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.myinterval = setInterval(this.updateStatus, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearInterval(this.myinterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<>
|
2020-10-21 19:14:45 +00:00
|
|
|
<button disabled={this.state.startbtnDisabled}
|
|
|
|
className='btn btn-success'
|
2020-10-25 18:48:23 +00:00
|
|
|
onClick={() => {this.startReindex();}}>Reindex Movie
|
2020-10-21 19:14:45 +00:00
|
|
|
</button>
|
|
|
|
<button className='btn btn-warning'
|
2020-10-25 18:48:23 +00:00
|
|
|
onClick={() => {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 => (
|
2020-06-25 22:43:26 +02:00
|
|
|
<div className='textarea-element'>{m}</div>
|
|
|
|
))}</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* starts the reindex process of the videos in the specified folder
|
|
|
|
*/
|
2020-06-25 22:43:26 +02:00
|
|
|
startReindex() {
|
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
|
|
|
|
|
|
|
callAPI('settings.php', {action: 'startReindex'}, (result) => {
|
|
|
|
console.log(result);
|
|
|
|
if (result.success) {
|
|
|
|
console.log('started successfully');
|
|
|
|
} else {
|
|
|
|
console.log('error, reindex already running');
|
|
|
|
this.setState({startbtnDisabled: true});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-25 22:43:26 +02:00
|
|
|
if (this.myinterval) {
|
|
|
|
clearInterval(this.myinterval);
|
|
|
|
}
|
|
|
|
this.myinterval = setInterval(this.updateStatus, 1000);
|
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* This interval function reloads the current status of reindexing from backend
|
|
|
|
*/
|
2020-06-25 22:43:26 +02:00
|
|
|
updateStatus = () => {
|
2020-12-17 20:53:22 +00:00
|
|
|
callAPI('settings.php', {action: 'getStatusMessage'}, (result) => {
|
|
|
|
if (result.contentAvailable === true) {
|
|
|
|
console.log(result);
|
|
|
|
// 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
|
|
|
|
*/
|
|
|
|
cleanupGravity() {
|
2020-12-17 20:53:22 +00:00
|
|
|
callAPI('settings.php', {action: 'cleanupGravity'}, (result) => {
|
|
|
|
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;
|