Skip to content

Commit

Permalink
added landing page event
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Jul 26, 2020
1 parent 7feb9e9 commit dd9e95f
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 42 deletions.
22 changes: 22 additions & 0 deletions app/Events/Auth/LandingPageShowing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Events\Auth;

use Illuminate\Queue\SerializesModels;

class LandingPageShowing
{
use SerializesModels;

public $user;

/**
* Create a new event instance.
*
* @param $user
*/
public function __construct($user)
{
$this->user = $user;
}
}
55 changes: 15 additions & 40 deletions app/Http/Controllers/Auth/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,33 +47,20 @@ public function index()
*/
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');
});

$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'));
}

/**
Expand Down Expand Up @@ -116,25 +104,12 @@ public function edit(User $user)
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
Expand All @@ -150,7 +125,7 @@ public function edit(User $user)

$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'));
}

/**
Expand Down
42 changes: 42 additions & 0 deletions app/Listeners/Auth/AddLandingPages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Listeners\Auth;

use App\Events\Auth\LandingPageShowing as Event;

class AddLandingPages
{
/**
* Handle the event.
*
* @param Event $event
* @return void
*/
public function handle(Event $event)
{
$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),
'users.index' => trans_choice('general.users', 2),
];

foreach($routes as $key => $value) {
$event->user->landing_pages[$key] = $value;
}
}
}
3 changes: 3 additions & 0 deletions app/Providers/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 19 additions & 0 deletions modules/OfflinePayments/Listeners/AddLandingPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Modules\OfflinePayments\Listeners;

use App\Events\Auth\LandingPageShowing as Event;

class AddLandingPage
{
/**
* Handle the event.
*
* @param Event $event
* @return void
*/
public function handle(Event $event)
{
$event->user->landing_pages['offline-payments.settings.edit'] = trans('offline-payments::general.name');
}
}
19 changes: 19 additions & 0 deletions modules/PaypalStandard/Listeners/AddLandingPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Modules\PaypalStandard\Listeners;

use App\Events\Auth\LandingPageShowing as Event;

class AddLandingPage
{
/**
* Handle the event.
*
* @param Event $event
* @return void
*/
public function handle(Event $event)
{
$event->user->landing_pages['paypal-standard.settings.edit'] = trans('paypal-standard::general.name');
}
}
2 changes: 1 addition & 1 deletion resources/views/auth/users/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/users/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit dd9e95f

Please sign in to comment.