This commit is contained in:
Kekskurse 2021-01-21 18:56:30 +01:00
parent ad52bb15a3
commit 24df31060e
16 changed files with 345 additions and 7 deletions

View file

@ -0,0 +1,81 @@
<?php
namespace App\Console\Commands;
use App\Models\Theme;
use Illuminate\Console\Command;
class ThemesScann extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'theme:scan';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$themesGallery = scandir(__DIR__."/../../../resources/views/themes/gallery");
foreach ($themesGallery as $theme) {
if(substr($theme, 0, 1) == ".") {
continue;
}
$themeModel = Theme::query()->where("name", "=", $theme)->where("typ", "=", "gallery")->first();
if(!is_null($themeModel)) {
continue;
}
$this->info("Found new Theme: ".$theme);
$themeModel = new Theme();
$themeModel->typ = "gallery";
$themeModel->name = $theme;
$themeModel->status = "private";
$themeModel->saveOrFail();
}
$themesGallery = scandir(__DIR__."/../../../resources/views/themes/tenant");
foreach ($themesGallery as $theme) {
$this->info("Check Theme: ".$theme);
if(substr($theme, 0, 1) == ".") {
continue;
}
$themeModel = Theme::query()->where("name", "=", $theme)->where("typ", "=", "tenant")->first();
if(!is_null($themeModel)) {
$this->info("Themes already exists: ".$theme);
continue;
}
$this->info("Found new Theme: ".$theme);
$themeModel = new Theme();
$themeModel->typ = "tenant";
$themeModel->name = $theme;
$themeModel->status = "private";
$themeModel->saveOrFail();
}
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class UserAdmin extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:admin {username}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$username = $this->argument('username');
$user = User::query()->where("username", "=", $username)->firstOrFail();
$user->typ = "admin";
$user->saveOrFail();
}
}

View file

@ -6,6 +6,8 @@ use App\Console\Commands\CalculateSpace;
use App\Console\Commands\CalculateTraffic;
use App\Console\Commands\EXIFRead;
use App\Console\Commands\ImageCacheAll;
use App\Console\Commands\ThemesScann;
use App\Console\Commands\UserAdmin;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@ -20,7 +22,9 @@ class Kernel extends ConsoleKernel
CalculateSpace::class,
CalculateTraffic::class,
ImageCacheAll::class,
EXIFRead::class
EXIFRead::class,
UserAdmin::class,
ThemesScann::class
];
/**
@ -35,6 +39,7 @@ class Kernel extends ConsoleKernel
//$schedule->command('calculate:traffic')->hourlyAt(10)->withoutOverlapping();
$schedule->command('calculate:traffic')->everyFiveMinutes()->withoutOverlapping();
$schedule->command('exit:read')->everyMinute()->withoutOverlapping();
$schedule->command('theme:scan')->everyMinute()->withoutOverlapping();
}
/**

View file

@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers;
use App\Models\Theme;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Redirect;
class AdminController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function themesView() {
$themes = Theme::query()->get();
return view("admin.themes", ["themes" => $themes]);
}
public function themesSettings(Request $request) {
$theme = Theme::query()->where("id", "=", $request->input("id"))->firstOrFail();
$theme->status = $request->input("status");
$theme->img_big = (bool)$request->input("img_big", false);
$theme->img_medium = (bool)$request->input("img_medium", false);
$theme->img_small = (bool)$request->input("img_small", false);
$theme->img_pixel = (bool)$request->input("img_pixel", false);
$theme->saveOrFail();
return Redirect::back();
}
}

View file

@ -23,7 +23,7 @@ class PublicController extends BaseController
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function listGalleriesView($name) {
public function listGalleriesView($name, Request $request) {
$tenant = Tenant::query()->where("url", "=", $name)->firstOrFail();
$galleries = Gallery::query()
->where("tenant", "=", $tenant->id)
@ -36,7 +36,12 @@ class PublicController extends BaseController
foreach ($galleries as $gallery) {
$gallery->html = $parser->parse($gallery->description);
}
return view("themes.tenant.kuvia-blog.list", ["galleries" => $galleries, "tenant" => $tenant]);
$theme = "kuvia-blog";
if($request->input("theme", false) && $tenant->owner == Auth::id()) {
$theme = $request->input("theme");
}
return view("themes.tenant.".$theme.".list", ["galleries" => $galleries, "tenant" => $tenant]);
}
public function listGalleryImagesView($tenant, $gallery) {
@ -56,7 +61,7 @@ class PublicController extends BaseController
$parser = new \Parsedown();
$gallery->html = $parser->parse($gallery->description);
return view("themes.gallery.gallery-detail.list", ["gallery" => $gallery, "tenant" => $tenant, "images" => $images]);
return view("themes.gallery.kuvia-gallery.list", ["gallery" => $gallery, "tenant" => $tenant, "images" => $images]);
}
public function returnWatermakeFile(\App\Helper\Image $imageHelper, \App\Helper\Access $accessHelper) {

View file

@ -15,7 +15,11 @@ class ReportController extends BaseController
public function showReportList()
{
$oldesDate = DB::select("SELECT `year`, `month` FROM storage WHERE tenant = " . (int)session("current_tenant_id") . " ORDER BY `date` ASC LIMIT 1;")[0];
$oldesDate = DB::select("SELECT `year`, `month` FROM storage WHERE tenant = " . (int)session("current_tenant_id") . " ORDER BY `date` ASC LIMIT 1;");
if(count($oldesDate) == 0) {
return view("dashboard.reports", ["avalibleReports" => []]);
}
$oldesDate = $oldesDate[0];
$avalibleReports = [];
for ($i = $oldesDate->year; $i <= date("Y"); $i++) {
for ($m = 1; $m <= 12; $m++) {

View file

@ -3,6 +3,7 @@
namespace App\Http\Middleware;
use App\Models\Tenant;
use App\Models\User;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
@ -26,6 +27,7 @@ class TenanMiddleware
}
view()->share('user_tenants', Tenant::getTenantPerUser(Auth::id()));
view()->share('current_tenant', Tenant::query()->where("id", "=", session("current_tenant_id"))->first());
view()->share('user', Auth::user());
}

43
app/Models/Theme.php Normal file
View file

@ -0,0 +1,43 @@
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class Theme extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'username',
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}

View file

@ -0,0 +1,59 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Themes extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table("users", function (Blueprint $table) {
$table->enum("typ", ["user", "admin"])->default("user");
});
Schema::create("themes", function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->enum("typ", ["tenant", "gallery"]);
$table->string("name");
$table->enum("status", ["public", "private"]);
$table->boolean("img_pixel")->default(false);
$table->boolean("img_small")->default(false);
$table->boolean("img_medium")->default(false);
$table->boolean("img_big")->default(false);
});
Schema::table("tenants", function (Blueprint $table) {
$table->string("gallery_default_theme")->default("default");
});
Schema::table("galleries", function (Blueprint $table) {
$table->string("theme")->nullable()->default(null);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table("users", function (Blueprint $table) {
$table->dropColumn('typ');
});
Schema::table("tenants", function (Blueprint $table) {
$table->dropColumn('gallery_default_theme');
});
Schema::table("galleries", function (Blueprint $table) {
$table->dropColumn('theme');
});
Schema::dropIfExists("themes");
}
}

View file

@ -0,0 +1,49 @@
@extends('layout/template')
@section('content')
<div class="row" style="margin-top: 20px;">
<div class="col-md-12">
<h1>Reports</h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table class="table-striped table">
<tr>
<th>Name</th>
<th>Typ</th>
<th>Status</th>
<th>Big</th>
<th>Medium</th>
<th>Small</th>
<th>Pixel</th>
<th>Save</th>
</tr>
@foreach($themes as $theme)
<form method="post" action="/a/themes?id={{ $theme->id }}">
@csrf
<tr>
<td>{{ $theme->name }}</td>
<td>{{ $theme->typ }}</td>
<td>
<select name="status" class="form-control">
<option @if ($theme->status == "private") selected @endif >Private</option>
<option @if ($theme->status == "public") selected @endif>Public</option>
</select>
</td>
<td><input type="checkbox" @if ($theme->img_big) checked @endif name="img_big"> </td>
<td><input type="checkbox" @if ($theme->img_medium) checked @endif name="img_medium"></td>
<td><input type="checkbox" @if ($theme->img_small) checked @endif name="img_small"></td>
<td><input type="checkbox" @if ($theme->img_pixel) checked @endif name="img_pixel"></td>
<td><input type="submit" class="btn btn-sm btn-outline-success" value="Save"></td>
</tr>
</form>
@endforeach
</table>
</div>
</div>
@endsection

View file

@ -5,6 +5,7 @@
<div class="row" style="margin-top: 20px;">
<div class="col-md-12">
<h1>Dashboard</h1>
<p>Hello, {{ $user->username }}</p>
<div class="alert alert-danger" role="alert">
This system is in alpha mode, if you found issue contact hello@kekskurse.de
</div>

View file

@ -32,6 +32,14 @@
@endauth
<ul class="nav navbar-nav float-md-right">
@auth
@if($user->typ == "admin")
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Admin</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="/a/themes">Themes</a>
</div>
</li>
@endif
<li class="nav-item active">
<a class="nav-link" href="/{{ $current_tenant->url }}"><i class="fas fa-external-link-alt"></i></a>
</li>

View file

@ -11,7 +11,7 @@
{{ $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">
<img class="card-img-top" src="/{{$tenant->url}}/{{$gallery->url}}/{{$gallery->main_image}}/file?size=medium" style="max-height: 400px; width: auto;max-width: 100%;" alt="Card image cap">
<p class="card-text">from {{ $gallery->gallery_create_time }}<br>{{ $gallery->description }}</p>
</div>
</div>

View file

@ -8,7 +8,7 @@
<div id="mygallery">
@foreach($galleries as $gallery)
<a href="/{{ $tenant->url }}/{{ $gallery->url }}/">
<img style="height: 200px;" alt="{{ $gallery->name }}" src="/{{ $tenant->url }}/{{ $gallery->url }}/{{ $gallery->main_image }}/file"/>
<img style="height: 200px;" alt="{{ $gallery->name }}" src="/{{ $tenant->url }}/{{ $gallery->url }}/{{ $gallery->main_image }}/file?size=medium"/>
</a>
@endforeach
</div>

View file

@ -52,6 +52,9 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function
Route::get("s/reports", [\App\Http\Controllers\ReportController::class, "showReportList"]);
Route::get("s/reports/{year}/{month}/space", [\App\Http\Controllers\ReportController::class, "spaceReport"]);
Route::get("s/reports/{year}/{month}/traffic", [\App\Http\Controllers\ReportController::class, "trafficReport"]);
Route::get("a/themes", [\App\Http\Controllers\AdminController::class, "themesView"]);
Route::post("a/themes", [\App\Http\Controllers\AdminController::class, "themesSettings"]);
});
Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);