Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions ProcessMaker/Http/Middleware/GenerateMenus.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,32 @@ public function handle(Request $request, Closure $next)
{
Menu::make('topnav', function ($menu) {
$menu->group(['prefix' => 'requests'], function ($request_items) {
$request_items->add(__('Requests'), ['route' => 'requests.index'])->active('requests/*');
$request_items->add(
__('Requests'),
['route' => 'requests.index', 'id' => 'requests']
)->active('requests/*');
});
//@TODO change the index to the correct blade
$menu->group(['prefix' => 'tasks'], function ($request_items) {
$request_items->add(__('Tasks'), ['route' => 'tasks.index'])->active('tasks/*');
$request_items->add(
__('Tasks'),
['route' => 'tasks.index', 'id' => 'tasks']
)->active('tasks/*');
});
if (\Auth::check() && \Auth::user()->canAny('view-processes|view-process-categories|view-scripts|view-screens|view-environment_variables')) {
$menu->group(['prefix' => 'processes'], function ($request_items) {
$request_items->add(__('Designer'), ['route' => 'processes.index'])->active('processes/*');
$request_items->add(
__('Designer'),
['route' => 'processes.index', 'id' => 'designer']
)->active('processes/*');
});
}
if (\Auth::check() && \Auth::user()->canAny('view-users|view-groups|view-auth_clients|view-settings')) {
$menu->group(['prefix' => 'admin'], function ($admin_items) {
$admin_items->add(__('Admin'), ['route' => 'admin.index'])->active('admin/*');
$admin_items->add(
__('Admin'),
['route' => 'admin.index', 'id' => 'admin']
)->active('admin/*');
});
}
});
Expand Down
35 changes: 35 additions & 0 deletions ProcessMaker/Managers/MenuBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace ProcessMaker\Managers;

use Lavary\Menu\Item;

class MenuBuilder extends \Lavary\Menu\Builder
Comment thread
CarliPinell marked this conversation as resolved.
{
/**
* Adds an item to the menu.
*
* @param string $title
* @param string|array $options
*
* @return Item $item
*/
public function add($title, $options = '')
{
$id = isset($options['id']) ? $options['id'] : $this->id();

$item = new Item($this, $id, $title, $options);

if (!empty($options['beforeItem']) && !empty($options['index'])) {
$beforeItem = $this->items->where('id', $options['beforeItem'])->first();
$this->items->splice($this->items->search($beforeItem) - $options['index'], 0, [$item]);
} elseif (!empty($options['afterItem']) && !empty($options['index'])) {
$afterItem = $this->items->where('id', $options['afterItem'])->first();
$this->items->splice($this->items->search($afterItem) + $options['index'], 0, [$item]);
} else {
$this->items->push($item);
}

return $item;
}
}
39 changes: 39 additions & 0 deletions ProcessMaker/Managers/MenuManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace ProcessMaker\Managers;

use Illuminate\Support\Facades\View;

class MenuManager extends \Lavary\Menu\Menu
Comment thread
CarliPinell marked this conversation as resolved.
{
/**
* Create a new menu builder instance.
*
* @param string $name
* @param callable $callback
* @param array $options (optional, it will be combined with the options to be applied)
*
* @return Builder
*/
public function make($name, $callback, array $options = [])
{
if (!is_callable($callback)) {
return null;
}

if (!array_key_exists($name, $this->menu)) {
$this->menu[$name] = new MenuBuilder($name, array_merge($this->loadConf($name), $options));
}

// Registering the items
call_user_func($callback, $this->menu[$name]);

// Storing each menu instance in the collection
$this->collection->put($name, $this->menu[$name]);

// Make the instance available in all views
View::share($name, $this->menu[$name]);

return $this->menu[$name];
}
}
10 changes: 8 additions & 2 deletions ProcessMaker/Providers/ProcessMakerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Notifications\Events\NotificationSent;
use Illuminate\Support\Facades;
use Illuminate\Support\Str;
use Lavary\Menu\Menu;
use Laravel\Dusk\DuskServiceProvider;
use Laravel\Horizon\Horizon;
use Laravel\Passport\Passport;
Expand All @@ -16,6 +17,7 @@
use ProcessMaker\ImportExport\Extension;
use ProcessMaker\ImportExport\SignalHelper;
use ProcessMaker\Managers;
use ProcessMaker\Managers\MenuManager;
use ProcessMaker\Models;
use ProcessMaker\Observers;
use ProcessMaker\PolicyExtension;
Expand All @@ -27,6 +29,10 @@ class ProcessMakerServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->app->singleton(Menu::class, function ($app) {
return new MenuManager();
});

static::bootObservers();

static::extendValidators();
Expand Down Expand Up @@ -93,11 +99,11 @@ public function register(): void
});

$this->app->singleton(PmHash::class, function () {
return new PmHash;
return new PmHash();
});

$this->app->singleton(Models\RequestDevice::class, function () {
return new Models\RequestDevice;
return new Models\RequestDevice();
Comment thread
CarliPinell marked this conversation as resolved.
});

/*
Expand Down
8 changes: 8 additions & 0 deletions resources/views/layouts/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
</div>
@php
$menuItems = [];
// Add here the package to add in the topNav menu
$packagesList = ['package-analytics-reporting'];
$existsMenuProvider = Menu::get('customtopnav') !== null;
$items = $existsMenuProvider ? Menu::get('customtopnav')->items->all() : [];

Expand Down Expand Up @@ -64,6 +66,12 @@
$newItem['isCustom'] = count($itemsInCustom) > 0;
$menuItems[] = $newItem;
}
// @todo make a refactor in the topNav reviewing the active() function
// The add a menu the Request is always highligth
if (in_array(Request::path(), $packagesList)) {
$menuItems[0]['isActive'] = false;
}

// If a menu provider is installed, remove menu items from ProcessMaker but preserve any other (from packages, for example)
if ($existsMenuProvider) {
$menuItems = array_filter($menuItems, function ($item) use($customNav) {
Expand Down