working on category browser

This commit is contained in:
Jonas Heinrich 2019-05-12 13:16:32 +02:00
parent 386036fc4c
commit 479254e75e
2 changed files with 56 additions and 34 deletions

View File

@ -13,16 +13,10 @@ var MODULE = (function (radio) {
if ( ( $(window).scrollTop() + $(window).height() ) == $(document).height() ) { if ( ( $(window).scrollTop() + $(window).height() ) == $(document).height() ) {
if(!station_list.data("didfire")) { if(!station_list.data("didfire")) {
station_list.data("didfire", true); station_list.data("didfire", true);
if ($('li.nav-files').hasClass('active')){
radio.radio_query(1, ""); var hashurl = window.location.hash;
} else if ($('li.nav-recent').hasClass('active')) { radio.radio_query(hashurl);
radio.radio_query(2, "");
} else if ($('li.nav-favorites').hasClass('active')) {
console.log("todo");
} else {
var query = $('#searchbox').val();
radio.radio_query(0, query);
};
var ref = station_list; var ref = station_list;
setTimeout(function(){ setTimeout(function(){
ref.data("didfire", false); ref.data("didfire", false);
@ -112,6 +106,12 @@ var MODULE = (function (radio) {
}; };
$.each(data, function(i, station) { $.each(data, function(i, station) {
if (typeof station['id'] == "undefined") {
var entry_type = "folder";
var isstarred = false;
var hashurl = window.location.hash + "/" + station['name'];
} else {
var entry_type = "station";
var isstarred = false; var isstarred = false;
for (var fav_station in fav_stations) { for (var fav_station in fav_stations) {
if (fav_stations[fav_station]["stationid"] == station['id']) { if (fav_stations[fav_station]["stationid"] == station['id']) {
@ -119,7 +119,9 @@ var MODULE = (function (radio) {
break; break;
} }
}; };
radio.render_entry("station", isstarred, '#station/'+station['id'], station['favicon'], station['name']); var hashurl = '#station/'+station['id'];
}
radio.render_entry(entry_type, isstarred, hashurl, station['favicon'], station['name']);
}); });
}); });
@ -178,7 +180,6 @@ var MODULE = (function (radio) {
}; };
radio.radio_query = function(hashurl){ radio.radio_query = function(hashurl){
console.log(hashurl);
var offset = $('tbody > tr').length; var offset = $('tbody > tr').length;
var query = ""; var query = "";
var api_baseurl = "https://www.radio-browser.info/webservice/json/"; var api_baseurl = "https://www.radio-browser.info/webservice/json/";
@ -189,24 +190,32 @@ var MODULE = (function (radio) {
case "#recent": case "#recent":
var query_url = "stations/lastchange"; var query_url = "stations/lastchange";
break; break;
case "#categories/countries": case (hashurl.match(/^#categories/) || {}).input:
var query_url = "countries"; var query_url = hashurl.substring(12);
if (query_url.split("/").length == 2) {
var subcategory = query_url.split("/")[1];
switch (query_url.split("/")[0]) {
case "countries":
var query_url = "stations/bycountryexact/"+subcategory;
break; break;
case "#categories/states": case "states":
var query_url = "states"; var query_url = "stations/bystateexact/"+subcategory;
break; break;
case "#categories/languages": case "languages":
var query_url = "languages"; var query_url = "stations/bylanguageexact/"+subcategory;
break; break;
case "#categories/tags": case "tags":
var query_url = "tags"; var query_url = "stations/bytagsexact/"+subcategory;
break;
}
}
break; break;
case (hashurl.match(/^#search/) || {}).input: case (hashurl.match(/^#search/) || {}).input:
var query_url = "stations/search"; var query_url = "stations/search";
var query = hashurl.substring(8); var query = hashurl.substring(8);
break; break;
}; };
console.log(api_baseurl + query_url, query); console.log(query_url);
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: api_baseurl + query_url, url: api_baseurl + query_url,
@ -218,7 +227,9 @@ var MODULE = (function (radio) {
}, },
dataType: 'json', dataType: 'json',
}).success( function(data){ }).success( function(data){
if (data.length) {
radio.parse_results(data); radio.parse_results(data);
}
}); });
}; };
@ -226,9 +237,11 @@ var MODULE = (function (radio) {
new OCA.Search(function (query) { new OCA.Search(function (query) {
$('#app-navigation').find('li').removeClass("active"); $('#app-navigation').find('li').removeClass("active");
$("tbody > tr").remove(); $("tbody > tr").remove();
radio.radio_query("#search/"+query); var hashurl = "#search/"+query;
history.pushState("", "", hashurl);
radio.radio_query(hashurl);
}, function (arg) { }, function (arg) {
radio.switch_menu(0); console.log("quit search dialog");
}); });
radio.render_entry = function(entry_type, starred, hashurl, iconurl, title){ radio.render_entry = function(entry_type, starred, hashurl, iconurl, title){

View File

@ -87,6 +87,9 @@ var MODULE = (function (radio) {
$('li.nav-categories').addClass('active'); $('li.nav-categories').addClass('active');
radio.radio_query(hashurl); radio.radio_query(hashurl);
break; break;
case (hashurl.match(/^#search/) || {}).input:
radio.radio_query(hashurl);
break;
} }
}, 500); }, 500);
}; };
@ -99,5 +102,11 @@ var MODULE = (function (radio) {
radio.action_load_menu_state(); radio.action_load_menu_state();
}; };
window.addEventListener('hashchange', function(event) {
var hashurl = "#" + event.newURL.split("#")[1];
console.log(hashurl);
radio.action_navigate(hashurl);
}, false);
return radio; return radio;
}(MODULE || {})); }(MODULE || {}));