openhab-android icon indicating copy to clipboard operation
openhab-android copied to clipboard

Filter notification list by severity

Open mueller-ma opened this issue 3 years ago • 1 comments

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".

mueller-ma avatar Sep 17 '22 12:09 mueller-ma

Does openhab-cloud allow for that? The notifications are fetched in pages, which means the backend needs to do that filtering.

maniac103 avatar Sep 17 '22 12:09 maniac103

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

mueller-ma avatar Sep 23 '22 05:09 mueller-ma

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"
                    }]
                });
            }
        });
};

iPavel89-work avatar Jun 28 '24 05:06 iPavel89-work

What do you want to say with that?

mueller-ma avatar Jun 28 '24 10:06 mueller-ma