Fixes #100: set the first active storage location as default when the current default is deactivated. Also remove the stupid _old_input thingy as this was the very first screen I did in Laravel and it's not needed!

This commit is contained in:
Andy Heathershaw 2019-07-20 18:06:21 +01:00
parent 5947b6e08c
commit 8a758f2b06
7 changed files with 45 additions and 30 deletions

View File

@ -4,11 +4,10 @@ namespace App\Http\Controllers\Admin;
use App\Facade\Theme; use App\Facade\Theme;
use App\Facade\UserConfig; use App\Facade\UserConfig;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Storage; use App\Storage;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
@ -60,7 +59,8 @@ class StorageController extends Controller
return Theme::render('admin.create_storage', [ return Theme::render('admin.create_storage', [
'album_sources' => UserConfig::albumSources(), 'album_sources' => UserConfig::albumSources(),
'filesystem_default_location' => $filesystemDefaultLocation, 'filesystem_default_location' => $filesystemDefaultLocation,
'info' => $request->session()->get('info') 'info' => $request->session()->get('info'),
'storage' => new Storage()
]); ]);
} }
@ -186,11 +186,6 @@ class StorageController extends Controller
} }
} }
if (!$request->session()->has('_old_input'))
{
$request->session()->flash('_old_input', $storage->toArray());
}
return Theme::render('admin.edit_storage', ['storage' => $storage]); return Theme::render('admin.edit_storage', ['storage' => $storage]);
} }
@ -246,6 +241,10 @@ class StorageController extends Controller
{ {
$this->unsetIsDefaultFromOthers($storage); $this->unsetIsDefaultFromOthers($storage);
} }
else
{
$this->setIsDefaultForFirstStorage();
}
return redirect(route('storage.index')); return redirect(route('storage.index'));
} }
@ -285,6 +284,22 @@ class StorageController extends Controller
return redirect(route('storage.index')); return redirect(route('storage.index'));
} }
private function setIsDefaultForFirstStorage()
{
$count = Storage::where('is_default', true)->count();
if ($count == 0)
{
$storage = Storage::where('is_active', true)->first();
if (!is_null($storage))
{
$storage->is_default = true;
$storage->save();
}
}
}
private function unsetIsDefaultFromOthers(Storage $storage) private function unsetIsDefaultFromOthers(Storage $storage)
{ {
// If this storage is flagged as default, remove all others // If this storage is flagged as default, remove all others

View File

@ -21,7 +21,7 @@
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="storage-name">@lang('forms.name_label')</label> <label class="form-control-label" for="storage-name">@lang('forms.name_label')</label>
<input type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" id="storage-name" name="name" value="{{ old('name') }}"> <input type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" id="storage-name" name="name" value="{{ old('name', $storage->name) }}">
@if ($errors->has('name')) @if ($errors->has('name'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -64,7 +64,7 @@
</div> </div>
<div class="form-check"> <div class="form-check">
<input type="checkbox" class="form-check-input" id="is-default" name="is_default"@if (old('is_default')) checked="checked"@endif> <input type="checkbox" class="form-check-input" id="is-default" name="is_default"@if (old('is_default', $storage->is_default)) checked="checked"@endif>
<label class="form-check-label" for="is-default">@lang('forms.default_storage_label')</label> <label class="form-check-label" for="is-default">@lang('forms.default_storage_label')</label>
</div> </div>

View File

@ -22,7 +22,7 @@
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="storage-name">@lang('forms.name_label')</label> <label class="form-control-label" for="storage-name">@lang('forms.name_label')</label>
<input type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" id="storage-name" name="name" value="{{ old('name') }}"> <input type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" id="storage-name" name="name" value="{{ old('name', $storage->name) }}">
@if ($errors->has('name')) @if ($errors->has('name'))
<div class="invalid-feedback"> <div class="invalid-feedback">

View File

@ -2,7 +2,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="access-key">@lang('forms.storage_access_key_label')</label> <label class="form-control-label" for="access-key">@lang('forms.storage_access_key_label')</label>
<input type="text" class="form-control{{ $errors->has('access_key') ? ' is-invalid' : '' }}" id="access-key" name="access_key" value="{{ old('access_key') }}"> <input type="text" class="form-control{{ $errors->has('access_key') ? ' is-invalid' : '' }}" id="access-key" name="access_key" value="{{ old('access_key', $storage->access_key) }}">
@if ($errors->has('access_key')) @if ($errors->has('access_key'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -14,7 +14,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="secret-key">@lang('forms.storage_secret_key_label')</label> <label class="form-control-label" for="secret-key">@lang('forms.storage_secret_key_label')</label>
<input type="text" class="form-control{{ $errors->has('secret_key') ? ' is-invalid' : '' }}" id="secret-key" name="secret_key" value="{{ old('secret_key') }}"> <input type="text" class="form-control{{ $errors->has('secret_key') ? ' is-invalid' : '' }}" id="secret-key" name="secret_key" value="{{ old('secret_key', $storage->secret_key) }}">
@if ($errors->has('secret_key')) @if ($errors->has('secret_key'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -29,7 +29,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="container-name">@lang('forms.storage_bucket_name_label')</label> <label class="form-control-label" for="container-name">@lang('forms.storage_bucket_name_label')</label>
<input type="text" class="form-control{{ $errors->has('container_name') ? ' is-invalid' : '' }}" id="container-name" name="container_name" value="{{ old('container_name') }}"> <input type="text" class="form-control{{ $errors->has('container_name') ? ' is-invalid' : '' }}" id="container-name" name="container_name" value="{{ old('container_name', $storage->container_name) }}">
@if ($errors->has('container_name')) @if ($errors->has('container_name'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -41,7 +41,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="service-region">@lang('forms.storage_service_region_label')</label> <label class="form-control-label" for="service-region">@lang('forms.storage_service_region_label')</label>
<input type="text" class="form-control{{ $errors->has('service_region') ? ' is-invalid' : '' }}" id="service-region" name="service_region" value="{{ old('service_region') }}"> <input type="text" class="form-control{{ $errors->has('service_region') ? ' is-invalid' : '' }}" id="service-region" name="service_region" value="{{ old('service_region', $storage->service_region) }}">
@if ($errors->has('service_region')) @if ($errors->has('service_region'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -54,7 +54,7 @@
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="auth-url">@lang('forms.storage_auth_url_label')</label> <label class="form-control-label" for="auth-url">@lang('forms.storage_auth_url_label')</label>
<input type="text" class="form-control{{ $errors->has('auth_url') ? ' is-invalid' : '' }}" id="auth-url" name="auth_url" value="{{ old('auth_url') }}"> <input type="text" class="form-control{{ $errors->has('auth_url') ? ' is-invalid' : '' }}" id="auth-url" name="auth_url" value="{{ old('auth_url', $storage->auth_url) }}">
@if ($errors->has('auth_url')) @if ($errors->has('auth_url'))
<div class="invalid-feedback"> <div class="invalid-feedback">

View File

@ -1,6 +1,6 @@
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="storage-location">@lang('forms.storage_location_label')</label> <label class="form-control-label" for="storage-location">@lang('forms.storage_location_label')</label>
<input type="text" class="form-control{{ $errors->has('location') ? ' is-invalid' : '' }}" id="storage-location" name="location" value="{{ old('location', isset($filesystem_default_location) ? $filesystem_default_location : '') }}"> <input type="text" class="form-control{{ $errors->has('location') ? ' is-invalid' : '' }}" id="storage-location" name="location" value="{{ old('location', isset($filesystem_default_location) ? $filesystem_default_location : $storage->location) }}">
@if ($errors->has('location')) @if ($errors->has('location'))
<div class="invalid-feedback"> <div class="invalid-feedback">

View File

@ -2,7 +2,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="auth-url">@lang('forms.storage_auth_url_label')</label> <label class="form-control-label" for="auth-url">@lang('forms.storage_auth_url_label')</label>
<input type="text" class="form-control{{ $errors->has('auth_url') ? ' is-invalid' : '' }}" id="auth-url" name="auth_url" value="{{ old('auth_url') }}"> <input type="text" class="form-control{{ $errors->has('auth_url') ? ' is-invalid' : '' }}" id="auth-url" name="auth_url" value="{{ old('auth_url', $storage->auth_url) }}">
@if ($errors->has('auth_url')) @if ($errors->has('auth_url'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -14,7 +14,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="tenant-name">@lang('forms.storage_tenant_name_label')</label> <label class="form-control-label" for="tenant-name">@lang('forms.storage_tenant_name_label')</label>
<input type="text" class="form-control{{ $errors->has('tenant_name') ? ' is-invalid' : '' }}" id="tenant-name" name="tenant_name" value="{{ old('tenant_name') }}"> <input type="text" class="form-control{{ $errors->has('tenant_name') ? ' is-invalid' : '' }}" id="tenant-name" name="tenant_name" value="{{ old('tenant_name', $storage->tenant_name) }}">
@if ($errors->has('tenant_name')) @if ($errors->has('tenant_name'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -29,7 +29,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="username">@lang('forms.username_label')</label> <label class="form-control-label" for="username">@lang('forms.username_label')</label>
<input type="text" class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}" id="username" name="username" value="{{ old('username') }}"> <input type="text" class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}" id="username" name="username" value="{{ old('username', $storage->username) }}">
@if ($errors->has('username')) @if ($errors->has('username'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -41,7 +41,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="password">@lang('forms.password_label')</label> <label class="form-control-label" for="password">@lang('forms.password_label')</label>
<input type="text" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" id="password" name="password" value="{{ old('password') }}"> <input type="text" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" id="password" name="password" value="{{ old('password', $storage->password) }}">
@if ($errors->has('password')) @if ($errors->has('password'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -56,7 +56,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="service-name">@lang('forms.storage_service_name_label')</label> <label class="form-control-label" for="service-name">@lang('forms.storage_service_name_label')</label>
<input type="text" class="form-control{{ $errors->has('service_name') ? ' is-invalid' : '' }}" id="service-name" name="service_name" value="{{ old('service_name') }}"> <input type="text" class="form-control{{ $errors->has('service_name') ? ' is-invalid' : '' }}" id="service-name" name="service_name" value="{{ old('service_name', $storage->service_name) }}">
@if ($errors->has('service_name')) @if ($errors->has('service_name'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -68,7 +68,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="service-region">@lang('forms.storage_service_region_label')</label> <label class="form-control-label" for="service-region">@lang('forms.storage_service_region_label')</label>
<input type="text" class="form-control{{ $errors->has('service_region') ? ' is-invalid' : '' }}" id="service-region" name="service_region" value="{{ old('service_region') }}"> <input type="text" class="form-control{{ $errors->has('service_region') ? ' is-invalid' : '' }}" id="service-region" name="service_region" value="{{ old('service_region', $storage->service_region) }}">
@if ($errors->has('service_region')) @if ($errors->has('service_region'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -81,7 +81,7 @@
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="container-name">@lang('forms.storage_container_name_label')</label> <label class="form-control-label" for="container-name">@lang('forms.storage_container_name_label')</label>
<input type="text" class="form-control{{ $errors->has('container_name') ? ' is-invalid' : '' }}" id="container-name" name="container_name" value="{{ old('container_name') }}"> <input type="text" class="form-control{{ $errors->has('container_name') ? ' is-invalid' : '' }}" id="container-name" name="container_name" value="{{ old('container_name', $storage->container_name) }}">
@if ($errors->has('container_name')) @if ($errors->has('container_name'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -92,7 +92,7 @@
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="cdn-url">@lang('forms.storage_cdn_url_label')</label> <label class="form-control-label" for="cdn-url">@lang('forms.storage_cdn_url_label')</label>
<input type="text" class="form-control{{ $errors->has('cdn_url') ? ' is-invalid' : '' }}" id="cdn-url" name="cdn_url" value="{{ old('cdn_url') }}"> <input type="text" class="form-control{{ $errors->has('cdn_url') ? ' is-invalid' : '' }}" id="cdn-url" name="cdn_url" value="{{ old('cdn_url', $storage->cdn_url) }}">
@if ($errors->has('cdn_url')) @if ($errors->has('cdn_url'))
<div class="invalid-feedback"> <div class="invalid-feedback">

View File

@ -2,7 +2,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="username">@lang('forms.username_label')</label> <label class="form-control-label" for="username">@lang('forms.username_label')</label>
<input type="text" class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}" id="username" name="username" value="{{ old('username') }}"> <input type="text" class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}" id="username" name="username" value="{{ old('username', $storage->username) }}">
@if ($errors->has('username')) @if ($errors->has('username'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -14,7 +14,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="password">@lang('forms.password_label')</label> <label class="form-control-label" for="password">@lang('forms.password_label')</label>
<input type="text" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" id="password" name="password" value="{{ old('password') }}"> <input type="text" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" id="password" name="password" value="{{ old('password', $storage->password) }}">
@if ($errors->has('password')) @if ($errors->has('password'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -29,7 +29,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="service-region">@lang('forms.storage_service_region_label')</label> <label class="form-control-label" for="service-region">@lang('forms.storage_service_region_label')</label>
<input type="text" class="form-control{{ $errors->has('service_region') ? ' is-invalid' : '' }}" id="service-region" name="service_region" value="{{ old('service_region') }}"> <input type="text" class="form-control{{ $errors->has('service_region') ? ' is-invalid' : '' }}" id="service-region" name="service_region" value="{{ old('service_region', $storage->service_region) }}">
@if ($errors->has('service_region')) @if ($errors->has('service_region'))
<div class="invalid-feedback"> <div class="invalid-feedback">
@ -41,7 +41,7 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="container-name">@lang('forms.storage_container_name_label')</label> <label class="form-control-label" for="container-name">@lang('forms.storage_container_name_label')</label>
<input type="text" class="form-control{{ $errors->has('container_name') ? ' is-invalid' : '' }}" id="container-name" name="container_name" value="{{ old('container_name') }}"> <input type="text" class="form-control{{ $errors->has('container_name') ? ' is-invalid' : '' }}" id="container-name" name="container_name" value="{{ old('container_name', $storage->container_name) }}">
@if ($errors->has('container_name')) @if ($errors->has('container_name'))
<div class="invalid-feedback"> <div class="invalid-feedback">