system-messages.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-undef,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. define(['base'], function(App) {
  14. const MESSAGE_POLL_INTERVAL = 15 * 60 * 1000
  15. // Controller for messages (array)
  16. App.controller('SystemMessagesController', ($http, $scope) => {
  17. $scope.messages = window.systemMessages
  18. var pollSystemMessages = function() {
  19. $http
  20. .get('/system/messages')
  21. .then(response => {
  22. $scope.messages = response.data
  23. })
  24. .catch(() => {
  25. // ignore errors
  26. })
  27. }
  28. pollSystemMessages()
  29. setInterval(pollSystemMessages, MESSAGE_POLL_INTERVAL)
  30. })
  31. // Controller for individual message (show/hide)
  32. return App.controller('SystemMessageController', function($scope, $sce) {
  33. $scope.hidden = $.localStorage(`systemMessage.hide.${$scope.message._id}`)
  34. $scope.protected = $scope.message._id === 'protected'
  35. $scope.htmlContent = $scope.message.content
  36. return ($scope.hide = function() {
  37. if (!$scope.protected) {
  38. // do not allow protected messages to be hidden
  39. $scope.hidden = true
  40. return $.localStorage(`systemMessage.hide.${$scope.message._id}`, true)
  41. }
  42. })
  43. })
  44. })