Now delete 3 ways

pull/46/head
Akhil Gupta 4 years ago
parent 8a76a55a2e
commit 593acfad4b

@ -134,19 +134,29 @@
</div>
<div class="columns" v-bind:class="{four:layout=='list', twelve:layout=='grid'}">
<button
class="button button-delete"
@click="deletePodcast(podcast.ID)"
class="button button-delete deletePodcast"
:data-id="podcast.ID"
title="Delete Podcast and episode files"
>
<i class="fas fa-trash"></i>
</button>
<button
</button>
<div :id="'deleteDdl-'+podcast.ID" style="display: none">
<ul>
<li style="list-style: none;"> <button class="button" :data-id="podcast.ID" onclick="deletePodcast(this)" >Delete Files and Podcast</button></li>
<li style="list-style: none;"> <button class="button" :data-id="podcast.ID" onclick="deletePodcastEpisodes(this)">Delete Files, Keep Podcast</button></li>
<li style="list-style: none;"> <button class="button" :data-id="podcast.ID" onclick="deleteOnlyPodcast(this)">Keep Files, Delete Podcast</button></li>
</ul>
</div>
<!-- <button
class="button button-delete"
title="Delete only episode files"
@click="deletePodcastEpisodes(podcast.ID)"
>
<i class="fas fa-folder-minus"></i>
</button>
</button> -->
<button
class="button"
@ -197,6 +207,9 @@
</div>
</div>
{{template "scripts"}}
<script src="/webassets/popper.min.js"></script>
<script src="/webassets/tippy-bundle.umd.min.js"></script>
<script>
var app = new Vue({
delimiters: ["${", "}"],
@ -216,6 +229,10 @@
},
methods:{
removePodcast(id) {
const index= this.podcasts.findIndex(x=>x.ID===id);
this.podcasts.splice(index,1);
},
sortPodcasts(order){
let compareFunction;
switch(order){
@ -296,7 +313,24 @@
if (screen.width <= 760) {
this.layout='list'
}
this.$nextTick(function () {
checkUseMore();
tippy(".deletePodcast",{
allowHTML: true,
content(reference) {
const id = reference.getAttribute('data-id');
const template = document.getElementById('deleteDdl-'+id);
return template.innerHTML;
},
trigger:'click',
interactive: true
})
})
},
watch:{
sortOrder(newOrder,oldOrder){
@ -316,9 +350,6 @@
localStorage.layout=newLayout
}
},
},
updated(){
},
data: {
isMobile:false,
@ -389,7 +420,10 @@
return false;
}
function deletePodcast(id,onSuccess) {
// console.log(id);
if (typeof id !== 'string'){
id= id.getAttribute('data-id')
}
console.log(id)
var confirmed = confirm(
"Are you sure you want to delete this podcast and all files?"
);
@ -405,9 +439,7 @@
position: "top-right",
duration: 5000,
});
if(onSuccess){
onSuccess();
}
app.removePodcast(id)
})
.catch(function (error) {
@ -425,6 +457,9 @@
}
function deletePodcastEpisodes(id) {
if (typeof id !== 'string'){
id= id.getAttribute('data-id')
}
console.log(id);
var confirmed = confirm(
"Are you sure you want to delete all episodes of this podcast?"
@ -455,6 +490,41 @@
.then(function () {});
return false;
}
function deleteOnlyPodcast(id) {
if (typeof id !== 'string'){
id= id.getAttribute('data-id')
}
console.log(id);
var confirmed = confirm(
"Are you sure you want to delete this podcast (without deleting the files)?"
);
if (!confirmed) {
return false;
}
axios
.delete("/podcasts/" + id + "/podcast")
.then(function (response) {
Vue.toasted.show("Podcast deleted successfully.", {
theme: "bubble",
type: "success",
position: "top-right",
duration: 5000,
});
app.removePodcast(id)
})
.catch(function (error) {
if (error.response) {
Vue.toasted.show(error.response.data?.message, {
theme: "bubble",
type: "error",
position: "top-right",
duration: 5000,
});
}
})
.then(function () {});
return false;
}
</script>
</body>
</html>

@ -94,12 +94,25 @@ func DeletePodcastById(c *gin.Context) {
if c.ShouldBindUri(&searchByIdQuery) == nil {
service.DeletePodcast(searchByIdQuery.Id)
service.DeletePodcast(searchByIdQuery.Id, true)
c.JSON(http.StatusNoContent, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
}
func DeleteOnlyPodcastById(c *gin.Context) {
var searchByIdQuery SearchByIdQuery
if c.ShouldBindUri(&searchByIdQuery) == nil {
service.DeletePodcast(searchByIdQuery.Id, false)
c.JSON(http.StatusNoContent, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
}
func DeletePodcastEpisodesById(c *gin.Context) {
var searchByIdQuery SearchByIdQuery
@ -111,6 +124,17 @@ func DeletePodcastEpisodesById(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
}
func DeletePodcasDeleteOnlyPodcasttEpisodesById(c *gin.Context) {
var searchByIdQuery SearchByIdQuery
if c.ShouldBindUri(&searchByIdQuery) == nil {
service.DeletePodcastEpisodes(searchByIdQuery.Id)
c.JSON(http.StatusNoContent, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
}
func GetPodcastItemsByPodcastId(c *gin.Context) {
var searchByIdQuery SearchByIdQuery

@ -111,6 +111,7 @@ func main() {
router.GET("/podcasts/:id/items", controllers.GetPodcastItemsByPodcastId)
router.GET("/podcasts/:id/download", controllers.DownloadAllEpisodesByPodcastId)
router.DELETE("/podcasts/:id/items", controllers.DeletePodcastEpisodesById)
router.DELETE("/podcasts/:id/podcast", controllers.DeleteOnlyPodcastById)
router.GET("/podcastitems", controllers.GetAllPodcastItems)
router.GET("/podcastitems/:id", controllers.GetPodcastItemById)

@ -483,7 +483,7 @@ func DeletePodcastEpisodes(id string) error {
return nil
}
func DeletePodcast(id string) error {
func DeletePodcast(id string, deleteFiles bool) error {
var podcast db.Podcast
err := db.GetPodcastById(id, &podcast)
@ -497,7 +497,9 @@ func DeletePodcast(id string) error {
return err
}
for _, item := range podcastItems {
DeleteFile(item.DownloadPath)
if deleteFiles {
DeleteFile(item.DownloadPath)
}
db.DeletePodcastItemById(item.ID)
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save