diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index ac566b257e..2aba22d617 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -472,7 +472,7 @@ class TransactionJournal extends Model */ public function attachments() { - return $this->morphMany('App\Models\Attachment', 'attachable'); + return $this->morphMany('FireflyIII\Models\Attachment', 'attachable'); } /** diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index b42350a579..d7a0722d14 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -35,7 +35,8 @@ class General extends Twig_Extension $this->formatAmountPlain(), $this->formatJournal(), $this->balance(), - $this->getAccountRole() + $this->getAccountRole(), + $this->formatFilesize() ]; } @@ -66,6 +67,27 @@ class General extends Twig_Extension return 'FireflyIII\Support\Twig\General'; } + protected function formatFilesize() + { + return new Twig_SimpleFilter( + 'filesize', function ($size) { + $size = intval($size); + + // less than one GB, more than one MB + if ($size < (1024 * 1024 * 2014) && $size >= (1024 * 1024)) { + return round($size / (1024 * 1024), 2) . ' MB'; + } + + // less than one MB + if ($size < (1024 * 1024)) { + return round($size / 1024, 2) . ' KB'; + } + + return $size . ' bytes'; + } + ); + } + /** * @return Twig_SimpleFilter */ diff --git a/resources/twig/list/journals.twig b/resources/twig/list/journals.twig index ffbdee1e26..e5292f7f2c 100644 --- a/resources/twig/list/journals.twig +++ b/resources/twig/list/journals.twig @@ -52,6 +52,10 @@
+ + | ++ + {{ att.filename }} + ({{ att.size|filesize }}) + | +