From 24df31060e37bf6b5903dd34b0c0904818209e1c Mon Sep 17 00:00:00 2001 From: Kekskurse Date: Thu, 21 Jan 2021 18:56:30 +0100 Subject: [PATCH] Stuff --- app/Console/Commands/ThemesScann.php | 81 +++++++++++++++++++ app/Console/Commands/UserAdmin.php | 46 +++++++++++ app/Console/Kernel.php | 7 +- app/Http/Controllers/AdminController.php | 32 ++++++++ app/Http/Controllers/PublicController.php | 11 ++- app/Http/Controllers/ReportController.php | 6 +- app/Http/Middleware/TenanMiddleware.php | 2 + app/Models/Theme.php | 43 ++++++++++ .../migrations/2021_01_21_162803_themes.php | 59 ++++++++++++++ resources/views/admin/themes.blade.php | 49 +++++++++++ resources/views/dashboard/index.blade.php | 1 + resources/views/layout/template.blade.php | 8 ++ .../list.blade.php | 0 .../themes/tenant/default/list.blade.php | 2 +- .../tenant/kuvia-gallery/list.blade.php | 2 +- routes/web.php | 3 + 16 files changed, 345 insertions(+), 7 deletions(-) create mode 100644 app/Console/Commands/ThemesScann.php create mode 100644 app/Console/Commands/UserAdmin.php create mode 100644 app/Http/Controllers/AdminController.php create mode 100644 app/Models/Theme.php create mode 100644 database/migrations/2021_01_21_162803_themes.php create mode 100644 resources/views/admin/themes.blade.php rename resources/views/themes/gallery/{gallery-detail => kuvia-gallery}/list.blade.php (100%) diff --git a/app/Console/Commands/ThemesScann.php b/app/Console/Commands/ThemesScann.php new file mode 100644 index 0000000..db3e69c --- /dev/null +++ b/app/Console/Commands/ThemesScann.php @@ -0,0 +1,81 @@ +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(); + } + } +} diff --git a/app/Console/Commands/UserAdmin.php b/app/Console/Commands/UserAdmin.php new file mode 100644 index 0000000..3e98549 --- /dev/null +++ b/app/Console/Commands/UserAdmin.php @@ -0,0 +1,46 @@ +argument('username'); + $user = User::query()->where("username", "=", $username)->firstOrFail(); + $user->typ = "admin"; + $user->saveOrFail(); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index bb6a65e..1cacf04 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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(); } /** diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php new file mode 100644 index 0000000..f18ac13 --- /dev/null +++ b/app/Http/Controllers/AdminController.php @@ -0,0 +1,32 @@ +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(); + + } +} diff --git a/app/Http/Controllers/PublicController.php b/app/Http/Controllers/PublicController.php index c7df2c9..f26e72f 100644 --- a/app/Http/Controllers/PublicController.php +++ b/app/Http/Controllers/PublicController.php @@ -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) { diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 15f6b42..14b39ef 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -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++) { diff --git a/app/Http/Middleware/TenanMiddleware.php b/app/Http/Middleware/TenanMiddleware.php index 75fef62..d7b7cf5 100644 --- a/app/Http/Middleware/TenanMiddleware.php +++ b/app/Http/Middleware/TenanMiddleware.php @@ -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()); } diff --git a/app/Models/Theme.php b/app/Models/Theme.php new file mode 100644 index 0000000..8895444 --- /dev/null +++ b/app/Models/Theme.php @@ -0,0 +1,43 @@ + 'datetime', + ]; +} diff --git a/database/migrations/2021_01_21_162803_themes.php b/database/migrations/2021_01_21_162803_themes.php new file mode 100644 index 0000000..99b34e4 --- /dev/null +++ b/database/migrations/2021_01_21_162803_themes.php @@ -0,0 +1,59 @@ +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"); + } +} diff --git a/resources/views/admin/themes.blade.php b/resources/views/admin/themes.blade.php new file mode 100644 index 0000000..59da158 --- /dev/null +++ b/resources/views/admin/themes.blade.php @@ -0,0 +1,49 @@ +@extends('layout/template') + +@section('content') + +
+
+

Reports

+
+
+
+
+ + + + + + + + + + + + @foreach($themes as $theme) + + @csrf + + + + + + + + + + + + @endforeach +
NameTypStatusBigMediumSmallPixelSave
{{ $theme->name }}{{ $theme->typ }} + + img_big) checked @endif name="img_big"> img_medium) checked @endif name="img_medium">img_small) checked @endif name="img_small">img_pixel) checked @endif name="img_pixel">
+
+
+ + + +@endsection diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 87c158d..d5d6daf 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -5,6 +5,7 @@

Dashboard

+

Hello, {{ $user->username }}

diff --git a/resources/views/layout/template.blade.php b/resources/views/layout/template.blade.php index 662b206..87e272a 100644 --- a/resources/views/layout/template.blade.php +++ b/resources/views/layout/template.blade.php @@ -32,6 +32,14 @@ @endauth
- Card image cap + Card image cap

from {{ $gallery->gallery_create_time }}
{{ $gallery->description }}

diff --git a/resources/views/themes/tenant/kuvia-gallery/list.blade.php b/resources/views/themes/tenant/kuvia-gallery/list.blade.php index 86f5cf4..1d5afdd 100644 --- a/resources/views/themes/tenant/kuvia-gallery/list.blade.php +++ b/resources/views/themes/tenant/kuvia-gallery/list.blade.php @@ -8,7 +8,7 @@
@foreach($galleries as $gallery) - {{ $gallery->name }} + {{ $gallery->name }} @endforeach
diff --git a/routes/web.php b/routes/web.php index 4246855..880618e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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]);