Will now warn about non-existent attachments.

This commit is contained in:
James Cole 2018-11-11 07:03:36 +01:00
parent 7380c5096e
commit edf764aaf4
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 79 additions and 20 deletions

View File

@ -26,13 +26,16 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelper;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\CountAttachmentsFilter;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Filter\SplitIndicatorFilter;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use FireflyIII\Support\Http\Controllers\ModelInformation;
@ -53,6 +56,8 @@ use View;
class TransactionController extends Controller
{
use ModelInformation, PeriodOverview;
/** @var AttachmentRepositoryInterface */
private $attachmentRepository;
/** @var JournalRepositoryInterface Journals and transactions overview */
private $repository;
@ -67,7 +72,8 @@ class TransactionController extends Controller
function ($request, $next) {
app('view')->share('title', (string)trans('firefly.transactions'));
app('view')->share('mainTitleIcon', 'fa-repeat');
$this->repository = app(JournalRepositoryInterface::class);
$this->repository = app(JournalRepositoryInterface::class);
$this->attachmentRepository = app(AttachmentRepositoryInterface::class);
return $next($request);
}
@ -212,6 +218,7 @@ class TransactionController extends Controller
*
* @param TransactionJournal $journal
* @param LinkTypeRepositoryInterface $linkTypeRepository
* @param AttachmentHelper $attHelper
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
* @throws FireflyException
@ -228,6 +235,16 @@ class TransactionController extends Controller
$linkTypes = $linkTypeRepository->get();
$links = $linkTypeRepository->getLinks($journal);
// get attachments:
$attachments = $this->repository->getAttachments($journal);
$attachments = $attachments->each(
function (Attachment $attachment) {
$attachment->file_exists = $this->attachmentRepository->exists($attachment);
return $attachment;
}
);
// get transactions using the collector:
$collector = app(TransactionCollectorInterface::class);
$collector->setUser(auth()->user());
@ -246,7 +263,7 @@ class TransactionController extends Controller
$what = strtolower($transactionType);
$subTitle = (string)trans('firefly.' . $what) . ' "' . $journal->description . '"';
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions', 'linkTypes', 'links'));
return view('transactions.show', compact('journal','attachments', 'events', 'subTitle', 'what', 'transactions', 'linkTypes', 'links'));
}

View File

@ -29,7 +29,6 @@ use FireflyIII\Factory\TransactionJournalFactory;
use FireflyIII\Factory\TransactionJournalMetaFactory;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\PiggyBankEvent;
@ -263,6 +262,18 @@ class JournalRepository implements JournalRepositoryInterface
return null;
}
/**
* Return all attachments for journal.
*
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getAttachments(TransactionJournal $journal): Collection
{
return $journal->attachments;
}
/**
* Returns the first positive transaction for the journal. Useful when editing journals.
*
@ -585,10 +596,10 @@ class JournalRepository implements JournalRepositoryInterface
public function getTransactionsById(array $transactionIds): Collection
{
$journalIds = Transaction::whereIn('id', $transactionIds)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
$journals = new Collection;
foreach($journalIds as $journalId) {
$journals = new Collection;
foreach ($journalIds as $journalId) {
$result = $this->findNull((int)$journalId);
if(null !== $result) {
if (null !== $result) {
$journals->push($result);
}
}
@ -600,6 +611,7 @@ class JournalRepository implements JournalRepositoryInterface
//$collector->addFilter(TransferFilter::class);
$collector->setJournals($journals)->withOpposingAccount();
return $collector->getTransactions();
}

View File

@ -38,6 +38,16 @@ use Illuminate\Support\MessageBag;
*/
interface JournalRepositoryInterface
{
/**
* Return all attachments for journal.
*
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getAttachments(TransactionJournal $journal): Collection;
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param TransactionJournal $journal

View File

@ -851,6 +851,7 @@ return [
'opt_group_l_Credit card' => 'Liability: Credit card',
'notes' => 'Notes',
'unknown_journal_error' => 'Could not store the transaction. Please check the log files.',
'attachment_not_found' => 'This attachment could not found in the storage.',
// new user:
'welcome' => 'Welcome to Firefly III!',

View File

@ -249,7 +249,7 @@
</table>
</div>
</div>
{% if journal.attachments|length > 0 %}
{% if attachments|length > 0 %}
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'attachments'|_ }}</h3>
@ -262,21 +262,38 @@
<div class="btn-group btn-group-xs">
<a href="{{ route('attachments.edit', att.id) }}" class="btn btn-default"><i class="fa fa-pencil"></i></a>
<a href="{{ route('attachments.delete', att.id) }}" class="btn btn-danger"><i class="fa fa-trash"></i></a>
<a href="{{ route('attachments.download', att.id) }}" class="btn btn-default"><i class="fa fa-download"></i></a>
{% if att.file_exists %}
<a href="{{ route('attachments.download', att.id) }}" class="btn btn-default"><i class="fa fa-download"></i></a>
{% endif %}
{% if not att.file_exists %}
<a href="#" class="btn btn-danger"><i class="fa fa-exclamation-triangle"></i></a>
{% endif %}
</div>
</td>
<td>
<i class="fa {{ att.mime|mimeIcon }}"></i>
<a href="{{ route('attachments.view', att.id) }}" title="{{ att.filename }}">
{% if att.title %}
{{ att.title }}
{% else %}
{{ att.filename }}
{% if att.file_exists %}
<i class="fa {{ att.mime|mimeIcon }}"></i>
<a href="{{ route('attachments.view', att.id) }}" title="{{ att.filename }}">
{% if att.title %}
{{ att.title }}
{% else %}
{{ att.filename }}
{% endif %}
</a>
({{ att.size|filesize }})
{% if att.notes.first %}
{{ att.notes.first.text|markdown }}
{% endif %}
</a>
({{ att.size|filesize }})
{% if att.notes.first %}
{{ att.notes.first.text|markdown }}
{% endif %}
{% if not att.file_exists %}
<i class="fa fa-fw fa-exclamation-triangle"></i>
{% if att.title %}
{{ att.title }}
{% else %}
{{ att.filename }}
{% endif %}
<br>
<span class="text-danger">{{ 'attachment_not_found'|_ }}</span>
{% endif %}
</td>
</tr>
@ -426,8 +443,10 @@
<div class="col-sm-10">
<select id="link_type" class="form-control" name="link_type">
{% for linkType in linkTypes %}
<option label="{{ journalLinkTranslation('inward', linkType.inward) }}" value="{{ linkType.id }}_inward">{{ journalLinkTranslation('inward', linkType.inward) }}</option>
<option label="{{ journalLinkTranslation('outward', linkType.outward) }}" value="{{ linkType.id }}_outward">{{ journalLinkTranslation('outward', linkType.outward) }}</option>
<option label="{{ journalLinkTranslation('inward', linkType.inward) }}"
value="{{ linkType.id }}_inward">{{ journalLinkTranslation('inward', linkType.inward) }}</option>
<option label="{{ journalLinkTranslation('outward', linkType.outward) }}"
value="{{ linkType.id }}_outward">{{ journalLinkTranslation('outward', linkType.outward) }}</option>
{% endfor %}
</select>
</div>