From 0b857a477406ade689cf6bbeb2c7a12e38ee0efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Tue, 5 Dec 2023 16:20:31 +0300 Subject: [PATCH] Widget styling re-factor.. --- app/Abstracts/Widget.php | 2 +- app/Listeners/Update/V31/Version315.php | 80 +++++++++++++++++++ app/Models/Common/Widget.php | 57 +++++++++++++ app/Widgets/CashFlow.php | 2 +- public/css/app.css | 6 ++ .../assets/js/components/AkauntingWidget.vue | 8 +- .../assets/js/views/common/dashboards.js | 2 +- .../views/common/dashboards/show.blade.php | 2 +- .../views/components/widgets/header.blade.php | 12 +-- resources/views/widgets/cash_flow.blade.php | 2 +- safelist.txt | 8 +- 11 files changed, 165 insertions(+), 16 deletions(-) create mode 100644 app/Listeners/Update/V31/Version315.php diff --git a/app/Abstracts/Widget.php b/app/Abstracts/Widget.php index 59470a357f7..32d03248b05 100644 --- a/app/Abstracts/Widget.php +++ b/app/Abstracts/Widget.php @@ -17,7 +17,7 @@ abstract class Widget public $default_name = ''; public $default_settings = [ - 'width' => 'w-full lg:w-2/4 lg:px-6 my-8', + 'width' => '50', ]; public $description = ''; diff --git a/app/Listeners/Update/V31/Version315.php b/app/Listeners/Update/V31/Version315.php new file mode 100644 index 00000000000..f00a9a100ba --- /dev/null +++ b/app/Listeners/Update/V31/Version315.php @@ -0,0 +1,80 @@ +skipThisUpdate($event)) { + return; + } + + Log::channel('stdout')->info('Updating to 3.1.5 version...'); + + $this->updateWidgets(); + + Log::channel('stdout')->info('Done!'); + } + + public function updateWidgets() + { + Log::channel('stdout')->info('Updating widgets...'); + + $widgets = Widget::cursor(); + + foreach ($widgets as $widget) { + Log::channel('stdout')->info('Updating widget:' . $widget->id); + + $widget_settings = $widget->settings; + + if (empty($widget_settings->width)) { + Log::channel('stdout')->info('Skip widget:' . $widget->id); + + continue; + } + + if (! empty($widget_settings->raw_width)) { + Log::channel('stdout')->info('Already new classs widget:' . $widget->id); + + continue; + } + + unset($widget_settings->raw_width); + + if (Str::contains($widget_settings->width, 'lg:w-1/4')) { + $widget_settings->width = 25; + } elseif (Str::contains($widget_settings->width, 'lg:w-1/3')) { + $widget_settings->width = 33; + } elseif (Str::contains($widget_settings->width, 'lg:w-2/4')) { + $widget_settings->width = 50; + } else { + $widget_settings->width = 100; + } + + $widget->settings = $widget_settings; + + $widget->save(); + + Log::channel('stdout')->info('Widget updated:' . $widget->id); + } + + Log::channel('stdout')->info('Widgets updated.'); + } +} diff --git a/app/Models/Common/Widget.php b/app/Models/Common/Widget.php index 7472c0061f1..2ce313e21ed 100644 --- a/app/Models/Common/Widget.php +++ b/app/Models/Common/Widget.php @@ -70,6 +70,63 @@ public function getAliasAttribute() return Str::kebab($arr[1]); } + /** + * Get the alias based on class. + * + * @return object + */ + public function getSettingsAttribute($value) + { + $settings = ! empty($value) ? json_decode($value) : (object) []; + + $settings->raw_width = false; + + if (isset($settings->width)) { + + $raw_width = $settings->width; + $width = $this->getWidthAttribute($settings->width); + + if ($raw_width != $width) { + $settings->raw_width = $raw_width; + } + + $settings->width = $width; + } + + return $settings; + } + + /** + * Get the alias based on class. + * + * @return string + */ + public function getWidthAttribute($value) + { + $width = $value; + + switch ($width) { + case '25': + $width = 'w-full lg:w-1/4 lg:px-6'; + break; + case '33': + $width = 'w-full lg:w-1/3 px-6'; + break; + case '50': + $width = 'w-full lg:w-2/4 lg:px-6'; + break; + case '100': + $width = 'w-full px-6'; + break; + } + + if (empty($width)) { + $width = 'w-full lg:w-2/4 lg:px-6'; + } + + return $width; + } + /** * Create a new factory instance for the model. * diff --git a/app/Widgets/CashFlow.php b/app/Widgets/CashFlow.php index 8d5684dad34..3eaa33fbe8c 100644 --- a/app/Widgets/CashFlow.php +++ b/app/Widgets/CashFlow.php @@ -17,7 +17,7 @@ class CashFlow extends Widget public $default_name = 'widgets.cash_flow'; public $default_settings = [ - 'width' => 'w-full my-8 lg:px-6', + 'width' => '100', ]; public $description = 'widgets.description.cash_flow'; diff --git a/public/css/app.css b/public/css/app.css index 16187fb383c..0d407f45e1a 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -70145,6 +70145,12 @@ body{ align-items: center; } + .lg\:justify-start{ + -webkit-box-pack: start; + -ms-flex-pack: start; + justify-content: flex-start; + } + .lg\:justify-end{ -webkit-box-pack: end; -ms-flex-pack: end; diff --git a/resources/assets/js/components/AkauntingWidget.vue b/resources/assets/js/components/AkauntingWidget.vue index 44be2fdfd25..9d060030499 100644 --- a/resources/assets/js/components/AkauntingWidget.vue +++ b/resources/assets/js/components/AkauntingWidget.vue @@ -165,19 +165,19 @@ export default { widthOptions: [ { label: '25%', - value: 'w-full lg:w-1/4 lg:px-6' + value: '25' }, { label: '33%', - value: 'w-full lg:w-1/3 lg:px-6' + value: '33' }, { label: '50%', - value: 'w-full lg:w-2/4 lg:px-6' + value: '50' }, { label: '100%', - value: 'w-full lg:px-6' + value: '100' } ], form: { diff --git a/resources/assets/js/views/common/dashboards.js b/resources/assets/js/views/common/dashboards.js index 0eb4b69505b..79090060a57 100644 --- a/resources/assets/js/views/common/dashboards.js +++ b/resources/assets/js/views/common/dashboards.js @@ -96,7 +96,7 @@ const dashboard = new Vue({ self.widget.id = widget_id; self.widget.name = response.data.name; self.widget.class = response.data.class; - self.widget.width = response.data.settings.width; + self.widget.width = (response.data.settings.raw_width) ? response.data.settings.raw_width : response.data.settings.width; self.widget.action = 'edit'; self.widget.sort = response.data.sort; diff --git a/resources/views/common/dashboards/show.blade.php b/resources/views/common/dashboards/show.blade.php index 9789d9cd9dd..887db3d4da1 100644 --- a/resources/views/common/dashboards/show.blade.php +++ b/resources/views/common/dashboards/show.blade.php @@ -128,7 +128,7 @@ class="w-full h-full flex items-center rounded-md px-2 text-sm hover:bg-lilac-10 @if ($report = $class->getReportUrl()) - @if (1) + @if ($class->model?->settings?->raw_width == '25' || $class->model?->settings?->width == 'w-full lg:w-1/4 lg:px-6') @else - - - {{ trans('widgets.view_report') }} - - + + + {{ trans('widgets.view_report') }} + + @endif @endif diff --git a/resources/views/widgets/cash_flow.blade.php b/resources/views/widgets/cash_flow.blade.php index 7a4e88c1215..cee46af15e2 100644 --- a/resources/views/widgets/cash_flow.blade.php +++ b/resources/views/widgets/cash_flow.blade.php @@ -1,4 +1,4 @@ -
+
@include($class->views['header'], ['header_class' => ''])
diff --git a/safelist.txt b/safelist.txt index a32f6f4d456..ccf0776cc58 100644 --- a/safelist.txt +++ b/safelist.txt @@ -100,4 +100,10 @@ ltr:float-left rtl:float-right rtl:float-left rtl:rotate-180 -hover:bg-purple-200 \ No newline at end of file +hover:bg-purple-200 +lg:w-1/4 +lg:px-6 +lg:w-1/3 +px-6 +lg:w-2/4 +lg:px-6 \ No newline at end of file