Skip to content

Commit

Permalink
Notifications now save their filter and type. Also updates the UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelclay committed Nov 16, 2016
1 parent 201b024 commit fd4db68
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 63 deletions.
17 changes: 10 additions & 7 deletions apps/notifications/models.py
Expand Up @@ -22,6 +22,7 @@ class MUserFeedNotification(mongo.Document):
user_id = mongo.IntField()
feed_id = mongo.IntField()
frequency = mongoengine_fields.IntEnumField(NotificationFrequency)
is_focus = mongo.BooleanField()
last_notification_date = mongo.DateTimeField(default=datetime.datetime.now)
is_email = mongo.BooleanField()
is_web = mongo.BooleanField()
Expand Down Expand Up @@ -58,12 +59,14 @@ def feeds_for_user(cls, user_id):

for feed in notifications:
notifications_by_feed[feed.feed_id] = {
'notifications': [],
'notification_freq': feed.frequency
'notification_types': [],
'notification_filter': "focus" if feed.is_focus else "unread",
}
if feed.is_email: notifications_by_feed[feed.feed_id]['notifications'].append('email')
if feed.is_web: notifications_by_feed[feed.feed_id]['notifications'].append('web')
if feed.is_ios: notifications_by_feed[feed.feed_id]['notifications'].append('ios')
if feed.is_android: notifications_by_feed[feed.feed_id]['notifications'].append('android')
if feed.is_email: notifications_by_feed[feed.feed_id]['notification_types'].append('email')
if feed.is_web: notifications_by_feed[feed.feed_id]['notification_types'].append('web')
if feed.is_ios: notifications_by_feed[feed.feed_id]['notification_types'].append('ios')
if feed.is_android: notifications_by_feed[feed.feed_id]['notification_types'].append('android')

return notifications_by_feed
return notifications_by_feed


3 changes: 2 additions & 1 deletion apps/notifications/urls.py
Expand Up @@ -3,5 +3,6 @@
from oauth2_provider import views as op_views

urlpatterns = patterns('',
url(r'^/?$', views.notifications_by_feed, name='notifications-by-feed'),
url(r'^$', views.notifications_by_feed, name='notifications-by-feed'),
url(r'^feed/?$', views.set_notifications_for_feed, name='set-notifications-for-feed'),
)
36 changes: 35 additions & 1 deletion apps/notifications/views.py
Expand Up @@ -10,4 +10,38 @@ def notifications_by_feed(request):
user = get_user(request)
notifications_by_feed = MUserFeedNotification.feeds_for_user(user.pk)

return notifications_by_feed
return notifications_by_feed

@ajax_login_required
@json.json_view
def set_notifications_for_feed(request):
user = get_user(request)
feed_id = request.POST['feed_id']
notification_types = request.POST.getlist('notification_types')
notification_filter = request.POST.get('notification_filter')

try:
notification = MUserFeedNotification.objects.get(user_id=user.pk, feed_id=feed_id)
except MUserFeedNotification.DoesNotExist:
params = {
"user_id": user.pk,
"feed_id": feed_id,
}
notification = MUserFeedNotification.objects.create(**params)

notification.is_focus = bool(notification_filter == "focus")
notification.is_email = bool('email' in notification_types)
notification.is_ios = bool('ios' in notification_types)
notification.is_android = bool('android' in notification_types)
notification.is_web = bool('web' in notification_types)
notification.save()

if (not notification.is_email and
not notification.is_ios and
not notification.is_android and
not notification.is_web):
notification.delete()

notifications_by_feed = MUserFeedNotification.feeds_for_user(user.pk)

return {"notifications_by_feed": notifications_by_feed}
60 changes: 50 additions & 10 deletions media/css/reader.css
Expand Up @@ -8821,6 +8821,10 @@ form.opml_import_form input {
/* = Notifications Modal = */
/* ======================= */

.NB-modal-notifications .NB-modal-title .NB-icon {
background: transparent url('/media/embed/icons/circular/menu_icn_notifications_128.png');
background-size: 28px;
}
.NB-modal.NB-modal-notifications .NB-fieldset {
border-bottom: none;
width: 100%;
Expand All @@ -8836,21 +8840,54 @@ form.opml_import_form input {
float: left;
overflow: hidden;
}
.NB-modal-notifications .NB-modal-section-site {
margin: 12px 0 0;
}

.NB-feed-notification {
width: 100%;
overflow: hidden;
position: relative;
padding: 10px 0;
border-bottom: 1px solid #F0F0F0;
}
.NB-feed-notification .NB-feed-notification-filter {
float: right;
margin: 0 12px;
.NB-feed-notification:last-child {
border-bottom: none;
}

.NB-feed-notification .NB-feed-title {
font-size: 12px;
padding: 0 260px 0 24px;
}
.NB-feed-notification .NB-feed-icon {
width: 16px;
height: 16px;
position: absolute;
top: 10px;
left: 0;
}
.NB-feed-notification .NB-feed-frequency-icon {
float: left;
margin: 0 7px 0 0;
clear: left;
width: 16px;
height: 16px;
margin: 4px 7px 0 0;
}
.NB-feed-notification .NB-feed-frequency {
float: left;
color: #A0A0A0;
font-size: 10px;
margin: 2px 0 0 0;
}

.NB-feed-notification .NB-feed-notification-controls {
position: relative;
top: 0;
right: 0;
}
.NB-feed-notification .NB-feed-notification-filter {
float: right;
margin: 0 12px;
}
.NB-feed-notification .NB-feed-notification-filter .NB-unread-icon,
.NB-feed-notification .NB-feed-notification-filter .NB-focus-icon {
Expand All @@ -8867,21 +8904,24 @@ form.opml_import_form input {
background-size: 8px;
}
.NB-feed-notification .segmented-control {
margin-top: -2px;
margin-bottom: 2px;
margin: 0 0 4px 0;
}
.NB-feed-notification .segmented-control li {
padding: 2px 6px;
font-size: 10px;
min-width: 36px;
}
.NB-feed-notification .segmented-control li:not(.NB-active) {
color: #A0A0A0;
}
.NB-feed-notification .NB-feed-notifications {
.NB-feed-notification .NB-feed-notification-types {
float: right;
clear: right;
}
.NB-modal-notifications .NB-modal-section-site {
margin: 12px 0 0;
.NB-feed-notification .NB-feed-notification-filter-focus {
width: 82px;
}


/* ===================== */
/* = Feedchooser Modal = */
/* ===================== */
Expand Down
12 changes: 12 additions & 0 deletions media/js/newsblur/common/assetmodel.js
Expand Up @@ -1482,6 +1482,18 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
}
},

set_notifications_for_feed: function(feed, callback) {
if (NEWSBLUR.Globals.is_authenticated) {
this.make_request('/notifications/feed/', {
'feed_id': feed.id,
'notification_types': feed.get('notification_types'),
'notification_filter': feed.get('notification_filter')
}, callback);
} else {
if ($.isFunction(callback)) callback();
}
},

send_story_email: function(data, callback, error_callback) {
if (NEWSBLUR.Globals.is_authenticated) {
this.make_request('/reader/send_story_email', data, callback, error_callback, {'timeout': 6000});
Expand Down
2 changes: 2 additions & 0 deletions media/js/newsblur/models/feeds.js
Expand Up @@ -271,6 +271,8 @@ NEWSBLUR.Collections.Feeds = Backbone.Collection.extend({
this.bind('change', this.detect_active_feed);
},

comparator: 'feed_title',

// ===========
// = Actions =
// ===========
Expand Down
27 changes: 19 additions & 8 deletions media/js/newsblur/reader/reader_notifications.js
Expand Up @@ -34,9 +34,13 @@ _.extend(NEWSBLUR.ReaderNotifications.prototype, {
var frequency = this.feed.get('notification_frequency');
var notifications = this.feed.get('notifications');

if (this.feed) {
NEWSBLUR.Modal.prototype.initialize_feed.call(this, feed_id);
}
NEWSBLUR.Modal.prototype.initialize_feed.call(this, feed_id);

var $site = $(".NB-modal-section-site", this.$modal);
$site.html(this.make_feed_notification(this.feed));

var $all = $(".NB-modal-section-all", this.$modal);
$all.html(this.make_feed_notifications());

this.resize();
},
Expand Down Expand Up @@ -68,7 +72,12 @@ _.extend(NEWSBLUR.ReaderNotifications.prototype, {
this.make_feed_chooser()
])),
$.make('div', { className: 'NB-modal-loading' }),
$.make('h2', { className: 'NB-modal-title' }, 'Notifications'),
$.make('h2', { className: 'NB-modal-title' }, [
$.make('div', { className: 'NB-modal-loading' }),
$.make('div', { className: 'NB-icon' }),
'Notificatons',
$.make('div', { className: 'NB-icon-dropdown' })
]),
(this.feed && $.make('div', { className: 'NB-fieldset NB-modal-submit' }, [
$.make('fieldset', [
$.make('legend', 'Site Notifications'),
Expand All @@ -80,7 +89,7 @@ _.extend(NEWSBLUR.ReaderNotifications.prototype, {
$.make('div', { className: 'NB-fieldset NB-modal-submit' }, [
$.make('fieldset', [
$.make('legend', 'All Notifications'),
$.make('div', { className: 'NB-modal-section'}, [
$.make('div', { className: 'NB-modal-section NB-modal-section-all'}, [
this.make_feed_notifications()
])
])
Expand All @@ -104,13 +113,15 @@ _.extend(NEWSBLUR.ReaderNotifications.prototype, {
},

make_feed_notifications: function() {
var notifications = this.model.get_feeds().filter(function(feed) {
return feed.get('notifications');
var site_feed_id = this.model.id;
var notifications = this.model.get_feeds().select(function(feed) {
return feed.get('notification_types') && feed.id != site_feed_id;
});
var $feeds = [];

notifications.sort(function(a, b) { return a.get('feed_title') < b.get('feed_title'); });
for (var feed in notifications) {
$feeds.push(this.make_feed_notification(feed));
$feeds.push(this.make_feed_notification(notifications[feed]));
}

return $feeds;
Expand Down

0 comments on commit fd4db68

Please sign in to comment.