FIX: fix few minor bugs

This commit is contained in:
Michal Kváček
2017-02-09 23:42:07 +01:00
parent 9593b6502e
commit 0ba0d1c15d
4 changed files with 32 additions and 27 deletions
+22 -5
View File
@@ -3,15 +3,32 @@ namespace App\CMS\Repositories\FileManager;
use App\CMS\Helpers\RootDirectory;
use App\Models\FileManager\Directory as DirectoryModel;
use App\Models\FileManager\File;
class Directory
{
public function checkIfNameExists($name, $directoryId)
/**
* Checks if directory with given name does not exist in current directory
*
* @param $name
* @param $parentDirectoryId
* @param bool $ignoredId
*/
public function checkIfNameExists($name, $parentDirectoryId, $ignoredId = false)
{
return DirectoryModel::where('name', $name)
->where('parent_id', $directoryId)
->exists();
$exists = DirectoryModel::where('name', $name)
->where('parent_id', $parentDirectoryId);
if ($ignoredId !== false) {
$exists = $exists->where('id', '!=', $ignoredId);
}
return $exists->exists();
}
public function update(DirectoryModel $directory, $data) {
$directory->name = $data['name'];
$directory->description = $data['description'];
$directory->save();
}
/**
@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Admin\FileManager;
use App\CMS\Repositories\FileManager\Directory as DirectoryRepository;
use App\Http\Controllers\Admin\Controller;
use App\Http\Requests;
use App\Models\FileManager\Directory;
@@ -16,30 +17,21 @@ class EditDirectory extends Controller
* @internal param $directoryId
*
*/
public function postEdit(Requests\EditDirectoryRequest $request, Directory $directory)
public function update(Requests\EditDirectoryRequest $request, Directory $directory)
{
// check if given name is not used in parent directory
$exists = Directory::where('parent_id', $directory->parent_id)
->where('name', $request->name)
->where('id', '!=', $directory->id)
->exists();
if ($exists) {
$repository = app(DirectoryRepository::class);
if ($repository->checkIfNameExists($request->name, $directory->parent_id, $directory->id)) {
return redirect()
->route('upload.overview', ['id' => $directory->id])
->back()
->withInput()
->with('error', trans('admin/fileManager.subdirectoryExists'));
}
$directory->name = $request->name;
$directory->description = $request->description;
$directory->save();
$repository->update($directory, $request->except('_token'));
$message = trans('admin/fileManager.editDirectorySuccess');
return redirect()
->route('upload.overview', ['id' => $directory->id])
->back()
->with('success', $message);
}
}
+1 -2
View File
@@ -1,11 +1,10 @@
<?php
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['localeSessionRedirect', 'localizationRedirect'],
'namespace' => 'Modules\Blog\Article\Http\Controllers'
], function () {
Route::group([
'middleware' => ['web', 'auth', 'adminMenu'],
'middleware' => ['admin'],
'prefix' => 'admin/comments',
'namespace' => 'Admin'
], function () {
@@ -1,14 +1,13 @@
<form method="POST" action="{{$action}}">
{!! csrf_field() !!}
<input type="text" name="name" placeholder="@lang('admin/fileManager.directoryName')" class="form-control"
<input type="text" name="name" required placeholder="@lang('admin/fileManager.directoryName')" class="form-control"
value="{{old('name', $directory->name)}}" />
<textarea name="description" class="form-control" placeholder="@lang('admin/fileManager.directoryDescription')"
rows="3">{{old('description', $directory->description)}}</textarea>
@if ($parentDirectory->id)
<input type="text" name="parentDirectory" value="{{$parentDirectory->id}}">
<input type="hidden" name="parentDirectory" value="{{$parentDirectory->id}}">
@endif
<button type="submit" class="btn btn-primary">
@@ -17,7 +16,5 @@
@else
@lang('admin/fileManager.newDirectory')
@endif
</button>
</form>