move into sonardesk
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Stylist\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Settings\Services\SettingsRepository;
|
||||
use Modules\Stylist\Services\ThemeAccessibilityValidator;
|
||||
use Modules\Stylist\Services\ThemeOptimizer;
|
||||
use Modules\Stylist\Services\ThemePackageManager;
|
||||
use Modules\Stylist\Services\ThemeSettings;
|
||||
use Modules\Stylist\Theme\Loader;
|
||||
use Modules\Stylist\View\ThemeViewResolver;
|
||||
|
||||
final class ThemeManagementController extends Controller
|
||||
{
|
||||
public function activate(string $theme, Loader $loader, SettingsRepository $settings)
|
||||
{
|
||||
$item = $loader->find($theme);
|
||||
abort_unless(in_array($item->type(), ['frontend', 'backend'], true), 422, 'Only frontend and backend themes can be activated.');
|
||||
|
||||
$settings->put($item->type().'_theme', $item->key(), 'site', 'string', true);
|
||||
|
||||
return back()->with('status', $item->name().' is now the active '.$item->type().' theme.');
|
||||
}
|
||||
|
||||
public function preview(string $theme, Loader $loader, ThemeViewResolver $views)
|
||||
{
|
||||
$item = $loader->find($theme);
|
||||
|
||||
return $views->makeForTheme($item->key(), $item->entryView(), [
|
||||
'themePreview' => true,
|
||||
'previewTheme' => $item,
|
||||
]);
|
||||
}
|
||||
|
||||
public function settings(Request $request, string $theme, Loader $loader, ThemeSettings $settings)
|
||||
{
|
||||
$item = $loader->find($theme);
|
||||
$settings->save(
|
||||
$item,
|
||||
(array) $request->input('settings', []),
|
||||
(string) $request->input('variant', 'light'),
|
||||
$request->string('appearance')->toString() ?: null,
|
||||
$request->string('accent')->toString() ?: null,
|
||||
);
|
||||
|
||||
return back()->with('status', 'Theme settings saved.');
|
||||
}
|
||||
|
||||
public function install(Request $request, ThemePackageManager $packages)
|
||||
{
|
||||
$request->validate(['theme' => ['required', 'file', 'mimes:zip', 'max:51200']]);
|
||||
$theme = $packages->install($request->file('theme'));
|
||||
|
||||
return back()->with('status', $theme->name().' installed.');
|
||||
}
|
||||
|
||||
public function uninstall(string $theme, Loader $loader, ThemePackageManager $packages)
|
||||
{
|
||||
$item = $loader->find($theme);
|
||||
$packages->uninstall($item);
|
||||
|
||||
return back()->with('status', $item->name().' uninstalled.');
|
||||
}
|
||||
|
||||
public function export(string $theme, Loader $loader, ThemePackageManager $packages)
|
||||
{
|
||||
$item = $loader->find($theme);
|
||||
$path = $packages->export($item);
|
||||
|
||||
return response()->download($path)->deleteFileAfterSend();
|
||||
}
|
||||
|
||||
public function optimize(string $theme, Loader $loader, ThemeOptimizer $optimizer)
|
||||
{
|
||||
$item = $loader->find($theme);
|
||||
$result = $optimizer->optimize($item);
|
||||
|
||||
return back()->with('status', "Optimised {$result['css']} CSS, {$result['js']} JS and {$result['images']} images.");
|
||||
}
|
||||
|
||||
public function validateTheme(string $theme, Loader $loader, ThemeAccessibilityValidator $validator)
|
||||
{
|
||||
return response()->json(['issues' => $validator->validate($loader->find($theme))]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user