From 430963064edccf9028ac5cd6a0fedc742becc0fb Mon Sep 17 00:00:00 2001 From: Mosen Date: Tue, 16 Jan 2024 14:12:24 +1100 Subject: [PATCH] Swap comment widget into blade component, remove comment JS from common clients/detail layout. Swap calls to conf() with config() where possible. Remove unused head js in 426 error page. Update CHANGELOG --- CHANGELOG.md | 1 + .../Components/Widget/Detail/Comments.php | 36 +++++++++++++++++++ app/lib/munkireport/Modules.php | 16 ++++++--- app/lib/munkireport/Widgets.php | 7 +++- resources/views/clients/detail.blade.php | 2 -- .../widget/detail/comments.blade.php | 20 +++++++++++ resources/views/errors/426.blade.php | 4 --- 7 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 app/View/Components/Widget/Detail/Comments.php create mode 100644 resources/views/components/widget/detail/comments.blade.php diff --git a/CHANGELOG.md b/CHANGELOG.md index a74be7a4c..a21a8bb58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Composer 2.2.x now required - Blade Component Dashboards now default layout type, old style dashboard.php view has a warning applied. - Jetstream views are used instead of custom ones for user profile editing and password update. +- Client Summary Widgets are partially converted to use blade components. ### [6.0.0-beta.3](https://github.com/munkireport/munkireport-php/compare/v6.0.0-beta.3...wip) (Unreleased) diff --git a/app/View/Components/Widget/Detail/Comments.php b/app/View/Components/Widget/Detail/Comments.php new file mode 100644 index 000000000..65417e641 --- /dev/null +++ b/app/View/Components/Widget/Detail/Comments.php @@ -0,0 +1,36 @@ +name = $name; + $this->data = $data; + } + + /** + * Get the view / contents that represent the component. + */ + public function render(): View|Closure|string + { + return view('components.widget.detail.comments', $this->data); + } +} diff --git a/app/lib/munkireport/Modules.php b/app/lib/munkireport/Modules.php index e0f7d6b33..850bb0cd5 100644 --- a/app/lib/munkireport/Modules.php +++ b/app/lib/munkireport/Modules.php @@ -50,7 +50,7 @@ class Modules public function __construct() { // Populate allowedModules if hide_inactive_modules is true - if(conf('hide_inactive_modules')){ + if(config('_munkireport.hide_inactive_modules', false)){ $this->skipInactiveModules = True; } @@ -60,9 +60,9 @@ public function __construct() $moduleSearchPaths = conf('module_search_paths'); } // And then local modules - $moduleSearchPaths[] = conf('local') . 'modules/'; + $moduleSearchPaths[] = config('_munkireport.local') . 'modules/'; // And then built-in modules - $moduleSearchPaths[] = conf('module_path'); + $moduleSearchPaths[] = config('_munkireport.module_path'); foreach ($moduleSearchPaths as $path) { if(is_dir($path)){ @@ -148,7 +148,14 @@ protected function addCoreModules(): void $this->moduleList['comment'] = [ 'detail_widgets' => [ - 'comment_detail' => [ 'view' => 'comment_detail_widget'], + 'comment_detail' => [ + 'version' => 6, + 'component' => 'widget.detail.comments', +// 'view' => 'comment_detail_widget', + 'id' => 'comment-widget', + 'icon' => 'comment-o', + 'i18n_title' => 'client.comment' + ] ], 'path' => realpath(__DIR__ . '../'), 'core' => true, @@ -275,6 +282,7 @@ public function getModuleList(bool $all_modules = false): array * Load Module info * * Load info from provides.php + * - v6.0.0: Added loading from module cache to speed up page loads. * * @param boolean $allModules If true, don't mind $skipInactiveModules */ diff --git a/app/lib/munkireport/Widgets.php b/app/lib/munkireport/Widgets.php index a3f999eb5..4d2d44d2e 100644 --- a/app/lib/munkireport/Widgets.php +++ b/app/lib/munkireport/Widgets.php @@ -97,6 +97,8 @@ public function get($widgetName, $data = []) * The output array is mapped into the same format as a dashboard widget so that all widget data * appears the same, even though client detail widgets are declared using a totally different structure in v5. * + * In v6, the `view` key is not required (supply one of `view` or `component`+`version`+`module`) + * * @param array $data Widget data, including the widget name. * @param string|null $name Optional name to override the widget to render. * @return array Widget info which will be used to render the widget. @@ -107,7 +109,10 @@ public function getDetail(array $data, ?string $name = null): array 'widget' => $data['widget'] ?? $name, 'vars' => $data['view_vars'] ?? [], 'path' => $data['view_path'], - 'file' => $data['view'], + 'file' => $data['view'] ?? null, + 'version' => $data['version'] ?? 5, + 'module' => $data['module'] ?? null, + 'component' => $data['component'] ?? null, ]; // $view = $data['view']; diff --git a/resources/views/clients/detail.blade.php b/resources/views/clients/detail.blade.php index 040567d7b..edea04aec 100644 --- a/resources/views/clients/detail.blade.php +++ b/resources/views/clients/detail.blade.php @@ -11,8 +11,6 @@ {{-- - - @endpush @section('content') diff --git a/resources/views/components/widget/detail/comments.blade.php b/resources/views/components/widget/detail/comments.blade.php new file mode 100644 index 000000000..d96f2581f --- /dev/null +++ b/resources/views/components/widget/detail/comments.blade.php @@ -0,0 +1,20 @@ +
+

+ @isset($icon) + + @endisset + +

+
+
+ + +@push('scripts') + + +@endpush diff --git a/resources/views/errors/426.blade.php b/resources/views/errors/426.blade.php index 40305dc03..4e66be42d 100644 --- a/resources/views/errors/426.blade.php +++ b/resources/views/errors/426.blade.php @@ -1,16 +1,12 @@ @extends('layouts.blank') @push('stylesheets') - @endpush @push('scripts') - - - @endpush @section('content')