mirror of
https://github.com/Karaka-Management/oms-Help.git
synced 2026-01-11 04:48:41 +00:00
Test fixes
This commit is contained in:
parent
be2120992d
commit
e478069851
|
|
@ -167,6 +167,12 @@ final class BackendController extends Controller
|
|||
|
||||
$view->data['modules'] = $this->app->moduleManager->getInstalledModules();
|
||||
|
||||
foreach ($view->data['modules'] as $idx => $_) {
|
||||
if (!\is_file(__DIR__ . '/../../' . $idx . '/Docs/Help/en/introduction.md')) {
|
||||
unset($view->data['modules'][$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
$tableView = new TableView($this->app->l11nManager, $request, $response);
|
||||
$tableView->module = 'Help';
|
||||
$tableView->theme = 'Backend';
|
||||
|
|
@ -230,6 +236,18 @@ final class BackendController extends Controller
|
|||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show module ER diagram
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param array $data Generic data
|
||||
*
|
||||
* @return RenderableInterface
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function viewHelpModuleER(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
||||
{
|
||||
$active = $this->app->moduleManager->getActiveModules();
|
||||
|
|
@ -260,15 +278,40 @@ final class BackendController extends Controller
|
|||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create ER diagram for module using Mappers (*Mapper.php) and database definition (db.json)
|
||||
*
|
||||
* @param string $module Module name
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createERFromMappers(string $module) : string
|
||||
{
|
||||
$mappers = \scandir(__DIR__ . '/../../../Modules/' . $module . '/Models');
|
||||
if (!\is_array($mappers)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$toParse = "```mermaid\n";
|
||||
$toParse .= "erDiagram\n";
|
||||
|
||||
$indent = 4;
|
||||
|
||||
$db = [];
|
||||
if (\is_file(__DIR__ . '/../../../Modules/' . $module . '/Admin/Install/db.json')) {
|
||||
$dbContent = \file_get_contents(__DIR__ . '/../../../Modules/' . $module . '/Admin/Install/db.json');
|
||||
|
||||
if ($dbContent !== false) {
|
||||
$db = \json_decode($dbContent, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!\is_array($db)) {
|
||||
$db = [];
|
||||
}
|
||||
|
||||
foreach ($mappers as $mapper) {
|
||||
if (!\str_ends_with($mapper, 'Mapper.php')) {
|
||||
continue;
|
||||
|
|
@ -285,37 +328,122 @@ final class BackendController extends Controller
|
|||
|
||||
$toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . " {\n";
|
||||
|
||||
foreach ($class::COLUMNS as $data) {
|
||||
$toParse .= \str_repeat(' ', $indent + 4) . $data['type'] . ' ' . \str_replace('/', '_', $data['internal']) . "\n";
|
||||
foreach ($class::COLUMNS as $column => $data) {
|
||||
$toParse .= \str_repeat(' ', $indent + 4) . $data['type'] . ' ' . \str_replace('/', '_', $data['internal']);
|
||||
|
||||
$relations = [];
|
||||
if ($class::PRIMARYFIELD === $column) {
|
||||
$relations[] = 'PK';
|
||||
}
|
||||
|
||||
if (isset($db[$class::TABLE]['fields'][$column]['foreignTable'])) {
|
||||
$relations[] = 'FK';
|
||||
}
|
||||
|
||||
if (!empty($relations)) {
|
||||
$toParse .= ' ' . \implode(', ', $relations);
|
||||
}
|
||||
|
||||
if (isset($db[$class::TABLE]['fields'][$column]['comment'])) {
|
||||
$toParse .= ' "' . $db[$class::TABLE]['fields'][$column]['comment'] . '"';
|
||||
}
|
||||
|
||||
$toParse .= "\n";
|
||||
}
|
||||
|
||||
foreach ($class::HAS_MANY as $name => $data) {
|
||||
$toParse .= \str_repeat(' ', $indent + 4) . 'array ' . \str_replace('/', '_', $name) . "\n";
|
||||
$toParse .= \str_repeat(' ', $indent + 4) . 'array ' . \str_replace('/', '_', $name);
|
||||
|
||||
$relations = [];
|
||||
if (isset($db[$data['table']]['fields'][$data['self']]['foreignTable'])) {
|
||||
$relations[] = 'FK';
|
||||
}
|
||||
|
||||
if (!empty($relations)) {
|
||||
$toParse .= ' ' . \implode(', ', $relations);
|
||||
}
|
||||
|
||||
if (isset($db[$data['table']]['fields'][$data['self']]['comment'])) {
|
||||
$toParse .= ' "' . $db[$data['table']]['fields'][$data['self']]['comment'] . '"';
|
||||
}
|
||||
|
||||
$toParse .= "\n";
|
||||
}
|
||||
|
||||
$toParse .= \str_repeat(' ', $indent) . "}\n";
|
||||
|
||||
foreach ($class::BELONGS_TO as $name => $data) {
|
||||
$childMapper = \substr($data['mapper'], \strrpos($data['mapper'], '\\') + 1, -6);
|
||||
$toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--o| ' . $childMapper . " : references\n";
|
||||
$toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--o| ' . $childMapper . " : \"belongs to\"\n";
|
||||
}
|
||||
|
||||
foreach ($class::OWNS_ONE as $name => $data) {
|
||||
$childMapper = \substr($data['mapper'], \strrpos($data['mapper'], '\\') + 1, -6);
|
||||
$toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--o| ' . $childMapper . " : references\n";
|
||||
$toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--o| ' . $childMapper . " : owns\n";
|
||||
}
|
||||
|
||||
foreach ($class::HAS_MANY as $name => $data) {
|
||||
$childMapper = \substr($data['mapper'], \strrpos($data['mapper'], '\\') + 1, -6);
|
||||
$toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--|{ ' . $childMapper . " : references\n";
|
||||
$toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--|{ ' . $childMapper . " : has\n";
|
||||
}
|
||||
|
||||
foreach ($db[$class::TABLE]['fields'] as $column => $field) {
|
||||
if (!\is_array($field)
|
||||
|| !isset($field['foreignTable'])
|
||||
|| !isset($db[$field['foreignTable']])
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($class::OWNS_ONE as $name => $data) {
|
||||
if ($data['external'] === $field['foreignKey']) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($class::BELONGS_TO as $name => $data) {
|
||||
if ($data['external'] === $field['foreignKey']) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($class::HAS_MANY as $name => $data) {
|
||||
if ($data['external'] === $field['foreignKey']) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($mappers as $mapper2) {
|
||||
if ($mapper === $mapper2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!\str_ends_with($mapper2, 'Mapper.php')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$childMapper = \substr($mapper2, 0, -10);
|
||||
|
||||
$class2 = '\\Modules\\' . $module . '\\Models\\' . \substr($mapper2, 0, -4);
|
||||
|
||||
if (!empty($class2::MODEL)
|
||||
&& \is_file(__DIR__ . '/../../../Modules/' . $module . '/Models/' . \substr($class2::MODEL, \strrpos($class2::MODEL, '\\') + 1) . 'Mapper.php')
|
||||
&& \substr($class2::MODEL, \strrpos($class2::MODEL, '\\') + 1) !== \substr($mapper2, 0, -10)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($class2::TABLE === $field['foreignTable']
|
||||
&& \stripos($toParse, \substr($mapper, 0, -10) . ' }|--|{ ' . $childMapper) === false
|
||||
&& \stripos($toParse, $childMapper . ' }|--|{ ' . \substr($mapper, 0, -10)) === false
|
||||
) {
|
||||
$toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--|{ ' . $childMapper . " : references\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$toParse .= "\n```\n";
|
||||
|
||||
//echo $toParse;
|
||||
|
||||
return $toParse;
|
||||
return $toParse . "\n```\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ omsApp.Modules.Help = class {
|
|||
svg.html('<g>' + svg.html() + '</g>');
|
||||
const inner = svg.select('g');
|
||||
const zoom = d3.zoom().on('zoom', function(event) {
|
||||
inner.attr('transform', event.transform);
|
||||
inner.attr('transform', event.transform);
|
||||
});
|
||||
svg.call(zoom);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# Developer Content
|
||||
|
||||
* [Documentation]({%}&page=Dev/documentation)
|
||||
* [Structure]({%}&page=Dev/structure)
|
||||
|
|
|
|||
0
Docs/Help/de/documentation.md → Docs/Dev/en/documentation.md
Executable file → Normal file
0
Docs/Help/de/documentation.md → Docs/Dev/en/documentation.md
Executable file → Normal file
|
|
@ -1,5 +0,0 @@
|
|||
# Structure
|
||||
|
||||
## ER
|
||||
|
||||

|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# User Content
|
||||
|
||||
* [Documentation]({%}&page=Help/documentation)
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
# Introduction
|
||||
|
||||
The **Help** module is one of the essential core modules that is always required. This module allows other modules to provide helpful documentation for users, administrators and developers.
|
||||
|
||||
## Target Group
|
||||
|
||||
The target group for this module is everyone.
|
||||
|
||||
# Setup
|
||||
|
||||
This module doesn't have any additional setup requirements since it is installed during the application install process. This module cannot be uninstalled if it is manually deleted from the hard drive please manually download the module from the page and put it into the `Modules/` directory.
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# User Content
|
||||
|
||||
* [Documentation]({%}&page=Help/documentation)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# Documentation
|
||||
|
||||
A documentation can be added to every module by adding the `Docs/Help/{lang}` directory in the module. The language directory needs to be a 2 character ISO code. Inside of this directory you can add/find all the documentation files provided by the module.
|
||||
|
||||
Mandatory files are a `SUMMARY.md` file which contains the list of all documents and a `introduction.md` file which contains a general description of the module.
|
||||
|
||||
## SUMMARY.md example
|
||||
|
||||
```md
|
||||
# Table of Contents
|
||||
|
||||
* [Link Name 1]({%}&page=Help/document_name_1)
|
||||
* [Link Name 2]({%}&page=Help/document_name_2)
|
||||
* [Link Name 3]({%}&page=Help/document_name_3)
|
||||
```
|
||||
|
||||

|
||||
|
|
@ -8,4 +8,4 @@ The target group for this module is everyone.
|
|||
|
||||
# Setup
|
||||
|
||||
This module doesn't have any additional setup requirements since it is installed during the application install process. This module cannot be uninstalled if it is manually deleted from the hard drive please manually download the module from the page and put it into the `Modules/` directory.
|
||||
This module doesn't have any additional setup requirements. This module cannot be uninstalled if it is manually deleted from the hard drive please manually download the module from the page and put it into the `Modules/` directory.
|
||||
7
Docs/Help/img.json
Normal file
7
Docs/Help/img.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[
|
||||
[
|
||||
"/?darkmode",
|
||||
"/html/body",
|
||||
"/../User-Guide/ui/img/darkmode.png"
|
||||
]
|
||||
]
|
||||
Loading…
Reference in New Issue
Block a user