Commit f5479223 authored by kempe's avatar kempe

Refactoring: moved getCategories to RadioAPI

parent bb6c544c
......@@ -48,6 +48,14 @@ Python {
FavoritesUtils.addFavorite(stationData)
});
}
function getCategories(cat, callback) {
loading = true;
call('api.radio.getCategories', [cat], function(response) {
callback(response);
loading = false
});
}
onError: {
console.log('python error: ' + traceback);
......
......@@ -45,7 +45,7 @@ class Radio_API:
params = {"category": "_{0}".format(category)}
pyotherside.send('log', "getCategories for: {}".format(params))
response = self.doRequest(categoriesURL, params)
pyotherside.send('updateCategories', response)
return response
def getStationsByCategory(self, category, value):
params = {"category": "_{0}".format(category), "value": value}
......
......@@ -11,7 +11,7 @@ Page {
SilicaListView {
id: browseByListView
VerticalScrollDecorator { flickable: browseByPageListView }
VerticalScrollDecorator { flickable: browseByListView }
anchors.fill: parent
NavigationMenu {
......@@ -57,33 +57,6 @@ Page {
}
}
Python {
id: python
Component.onCompleted: {
addImportPath(Qt.resolvedUrl('../components/python'));
setHandler('updateCategories', function(stations) {
window.loading = false;
populateList(stations)
});
importModule('api', function () {});
}
function getCategories(cat) {
window.loading = true;
call('api.radio.getCategories', [cat], function() {});
}
onError: {
console.log('python error: ' + traceback);
}
onReceived: {
console.log('got message from python');
}
}
function populateList(cats) {
console.log("Number of results:", cats.length)
browseByModel.clear()
......@@ -94,6 +67,8 @@ Page {
}
Component.onCompleted: {
python.getCategories(category.toLowerCase())
radioAPI.getCategories(category.toLocaleLowerCase(), function(cats) {
populateList(cats)
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment