This commit is contained in:
Kekskurse 2021-01-19 23:30:21 +01:00
parent 9082b89b76
commit ebc4629c91
4 changed files with 117 additions and 8 deletions

View file

@ -14,6 +14,7 @@ use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController; use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\Rule;
class GalleryController extends BaseController class GalleryController extends BaseController
{ {
@ -22,12 +23,21 @@ class GalleryController extends BaseController
public function listView() { public function listView() {
$galleries = Gallery::query()->where("tenant", "=", session("current_tenant_id"))->orderByDesc("gallery_create_time")->orderByDesc("id")->get(); $galleries = Gallery::query()->where("tenant", "=", session("current_tenant_id"))->orderByDesc("gallery_create_time")->orderByDesc("id")->get();
$tenant = Tenant::query()->where("id", "=", session("current_tenant_id"))->firstOrFail(); $tenant = Tenant::query()->where("id", "=", session("current_tenant_id"))->firstOrFail();
return view("gallery.index", ["galleries" => $galleries, "tenant" => $tenant]); return view("gallery.index", [ "galleries" => $galleries, "tenant" => $tenant]);
} }
public function newView() { public function newView(Request $request) {
$gallery = new Gallery(); $gallery = new Gallery();
return view("gallery.new", ["gallery" => $gallery]); $status = "preview";
if(!empty($request->old("status"))) {
$status = $request->old("status");
}
$listed = true;
if(!empty($request->old("listed"))) {
$listed = $request->old("listed");
}
$tags = "";
return view("gallery.new", ["gallery" => $gallery, "tags" => $tags, "status" => $status, "listed" => $listed]);
} }
public function newGallery(Request $request) { public function newGallery(Request $request) {
@ -36,8 +46,19 @@ class GalleryController extends BaseController
'description' => 'max:15000000', 'description' => 'max:15000000',
'url' => [new urlOrNull()], 'url' => [new urlOrNull()],
'date' => [new dateOrNull()], 'date' => [new dateOrNull()],
'status' => ['required', Rule::in(['preview', 'online', 'archiv'])],
'listed' => '',
'tags' => ''
]); ]);
if(!array_key_exists("listed", $validated)) {
$validated["listed"] = false;
}
if(strtolower($validated["listed"]) == "off") {
$validated["listed"] = false;
}
$validated["listed"] = (bool)$validated["listed"];
//Check if Gallery Date is in the feature //Check if Gallery Date is in the feature
if(!empty($validated["date"])) { if(!empty($validated["date"])) {
$t = new \DateTime($validated["date"]); $t = new \DateTime($validated["date"]);
@ -88,6 +109,9 @@ class GalleryController extends BaseController
$gallery->url = $newUrl; $gallery->url = $newUrl;
$gallery->description = $validated["description"]; $gallery->description = $validated["description"];
$gallery->tenant = session("current_tenant_id"); $gallery->tenant = session("current_tenant_id");
$gallery->status = $validated["status"];
$gallery->listed = $validated["listed"];
$gallery->tags = json_encode(mb_split(",", $validated["tags"]));
if(!empty($validated["date"])) { if(!empty($validated["date"])) {
$gallery->gallery_create_time = $validated["date"]; $gallery->gallery_create_time = $validated["date"];
} else { } else {
@ -102,7 +126,21 @@ 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);
return view("gallery.new", ["gallery" => $gallery]); $status = $gallery->status;
if(!empty($request->old("status"))) {
$status = $request->old("status");
}
$listed = $gallery->listed;
if(!empty($request->old("listed"))) {
$listed = $request->old("listed");
}
$tagsArray = json_decode($gallery->tags);
$tags = "";
if(is_array($tagsArray)) {
$tags = implode(",", $tagsArray);
}
return view("gallery.new", ["gallery" => $gallery, "tags" => $tags, "status" => $status, "listed" => $listed]);
} }
public function editGallery($name, Request $request) { public function editGallery($name, Request $request) {
@ -111,13 +149,27 @@ class GalleryController extends BaseController
'description' => 'max:15000000', 'description' => 'max:15000000',
'url' => 'required|regex:/^[a-z0-9\-]{8,30}$/i', 'url' => 'required|regex:/^[a-z0-9\-]{8,30}$/i',
'date' => 'required|regex:/^\d{4}-\d{2}-\d{2}$/i', 'date' => 'required|regex:/^\d{4}-\d{2}-\d{2}$/i',
'status' => ['required', Rule::in(['preview', 'online', 'archiv'])],
'listed' => '',
'tags' => ''
]); ]);
if(!array_key_exists("listed", $validated)) {
$validated["listed"] = false;
}
if(strtolower($validated["listed"]) == "off") {
$validated["listed"] = false;
}
$validated["listed"] = (bool)$validated["listed"];
$gallery = Gallery::getByTenantAndUrl(session("current_tenant_id"), $name); $gallery = Gallery::getByTenantAndUrl(session("current_tenant_id"), $name);
$gallery->name = $validated["name"]; $gallery->name = $validated["name"];
$gallery->description = $validated["description"]; $gallery->description = $validated["description"];
$gallery->url = $validated["url"]; $gallery->url = $validated["url"];
$gallery->gallery_create_time = $validated["date"]; $gallery->gallery_create_time = $validated["date"];
$gallery->status = $validated["status"];
$gallery->listed = $validated["listed"];
$gallery->tags = json_encode(mb_split(",", $validated["tags"]));
$gallery->saveOrFail(); $gallery->saveOrFail();

View file

@ -27,7 +27,13 @@ class PublicController extends BaseController
public function listGalleriesView($name) { public function listGalleriesView($name) {
$tenant = Tenant::query()->where("url", "=", $name)->firstOrFail(); $tenant = Tenant::query()->where("url", "=", $name)->firstOrFail();
$galleries = Gallery::query()->where("tenant", "=", $tenant->id)->orderByDesc("gallery_create_time")->orderByDesc("created_at")->get(); $galleries = Gallery::query()
->where("tenant", "=", $tenant->id)
->where("status", "=", "online")
->where("listed", "=", 1)
->orderByDesc("gallery_create_time")
->orderByDesc("created_at")
->get();
$parser = new \Parsedown(); $parser = new \Parsedown();
foreach ($galleries as $gallery) { foreach ($galleries as $gallery) {
$gallery->html = $parser->parse($gallery->description); $gallery->html = $parser->parse($gallery->description);

View file

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class GalleryMetaInfos extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table("galleries", function (Blueprint $table) {
$table->enum("status", ["preview", "online", "deleted", "archiv"])->default("online");
$table->boolean("listed")->default(true)->comment("Listet on the Tenant Page");
$table->mediumText("tags")->nullable()->default(null);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View file

@ -42,13 +42,31 @@
</div> </div>
<input type="submit" class="btn btn-outline-success" value="Save" style="margin-top: 10px;"> <input type="submit" class="btn btn-outline-success" value="Save" style="margin-top: 10px;">
</form>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<div class="custom-control custom-switch"> <div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" disabled value="on" id="customSwitch1" checked=""> <b>Status</b>
<label class="custom-control-label" disabled="disabled" for="customSwitch1">Publish</label> <select name="status" class="custom-select" id="exampleSelect2"">
<option @if ($status == "preview") selected @endif value="preview">Preview</option>
<option @if ($status == "online") selected @endif value="online">Online</option>
<option @if ($status == "archiv") selected @endif value="archiv">Archiv</option>
<option @if ($status == "deleted") selected @endif value="deleted" disabled>Deleted</option>
</select>
<div class="custom-control custom-switch" style="margin-top: 10px;">
<input type="checkbox" class="custom-control-input" name="listed" id="customSwitch1" @if ($listed) checked @endif>
<label class="custom-control-label" for="customSwitch1">Toggle this switch element</label>
</div>
<div style="margin-top: 20px;border-top: 1px solid grey;padding-top: 10px;">
<b>Tags (sperate by comma)</b>
<textarea class="form-control" name="tags" rows="3" placeholder="Tags">{{ old('tags') ?? $tags }}</textarea>
</div>
<div style="margin-top: 10px;">
<a href="/{{ $current_tenant->url }}/{{ $gallery->url }}/" class="btn btn-outline-primary" style="width: 100%">View Gallery</a>
</div>
</div> </div>
</div> </div>
</form>
</div> </div>
@endsection @endsection