diff --git a/rest/index.php b/rest/index.php index 4aaa230fdc250a1c9b94a8773dc6e481a0dada0f..76dd3b77b92e9c8f2763b9ca4b033aed19bfeb6d 100755 --- a/rest/index.php +++ b/rest/index.php @@ -214,8 +214,8 @@ $app->get('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplat $app->put('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplateController::class . ':updateTypeRoles'); //Notes -$app->get('/res/{resId}/notes/templates', \Note\controllers\NoteController::class . ':getTemplateListByResId'); -$app->get('/notes/templates', \Note\controllers\NoteController::class . ':getAllTemplateList'); +$app->get('/notes/templates/resources/{resId}', \Note\controllers\NoteController::class . ':getTemplatesByResId'); +$app->get('/notes/templates', \Note\controllers\NoteController::class . ':getTemplates'); $app->get('/res/{resId}/notes', \Note\controllers\NoteController::class . ':getByResId'); $app->post('/res/{resId}/notes', \Note\controllers\NoteController::class . ':create'); diff --git a/src/app/action/controllers/AcknowledgementReceiptTrait.php b/src/app/action/controllers/AcknowledgementReceiptTrait.php index 2919314fcd5fc39da0f0f67147ffa9ffee2f42fa..5184d822615539909644736f4689551a0fc4131e 100644 --- a/src/app/action/controllers/AcknowledgementReceiptTrait.php +++ b/src/app/action/controllers/AcknowledgementReceiptTrait.php @@ -179,6 +179,6 @@ trait AcknowledgementReceiptTrait } } - return ['ids' => $ids, 'errors' => $errors]; + return ['data' => $ids, 'errors' => $errors]; } } diff --git a/src/app/note/controllers/NoteController.php b/src/app/note/controllers/NoteController.php index cd3daee09b733e98adaa75ab3af9590ab04b9a40..bd1ef0c01bd7c78ecfb4dad7406504ef02bd9e3f 100755 --- a/src/app/note/controllers/NoteController.php +++ b/src/app/note/controllers/NoteController.php @@ -126,38 +126,30 @@ class NoteController return ['encodedDocument' => base64_encode($fileContent)]; } - public static function getTemplateListByResId(Request $request, Response $response, array $aArgs) + public static function getTemplatesByResId(Request $request, Response $response, array $aArgs) { - $check = Validator::intVal()->notEmpty()->validate($aArgs['resId']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'resId is empty or not an integer']); + if (!Validator::intVal()->notEmpty()->validate($aArgs['resId'])) { + return $response->withStatus(400)->withJson(['errors' => 'Route resId is not an integer']); } - - if (!empty($aArgs['resId']) && !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) { + if (!ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) { return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); } - //get all templates note - $tmpAllNotes = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_id', 'template_label', 'template_content']]); - - //get entity resource - $resEntity = ResModel::getById(['resId' => $aArgs['resId'], 'select' => ['destination']]); + $resource = ResModel::getById(['resId' => $aArgs['resId'], 'select' => ['destination']]); if (!empty($resEntity['destination'])) { - //get retricted templates note - $aReturn = TemplateModel::getWithAssociation(['select' => ['DISTINCT(templates.template_id), template_label', 'template_content'], 'where' => ['template_target = ?', 'value_field = ?', 'templates.template_id = templates_association.template_id'], 'data' => ['notes', $resEntity['destination']], 'orderBy' => ['template_label']]); + $templates = TemplateModel::getWithAssociation(['select' => ['DISTINCT(templates.template_id), template_label', 'template_content'], 'where' => ['template_target = ?', 'value_field = ?', 'templates.template_id = templates_association.template_id'], 'data' => ['notes', $resource['destination']], 'orderBy' => ['template_label']]); } else { - $aReturn = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_label', 'template_content']]); + $templates = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_label', 'template_content']]); } - return $response->withJson($aReturn); + return $response->withJson(['templates' => $templates]); } - public static function getAllTemplateList(Request $request, Response $response) + public static function getTemplates(Request $request, Response $response) { - //get all templates note - $aReturn = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_label', 'template_content']]); + $templates = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_label', 'template_content']]); - return $response->withJson($aReturn); + return $response->withJson(['templates' => $templates]); } } diff --git a/src/app/resource/controllers/ResourceListController.php b/src/app/resource/controllers/ResourceListController.php index 01fb05137197feefc3d0ffb2774e72a16bdd4984..a9ead58b6cb180dddc24067bacf0097cd51d3add 100644 --- a/src/app/resource/controllers/ResourceListController.php +++ b/src/app/resource/controllers/ResourceListController.php @@ -642,12 +642,18 @@ class ResourceListController foreach ($resourcesForAction as $resId) { if (!empty($method)) { $methodResponse = ActionMethodController::$method(['resId' => $resId, 'data' => $body['data']]); + if (!empty($methodResponse['errors'])) { - return $response->withStatus(500)->withJson(['errors' => $methodResponse['errors']]); + if (empty($methodResponses['errors'])) { + $methodResponses['errors'] = []; + } + $methodResponses['errors'] = array_merge($methodResponses['errors'], $methodResponse['errors']); } - if ($methodResponse !== true) { - //TODO array_merge keys avec errors - $methodResponses = array_merge($methodResponses, $methodResponse); + if (!empty($methodResponse['data'])) { + if (empty($methodResponses['data'])) { + $methodResponses['data'] = []; + } + $methodResponses['data'] = array_merge($methodResponses['data'], $methodResponse['data']); } } } diff --git a/src/frontend/app/notes/note-editor.component.ts b/src/frontend/app/notes/note-editor.component.ts index 5ce5be6c10bfdf9a3b6a4d0bf8e5d089cc132233..62101ba37a2b7f24d6358a318ba3a418328d55ce 100644 --- a/src/frontend/app/notes/note-editor.component.ts +++ b/src/frontend/app/notes/note-editor.component.ts @@ -50,7 +50,7 @@ export class NoteEditorComponent implements AfterViewInit { getTemplatesNote() { if (this.templatesNote.length == 0) { if (this.resIds.length == 1) { - this.http.get("../../rest/res/" + this.resIds[0] + "/notes/templates") + this.http.get("../../rest/notes/templates/resources/" + this.resIds[0]) .subscribe((data: any) => { this.templatesNote = data['templates']; });