From f2a5970ebcf36feea6c0a82fec778f0078b32134 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 17 Apr 2024 17:45:07 +0000 Subject: [PATCH] fix templates --- Admin/Install/Navigation.install.json | 15 ---- Admin/Install/db.json | 8 +++ Admin/Routes/Web/Backend.php | 24 ------- Controller/BackendController.php | 100 +++++++++++++++++++++----- Models/Asset.php | 2 + Models/AssetMapper.php | 1 + Theme/Backend/Lang/en.lang.php | 4 ++ Theme/Backend/asset-create.tpl.php | 91 +++++++++++++++++++++++ Theme/Backend/asset-view.tpl.php | 2 +- 9 files changed, 188 insertions(+), 59 deletions(-) create mode 100644 Theme/Backend/asset-create.tpl.php diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json index 2ebedd9..7227247 100644 --- a/Admin/Install/Navigation.install.json +++ b/Admin/Install/Navigation.install.json @@ -42,21 +42,6 @@ "permission": { "permission": 2, "type": null, "element": null }, "parent": 1006601001, "children": [] - }, - { - "id": 1006604001, - "pid": "/accounting/asset", - "type": 3, - "subtype": 1, - "name": "Entries", - "uri": "{/base}/accounting/asset/entry/list", - "target": "self", - "icon": null, - "order": 15, - "from": "AssetManagement", - "permission": { "permission": 2, "type": null, "element": null }, - "parent": 1006601001, - "children": [] } ] } diff --git a/Admin/Install/db.json b/Admin/Install/db.json index a4d3c55..a290f74 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -113,6 +113,14 @@ "null": true, "foreignTable": "unit", "foreignKey": "unit_id" + }, + "assetmgmt_asset_equipment": { + "name": "assetmgmt_asset_equipment", + "type": "INT", + "default": null, + "null": true, + "foreignTable": "equipmgmt_equipment", + "foreignKey": "equipmgmt_equipment_id" } } }, diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index 4589436..5fa3404 100644 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -55,30 +55,6 @@ return [ ], ], ], - '^/accounting/asset/entry/list(\?.*$|$)' => [ - [ - 'dest' => '\Modules\AssetManagement\Controller\BackendController:viewAssetManagementEntryList', - 'verb' => RouteVerb::GET, - 'active' => true, - 'permission' => [ - 'module' => BackendController::MODULE_NAME, - 'type' => PermissionType::READ, - 'state' => PermissionCategory::ASSET, - ], - ], - ], - '^/accounting/asset/entry/view(\?.*$|$)' => [ - [ - 'dest' => '\Modules\AssetManagement\Controller\BackendController:viewAssetManagementEntryView', - 'verb' => RouteVerb::GET, - 'active' => true, - 'permission' => [ - 'module' => BackendController::MODULE_NAME, - 'type' => PermissionType::READ, - 'state' => PermissionCategory::ASSET, - ], - ], - ], '^/accounting/asset/create(\?.*$|$)' => [ [ 'dest' => '\Modules\AssetManagement\Controller\BackendController:viewAssetManagementCreate', diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 2a3fdff..3b98528 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -18,6 +18,7 @@ use Modules\AssetManagement\Models\AssetMapper; use Modules\AssetManagement\Models\AssetTypeMapper; use Modules\AssetManagement\Models\Attribute\AssetAttributeTypeL11nMapper; use Modules\AssetManagement\Models\Attribute\AssetAttributeTypeMapper; +use Modules\Attribute\Models\NullAttributeType; use Modules\Media\Models\MediaMapper; use Modules\Media\Models\MediaTypeMapper; use Modules\Organization\Models\UnitMapper; @@ -105,14 +106,57 @@ final class BackendController extends Controller * @since 1.0.0 * @codeCoverageIgnore */ - public function viewAssetManagementAttributeType(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface + public function viewAssetManagementAssetTable(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); - $view->setTemplate('/Modules/AssetManagement/Theme/Backend/asset-view'); + $view->setTemplate('/Modules/AssetManagement/Theme/Backend/asset-table'); + $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1006601001, $request, $response); + + return $view; + } + + /** + * Routing end-point for application behavior. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return RenderableInterface + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + public function viewAssetManagementCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface + { + $view = new View($this->app->l11nManager, $request, $response); + $view->setTemplate('/Modules/AssetManagement/Theme/Backend/asset-create'); + $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1006601001, $request, $response); + + $view->data['hasEquipmentManagement'] = $this->app->moduleManager->isActive('EquipmentManagement'); + + return $view; + } + + /** + * Routing end-point for application behavior. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return RenderableInterface + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + public function viewAssetManagementAttributeType(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface + { + $view = new \Modules\Attribute\Theme\Backend\Components\AttributeTypeView($this->app->l11nManager, $request, $response); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1006601001, $request, $response); /** @var \Modules\Attribute\Models\AttributeType $attribute */ - $attribute = AssetAttributeTypeMapper::get() + $view->attribute = AssetAttributeTypeMapper::get() ->with('l11n') ->with('defaults') ->with('defaults/l11n') @@ -121,12 +165,11 @@ final class BackendController extends Controller ->where('defaults/l11n/language', [$response->header->l11n->language, null]) ->execute(); - $l11ns = AssetAttributeTypeL11nMapper::getAll() + $view->l11ns = AssetAttributeTypeL11nMapper::getAll() ->where('ref', $attribute->id) ->executeGetArray(); - $view->data['attribute'] = $attribute; - $view->data['l11ns'] = $l11ns; + $view->path = 'accounting/asset'; return $view; } @@ -150,7 +193,7 @@ final class BackendController extends Controller $view->setTemplate('/Modules/AssetManagement/Theme/Backend/asset-view'); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008402001, $request, $response); - $asset = AssetMapper::get() + $view->data['asset'] = AssetMapper::get() ->with('attributes') ->with('attributes/type') ->with('attributes/value') @@ -166,8 +209,6 @@ final class BackendController extends Controller ->where('attributes/value/l11n/language', [$response->header->l11n->language, null]) ->execute(); - $view->data['asset'] = $asset; - // @feature Create a new read mapper function that returns relation models instead of its own model // https://github.com/Karaka-Management/phpOMS/issues/320 $query = new Builder($this->app->dbPool->get()); @@ -181,29 +222,23 @@ final class BackendController extends Controller ->on(MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD, '=', MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['self']) ->leftJoin(MediaTypeMapper::TABLE) ->on(MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['external'], '=', MediaTypeMapper::TABLE . '.' . MediaTypeMapper::PRIMARYFIELD) - ->where(AssetMapper::HAS_MANY['files']['self'], '=', $asset->id) + ->where(AssetMapper::HAS_MANY['files']['self'], '=', $view->data['asset']->id) ->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'asset_profile_image'); - $assetImage = MediaMapper::get() + $view->data['assetImage'] = MediaMapper::get() ->with('types') ->where('id', $results) ->limit(1) ->execute(); - $view->data['assetImage'] = $assetImage; - - $assetTypes = AssetTypeMapper::getAll() + $view->data['types'] = AssetTypeMapper::getAll() ->with('l11n') ->where('l11n/language', $response->header->l11n->language) ->executeGetArray(); - $view->data['types'] = $assetTypes; - - $units = UnitMapper::getAll() + $view->data['units'] = UnitMapper::getAll() ->executeGetArray(); - $view->data['units'] = $units; - $view->data['attributeView'] = new \Modules\Attribute\Theme\Backend\Components\AttributeView($this->app->l11nManager, $request, $response); $view->data['attributeView']->data['default_localization'] = $this->app->l11nServer; @@ -212,4 +247,31 @@ final class BackendController extends Controller return $view; } + + /** + * Routing end-point for application behavior. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return RenderableInterface Returns a renderable object + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + public function viewAssetManagementAttributeTypeList(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface + { + $view = new \Modules\Attribute\Theme\Backend\Components\AttributeTypeListView($this->app->l11nManager, $request, $response); + $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1006601001, $request, $response); + + $view->attributes = AssetAttributeTypeMapper::getAll() + ->with('l11n') + ->where('l11n/language', $response->header->l11n->language) + ->executeGetArray(); + + $view->path = 'accounting/asset'; + + return $view; + } } diff --git a/Models/Asset.php b/Models/Asset.php index 9577bef..46bafe5 100644 --- a/Models/Asset.php +++ b/Models/Asset.php @@ -44,6 +44,8 @@ class Asset implements \JsonSerializable public \DateTimeImmutable $createdAt; + public int $equipment = 0; + /** * Constructor. * diff --git a/Models/AssetMapper.php b/Models/AssetMapper.php index 799e5b0..6a35b6f 100644 --- a/Models/AssetMapper.php +++ b/Models/AssetMapper.php @@ -45,6 +45,7 @@ final class AssetMapper extends DataMapperFactory 'assetmgmt_asset_status' => ['name' => 'assetmgmt_asset_status', 'type' => 'int', 'internal' => 'status'], 'assetmgmt_asset_info' => ['name' => 'assetmgmt_asset_info', 'type' => 'string', 'internal' => 'info'], 'assetmgmt_asset_unit' => ['name' => 'assetmgmt_asset_unit', 'type' => 'int', 'internal' => 'unit'], + 'assetmgmt_asset_equipment' => ['name' => 'assetmgmt_asset_equipment', 'type' => 'int', 'internal' => 'equipment'], 'assetmgmt_asset_type' => ['name' => 'assetmgmt_asset_type', 'type' => 'int', 'internal' => 'type'], 'assetmgmt_asset_responsible' => ['name' => 'assetmgmt_asset_responsible', 'type' => 'int', 'internal' => 'responsible'], 'assetmgmt_asset_created_at' => ['name' => 'assetmgmt_asset_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index b8ce2bf..b34df07 100644 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -14,6 +14,10 @@ declare(strict_types=1); return ['AssetManagement' => [ 'Assets' => 'Assets', + 'Asset' => 'Asset', + 'Equipment' => 'Equipment', + 'CreateEquipment' => 'Create Equipment', + 'Number' => 'Number', 'Status' => 'Status', 'Name' => 'Name', 'Type' => 'Type', diff --git a/Theme/Backend/asset-create.tpl.php b/Theme/Backend/asset-create.tpl.php new file mode 100644 index 0000000..81c3de3 --- /dev/null +++ b/Theme/Backend/asset-create.tpl.php @@ -0,0 +1,91 @@ +data['nav']->render(); +?> +
+
+
+
+
getHtml('Asset'); ?>
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ + data['hasEquipmentManagement'] ?? false) : ?> +
+ + +
+ +
+ +
+ +
+
+ +
+
+
+
+
diff --git a/Theme/Backend/asset-view.tpl.php b/Theme/Backend/asset-view.tpl.php index 1d03aa6..7e92e16 100644 --- a/Theme/Backend/asset-view.tpl.php +++ b/Theme/Backend/asset-view.tpl.php @@ -36,7 +36,7 @@ echo $this->data['nav']->render();