Improved filters for size progress
This commit is contained in:
parent
af58efd56a
commit
693ac35114
@ -11,25 +11,26 @@
|
|||||||
|
|
||||||
angular.module('myApp.filters', ['myApp.i18n'])
|
angular.module('myApp.filters', ['myApp.i18n'])
|
||||||
|
|
||||||
.filter('userName', ['_', function(_) {
|
.filter('userName', function(_) {
|
||||||
return function (user) {
|
return function (user) {
|
||||||
if (!user || !user.first_name && !user.last_name) {
|
if (!user || !user.first_name && !user.last_name) {
|
||||||
return _('user_name_deleted');
|
return _('user_name_deleted');
|
||||||
}
|
}
|
||||||
return user.first_name + ' ' + user.last_name;
|
return user.first_name + ' ' + user.last_name;
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
|
||||||
.filter('userFirstName', ['_', function(_) {
|
.filter('userFirstName', function(_) {
|
||||||
return function (user) {
|
return function (user) {
|
||||||
if (!user || !user.first_name && !user.last_name) {
|
if (!user || !user.first_name && !user.last_name) {
|
||||||
return _('user_first_name_deleted');
|
return _('user_first_name_deleted');
|
||||||
}
|
}
|
||||||
return user.first_name || user.last_name;
|
return user.first_name || user.last_name;
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
|
||||||
.filter('userStatus', ['$filter', '_', function($filter, _) {
|
.filter('userStatus', function($filter, _) {
|
||||||
|
var relativeTimeFilter = $filter('relativeTime');
|
||||||
return function (user) {
|
return function (user) {
|
||||||
if (!user || !user.status || user.status._ == 'userStatusEmpty') {
|
if (!user || !user.status || user.status._ == 'userStatusEmpty') {
|
||||||
return _('user_status_offline');
|
return _('user_status_offline');
|
||||||
@ -38,20 +39,20 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
return _('user_status_online');
|
return _('user_status_online');
|
||||||
}
|
}
|
||||||
|
|
||||||
return _('user_status_last_seen', $filter('relativeTime')(user.status.was_online));
|
return _('user_status_last_seen', relativeTimeFilter(user.status.was_online));
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
|
||||||
.filter('chatTitle', ['_', function(_) {
|
.filter('chatTitle', function(_) {
|
||||||
return function (chat) {
|
return function (chat) {
|
||||||
if (!chat || !chat.title) {
|
if (!chat || !chat.title) {
|
||||||
return _('chat_title_deleted');
|
return _('chat_title_deleted');
|
||||||
}
|
}
|
||||||
return chat.title;
|
return chat.title;
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
|
||||||
.filter('dateOrTime', ['$filter', function($filter) {
|
.filter('dateOrTime', function($filter) {
|
||||||
var cachedDates = {},
|
var cachedDates = {},
|
||||||
dateFilter = $filter('date');
|
dateFilter = $filter('date');
|
||||||
|
|
||||||
@ -73,9 +74,9 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
}
|
}
|
||||||
return cachedDates[timestamp] = dateFilter(ticks, format);
|
return cachedDates[timestamp] = dateFilter(ticks, format);
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
|
||||||
.filter('time', ['$filter', function($filter) {
|
.filter('time', function($filter) {
|
||||||
var cachedDates = {},
|
var cachedDates = {},
|
||||||
dateFilter = $filter('date'),
|
dateFilter = $filter('date'),
|
||||||
format = Config.Mobile ? 'shortTime' : 'mediumTime';
|
format = Config.Mobile ? 'shortTime' : 'mediumTime';
|
||||||
@ -87,9 +88,9 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
|
|
||||||
return cachedDates[timestamp] = dateFilter(timestamp * 1000, format);
|
return cachedDates[timestamp] = dateFilter(timestamp * 1000, format);
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
|
||||||
.filter('myDate', ['$filter', function($filter) {
|
.filter('myDate', function($filter) {
|
||||||
var cachedDates = {},
|
var cachedDates = {},
|
||||||
dateFilter = $filter('date');
|
dateFilter = $filter('date');
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
|
|
||||||
return cachedDates[timestamp] = dateFilter(timestamp * 1000, 'fullDate');
|
return cachedDates[timestamp] = dateFilter(timestamp * 1000, 'fullDate');
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
|
||||||
.filter('duration', [function() {
|
.filter('duration', [function() {
|
||||||
return function (duration) {
|
return function (duration) {
|
||||||
@ -131,7 +132,7 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
}])
|
}])
|
||||||
|
|
||||||
.filter('formatSize', [function () {
|
.filter('formatSize', [function () {
|
||||||
return function (size) {
|
return function (size, progressing) {
|
||||||
if (!size) {
|
if (!size) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
@ -141,16 +142,22 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
else if (size < 1048576) {
|
else if (size < 1048576) {
|
||||||
return (Math.round(size / 1024 * 10) / 10) + ' Kb';
|
return (Math.round(size / 1024 * 10) / 10) + ' Kb';
|
||||||
}
|
}
|
||||||
|
var mbs = size / 1048576;
|
||||||
return (Math.round(size / 1048576 * 100) / 100) + ' Mb';
|
if (progressing) {
|
||||||
|
mbs = mbs.toFixed(1);
|
||||||
|
} else {
|
||||||
|
mbs = (Math.round(mbs * 100) / 100);
|
||||||
|
}
|
||||||
|
return mbs + ' Mb';
|
||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.filter('formatSizeProgress', ['$filter', '_', function ($filter, _) {
|
.filter('formatSizeProgress', function ($filter, _) {
|
||||||
|
var formatSizeFilter = $filter('formatSize');
|
||||||
return function (progress) {
|
return function (progress) {
|
||||||
var done = $filter('formatSize')(progress.done),
|
var done = formatSizeFilter(progress.done, true),
|
||||||
doneParts = done.split(' '),
|
doneParts = done.split(' '),
|
||||||
total = $filter('formatSize')(progress.total),
|
total = formatSizeFilter(progress.total),
|
||||||
totalParts = total.split(' ');
|
totalParts = total.split(' ');
|
||||||
|
|
||||||
if (totalParts[1] === doneParts[1]) {
|
if (totalParts[1] === doneParts[1]) {
|
||||||
@ -158,7 +165,7 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
}
|
}
|
||||||
return _('format_size_progress', {done: done, total: total});
|
return _('format_size_progress', {done: done, total: total});
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
|
||||||
.filter('nl2br', [function () {
|
.filter('nl2br', [function () {
|
||||||
return function (text) {
|
return function (text) {
|
||||||
@ -166,15 +173,17 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.filter('richText', ['$filter', function ($filter) {
|
.filter('richText', function ($filter) {
|
||||||
|
var linkyFilter = $filter('linky');
|
||||||
return function (text) {
|
return function (text) {
|
||||||
return $filter('linky')(text, '_blank').replace(/\n| /g, '<br/>');
|
return linkyFilter(text, '_blank').replace(/\n| /g, '<br/>');
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
|
||||||
.filter('relativeTime', ['$filter', '_', function($filter, _) {
|
.filter('relativeTime', function($filter, _) {
|
||||||
var langMinutesPluralize = _.pluralize('relative_time_pluralize_minutes_ago'),
|
var langMinutesPluralize = _.pluralize('relative_time_pluralize_minutes_ago'),
|
||||||
langHoursPluralize = _.pluralize('relative_time_pluralize_hours_ago');
|
langHoursPluralize = _.pluralize('relative_time_pluralize_hours_ago'),
|
||||||
|
dateOrTimeFilter = $filter('dateOrTime');
|
||||||
|
|
||||||
return function (timestamp) {
|
return function (timestamp) {
|
||||||
var ticks = timestamp * 1000,
|
var ticks = timestamp * 1000,
|
||||||
@ -191,6 +200,6 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
var hours = Math.ceil(diff / 3600000);
|
var hours = Math.ceil(diff / 3600000);
|
||||||
return langHoursPluralize(hours);
|
return langHoursPluralize(hours);
|
||||||
}
|
}
|
||||||
return $filter('dateOrTime')(timestamp);
|
return dateOrTimeFilter(timestamp);
|
||||||
}
|
}
|
||||||
}])
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user