openhab-android
openhab-android copied to clipboard
Filter notification list by severity
Is your feature request related to a problem? Please describe.
I'd like to have an overview of all notifications with a specific severity.
Describe the solution you'd like
Add an action bar item to filter notification list by severity. It should default to "all notifications".
Does openhab-cloud allow for that? The notifications are fetched in pages, which means the backend needs to do that filtering.
I first thought about doing the filtering on the client, but it makes indeed more sense on the server: https://github.com/openhab/openhab-cloud/issues/383
file routes/api.js
exports.notificationsget = function (req, res) {
var limit = req.query.limit > 0 ? parseInt(req.query.limit) : 10,
skip = req.query.skip > 0 ? parseInt(req.query.skip) : 0;
var filter = { user: req.user.id };
// Добавляем фильтр по параметру severity, если он указан в запросе
if (req.query.severity) {
filter.severity = req.query.severity;
}
Notification.find(filter, '-user')
.limit(limit)
.skip(skip)
.sort({ created: 'desc' })
.exec(function (error, notifications) {
if (!error) {
res.status(200).json(notifications);
} else {
return res.status(500).json({
errors: [{
message: "Error getting notifications"
}]
});
}
});
};
What do you want to say with that?