From 92d74a7f3fb652d20a1039dbc6956e38e86debfa Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 10 Feb 2023 20:48:24 +0200 Subject: [PATCH] Fetch MVEA types as part of the REST API responses --- app/src/Controller/ApiV2Controller.php | 15 ++++++++++++++- .../js/comanage/components/mvea/mvea-item.js | 14 +++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/src/Controller/ApiV2Controller.php b/app/src/Controller/ApiV2Controller.php index 3553dca69..78c5fb7c8 100644 --- a/app/src/Controller/ApiV2Controller.php +++ b/app/src/Controller/ApiV2Controller.php @@ -280,7 +280,20 @@ public function index() { if(!empty($link->attr) && !empty($link->value)) { $query = $query->where([$this->$modelsName->getAlias().'.'.$link->attr => $link->value]); } - + + // This will produce a nested object which is very useful for vue integration + if($this->request->getQuery('extended') !== null) { + $modelContain = []; + $associations = $this->$modelsName->associations(); + foreach($associations->getByType(['BelongsTo']) as $a) { + $modelContain[] = $a->getClassName(); + } + + if(!empty($modelContain)) { + $query = $query->contain($modelContain); + } + } + if($modelsName == 'AuthenticationEvents') { // Special case for filtering on authenticated identifier. There is a // similar filter in AuthenticationEventsController::beforeFilter. diff --git a/app/webroot/js/comanage/components/mvea/mvea-item.js b/app/webroot/js/comanage/components/mvea/mvea-item.js index 5c4d8ee6d..134060ffe 100644 --- a/app/webroot/js/comanage/components/mvea/mvea-item.js +++ b/app/webroot/js/comanage/components/mvea/mvea-item.js @@ -50,7 +50,7 @@ export default {
{{ this.txt.primary }} - type: {{ this.mvea.type_id }} + {{ this.mvea.type.display_name }} {{ calcLangHR(this.mvea.language) }}
@@ -61,7 +61,7 @@ export default {
{{ this.txt.unverified }} - type: {{ this.mvea.type_id }} + {{ this.mvea.type.display_name }}
@@ -71,7 +71,7 @@ export default {
- type: {{ this.mvea.type_id }} + {{ this.mvea.type.display_name }}
@@ -97,7 +97,7 @@ export default {
- type: {{ this.mvea.type_id }} + {{ this.mvea.type.display_name }}
@@ -106,7 +106,7 @@ export default { {{ this.mvea.country_code }} {{ this.mvea.area_code }} {{ this.mvea.number }}
- type: {{ this.mvea.type_id }} + {{ this.mvea.type.display_name }}
@@ -116,7 +116,7 @@ export default { north_east
- type: {{ this.mvea.type_id }} + {{ this.mvea.type.display_name }}
@@ -125,7 +125,7 @@ export default { {{ this.mvea.type_id }}
- type: {{ this.mvea.type_id }} + {{ this.mvea.type.display_name }}
`