From ceb310764317957de4aa650d153c791a7ca3445c Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Tue, 21 Aug 2018 22:24:04 +0200 Subject: [PATCH] fix loading all favorites and remember sorting order --- CHANGELOG.md | 6 +++++- js/main.js | 31 ++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90121d9..d74a5a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ -## 0.6.2 – +## 0.6.3 – ### Fixed +- Fix loading all favorites + [#58](https://git.project-insanity.org/onny/nextcloud-app-radio/issues/58) @onny +- Remember favorite stations sort order + [#64](https://git.project-insanity.org/onny/nextcloud-app-radio/issues/64) @onny - Split up javascript file [#67](https://git.project-insanity.org/onny/nextcloud-app-radio/issues/67) @onny diff --git a/js/main.js b/js/main.js index 1ce98f5..5398422 100644 --- a/js/main.js +++ b/js/main.js @@ -196,20 +196,33 @@ var MODULE = (function (radio) { radio.query_stations = function(station_ids){ var station_array = []; + var station_array_new = []; station_ids.forEach(function (station_id, idx) { + var url = "https://www.radio-browser.info/webservice/json/stations/byid/"+station_ids[idx]; + $.getJSON( url , function( data ) { - $.ajax({ - method: "GET", - url: "https://www.radio-browser.info/webservice/json/stations/byid/"+station_ids[idx], - dataType: 'json', - }).success( function(data){ - station_array = station_array.concat(data); - if (station_ids.length == (idx+1)){ - radio.render_results(station_array); + if (data.length === 0) { + station_array = station_array.concat([{'id': station_id, 'name': 'Broken radio station entry :(', 'favicon': '', 'url': ''}]) + } else { + station_array = station_array.concat(data); }; - }); + if (station_ids.length == station_array.length){ + + // sorting results array + station_ids.forEach( function (station_id) { + station_array.forEach( function (station) { + if (station_id === station['id']) { + station_array_new = station_array_new.concat(station); + }; + }); + }); + + radio.render_results(station_array_new); + }; + + }); }); };