From 0430dc5f36b8e810c18f741f9458bc75bf56a66a Mon Sep 17 00:00:00 2001 From: denisdulici Date: Thu, 16 Jan 2020 00:42:20 +0300 Subject: [PATCH] updated widgets --- app/Abstracts/Widget.php | 27 +++++++++++++++---- app/Widgets/AccountBalance.php | 12 +-------- app/Widgets/CashFlow.php | 14 +++------- app/Widgets/ExpensesByCategory.php | 14 +++------- app/Widgets/IncomeByCategory.php | 14 +++------- app/Widgets/LatestExpenses.php | 12 +-------- app/Widgets/LatestIncome.php | 12 +-------- app/Widgets/TotalExpenses.php | 14 +++------- app/Widgets/TotalIncome.php | 14 +++------- app/Widgets/TotalProfit.php | 14 +++------- .../widgets/standard_header.blade.php | 6 ++--- .../partials/widgets/stats_header.blade.php | 4 +-- .../views/widgets/account_balance.blade.php | 4 +-- resources/views/widgets/donut_chart.blade.php | 10 +++---- .../views/widgets/latest_expenses.blade.php | 4 +-- .../views/widgets/latest_income.blade.php | 4 +-- resources/views/widgets/line_chart.blade.php | 10 +++---- .../views/widgets/total_expenses.blade.php | 6 ++--- .../views/widgets/total_income.blade.php | 6 ++--- .../views/widgets/total_profit.blade.php | 6 ++--- 20 files changed, 79 insertions(+), 128 deletions(-) diff --git a/app/Abstracts/Widget.php b/app/Abstracts/Widget.php index abe69783b..ac7a4e766 100644 --- a/app/Abstracts/Widget.php +++ b/app/Abstracts/Widget.php @@ -2,7 +2,6 @@ namespace App\Abstracts; -use App\Models\Sale\Invoice; use App\Traits\Charts; use Date; @@ -12,21 +11,39 @@ abstract class Widget public $model; + public $default_name = ''; + + public $default_settings = [ + 'width' => 'col-md-4', + ]; + + public $views = [ + 'header' => 'partials.widgets.standard_header', + ]; + public function __construct($model = null) { $this->model = $model; } + public function getDefaultName() + { + return trans($this->default_name); + } + public function getDefaultSettings() { - return [ - 'width' => 'col-md-4', - ]; + return $this->default_settings; + } + + public function getViews() + { + return $this->views; } public function view($name, $data = []) { - return view($name, array_merge(['model' => $this->model], (array) $data)); + return view($name, array_merge(['class' => $this], (array) $data)); } public function applyFilters($model, $args = ['date_field' => 'paid_at']) diff --git a/app/Widgets/AccountBalance.php b/app/Widgets/AccountBalance.php index 41a6978bb..5318d18aa 100644 --- a/app/Widgets/AccountBalance.php +++ b/app/Widgets/AccountBalance.php @@ -7,17 +7,7 @@ use App\Models\Banking\Account; class AccountBalance extends Widget { - public function getDefaultName() - { - return trans('widgets.account_balance'); - } - - public function getDefaultSettings() - { - return [ - 'width' => 'col-md-4', - ]; - } + public $default_name = 'widgets.account_balance'; public function show() { diff --git a/app/Widgets/CashFlow.php b/app/Widgets/CashFlow.php index 612b11a9f..fbc9b5ece 100644 --- a/app/Widgets/CashFlow.php +++ b/app/Widgets/CashFlow.php @@ -13,17 +13,11 @@ class CashFlow extends Widget { use Currencies, DateTime; - public function getDefaultName() - { - return trans('widgets.cash_flow'); - } + public $default_name = 'widgets.cash_flow'; - public function getDefaultSettings() - { - return [ - 'width' => 'col-md-12', - ]; - } + public $default_settings = [ + 'width' => 'col-md-12', + ]; public function show() { diff --git a/app/Widgets/ExpensesByCategory.php b/app/Widgets/ExpensesByCategory.php index 76d916a77..f131d67db 100644 --- a/app/Widgets/ExpensesByCategory.php +++ b/app/Widgets/ExpensesByCategory.php @@ -7,17 +7,11 @@ use App\Models\Setting\Category; class ExpensesByCategory extends Widget { - public function getDefaultName() - { - return trans('widgets.expenses_by_category'); - } + public $default_name = 'widgets.expenses_by_category'; - public function getDefaultSettings() - { - return [ - 'width' => 'col-md-6', - ]; - } + public $default_settings = [ + 'width' => 'col-md-6', + ]; public function show() { diff --git a/app/Widgets/IncomeByCategory.php b/app/Widgets/IncomeByCategory.php index 23952184d..1d0dbf43d 100644 --- a/app/Widgets/IncomeByCategory.php +++ b/app/Widgets/IncomeByCategory.php @@ -7,17 +7,11 @@ use App\Models\Setting\Category; class IncomeByCategory extends Widget { - public function getDefaultName() - { - return trans('widgets.income_by_category'); - } + public $default_name = 'widgets.income_by_category'; - public function getDefaultSettings() - { - return [ - 'width' => 'col-md-6', - ]; - } + public $default_settings = [ + 'width' => 'col-md-6', + ]; public function show() { diff --git a/app/Widgets/LatestExpenses.php b/app/Widgets/LatestExpenses.php index 6a48391e5..ffdfb521e 100644 --- a/app/Widgets/LatestExpenses.php +++ b/app/Widgets/LatestExpenses.php @@ -7,17 +7,7 @@ use App\Models\Banking\Transaction; class LatestExpenses extends Widget { - public function getDefaultName() - { - return trans('widgets.latest_expenses'); - } - - public function getDefaultSettings() - { - return [ - 'width' => 'col-md-4', - ]; - } + public $default_name = 'widgets.latest_expenses'; public function show() { diff --git a/app/Widgets/LatestIncome.php b/app/Widgets/LatestIncome.php index 933c325e1..89334b9ee 100644 --- a/app/Widgets/LatestIncome.php +++ b/app/Widgets/LatestIncome.php @@ -7,17 +7,7 @@ use App\Models\Banking\Transaction; class LatestIncome extends Widget { - public function getDefaultName() - { - return trans('widgets.latest_income'); - } - - public function getDefaultSettings() - { - return [ - 'width' => 'col-md-4', - ]; - } + public $default_name = 'widgets.latest_income'; public function show() { diff --git a/app/Widgets/TotalExpenses.php b/app/Widgets/TotalExpenses.php index 7f633001b..b69ce3dfd 100644 --- a/app/Widgets/TotalExpenses.php +++ b/app/Widgets/TotalExpenses.php @@ -8,17 +8,11 @@ use App\Models\Purchase\Bill; class TotalExpenses extends Widget { - public function getDefaultName() - { - return trans('widgets.total_expenses'); - } + public $default_name = 'widgets.total_expenses'; - public function getDefaultSettings() - { - return [ - 'width' => 'col-md-4', - ]; - } + public $views = [ + 'header' => 'partials.widgets.stats_header', + ]; public function show() { diff --git a/app/Widgets/TotalIncome.php b/app/Widgets/TotalIncome.php index dc5e7c50d..e41ecc73d 100644 --- a/app/Widgets/TotalIncome.php +++ b/app/Widgets/TotalIncome.php @@ -8,17 +8,11 @@ use App\Models\Sale\Invoice; class TotalIncome extends Widget { - public function getDefaultName() - { - return trans('widgets.total_income'); - } + public $default_name = 'widgets.total_income'; - public function getDefaultSettings() - { - return [ - 'width' => 'col-md-4', - ]; - } + public $views = [ + 'header' => 'partials.widgets.stats_header', + ]; public function show() { diff --git a/app/Widgets/TotalProfit.php b/app/Widgets/TotalProfit.php index bae805d14..298e4a00f 100644 --- a/app/Widgets/TotalProfit.php +++ b/app/Widgets/TotalProfit.php @@ -9,17 +9,11 @@ use App\Models\Sale\Invoice; class TotalProfit extends Widget { - public function getDefaultName() - { - return trans('widgets.total_profit'); - } + public $default_name = 'widgets.total_profit'; - public function getDefaultSettings() - { - return [ - 'width' => 'col-md-4', - ]; - } + public $views = [ + 'header' => 'partials.widgets.stats_header', + ]; public function show() { diff --git a/resources/views/partials/widgets/standard_header.blade.php b/resources/views/partials/widgets/standard_header.blade.php index 26af63eea..b56ee13d0 100644 --- a/resources/views/partials/widgets/standard_header.blade.php +++ b/resources/views/partials/widgets/standard_header.blade.php @@ -3,7 +3,7 @@
-

{{ $model->name }}

+

{{ $class->model->name }}

diff --git a/resources/views/partials/widgets/stats_header.blade.php b/resources/views/partials/widgets/stats_header.blade.php index 546035ea5..83044a71d 100644 --- a/resources/views/partials/widgets/stats_header.blade.php +++ b/resources/views/partials/widgets/stats_header.blade.php @@ -11,12 +11,12 @@ 'type' => 'button', 'class' => 'dropdown-item', 'title' => trans('general.edit'), - '@click' => 'onEditWidget(' . $model->id . ')' + '@click' => 'onEditWidget(' . $class->model->id . ')' ]) !!} @endpermission @permission('delete-common-widgets') - {!! Form::deleteLink($model, 'common/widgets') !!} + {!! Form::deleteLink($class->model, 'common/widgets') !!} @endpermission diff --git a/resources/views/widgets/account_balance.blade.php b/resources/views/widgets/account_balance.blade.php index b61bd54d9..f9cd2974b 100644 --- a/resources/views/widgets/account_balance.blade.php +++ b/resources/views/widgets/account_balance.blade.php @@ -1,6 +1,6 @@ -
+
- @include('partials.widgets.standard_header', ['header_class' => 'border-bottom-0']) + @include($class->views['header'], ['header_class' => 'border-bottom-0'])
diff --git a/resources/views/widgets/donut_chart.blade.php b/resources/views/widgets/donut_chart.blade.php index 5441b2709..9e3823b2b 100644 --- a/resources/views/widgets/donut_chart.blade.php +++ b/resources/views/widgets/donut_chart.blade.php @@ -1,8 +1,8 @@ -
+
- @include('partials.widgets.standard_header') + @include($class->views['header']) -
+
{!! $chart->container() !!}
@@ -12,8 +12,8 @@ @push('charts') @endpush diff --git a/resources/views/widgets/latest_expenses.blade.php b/resources/views/widgets/latest_expenses.blade.php index 246d6b6ff..f82241a2c 100644 --- a/resources/views/widgets/latest_expenses.blade.php +++ b/resources/views/widgets/latest_expenses.blade.php @@ -1,6 +1,6 @@ -
+
- @include('partials.widgets.standard_header', ['header_class' => 'border-bottom-0']) + @include($class->views['header'], ['header_class' => 'border-bottom-0'])
diff --git a/resources/views/widgets/latest_income.blade.php b/resources/views/widgets/latest_income.blade.php index 246d6b6ff..f82241a2c 100644 --- a/resources/views/widgets/latest_income.blade.php +++ b/resources/views/widgets/latest_income.blade.php @@ -1,6 +1,6 @@ -
+
- @include('partials.widgets.standard_header', ['header_class' => 'border-bottom-0']) + @include($class->views['header'], ['header_class' => 'border-bottom-0'])
diff --git a/resources/views/widgets/line_chart.blade.php b/resources/views/widgets/line_chart.blade.php index 2f3d8efad..3a9f80ace 100644 --- a/resources/views/widgets/line_chart.blade.php +++ b/resources/views/widgets/line_chart.blade.php @@ -1,8 +1,8 @@ -
+
- @include('partials.widgets.standard_header') + @include($class->views['header']) -
+
{!! $chart->container() !!}
@@ -12,8 +12,8 @@ @push('charts') @endpush diff --git a/resources/views/widgets/total_expenses.blade.php b/resources/views/widgets/total_expenses.blade.php index caddf5b74..58bafe65f 100644 --- a/resources/views/widgets/total_expenses.blade.php +++ b/resources/views/widgets/total_expenses.blade.php @@ -1,11 +1,11 @@ -
+
- @include('partials.widgets.stats_header', ['header_class' => 'border-bottom-0']) + @include($class->views['header'], ['header_class' => 'border-bottom-0'])
-
{{ $model->name }}
+
{{ $class->model->name }}
@money($totals['current'], setting('default.currency'), true)
diff --git a/resources/views/widgets/total_income.blade.php b/resources/views/widgets/total_income.blade.php index 8ac73ec6f..8f95c66b2 100644 --- a/resources/views/widgets/total_income.blade.php +++ b/resources/views/widgets/total_income.blade.php @@ -1,11 +1,11 @@ -
+
- @include('partials.widgets.stats_header', ['header_class' => 'border-bottom-0']) + @include($class->views['header'], ['header_class' => 'border-bottom-0'])
-
{{ $model->name }}
+
{{ $class->model->name }}
@money($totals['current'], setting('default.currency'), true)
diff --git a/resources/views/widgets/total_profit.blade.php b/resources/views/widgets/total_profit.blade.php index 2a312ff16..5545cec63 100644 --- a/resources/views/widgets/total_profit.blade.php +++ b/resources/views/widgets/total_profit.blade.php @@ -1,11 +1,11 @@ -
+
- @include('partials.widgets.stats_header', ['header_class' => 'border-bottom-0']) + @include($class->views['header'], ['header_class' => 'border-bottom-0'])
-
{{ $model->name }}
+
{{ $class->model->name }}
@money($totals['current'], setting('default.currency'), true)