Storage locations can now be edited. Added the rotate photo left/right to the max post size exclusion list

This commit is contained in:
Andy Heathershaw 2016-09-28 20:13:18 +01:00
parent 48b43c3dd2
commit 6635d20ead
8 changed files with 158 additions and 24 deletions

View File

@ -3,7 +3,7 @@
<component name="WebServers">
<option name="servers">
<webServer id="b14a34b0-0127-4886-964a-7be75a2281ac" name="Development" url="http://blue-twilight-dev.andys.eu">
<fileTransfer host="miami.andys.eu" port="22" rootFolder="/srv/www/blue-twilight-dev" accessType="SFTP">
<fileTransfer host="orlando.andys.eu" port="22" rootFolder="/srv/www/blue-twilight-dev" accessType="SFTP">
<advancedOptions>
<advancedOptions dataProtectionLevel="Private" />
</advancedOptions>

View File

@ -40,8 +40,14 @@ class Album extends Model
*/
public function getAlbumSource()
{
// TODO allow albums to specify different storage locations - e.g. Amazon S3, SFTP/FTP, OpenStack
return new LocalFilesystemSource($this, dirname(__DIR__) . '/storage/app/albums');
$fullClassName = sprintf('App\AlbumSources\%s', $this->storage->source);
/** @var IAlbumSource $source */
$source = new $fullClassName;
$source->setAlbum($this);
$source->setConfiguration($this->storage);
return $source;
}
public function photos()
@ -49,6 +55,11 @@ class Album extends Model
return $this->hasMany(Photo::class);
}
public function storage()
{
return $this->belongsTo(Storage::class);
}
public function thumbnailUrl($thumbnailName)
{
$photo = $this->photos()

View File

@ -4,6 +4,7 @@ namespace App\AlbumSources;
use App\Album;
use App\Photo;
use App\Storage;
use Symfony\Component\HttpFoundation\File\File;
interface IAlbumSource
@ -59,4 +60,16 @@ interface IAlbumSource
* @return File
*/
function saveUploadedPhoto(File $uploadedFile);
/**
* @param Album $album
* @return mixed
*/
function setAlbum(Album $album);
/**
* @param Storage $configuration
* @return mixed
*/
function setConfiguration(Storage $configuration);
}

View File

@ -9,6 +9,7 @@ use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\App;
class StorageController extends Controller
{
@ -63,24 +64,12 @@ class StorageController extends Controller
$storage = new Storage();
$storage->fill($request->only(['name', 'source', 'location']));
$storage->is_default = (strtolower($request->get('is_default')) == 'on');
$storage->save();
if ($storage->is_default)
{
// If this storage is flagged as default, remove all others
foreach (Storage::all() as $otherStorage)
{
if ($otherStorage->id == $storage->id)
{
// Ignore the one just created
continue;
}
$otherStorage->is_default = false;
$otherStorage->save();
}
$this->unsetIsDefaultFromOthers($storage);
}
return redirect(route('storage.index'));
@ -105,7 +94,15 @@ class StorageController extends Controller
*/
public function edit($id)
{
//
$this->authorize('admin-access');
$storage = Storage::where('id', intval($id))->first();
if (is_null($storage))
{
App::abort(404);
}
return Theme::render('admin.edit_storage', ['storage' => $storage]);
}
/**
@ -115,9 +112,26 @@ class StorageController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Requests\StoreStorageRequest $request, $id)
{
//
$this->authorize('admin-access');
$storage = Storage::where('id', intval($id))->first();
if (is_null($storage))
{
App::abort(404);
}
$storage->fill($request->only(['name']));
$storage->is_default = (strtolower($request->get('is_default')) == 'on');
$storage->save();
if ($storage->is_default)
{
$this->unsetIsDefaultFromOthers($storage);
}
return redirect(route('storage.index'));
}
/**
@ -130,4 +144,20 @@ class StorageController extends Controller
{
//
}
private function unsetIsDefaultFromOthers(Storage $storage)
{
// If this storage is flagged as default, remove all others
foreach (Storage::all() as $otherStorage)
{
if ($otherStorage->id == $storage->id)
{
// Ignore the one just created
continue;
}
$otherStorage->is_default = false;
$otherStorage->save();
}
}
}

View File

@ -18,7 +18,8 @@ class CheckMaxPostSizeExceeded
protected $exclude = [
'/admin/photos/analyse/*',
'/admin/photos/regenerate-thumbnails/*'
'/admin/photos/regenerate-thumbnails/*',
'/admin/photos/rotate/*'
];
/**

View File

@ -2,6 +2,7 @@
namespace App\Http\Requests;
use App\Storage;
use Illuminate\Foundation\Http\FormRequest;
class StoreStorageRequest extends FormRequest
@ -23,9 +24,22 @@ class StoreStorageRequest extends FormRequest
*/
public function rules()
{
switch ($this->method())
{
case 'POST':
return [
'name' => 'required|unique:storages|max:255',
'source' => 'required|max:255',
];
case 'PATCH':
case 'PUT':
$storageId = intval($this->segment(3));
return [
'name' => 'required|max:255|unique:storages,name,' . $storageId
];
}
}
}

View File

@ -22,6 +22,8 @@ return [
'edit_album' => 'Edit photo album: :album_name',
'edit_album_intro' => 'Photo albums contain individual photographs together in the same way as a physical photo album or memory book.',
'edit_album_intro2' => 'Complete the form below to edit the properties of the album: :album_name.',
'edit_storage' => 'Edit storage location: :storage_name',
'edit_storage_intro' => 'Use the form below to update the details of the :storage_name storage location.',
'is_uploading' => 'Uploading in progress...',
'manage_widget' => [
'panel_header' => 'Manage'

View File

@ -0,0 +1,63 @@
@extends('themes.base.layout')
@section('title', trans('admin.edit_storage', ['storage_name' => $storage->name]))
@section('breadcrumb')
<div class="breadcrumb">
<div class="container">
<ol class="breadcrumb">
<li><a href="{{ route('home') }}">@lang('navigation.breadcrumb.home')</a></li>
<li><a href="{{ route('admin') }}">@lang('navigation.breadcrumb.admin')</a></li>
<li><a href="{{ route('storage.index') }}">@lang('navigation.breadcrumb.storage')</a></li>
<li class="active">@lang('navigation.breadcrumb.create_storage')</li>
</ol>
</div>
</div>
@endsection
@section('content')
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>@yield('title')</h1>
<p>@lang('admin.edit_storage_intro', ['storage_name' => $storage->name])</p>
<hr/>
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $formError)
<li>{{ $formError }}</li>
@endforeach
</ul>
</div>
@endif
{!! Form::model($storage, ['route' => ['storage.update', $storage->id], 'method' => 'PUT']) !!}
<div class="form-group">
{!! Form::label('name', trans('forms.name_label'), ['class' => 'control-label']) !!}
{!! Form::text('name', old('name'), ['class' => 'form-control']) !!}
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="is_default"@if ($storage->is_default) checked="checked"@endif>
<strong>@lang('forms.default_storage_label')</strong>
</label>
</div>
<div class="form-actions">
<a href="{{ route('storage.index') }}" class="btn btn-default">@lang('forms.cancel_action')</a>
{!! Form::submit(trans('forms.save_action'), ['class' => 'btn btn-success']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
@endsection
@push('scripts')
<script type="text/javascript">
var viewModel = new StorageLocationsViewModel();
ko.applyBindings(viewModel);
</script>
@endpush