mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Allow to edit an attachment.
This commit is contained in:
parent
b5e2e8aa1d
commit
0dbe4e94fa
@ -5,7 +5,12 @@ namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Crypt;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Http\Requests\AttachmentFormRequest;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use Input;
|
||||
use Preferences;
|
||||
use Session;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@ -66,8 +71,40 @@ class AttachmentController extends Controller
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param AttachmentFormRequest $request
|
||||
* @param AttachmentRepositoryInterface $repository
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(AttachmentFormRequest $request, AttachmentRepositoryInterface $repository, Attachment $attachment)
|
||||
{
|
||||
|
||||
$attachmentData = [
|
||||
'title' => $request->input('title'),
|
||||
'description' => $request->input('description'),
|
||||
'notes' => $request->input('notes'),
|
||||
];
|
||||
|
||||
$repository->update($attachment, $attachmentData);
|
||||
|
||||
Session::flash('success', 'Attachment "' . $attachment->filename . '" updated.');
|
||||
Preferences::mark();
|
||||
|
||||
if (intval(Input::get('return_to_edit')) === 1) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
Session::put('accounts.edit.fromUpdate', true);
|
||||
|
||||
return redirect(route('attachment.edit', [$attachment->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
// redirect to previous URL.
|
||||
return redirect(Session::get('accounts.edit.url'));
|
||||
|
||||
}
|
||||
|
||||
}
|
36
app/Http/Requests/AttachmentFormRequest.php
Normal file
36
app/Http/Requests/AttachmentFormRequest.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class AttachmentFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class AttachmentFormRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
|
||||
return [
|
||||
'title' => 'between:1,255',
|
||||
'description' => 'between:1,65536',
|
||||
'notes' => 'between:1,65536',
|
||||
];
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Crypt;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
@ -9,20 +10,20 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* Class Attachment
|
||||
*
|
||||
* @package FireflyIII\Models
|
||||
* @property integer $id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property string $deleted_at
|
||||
* @property integer $attachable_id
|
||||
* @property string $attachable_type
|
||||
* @property integer $user_id
|
||||
* @property string $md5
|
||||
* @property string $filename
|
||||
* @property string $mime
|
||||
* @property integer $size
|
||||
* @property boolean $uploaded
|
||||
* @property-read \ $attachable
|
||||
* @property-read \FireflyIII\User $user
|
||||
* @property integer $id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property string $deleted_at
|
||||
* @property integer $attachable_id
|
||||
* @property string $attachable_type
|
||||
* @property integer $user_id
|
||||
* @property string $md5
|
||||
* @property string $filename
|
||||
* @property string $mime
|
||||
* @property integer $size
|
||||
* @property boolean $uploaded
|
||||
* @property-read \ $attachable
|
||||
* @property-read \FireflyIII\User $user
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereUpdatedAt($value)
|
||||
@ -35,12 +36,18 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereMime($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereSize($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereUploaded($value)
|
||||
* @property string $title
|
||||
* @property string $description
|
||||
* @property string $notes
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereTitle($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereDescription($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereNotes($value)
|
||||
*/
|
||||
class Attachment extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = ['attachable_id', 'attachable_type', 'user_id', 'md5', 'filename', 'mime', 'size', 'uploaded'];
|
||||
protected $fillable = ['attachable_id', 'attachable_type', 'user_id', 'md5', 'filename', 'mime', 'title', 'notes', 'description', 'size', 'uploaded'];
|
||||
|
||||
/**
|
||||
* Get all of the owning imageable models.
|
||||
@ -59,4 +66,125 @@ class Attachment extends Model
|
||||
return $this->belongsTo('FireflyIII\User');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getFilenameAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setFilenameAttribute($value)
|
||||
{
|
||||
$this->attributes['filename'] = Crypt::encrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getMimeAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setMimeAttribute($value)
|
||||
{
|
||||
$this->attributes['mime'] = Crypt::encrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getTitleAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setTitleAttribute($value)
|
||||
{
|
||||
$this->attributes['title'] = Crypt::encrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getDescriptionAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setDescriptionAttribute($value)
|
||||
{
|
||||
$this->attributes['description'] = Crypt::encrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getNotesAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setNotesAttribute($value)
|
||||
{
|
||||
$this->attributes['notes'] = Crypt::encrypt($value);
|
||||
}
|
||||
|
||||
}
|
@ -88,6 +88,7 @@ class FireflyServiceProvider extends ServiceProvider
|
||||
$this->app->bind('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface', 'FireflyIII\Repositories\PiggyBank\PiggyBankRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\Tag\TagRepositoryInterface', 'FireflyIII\Repositories\Tag\TagRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface', 'FireflyIII\Repositories\Attachment\AttachmentRepository');
|
||||
$this->app->bind('FireflyIII\Support\Search\SearchInterface', 'FireflyIII\Support\Search\Search');
|
||||
|
||||
// CSV import
|
||||
|
32
app/Repositories/Attachment/AttachmentRepository.php
Normal file
32
app/Repositories/Attachment/AttachmentRepository.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Repositories\Attachment;
|
||||
|
||||
use FireflyIII\Models\Attachment;
|
||||
|
||||
/**
|
||||
* Class AttachmentRepository
|
||||
*
|
||||
* @package FireflyIII\Repositories\Attachment
|
||||
*/
|
||||
class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment
|
||||
*/
|
||||
public function update(Attachment $attachment, array $data)
|
||||
{
|
||||
|
||||
$attachment->title = $data['title'];
|
||||
$attachment->description = $data['description'];
|
||||
$attachment->notes = $data['notes'];
|
||||
$attachment->save();
|
||||
|
||||
return $attachment;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Repositories\Attachment;
|
||||
|
||||
use FireflyIII\Models\Attachment;
|
||||
|
||||
/**
|
||||
* Interface AttachmentRepositoryInterface
|
||||
*
|
||||
* @package FireflyIII\Repositories\Attachment
|
||||
*/
|
||||
interface AttachmentRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param array $attachmentData
|
||||
*
|
||||
* @return Attachment
|
||||
*/
|
||||
public function update(Attachment $attachment, array $attachmentData);
|
||||
}
|
@ -24,12 +24,11 @@ class ChangesForV3410 extends Migration
|
||||
$table->string('attachable_type');
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('md5', 32);
|
||||
$table->string('filename');
|
||||
$table->string('title')->nullable();
|
||||
$table->text('filename');
|
||||
$table->text('title')->nullable();
|
||||
$table->text('description')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
|
||||
$table->string('mime');
|
||||
$table->text('mime');
|
||||
$table->integer('size')->unsigned();
|
||||
$table->tinyInteger('uploaded', false, true)->default(0);
|
||||
|
||||
@ -37,6 +36,8 @@ class ChangesForV3410 extends Migration
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
|
@ -31,9 +31,9 @@
|
||||
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.text('title') }}
|
||||
{{ ExpandedForm.textarea('description') }}
|
||||
{{ ExpandedForm.textarea('notes') }}
|
||||
{{ ExpandedForm.text('title', attachment.title) }}
|
||||
{{ ExpandedForm.textarea('description', attachment.description) }}
|
||||
{{ ExpandedForm.textarea('notes', attachment.notes) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -93,8 +93,18 @@
|
||||
</td>
|
||||
<td>
|
||||
<i class="fa fa-file-pdf-o"></i>
|
||||
<a href="{{ route('attachment.download', att.id) }}">{{ att.filename }}</a>
|
||||
<a href="{{ route('attachment.download', att.id) }}" title="{{ att.filename }}">
|
||||
{% if att.title %}
|
||||
{{ att.title }}
|
||||
{% else %}
|
||||
{{ att.filename }}
|
||||
{% endif %}
|
||||
</a>
|
||||
({{ att.size|filesize }})
|
||||
{% if att.description %}
|
||||
<br/>
|
||||
<em>{{ att.description }}</em>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user