Skip to content

Commit 168311a

Browse files
committed
!410 - Fixed bugs. Fixed views, subviews, packages.
1 parent 9aba571 commit 168311a

File tree

14 files changed

+456
-167
lines changed

14 files changed

+456
-167
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ external/cache/*
1818
external/base.lock
1919
ignore/*
2020
composer.json
21-
apps/Dash/Packages/System/Api/CallStats/*
21+
apps/Core/Packages/System/Api/CallStats/*
2222
system/.keys
2323
system/.dbkeys
2424
composer

apps/Core/Packages/Devtools/Modules/DevtoolsModules.php

Lines changed: 137 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ class DevtoolsModules extends BasePackage
3939

4040
public function addModule($data)
4141
{
42-
if (!checkCtype($data['name'], 'alpha', [''])) {
42+
if (isset($data['module_type']) &&
43+
$data['module_type'] === 'components'
44+
) {
45+
$ignoreChars = [' '];
46+
} else {
47+
$ignoreChars = [''];
48+
}
49+
50+
if (!checkCtype($data['name'], 'alpha', $ignoreChars)) {
4351
$this->addResponse('Name cannot have special chars or numbers.', 1);
4452

4553
return false;
@@ -120,13 +128,20 @@ public function addModule($data)
120128
}
121129

122130
try {
123-
if ($this->modules->{$data['module_type']}->add($data) &&
124-
$this->updateModuleJson($data) &&
125-
$this->generateNewFiles($data)
131+
if ($this->updateModuleJson($data) &&
132+
$this->generateNewFiles($data) &&
133+
$this->modules->{$data['module_type']}->add($data)
126134
) {
127135
if ($data['createrepo'] == true) {
128-
if (!$this->checkRepo($data)) {
129-
$newRepo = $this->createRepo($data);
136+
if ($data['module_type'] === 'views' && $data['base_view_module_id'] == 0) {//Create public repository as well
137+
if (!$this->checkRepo($data)) {
138+
$newRepo['base'] = $this->createRepo($data);
139+
}
140+
141+
$data['repo'] = $data['repo'] . '-public';
142+
if (!$this->checkRepo($data)) {
143+
$newRepo['public'] = $this->createRepo($data);
144+
}
130145

131146
$this->addResponse('Module added & created new repo.',
132147
0,
@@ -138,6 +153,21 @@ public function addModule($data)
138153
);
139154

140155
return;
156+
} else {
157+
if (!$this->checkRepo($data)) {
158+
$newRepo = $this->createRepo($data);
159+
160+
$this->addResponse('Module added & created new repo.',
161+
0,
162+
[
163+
'newFiles' => $this->newFiles,
164+
'newDirs' => $this->newDirs,
165+
'newRepo' => $newRepo
166+
]
167+
);
168+
169+
return;
170+
}
141171
}
142172
}
143173

@@ -161,7 +191,15 @@ public function addModule($data)
161191

162192
public function updateModule($data)
163193
{
164-
if (!checkCtype($data['name'], 'alpha', [''])) {
194+
if (isset($data['module_type']) &&
195+
$data['module_type'] === 'components'
196+
) {
197+
$ignoreChars = [' '];
198+
} else {
199+
$ignoreChars = [''];
200+
}
201+
202+
if (!checkCtype($data['name'], 'alpha', $ignoreChars)) {
165203
$this->addResponse('Name cannot have special chars or numbers.', 1);
166204

167205
return false;
@@ -211,8 +249,8 @@ public function updateModule($data)
211249

212250
$module = array_merge($module, $data);
213251

214-
if ($this->modules->{$data['module_type']}->update($module) &&
215-
$this->updateModuleJson($data)
252+
if ($this->updateModuleJson($data) &&
253+
$this->modules->{$data['module_type']}->update($module)
216254
) {
217255
if ($data['module_type'] === 'components') {
218256
$this->addUpdateComponentMenu($data);
@@ -259,9 +297,8 @@ public function removeModule($data)
259297
return false;
260298
}
261299

262-
263-
if ($this->modules->{$data['module_type']}->remove($module['id'])) {
264-
$this->addResponse('Removed module ' . $module['display_name'] . ' from DB. Remove files manually...');
300+
if ($module && $this->modules->{$data['module_type']}->remove($module['id'])) {
301+
$this->addResponse('Removed module from DB. Remove files manually...');
265302
} else {
266303
$this->addResponse('Error removing module.', 1);
267304
}
@@ -879,6 +916,36 @@ protected function generateNewComponentsFiles($moduleFilesLocation, $data)
879916
return true;
880917
}
881918

919+
protected function generateNewMiddlewaresFiles($moduleFilesLocation, $data)
920+
{
921+
//Package File
922+
try {
923+
$file = $this->localContent->read('apps/Core/Packages/Devtools/Modules/Files/Middleware.txt');
924+
} catch (FilesystemException | UnableToReadFile $exception) {
925+
$this->addResponse('Unable to read module base package file.');
926+
927+
return false;
928+
}
929+
930+
$data['class'] = explode('\\', $data['class']);
931+
unset($data['class'][$this->helper->lastKey($data['class'])]);
932+
$namespaceClass = implode('\\', $data['class']);
933+
934+
$file = str_replace('"NAMESPACE"', 'namespace ' . $namespaceClass . ';', $file);
935+
$file = str_replace('"MIDDLEWARENAME"', $data['name'], $file);
936+
$fileName = $moduleFilesLocation . $data['name'] . '.php';
937+
938+
try {
939+
$this->localContent->write($fileName, $file);
940+
941+
array_push($this->newFiles, $fileName);
942+
} catch (FilesystemException | UnableToWriteFile $exception) {
943+
$this->addResponse('Unable to write module middleware file');
944+
945+
return false;
946+
}
947+
}
948+
882949
protected function generateNewPackagesFiles($moduleFilesLocation, $data)
883950
{
884951
//Package File
@@ -909,7 +976,7 @@ protected function generateNewPackagesFiles($moduleFilesLocation, $data)
909976

910977
array_push($this->newFiles, $fileName);
911978
} catch (FilesystemException | UnableToWriteFile $exception) {
912-
$this->addResponse('Unable to write module component file');
979+
$this->addResponse('Unable to write module package file');
913980

914981
return false;
915982
}
@@ -953,7 +1020,7 @@ protected function generateNewPackagesInstallFiles($data, $moduleFilesLocation)
9531020
$this->localContent->write($fileName, $file);
9541021
array_push($this->newFiles, $fileName);
9551022
} catch (FilesystemException | UnableToWriteFile $exception) {
956-
$this->addResponse('Unable to write module component file');
1023+
$this->addResponse('Unable to write module package file');
9571024

9581025
return false;
9591026
}
@@ -968,7 +1035,7 @@ protected function generateNewPackagesInstallFiles($data, $moduleFilesLocation)
9681035
}
9691036

9701037
if ($data['category'] !== str_starts_with($data['category'], 'basepackages') && $data['category'] !== 'providers') {
971-
$moduleFilesLocation = str_replace('/Schema', '', ucfirst($moduleFilesLocation));
1038+
$moduleFilesLocation = str_replace('/Schema', '', $moduleFilesLocation);
9721039
$fileName = $moduleFilesLocation . '/' . 'Package.php';
9731040
$moduleFilesLocationClass = str_replace('/', '\\', ucfirst($moduleFilesLocation));
9741041
$moduleFilesLocationClass = str_replace('\\' . $data['name'], '', $moduleFilesLocationClass);
@@ -980,7 +1047,7 @@ protected function generateNewPackagesInstallFiles($data, $moduleFilesLocation)
9801047
$this->localContent->write($fileName, $file);
9811048
array_push($this->newFiles, $fileName);
9821049
} catch (FilesystemException | UnableToWriteFile $exception) {
983-
$this->addResponse('Unable to write module component file');
1050+
$this->addResponse('Unable to write module package file');
9841051

9851052
return false;
9861053
}
@@ -1039,7 +1106,7 @@ protected function generateNewPackagesModelFiles($data, $moduleFilesLocation)
10391106
$this->localContent->write($fileName, $file);
10401107
array_push($this->newFiles, $fileName);
10411108
} catch (FilesystemException | UnableToWriteFile $exception) {
1042-
$this->addResponse('Unable to write module component file');
1109+
$this->addResponse('Unable to write module package file');
10431110

10441111
return false;
10451112
}
@@ -1051,6 +1118,7 @@ protected function generateNewViewsFiles($moduleFilesLocation, $data)
10511118
{
10521119
if ($data['base_view_module_id'] == 0) {
10531120
$modulePublicFilesLocation = $this->getNewFilesLocation($data, true);
1121+
10541122
try {
10551123
if (is_string($data['settings'])) {
10561124
$data['settings'] = $this->helper->decode($data['settings'], true);
@@ -1060,25 +1128,41 @@ protected function generateNewViewsFiles($moduleFilesLocation, $data)
10601128
array_push($this->newDirs, $moduleFilesLocation . 'html');
10611129
$this->localContent->createDirectory($moduleFilesLocation . 'html/layouts');
10621130
array_push($this->newDirs, $moduleFilesLocation . 'html/layouts');
1131+
$this->localContent->createDirectory($moduleFilesLocation . 'html/common');
1132+
array_push($this->newDirs, $moduleFilesLocation . 'html/common');
1133+
$this->localContent->write($moduleFilesLocation . 'html/common/.gitkeep', '');
1134+
1135+
$file = $this->localContent->read('apps/Core/Packages/Devtools/Modules/Files/ViewsLayout.txt');
10631136

1064-
$file = $this->localContent->read('apps/Core/Packages/Devtools/Modules/Files/layout.txt');
10651137
foreach ($data['settings']['layouts'] as $layout) {
10661138
$this->localContent->write($moduleFilesLocation . 'html/layouts/' . $layout['view'] . '.html', $file);
10671139
array_push($this->newFiles, $moduleFilesLocation . 'html/layouts/' . $layout['view'] . '.html');
10681140
}
10691141

10701142
$this->localContent->createDirectory($modulePublicFilesLocation . 'css');
10711143
array_push($this->newDirs, $modulePublicFilesLocation . 'css');
1144+
$this->localContent->write($modulePublicFilesLocation . 'css/.gitkeep', '');
1145+
10721146
$this->localContent->createDirectory($modulePublicFilesLocation . 'fonts');
10731147
array_push($this->newDirs, $modulePublicFilesLocation . 'fonts');
1148+
$this->localContent->write($modulePublicFilesLocation . 'fonts/.gitkeep', '');
1149+
10741150
$this->localContent->createDirectory($modulePublicFilesLocation . 'images');
10751151
array_push($this->newDirs, $modulePublicFilesLocation . 'images');
1152+
$this->localContent->write($modulePublicFilesLocation . 'images/.gitkeep', '');
1153+
10761154
$this->localContent->createDirectory($modulePublicFilesLocation . 'js');
10771155
array_push($this->newDirs, $modulePublicFilesLocation . 'js');
1156+
$this->localContent->write($modulePublicFilesLocation . 'js/.gitkeep', '');
1157+
10781158
$this->localContent->createDirectory($modulePublicFilesLocation . 'sounds');
10791159
array_push($this->newDirs, $modulePublicFilesLocation . 'sounds');
1080-
} catch (FilesystemException | UnableToCreateDirectory $exception) {
1081-
$this->addResponse('Unable to create view directories in public folder.');
1160+
$this->localContent->write($modulePublicFilesLocation . 'sounds/.gitkeep', '');
1161+
1162+
$file = $this->localContent->read('apps/Core/Packages/Devtools/Modules/Files/ViewsGitignore.txt');
1163+
$this->localContent->write($moduleFilesLocation . '.gitignore', $file);
1164+
} catch (FilesystemException | UnableToCreateDirectory | UnableToWriteFile | UnableToReadFile $exception) {
1165+
$this->addResponse('Unable to create view directories or read/write module base html files in public folder.');
10821166

10831167
return false;
10841168
}
@@ -1890,6 +1974,7 @@ protected function checkRepo($data)
18901974
return false;
18911975
}
18921976
}
1977+
18931978
if (isset($repo)) {
18941979
return $repo;
18951980
}
@@ -2101,14 +2186,38 @@ public function generateModuleRepoUrl($data)
21012186
}
21022187
} else {
21032188
$this->validation->add('name', PresenceOf::class, ["message" => "Please provide name."]);
2189+
21042190
if ($data['module_type'] !== 'bundles' && $data['module_type'] !== 'apps_types') {
21052191
$this->validation->add('category', PresenceOf::class, ["message" => "Please provide category."]);
21062192
}
21072193

2194+
if ($data['module_type'] === 'views' && isset($data['subview']) && $data['subview'] == 'true') {
2195+
$this->validation->add('base_view_module_id', PresenceOf::class, ["message" => "Please provide main view module id."]);
2196+
}
2197+
21082198
if (!$this->validateData($data)) {
21092199
return false;
21102200
}
2111-
if (!checkCtype($data['name'], 'alpha', [''])) {
2201+
2202+
if ($data['module_type'] === 'views' &&
2203+
strtolower($data['name']) === 'public'
2204+
) {
2205+
$this->addResponse('Public keyword for module type views is reserved', 1);
2206+
2207+
return false;
2208+
}
2209+
2210+
if ($data['module_type'] === 'views' && isset($data['subview']) && $data['subview'] == 'true') {
2211+
$baseView = $this->modules->views->getViewById($data['base_view_module_id']);
2212+
}
2213+
2214+
if ($data['module_type'] === 'components') {
2215+
$ignoreChars = [' '];
2216+
} else {
2217+
$ignoreChars = [''];
2218+
}
2219+
2220+
if (!checkCtype($data['name'], 'alpha', $ignoreChars)) {
21122221
$this->addResponse('Name cannot have special chars or numbers.', 1);
21132222

21142223
return false;
@@ -2140,7 +2249,13 @@ public function generateModuleRepoUrl($data)
21402249
$name = preg_split('/(?=[A-Z])/', $name);
21412250

21422251
if ($data['module_type'] !== 'bundles') {
2143-
$url .= '/' . $data['app_type'] . '-' . $data['module_type'] . '-' . $data['category'] . '-' . strtolower(implode('', $name));
2252+
if (isset($baseView) && isset($baseView['name'])) {
2253+
$name = strtolower($baseView['name'] . '-' . implode('', $name));
2254+
} else {
2255+
$name = strtolower(implode('', $name));
2256+
}
2257+
2258+
$url .= '/' . $data['app_type'] . '-' . $data['module_type'] . '-' . $data['category'] . '-' . $name;
21442259
} else {
21452260
$url .= '/' . $data['app_type'] . '-' . $data['module_type'] . '-' . strtolower(implode('', $name));
21462261
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#Ignore everything else in the html folder to avoid adding subview. Change file content as needed
2+
html/*
3+
#Only include the following. Change file content as needed
4+
!html/
5+
!html/layouts/
6+
!html/common/
7+
!README.md
8+
!view.json

apps/Core/Packages/Devtools/Modules/Files/layout.txt renamed to apps/Core/Packages/Devtools/Modules/Files/ViewsLayout.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- htmlhint tag-pair:false -->
2-
{{get_doctype()}}
2+
{{assets.get('doctype').getCodes()[0].getContent()}}
33
<html lang="en">
44
<head>
55
{% for meta in assets.get('meta').getCodes() %}
@@ -9,7 +9,7 @@
99
<meta name="{{meta.getType()}}" content="{{meta.getContent()}}">
1010
{% endif %}
1111
{% endfor %}
12-
{{renderTitle()}}
12+
{{assets.get('title').getCodes()[0].getContent()}}
1313
{{assets.outputCss('headLinks')}}
1414
{{assets.outputJs('headJs')}}
1515
</head>

0 commit comments

Comments
 (0)