Merge branch 'labels' of git://github.com/michael-k/ttrss into michael-k-labels

Conflicts:
	qml/ttrss/sailfish/pages/FeedItem.qml
	qml/ttrss/sailfish/pages/LabelUpdater.qml
This commit is contained in:
Hauke Schade 2014-11-02 17:45:25 +01:00
commit 141bb79994
4 changed files with 127 additions and 52 deletions

View file

@ -187,7 +187,7 @@ ListModel {
root.itemUnreadChanged(m)
}
// TODO Add a callback to toogleRead() which can be used to display
// TODO Add a callback to toggleRead() which can be used to display
// errorMessage.
})
}
@ -202,7 +202,7 @@ ListModel {
root.itemStarChanged(m)
}
// TODO Add a callback to toogleStar() which can be used to display
// TODO Add a callback to toggleStar() which can be used to display
// errorMessage.
})
}
@ -217,8 +217,82 @@ ListModel {
root.itemPublishedChanged(m)
}
// TODO Add a callback to tooglePublished() which can be used to display
// errorMessage.
// TODO Add a callback to togglePublished() which can be used to
// display errorMessage.
})
}
function getLabels(callback) {
var ttrss = rootWindow.getTTRSS()
var item = getSelectedItem()
ttrss.getLabels(item.id, function(successful, errorMessage, labels) {
if (!successful) {
callback(false, errorMessage)
return
}
if (!labels || labels.length === 0) {
callback(true, "", [])
return
}
var i
var j
// This is in O(nm) where n is the number of labels defined and
// m the number of labels checked. It's unefficient, but it should
// be fast enough for us.
for (i = 0; i < labels.length; ++i) {
labels[i].checked = false
for (j = 0; j < item.labels.count; ++j) {
if(labels[i].id === item.labels.get(j).id) {
labels[i].checked = true
break
}
}
}
callback(true, "", labels)
})
}
function setLabel(labelId, assign, callback) {
var ttrss = rootWindow.getTTRSS()
var item = getSelectedItem()
ttrss.setLabel(item.id, labelId, assign,
function(successful, errorMessage) {
callback(successful, errorMessage);
})
}
function updateLabels(callback) {
var ttrss = rootWindow.getTTRSS()
var item = getSelectedItem()
ttrss.updateLabels(item.id, function(successful, errorMessage, labels) {
if (!successful) {
callback(false, errorMessage)
return
}
item.labels.clear()
for (var i = 0; i < labels.length; ++i) {
if (!labels[i].checked) {
continue
}
item.labels.append({
'id': parseInt(labels[i].id),
'caption': labels[i].caption,
'fg_color': (labels[i].fg_color === "" ? "black" : labels[i].fg_color),
'bg_color': (labels[i].bg_color === "" ? "white" : labels[i].bg_color)
})
}
callback(true, "", item.labels)
})
}

View file

@ -86,6 +86,7 @@ function initState() {
'lastfeeditem': { 'feedId': null, 'articleId': null },
'lastfeeditemunread':{ 'feedId': null, 'articleId': null },
'lastfeeditemrss': { 'feedId': null, 'articleId': null },
'labelscache': null,
};
requestsPending = {
@ -912,6 +913,22 @@ function process_updateFeedUnread(callback, httpreq) {
}
}
/**
* Get the list of configured labels.
* @param {int} The id of an arbitrary article.
* @param {function} A callback function with parameters boolean (indicating
* success), string (an optional error message), and array (the labels as
* objects).
*/
function getLabels(articleId, callback) {
if (state['labelscache']) {
callback(true, "", state['labelscache'])
return
}
updateLabels(articleId, callback)
}
/**
* Get the list of configured labels with a flag if a label is assigned to a
* specific article.
@ -920,7 +937,7 @@ function process_updateFeedUnread(callback, httpreq) {
* success), string (an optional error message), and array (the labels as
* objects).
*/
function getLabels(articleId, callback) {
function updateLabels(articleId, callback) {
if(responsesPending['getlabel'])
return;
@ -943,11 +960,11 @@ function getLabels(articleId, callback) {
'article_id': articleId
}
networkCall(params, function(http) { process_getLabels(callback, http) });
networkCall(params, function(http) { process_updateLabels(callback, http) });
}
/** @private */
function process_getLabels(callback, httpreq) {
function process_updateLabels(callback, httpreq) {
var response = process_readyState(httpreq);
responsesPending['getlabel'] = false;
@ -960,6 +977,8 @@ function process_getLabels(callback, httpreq) {
return;
}
state['labelscache'] = response.content
if(!processPendingRequests(callback) && callback) {
// This action is complete (as there's no other requests to do)
// Fire callback saying all ok

View file

@ -36,7 +36,6 @@ Page {
property bool nextId: false
property bool isCat: false
property var labels
property int itemId
anchors.margins: 0
@ -64,13 +63,13 @@ Page {
}
MenuItem {
text: qsTr("Assign Labels")
enabled: !network.loading
onClicked: {
var ttrss = rootWindow.getTTRSS();
ttrss.getLabels(itemId, function(successful, errorMessage,
feedItemModel.getLabels(function(successful, errorMessage,
labels) {
if (successful) {
var params = {
articleId: root.itemId,
labels: labels,
headline: root.pageTitle,
feedItemPage: root
@ -78,6 +77,8 @@ Page {
pageStack.push(Qt.resolvedUrl("LabelUpdater.qml"),
params);
}
// TODO make use of errorMessage
})
}
}
@ -340,7 +341,6 @@ Page {
//unreadSwitch.checked = unread
rss = data.rss
//rssSwitch.checked = rss
itemId = data.id
previousId = feedItemModel.hasPrevious()
nextId = feedItemModel.hasNext()
@ -353,35 +353,12 @@ Page {
}
function updateLabels() {
var ttrss = rootWindow.getTTRSS();
ttrss.getLabels(itemId, function(successful, errorMessage, labels) {
if (!successful) {
// TODO do something with errorMessage
return
feedItemModel.updateLabels(function(successful, errorMessage, labels) {
if (successful) {
root.labels = labels
}
var item = feedItemModel.getSelectedItem()
if (!item || !item.labels) {
return
}
item.labels.clear()
var newLabels = []
for (var index = 0; index < labels.length; ++index) {
if (!labels[index].checked) {
continue
}
item.labels.append({
'id': parseInt(labels[index].id),
'caption': labels[index].caption,
'fg_color': (labels[index].fg_color === "" ? "black" : labels[index].fg_color),
'bg_color': (labels[index].bg_color === "" ? "white" : labels[index].bg_color)
})
}
root.labels = item.labels
// TODO make use of errorMessage
})
}

View file

@ -25,7 +25,6 @@ import Sailfish.Silica 1.0
Page {
id: page
property int articleId
property string headline
property var labels
property var feedItemPage
@ -62,13 +61,14 @@ Page {
delegate: ListItem {
id: item
width: parent.width
property var label: page.labels[index]
Switch {
id: checkbox
checked: item.label.checked
enabled: !network.loading
anchors.verticalCenter: parent.verticalCenter
property bool noAPIcall: false
@ -85,17 +85,15 @@ Page {
page.labelsChanged = true
checkbox.busy = true
var ttrss = rootWindow.getTTRSS();
ttrss.setLabel(page.articleId, item.label.id,
checkbox.checked,
function(successful, errorMessage) {
checkbox.busy = false
if (!successful) {
checkbox.noAPIcall = true
checkbox.checked = !checkbox.checked
// TODO display errorMessage
}
})
feedItemModel.setLabel(item.label.id, checkbox.checked,
function(successful, errorMessage) {
checkbox.busy = false
if (!successful) {
checkbox.noAPIcall = true
checkbox.checked = !checkbox.checked
// TODO display errorMessage
}
})
}
}
@ -107,6 +105,13 @@ Page {
}
}
}
ViewPlaceholder {
enabled: listView.count === 0
text: network.loading ?
qsTr("Loading") :
qsTr("You have no label defined. You can create them in the webview.")
}
}
BusyIndicator {