This commit is contained in:
Torsten 2023-11-26 17:08:22 +01:00
parent e85a45cb17
commit f3ae2ea1df
4 changed files with 147 additions and 18 deletions

View file

@ -71,15 +71,45 @@ class GalleryController extends Controller
->with("imagelist",$imagelist)
->with("tour_name",$tour_name);
}
}
/*
tour-1
2023-04-24-ref1png.jpg
*/
public function show_deleted_images($tour_id)
{
Log::info("GalleryController::show_deleted");
if(Auth::user()->role!="ADMIN") {
return redirect('/tour/index_old');
}
$imagelist_orig = Storage::disk('img_storage')->files("tour-$tour_id-DELETED");
$imagelist=[];
foreach($imagelist_orig as $image) {
$arr = explode("/", $image);
$image = end($arr);
$before = $image;
if (str_ends_with($image, "_gross.jpg")) {
$image = substr($image, 0, -10); # Remove last 10 characters
$imagenames=[$image, $image]; # filename, displayname
$imagefilename=$image.".jpg";
Log::info("Searching displayname for filenamename $imagefilename");
$row = DB::table('gallery_items')->select('displayname')->where('filename',$imagefilename)->get();
$displayname = sizeof($row) ? $row[0]->displayname : $imagefilename;
Log::info("=> $displayname");
array_push($imagelist, [$image, $displayname] );
}
}
//dd($imagelist);
$tour_name = DB::select("select name from tours where id=".$tour_id)[0]->name;
return view('tour/gallery/show_deleted')->with("tour_id",$tour_id)
->with("imagelist",$imagelist)
->with("tour_name",$tour_name);
}
/**
* Show the form for editing the specified resource.
*
@ -149,6 +179,7 @@ class GalleryController extends Controller
}
public function delete_image($tour_id, $image_name) {
Log::info("GalleryController::delete_image, tour_id=$tour_id, image_name=$image_name");
$image_name = explode(".", $image_name)[0];
$files = [$image_name . ".jpg" , $image_name . "_gross.jpg"];
$sourceDir = storage_path() . "/img_storage/tour-$tour_id";
@ -165,6 +196,23 @@ class GalleryController extends Controller
}
public function restore_image($tour_id, $image_name) {
Log::info("GalleryController::restore_image, tour_id=$tour_id, image_name=$image_name");
$image_name = explode(".", $image_name)[0];
$files = [$image_name . ".jpg" , $image_name . "_gross.jpg"];
$targetDir = storage_path() . "/img_storage/tour-$tour_id";
$sourceDir = storage_path() . "/img_storage/tour-$tour_id-DELETED";
if (!file_exists($targetDir)) {
mkdir($targetDir, 0777, true);
}
foreach($files as $file) {
rename("$sourceDir/$file", "$targetDir/$file");
}
return redirect("/tour/gallery/$tour_id/show_deleted");
}
public function name_image(Request $request, $tour_id, $image_name) {
$displayname = $request->new_image_name;
Log::info("GalleryController::name_image for tour $tour_id , image_name=$image_name, display_name=$displayname");

View file

@ -3,10 +3,8 @@
@section('content')
<div class="container text-center text-light mt-5">
<h1>{{$tour_name}}</h1>
<div class="container text-primary" style="display:flex">
<!-- <ul class="list-group offset-2 col-8" style="display:inline"> -->
<ul class="list-group offset-2 col-8" style="display:flex; flex-direction: row;">
@ -37,6 +35,8 @@
</label>
@endforeach
</ul>
</div>
<!-- Tooltip demo -->
@ -91,15 +91,6 @@
</script>
<h1 style="color:white;">Hochladen</h1>
<form style="background-color: #fff;" class="text-dark" method="post" action="/tour/gallery/{{$tour_id}}" enctype="multipart/form-data">
@csrf
@ -107,6 +98,9 @@
<input type="submit" value="Hochladen">
</form>
@if(Auth::user()->role=="ADMIN")
<a style="color:red; font-size:40px;" href="{{$tour_id}}/show_deleted">Gelöschte Bilder</a>
@endif
</div>

View file

@ -0,0 +1,85 @@
@extends('layouts.app')
@section('content')
<div class="container text-center text-light mt-5">
<h1>{{$tour_name}}</h1>
<h1 style="color:red">Gelöschte Bilder</h1>
<div class="container text-primary" style="display:flex">
<!-- <ul class="list-group offset-2 col-8" style="display:inline"> -->
<ul class="list-group offset-2 col-8" style="display:flex; flex-direction: row;">
@foreach($imagelist as $img_tpl) <!-- 0=filename, 1=displayname -->
<label style="display:flex; flex-direction: column;">
<a title="{{$img_tpl[1]}}" style="display: inline;" href="/img_storage/tour-{{$tour_id}}-DELETED/{{$img_tpl[0]}}_gross.jpg" data-lightbox="/img_storage/tour-{{$tour_id}}/{{$img_tpl[0]}}_gross.jpg" data-title="{{$img_tpl[1]}}">
<img class="mt-3 ml-3" src="/img_storage/tour-{{$tour_id}}-DELETED/{{$img_tpl[0]}}.jpg">
</a>
<div>
<a href="/tour/gallery/{{$tour_id}}/restore_image/{{$img_tpl[0]}}.jpg" style="color:red;"><span data-toggle="tooltip" title="Wiederherstellen">Wiederherstellen</a>
</div>
</label>
@endforeach
</ul>
</div>
<!-- Tooltip demo -->
<!--
<a style="color:white" href="#">
<span data-toggle="tooltip" title="tooltip for hover">Hover
</span> Rest of field
</a>
-->
<script>
// Open the Modal
function openModal() {
document.getElementById("myModal").style.display = "block";
}
// Close the Modal
function closeModal() {
document.getElementById("myModal").style.display = "none";
}
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
var captionText = document.getElementById("caption");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>
<a style="color:green; font-size:40px;" href="/tour/gallery/{{$tour_id}}">Zurück</a>
</div>
@endsection

View file

@ -68,6 +68,8 @@
Route::get('/tour/gallery/{gallery_id}/delete_image/{imageName}', 'GalleryController@delete_image');
Route::put('/tour/gallery/{gallery_id}/name_image/{imageName}', 'GalleryController@name_image');
Route::get('/tour/gallery/{gallery_id}/show_deleted', 'GalleryController@show_deleted_images');
Route::get('/tour/gallery/{gallery_id}/restore_image/{imageName}', 'GalleryController@restore_image');
Auth::routes();