瀏覽代碼

Add 'Updates' notification

Ref #25.
Thibaut Courouble 10 年之前
父節點
當前提交
d20156e1f1

+ 1 - 0
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: ->

+ 9 - 0
assets/javascripts/templates/notif_tmpl.coffee

@@ -26,6 +26,15 @@ app.templates.notifInvalidLocation = ->
 app.templates.notifNews = (news) ->
   notif 'Changelog', """<div class="_notif-content _notif-news">#{app.templates.newsList(news, years: false)}</div>"""
 
+app.templates.notifUpdates = (docs) ->
+  html = """<ul class="_notif-content _notif-list">"""
+  for doc in docs
+    html += "<li>#{doc.name}"
+    html += " (#{doc.release})" if doc.release
+    html += "</li>"
+  html += "</ul>"
+  notif 'Updates', html
+
 app.templates.notifShare = ->
   textNotif """ Hi there! """,
             """ Like DevDocs? Help us reach more developers by sharing the link with your friends, on

+ 25 - 0
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

+ 0 - 1
assets/stylesheets/components/_notif.scss

@@ -114,7 +114,6 @@
 }
 
 ._notif-list {
-  margin: .5em 0;
   padding-left: 1rem;
 }