Now delete 3 ways

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

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

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

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

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