diff --git a/modules/users/client/config/users.client.routes.js b/modules/users/client/config/users.client.routes.js index 810de7ff..ff715c1e 100644 --- a/modules/users/client/config/users.client.routes.js +++ b/modules/users/client/config/users.client.routes.js @@ -97,6 +97,30 @@ pageTitle: 'PAGETITLE.MY_FOLLOWING' } }) + .state('follow.userFollowers', { + url: '/:userId/followers', + templateUrl: '/modules/users/client/views/follow/user-followers.client.view.html', + controller: 'UserFollowersController', + controllerAs: 'vm', + resolve: { + userResolve: getUser + }, + data: { + pageTitle: 'PAGETITLE.USER_FOLLOWERS' + } + }) + .state('follow.userFollowing', { + url: '/:userId/following', + templateUrl: '/modules/users/client/views/follow/user-following.client.view.html', + controller: 'UserFollowingController', + controllerAs: 'vm', + resolve: { + userResolve: getUser + }, + data: { + pageTitle: 'PAGETITLE.USER_FOLLOWING' + } + }) .state('status', { abstract: true, url: '/status', @@ -246,5 +270,13 @@ pageTitle: 'PAGETITLE.PASSWORD_RESET' } }); + + getUser.$inject = ['$stateParams', 'AdminService']; + + function getUser($stateParams, AdminService) { + return AdminService.get({ + userId: $stateParams.userId + }).$promise; + } } }()); diff --git a/modules/users/client/controllers/follow/user-followers.client.controller.js b/modules/users/client/controllers/follow/user-followers.client.controller.js new file mode 100644 index 00000000..f818893d --- /dev/null +++ b/modules/users/client/controllers/follow/user-followers.client.controller.js @@ -0,0 +1,142 @@ +(function () { + 'use strict'; + + angular + .module('users') + .controller('UserFollowersController', UserFollowersController); + + UserFollowersController.$inject = ['$scope', '$rootScope', '$state', '$timeout', '$translate', 'Authentication', 'UsersService', 'ScoreLevelService', 'MeanTorrentConfig', 'DebugConsoleService', + 'NotifycationService', 'userResolve']; + + function UserFollowersController($scope, $rootScope, $state, $timeout, $translate, Authentication, UsersService, ScoreLevelService, MeanTorrentConfig, mtDebug, + NotifycationService, userResolve) { + var vm = this; + vm.me = Authentication.user; + vm.user = userResolve; + vm.scoreLevelData = ScoreLevelService.getScoreLevelJson(vm.user.score); + vm.itemsPerPageConfig = MeanTorrentConfig.meanTorrentConfig.itemsPerPage; + vm.announceConfig = MeanTorrentConfig.meanTorrentConfig.announce; + + /** + * buildPager + */ + vm.buildPager = function () { + vm.pagedItems = []; + vm.itemsPerPage = vm.itemsPerPageConfig.followListPerPage; + vm.currentPage = 1; + vm.figureOutItemsToDisplay(); + }; + + /** + * figureOutItemsToDisplay + * @param callback + */ + vm.figureOutItemsToDisplay = function (callback) { + vm.getUserFollowers(vm.currentPage, function (items) { + vm.filterLength = items.total; + vm.pagedItems = items; + + if (callback) callback(); + }); + }; + + /** + * getUserFollowers + */ + vm.getUserFollowers = function (p, callback) { + vm.statusMsg = 'FOLLOW.STATUS_GETTING'; + + UsersService.getUserFollowers({ + userId: vm.user._id, + skip: (p - 1) * vm.itemsPerPage, + limit: vm.itemsPerPage + }) + .then(onSuccess) + .catch(onError); + + function onSuccess(data) { + vm.statusMsg = undefined; + mtDebug.info(data); + callback(data); + } + + function onError(data) { + vm.statusMsg = 'FOLLOW.STATUS_GETTING_ERROR'; + } + }; + + /** + * pageChanged + */ + vm.pageChanged = function () { + var element = angular.element('#top_of_follow_list'); + + vm.figureOutItemsToDisplay(function () { + $timeout(function () { + $('html,body').animate({scrollTop: element[0].offsetTop - 60}, 200); + }, 10); + }); + }; + + /** + * followTo + */ + vm.followTo = function (u) { + UsersService.userFollowTo({ + userId: u._id + }).then(onSuccess) + .catch(onError); + + function onSuccess(response) { + mtDebug.info(response); + vm.me = Authentication.user = response; + $rootScope.$broadcast('user-follow-changed', response); + + NotifycationService.showSuccessNotify('FOLLOW_SUCCESSFULLY'); + } + + function onError(response) { + NotifycationService.showErrorNotify($translate.instant(response.data.message, {name: u.displayName}), 'FOLLOW_ERROR'); + } + }; + + /** + * unFollowTo + */ + vm.unFollowTo = function (u) { + UsersService.userUnfollowTo({ + userId: u._id + }).then(onSuccess) + .catch(onError); + + function onSuccess(response) { + mtDebug.info(response); + vm.me = Authentication.user = response; + $rootScope.$broadcast('user-follow-changed', response); + + NotifycationService.showSuccessNotify('UNFOLLOW_SUCCESSFULLY'); + } + + function onError(response) { + NotifycationService.showErrorNotify(response.data.message, 'UNFOLLOW_ERROR'); + } + }; + + /** + * inMyFollowing + * @returns {boolean} + */ + vm.inMyFollowing = function (u) { + return vm.me.following.indexOf(u._id) >= 0 ? true : false; + }; + + /** + * isContextUserSelf + * @returns {boolean} + */ + vm.isContextUserSelf = function (u) { + return vm.me.username === u.username; + } + + } +}()); diff --git a/modules/users/client/controllers/follow/user-following.client.controller.js b/modules/users/client/controllers/follow/user-following.client.controller.js new file mode 100644 index 00000000..f08c97c8 --- /dev/null +++ b/modules/users/client/controllers/follow/user-following.client.controller.js @@ -0,0 +1,142 @@ +(function () { + 'use strict'; + + angular + .module('users') + .controller('UserFollowingController', UserFollowingController); + + UserFollowingController.$inject = ['$scope', '$rootScope', '$state', '$timeout', '$translate', 'Authentication', 'UsersService', 'ScoreLevelService', 'MeanTorrentConfig', 'DebugConsoleService', + 'NotifycationService', 'userResolve']; + + function UserFollowingController($scope, $rootScope, $state, $timeout, $translate, Authentication, UsersService, ScoreLevelService, MeanTorrentConfig, mtDebug, + NotifycationService, userResolve) { + var vm = this; + vm.me = Authentication.user; + vm.user = userResolve; + vm.scoreLevelData = ScoreLevelService.getScoreLevelJson(vm.user.score); + vm.itemsPerPageConfig = MeanTorrentConfig.meanTorrentConfig.itemsPerPage; + vm.announceConfig = MeanTorrentConfig.meanTorrentConfig.announce; + + /** + * buildPager + */ + vm.buildPager = function () { + vm.pagedItems = []; + vm.itemsPerPage = vm.itemsPerPageConfig.followListPerPage; + vm.currentPage = 1; + vm.figureOutItemsToDisplay(); + }; + + /** + * figureOutItemsToDisplay + * @param callback + */ + vm.figureOutItemsToDisplay = function (callback) { + vm.getUserFollowing(vm.currentPage, function (items) { + vm.filterLength = items.total; + vm.pagedItems = items; + + if (callback) callback(); + }); + }; + + /** + * getUserFollowing + */ + vm.getUserFollowing = function (p, callback) { + vm.statusMsg = 'FOLLOW.STATUS_GETTING'; + + UsersService.getUserFollowing({ + userId: vm.user._id, + skip: (p - 1) * vm.itemsPerPage, + limit: vm.itemsPerPage + }) + .then(onSuccess) + .catch(onError); + + function onSuccess(data) { + vm.statusMsg = undefined; + mtDebug.info(data); + callback(data); + } + + function onError(data) { + vm.statusMsg = 'FOLLOW.STATUS_GETTING_ERROR'; + } + }; + + /** + * pageChanged + */ + vm.pageChanged = function () { + var element = angular.element('#top_of_follow_list'); + + vm.figureOutItemsToDisplay(function () { + $timeout(function () { + $('html,body').animate({scrollTop: element[0].offsetTop - 60}, 200); + }, 10); + }); + }; + + /** + * followTo + */ + vm.followTo = function (u) { + UsersService.userFollowTo({ + userId: u._id + }).then(onSuccess) + .catch(onError); + + function onSuccess(response) { + mtDebug.info(response); + vm.me = Authentication.user = response; + $rootScope.$broadcast('user-follow-changed', response); + + NotifycationService.showSuccessNotify('FOLLOW_SUCCESSFULLY'); + } + + function onError(response) { + NotifycationService.showErrorNotify($translate.instant(response.data.message, {name: u.displayName}), 'FOLLOW_ERROR'); + } + }; + + /** + * unFollowTo + */ + vm.unFollowTo = function (u) { + UsersService.userUnfollowTo({ + userId: u._id + }).then(onSuccess) + .catch(onError); + + function onSuccess(response) { + mtDebug.info(response); + vm.me = Authentication.user = response; + $rootScope.$broadcast('user-follow-changed', response); + + NotifycationService.showSuccessNotify('UNFOLLOW_SUCCESSFULLY'); + } + + function onError(response) { + NotifycationService.showErrorNotify(response.data.message, 'UNFOLLOW_ERROR'); + } + }; + + /** + * inMyFollowing + * @returns {boolean} + */ + vm.inMyFollowing = function (u) { + return vm.me.following.indexOf(u._id) >= 0 ? true : false; + }; + + /** + * isContextUserSelf + * @returns {boolean} + */ + vm.isContextUserSelf = function (u) { + return vm.me.username === u.username; + } + + } +}()); diff --git a/modules/users/client/services/users.client.service.js b/modules/users/client/services/users.client.service.js index affa107b..8c1d9350 100644 --- a/modules/users/client/services/users.client.service.js +++ b/modules/users/client/services/users.client.service.js @@ -79,6 +79,16 @@ method: 'GET', url: '/api/users/following', isArray: true + }, + userFollowers: { + method: 'GET', + url: '/api/users/:userId/followers', + isArray: true + }, + userFollowing: { + method: 'GET', + url: '/api/users/:userId/following', + isArray: true } }); @@ -128,6 +138,12 @@ }, getMyFollowing: function (params) { return this.myFollowing(params).$promise; + }, + getUserFollowers: function (params) { + return this.userFollowers(params).$promise; + }, + getUserFollowing: function (params) { + return this.userFollowing(params).$promise; } }); diff --git a/modules/users/client/views/admin/view-user.client.view.html b/modules/users/client/views/admin/view-user.client.view.html index 1eefc114..605d1e30 100644 --- a/modules/users/client/views/admin/view-user.client.view.html +++ b/modules/users/client/views/admin/view-user.client.view.html @@ -2,7 +2,7 @@