Closes #51: File sizes displayed in kB or MB

This commit is contained in:
jendib 2015-12-05 20:00:51 +01:00
parent 5f516047bd
commit 046984a447
10 changed files with 48 additions and 8 deletions

View File

@ -0,0 +1,18 @@
'use strict';
/**
* Format file sizes.
*/
angular.module('docs').filter('filesize', function() {
return function(text) {
if (!text) {
return '';
}
var size = parseInt(text);
if (size > 1000000) { // 1MB
return Math.round(size / 1000000) + 'MB';
}
return Math.round(size / 1000) + 'kB';
}
});

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
/** /**
* Filter converting new lines in <br /> * Filter converting new lines in <br />.
*/ */
angular.module('docs').filter('newline', function() { angular.module('docs').filter('newline', function() {
return function(text) { return function(text) {
@ -10,4 +10,4 @@ angular.module('docs').filter('newline', function() {
} }
return text.replace(/\n/g, '<br/>'); return text.replace(/\n/g, '<br/>');
} }
}) });

View File

@ -10,4 +10,4 @@ angular.module('docs').filter('shorten', function() {
} }
return text.substring(0, 1).toUpperCase(); return text.substring(0, 1).toUpperCase();
} }
}) });

View File

@ -0,0 +1,18 @@
'use strict';
/**
* Format file sizes.
*/
angular.module('share').filter('filesize', function() {
return function(text) {
if (!text) {
return '';
}
var size = parseInt(text);
if (size > 1000000) { // 1MB
return Math.round(size / 1000000) + 'MB';
}
return Math.round(size / 1000) + 'kB';
}
});

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
/** /**
* Filter converting new lines in <br /> * Filter converting new lines in <br />.
*/ */
angular.module('share').filter('newline', function() { angular.module('share').filter('newline', function() {
return function(text) { return function(text) {
@ -10,4 +10,4 @@ angular.module('share').filter('newline', function() {
} }
return text.replace(/\n/g, '<br/>'); return text.replace(/\n/g, '<br/>');
} }
}) });

View File

@ -63,6 +63,7 @@
<script src="app/docs/service/Tag.js" type="text/javascript"></script> <script src="app/docs/service/Tag.js" type="text/javascript"></script>
<script src="app/docs/filter/Newline.js" type="text/javascript"></script> <script src="app/docs/filter/Newline.js" type="text/javascript"></script>
<script src="app/docs/filter/Shorten.js" type="text/javascript"></script> <script src="app/docs/filter/Shorten.js" type="text/javascript"></script>
<script src="app/docs/filter/Filesize.js" type="text/javascript"></script>
<script src="app/docs/directive/File.js" type="text/javascript"></script> <script src="app/docs/directive/File.js" type="text/javascript"></script>
<script src="app/docs/directive/SelectTag.js" type="text/javascript"></script> <script src="app/docs/directive/SelectTag.js" type="text/javascript"></script>
<script src="app/docs/directive/AuditLog.js" type="text/javascript"></script> <script src="app/docs/directive/AuditLog.js" type="text/javascript"></script>

View File

@ -8,7 +8,7 @@
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-center" ng-repeat="file in files"> <div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-center" ng-repeat="file in files">
<div class="thumbnail" ng-class="{ 'thumbnail-checked': file.checked }" ng-if="file.id"> <div class="thumbnail" ng-class="{ 'thumbnail-checked': file.checked }" ng-if="file.id">
<a ng-click="openFile(file)"> <a ng-click="openFile(file)">
<img class="thumbnail-file" ng-src="../api/file/{{ file.id }}/data?size=thumb" tooltip="{{ file.mimetype }}" tooltip-placement="top" /> <img class="thumbnail-file" ng-src="../api/file/{{ file.id }}/data?size=thumb" tooltip="{{ file.mimetype }} | {{ file.size | filesize }}" tooltip-placement="top" />
</a> </a>
<div class="caption pointer" ng-click="file.checked = !file.checked"> <div class="caption pointer" ng-click="file.checked = !file.checked">
<div class="pull-left"> <div class="pull-left">

View File

@ -6,7 +6,7 @@
<div class="col-xs-6 col-sm-4 col-md-4 col-lg-3 text-center" ng-repeat="file in files"> <div class="col-xs-6 col-sm-4 col-md-4 col-lg-3 text-center" ng-repeat="file in files">
<div class="thumbnail" ng-if="file.id"> <div class="thumbnail" ng-if="file.id">
<a ng-click="openFile(file)"> <a ng-click="openFile(file)">
<img class="thumbnail-file" ng-src="../api/file/{{ file.id }}/data?size=thumb" tooltip="{{ file.mimetype }}" tooltip-placement="top" /> <img class="thumbnail-file" ng-src="../api/file/{{ file.id }}/data?size=thumb" tooltip="{{ file.mimetype }} | {{ file.size | filesize }}" tooltip-placement="top" />
</a> </a>
<div class="caption" ng-show="document.writable"> <div class="caption" ng-show="document.writable">
<div class="pull-left"> <div class="pull-left">

View File

@ -18,7 +18,9 @@
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-center" ng-repeat="file in files"> <div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-center" ng-repeat="file in files">
<div class="thumbnail"> <div class="thumbnail">
<a ng-click="openFile(file)"> <a ng-click="openFile(file)">
<img class="thumbnail-file" ng-src="../api/file/{{ file.id }}/data?size=thumb&share={{ $stateParams.shareId }}" tooltip="{{ file.mimetype }}" tooltip-placement="top" /> <img class="thumbnail-file"
ng-src="../api/file/{{ file.id }}/data?size=thumb&share={{ $stateParams.shareId }}"
tooltip="{{ file.mimetype }} | {{ file.size | filesize }}" tooltip-placement="top" />
</a> </a>
</div> </div>
</div> </div>

View File

@ -37,6 +37,7 @@
<script src="app/share/controller/FileView.js" type="text/javascript"></script> <script src="app/share/controller/FileView.js" type="text/javascript"></script>
<script src="app/share/controller/FileModalView.js" type="text/javascript"></script> <script src="app/share/controller/FileModalView.js" type="text/javascript"></script>
<script src="app/share/filter/Newline.js" type="text/javascript"></script> <script src="app/share/filter/Newline.js" type="text/javascript"></script>
<script src="app/share/filter/Filesize.js" type="text/javascript"></script>
<!-- endref --> <!-- endref -->
</head> </head>
<body> <body>