浏览代码

fix: bug with empty icon-url

Thomas Hanika 3 年之前
父节点
当前提交
3a94ea1618
共有 3 个文件被更改,包括 34 次插入30 次删除
  1. 5 1
      ycast/my_stations.py
  2. 26 26
      ycast/static/script.js
  3. 3 3
      ycast/templates/index.html

+ 5 - 1
ycast/my_stations.py

@@ -89,7 +89,11 @@ def putBookmarkJson(elements):
         logging.debug("%s ... %s",stationJson['description'], stationJson['name'])
         logging.debug("%s ... %s",stationJson['description'], stationJson['name'])
         if stationJson['description'] not in newDict:
         if stationJson['description'] not in newDict:
             newDict[stationJson['description']] = {}
             newDict[stationJson['description']] = {}
+        logging.debug(stationJson)
+        if stationJson['icon'] is not None:
+            newDict[stationJson['description']][stationJson['name']] = stationJson['url'] + "|" + stationJson['icon']
+        else:
+            newDict[stationJson['description']][stationJson['name']] = stationJson['url']
 
 
-        newDict[stationJson['description']][stationJson['name']] = stationJson['url'] + "|" + stationJson['icon']
     generic.write_yaml_file(generic.get_stations_file(),newDict)
     generic.write_yaml_file(generic.get_stations_file(),newDict)
     return elements
     return elements

+ 26 - 26
ycast/static/script.js

@@ -6,7 +6,7 @@ window.onload = function () {
     requestStationList(requestSrc, param, false);
     requestStationList(requestSrc, param, false);
 
 
     requestStationList('', '', true);
     requestStationList('', '', true);
-    setBookmarkTopicList();
+    setBookmarkcategoryList();
 }
 }
 
 
 function searchTree(element, id) {
 function searchTree(element, id) {
@@ -32,7 +32,7 @@ function createItem(name, icon, description) {
     var itemicon = document.createElement("div");
     var itemicon = document.createElement("div");
     itemicon.className = "itemicon";
     itemicon.className = "itemicon";
 
 
-    if (icon.length > 0) {
+    if (icon && icon.length > 0) {
         var itemiconimg = document.createElement("img");
         var itemiconimg = document.createElement("img");
         itemiconimg.src = icon;
         itemiconimg.src = icon;
         itemiconimg.className = "itemicon";
         itemiconimg.className = "itemicon";
@@ -118,7 +118,7 @@ function requestStationList(category, param, isbookmarklist) {
                 if (textElem) textElem.textContent = '';
                 if (textElem) textElem.textContent = '';
             }
             }
             if (isbookmarklist) {
             if (isbookmarklist) {
-                setBookmarkTopicList();
+                setBookmarkcategoryList();
             } else {
             } else {
                 document.getElementById('stationcount').textContent = countall + '/' + countall;
                 document.getElementById('stationcount').textContent = countall + '/' + countall;
             }
             }
@@ -131,8 +131,8 @@ function requestStationList(category, param, isbookmarklist) {
 function deleteElement(event, objElem) {
 function deleteElement(event, objElem) {
     if (objElem) {
     if (objElem) {
         objElem.remove();
         objElem.remove();
-        refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idTopic').value, true);
-        setBookmarkTopicList();
+        refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idcategory').value, true);
+        setBookmarkcategoryList();
         saveBookmarks();
         saveBookmarks();
     }
     }
 }
 }
@@ -143,9 +143,9 @@ function copyElementToBookmark(event, objElem) {
         let myList = document.getElementById("bookmarkList")
         let myList = document.getElementById("bookmarkList")
         let listItem = document.createElement('li');
         let listItem = document.createElement('li');
         let station = JSON.parse(objElem.dataset.json);
         let station = JSON.parse(objElem.dataset.json);
-        let topicElem = document.getElementById('idTopic');
-        if (topicElem.value.length == 0) topicElem.value = 'Others'
-        station.description = topicElem.value;
+        let categoryElem = document.getElementById('idcategory');
+        if (categoryElem.value.length == 0) categoryElem.value = 'Others'
+        station.description = categoryElem.value;
         listItem.appendChild(
         listItem.appendChild(
             createItem(station.name, station.icon, station.description)
             createItem(station.name, station.icon, station.description)
         );
         );
@@ -157,8 +157,8 @@ function copyElementToBookmark(event, objElem) {
             deleteElement(event, listItem)
             deleteElement(event, listItem)
         };
         };
         myList.appendChild(listItem);
         myList.appendChild(listItem);
-        refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idTopic').value, true);
-        setBookmarkTopicList();
+        refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idcategory').value, true);
+        setBookmarkcategoryList();
         saveBookmarks();
         saveBookmarks();
     }
     }
 }
 }
@@ -240,8 +240,8 @@ function onInputSelect(e, objElem) {
             }
             }
             break;
             break;
 
 
-        case 'idTopic':
-            refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idTopic').value, true);
+        case 'idcategory':
+            refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idcategory').value, true);
             break;
             break;
 
 
         case 'stationsearch':
         case 'stationsearch':
@@ -252,31 +252,31 @@ function onInputSelect(e, objElem) {
     }
     }
 }
 }
 
 
-function setBookmarkTopicList() {
-    var topicList = [];
+function setBookmarkcategoryList() {
+    var categoryList = [];
     var bookmarkList = Array.from(document.getElementById("bookmarkList").childNodes);
     var bookmarkList = Array.from(document.getElementById("bookmarkList").childNodes);
     bookmarkList.forEach(function (listItem) {
     bookmarkList.forEach(function (listItem) {
         try {
         try {
             if (listItem.dataset.isemptyelement === 'false') {
             if (listItem.dataset.isemptyelement === 'false') {
-                var topic = listItem.dataset.category;
-                if (!topicList.find(function (arElem) {
-                        return (topic === arElem);
+                var category = listItem.dataset.category;
+                if (!categoryList.find(function (arElem) {
+                        return (category === arElem);
                     })) {
                     })) {
-                    topicList.push(topic);
+                    categoryList.push(category);
                 }
                 }
             }
             }
         } catch (e) {
         } catch (e) {
             console.error(listItem, e)
             console.error(listItem, e)
         }
         }
     })
     })
-    if (topicList.length > 0) {
-        var myOldList = document.getElementById('topicList');
+    if (categoryList.length > 0) {
+        var myOldList = document.getElementById('categoryList');
         var myList = myOldList.cloneNode(false);
         var myList = myOldList.cloneNode(false);
         myOldList.parentNode.replaceChild(myList, myOldList);
         myOldList.parentNode.replaceChild(myList, myOldList);
 
 
-        for (const topic of topicList) {
+        for (const category of categoryList) {
             var option = document.createElement('option');
             var option = document.createElement('option');
-            option.value = topic;
+            option.value = category;
             myList.appendChild(option);
             myList.appendChild(option);
         }
         }
     }
     }
@@ -316,8 +316,8 @@ function keyUpEvent(e, objElem) {
                         refreshFilteredList(document.getElementById('stationList'),
                         refreshFilteredList(document.getElementById('stationList'),
                             document.getElementById('stationsearch').value.toUpperCase(), false);
                             document.getElementById('stationsearch').value.toUpperCase(), false);
                     break;
                     break;
-                case 'idTopic':
-                    refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idTopic').value, true);
+                case 'idcategory':
+                    refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idcategory').value, true);
                     break;
                     break;
 
 
                 default:
                 default:
@@ -347,8 +347,8 @@ function keyUpEvent(e, objElem) {
                 refreshFilteredList(document.getElementById('stationList'),
                 refreshFilteredList(document.getElementById('stationList'),
                     document.getElementById('stationsearch').value.toUpperCase(), false);
                     document.getElementById('stationsearch').value.toUpperCase(), false);
             break;
             break;
-        case 'idTopic':
-            refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idTopic').value, true);
+        case 'idcategory':
+            refreshFilteredList(document.getElementById("bookmarkList"), document.getElementById('idcategory').value, true);
             break;
             break;
         default:
         default:
             break;
             break;

+ 3 - 3
ycast/templates/index.html

@@ -44,9 +44,9 @@
         <div class="content">
         <div class="content">
             <div class="contentheader">
             <div class="contentheader">
                 <h3>Bookmarks</h3>
                 <h3>Bookmarks</h3>
-                <label for="idTopic">category:</label>
-                <input type="search" tabindex="10000" list="topicList" id="idTopic" onkeyup="keyUpEvent(event,this)" oninput="onInputSelect(event, this)">
-                <datalist id="topicList">
+                <label for="idcategory">category:</label>
+                <input type="search" tabindex="10000" list="categoryList" id="idcategory" title="filter existing or a new category, if empty all bookmarks are shown." onkeyup="keyUpEvent(event,this)" oninput="onInputSelect(event, this)">
+                <datalist id="categoryList">
                     <option value="Actual">
                     <option value="Actual">
                     <option value="Pop">
                     <option value="Pop">
                     <option value="Classics">
                     <option value="Classics">