feat(users): add filter to show ratio formated info

This commit is contained in:
OldHawk
2017-06-21 09:58:27 +08:00
parent 253bd9d42c
commit dbba4c0d64
5 changed files with 25 additions and 4 deletions

View File

@@ -0,0 +1,19 @@
(function () {
'use strict';
// Focus the element on page load
// Unless the user is on a small device, because this could obscure the page with a keyboard
angular.module('core')
.filter('ratio', ratio);
function ratio() {
return function (number) {
if (number === -1) {
return '∞';
} else {
return number;
}
};
}
}());

View File

@@ -14,7 +14,7 @@
ng-class="{'span-banned': user.status == 'banned'}">
<img class="ulist-avatar" ng-src="/{{user.profileImageURL}}">
<h4 class="list-group-item-heading" ng-bind="user.username"></h4>
<h4 class="list-group-item-heading">{{user.displayName}} - <small>{{user.username}}</small></h4>
<p class="list-group-item-text pull-right small" ng-bind="user.roles"></p>

View File

@@ -145,7 +145,7 @@
</dd>
<dt class="h-line">{{ 'STATUS_FIELD.RATIO' | translate}}</dt>
<dd class="h-line"><span ng-class="vm.user.ratio > 1 ? 'ratio-normal' : 'ratio-warning' ">{{ vm.user.ratio }}</span></dd>
<dd class="h-line"><span ng-class="vm.user.ratio == 0 ? 'ratio-warning' : 'ratio-normal' ">{{ vm.user.ratio | ratio}}</span></dd>
<dt class="h-line">{{ 'STATUS_FIELD.SCORE' | translate}}</dt>
<dd class="h-line">

View File

@@ -99,7 +99,7 @@
</dd>
<dt class="h-line">{{ 'STATUS_FIELD.RATIO' | translate}}</dt>
<dd class="h-line"><span ng-class="vm.user.ratio > 1 ? 'ratio-normal' : 'ratio-warning' ">{{ vm.user.ratio }}</span></dd>
<dd class="h-line"><span ng-class="vm.user.ratio == 0 ? 'ratio-warning' : 'ratio-normal' ">{{ vm.user.ratio | ratio}}</span></dd>
<li class="status-divider"></li>

View File

@@ -214,7 +214,9 @@ UserSchema.pre('save', function (next) {
this.password = this.hashPassword(this.password);
}
if (this.uploaded === 0 || this.downloaded === 0) {
if (this.uploaded > 0 && this.downloaded === 0) {
this.ratio = -1;
} else if (this.uploaded === 0 || this.downloaded === 0) {
this.ratio = 0;
} else {
this.ratio = Math.round((this.uploaded / this.downloaded) * 100) / 100;