-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathUI5View.php
More file actions
188 lines (160 loc) · 5.31 KB
/
UI5View.php
File metadata and controls
188 lines (160 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
namespace exface\UI5Facade;
use exface\UI5Facade\Facades\Interfaces\UI5ControllerInterface;
use exface\UI5Facade\Facades\Interfaces\UI5ViewInterface;
use exface\UI5Facade\Facades\Elements\UI5AbstractElement;
use exface\Core\DataTypes\StringDataType;
use exface\UI5Facade\Facades\Interfaces\UI5ModelInterface;
class UI5View implements UI5ViewInterface
{
private $isBuilt = false;
private $contentJs = null;
private $viewName = null;
private $webapp = null;
private $rootElement = null;
private $controller = null;
private $model = null;
public function __construct(Webapp $webapp, string $viewName, ui5AbstractElement $rootElement)
{
$this->webapp = $webapp;
$this->viewName = $viewName;
$this->rootElement = $rootElement;
}
protected function buildJsContent(): string
{
if ($this->isBuilt === false || $this->contentJs === null) {
$this->isBuilt = true;
// Trim off things like line brea in order to make the script concatenatable (e.g. return ...)
$this->contentJs = trim($this->getRootElement()->buildJsConstructor());
}
return $this->contentJs;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ViewInterface::isBuilt()
*/
public function isBuilt(): bool
{
return $this->isBuilt;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ViewInterface::getName()
*/
public function getName(): string
{
return $this->viewName;
}
public function getRouteName(): string
{
return StringDataType::substringAfter($this->getName(), $this->getController()->getWebapp()->getComponentName() . '.view.');
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ViewInterface::getPath()
*/
public function getPath(bool $relativeToAppRoot = false) : string
{
if ($relativeToAppRoot === true) {
$name = StringDataType::substringAfter($this->getName(), $this->getController()->getWebapp()->getComponentName() . '.');
} else {
$name = $this->getName();
}
return $this->getController()->getWebapp()->convertNameToPath($name, $this->getController()->getWebapp()->getViewFileSuffix());
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ViewInterface::getRootElement()
*/
public function getRootElement(): ui5AbstractElement
{
return $this->rootElement;
}
public function buildJsView(): string
{
$controllerName = $this->getController() === null ? 'null' : '"' . $this->getController()->getName() . '"';
return <<<JS
sap.ui.jsview("{$this->getName()}", {
/** Specifies the Controller belonging to this View.
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
*/
getControllerName : function() {
return {$controllerName};
},
/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.
* Since the Controller is given to this method, its event handlers can be attached right away.
*/
createContent : function(oController) {
return {$this->buildJsContent()}
}
});
JS;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ViewInterface::getController()
*/
public function getController(): ?ui5ControllerInterface
{
return $this->controller;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ViewInterface::setController()
*/
public function setController(ui5ControllerInterface $controller): ui5ViewInterface
{
$this->controller = $controller;
return $this;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ViewInterface::buildJsViewGetter()
*/
public function buildJsViewGetter(ui5AbstractElement $fromElement) : string
{
return "{$this->getController()->buildJsComponentGetter($fromElement)}.findViewOfControl(sap.ui.getCore().byId('{$fromElement->getId()}'))";
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ViewInterface::getModel()
*/
public function getModel(string $name = '') : ui5ModelInterface
{
if ($this->model === null) {
$this->model = $this->webapp->getViewModel($this, $name);
}
return $this->model;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ViewInterface::isWebAppRoot()
*/
public function isWebAppRoot() : bool
{
$rootWidget = $this->getRootElement()->getWidget();
return $rootWidget->hasParent() === false && $rootWidget->getPage()->is($this->webapp->getRootPage());
}
/**
* {@inheritDoc}
* @see UI5ViewInterface::getCaption()
*/
public function getCaption() : string
{
$widget = $this->getRootElement()->getWidget();
$widgetCaption = $widget->getCaption();
if ($widgetCaption) {
return $widgetCaption;
}
return $widget->getPage()->getName() ?? '';
}
}