diff --git a/publishable/assets/css/voyager.css b/publishable/assets/css/voyager.css index 9533f94cbc..f61173efb6 100644 --- a/publishable/assets/css/voyager.css +++ b/publishable/assets/css/voyager.css @@ -1414,4 +1414,17 @@ ul.checkbox label { .show-res{ margin-left: 5px; margin-top: 15px; +} + +.alerts { + padding: 10px 10px 0px 10px; +} + +.alerts .alert { + margin-right: 15px; +} + +.alerts .alert>p, +.alerts .alert>ul { + margin-top: 0; } \ No newline at end of file diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index a465379fdc..9e510eac13 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -6,6 +6,15 @@ @section('content')
+
+ @foreach ($alerts as $alert) +
+ @foreach($alert->components as $component) + render(); ?> + @endforeach +
+ @endforeach +
getTable())) { ?>
diff --git a/src/Alert.php b/src/Alert.php new file mode 100644 index 0000000000..9eadd107f1 --- /dev/null +++ b/src/Alert.php @@ -0,0 +1,41 @@ +name = $name; + $this->type = $type; + } + + public function addComponent(ComponentInterface $component) + { + $this->components[] = $component; + + return $this; + } + + public function __get($name) + { + return $this->$name; + } + + public function __call($name, $arguments) + { + $component = app('voyager.alert.components.'.$name, ['alert' => $this]) + ->setAlert($this); + + call_user_func_array([$component, 'create'], $arguments); + + return $this->addComponent($component); + } +} diff --git a/src/Alert/Components/AbstractComponent.php b/src/Alert/Components/AbstractComponent.php new file mode 100644 index 0000000000..ca4a631960 --- /dev/null +++ b/src/Alert/Components/AbstractComponent.php @@ -0,0 +1,22 @@ +alert = $alert; + + return $this; + } + + public function __call($name, $arguments) + { + return call_user_func_array([$this->alert, $name], $arguments); + } +} \ No newline at end of file diff --git a/src/Alert/Components/ButtonComponent.php b/src/Alert/Components/ButtonComponent.php new file mode 100644 index 0000000000..bc7a133897 --- /dev/null +++ b/src/Alert/Components/ButtonComponent.php @@ -0,0 +1,22 @@ +text = $text; + $this->link = $link; + $this->style = $style; + } + + public function render() + { + return "{$this->text}"; + } +} \ No newline at end of file diff --git a/src/Alert/Components/ComponentInterface.php b/src/Alert/Components/ComponentInterface.php new file mode 100644 index 0000000000..4f886b6e03 --- /dev/null +++ b/src/Alert/Components/ComponentInterface.php @@ -0,0 +1,8 @@ +text = $text; + } + + public function render() + { + return "

{$this->text}

"; + } +} \ No newline at end of file diff --git a/src/Alert/Components/TitleComponent.php b/src/Alert/Components/TitleComponent.php new file mode 100644 index 0000000000..472db9a059 --- /dev/null +++ b/src/Alert/Components/TitleComponent.php @@ -0,0 +1,18 @@ +title = $title; + } + + public function render() + { + return "{$this->title}"; + } +} \ No newline at end of file diff --git a/src/Voyager.php b/src/Voyager.php index 3d781f89b7..5041fb1e4b 100644 --- a/src/Voyager.php +++ b/src/Voyager.php @@ -17,6 +17,8 @@ class Voyager protected $version; protected $filesystem; + protected $alerts = []; + public function __construct() { $this->filesystem = app(Filesystem::class); @@ -78,6 +80,16 @@ public function getVersion() return $this->version; } + public function addAlert(Alert $alert) + { + $this->alerts[] = $alert; + } + + public function alerts() + { + return $this->alerts; + } + protected function findVersion() { if (!is_null($this->version)) { diff --git a/src/VoyagerServiceProvider.php b/src/VoyagerServiceProvider.php index 1e917b5056..76d3d2d332 100644 --- a/src/VoyagerServiceProvider.php +++ b/src/VoyagerServiceProvider.php @@ -5,6 +5,7 @@ use Illuminate\Foundation\AliasLoader; use Illuminate\Routing\Router; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Facades\View; use Intervention\Image\ImageServiceProvider; use TCG\Voyager\Facades\Voyager as VoyagerFacade; use TCG\Voyager\Http\Middleware\VoyagerAdminMiddleware; @@ -28,6 +29,9 @@ public function register() return new Voyager(); }); + $this->registerViewComposers(); + $this->registerAlertComponents(); + if ($this->app->runningInConsole()) { $this->registerPublishableResources(); $this->registerConsoleCommands(); @@ -57,6 +61,48 @@ public function boot(Router $router) $this->loadViewsFrom(__DIR__.'/../resources/views', 'voyager'); $router->middleware('admin.user', VoyagerAdminMiddleware::class); + + $this->addStorageSymlinkAlert(); + } + + /** + * Register view composers. + */ + protected function registerViewComposers() + { + // Register alerts + View::composer('voyager::index', function ($view) { + $view->with('alerts', VoyagerFacade::alerts()); + }); + } + + /** + * Add storage symlink alert. + */ + protected function addStorageSymlinkAlert() + { + if (!is_link(public_path('storage-off'))) { + $alert = (new Alert('missing-storage-symlink', 'warning')) + ->title('Missing storage symlink') + ->text('We could not find a storage symlink. This could cause problems with loading media files from the browser.') + ->button('Fix it', '?fix-missing-storage-symlink'); + + VoyagerFacade::addAlert($alert); + } + } + + /** + * Register alert components. + */ + protected function registerAlertComponents() + { + $components = ['title', 'text', 'button']; + + foreach ($components as $component) { + $class = 'TCG\\Voyager\\Alert\\Components\\'.ucfirst(camel_case($component)).'Component'; + + $this->app->bind("voyager.alert.components.{$component}", $class); + } } /**