From d0f27f970448525a271bd3dedb30f5e80dbb764b Mon Sep 17 00:00:00 2001 From: OldHawk Date: Sun, 10 Jun 2018 18:04:03 +0800 Subject: [PATCH] feat(home): refresh new torrents and opened tickets status when torrent was reviewed or tickets was replied. --- .../client/controllers/header.client.controller.js | 14 ++++++++++++++ .../torrent-list-item.client.directive.js | 5 +++-- .../view-message-tickets.client.controller.js | 9 +++++---- .../controllers/torrent-info.client.controller.js | 5 +++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/modules/core/client/controllers/header.client.controller.js b/modules/core/client/controllers/header.client.controller.js index 4cd15674..cd5040aa 100644 --- a/modules/core/client/controllers/header.client.controller.js +++ b/modules/core/client/controllers/header.client.controller.js @@ -154,6 +154,20 @@ vm.getCountUnread(); }); + /** + * new-torrents-changed + */ + $scope.$on('new-torrents-changed', function (event, args) { + vm.getNewTorrentsCount(); + }); + + /** + * opened-tickets-changed + */ + $scope.$on('opened-tickets-changed', function (event, args) { + vm.getTicketsOpenedCount(); + }); + /** * user-invitations-changed */ diff --git a/modules/core/client/directives/torrent-list-item.client.directive.js b/modules/core/client/directives/torrent-list-item.client.directive.js index 0df43219..8c82c3b1 100644 --- a/modules/core/client/directives/torrent-list-item.client.directive.js +++ b/modules/core/client/directives/torrent-list-item.client.directive.js @@ -5,9 +5,9 @@ .directive('torrentListItem', torrentListItem); function torrentListItem() { - var TorrentsItemController = ['$scope', '$state', 'TorrentGetInfoServices', 'ResourcesTagsServices', '$timeout', 'DownloadService', 'MeanTorrentConfig', + var TorrentsItemController = ['$scope', '$rootScope', '$state', 'TorrentGetInfoServices', 'ResourcesTagsServices', '$timeout', 'DownloadService', 'MeanTorrentConfig', 'TorrentsService', 'Authentication', 'NotifycationService', 'ModalConfirmService', '$translate', 'moment', - function ($scope, $state, TorrentGetInfoServices, ResourcesTagsServices, $timeout, DownloadService, MeanTorrentConfig, TorrentsService, Authentication, + function ($scope, $rootScope, $state, TorrentGetInfoServices, ResourcesTagsServices, $timeout, DownloadService, MeanTorrentConfig, TorrentsService, Authentication, NotifycationService, ModalConfirmService, $translate, moment) { var vm = this; @@ -292,6 +292,7 @@ _torrentId: item._id }, function (res) { $scope.list[$scope.list.indexOf(item)] = res; + $rootScope.$broadcast('new-torrents-changed'); NotifycationService.showSuccessNotify('TORRENT_SETREVIEWED_SUCCESSFULLY'); }, function (res) { NotifycationService.showErrorNotify(res.data.message, 'TORRENT_SETREVIEWED_ERROR'); diff --git a/modules/tickets/client/controllers/admin/view-message-tickets.client.controller.js b/modules/tickets/client/controllers/admin/view-message-tickets.client.controller.js index 6ecbc94b..cc20079c 100644 --- a/modules/tickets/client/controllers/admin/view-message-tickets.client.controller.js +++ b/modules/tickets/client/controllers/admin/view-message-tickets.client.controller.js @@ -5,11 +5,11 @@ .module('tickets') .controller('ViewMessageTicketController', ViewMessageTicketController); - ViewMessageTicketController.$inject = ['$scope', '$state', '$timeout', '$translate', 'Authentication', 'MessageTicketsService', 'ModalConfirmService', 'NotifycationService', 'marked', - 'DebugConsoleService', 'MeanTorrentConfig', '$filter', '$stateParams', 'Upload', 'localStorageService', '$compile']; + ViewMessageTicketController.$inject = ['$scope', '$rootScope', '$state', '$timeout', '$translate', 'Authentication', 'MessageTicketsService', 'ModalConfirmService', + 'NotifycationService', 'marked', 'DebugConsoleService', 'MeanTorrentConfig', '$filter', '$stateParams', 'Upload', 'localStorageService', '$compile']; - function ViewMessageTicketController($scope, $state, $timeout, $translate, Authentication, MessageTicketsService, ModalConfirmService, NotifycationService, marked, - mtDebug, MeanTorrentConfig, $filter, $stateParams, Upload, localStorageService, $compile) { + function ViewMessageTicketController($scope, $rootScope, $state, $timeout, $translate, Authentication, MessageTicketsService, ModalConfirmService, + NotifycationService, marked, mtDebug, MeanTorrentConfig, $filter, $stateParams, Upload, localStorageService, $compile) { var vm = this; vm.user = Authentication.user; vm.itemsPerPageConfig = MeanTorrentConfig.meanTorrentConfig.itemsPerPage; @@ -154,6 +154,7 @@ vm.postReplyFields = {}; vm.currentPage = Math.ceil(res._replies.length / vm.itemsPerPage); vm.ticket = res; + $rootScope.$broadcast('opened-tickets-changed'); vm.pageChanged(); $scope.$broadcast('show-errors-reset', 'vm.replyForm'); diff --git a/modules/torrents/client/controllers/torrent-info.client.controller.js b/modules/torrents/client/controllers/torrent-info.client.controller.js index e9eb8ed3..09f9ef49 100644 --- a/modules/torrents/client/controllers/torrent-info.client.controller.js +++ b/modules/torrents/client/controllers/torrent-info.client.controller.js @@ -5,12 +5,12 @@ .module('torrents') .controller('TorrentsInfoController', TorrentsInfoController); - TorrentsInfoController.$inject = ['$scope', '$state', '$stateParams', '$translate', 'Authentication', 'Notification', 'TorrentsService', + TorrentsInfoController.$inject = ['$scope', '$rootScope', '$state', '$stateParams', '$translate', 'Authentication', 'Notification', 'TorrentsService', 'MeanTorrentConfig', 'DownloadService', '$sce', '$filter', 'CommentsService', 'ModalConfirmService', 'marked', 'Upload', '$timeout', 'SubtitlesService', 'getStorageLangService', 'NotifycationService', 'DebugConsoleService', 'TorrentGetInfoServices', 'AlbumsService', 'localStorageService', '$compile', 'SideOverlay', 'ResourcesTagsServices', 'CollectionsService', 'moment']; - function TorrentsInfoController($scope, $state, $stateParams, $translate, Authentication, Notification, TorrentsService, MeanTorrentConfig, + function TorrentsInfoController($scope, $rootScope, $state, $stateParams, $translate, Authentication, Notification, TorrentsService, MeanTorrentConfig, DownloadService, $sce, $filter, CommentsService, ModalConfirmService, marked, Upload, $timeout, SubtitlesService, getStorageLangService, NotifycationService, mtDebug, TorrentGetInfoServices, AlbumsService, localStorageService, $compile, SideOverlay, ResourcesTagsServices, CollectionsService, moment) { @@ -191,6 +191,7 @@ _torrentId: vm.torrentLocalInfo._id }, function (res) { vm.torrentLocalInfo = res; + $rootScope.$broadcast('new-torrents-changed'); NotifycationService.showSuccessNotify('TORRENT_SETREVIEWED_SUCCESSFULLY'); }, function (res) { NotifycationService.showErrorNotify(res.data.message, 'TORRENT_SETREVIEWED_ERROR');