From c5bb4f796922036ca88f1bd8f49f8c2b9a72308e Mon Sep 17 00:00:00 2001 From: OldHawk Date: Thu, 11 Jan 2018 12:53:02 +0800 Subject: [PATCH] feat(requests): add request my responses list view, route, controller --- config/env/torrents.js | 5 +- modules/core/client/app/trans-string-en.js | 7 +- modules/core/client/app/trans-string-zh.js | 13 ++- .../client/config/requests.client.routes.js | 7 ++ .../requests-add.client.controller.js | 1 + .../requests-res.client.controller.js | 88 +++++++++++++++ modules/requests/client/less/requests.less | 18 ++- .../views/requests-add.client.view.html | 18 ++- .../views/requests-list.client.view.html | 23 ++-- .../client/views/requests-my.client.view.html | 23 ++-- .../views/requests-res.client.view.html | 104 ++++++++++++++++++ .../controllers/requests.server.controller.js | 9 ++ .../server/models/request.server.model.js | 6 +- 13 files changed, 293 insertions(+), 29 deletions(-) create mode 100644 modules/requests/client/controllers/requests-res.client.controller.js create mode 100644 modules/requests/client/views/requests-res.client.view.html diff --git a/config/env/torrents.js b/config/env/torrents.js index 0156c941..bf686a59 100644 --- a/config/env/torrents.js +++ b/config/env/torrents.js @@ -376,7 +376,10 @@ module.exports = { forumReplyContentLength: 2048, makerGroupDescLength: 2048, - collectionsOverviewLength: 2048 + collectionsOverviewLength: 2048, + + requestDescLength: 1024, + requestCommentLength: 512 }, /** diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 52aaaed4..02fd5990 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -185,6 +185,7 @@ FORUM: 'Forum', REQUESTS: 'Requests', REQUESTS_MY: 'My Requests', + REQUESTS_RES: 'My Responses', REQUESTS_ADD: 'Add Requests', ADMIN_USER_LIST: 'User List', ADMIN_USER_VIEW: 'View User', @@ -705,6 +706,7 @@ REQUESTS: { NAV_LIST: 'Requests List', NAV_MY: 'My Requests', + NAV_RES: 'My Responses', NAV_ADD: 'Add Request', FORM_TITLE: 'Resource Title', FORM_TITLE_REQUIRED: 'Resource title is required', @@ -714,6 +716,7 @@ FORM_REWARDS_MAX_MIN: 'Rewards score numbers must more than {{min}} and less than {{max}}', BTN_SUBMIT_REQUEST: 'Submit Request', NO_MY_REQUESTS: 'You aren’t post any request.', + NO_RES_REQUESTS: 'You aren’t response any request.', NO_REQUESTS: 'Has no anybody post request.', STATUS_GETTING: 'Getting requests, please waiting ...', STATUS_GETTING_ERROR: 'Getting requests ERROR!', @@ -721,8 +724,10 @@ POST_REQUEST_FAILED: 'Create request failed', FIELD_TITLE: 'Title', FIELD_TYPE: 'Type', - FIELD_CREATEDAT: 'Created At', + FIELD_LIFE: 'Life', FIELD_REWARDS: 'Rewards', + FIELD_COMMENTS: 'Comments', + FIELD_RESPONSES: 'responses', FIELD_USER: 'User', DESC_LIST: '### NOTE: \n - The list contains only the last `{{days}}` days of the requests. \n - If your response is accepted, the requestor\'s reward score will be automatically transferred to your account. \n - Only the torrents reviewed by the administrator can be accepted by the requestor. \n - The requester can only accept one of the responses. \n - If your response is complains, your account may be punished, Please respond to the user\'s request carefully.', DESC_MY: '### NOTE: \n - If you accept a response, your reward score will be transferred to the respondent\'s account that you accept. \n - Only the torrents reviewed by the administrator can be accepted by you. \n - You can only accept one of the responses. \n - The request over `{{days}}` days has expired and cannot accept the response, you can only post the request again. \n - If your score is maliciously damaged, please mail to the [administrator](mailto:{{admin}})', diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index 336635d5..ea63255c 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -185,6 +185,7 @@ FORUM: '论坛', REQUESTS: '求种', REQUESTS_MY: '我的求种', + REQUESTS_RES: '我的响应', REQUESTS_ADD: '我要求种', ADMIN_USER_LIST: '用户管理', ADMIN_USER_VIEW: '查看用户', @@ -703,9 +704,10 @@ //requests REQUESTS: { - NAV_LIST: '求种请求列表', - NAV_MY: '我的求种请求', - NAV_ADD: '发起求种请求', + NAV_LIST: '求种列表', + NAV_MY: '我的求种', + NAV_RES: '我的响应', + NAV_ADD: '发起请求', FORM_TITLE: '资源标题', FORM_TITLE_REQUIRED: '资源标题不能为空', FORM_DESC: '对资源的要求', @@ -714,6 +716,7 @@ FORM_REWARDS_MAX_MIN: '悬赏积分必须大于 {{min}} 且小于 {{max}}', BTN_SUBMIT_REQUEST: '提交请求', NO_MY_REQUESTS: '您没有提交过任何求种请求.', + NO_RES_REQUESTS: '您没有响应过任何求种请求.', NO_REQUESTS: '还有没任何用户发起求种请求.', STATUS_GETTING: '正在获取求种请求, 请稍候 ...', STATUS_GETTING_ERROR: '获取求种请求失败!', @@ -721,8 +724,10 @@ POST_REQUEST_FAILED: '创建求种请求失败!', FIELD_TITLE: '求种标题', FIELD_TYPE: '求种类型', - FIELD_CREATEDAT: '创建时间', + FIELD_LIFE: '创建时间', FIELD_REWARDS: '悬赏积分', + FIELD_COMMENTS: '留言', + FIELD_RESPONSES: '响应', FIELD_USER: '求种用户', DESC_LIST: '### 提示: \n - 此列表只包含最近 `{{days}}` 天内发布的求种请求. \n - 如果你的回应被采纳,请求者悬赏的积分将自动转入你的帐户. \n - 只有被管理员审核通过的种子才能被请求者接受. \n - 请求者只能接受多个响应中的一个. \n - 如果你的响应被请求者投诉,你的帐号就可能会受到惩罚, 请认真响应用户的请求.', DESC_MY: '### 提示: \n - 如果您接受一个响应,你的悬赏积分就会转入你接受的响应者的帐户. \n - 只有被管理员审核通过的种子才能被您接受. \n - 您只能接受多个响应中的一个. \n - 超过 `{{days}}` 天的请求已经过期且不能接受响应, 如果需要你只能再次发起请求. \n - 如果您的积分受到恶意损害,请向管理员[投诉](mailto:{{admin}}).', diff --git a/modules/requests/client/config/requests.client.routes.js b/modules/requests/client/config/requests.client.routes.js index aa0780dd..1c2370a6 100644 --- a/modules/requests/client/config/requests.client.routes.js +++ b/modules/requests/client/config/requests.client.routes.js @@ -31,6 +31,13 @@ pageTitle: 'PAGETITLE.REQUESTS_MY' } }) + .state('requests.res', { + url: '/res', + templateUrl: '/modules/requests/client/views/requests-res.client.view.html', + data: { + pageTitle: 'PAGETITLE.REQUESTS_RES' + } + }) .state('requests.add', { url: '/add', templateUrl: '/modules/requests/client/views/requests-add.client.view.html', diff --git a/modules/requests/client/controllers/requests-add.client.controller.js b/modules/requests/client/controllers/requests-add.client.controller.js index deb3c1b6..379ff4fe 100644 --- a/modules/requests/client/controllers/requests-add.client.controller.js +++ b/modules/requests/client/controllers/requests-add.client.controller.js @@ -15,6 +15,7 @@ vm.itemsPerPageConfig = MeanTorrentConfig.meanTorrentConfig.itemsPerPage; vm.requestsConfig = MeanTorrentConfig.meanTorrentConfig.requests; vm.torrentTypeConfig = MeanTorrentConfig.meanTorrentConfig.torrentType; + vm.inputLengthConfig = MeanTorrentConfig.meanTorrentConfig.inputLength; vm.request = { type: 'movie', diff --git a/modules/requests/client/controllers/requests-res.client.controller.js b/modules/requests/client/controllers/requests-res.client.controller.js new file mode 100644 index 00000000..1945591a --- /dev/null +++ b/modules/requests/client/controllers/requests-res.client.controller.js @@ -0,0 +1,88 @@ +(function () { + 'use strict'; + + angular + .module('requests') + .controller('RequestsResController', RequestsResController); + + RequestsResController.$inject = ['$scope', '$rootScope', '$state', '$timeout', '$translate', 'Authentication', 'RequestsService', 'ScoreLevelService', 'MeanTorrentConfig', 'DebugConsoleService', + 'NotifycationService', 'uibButtonConfig', 'marked']; + + function RequestsResController($scope, $rootScope, $state, $timeout, $translate, Authentication, RequestsService, ScoreLevelService, MeanTorrentConfig, mtDebug, + NotifycationService, uibButtonConfig, marked) { + var vm = this; + vm.user = Authentication.user; + vm.itemsPerPageConfig = MeanTorrentConfig.meanTorrentConfig.itemsPerPage; + vm.requestsConfig = MeanTorrentConfig.meanTorrentConfig.requests; + vm.announceConfig = MeanTorrentConfig.meanTorrentConfig.announce; + + /** + * getRequestsDesc + * @returns {*} + */ + vm.getRequestsDesc = function () { + var ts = $translate.instant('REQUESTS.DESC_RES', { + days: vm.requestsConfig.requestExpires / (60 * 60 * 1000 * 24), + admin: vm.announceConfig.admin + }); + + return marked(ts, {sanitize: true}); + }; + + /** + * buildPager + */ + vm.buildPager = function () { + vm.pagedItems = []; + vm.itemsPerPage = vm.itemsPerPageConfig.requestListPerPage; + vm.currentPage = 1; + vm.figureOutItemsToDisplay(); + }; + + /** + * figureOutItemsToDisplay + * @param callback + */ + vm.figureOutItemsToDisplay = function (callback) { + vm.getResRequests(vm.currentPage, function (items) { + vm.filterLength = items.total; + vm.pagedItems = items.rows; + + if (callback) callback(); + }); + }; + + /** + * getResRequests + */ + vm.getResRequests = function (p, callback) { + vm.statusMsg = 'REQUESTS.STATUS_GETTING'; + + RequestsService.get({ + skip: (p - 1) * vm.itemsPerPage, + limit: vm.itemsPerPage, + res_id: vm.user._id + }, function (data) { + vm.statusMsg = undefined; + mtDebug.info(data); + callback(data); + }, function (res) { + vm.statusMsg = 'REQUESTS.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); + }); + }; + + } +}()); diff --git a/modules/requests/client/less/requests.less b/modules/requests/client/less/requests.less index 146cc0db..c40f7f49 100644 --- a/modules/requests/client/less/requests.less +++ b/modules/requests/client/less/requests.less @@ -4,12 +4,26 @@ .btn { text-shadow: none !important; } + @media (max-width: @screen-sm-max) { + .btn { + min-width: 160px !important; + } + } @media (max-width: @screen-xs-max) { .btn { min-width: auto !important; } } - + @media (max-width: @screen-xs) { + .btn { + margin: 0 5px !important; + border-radius: 4px !important; + min-width: 180px !important; + } + .visible-xxs-block { + margin-bottom: 10px; + } + } } .requests-desc { @@ -34,7 +48,7 @@ textarea { resize: vertical; min-height: 120px; - max-height: 240px; + max-height: 300px; } } diff --git a/modules/requests/client/views/requests-add.client.view.html b/modules/requests/client/views/requests-add.client.view.html index 897df8a9..ca2448af 100644 --- a/modules/requests/client/views/requests-add.client.view.html +++ b/modules/requests/client/views/requests-add.client.view.html @@ -3,18 +3,23 @@
@@ -51,10 +56,11 @@
- +
-

{{ 'REQUESTS.FORM_DESC_REQUIRED' | translate}}

diff --git a/modules/requests/client/views/requests-list.client.view.html b/modules/requests/client/views/requests-list.client.view.html index e162d0cc..79c7cdff 100644 --- a/modules/requests/client/views/requests-list.client.view.html +++ b/modules/requests/client/views/requests-list.client.view.html @@ -3,18 +3,23 @@ @@ -28,7 +33,7 @@
-
+

{{vm.statusMsg | translate}}

@@ -55,22 +60,26 @@ {{ 'REQUESTS.FIELD_TITLE' | translate}} {{ 'REQUESTS.FIELD_TYPE' | translate}} - {{ 'REQUESTS.FIELD_CREATEDAT' | translate}} + {{ 'REQUESTS.FIELD_LIFE' | translate}} {{ 'REQUESTS.FIELD_REWARDS' | translate}} + {{ 'REQUESTS.FIELD_RESPONSES' | translate}} + {{ 'REQUESTS.FIELD_COMMENTS' | translate}} {{ 'REQUESTS.FIELD_USER' | translate}} - +

{{item.title}}

{{item.desc}}
{{'MENU_TORRENTS_SUB.'+item.type.toUpperCase() | translate}} - {{item.createdAt | date: 'yyyy-MM-dd HH:mm:ss'}} + {{item.createdAt | life }} {{item.rewards}} + {{item.torrents.length}} + {{item.comments.length}} diff --git a/modules/requests/client/views/requests-my.client.view.html b/modules/requests/client/views/requests-my.client.view.html index 3e0f528b..e05fda91 100644 --- a/modules/requests/client/views/requests-my.client.view.html +++ b/modules/requests/client/views/requests-my.client.view.html @@ -3,18 +3,23 @@ @@ -28,7 +33,7 @@
-
+

{{vm.statusMsg | translate}}

@@ -55,22 +60,26 @@ {{ 'REQUESTS.FIELD_TITLE' | translate}} {{ 'REQUESTS.FIELD_TYPE' | translate}} - {{ 'REQUESTS.FIELD_CREATEDAT' | translate}} + {{ 'REQUESTS.FIELD_LIFE' | translate}} {{ 'REQUESTS.FIELD_REWARDS' | translate}} + {{ 'REQUESTS.FIELD_RESPONSES' | translate}} + {{ 'REQUESTS.FIELD_COMMENTS' | translate}} {{ 'REQUESTS.FIELD_USER' | translate}} - +

{{item.title}}

{{item.desc}}
{{'MENU_TORRENTS_SUB.'+item.type.toUpperCase() | translate}} - {{item.createdAt | date: 'yyyy-MM-dd HH:mm:ss'}} + {{item.createdAt | life }} {{item.rewards}} + {{item.comments.length}} + {{item.torrents.length}} diff --git a/modules/requests/client/views/requests-res.client.view.html b/modules/requests/client/views/requests-res.client.view.html new file mode 100644 index 00000000..37006bd6 --- /dev/null +++ b/modules/requests/client/views/requests-res.client.view.html @@ -0,0 +1,104 @@ +
+ + +
+
+
+
+

{{vm.statusMsg | translate}}

+
+
+ +

{{'REQUESTS.NO_RES_REQUESTS' | translate}}

+
+
+
+
+
+
    +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
{{ 'REQUESTS.FIELD_TITLE' | translate}}{{ 'REQUESTS.FIELD_TYPE' | translate}}{{ 'REQUESTS.FIELD_LIFE' | translate}}{{ 'REQUESTS.FIELD_REWARDS' | translate}}{{ 'REQUESTS.FIELD_RESPONSES' | translate}}{{ 'REQUESTS.FIELD_COMMENTS' | translate}}{{ 'REQUESTS.FIELD_USER' | translate}}
+

+ {{item.title}} +

+
{{item.desc}}
+
{{'MENU_TORRENTS_SUB.'+item.type.toUpperCase() | translate}}{{item.createdAt | life }}{{item.rewards}}{{item.comments.length}}{{item.torrents.length}} + +
+
+
+ +
+
    +
+
+
+
+
+
+
diff --git a/modules/requests/server/controllers/requests.server.controller.js b/modules/requests/server/controllers/requests.server.controller.js index 468894ea..7f1bdd70 100644 --- a/modules/requests/server/controllers/requests.server.controller.js +++ b/modules/requests/server/controllers/requests.server.controller.js @@ -120,6 +120,7 @@ exports.list = function (req, res) { var skip = 0; var limit = 0; var user_id = undefined; + var res_id = undefined; if (req.query.skip !== undefined) { skip = parseInt(req.query.skip, 10); @@ -130,11 +131,17 @@ exports.list = function (req, res) { if (req.query.user_id !== undefined) { user_id = req.query.user_id; } + if (req.query.res_id !== undefined) { + res_id = req.query.res_id; + } var condition = {}; if (user_id !== undefined) { condition.user = user_id; } + if (res_id !== undefined) { + condition.responses = {$in: [res_id]}; + } var countQuery = function (callback) { Request.count(condition, function (err, count) { @@ -150,6 +157,8 @@ exports.list = function (req, res) { Request.find(condition) .sort('-createdAt') .populate('user', 'username displayName profileImageURL isVip') + .skip(skip) + .limit(limit) .exec(function (err, requests) { if (err) { return res.status(422).send({ diff --git a/modules/requests/server/models/request.server.model.js b/modules/requests/server/models/request.server.model.js index 07a72696..8670522e 100644 --- a/modules/requests/server/models/request.server.model.js +++ b/modules/requests/server/models/request.server.model.js @@ -39,12 +39,16 @@ var RequestSchema = new Schema({ type: Schema.Types.ObjectId, ref: 'Torrent' }], + responses: [{ + type: Schema.Types.ObjectId, + ref: 'User' + }], accept: { type: Schema.Types.ObjectId, ref: 'Torrent' }, - comment: [CommonSchema.CommentSchema], + comments: [CommonSchema.CommentSchema], createdAt: { type: Date,