diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 32a2718e..812eeaaa 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -701,7 +701,13 @@ ACTIVE_IDLE_CONFIRM_BODY_TEXT: 'Are you sure want to active your account with {{score}} scores?', ACTIVE_IDLE_SUCCESSFULLY: 'Active account successfully', ACTIVE_IDLE_ERROR: 'Active account failed', + FOLLOW_SUCCESSFULLY: 'Follow successfully', + FOLLOW_ERROR: 'Follow failed', + UNFOLLOW_SUCCESSFULLY: 'Unfollow successfully', + UNFOLLOW_ERROR: 'Unfollow failed', STATUS_FIELD: { + BTN_FOLLOW: 'Follow', + BTN_UNFOLLOW: 'Unfollow', PICTURE: 'Profile picture', RESET_DEFAULT_PICTURE: 'Reset to default picture', ADD_VIP_MONTHS: '+ VIP a month', diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index eca56386..ebed5cb9 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -701,7 +701,13 @@ ACTIVE_IDLE_CONFIRM_BODY_TEXT: '您确认要使用 {{score}} 积分来重新激活您的帐户?', ACTIVE_IDLE_SUCCESSFULLY: '激活帐户成功', ACTIVE_IDLE_ERROR: '激活帐户失败', + FOLLOW_SUCCESSFULLY: '添加关注成功', + FOLLOW_ERROR: '添加关注失败', + UNFOLLOW_SUCCESSFULLY: '取消关注成功', + UNFOLLOW_ERROR: '取消关注失败', STATUS_FIELD: { + BTN_FOLLOW: '关注', + BTN_UNFOLLOW: '取消关注', PICTURE: '头像', RESET_DEFAULT_PICTURE: '重置为默认图片', ADD_VIP_MONTHS: '+ VIP一个月', diff --git a/modules/core/client/controllers/header.client.controller.js b/modules/core/client/controllers/header.client.controller.js index ca0d6a7b..5d74a220 100644 --- a/modules/core/client/controllers/header.client.controller.js +++ b/modules/core/client/controllers/header.client.controller.js @@ -76,6 +76,13 @@ vm.getCountUnread(); }); + /** + * user-follow-changed + */ + $scope.$on('user-follow-changed', function (event, u) { + vm.user = Authentication.user = u; + }); + /** * getInvitationsCount */ @@ -97,9 +104,9 @@ */ vm.getFollowCount = function (item) { if (item.state.indexOf('followers') >= 0) { - return vm.user.followers.length; + return vm.user ? vm.user.followers.length : 0; } else { - return vm.user.following.length; + return vm.user ? vm.user.following.length : 0; } }; diff --git a/modules/core/client/less/btn-size.less b/modules/core/client/less/btn-size.less index ebdb2067..8ba212e8 100644 --- a/modules/core/client/less/btn-size.less +++ b/modules/core/client/less/btn-size.less @@ -109,4 +109,8 @@ border-color: @state-success-text; } } +} + +.btn-bold { + font-weight: 500; } \ No newline at end of file diff --git a/modules/core/client/less/mt.less b/modules/core/client/less/mt.less index e202d14a..6914ef6b 100644 --- a/modules/core/client/less/mt.less +++ b/modules/core/client/less/mt.less @@ -1537,6 +1537,10 @@ body { } } +.userinfo-name { + margin-top: 8px; +} + .lang-list { margin-left: 10px; line-height: 2; diff --git a/modules/users/client/controllers/userinfo/userinfo.client.controller.js b/modules/users/client/controllers/userinfo/userinfo.client.controller.js index e1ce656c..f43c7885 100644 --- a/modules/users/client/controllers/userinfo/userinfo.client.controller.js +++ b/modules/users/client/controllers/userinfo/userinfo.client.controller.js @@ -5,10 +5,11 @@ .module('users') .controller('UserInfoController', UserInfoController); - UserInfoController.$inject = ['$scope', '$state', 'Authentication', 'userResolve', 'ScoreLevelService', '$timeout', 'MeanTorrentConfig', - 'DebugConsoleService']; + UserInfoController.$inject = ['$scope', '$rootScope', '$state', 'Authentication', 'userResolve', 'ScoreLevelService', '$timeout', 'MeanTorrentConfig', 'UsersService', + 'DebugConsoleService', 'NotifycationService']; - function UserInfoController($scope, $state, Authentication, user, ScoreLevelService, $timeout, MeanTorrentConfig, mtDebug) { + function UserInfoController($scope, $rootScope, $state, Authentication, user, ScoreLevelService, $timeout, MeanTorrentConfig, UsersService, + mtDebug, NotifycationService) { var vm = this; vm.authentication = Authentication; @@ -35,5 +36,57 @@ function isContextUserSelf() { return vm.user.username === vm.authentication.user.username; } + + /** + * inMyFollowing + * @returns {boolean} + */ + vm.inMyFollowing = function () { + return vm.authentication.user.following.indexOf(vm.user._id) >= 0 ? true : false; + }; + + /** + * followTo + */ + vm.followTo = function () { + UsersService.userFollowTo({ + userId: vm.user._id + }).then(onSuccess) + .catch(onError); + + function onSuccess(response) { + mtDebug.info(response); + vm.authentication.user = Authentication.user = response; + $rootScope.$broadcast('user-follow-changed', response); + + NotifycationService.showSuccessNotify('FOLLOW_SUCCESSFULLY'); + } + + function onError(response) { + NotifycationService.showErrorNotify(response.data.message, 'FOLLOW_ERROR'); + } + }; + + /** + * unFollowTo + */ + vm.unFollowTo = function () { + UsersService.userUnfollowTo({ + userId: vm.user._id + }).then(onSuccess) + .catch(onError); + + function onSuccess(response) { + mtDebug.info(response); + vm.authentication.user = Authentication.user = response; + $rootScope.$broadcast('user-follow-changed', response); + + NotifycationService.showSuccessNotify('UNFOLLOW_SUCCESSFULLY'); + } + + function onError(response) { + NotifycationService.showErrorNotify(response.data.message, 'UNFOLLOW_ERROR'); + } + }; } }()); diff --git a/modules/users/client/services/users.client.service.js b/modules/users/client/services/users.client.service.js index a49a5b47..76cd3f1b 100644 --- a/modules/users/client/services/users.client.service.js +++ b/modules/users/client/services/users.client.service.js @@ -55,6 +55,20 @@ unIdle: { method: 'POST', url: '/api/users/unIdle' + }, + followTo: { + method: 'POST', + url: '/api/users/followTo/:userId', + params: { + userId: '@userId' + } + }, + unFollowTo: { + method: 'POST', + url: '/api/users/unFollowTo/:userId', + params: { + userId: '@userId' + } } }); @@ -92,6 +106,12 @@ }, userUnIdle: function () { return this.unIdle().$promise; + }, + userFollowTo: function (uid) { + return this.followTo(uid).$promise; + }, + userUnfollowTo: function (uid) { + return this.unFollowTo(uid).$promise; } }); diff --git a/modules/users/client/views/userinfo/userinfo.client.view.html b/modules/users/client/views/userinfo/userinfo.client.view.html index 0b54ea9d..529969ac 100644 --- a/modules/users/client/views/userinfo/userinfo.client.view.html +++ b/modules/users/client/views/userinfo/userinfo.client.view.html @@ -1,10 +1,10 @@