Test Setup Failed
Push — master ( 6b6842...4dae76 )
by Georgi
04:14
created

LayoutView::initActionBar()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Epesi\Core\Layout;
4
5
use atk4\ui\jQuery;
6
use Illuminate\Support\Arr;
7
use Epesi\Core\System\Modules\ModuleView;
8
use atk4\core\SessionTrait;
9
use atk4\ui\Menu;
10
11
class LayoutView extends \atk4\ui\Layout
12
{
13
    use SessionTrait;
14
    
15
    /**
16
     * @var View\NavMenu
17
     */
18
    public $menuLeft;    // vertical menu
19
       
20
    /**
21
     * @var \atk4\ui\Menu
22
     */
23
    public $menuTop;        // horizontal menu
24
    
25
    /**
26
     * @var \atk4\ui\Menu
27
     */
28
    public $menuRight;   // vertical pull-down
29
       
30
    /**
31
     * @var View\ActionBar
32
     */
33
    public $actionBar;   
34
    public $locationBar;
35
    
36
    public $burger = true;      // burger menu item
37
38
    /*
39
     * Whether or not left Menu is visible on Page load.
40
     */
41
    public $isMenuLeftVisible = true;
42
43
    public $defaultTemplate = 'layout/admin.html';
44
    
45
    protected $location;
46
47
    protected function init(): void
48
    {
49
        parent::init();
50
        
51
        $this->initMenuTop();
52
        $this->initActionBar();
53
        
54
//         if (request()->pjax()) return;
55
        
56
        $this->initMenuLeft();  
57
        $this->initMenuRight();
58
        
59
        $this->template->trySet('version', $this->getApp()->version);
60
        
61
//         $this->js(true, null, 'body')->niceScroll();
62
        
63
//         $this->js(true, null, new jsExpression('window'))->on('pageshow', new jsFunction(['event'], [
64
//         			new jsExpression('
65
// 		if (event.originalEvent.persisted) {
66
//         	window.location.reload(); 
67
//     	}')]));
68
    }
69
    
70
	/**
71
	 * @return static 
72
	 */
73
	public function setLocation(array $crumbs)
74
	{
75
		$this->location = $crumbs;
76
77
		$crumb = \atk4\ui\Breadcrumb::addTo($this->locationBar);
78
		
79
		$title = [];
80
		foreach ($crumbs as $level) {
81
			$label = $level['label'] ?? $level;
82
			$link = $level['link'] ?? null;
83
			
84
			$crumb->addCrumb($label, $link);
85
			
86
			$title[] = $label;
87
		}
88
89
		$crumb->popTitle();
90
		
91
		$this->getApp()->title = implode(' > ', Arr::prepend($title, config('epesi.ui.title', 'EPESI')));
92
		
93
		return $this;
94
	}
95
	
96
	public function getLocation()
97
	{
98
		return $this->location;
99
	}
100
	
101
	protected function initMenuTop()
102
	{
103
		if ($this->menuTop) return;
104
		
105
		$this->menuTop = Menu::addTo($this, ['atk-topMenu fixed horizontal', 'element' => 'header'], ['TopMenu']);
106
		
107
		// company logo
108
		// see \Epesi\Core\Controller::logo
109
		\atk4\ui\View::addTo($this->menuTop, ['class' => ['epesi-logo'], 'style' => ['width' =>  '167px']])->add([\atk4\ui\Image::class, url('logo')])->setStyle(['max-height' => '32px']);
0 ignored issues
show
Bug introduced by
array(atk4\ui\Image::class, url('logo')) of type array<integer,string> is incompatible with the type atk4\ui\View expected by parameter $object of atk4\ui\View::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
		\atk4\ui\View::addTo($this->menuTop, ['class' => ['epesi-logo'], 'style' => ['width' =>  '167px']])->add(/** @scrutinizer ignore-type */ [\atk4\ui\Image::class, url('logo')])->setStyle(['max-height' => '32px']);
Loading history...
Bug introduced by
The method setStyle() does not exist on atk4\ui\AbstractView. It seems like you code against a sub-type of atk4\ui\AbstractView such as atk4\ui\View. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
		\atk4\ui\View::addTo($this->menuTop, ['class' => ['epesi-logo'], 'style' => ['width' =>  '167px']])->add([\atk4\ui\Image::class, url('logo')])->/** @scrutinizer ignore-call */ setStyle(['max-height' => '32px']);
Loading history...
110
		
111
		if ($this->burger) {
112
			$this->burger = $this->menuTop->addItem(['class' => ['icon atk-leftMenuTrigger']]);
113
		}
114
		
115
		// home icon redirects to /home path
116
		// see \Epesi\Core\Controller::home
117
		$this->menuTop->addItem(['class' => ['icon epesi-home']], url('home'))->add([\atk4\ui\Icon::class, 'home']);
118
		
119
		// location bar
120
		$this->locationBar = $this->menuTop->add([\atk4\ui\View::class, ['ui' => 'epesi-location']]);
121
	}
122
123
	protected function initMenuRight()
124
	{
125
		if ($this->menuRight) return;
126
127
		$this->menuRight = $this->menuTop->add(new View\RightMenu(['ui' => false]), 'RightMenu')->addClass('right menu')->removeClass('item');
0 ignored issues
show
Bug introduced by
The method addClass() does not exist on atk4\ui\AbstractView. It seems like you code against a sub-type of atk4\ui\AbstractView such as atk4\ui\View. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

127
		$this->menuRight = $this->menuTop->add(new View\RightMenu(['ui' => false]), 'RightMenu')->/** @scrutinizer ignore-call */ addClass('right menu')->removeClass('item');
Loading history...
128
	}
129
	
130
    protected function initMenuLeft()
131
    {
132
        if ($this->menuLeft) return;
133
        
134
        $this->menuLeft = View\NavMenu::addTo($this, 'left vertical labeled sidebar', ['LeftMenu']);
0 ignored issues
show
Bug introduced by
'left vertical labeled sidebar' of type string is incompatible with the type array expected by parameter $seed of atk4\ui\AbstractView::addTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

134
        $this->menuLeft = View\NavMenu::addTo($this, /** @scrutinizer ignore-type */ 'left vertical labeled sidebar', ['LeftMenu']);
Loading history...
135
136
        if ($this->burger) {
137
        	$this->isMenuLeftVisible = $this->learn('menu', $this->isMenuLeftVisible);
138
        	
139
        	$this->burger->add([\atk4\ui\Icon::class, 'content'])->on('click', [
140
        			(new jQuery('.ui.left.sidebar'))->toggleClass('visible'),
0 ignored issues
show
Unused Code introduced by
The call to atk4\ui\Jquery::toggleClass() has too many arguments starting with 'visible'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

140
        			(new jQuery('.ui.left.sidebar'))->/** @scrutinizer ignore-call */ toggleClass('visible'),

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
141
        			(new jQuery('.epesi-logo'))->toggleClass('expanded'),
142
        			(new jQuery('body'))->toggleClass('atk-leftMenu-visible'),
143
        			\atk4\ui\JsCallback::addTo($this->burger)->set(function($jsCallback, $visible) {
0 ignored issues
show
Bug introduced by
$this->burger of type true is incompatible with the type object expected by parameter $parent of atk4\ui\AbstractView::addTo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

143
        			\atk4\ui\JsCallback::addTo(/** @scrutinizer ignore-type */ $this->burger)->set(function($jsCallback, $visible) {
Loading history...
144
        				$this->memorize('menu', filter_var($visible, FILTER_VALIDATE_BOOLEAN));
145
        			}, [$this->menuLeft->js(true)->hasClass('visible')])
146
        	]);
147
        }
148
    }
149
    
150
    protected function initActionBar()
151
    {
152
    	if (!$this->actionBar) {
153
    		$this->actionBar = View\ActionBar::addTo($this, [], ['ActionBar']);
154
    	}
155
    	
156
    	return $this;
157
    }
158
159
    public function renderView(): void
160
    {
161
    	if ($this->menuLeft && $this->isMenuLeftVisible) {
162
               $this->menuLeft->addClass('visible');
163
        }
164
        parent::renderView();
165
    }
166
}
167