Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions client/src/vue_components/config/ConfigShows.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,29 @@
<b-button v-b-modal.show-config variant="success"> Setup New Show </b-button>
</template>
<template #cell(btn)="data">
<b-button
variant="primary"
:disabled="
isSubmittingLoad || (CURRENT_SHOW != null && CURRENT_SHOW.id === data.item.id)
"
@click="loadShow(data.item)"
>
{{
(CURRENT_SHOW != null && CURRENT_SHOW.id !== data.item.id) || CURRENT_SHOW == null
? 'Load Show'
: 'Loaded'
}}
</b-button>
<b-button-group>
<b-button
variant="primary"
:disabled="
isSubmittingLoad || (CURRENT_SHOW != null && CURRENT_SHOW.id === data.item.id)
"
@click="loadShow(data.item)"
>
{{
(CURRENT_SHOW != null && CURRENT_SHOW.id !== data.item.id) ||
CURRENT_SHOW == null
? 'Load Show'
: 'Loaded'
}}
</b-button>
<b-button
variant="danger"
:disabled="CURRENT_SHOW != null && CURRENT_SHOW.id === data.item.id"
@click.stop.prevent="deleteShow(data.item)"
>
Delete
</b-button>
</b-button-group>
</template>
</b-table>
<b-pagination
Expand Down Expand Up @@ -290,6 +300,37 @@ export default {
this.$v.$reset();
});
},
async deleteShow(item) {
if (this.CURRENT_SHOW != null && this.CURRENT_SHOW.id === item.id) {
this.$toast.error('Unable to delete currently loaded show');
return;
}

const msg = `Are you sure you want to delete ${item.name}? This will delete all data associated with this show and cannot be undone.`;
const action = await this.$bvModal.msgBoxConfirm(msg, {});
if (action !== true) {
return;
}

try {
const searchParams = new URLSearchParams({
id: item.id,
});
const response = await fetch(`${makeURL('/api/v1/show')}?${searchParams}`, {
method: 'DELETE',
});
if (response.ok) {
await this.GET_AVAILABLE_SHOWS();
this.$toast.success('Deleted show!');
} else {
this.$toast.error('Unable to delete show');
log.error('Unable to delete show');
}
} catch (error) {
this.$toast.error('Unable to delete show');
log.error('Error deleting show:', error);
}
},
...mapActions(['GET_AVAILABLE_SHOWS', 'GET_SCRIPT_MODES']),
},
};
Expand Down
52 changes: 50 additions & 2 deletions server/controllers/api/show/shows.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@
from sqlalchemy import select
from tornado import escape

from controllers.api.constants import ERROR_SHOW_NOT_FOUND
from controllers.api.constants import (
ERROR_ID_MISSING,
ERROR_INVALID_ID,
ERROR_SHOW_NOT_FOUND,
)
from digi_server.logger import get_logger
from models.script import Script, ScriptRevision
from models.show import Show, ShowScriptType
from rbac.role import Role
from schemas.schemas import ShowSchema
from utils.web.base_controller import BaseAPIController
from utils.web.route import ApiRoute, ApiVersion
from utils.web.web_decorators import api_authenticated, require_admin, requires_show
from utils.web.web_decorators import (
api_authenticated,
no_live_session,
require_admin,
requires_show,
)


@ApiRoute("show", ApiVersion.V1)
Expand Down Expand Up @@ -220,6 +229,45 @@ async def patch(self):
self.set_status(404)
await self.finish({"message": ERROR_SHOW_NOT_FOUND})

@requires_show
@no_live_session
async def delete(self):
"""
Deletes a show. This is a destructive action and will delete all associated data including scripts, script revisions, acts, cues, etc. Use with caution.
"""
show_id_str = self.get_argument("id", None)
if not show_id_str:
self.set_status(400)
await self.finish({"message": ERROR_ID_MISSING})
return

try:
show_id = int(show_id_str)
except ValueError:
self.set_status(400)
await self.finish({"message": ERROR_INVALID_ID})
return

current_show = self.get_current_show()
current_show_id = current_show["id"]
if show_id == current_show_id:
self.set_status(400)
await self.finish({"message": "Cannot delete the currently loaded show"})
return

with self.make_session() as session:
show: Show = session.get(Show, show_id)
if show:
session.delete(show)
session.commit()

self.set_status(200)
await self.application.ws_send_to_all("NOOP", "GET_SHOW_DETAILS", {})
await self.finish({"message": "Successfully deleted show"})
else:
self.set_status(404)
await self.finish({"message": ERROR_SHOW_NOT_FOUND})


@ApiRoute("show/script_modes", ApiVersion.V1)
class ShowScriptModesController(BaseAPIController):
Expand Down
Loading