From dd9e95f57edd07798a351eba0bc15d0f6d15fcfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Sun, 26 Jul 2020 19:47:23 +0300 Subject: [PATCH] added landing page event --- app/Events/Auth/LandingPageShowing.php | 22 ++++++++ app/Http/Controllers/Auth/Users.php | 55 +++++-------------- app/Listeners/Auth/AddLandingPages.php | 42 ++++++++++++++ app/Providers/Event.php | 3 + .../Listeners/AddLandingPage.php | 19 +++++++ .../Listeners/AddLandingPage.php | 19 +++++++ resources/views/auth/users/create.blade.php | 2 +- resources/views/auth/users/edit.blade.php | 2 +- 8 files changed, 122 insertions(+), 42 deletions(-) create mode 100644 app/Events/Auth/LandingPageShowing.php create mode 100644 app/Listeners/Auth/AddLandingPages.php create mode 100644 modules/OfflinePayments/Listeners/AddLandingPage.php create mode 100644 modules/PaypalStandard/Listeners/AddLandingPage.php diff --git a/app/Events/Auth/LandingPageShowing.php b/app/Events/Auth/LandingPageShowing.php new file mode 100644 index 000000000..c76df2b39 --- /dev/null +++ b/app/Events/Auth/LandingPageShowing.php @@ -0,0 +1,22 @@ +user = $user; + } +} diff --git a/app/Http/Controllers/Auth/Users.php b/app/Http/Controllers/Auth/Users.php index cc8d259c2..1d4459182 100644 --- a/app/Http/Controllers/Auth/Users.php +++ b/app/Http/Controllers/Auth/Users.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Auth; use App\Abstracts\Http\Controller; +use App\Events\Auth\LandingPageShowing; use App\Http\Requests\Auth\User as Request; use App\Jobs\Auth\CreateUser; use App\Jobs\Auth\DeleteUser; @@ -46,25 +47,12 @@ class Users extends Controller */ public function create() { - $routes = [ - 'dashboard' => trans_choice('general.dashboards', 1), - 'items.index' => trans_choice('general.items', 2), - 'invoices.index' => trans_choice('general.invoices', 2), - 'revenues.index' => trans_choice('general.revenues', 2), - 'customers.index' => trans_choice('general.customers', 2), - 'bills.index' => trans_choice('general.bills', 2), - 'payments.index' => trans_choice('general.payments', 2), - 'vendors.index' => trans_choice('general.vendors', 2), - 'accounts.index' => trans_choice('general.accounts', 2), - 'transfers.index' => trans_choice('general.transfers', 2), - 'transactions.index' => trans_choice('general.transactions', 2), - 'reconciliations.index' => trans_choice('general.reconciliations', 2), - 'reports.index' => trans_choice('general.reports', 2), - 'settings.index' => trans_choice('general.settings', 2), - 'categories.index' => trans_choice('general.categories', 2), - 'currencies.index' => trans_choice('general.currencies', 2), - 'taxes.index' => trans_choice('general.taxes', 2), - ]; + $u = new \stdClass(); + $u->landing_pages = []; + + event(new LandingPageShowing($u)); + + $landing_pages = $u->landing_pages; $roles = Role::all()->reject(function ($r) { return $r->hasPermission('read-client-portal'); @@ -72,7 +60,7 @@ class Users extends Controller $companies = user()->companies()->take(10)->get()->sortBy('name')->pluck('name', 'id'); - return view('auth.users.create', compact('roles', 'companies', 'routes')); + return view('auth.users.create', compact('roles', 'companies', 'landing_pages')); } /** @@ -116,25 +104,12 @@ class Users extends Controller abort(403); } - $routes = [ - 'dashboard' => trans_choice('general.dashboards', 1), - 'items.index' => trans_choice('general.items', 2), - 'invoices.index' => trans_choice('general.invoices', 2), - 'revenues.index' => trans_choice('general.revenues', 2), - 'customers.index' => trans_choice('general.customers', 2), - 'bills.index' => trans_choice('general.bills', 2), - 'payments.index' => trans_choice('general.payments', 2), - 'vendors.index' => trans_choice('general.vendors', 2), - 'accounts.index' => trans_choice('general.accounts', 2), - 'transfers.index' => trans_choice('general.transfers', 2), - 'transactions.index' => trans_choice('general.transactions', 2), - 'reconciliations.index' => trans_choice('general.reconciliations', 2), - 'reports.index' => trans_choice('general.reports', 2), - 'settings.index' => trans_choice('general.settings', 2), - 'categories.index' => trans_choice('general.categories', 2), - 'currencies.index' => trans_choice('general.currencies', 2), - 'taxes.index' => trans_choice('general.taxes', 2), - ]; + $u = new \stdClass(); + $u->landing_pages = []; + + event(new LandingPageShowing($u)); + + $landing_pages = $u->landing_pages; if ($user->can('read-client-portal')) { // Show only roles with customer permission @@ -150,7 +125,7 @@ class Users extends Controller $companies = user()->companies()->take(10)->get()->sortBy('name')->pluck('name', 'id'); - return view('auth.users.edit', compact('user', 'companies', 'roles', 'routes')); + return view('auth.users.edit', compact('user', 'companies', 'roles', 'landing_pages')); } /** diff --git a/app/Listeners/Auth/AddLandingPages.php b/app/Listeners/Auth/AddLandingPages.php new file mode 100644 index 000000000..cbdcf2112 --- /dev/null +++ b/app/Listeners/Auth/AddLandingPages.php @@ -0,0 +1,42 @@ + trans_choice('general.dashboards', 1), + 'items.index' => trans_choice('general.items', 2), + 'invoices.index' => trans_choice('general.invoices', 2), + 'revenues.index' => trans_choice('general.revenues', 2), + 'customers.index' => trans_choice('general.customers', 2), + 'bills.index' => trans_choice('general.bills', 2), + 'payments.index' => trans_choice('general.payments', 2), + 'vendors.index' => trans_choice('general.vendors', 2), + 'accounts.index' => trans_choice('general.accounts', 2), + 'transfers.index' => trans_choice('general.transfers', 2), + 'transactions.index' => trans_choice('general.transactions', 2), + 'reconciliations.index' => trans_choice('general.reconciliations', 2), + 'reports.index' => trans_choice('general.reports', 2), + 'settings.index' => trans_choice('general.settings', 2), + 'categories.index' => trans_choice('general.categories', 2), + 'currencies.index' => trans_choice('general.currencies', 2), + 'taxes.index' => trans_choice('general.taxes', 2), + 'users.index' => trans_choice('general.users', 2), + ]; + + foreach($routes as $key => $value) { + $event->user->landing_pages[$key] = $value; + } + } +} diff --git a/app/Providers/Event.php b/app/Providers/Event.php index 52175a0bb..6b4ea6517 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -29,6 +29,9 @@ class Event extends Provider 'Illuminate\Auth\Events\Logout' => [ 'App\Listeners\Auth\Logout', ], + 'App\Events\Auth\LandingPageShowing' => [ + 'App\Listeners\Auth\AddLandingPages', + ], 'App\Events\Purchase\BillCreated' => [ 'App\Listeners\Purchase\CreateBillCreatedHistory', 'App\Listeners\Purchase\IncreaseNextBillNumber', diff --git a/modules/OfflinePayments/Listeners/AddLandingPage.php b/modules/OfflinePayments/Listeners/AddLandingPage.php new file mode 100644 index 000000000..87306294a --- /dev/null +++ b/modules/OfflinePayments/Listeners/AddLandingPage.php @@ -0,0 +1,19 @@ +user->landing_pages['offline-payments.settings.edit'] = trans('offline-payments::general.name'); + } +} diff --git a/modules/PaypalStandard/Listeners/AddLandingPage.php b/modules/PaypalStandard/Listeners/AddLandingPage.php new file mode 100644 index 000000000..c84f6ca91 --- /dev/null +++ b/modules/PaypalStandard/Listeners/AddLandingPage.php @@ -0,0 +1,19 @@ +user->landing_pages['paypal-standard.settings.edit'] = trans('paypal-standard::general.name'); + } +} diff --git a/resources/views/auth/users/create.blade.php b/resources/views/auth/users/create.blade.php index 06ba5e40e..df59b55de 100644 --- a/resources/views/auth/users/create.blade.php +++ b/resources/views/auth/users/create.blade.php @@ -27,7 +27,7 @@ {{ Form::selectGroup('locale', trans_choice('general.languages', 1), 'flag', language()->allowed(), setting('default.locale')) }} - {{ Form::selectGroup('landing_page', trans('auth.landing_page'), 'sign-in-alt', $routes, 'dashboard') }} + {{ Form::selectGroup('landing_page', trans('auth.landing_page'), 'sign-in-alt', $landing_pages, 'dashboard') }} @if (setting('default.use_gravatar', '0') == '1') @stack('picture_input_start') diff --git a/resources/views/auth/users/edit.blade.php b/resources/views/auth/users/edit.blade.php index 2d631d8a0..cb8a09f93 100644 --- a/resources/views/auth/users/edit.blade.php +++ b/resources/views/auth/users/edit.blade.php @@ -28,7 +28,7 @@ {{ Form::selectGroup('locale', trans_choice('general.languages', 1), 'flag', language()->allowed(), $user->locale) }} - {{ Form::selectGroup('landing_page', trans('auth.landing_page'), 'sign-in-alt', $routes, $user->landing_page) }} + {{ Form::selectGroup('landing_page', trans('auth.landing_page'), 'sign-in-alt', $landing_pages, $user->landing_page) }} @if (setting('default.use_gravatar', '0') == '1') @stack('picture_input_start')