Skip to content

Commit

Permalink
feat: Option to Delete Actors without any scenes (xbapps#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
toshski authored Jul 16, 2023
1 parent 0e1f5ca commit 98be364
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
23 changes: 23 additions & 0 deletions pkg/api/actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (i ActorResource) WebService() *restful.WebService {
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(models.Actor{}))

ws.Route(ws.DELETE("/delete/{id}").To(i.deleteActor).
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(models.Actor{}))

ws.Route(ws.POST("/setimage").To(i.setActorImage).
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(models.Actor{}))
Expand Down Expand Up @@ -411,6 +415,25 @@ func (i ActorResource) editActor(req *restful.Request, resp *restful.Response) {
resp.WriteHeaderAndEntity(http.StatusOK, actor)
}

func (i ActorResource) deleteActor(req *restful.Request, resp *restful.Response) {
id, err := strconv.Atoi(req.PathParameter("id"))
if err != nil {
log.Error(err)
return
}

var actor models.Actor
db, _ := models.GetDB()
defer db.Close()

db.Exec(`delete from actor_akas where actor_id=?`, id)
db.Where("actor_id = ?", uint(id)).Delete(&models.ActionActor{})
db.Where("internal_table = 'actors' and internal_db_id = ?", uint(id)).Delete(&models.ExternalReferenceLink{})
db.Where("id = ?", uint(id)).Delete(&models.Actor{})

resp.WriteHeaderAndEntity(http.StatusOK, actor)
}

func checkStringFieldChanged(field_name string, newValue *string, actorField *string, actorId uint) {
if *actorField != *newValue {
*actorField = *newValue
Expand Down
19 changes: 18 additions & 1 deletion ui/src/views/actors/EditActor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@

<footer class="modal-card-foot">
<b-field>
<b-button type="is-primary" @click="save">{{ $t('Save Details') }}</b-button>
<b-button type="is-primary" @click="save">{{ $t('Save Details') }}</b-button>
<b-button v-if="actor.scenes.length == 0 && !actor.name.startsWith('aka:')" type="is-danger" outlined @click="deleteactor">{{ $t('Delete Actor') }}</b-button>
</b-field>
</footer>
</div>
Expand Down Expand Up @@ -292,6 +293,22 @@ export default {
this.$store.state.actorList.isLoading = false
this.close()
},
deleteactor () {
this.$buefy.dialog.confirm({
title: 'Delete actor',
message: `Do you really want to delete <strong>${this.actor.name}</strong>`,
type: 'is-info is-wide',
hasIcon: true,
id: 'heh',
onConfirm: () => {
ky.delete(`/api/actor/delete/${this.actor.id}`).json().then(data => {
this.$store.dispatch('actorList/load', { offset: this.$store.state.actorList.offset - this.$store.state.actorList.limit })
this.$store.commit('overlay/hideActorEditDetails')
this.$store.commit('overlay/hideActorDetails')
})
}
})
},
blur (field) {
if (this.changesMade) return // Changes have already been made. No point to check any further
if (['image_arr', 'tattoos', 'piercings', 'aliases', 'urls'].includes(field)) {
Expand Down

0 comments on commit 98be364

Please sign in to comment.