home · contact · privacy
Remove over-complicating tag editing in playlist view. master
authorChristian Heller <c.heller@plomlompom.de>
Tue, 10 Dec 2024 16:21:37 +0000 (17:21 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 10 Dec 2024 16:21:37 +0000 (17:21 +0100)
src/templates/playlist.tmpl
src/ytplom/http.py
src/ytplom/misc.py

index d4f911c4ce4c527211f74eed4cadeef970adde7a..fc5ac840a2865c5ed9a9d06cb9ceb915147720f6 100644 (file)
@@ -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; }
 <tr><td colspan=2><button onclick="redo_playlist()">reload</button></td></tr>
 </table>
 
-<table>
-<tr><th colspan=2 class="screen_half_titles">current selection</th></tr>
-<tr><th>path:</th><td id="current_path"></td></tr>
-<tr><th>YouTube&nbsp;ID:</th><td id="current_yt_id"></td>
-</tr>
-<tr><th>tags</th><td><table id="current_tags"></table></td></tr>
-</table>
-<button id="btn_update_tags" onclick="update_tags()" disabled>update</button>
-<datalist id="unused_tags"></datalist>
-
 </td>
 <td class="screen_half">
 
index f9e3b49c2126c4a7e5ee911957a182ce674b42d4..9fab2777903c0cb94e7e7393e95520724de2c561 100644 (file)
@@ -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())
index 815821d3fa679ee47add4e5b949e73380d146031..f7d29094a0824e42ba0a7b7cda04e981602233ec 100644 (file)
@@ -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."""