This commit is contained in:
Kekskurse 2021-01-19 19:57:14 +01:00
parent 5cf01e160d
commit 722107ec10
4 changed files with 22 additions and 5 deletions

View file

@ -102,10 +102,6 @@ class GalleryController extends BaseController
public function editGalleryView($name, Request $request) { public function editGalleryView($name, Request $request) {
$gallery = Gallery::getByTenantAndUrl(session("current_tenant_id"), $name); $gallery = Gallery::getByTenantAndUrl(session("current_tenant_id"), $name);
/*session(['_old_input.name' => $gallery->name]);
session(['_old_input.description' => $gallery->description]);
session(['_old_input.date' => $gallery->gallery_create_time]);
session(['_old_input.url' => $gallery->url]);*/
return view("gallery.new", ["gallery" => $gallery]); return view("gallery.new", ["gallery" => $gallery]);
} }
@ -169,4 +165,16 @@ class GalleryController extends BaseController
$gallery->saveOrFail(); $gallery->saveOrFail();
return "OK"; return "OK";
} }
public function deleteImage($name, Request $request) {
$gallery = Gallery::getByTenantAndUrl(session("current_tenant_id"), $name);
$image = Image::query()->where("id", "=", $request->input("id"))->firstOrFail();
if($image->gallery != $gallery->id) {
abort(400);
}
Storage::disk($image->driver)->delete($image->path);
$image->delete();
return "OK";
}
} }

View file

@ -61,7 +61,7 @@ class ResizeImage implements ShouldQueue
$image = ImageResize::createFromString($file); $image = ImageResize::createFromString($file);
$image->resizeToLongSide($this->size); $image->resizeToLongSide($this->size);
Storage::disk("cache")->put($cacheName."_".$this->size, $image->getImageAsString()); Storage::disk("cache")->put($cacheName."_".$this->size, $image->getImageAsString(IMAGETYPE_JPEG, 100));
} }

View file

@ -38,7 +38,9 @@
<input style="display: none;" name="edit-id" id="edit-id" placeholder="ID" 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="deleteImage" class="btn btn-danger">Delete</button>
<button type="button" id="makeGalleryDefault" class="btn btn-warning">Make Galery Preview</button> <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>!-->
@ -61,6 +63,12 @@
alert("Set as Main Image"); alert("Set as Main Image");
}); });
}); });
$("#deleteImage").click(function () {
$.ajax("/g/{{ $gallery->url }}/delete?id="+$("#edit-id").val()).done(function () {
alert("Image deleted");
});
});
</script> </script>
@endsection @endsection

View file

@ -43,6 +43,7 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function
Route::get("/g/{url}/edit", [\App\Http\Controllers\GalleryController::class, 'editGalleryView']); Route::get("/g/{url}/edit", [\App\Http\Controllers\GalleryController::class, 'editGalleryView']);
Route::post("/g/{url}/edit", [\App\Http\Controllers\GalleryController::class, 'editGallery']); Route::post("/g/{url}/edit", [\App\Http\Controllers\GalleryController::class, 'editGallery']);
Route::get("/g/{url}/setDefault", [\App\Http\Controllers\GalleryController::class, 'setDefault']); Route::get("/g/{url}/setDefault", [\App\Http\Controllers\GalleryController::class, 'setDefault']);
Route::get("/g/{url}/delete", [\App\Http\Controllers\GalleryController::class, 'deleteImage']);
}); });
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]);