From: Christian Heller Date: Tue, 10 Dec 2024 16:21:37 +0000 (+0100) Subject: Remove over-complicating tag editing in playlist view. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/static/%7B%7Bprefix%7D%7D/balance?a=commitdiff_plain;h=ba5ebc5d85f125094cc04ef6a60c5fdc9faf5a82;p=ytplom Remove over-complicating tag editing in playlist view. --- diff --git a/src/templates/playlist.tmpl b/src/templates/playlist.tmpl index d4f911c..fc5ac84 100644 --- a/src/templates/playlist.tmpl +++ b/src/templates/playlist.tmpl @@ -3,16 +3,9 @@ {% block script %} -const PATH_PREFIX_TAGS_UPDATE = '/{{page_names.file_tags}}/'; const CLS_PLAYLIST_ROW = 'playlist_row'; -path_tags_update = '?'; events_params += 'playlist=1'; -function get_el_and_empty(id) { - let el = document.getElementById(id); - el.textContent = ''; - return el; } - function new_child_to(tag, parent, textContent='') { const el = document.createElement(tag); parent.appendChild(el); @@ -30,7 +23,7 @@ event_handlers.push(function(data) { // update playlist tr.classList.add(CLS_PLAYLIST_ROW); const td_entry_control = new_child_to('td', tr); td_entry_control.classList.add('entry_control'); - if (data.current_file && data.current_file.digest == file.digest) { + if (data.title_digest == file.digest) { td_entry_control.textContent = 'playing'; } else { for (const [symbol, prefix] of [['>', 'jump'], @@ -40,50 +33,7 @@ event_handlers.push(function(data) { // update playlist btn.onclick = function() { player_command(`${prefix}_${i}`) }; }} const td_link = new_child_to('td', tr); const a_file = new_child_to('a', td_link, file.rel_path); - a_file.href = `/${data.link_prefix}/${file.digest}`; }}) - -event_handlers.push(function(data) { // update current_file table - const td_current_path = get_el_and_empty('current_path'); - const td_current_yt_id = get_el_and_empty('current_yt_id'); - const table_current_tags = get_el_and_empty('current_tags'); - const datalist_unused_tags = get_el_and_empty('unused_tags'); - const btn_update = document.getElementById('btn_update_tags'); - btn_update.disabled = true; - path_tags_update = '?'; - if (data.current_file) { - const a_path = new_child_to('a', td_current_path, data.current_file.rel_path); - a_path.href = `/${data.link_prefix}/${data.current_file.digest}`; - if (data.current_file.yt_id) { - const a_yt = new_child_to('a', td_current_yt_id, data.current_file.yt_id); - a_yt.href = `/${data.yt_result_prefix}/${data.current_file.yt_id}` } - for (const tag of data.current_file.tags) { - const tr = new_child_to('tr', table_current_tags); - const td_checkbox = new_child_to('td', tr); - td_checkbox.classList.add('tag_checkbox'); - const checkbox = new_child_to('input', td_checkbox); - checkbox.type = 'checkbox'; - checkbox.name = 'tag_input'; - checkbox.value = tag; - checkbox.checked = true; - new_child_to('td', tr, tag); } - const tr = new_child_to('tr', table_current_tags); - new_child_to('td', tr, 'add:'); - const td_input = new_child_to('td', tr); - const tag_input = new_child_to('input', td_input); - tag_input.setAttribute('list', 'unused_tags'); - tag_input.name = 'tag_input'; - for (const tag of data.current_file.unused_tags) { - const option = new_child_to('option', datalist_unused_tags, tag); - option.value = tag; } - btn_update.disabled = false; - path_tags_update = `${PATH_PREFIX_TAGS_UPDATE}${data.current_file.digest}`; }}); - -function update_tags() { - var tags = []; - for (const tag_input of document.getElementsByName('tag_input')) { - if (tag_input.value && ('checkbox' != tag_input.type || tag_input.checked)) { - tags.push(tag_input.value); }} - send_to({tags: tags}, path_tags_update); } + a_file.href = `${PATH_PREFIX_FILE}${file.digest}`; }}) function redo_playlist() { send_to({filter_path: document.getElementsByName('filter_path')[0].value, @@ -98,7 +48,6 @@ function redo_playlist() { td.screen_half { width: 50%; } th.screen_half_titles { text-align: center; } td.entry_control { width: 5em; } -td.tag_checkboxes { width: 1em; } {% endblock %} @@ -113,16 +62,6 @@ td.tag_checkboxes { width: 1em; } - - - - - - -
current selection
path:
YouTube ID:
tags
- - - diff --git a/src/ytplom/http.py b/src/ytplom/http.py index f9e3b49..9fab277 100644 --- a/src/ytplom/http.py +++ b/src/ytplom/http.py @@ -42,7 +42,6 @@ PAGE_NAMES: _PageNames = { 'download': Path('dl'), 'events': Path('events'), 'file': Path('file'), - 'file_tags': Path('file_tags'), 'files': Path('files'), 'missing': Path('missing'), 'player': Path('player'), @@ -139,8 +138,6 @@ class _TaskHandler(BaseHTTPRequestHandler): self._receive_files_command(postvars) elif PAGE_NAMES['file'] == page_name: self._receive_file_data(Hash.from_b64(toks_url[2]), postvars) - elif PAGE_NAMES['file_tags'] == page_name: - self._receive_file_tags(Hash.from_b64(toks_url[2]), postvars) elif PAGE_NAMES['yt_queries'] == page_name: self._receive_yt_query(QueryText(postvars.first_for('query'))) elif PAGE_NAMES['player'] == page_name: @@ -177,14 +174,6 @@ class _TaskHandler(BaseHTTPRequestHandler): self.server.player.inject_and_play(file) self._redirect(Path(postvars.first_for('redir_target'))) - def _receive_file_tags(self, digest: Hash, postvars: _ReqMap) -> None: - with DbConn() as conn: - file = VideoFile.get_one(conn, digest) - file.tags = {Tag(t) for t in postvars.all_for('tags')} - file.save(conn) - conn.commit() - self._send_http('OK', code=200) - def _receive_file_data(self, digest: Hash, postvars: _ReqMap) -> None: with DbConn() as conn: file = VideoFile.get_one(conn, digest) @@ -366,17 +355,8 @@ class _TaskHandler(BaseHTTPRequestHandler): with DbConn() as conn: playing = VideoFile.get_one( conn, self.server.player.current_digest) - last_playing_update = ( - VideoFile.last_updates_since_start.get(playing.digest, '') - if playing - else '') - if playing and last_playing_update > playing.last_update: - with DbConn() as conn: - playing = VideoFile.get_one(conn, playing.digest) - last_update = max(self.server.player.last_update, - last_playing_update) - if last_sent < last_update: - last_sent = last_update + if last_sent < self.server.player.last_update: + last_sent = self.server.player.last_update data = { 'last_update': self.server.player.last_update, 'running': self.server.player.is_running, @@ -388,17 +368,6 @@ class _TaskHandler(BaseHTTPRequestHandler): data['playlist_files'] = [ {'rel_path': str(f.rel_path), 'digest': f.digest.b64} for f in self.server.player.files] - data['link_prefix'] = str(PAGE_NAMES['file']) - if playing: - with DbConn() as conn: - unused_tags = playing.unused_tags(conn) - data['current_file'] = { - 'digest': playing.digest.b64, - 'rel_path': str(playing.rel_path), - 'yt_id': playing.yt_id, - 'tags': list(playing.tags), - 'unused_tags': list(unused_tags)} - data['yt_link_prefix'] = str(PAGE_NAMES['yt_result']) try: self.wfile.write( f'data: {json_dumps(data)}\n\n'.encode()) diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index 815821d..f7d2909 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -255,7 +255,6 @@ class VideoFile(DbData): rel_path: Path digest: Hash tags: set[Tag] - last_updates_since_start: dict[Hash, DatetimeStr] = {} def __init__(self, digest: Optional[Hash], @@ -283,7 +282,6 @@ class VideoFile(DbData): def _renew_last_update(self): self.last_update = DatetimeStr(datetime.now().strftime(TIMESTAMP_FMT)) - self.last_updates_since_start[self.digest] = self.last_update def save(self, conn: BaseDbConn) -> Cursor: """Extend super().save by new .last_update if sufficient changes."""