This commit is contained in:
Kekskurse 2021-01-12 20:45:20 +01:00
parent c6d6fb7b78
commit 8b196bf5cf
5 changed files with 59 additions and 7 deletions

View file

@ -134,4 +134,11 @@ class GalleryController extends BaseController
$images = Image::query()->where("gallery", "=", $gallery->id)->get(); $images = Image::query()->where("gallery", "=", $gallery->id)->get();
return view("gallery.images", ["images" => $images, "gallery" => $gallery, "tenant" => $tenant]); return view("gallery.images", ["images" => $images, "gallery" => $gallery, "tenant" => $tenant]);
} }
public function setDefault($name, Request $request) {
$gallery = Gallery::getByTenantAndUrl(session("current_tenant_id"), $name);
$gallery->main_image = $request->input("id");
$gallery->saveOrFail();
return "OK";
}
} }

8
resources/js/polaroid.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -4,7 +4,7 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@foreach($images as $image) @foreach($images as $image)
<div class="card col-md-2" style="float:left;cursor: pointer;" data-toggle="modal" data-target="#exampleModal"> <div class="card col-md-2 editImage" x-id="{{ $image->id }}" x-name="{{ $image->filename }}" x-image-url="/{{ $tenant->url }}/{{ $gallery->url }}/{{ $image->id }}/file?size=medium" style="float:left;cursor: pointer;" >
<div class="card-body" style="text-align: center;"> <div class="card-body" style="text-align: center;">
<img class="card-img-top" src="/{{ $tenant->url }}/{{ $gallery->url }}/{{ $image->id }}/file?size=small" style="height: 200px;width: auto; max-width: 100%;"> <img class="card-img-top" src="/{{ $tenant->url }}/{{ $gallery->url }}/{{ $image->id }}/file?size=small" style="height: 200px;width: auto; max-width: 100%;">
@ -27,19 +27,40 @@
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <h5 class="modal-title" id="exampleModalLabel">Bild bearbeiten</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
... <img src="" id="imagePreview" style="width: 100%;">
<input style="display: none;" name="name" id="edit-name" placeholder="Name" class="form-control">
<input style="display: none;" name="edit-id" id="edit-id" placeholder="ID" class="form-control">
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" id="makeGalleryDefault" class="btn btn-warning">Make Galery Preview</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button> <!--<button type="button" class="btn btn-primary">Save changes</button>!-->
</div> </div>
</div> </div>
</div> </div>
</div> </div>
@endsection
@section('js')
<script>
$(".editImage").click(function () {
$("#imagePreview").attr("src", $(this).attr("x-image-url"));
$("#edit-name").val($(this).attr("x-name"));
$("#edit-id").val($(this).attr("x-id"));
$('#exampleModal').modal('show')
});
$("#makeGalleryDefault").click(function () {
$.ajax("/g/{{ $gallery->url }}/setDefault?id="+$("#edit-id").val()).done(function () {
alert("Set as Main Image");
});
});
</script>
@endsection @endsection

View file

@ -2,9 +2,24 @@
@section('content') @section('content')
<h1>Galleries</h1> <h1>Galleries</h1>
<div class="row">
@foreach($galleries as $gallery) @foreach($galleries as $gallery)
<ul> <div class="col-md-4" style="margin-bottom: 20px;">
<li><a href="/{{ $tenant->url }}/{{ $gallery->url }}">{{ $gallery->name }}</a></li> <a href="/{{$tenant->url}}/{{$gallery->url}}">
</ul> <div class="card">
<div class="card-header">
{{ $gallery->name }}
</div>
<div class="card-body">
<img class="card-img-top" src="/{{$tenant->url}}/{{$gallery->url}}/{{$gallery->main_image}}/file" style="max-height: 400px; width: auto;max-width: 100%;" alt="Card image cap">
<p class="card-text">{{ $gallery->description }}</p>
</div>
</div>
</a>
</div>
@endforeach @endforeach
</div>
@endsection
@section('js')
@endsection @endsection

View file

@ -40,6 +40,7 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function
Route::get("/g/{url}/upload", [\App\Http\Controllers\GalleryController::class, 'imagesUploadView']); Route::get("/g/{url}/upload", [\App\Http\Controllers\GalleryController::class, 'imagesUploadView']);
Route::post("/g/{url}/upload", [\App\Http\Controllers\GalleryController::class, 'imageUpload']); Route::post("/g/{url}/upload", [\App\Http\Controllers\GalleryController::class, 'imageUpload']);
Route::get("/g/{url}", [\App\Http\Controllers\GalleryController::class, 'showImagesView']); Route::get("/g/{url}", [\App\Http\Controllers\GalleryController::class, 'showImagesView']);
Route::get("/g/{url}/setDefault", [\App\Http\Controllers\GalleryController::class, 'setDefault']);
}); });
Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);