2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-undef,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
define(['base'], App =>
|
|
|
|
App.controller('AnnouncementsController', function(
|
|
|
|
$scope,
|
|
|
|
$http,
|
2019-10-23 08:22:50 -04:00
|
|
|
eventTracking,
|
2018-11-05 05:06:39 -05:00
|
|
|
$window,
|
|
|
|
_
|
|
|
|
) {
|
|
|
|
$scope.announcements = []
|
|
|
|
$scope.ui = {
|
|
|
|
isOpen: false,
|
|
|
|
newItems: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
const refreshAnnouncements = () =>
|
|
|
|
$http.get('/announcements').then(function(response) {
|
|
|
|
$scope.announcements = response.data
|
|
|
|
return ($scope.ui.newItems = _.filter(
|
|
|
|
$scope.announcements,
|
|
|
|
announcement => !announcement.read
|
|
|
|
).length)
|
|
|
|
})
|
|
|
|
|
|
|
|
const markAnnouncementsAsRead = () =>
|
2019-10-23 08:22:50 -04:00
|
|
|
eventTracking.sendMB('announcement-alert-dismissed', {
|
2018-11-05 05:06:39 -05:00
|
|
|
blogPostId: $scope.announcements[0].id
|
|
|
|
})
|
|
|
|
|
|
|
|
$scope.logAnnouncementClick = () =>
|
2019-10-23 08:22:50 -04:00
|
|
|
eventTracking.sendMB('announcement-read-more-clicked', {
|
2018-11-05 05:06:39 -05:00
|
|
|
blogPostId: $scope.announcements[0].id
|
|
|
|
})
|
|
|
|
|
|
|
|
refreshAnnouncements()
|
|
|
|
|
|
|
|
$scope.toggleAnnouncementsUI = function() {
|
|
|
|
$scope.ui.isOpen = !$scope.ui.isOpen
|
|
|
|
|
|
|
|
if (!$scope.ui.isOpen && $scope.ui.newItems) {
|
|
|
|
$scope.ui.newItems = 0
|
|
|
|
return markAnnouncementsAsRead()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($scope.showAll = () => ($scope.ui.newItems = 0))
|
|
|
|
}))
|