2020-06-25 20:43:26 +00:00
|
|
|
import React from "react";
|
2020-07-08 17:33:23 +00:00
|
|
|
import style from "./MovieSettings.module.css"
|
2020-06-25 20:43:26 +00:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* Component for MovieSettings on Settingspage
|
|
|
|
* handles settings concerning to movies in general
|
|
|
|
*/
|
2020-06-25 20:43:26 +00:00
|
|
|
class MovieSettings extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2020-07-08 17:33:23 +00:00
|
|
|
text: [],
|
|
|
|
startbtnDisabled: false
|
2020-06-25 20:43:26 +00: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'
|
|
|
|
onClick={() => {this.startReindex()}}>Reindex Movie
|
|
|
|
</button>
|
|
|
|
<button className='btn btn-warning'
|
|
|
|
onClick={() => {this.cleanupGravity()}}>Cleanup Gravity
|
2020-06-25 20:43:26 +00:00
|
|
|
</button>
|
2020-07-08 17:33:23 +00:00
|
|
|
<div className={style.indextextarea}>{this.state.text.map(m => (
|
2020-06-25 20:43:26 +00: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 20:43:26 +00:00
|
|
|
startReindex() {
|
2020-07-07 17:21:14 +00:00
|
|
|
// clear output text before start
|
|
|
|
this.setState({text: []});
|
|
|
|
|
2020-07-08 17:33:23 +00:00
|
|
|
this.setState({startbtnDisabled: true});
|
2020-07-07 17:21:14 +00:00
|
|
|
|
2020-06-25 20:43:26 +00:00
|
|
|
console.log("starting");
|
2020-10-21 19:14:45 +00:00
|
|
|
const request = new FormData();
|
|
|
|
request.append("action", "startReindex");
|
2020-06-25 20:43:26 +00:00
|
|
|
// fetch all videos available
|
2020-10-21 19:14:45 +00:00
|
|
|
fetch('/api/settings.php', {method: 'POST', body: request})
|
|
|
|
.then((response) => response.json()
|
2020-06-25 20:43:26 +00:00
|
|
|
.then((result) => {
|
2020-10-21 19:14:45 +00:00
|
|
|
console.log(result);
|
|
|
|
if (result.success) {
|
|
|
|
console.log("started successfully");
|
|
|
|
} else {
|
|
|
|
console.log("error, reindex already running");
|
|
|
|
this.setState({startbtnDisabled: true});
|
|
|
|
}
|
2020-06-25 20:43:26 +00:00
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
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 20:43:26 +00:00
|
|
|
updateStatus = () => {
|
2020-10-21 19:14:45 +00:00
|
|
|
const request = new FormData();
|
|
|
|
request.append("action", "getStatusMessage");
|
|
|
|
|
|
|
|
fetch('/api/settings.php', {method: 'POST', body: request})
|
2020-06-25 20:43:26 +00:00
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
|
|
|
if (result.contentAvailable === true) {
|
|
|
|
console.log(result);
|
2020-07-03 22:45:18 +00:00
|
|
|
// todo 2020-07-4: scroll to bottom of div here
|
2020-06-25 20:43:26 +00:00
|
|
|
this.setState({
|
2020-07-03 22:45:18 +00:00
|
|
|
// insert a string for each line
|
2020-06-25 20:43:26 +00:00
|
|
|
text: [...result.message.split("\n"),
|
|
|
|
...this.state.text]
|
|
|
|
});
|
|
|
|
} else {
|
2020-07-03 22:45:18 +00:00
|
|
|
// clear refresh interval if no content available
|
2020-06-25 20:43:26 +00:00
|
|
|
clearInterval(this.myinterval);
|
2020-07-07 17:21:14 +00:00
|
|
|
|
2020-07-08 17:33:23 +00:00
|
|
|
this.setState({startbtnDisabled: false});
|
2020-06-25 20:43:26 +00:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
};
|
2020-10-21 19:14:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* send request to cleanup db gravity
|
|
|
|
*/
|
|
|
|
cleanupGravity() {
|
|
|
|
const request = new FormData();
|
|
|
|
request.append("action", "cleanupGravity");
|
|
|
|
|
|
|
|
fetch('/api/settings.php', {method: 'POST', body: request})
|
|
|
|
.then((response) => response.text()
|
|
|
|
.then((result) => {
|
|
|
|
this.setState({
|
|
|
|
text: ['successfully cleaned up gravity!']
|
|
|
|
});
|
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
}
|
2020-06-25 20:43:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 17:33:23 +00:00
|
|
|
export default MovieSettings;
|