From b660d700b9a197b918950af5a3adf56d8104b1c0 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 10 Aug 2020 18:30:56 -0700 Subject: [PATCH] Add endpoint and gui button for deleting channels. --- .../backend/endpoints/channel_endpoints.py | 10 +++++++++ frontends/ycdl_flask/static/js/api.js | 21 +++++++++++++++++++ frontends/ycdl_flask/templates/channel.html | 11 ++++++++++ 3 files changed, 42 insertions(+) diff --git a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py index f6cfbbc..5489c3c 100644 --- a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py +++ b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py @@ -90,6 +90,16 @@ def post_add_channel(): channel = common.ycdldb.add_channel(channel_id, get_videos=True) return jsonify.make_json_response(ycdl.jsonify.channel(channel)) +@site.route('/channel//delete', methods=['POST']) +def post_delete_channel(channel_id): + try: + channel = common.ycdldb.get_channel(channel_id) + except ycdl.exceptions.NoSuchChannel as exc: + return jsonify.make_json_response(ycdl.jsonify.exception(exc), status=404) + + channel.delete() + return jsonify.make_json_response({}) + @site.route('/channel//refresh', methods=['POST']) def post_refresh_channel(channel_id): force = request.form.get('force', False) diff --git a/frontends/ycdl_flask/static/js/api.js b/frontends/ycdl_flask/static/js/api.js index bf3ebb9..7820998 100644 --- a/frontends/ycdl_flask/static/js/api.js +++ b/frontends/ycdl_flask/static/js/api.js @@ -12,6 +12,14 @@ function add_channel(channel_id, callback) return common.post(url, data, callback); } +api.channels.delete_channel = +function delete_channel(channel_id, callback) +{ + var url = `/channel/${channel_id}/delete`; + data = new FormData(); + return common.post(url, data, callback); +} + api.channels.refresh_channel = function refresh_channel(channel_id, force, callback) { @@ -39,6 +47,19 @@ function set_automark(channel_id, state, callback) return common.post(url, data, callback); } +api.channels.callback_go_to_channels = +function callback_go_to_channels(response) +{ + if (response.meta.status === 200) + { + window.location.href = "/channels"; + } + else + { + console.log(response); + } +} + /**************************************************************************************************/ api.videos = {}; diff --git a/frontends/ycdl_flask/templates/channel.html b/frontends/ycdl_flask/templates/channel.html index 06464c5..13df361 100644 --- a/frontends/ycdl_flask/templates/channel.html +++ b/frontends/ycdl_flask/templates/channel.html @@ -226,6 +226,12 @@ https://stackoverflow.com/a/35153397
+ {% if channel is not none %} + + {% endif %}
@@ -298,6 +304,11 @@ var DOWNLOAD_FILTER = "{{download_filter if download_filter else ""}}"; var video_card_first_selected = null; var video_card_selections = []; +function delete_channel_form() +{ + api.channels.delete_channel(CHANNEL_ID, api.channels.callback_go_to_channels); +} + function refresh_channel_form(force) { console.log(`Refreshing channel ${CHANNEL_ID}, force=${force}.`);