From d20156e1f1db48fdb5bc7a162e9e6f86343c1429 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 24 Jan 2016 09:24:13 -0500 Subject: [PATCH] Add 'Updates' notification Ref #25. --- assets/javascripts/app/app.coffee | 1 + .../javascripts/templates/notif_tmpl.coffee | 9 +++++++ assets/javascripts/views/misc/updates.coffee | 25 +++++++++++++++++++ assets/stylesheets/components/_notif.scss | 1 - 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 assets/javascripts/views/misc/updates.coffee diff --git a/assets/javascripts/app/app.coffee b/assets/javascripts/app/app.coffee index e92a5722..f8389d8d 100644 --- a/assets/javascripts/app/app.coffee +++ b/assets/javascripts/app/app.coffee @@ -133,6 +133,7 @@ @settings.set 'count', ++visitCount new app.views.Notif 'Share', autoHide: null if visitCount is 5 new app.views.News() + new app.views.Updates() @updateChecker = new app.UpdateChecker() reload: -> diff --git a/assets/javascripts/templates/notif_tmpl.coffee b/assets/javascripts/templates/notif_tmpl.coffee index 2b32a9b4..839b04d4 100644 --- a/assets/javascripts/templates/notif_tmpl.coffee +++ b/assets/javascripts/templates/notif_tmpl.coffee @@ -26,6 +26,15 @@ app.templates.notifInvalidLocation = -> app.templates.notifNews = (news) -> notif 'Changelog', """
#{app.templates.newsList(news, years: false)}
""" +app.templates.notifUpdates = (docs) -> + html = """" + notif 'Updates', html + app.templates.notifShare = -> textNotif """ Hi there! """, """ Like DevDocs? Help us reach more developers by sharing the link with your friends, on diff --git a/assets/javascripts/views/misc/updates.coffee b/assets/javascripts/views/misc/updates.coffee new file mode 100644 index 00000000..7e01ba0d --- /dev/null +++ b/assets/javascripts/views/misc/updates.coffee @@ -0,0 +1,25 @@ +#= require views/misc/notif + +class app.views.Updates extends app.views.Notif + @className += ' _notif-news' + + init: -> + @updatedDocs = @getUpdatedDocs() + @show() if @updatedDocs.length + @markAllAsRead() + return + + render: -> + @html app.templates.notifUpdates(@updatedDocs) + return + + getUpdatedDocs: -> + return [] unless time = @getLastUpdateTime() + doc for doc in app.docs.all() when doc.mtime > time + + getLastUpdateTime: -> + app.settings.get 'version' + + markAllAsRead: -> + app.settings.set 'version', if app.config.env is 'production' then app.config.version else Math.floor(Date.now() / 1000) + return diff --git a/assets/stylesheets/components/_notif.scss b/assets/stylesheets/components/_notif.scss index 66ade3b7..f745c9dd 100644 --- a/assets/stylesheets/components/_notif.scss +++ b/assets/stylesheets/components/_notif.scss @@ -114,7 +114,6 @@ } ._notif-list { - margin: .5em 0; padding-left: 1rem; }