mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-06 20:21:01 +01:00
feat(check in): new feather of check in daily
This commit is contained in:
24
modules/check/client/services/check.client.service.js
Normal file
24
modules/check/client/services/check.client.service.js
Normal file
@@ -0,0 +1,24 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// Users service used for communicating with the users REST endpoint
|
||||
angular
|
||||
.module('check.services')
|
||||
.factory('CheckService', CheckService);
|
||||
|
||||
CheckService.$inject = ['$resource'];
|
||||
|
||||
function CheckService($resource) {
|
||||
var Check = $resource('/api/check', {}, {
|
||||
get: {
|
||||
method: 'GET'
|
||||
},
|
||||
update: {
|
||||
method: 'PUT'
|
||||
}
|
||||
});
|
||||
|
||||
return Check;
|
||||
}
|
||||
|
||||
}());
|
||||
110
modules/check/server/controllers/check.server.controller.js
Normal file
110
modules/check/server/controllers/check.server.controller.js
Normal file
@@ -0,0 +1,110 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
var path = require('path'),
|
||||
config = require(path.resolve('./config/config')),
|
||||
mongoose = require('mongoose'),
|
||||
errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
|
||||
moment = require('moment'),
|
||||
User = mongoose.model('User'),
|
||||
Check = mongoose.model('Check'),
|
||||
scoreUpdate = require(path.resolve('./config/lib/score')).update;
|
||||
|
||||
var mtDebug = require(path.resolve('./config/lib/debug'));
|
||||
var scoreConfig = config.meanTorrentConfig.score;
|
||||
|
||||
/**
|
||||
* Show the current collection
|
||||
*/
|
||||
exports.get = function (req, res) {
|
||||
if (!req.user) {
|
||||
return res.status(403).json({
|
||||
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
|
||||
});
|
||||
} else {
|
||||
Check.findOne({user: req.user._id}, function (err, ck) {
|
||||
if (err) {
|
||||
return res.status(422).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
if (!ck) {
|
||||
return res.status(422).send({
|
||||
message: 'no check data founded'
|
||||
});
|
||||
} else {
|
||||
var oldCheckDate = moment(moment(ck.lastCheckedAt).format('YYYY-MM-DD'));
|
||||
var now = moment(moment().format('YYYY-MM-DD'));
|
||||
var diff = now.diff(oldCheckDate, 'days');
|
||||
|
||||
var nck = ck.toJSON();
|
||||
nck.todayIsDone = (diff === 0 ? true : false);
|
||||
res.json(nck);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Update an collection
|
||||
*/
|
||||
exports.check = function (req, res) {
|
||||
if (!req.user) {
|
||||
return res.status(403).json({
|
||||
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
|
||||
});
|
||||
} else {
|
||||
var score = 0;
|
||||
Check.findOne({user: req.user._id}, function (err, ck) {
|
||||
if (!ck) {
|
||||
ck = new Check();
|
||||
ck.user = req.user._id;
|
||||
ck.keepDays = 1;
|
||||
ck.save();
|
||||
|
||||
score = scoreConfig.action.dailyCheckIn.dailyBasicScore + (ck.keepDays - 1) * scoreConfig.action.dailyCheckIn.dailyStepScore;
|
||||
scoreUpdate(req, req.user, scoreConfig.action.dailyCheckIn, score);
|
||||
|
||||
ck = ck.toJSON();
|
||||
ck.todayIsDone = true;
|
||||
res.json(ck);
|
||||
} else {
|
||||
var oldCheckDate = moment(moment(ck.lastCheckedAt).format('YYYY-MM-DD'));
|
||||
var now = moment(moment().format('YYYY-MM-DD'));
|
||||
var diff = now.diff(oldCheckDate, 'days');
|
||||
|
||||
if (diff === 0) {
|
||||
return res.status(422).json({
|
||||
message: 'SERVER.YOU_ALREADY_CHECK_IN'
|
||||
});
|
||||
} else if (diff === 1) {
|
||||
ck.keepDays += 1;
|
||||
ck.lastCheckedAt = Date.now();
|
||||
ck.save();
|
||||
|
||||
score = scoreConfig.action.dailyCheckIn.dailyBasicScore + (ck.keepDays - 1) * scoreConfig.action.dailyCheckIn.dailyStepScore;
|
||||
scoreUpdate(req, req.user, scoreConfig.action.dailyCheckIn, score);
|
||||
|
||||
ck = ck.toJSON();
|
||||
ck.todayIsDone = true;
|
||||
res.json(ck);
|
||||
} else {
|
||||
ck.keepDays = 1;
|
||||
ck.lastCheckedAt = Date.now();
|
||||
ck.save();
|
||||
|
||||
score = scoreConfig.action.dailyCheckIn.dailyBasicScore + (ck.keepDays - 1) * scoreConfig.action.dailyCheckIn.dailyStepScore;
|
||||
scoreUpdate(req, req.user, scoreConfig.action.dailyCheckIn, score);
|
||||
|
||||
ck = ck.toJSON();
|
||||
ck.todayIsDone = true;
|
||||
res.json(ck);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
8
modules/check/server/routes/check.server.routes.js
Normal file
8
modules/check/server/routes/check.server.routes.js
Normal file
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (app) {
|
||||
var check = require('../controllers/check.server.controller');
|
||||
|
||||
app.route('/api/check').get(check.get);
|
||||
app.route('/api/check').put(check.check);
|
||||
};
|
||||
@@ -132,6 +132,15 @@
|
||||
}
|
||||
},
|
||||
|
||||
CHECK: {
|
||||
BTN_CHECK_IN: 'Check In',
|
||||
CHECK_TOOLTIP: '#### `mine.pt` invites you to participate in the daily check in. Now check in to get `{{todayScore}}` scores and renew tomorrow to get `{{tomorrowScore}}` scores!',
|
||||
CHECK_TODAY_NOT: '#### You have not checked in yet. Last check in at: `{{checkTime | date: "yyyy-MM-dd HH:mm"}}`. Now check in to get `{{todayScore}}` scores and renew tomorrow to get `{{tomorrowScore}}` scores!',
|
||||
CHECK_TODAY_DONE: '#### You have checked in to `{{keepDays}}` days in a row, today check in at: `{{checkTime | date: "yyyy-MM-dd HH:mm"}}`, you have got `{{todayScore}}` scores and renew tomorrow to get `{{tomorrowScore}}` scores, please be careful not to interrupt!',
|
||||
CHECK_SUCCESSFULLY: 'Check in successfully',
|
||||
CHECK_ERROR: 'Check in failed'
|
||||
},
|
||||
|
||||
//element title/alt
|
||||
TITLE_ALT: {
|
||||
SEEDS: 'Seeds users',
|
||||
@@ -1609,7 +1618,8 @@
|
||||
INFO_HASH_ALREADY_EXISTS: 'This info hash value is already exists',
|
||||
UPLOAD_ACCESS_DENY: 'System only accepts resources group to upload torrents',
|
||||
READ_TORRENT_FILE_FAILD: 'The torrent file parsing error. Please check your torrent file to check if some of the necessary information is missing',
|
||||
MOVE_TORRENT_FILE_ERROR: 'The torrent file was moved incorrectly. Please do not repeat the submit operation quickly or the uploaded torrent file is missing.'
|
||||
MOVE_TORRENT_FILE_ERROR: 'The torrent file was moved incorrectly. Please do not repeat the submit operation quickly or the uploaded torrent file is missing.',
|
||||
YOU_ALREADY_CHECK_IN: 'You already checked in today'
|
||||
},
|
||||
|
||||
//server message string, content string support markdown and emoji
|
||||
|
||||
@@ -132,6 +132,15 @@
|
||||
}
|
||||
},
|
||||
|
||||
CHECK: {
|
||||
BTN_CHECK_IN: '我要签到',
|
||||
CHECK_TOOLTIP: '#### `mine.pt` 邀请您参加每日签到,现在签到可获得 `{{todayScore}}` 积分,明日续签可获得 `{{tomorrowScore}}` 积分哦!',
|
||||
CHECK_TODAY_NOT: '#### 您今日还未签到,上次签到:`{{checkTime | date: "yyyy-MM-dd HH:mm"}}`,现在签到可获得 `{{todayScore}}` 积分,明日续签到可获得 `{{tomorrowScore}}` 积分哦!',
|
||||
CHECK_TODAY_DONE: '#### 您已连续签到 `{{keepDays}}` 天,今日签到时间:`{{checkTime | date: "yyyy-MM-dd HH:mm"}}`,已经获得 `{{todayScore}}` 积分,明日续签到可获得 `{{tomorrowScore}}` 积分,请注意不要中断哦!',
|
||||
CHECK_SUCCESSFULLY: '签到成功',
|
||||
CHECK_ERROR: '签到失败'
|
||||
},
|
||||
|
||||
//element title/alt
|
||||
TITLE_ALT: {
|
||||
SEEDS: '做种用户数',
|
||||
@@ -1609,7 +1618,8 @@
|
||||
INFO_HASH_ALREADY_EXISTS: '该 info hash 值已经存在,不能重复提交',
|
||||
UPLOAD_ACCESS_DENY: '当前系统只接受资源制作小组上传种子',
|
||||
READ_TORRENT_FILE_FAILD: '种子文件解析错误,请检查您的种子文件,看是否缺少某些必要信息',
|
||||
MOVE_TORRENT_FILE_ERROR: '种子文件移动错误,请不要快速重复进行提交操作或者上传的种子文件已丢失'
|
||||
MOVE_TORRENT_FILE_ERROR: '种子文件移动错误,请不要快速重复进行提交操作或者上传的种子文件已丢失',
|
||||
YOU_ALREADY_CHECK_IN: '您今天已经签过到了,不能重复签到'
|
||||
},
|
||||
|
||||
//server message string, content string support markdown and emoji
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
.module('core')
|
||||
.controller('HomeController', HomeController);
|
||||
|
||||
HomeController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'TorrentsService', 'Notification', 'MeanTorrentConfig',
|
||||
HomeController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'TorrentsService', 'NotifycationService', 'MeanTorrentConfig',
|
||||
'getStorageLangService', 'ForumsService', '$timeout', 'localStorageService', 'TopicsService', 'TorrentGetInfoServices', 'DebugConsoleService',
|
||||
'marked'];
|
||||
'marked', 'CheckService'];
|
||||
|
||||
function HomeController($scope, $state, $translate, Authentication, TorrentsService, Notification, MeanTorrentConfig, getStorageLangService,
|
||||
function HomeController($scope, $state, $translate, Authentication, TorrentsService, NotifycationService, MeanTorrentConfig, getStorageLangService,
|
||||
ForumsService, $timeout, localStorageService, TopicsService, TorrentGetInfoServices, mtDebug,
|
||||
marked) {
|
||||
marked, CheckService) {
|
||||
var vm = this;
|
||||
vm.user = Authentication.user;
|
||||
vm.appConfig = MeanTorrentConfig.meanTorrentConfig.app;
|
||||
@@ -23,8 +23,10 @@
|
||||
vm.announceConfig = MeanTorrentConfig.meanTorrentConfig.announce;
|
||||
vm.homeConfig = MeanTorrentConfig.meanTorrentConfig.home;
|
||||
vm.supportConfig = MeanTorrentConfig.meanTorrentConfig.support;
|
||||
vm.scoreConfig = MeanTorrentConfig.meanTorrentConfig.score;
|
||||
|
||||
vm.searchType = 'torrents';
|
||||
vm.checkData = undefined;
|
||||
|
||||
/**
|
||||
* initBodyBackground
|
||||
@@ -323,5 +325,86 @@
|
||||
return marked(ts, {sanitize: true});
|
||||
};
|
||||
|
||||
/**
|
||||
* getMyCheckData
|
||||
*/
|
||||
vm.getMyCheckData = function () {
|
||||
CheckService.get(function (res) {
|
||||
mtDebug.info(res);
|
||||
vm.checkData = res;
|
||||
vm.openCheckTooltip();
|
||||
}, function (err) {
|
||||
vm.checkData = false;
|
||||
vm.openCheckTooltip();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* checkIn
|
||||
*/
|
||||
vm.checkIn = function () {
|
||||
CheckService.update(function (res) {
|
||||
mtDebug.info(res);
|
||||
vm.checkData = res;
|
||||
NotifycationService.showSuccessNotify('CHECK.CHECK_SUCCESSFULLY');
|
||||
}, function (err) {
|
||||
NotifycationService.showErrorNotify(err.data.message, 'CHECK.CHECK_ERROR');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getCheckTodayDoneMessage
|
||||
* @returns {*}
|
||||
*/
|
||||
vm.getCheckTodayDoneMessage = function () {
|
||||
var ts = $translate.instant('CHECK.CHECK_TODAY_DONE', {
|
||||
keepDays: vm.checkData.keepDays,
|
||||
checkTime: vm.checkData.lastCheckedAt,
|
||||
todayScore: vm.scoreConfig.action.dailyCheckIn.dailyBasicScore + (vm.checkData.keepDays - 1) * vm.scoreConfig.action.dailyCheckIn.dailyStepScore,
|
||||
tomorrowScore: vm.scoreConfig.action.dailyCheckIn.dailyBasicScore + vm.checkData.keepDays * vm.scoreConfig.action.dailyCheckIn.dailyStepScore
|
||||
});
|
||||
|
||||
return marked(ts, {sanitize: false});
|
||||
};
|
||||
|
||||
/**
|
||||
* getCheckTodayNotMessage
|
||||
* @returns {*}
|
||||
*/
|
||||
vm.getCheckTodayNotMessage = function () {
|
||||
var ts = $translate.instant('CHECK.CHECK_TODAY_NOT', {
|
||||
checkTime: vm.checkData.lastCheckedAt,
|
||||
todayScore: vm.scoreConfig.action.dailyCheckIn.dailyBasicScore + vm.checkData.keepDays * vm.scoreConfig.action.dailyCheckIn.dailyStepScore,
|
||||
tomorrowScore: vm.scoreConfig.action.dailyCheckIn.dailyBasicScore + (vm.checkData.keepDays + 1) * vm.scoreConfig.action.dailyCheckIn.dailyStepScore
|
||||
});
|
||||
|
||||
return marked(ts, {sanitize: false});
|
||||
};
|
||||
|
||||
/**
|
||||
* getCheckTooltipMessage
|
||||
* @returns {*}
|
||||
*/
|
||||
vm.getCheckTooltipMessage = function () {
|
||||
var ts = $translate.instant('CHECK.CHECK_TOOLTIP', {
|
||||
todayScore: vm.scoreConfig.action.dailyCheckIn.dailyBasicScore,
|
||||
tomorrowScore: vm.scoreConfig.action.dailyCheckIn.dailyBasicScore + vm.scoreConfig.action.dailyCheckIn.dailyStepScore
|
||||
});
|
||||
|
||||
return marked(ts, {sanitize: false});
|
||||
};
|
||||
|
||||
/**
|
||||
* openCheckTooltip
|
||||
*/
|
||||
vm.openCheckTooltip = function () {
|
||||
var e = $('.home-check-in');
|
||||
|
||||
$timeout(function () {
|
||||
e.slideDown(800);
|
||||
e.removeClass('panel-collapsed');
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -113,6 +113,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
.col-valign-middle {
|
||||
@media (min-width: @screen-sm-min) {
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
float: none;
|
||||
}
|
||||
}
|
||||
|
||||
.home-check-in {
|
||||
padding: 10px 0;
|
||||
h4, .h4 {
|
||||
line-height: 1.8;
|
||||
}
|
||||
.check-in-btn {
|
||||
margin-top: 10px;
|
||||
@media(max-width: @screen-sm-max){
|
||||
margin-top: 20px;
|
||||
}
|
||||
@media(max-width: @screen-xs-max){
|
||||
margin-top: 15px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.home-button-list {
|
||||
padding: 50px 0;
|
||||
@media (max-width: @screen-xs-max) {
|
||||
@@ -316,6 +340,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
.filter-check-in {
|
||||
position: relative;
|
||||
margin-top: 2px;
|
||||
background-color: @mt-body-background-color;
|
||||
background-color: rgba(255, 255, 255, .85);
|
||||
transition: background-color .2s ease-in;
|
||||
&:hover {
|
||||
background-color: @mt-body-background-color;
|
||||
background-color: rgba(255, 255, 255, .95);
|
||||
}
|
||||
}
|
||||
|
||||
.filter-copy {
|
||||
position: relative;
|
||||
line-height: 2;
|
||||
@@ -449,17 +485,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.home-check-in {
|
||||
background-color: #2a2a2a;
|
||||
background-color: rgba(0,0,0, 0.5);
|
||||
.check-in-title {
|
||||
color: #fff;
|
||||
font-size: 2em;
|
||||
font-weight: 400;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.view-footer {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
|
||||
@@ -75,6 +75,46 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="home-check-in filter-check-in panel-collapsed" ng-init="vm.getMyCheckData()" style="display: none;">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12" ng-if="vm.checkData != undefined">
|
||||
<div ng-if="vm.checkData == false ">
|
||||
<div class="row text-center">
|
||||
<div class="col-sm-10">
|
||||
<span ng-bind-html="vm.getCheckTooltipMessage()"></span>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<button class="btn btn-success btn-block check-in-btn"
|
||||
ng-click="vm.checkIn()">{{'CHECK.BTN_CHECK_IN' | translate}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-if="vm.checkData && !vm.checkData.todayIsDone">
|
||||
<div class="row text-center">
|
||||
<div class="col-sm-10">
|
||||
<span ng-bind-html="vm.getCheckTodayNotMessage()"></span>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<button class="btn btn-success btn-block check-in-btn"
|
||||
ng-click="vm.checkIn()">{{'CHECK.BTN_CHECK_IN' | translate}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-if="vm.checkData && vm.checkData.todayIsDone">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 text-center">
|
||||
<span ng-bind-html="vm.getCheckTodayDoneMessage()"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="filter-notice">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
Reference in New Issue
Block a user