134 lines
3.1 KiB
PHP
134 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Facade\Theme;
|
|
use App\Facade\UserConfig;
|
|
use App\Storage;
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Requests;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
class StorageController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$storageLocations = Storage::orderBy('name')
|
|
->paginate(UserConfig::get('items_per_page'));
|
|
|
|
return Theme::render('admin.list_storage', [
|
|
'storageLocations' => $storageLocations
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$filesystemDefaultLocation = sprintf('%s/storage/app/albums', dirname(dirname(dirname(dirname(__DIR__)))));
|
|
|
|
return Theme::render('admin.create_storage', [
|
|
'album_sources' => UserConfig::albumSources(),
|
|
'filesystem_default_location' => $filesystemDefaultLocation
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Requests\StoreStorageRequest $request)
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$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();
|
|
}
|
|
}
|
|
|
|
return redirect(route('storage.index'));
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
//public function show($id)
|
|
//{
|
|
//
|
|
//}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
}
|