updates.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. #= require views/misc/notif
  2. class app.views.Updates extends app.views.Notif
  3. @className += ' _notif-news'
  4. @defautOptions:
  5. autoHide: 30000
  6. init: ->
  7. @lastUpdateTime = @getLastUpdateTime()
  8. @updatedDocs = @getUpdatedDocs()
  9. @updatedDisabledDocs = @getUpdatedDisabledDocs()
  10. @show() if @updatedDocs.length > 0 or @updatedDisabledDocs.length > 0
  11. @markAllAsRead()
  12. return
  13. render: ->
  14. @html app.templates.notifUpdates(@updatedDocs, @updatedDisabledDocs)
  15. return
  16. getUpdatedDocs: ->
  17. return [] unless @lastUpdateTime
  18. doc for doc in app.docs.all() when doc.mtime > @lastUpdateTime
  19. getUpdatedDisabledDocs: ->
  20. return [] unless @lastUpdateTime
  21. doc for doc in app.disabledDocs.all() when doc.mtime > @lastUpdateTime and app.docs.findBy('slug_without_version', doc.slug_without_version)
  22. getLastUpdateTime: ->
  23. app.settings.get 'version'
  24. markAllAsRead: ->
  25. app.settings.set 'version', if app.config.env is 'production' then app.config.version else Math.floor(Date.now() / 1000)
  26. return