add a delete button to delete a video

This commit is contained in:
Lukas Heiligenbrunner 2020-10-03 07:06:27 +00:00
parent c2991bcd50
commit 13a980f161
4 changed files with 57 additions and 5 deletions

View File

@ -219,5 +219,18 @@ class Video extends RequestBase {
$this->commitMessage('{"result":"' . $this->conn->error . '"}'); $this->commitMessage('{"result":"' . $this->conn->error . '"}');
} }
}); });
$this->addActionHandler("deleteVideo", function () {
$movieid = $_POST['movieid'];
// delete video entry and corresponding tag infos
$query = "DELETE FROM videos WHERE movie_id=$movieid";
if ($this->conn->query($query) === TRUE) {
$this->commitMessage('{"result":"success"}');
} else {
$this->commitMessage('{"result":"' . $this->conn->error . '"}');
}
});
} }
} }

View File

@ -27,6 +27,7 @@ create table if not exists video_tags
foreign key (tag_id) references tags (tag_id), foreign key (tag_id) references tags (tag_id),
constraint video_tags_videos_movie_id_fk constraint video_tags_videos_movie_id_fk
foreign key (video_id) references videos (movie_id) foreign key (video_id) references videos (movie_id)
on delete cascade
); );
create table settings create table settings

View File

@ -141,9 +141,8 @@ class Player extends React.Component {
<div>not loaded yet</div>} <div>not loaded yet</div>}
<div className={style.videoactions}> <div className={style.videoactions}>
<button className='btn btn-primary' onClick={() => this.likebtn()}>Like this Video!</button> <button className='btn btn-primary' onClick={() => this.likebtn()}>Like this Video!</button>
<button className='btn btn-info' onClick={() => this.setState({popupvisible: true})}>Give this <button className='btn btn-info' onClick={() => this.setState({popupvisible: true})}>Give this Video a Tag</button>
Video a Tag <button className='btn btn-danger' onClick={() =>{this.deleteVideo()}}>Delete Video</button>
</button>
{this.state.popupvisible ? {this.state.popupvisible ?
<AddTagPopup show={this.state.popupvisible} <AddTagPopup show={this.state.popupvisible}
onHide={() => { onHide={() => {
@ -225,6 +224,27 @@ class Player extends React.Component {
closebtn() { closebtn() {
this.props.viewbinding.returnToLastElement(); this.props.viewbinding.returnToLastElement();
} }
/**
* delete the current video and return to last page
*/
deleteVideo() {
const updateRequest = new FormData();
updateRequest.append('action', 'deleteVideo');
updateRequest.append('movieid', this.props.movie_id);
fetch('/api/video.php', {method: 'POST', body: updateRequest})
.then((response) => response.json()
.then((result) => {
if (result.result === "success") {
// return to last element if successful
this.props.viewbinding.returnToLastElement();
} else {
console.error("an error occured while liking");
console.error(result);
}
}));
}
} }
export default Player; export default Player;

View File

@ -69,13 +69,31 @@ describe('<Player/>', function () {
it('show tag popup', function () { it('show tag popup', function () {
const wrapper = shallow(<Player/>); const wrapper = shallow(<Player/>);
expect(wrapper.find("AddTagPopup")).toHaveLength(0); expect(wrapper.find("AddTagPopup")).toHaveLength(0);
wrapper.find('.videoactions').find("button").last().simulate('click'); // todo dynamic button find without index
wrapper.find('.videoactions').find("button").at(1).simulate('click');
// addtagpopup should be showing now // addtagpopup should be showing now
expect(wrapper.find("AddTagPopup")).toHaveLength(1); expect(wrapper.find("AddTagPopup")).toHaveLength(1);
}); });
it('test delete button', done => {
const wrapper = shallow(<Player viewbinding={{
returnToLastElement: jest.fn()
}}/>);
global.fetch = prepareFetchApi({result: "success"});
wrapper.find('.videoactions').find("button").at(2).simulate('click');
process.nextTick(() => {
// refetch is called so fetch called 3 times
expect(global.fetch).toHaveBeenCalledTimes(1);
expect(wrapper.instance().props.viewbinding.returnToLastElement).toHaveBeenCalledTimes(1);
global.fetch.mockClear();
done();
});
});
it('hide click ', function () { it('hide click ', function () {
const wrapper = shallow(<Player/>); const wrapper = shallow(<Player/>);
const func = jest.fn(); const func = jest.fn();