diff --git a/app/Abstracts/Widget.php b/app/Abstracts/Widget.php index 46e80dbbf..99a332e4e 100644 --- a/app/Abstracts/Widget.php +++ b/app/Abstracts/Widget.php @@ -2,31 +2,31 @@ namespace App\Abstracts; -use Arrilot\Widgets\AbstractWidget; use App\Models\Income\Invoice; use App\Traits\Charts; use Date; -abstract class Widget extends AbstractWidget +abstract class Widget { use Charts; - /** - * The configuration array. - * - * @var array - */ - protected $config = [ - 'width' => 'col-md-4', - ]; + public $model; - /** - * Treat this method as a controller action. - * Return view() or other content to display. - */ - public function run() + public function __construct($model = null) { - return $this->show(); + $this->model = $model; + } + + public function getDefaultSettings() + { + return [ + 'width' => 'col-md-4', + ]; + } + + public function view($name, $data = []) + { + return view($name, array_merge(['model' => $this->model], (array) $data)); } public function applyFilters($model, $args = ['date_field' => 'paid_at']) @@ -38,7 +38,7 @@ abstract class Widget extends AbstractWidget $start_date = request()->get('start_date') . ' 00:00:00'; $end_date = request()->get('end_date') . ' 23:59:59'; - return $model->whereBetween($args['date_field'], [$start_date, $end_date]); + return $model->whereBetween($args['date_field'], [$start_date, $end_date]); } public function calculateDocumentTotals($model) diff --git a/app/Console/Stubs/Modules/json.stub b/app/Console/Stubs/Modules/json.stub index 413f19e20..020931d66 100644 --- a/app/Console/Stubs/Modules/json.stub +++ b/app/Console/Stubs/Modules/json.stub @@ -10,6 +10,6 @@ "files": [], "requires": [], "reports": [], - "settings": [], - "widgets": [] + "widgets": [], + "settings": [] } diff --git a/app/Http/Controllers/Common/Dashboard.php b/app/Http/Controllers/Common/Dashboard.php index 288666ec6..5c287419c 100644 --- a/app/Http/Controllers/Common/Dashboard.php +++ b/app/Http/Controllers/Common/Dashboard.php @@ -3,10 +3,9 @@ namespace App\Http\Controllers\Common; use App\Abstracts\Http\Controller; - -use App\Models\Common\Dashboard as Model; -use App\Models\Common\DashboardWidget; use App\Http\Requests\Common\Dashboard as Request; +use App\Models\Common\Dashboard as Model; +use App\Models\Common\Widget; use App\Traits\DateTime; class Dashboard extends Controller @@ -40,14 +39,12 @@ class Dashboard extends Controller // Dashboard $dashboard = Model::find($dashboard_id); - // Dashboard Widgets - $widgets = DashboardWidget::where('dashboard_id', $dashboard->id) - ->where('user_id', $user_id) - ->orderBy('sort', 'asc')->get(); + // Widgets + $widgets = Widget::where('dashboard_id', $dashboard->id)->orderBy('sort', 'asc')->get(); $financial_start = $this->getFinancialStart()->format('Y-m-d'); - return view('common.dashboard.index', compact('dashboards','dashboard', 'widgets', 'financial_start')); + return view('common.dashboard.index', compact('dashboards', 'dashboard', 'widgets', 'financial_start')); } /** diff --git a/app/Http/Controllers/Common/Widgets.php b/app/Http/Controllers/Common/Widgets.php index c56f8f5ce..fb6f5d616 100644 --- a/app/Http/Controllers/Common/Widgets.php +++ b/app/Http/Controllers/Common/Widgets.php @@ -3,10 +3,9 @@ namespace App\Http\Controllers\Common; use App\Abstracts\Http\Controller; - -use App\Models\Common\DashboardWidget as Model; -use App\Models\Common\Widget; use App\Http\Requests\Common\Widget as Request; +use App\Models\Common\Widget; +use App\Utilities\Widgets as Utility; class Widgets extends Controller { @@ -17,7 +16,7 @@ class Widgets extends Controller */ public function index() { - $widgets = Widget::enabled()->get(); + $widgets = Utility::getClasses(); return response()->json($widgets); } @@ -30,13 +29,11 @@ class Widgets extends Controller */ public function store(Request $request) { - $request['user_id'] = user()->id; - $request['settings'] = [ 'width' => $request->get('width'), ]; - $widget = Model::create($request->input()); + $widget = Widget::create($request->input()); $settings = $widget->settings; unset($settings['widget']); @@ -59,17 +56,17 @@ class Widgets extends Controller /** * Show the form for editing the specified resource. * - * @param Model $dashboard + * @param Widget $widget * * @return Response */ - public function edit(Model $widget) + public function edit(Widget $widget) { $settings = $widget->settings; unset($settings['widget']); return response()->json([ - 'widget_id' => $widget->widget_id, + 'class' => $widget->class, 'name' => $widget->name, 'settings' => $settings, 'sort' => $widget->sort, @@ -79,14 +76,12 @@ class Widgets extends Controller /** * Update the specified resource in storage. * - * @param Model $dashboard + * @param Widget $widget * @param $request * @return Response */ - public function update(Model $widget, Request $request) + public function update(Widget $widget, Request $request) { - $request['user_id'] = user()->id; - $request['settings'] = [ 'width' => $request->get('width'), ]; @@ -102,7 +97,7 @@ class Widgets extends Controller 'error' => false, 'message' => trans('messages.success.added', ['type' => $widget->name]), 'data' => [ - 'widget_id' => $widget->widget_id, + 'class' => $widget->class, 'name' => $widget->name, 'settings' => $settings, 'sort' => $widget->sort, @@ -114,11 +109,11 @@ class Widgets extends Controller /** * Remove the specified resource from storage. * - * @param Model $dashboard + * @param Widget $widget * * @return Response */ - public function destroy(Model $widget) + public function destroy(Widget $widget) { $message = trans('messages.success.deleted', ['type' => $widget->name]); diff --git a/app/Jobs/Auth/DeleteUser.php b/app/Jobs/Auth/DeleteUser.php index adb1d1a36..de0ef9ea5 100644 --- a/app/Jobs/Auth/DeleteUser.php +++ b/app/Jobs/Auth/DeleteUser.php @@ -28,7 +28,7 @@ class DeleteUser extends Job { $this->authorize(); - $this->deleteRelationships($this->user, ['dashboards', 'dashboard_widgets']); + $this->deleteRelationships($this->user, ['widgets', 'dashboards']); $this->user->delete(); diff --git a/app/Jobs/Common/DeleteCompany.php b/app/Jobs/Common/DeleteCompany.php index 51d3f73e9..3a31eeb22 100644 --- a/app/Jobs/Common/DeleteCompany.php +++ b/app/Jobs/Common/DeleteCompany.php @@ -33,9 +33,9 @@ class DeleteCompany extends Job $this->deleteRelationships($this->company, [ 'accounts', 'bills', 'bill_histories', 'bill_items', 'bill_item_taxes', 'bill_statuses', 'bill_totals', 'categories', - 'contacts', 'currencies', 'dashboards', 'dashboard_widgets', 'email_templates', 'invoices', 'invoice_histories', - 'invoice_items', 'invoice_item_taxes', 'invoice_statuses', 'invoice_totals', 'items', 'modules', 'module_histories', - 'reconciliations', 'recurring', 'reports', 'settings', 'taxes', 'transactions', 'transfers', 'widgets', + 'contacts', 'currencies', 'dashboards', 'email_templates', 'invoices', 'invoice_histories', 'invoice_items', + 'invoice_item_taxes', 'invoice_statuses', 'invoice_totals', 'items', 'modules', 'module_histories', 'reconciliations', + 'recurring', 'reports', 'settings', 'taxes', 'transactions', 'transfers', 'widgets', ]); $this->company->delete(); diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index a98c0796f..9f4b7b2f0 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -62,9 +62,9 @@ class User extends Authenticatable return $this->hasMany('App\Models\Common\Dashboard'); } - public function dashboard_widgets() + public function widgets() { - return $this->hasMany('App\Models\Common\DashboardWidget'); + return $this->hasManyThrough('App\Models\Common\Widget', 'App\Models\Common\Dashboard'); } /** diff --git a/app/Models/Common/Company.php b/app/Models/Common/Company.php index 79c3b60c4..68794c646 100644 --- a/app/Models/Common/Company.php +++ b/app/Models/Common/Company.php @@ -98,11 +98,6 @@ class Company extends Eloquent return $this->hasMany('App\Models\Common\Dashboard'); } - public function dashboard_widgets() - { - return $this->hasMany('App\Models\Common\DashboardWidget'); - } - public function email_templates() { return $this->hasMany('App\Models\Common\EmailTemplate'); diff --git a/app/Models/Common/Dashboard.php b/app/Models/Common/Dashboard.php index 49ea9457c..f5b32014c 100644 --- a/app/Models/Common/Dashboard.php +++ b/app/Models/Common/Dashboard.php @@ -27,7 +27,7 @@ class Dashboard extends Model public function widgets() { - return $this->hasMany('App\Models\Common\DashboardWidget')->orderBy('sort', 'asc'); + return $this->hasMany('App\Models\Common\Widget')->orderBy('sort', 'asc'); } public function user() diff --git a/app/Models/Common/DashboardWidget.php b/app/Models/Common/DashboardWidget.php deleted file mode 100644 index 3de81dd6d..000000000 --- a/app/Models/Common/DashboardWidget.php +++ /dev/null @@ -1,65 +0,0 @@ - 'array', - ]; - - public function user() - { - return $this->belongsTo('App\Models\Auth\User', 'user_id', 'id'); - } - - public function dashboard() - { - return $this->belongsTo('App\Models\Common\Dashboard'); - } - - public function widget() - { - return $this->belongsTo('App\Models\Common\Widget'); - } - - public function getNameAttribute($value) - { - if ($value) { - return $value; - } - - return $this->widget->name; - } - - public function getSettingsAttribute($value) - { - if (!empty($value)) { - $value = json_decode($value, true); - - $value['widget'] = $this; - } else { - $value = [ - 'widget' => $this, - ]; - } - - return $value; - } -} diff --git a/app/Models/Common/Widget.php b/app/Models/Common/Widget.php index f7994e632..ed8994934 100644 --- a/app/Models/Common/Widget.php +++ b/app/Models/Common/Widget.php @@ -16,14 +16,7 @@ class Widget extends Model * * @var array */ - protected $fillable = ['company_id', 'name', 'alias', 'settings', 'enabled']; - - /** - * Sortable columns. - * - * @var array - */ - public $sortable = ['name', 'alias', 'enabled']; + protected $fillable = ['company_id', 'dashboard_id', 'class', 'name', 'settings', 'sort']; /** * The attributes that should be casted to native types. @@ -31,16 +24,11 @@ class Widget extends Model * @var array */ protected $casts = [ - 'settings' => 'array', + 'settings' => 'object', ]; - public function dashboard_widgets() + public function dashboard() { - return $this->hasMany('App\Models\Common\DashboardWidget'); - } - - public function dashboard_widget() - { - return $this->belongsTo('App\Models\Common\DashboardWidget', 'id', 'widget_id')->where('dashboard_id', 1); + return $this->belongsTo('App\Models\Common\Dashboard'); } } diff --git a/app/Providers/Blade.php b/app/Providers/Blade.php index dd4273ce7..2073f81c3 100644 --- a/app/Providers/Blade.php +++ b/app/Providers/Blade.php @@ -20,6 +20,10 @@ class Blade extends ServiceProvider Facade::directive('date', function ($expression) { return ""; }); + + Facade::directive('widget', function ($expression) { + return ""; + }); } /** diff --git a/app/Utilities/Widgets.php b/app/Utilities/Widgets.php new file mode 100644 index 000000000..1d4487bc5 --- /dev/null +++ b/app/Utilities/Widgets.php @@ -0,0 +1,67 @@ +get(); + + foreach ($modules as $module) { + $m = module($module->alias); + + // Check if the module exists and has widgets + if (!$m || empty($m->get('widgets'))) { + continue; + } + + static::parseClasses($classes, $m->get('widgets')); + } + + return $classes; + } + + protected static function parseClasses(&$classes, $list) + { + foreach ($list as $class) { + if (!class_exists($class)) { + continue; + } + + $name = (new $class())->getDefaultName(); + + $classes[$class] = $name; + } + } + + public static function getInstance($model) + { + $class = $model->class; + + return new $class($model); + } + + public static function show($model) + { + return static::getInstance($model)->show(); + } +} diff --git a/app/Utilities/helpers.php b/app/Utilities/helpers.php index 10b3d34d6..4dcc4b004 100644 --- a/app/Utilities/helpers.php +++ b/app/Utilities/helpers.php @@ -1,6 +1,7 @@ format($date_time->getCompanyDateFormat()); } } + +if (!function_exists('show_widget')) { + /** + * Format the given date based on company settings. + * + * @return string + */ + function show_widget($model) + { + return Widgets::show($model); + } +} diff --git a/app/Widgets/AccountBalance.php b/app/Widgets/AccountBalance.php index 44fc1b9f4..ec7095723 100644 --- a/app/Widgets/AccountBalance.php +++ b/app/Widgets/AccountBalance.php @@ -11,9 +11,13 @@ class AccountBalance extends Widget { $accounts = Account::enabled()->take(5)->get(); - return view('widgets.account_balance', [ - 'config' => (object) $this->config, + return $this->view('widgets.account_balance', [ 'accounts' => $accounts, ]); } + + public function getDefaultName() + { + return trans('widgets.account_balance'); + } } diff --git a/app/Widgets/CashFlow.php b/app/Widgets/CashFlow.php index 1b9c22ec6..9c557b7c1 100644 --- a/app/Widgets/CashFlow.php +++ b/app/Widgets/CashFlow.php @@ -13,10 +13,6 @@ class CashFlow extends Widget { use Currencies, DateTime; - protected $config = [ - 'width' => 'col-md-12', - ]; - public function show() { $financial_start = $this->getFinancialStart()->format('Y-m-d'); @@ -96,8 +92,7 @@ class CashFlow extends Widget ]) ->fill(false); - return view('widgets.cash_flow', [ - 'config' => (object) $this->config, + return $this->view('widgets.cash_flow', [ 'chart' => $chart, ]); } @@ -175,4 +170,16 @@ class CashFlow extends Widget return $profit; } + + public function getDefaultName() + { + return trans('widgets.cash_flow'); + } + + public function getDefaultSettings() + { + return [ + 'width' => 'col-md-12', + ]; + } } diff --git a/app/Widgets/ExpensesByCategory.php b/app/Widgets/ExpensesByCategory.php index d31686def..37f5a9601 100644 --- a/app/Widgets/ExpensesByCategory.php +++ b/app/Widgets/ExpensesByCategory.php @@ -7,10 +7,6 @@ use App\Models\Setting\Category; class ExpensesByCategory extends Widget { - protected $config = [ - 'width' => 'col-md-6', - ]; - public function show() { Category::with('expense_transactions')->type('expense')->enabled()->each(function ($category) { @@ -27,9 +23,20 @@ class ExpensesByCategory extends Widget $chart = $this->getDonutChart(trans_choice('general.expenses', 2), 0, 160, 6); - return view('widgets.expenses_by_category', [ - 'config' => (object) $this->config, + return $this->view('widgets.expenses_by_category', [ 'chart' => $chart, ]); } + + public function getDefaultName() + { + return trans('widgets.expenses_by_category'); + } + + public function getDefaultSettings() + { + return [ + 'width' => 'col-md-6', + ]; + } } diff --git a/app/Widgets/IncomeByCategory.php b/app/Widgets/IncomeByCategory.php index 0de7fcd65..b23bf08ef 100644 --- a/app/Widgets/IncomeByCategory.php +++ b/app/Widgets/IncomeByCategory.php @@ -7,10 +7,6 @@ use App\Models\Setting\Category; class IncomeByCategory extends Widget { - protected $config = [ - 'width' => 'col-md-6', - ]; - public function show() { Category::with('income_transacions')->type('income')->enabled()->each(function ($category) { @@ -27,9 +23,20 @@ class IncomeByCategory extends Widget $chart = $this->getDonutChart(trans_choice('general.incomes', 1), 0, 160, 6); - return view('widgets.income_by_category', [ - 'config' => (object) $this->config, + return $this->view('widgets.income_by_category', [ 'chart' => $chart, ]); } + + public function getDefaultName() + { + return trans('widgets.income_by_category'); + } + + public function getDefaultSettings() + { + return [ + 'width' => 'col-md-6', + ]; + } } diff --git a/app/Widgets/LatestExpenses.php b/app/Widgets/LatestExpenses.php index c1c2dfe7a..2996a3b78 100644 --- a/app/Widgets/LatestExpenses.php +++ b/app/Widgets/LatestExpenses.php @@ -11,9 +11,13 @@ class LatestExpenses extends Widget { $transactions = $this->applyFilters(Transaction::with('category')->type('expense')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get(); - return view('widgets.latest_expenses', [ - 'config' => (object) $this->config, + return $this->view('widgets.latest_expenses', [ 'transactions' => $transactions, ]); } + + public function getDefaultName() + { + return trans('widgets.latest_expenses'); + } } diff --git a/app/Widgets/LatestIncome.php b/app/Widgets/LatestIncome.php index 17b45cda6..52121176b 100644 --- a/app/Widgets/LatestIncome.php +++ b/app/Widgets/LatestIncome.php @@ -11,9 +11,13 @@ class LatestIncome extends Widget { $transactions = $this->applyFilters(Transaction::with('category')->type('income')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get(); - return view('widgets.latest_income', [ - 'config' => (object) $this->config, + return $this->view('widgets.latest_income', [ 'transactions' => $transactions, ]); } + + public function getDefaultName() + { + return trans('widgets.latest_income'); + } } diff --git a/app/Widgets/TotalExpenses.php b/app/Widgets/TotalExpenses.php index f17231de5..95f2ab78d 100644 --- a/app/Widgets/TotalExpenses.php +++ b/app/Widgets/TotalExpenses.php @@ -36,9 +36,13 @@ class TotalExpenses extends Widget 'progress' => $progress, ]; - return view('widgets.total_expenses', [ - 'config' => (object) $this->config, + return $this->view('widgets.total_expenses', [ 'totals' => $totals, ]); } + + public function getDefaultName() + { + return trans('widgets.total_expenses'); + } } diff --git a/app/Widgets/TotalIncome.php b/app/Widgets/TotalIncome.php index e63f53c8d..61d3e9401 100644 --- a/app/Widgets/TotalIncome.php +++ b/app/Widgets/TotalIncome.php @@ -30,15 +30,19 @@ class TotalIncome extends Widget } $totals = [ - 'current' => $current, - 'open' => money($open, setting('default.currency'), true), - 'overdue' => money($overdue, setting('default.currency'), true), - 'progress' => $progress, + 'current' => $current, + 'open' => money($open, setting('default.currency'), true), + 'overdue' => money($overdue, setting('default.currency'), true), + 'progress' => $progress, ]; - return view('widgets.total_income', [ - 'config' => (object) $this->config, + return $this->view('widgets.total_income', [ 'totals' => $totals, ]); } + + public function getDefaultName() + { + return trans('widgets.total_income'); + } } diff --git a/app/Widgets/TotalProfit.php b/app/Widgets/TotalProfit.php index d350ee202..f3c96fe98 100644 --- a/app/Widgets/TotalProfit.php +++ b/app/Widgets/TotalProfit.php @@ -55,9 +55,13 @@ class TotalProfit extends Widget 'progress' => $progress, ]; - return view('widgets.total_profit', [ - 'config' => (object) $this->config, + return $this->view('widgets.total_profit', [ 'totals' => $totals, ]); } + + public function getDefaultName() + { + return trans('widgets.total_profit'); + } } diff --git a/composer.json b/composer.json index cdae2679e..def723201 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,6 @@ "akaunting/money": "1.0.*", "akaunting/setting": "1.1.*", "akaunting/version": "1.0.*", - "arrilot/laravel-widgets": "3.13.*", "barryvdh/laravel-debugbar": "3.2.*", "barryvdh/laravel-dompdf": "0.*", "barryvdh/laravel-ide-helper": "2.6.*", diff --git a/composer.lock b/composer.lock index 961dd5c65..94f9d9735 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "986f507365ca5ee6e150335aec149b15", + "content-hash": "1833d7d2fe4dd91486f71b8f08ffb15d", "packages": [ { "name": "akaunting/firewall", @@ -262,16 +262,16 @@ }, { "name": "akaunting/money", - "version": "1.0.13", + "version": "1.0.14", "source": { "type": "git", "url": "https://github.com/akaunting/money.git", - "reference": "da302568d31122b200cbd215622cb0ae47131524" + "reference": "058b2256344ca5cb17aa1fecb574f5264a2444ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/akaunting/money/zipball/da302568d31122b200cbd215622cb0ae47131524", - "reference": "da302568d31122b200cbd215622cb0ae47131524", + "url": "https://api.github.com/repos/akaunting/money/zipball/058b2256344ca5cb17aa1fecb574f5264a2444ef", + "reference": "058b2256344ca5cb17aa1fecb574f5264a2444ef", "shasum": "" }, "require": { @@ -319,7 +319,7 @@ "laravel", "money" ], - "time": "2019-09-21T16:15:52+00:00" + "time": "2019-12-26T08:11:31+00:00" }, { "name": "akaunting/setting", @@ -440,68 +440,6 @@ ], "time": "2019-09-26T18:32:38+00:00" }, - { - "name": "arrilot/laravel-widgets", - "version": "3.13.0", - "source": { - "type": "git", - "url": "https://github.com/arrilot/laravel-widgets.git", - "reference": "24297e9a7b1988808b782567892170cd421e6715" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/arrilot/laravel-widgets/zipball/24297e9a7b1988808b782567892170cd421e6715", - "reference": "24297e9a7b1988808b782567892170cd421e6715", - "shasum": "" - }, - "require": { - "illuminate/cache": ">=5.5", - "illuminate/console": ">=5.5", - "illuminate/container": ">=5.5", - "illuminate/contracts": ">=5.5", - "illuminate/support": ">=5.5", - "illuminate/view": ">=5.5", - "php": ">=7.0" - }, - "require-dev": { - "phpunit/phpunit": "~6.0" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Arrilot\\Widgets\\ServiceProvider" - ], - "aliases": { - "Widget": "Arrilot\\Widgets\\Facade", - "AsyncWidget": "Arrilot\\Widgets\\AsyncFacade" - } - } - }, - "autoload": { - "psr-4": { - "Arrilot\\Widgets\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nekrasov Ilya", - "email": "nekrasov.ilya90@gmail.com" - } - ], - "description": "A powerful alternative to view composers. Asynchronous widgets, reloadable widgets, console generator, caching - everything you can think of.", - "homepage": "https://github.com/arrilot/laravel-widgets", - "keywords": [ - "ajax", - "laravel", - "widgets" - ], - "time": "2019-03-25T14:20:55+00:00" - }, { "name": "balping/json-raw-encoder", "version": "v1.0.0", @@ -2041,27 +1979,26 @@ }, { "name": "egulias/email-validator", - "version": "2.1.12", + "version": "2.1.13", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "a6255605af39f2db7f5cb62e672bd8a7bad8d208" + "reference": "834593d5900615639208417760ba6a17299e2497" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/a6255605af39f2db7f5cb62e672bd8a7bad8d208", - "reference": "a6255605af39f2db7f5cb62e672bd8a7bad8d208", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/834593d5900615639208417760ba6a17299e2497", + "reference": "834593d5900615639208417760ba6a17299e2497", "shasum": "" }, "require": { "doctrine/lexer": "^1.0.1", - "php": ">= 5.5" + "php": ">=5.5" }, "require-dev": { - "dominicsayers/isemail": "dev-master", - "phpunit/phpunit": "^4.8.35||^5.7||^6.0", - "satooshi/php-coveralls": "^1.0.1", - "symfony/phpunit-bridge": "^4.4@dev" + "dominicsayers/isemail": "^3.0.7", + "phpunit/phpunit": "^4.8.36|^7.5.15", + "satooshi/php-coveralls": "^1.0.1" }, "suggest": { "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" @@ -2095,7 +2032,7 @@ "validation", "validator" ], - "time": "2019-12-20T12:49:39+00:00" + "time": "2019-12-30T08:14:25+00:00" }, { "name": "erusev/parsedown", @@ -2199,44 +2136,46 @@ }, { "name": "guzzlehttp/guzzle", - "version": "6.3.3", + "version": "6.5.2", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" + "reference": "43ece0e75098b7ecd8d13918293029e555a50f82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/43ece0e75098b7ecd8d13918293029e555a50f82", + "reference": "43ece0e75098b7ecd8d13918293029e555a50f82", "shasum": "" }, "require": { + "ext-json": "*", "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.4", + "guzzlehttp/psr7": "^1.6.1", "php": ">=5.5" }, "require-dev": { "ext-curl": "*", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", - "psr/log": "^1.0" + "psr/log": "^1.1" }, "suggest": { + "ext-intl": "Required for Internationalized Domain Name (IDN) support", "psr/log": "Required for using the Log middleware" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "6.3-dev" + "dev-master": "6.5-dev" } }, "autoload": { - "files": [ - "src/functions_include.php" - ], "psr-4": { "GuzzleHttp\\": "src/" - } + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -2260,7 +2199,7 @@ "rest", "web service" ], - "time": "2018-04-22T15:46:56+00:00" + "time": "2019-12-23T11:57:10+00:00" }, { "name": "guzzlehttp/promises", @@ -3226,16 +3165,16 @@ }, { "name": "league/flysystem", - "version": "1.0.61", + "version": "1.0.62", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "4fb13c01784a6c9f165a351e996871488ca2d8c9" + "reference": "14dd5d7dff5fbc29ca9a2a53ff109760e40d91a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/4fb13c01784a6c9f165a351e996871488ca2d8c9", - "reference": "4fb13c01784a6c9f165a351e996871488ca2d8c9", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/14dd5d7dff5fbc29ca9a2a53ff109760e40d91a0", + "reference": "14dd5d7dff5fbc29ca9a2a53ff109760e40d91a0", "shasum": "" }, "require": { @@ -3306,7 +3245,7 @@ "sftp", "storage" ], - "time": "2019-12-08T21:46:50+00:00" + "time": "2019-12-29T14:46:55+00:00" }, { "name": "league/fractal", @@ -4312,16 +4251,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.3", + "version": "4.3.4", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "2ecaa9fef01634c83bfa8dc1fe35fb5cef223a62" + "reference": "da3fd972d6bafd628114f7e7e036f45944b62e9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/2ecaa9fef01634c83bfa8dc1fe35fb5cef223a62", - "reference": "2ecaa9fef01634c83bfa8dc1fe35fb5cef223a62", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/da3fd972d6bafd628114f7e7e036f45944b62e9c", + "reference": "da3fd972d6bafd628114f7e7e036f45944b62e9c", "shasum": "" }, "require": { @@ -4333,6 +4272,7 @@ "require-dev": { "doctrine/instantiator": "^1.0.5", "mockery/mockery": "^1.0", + "phpdocumentor/type-resolver": "0.4.*", "phpunit/phpunit": "^6.4" }, "type": "library", @@ -4359,7 +4299,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2019-12-20T13:40:23+00:00" + "time": "2019-12-28T18:55:12+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -7300,16 +7240,16 @@ }, { "name": "filp/whoops", - "version": "2.6.0", + "version": "2.7.0", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "ecbc8f3ed2cafca3cfca3d5febaae5a9d2899508" + "reference": "4c97f814aa2f0dd4d5bedc89181c10ef12c004c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/ecbc8f3ed2cafca3cfca3d5febaae5a9d2899508", - "reference": "ecbc8f3ed2cafca3cfca3d5febaae5a9d2899508", + "url": "https://api.github.com/repos/filp/whoops/zipball/4c97f814aa2f0dd4d5bedc89181c10ef12c004c5", + "reference": "4c97f814aa2f0dd4d5bedc89181c10ef12c004c5", "shasum": "" }, "require": { @@ -7328,7 +7268,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -7357,7 +7297,7 @@ "throwable", "whoops" ], - "time": "2019-12-25T10:00:00+00:00" + "time": "2019-12-29T10:00:00+00:00" }, { "name": "fzaninotto/faker", @@ -7459,23 +7399,22 @@ }, { "name": "mockery/mockery", - "version": "1.3.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/mockery/mockery.git", - "reference": "5571962a4f733fbb57bede39778f71647fae8e66" + "reference": "f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/5571962a4f733fbb57bede39778f71647fae8e66", - "reference": "5571962a4f733fbb57bede39778f71647fae8e66", + "url": "https://api.github.com/repos/mockery/mockery/zipball/f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be", + "reference": "f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be", "shasum": "" }, "require": { "hamcrest/hamcrest-php": "~2.0", "lib-pcre": ">=7.0", - "php": ">=5.6.0", - "sebastian/comparator": "^1.2.4|^3.0" + "php": ">=5.6.0" }, "require-dev": { "phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0" @@ -7483,7 +7422,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.3.x-dev" } }, "autoload": { @@ -7521,7 +7460,7 @@ "test double", "testing" ], - "time": "2019-11-24T07:54:50+00:00" + "time": "2019-12-26T09:49:15+00:00" }, { "name": "myclabs/deep-copy", @@ -8054,16 +7993,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.5.0", + "version": "8.5.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3ee1c1fd6fc264480c25b6fb8285edefe1702dab" + "reference": "7870c78da3c5e4883eaef36ae47853ebb3cb86f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3ee1c1fd6fc264480c25b6fb8285edefe1702dab", - "reference": "3ee1c1fd6fc264480c25b6fb8285edefe1702dab", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7870c78da3c5e4883eaef36ae47853ebb3cb86f2", + "reference": "7870c78da3c5e4883eaef36ae47853ebb3cb86f2", "shasum": "" }, "require": { @@ -8133,7 +8072,7 @@ "testing", "xunit" ], - "time": "2019-12-06T05:41:38+00:00" + "time": "2019-12-25T14:49:39+00:00" }, { "name": "scrivo/highlight.php", diff --git a/config/laravel-widgets.php b/config/laravel-widgets.php deleted file mode 100644 index ca2e8c036..000000000 --- a/config/laravel-widgets.php +++ /dev/null @@ -1,22 +0,0 @@ - 'App\Widgets', - - 'use_jquery_for_ajax_calls' => false, - - /* - * Set Ajax widget middleware - */ - 'route_middleware' => ['web'], - - /* - * Relative path from the base directory to a regular widget stub. - */ - 'widget_stub' => 'vendor/arrilot/laravel-widgets/src/Console/stubs/widget.stub', - - /* - * Relative path from the base directory to a plain widget stub. - */ - 'widget_plain_stub' => 'vendor/arrilot/laravel-widgets/src/Console/stubs/widget_plain.stub', -]; diff --git a/database/migrations/2019_11_14_000000_create_dashboards_table.php b/database/migrations/2019_11_14_000000_create_dashboards_table.php index 006ed1fd9..961701826 100644 --- a/database/migrations/2019_11_14_000000_create_dashboards_table.php +++ b/database/migrations/2019_11_14_000000_create_dashboards_table.php @@ -25,12 +25,11 @@ class CreateDashboardsTable extends Migration $table->index(['company_id']); }); - Schema::create('dashboard_widgets', function (Blueprint $table) { + Schema::create('widgets', function (Blueprint $table) { $table->increments('id'); $table->integer('company_id'); - $table->integer('user_id'); $table->integer('dashboard_id'); - $table->integer('widget_id'); + $table->string('class'); $table->string('name'); $table->text('settings')->nullable(); $table->integer('sort')->default(0); @@ -39,19 +38,6 @@ class CreateDashboardsTable extends Migration $table->index(['company_id']); }); - - Schema::create('widgets', function (Blueprint $table) { - $table->increments('id'); - $table->integer('company_id'); - $table->string('name'); - $table->string('alias'); - $table->text('settings')->nullable(); - $table->boolean('enabled')->default(1); - $table->timestamps(); - $table->softDeletes(); - - $table->index(['company_id', 'alias']); - }); } /** @@ -62,7 +48,6 @@ class CreateDashboardsTable extends Migration public function down() { Schema::drop('dashboards'); - Schema::drop('dashboard_widgets'); Schema::drop('widgets'); } } diff --git a/database/seeds/Dashboards.php b/database/seeds/Dashboards.php index c8ae32c48..c306335fe 100644 --- a/database/seeds/Dashboards.php +++ b/database/seeds/Dashboards.php @@ -5,7 +5,7 @@ namespace Database\Seeds; use App\Abstracts\Model; use App\Models\Common\Widget; use App\Models\Common\Dashboard; -use App\Models\Common\DashboardWidget; +use App\Utilities\Widgets as WidgetUtility; use Illuminate\Database\Seeder; class Dashboards extends Seeder @@ -29,35 +29,28 @@ class Dashboards extends Seeder $user_id = $this->command->argument('user'); $company_id = $this->command->argument('company'); - $rows = [ - [ + $dashboard = Dashboard::create([ + 'company_id' => $company_id, + 'user_id' => $user_id, + 'name' => trans('general.dashboard'), + 'enabled' => 1, + ]); + + $widgets = WidgetUtility::getClasses(); + + $sort = 1; + + foreach ($widgets as $class => $name) { + Widget::create([ 'company_id' => $company_id, - 'user_id' => $user_id, - 'name' => trans('general.dashboard'), - 'enabled' => 1, - ] - ]; + 'dashboard_id' => $dashboard->id, + 'class' => $class, + 'name' => $name, + 'settings' => (new $class())->getDefaultSettings(), + 'sort' => $sort, + ]); - foreach ($rows as $row) { - $dashboard = Dashboard::create($row); - - $widgets = Widget::where('company_id', $company_id)->orderBy('created_at','desc')->get(); - - $sort = 1; - - foreach ($widgets as $widget) { - DashboardWidget::create([ - 'company_id' => $company_id, - 'user_id' => $user_id, - 'dashboard_id' => $dashboard->id, - 'widget_id' => $widget->id, - 'name' => $widget->name, - 'settings' => $widget->settings, - 'sort' => $sort - ]); - - $sort++; - } + $sort++; } } } diff --git a/database/seeds/UserSeeder.php b/database/seeds/UserSeeder.php index 6703840b1..8b5d4e45e 100644 --- a/database/seeds/UserSeeder.php +++ b/database/seeds/UserSeeder.php @@ -11,7 +11,6 @@ class UserSeeder extends Seeder */ public function run() { - $this->call(Database\Seeds\Widgets::class); $this->call(Database\Seeds\Dashboards::class); } } diff --git a/database/seeds/Widgets.php b/database/seeds/Widgets.php deleted file mode 100644 index 9f3fa4944..000000000 --- a/database/seeds/Widgets.php +++ /dev/null @@ -1,99 +0,0 @@ -create(); - - Model::reguard(); - } - - private function create() - { - $company_id = $this->command->argument('company'); - - $rows = [ - [ - 'company_id' => $company_id, - 'name' => trans('dashboard.total_income'), - 'alias' => 'total-income', - 'settings' => ['width' => 'col-md-4'], - 'enabled' => 1, - ], - [ - 'company_id' => $company_id, - 'name' => trans('dashboard.total_expenses'), - 'alias' => 'total-expenses', - 'settings' => ['width' => 'col-md-4'], - 'enabled' => 1, - ], - [ - 'company_id' => $company_id, - 'name' => trans('dashboard.total_profit'), - 'alias' => 'total-profit', - 'settings' => ['width' => 'col-md-4'], - 'enabled' => 1, - ], - [ - 'company_id' => $company_id, - 'name' => trans('dashboard.cash_flow'), - 'alias' => 'cash-flow', - 'settings' => ['width' => 'col-md-12'], - 'enabled' => 1, - ], - [ - 'company_id' => $company_id, - 'name' => trans('dashboard.income_by_category'), - 'alias' => 'income-by-category', - 'settings' => ['width' => 'col-md-6'], - 'enabled' => 1, - ], - [ - 'company_id' => $company_id, - 'name' => trans('dashboard.expenses_by_category'), - 'alias' => 'expenses-by-category', - 'settings' => ['width' => 'col-md-6'], - 'enabled' => 1, - ], - [ - 'company_id' => $company_id, - 'name' => trans('dashboard.account_balance'), - 'alias' => 'account-balance', - 'settings' => ['width' => 'col-md-4'], - 'enabled' => 1, - ], - [ - 'company_id' => $company_id, - 'name' => trans('dashboard.latest_income'), - 'alias' => 'latest-income', - 'settings' => ['width' => 'col-md-4'], - 'enabled' => 1, - ], - [ - 'company_id' => $company_id, - 'name' => trans('dashboard.latest_expenses'), - 'alias' => 'latest-expenses', - 'settings' => ['width' => 'col-md-4'], - 'enabled' => 1, - ], - ]; - - foreach ($rows as $row) { - Widget::create($row); - } - } -} diff --git a/modules/OfflinePayments/module.json b/modules/OfflinePayments/module.json index 3a38699cb..fa90c8336 100644 --- a/modules/OfflinePayments/module.json +++ b/modules/OfflinePayments/module.json @@ -10,6 +10,6 @@ "files": [], "requires": [], "reports": [], - "settings": [], - "widgets": [] + "widgets": [], + "settings": [] } diff --git a/modules/PaypalStandard/module.json b/modules/PaypalStandard/module.json index a7d456148..ce0827c1d 100644 --- a/modules/PaypalStandard/module.json +++ b/modules/PaypalStandard/module.json @@ -11,6 +11,7 @@ "files": [], "requires": [], "reports": [], + "widgets": [], "settings": [ { "type": "textGroup", @@ -77,6 +78,5 @@ "icon": "sort", "attributes": {} } - ], - "widgets": [] + ] } diff --git a/resources/lang/en-GB/dashboard.php b/resources/lang/en-GB/widgets.php similarity index 100% rename from resources/lang/en-GB/dashboard.php rename to resources/lang/en-GB/widgets.php diff --git a/resources/views/common/dashboard/index.blade.php b/resources/views/common/dashboard/index.blade.php index ea412159f..0087b8948 100644 --- a/resources/views/common/dashboard/index.blade.php +++ b/resources/views/common/dashboard/index.blade.php @@ -174,8 +174,8 @@ @section('content')
- @foreach($widgets as $dashboard_widget) - @widget($dashboard_widget->widget->alias, $dashboard_widget->settings) + @foreach($widgets as $widget) + @widget($widget) @endforeach
@endsection diff --git a/resources/views/widgets/account_balance.blade.php b/resources/views/widgets/account_balance.blade.php index 79085210e..773a00a1b 100644 --- a/resources/views/widgets/account_balance.blade.php +++ b/resources/views/widgets/account_balance.blade.php @@ -1,10 +1,10 @@ -
+
-

{{ trans('dashboard.account_balance') }}

+

{{ $model->name }}

diff --git a/resources/views/widgets/cash_flow.blade.php b/resources/views/widgets/cash_flow.blade.php index 742b7324f..e61ff62a9 100644 --- a/resources/views/widgets/cash_flow.blade.php +++ b/resources/views/widgets/cash_flow.blade.php @@ -1,9 +1,9 @@ -
+
-

{{ trans('dashboard.cash_flow') }}

+

{{ $model->name }}

diff --git a/resources/views/widgets/expenses_by_category.blade.php b/resources/views/widgets/expenses_by_category.blade.php index f4cf522e2..4e0df529c 100644 --- a/resources/views/widgets/expenses_by_category.blade.php +++ b/resources/views/widgets/expenses_by_category.blade.php @@ -1,10 +1,10 @@ -
+
-

{{ trans('dashboard.expenses_by_category') }}

+

{{ $model->name }}

diff --git a/resources/views/widgets/income_by_category.blade.php b/resources/views/widgets/income_by_category.blade.php index dbee22153..e68e99ceb 100644 --- a/resources/views/widgets/income_by_category.blade.php +++ b/resources/views/widgets/income_by_category.blade.php @@ -1,10 +1,10 @@ -
+
-

{{ trans('dashboard.income_by_category') }}

+

{{ $model->name }}

diff --git a/resources/views/widgets/latest_expenses.blade.php b/resources/views/widgets/latest_expenses.blade.php index a98808eec..8ccc4d760 100644 --- a/resources/views/widgets/latest_expenses.blade.php +++ b/resources/views/widgets/latest_expenses.blade.php @@ -1,9 +1,9 @@ -
+
-

{{ trans('dashboard.latest_expenses') }}

+

{{ $model->name }}

diff --git a/resources/views/widgets/latest_income.blade.php b/resources/views/widgets/latest_income.blade.php index 09541f2fd..ff50b0a7c 100644 --- a/resources/views/widgets/latest_income.blade.php +++ b/resources/views/widgets/latest_income.blade.php @@ -1,9 +1,9 @@ -
+
-

{{ trans('dashboard.latest_income') }}

+

{{ $model->name }}

diff --git a/resources/views/widgets/total_expenses.blade.php b/resources/views/widgets/total_expenses.blade.php index 849c43413..69d77ee99 100644 --- a/resources/views/widgets/total_expenses.blade.php +++ b/resources/views/widgets/total_expenses.blade.php @@ -1,4 +1,4 @@ -
+
@@ -22,7 +22,7 @@
-
{{ trans('dashboard.total_expenses') }}
+
{{ $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 4e23a60da..6186724c0 100644 --- a/resources/views/widgets/total_income.blade.php +++ b/resources/views/widgets/total_income.blade.php @@ -1,4 +1,4 @@ -
+
@@ -22,7 +22,7 @@
-
{{ trans('dashboard.total_income') }}
+
{{ $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 a8ec04859..85909dd25 100644 --- a/resources/views/widgets/total_profit.blade.php +++ b/resources/views/widgets/total_profit.blade.php @@ -1,4 +1,4 @@ -
+
@@ -22,7 +22,7 @@
-
{{ trans('dashboard.total_profit') }}
+
{{ $model->name }}
@money($totals['current'], setting('default.currency'), true)
diff --git a/routes/admin.php b/routes/admin.php index 2bd423597..4a03c2353 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -10,9 +10,7 @@ Route::group(['prefix' => 'common'], function () { Route::get('companies/{company}/disable', 'Common\Companies@disable')->name('companies.disable'); Route::resource('companies', 'Common\Companies'); - Route::get('dashboard/cashflow', 'Common\Dashboard@cashFlow')->name('dashboards.cashflow'); Route::resource('dashboards', 'Common\Dashboard'); - Route::post('widgets/getData', 'Common\Widgets@getData')->name('widgets.getData'); Route::resource('widgets', 'Common\Widgets');