diff --git a/rest/index.php b/rest/index.php index 8fcc1c1e7f178a4e86db8484d297f9c4cab6b585..da163d1fd984e9dbea5327307d9f79f950c17dcb 100755 --- a/rest/index.php +++ b/rest/index.php @@ -272,8 +272,8 @@ $app->put('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/act $app->get('/resourcesList/exportTemplate', \Resource\controllers\ExportController::class . ':getExportTemplates'); //SignatureBook -$app->get('/{basketId}/signatureBook/resList/details', \SignatureBook\controllers\SignatureBookController::class . ':getDetailledResList'); -$app->get('/signatureBook/users/{userId}/groups/{groupId}/baskets/{basketId}/resource/{resId}', \SignatureBook\controllers\SignatureBookController::class . ':getSignatureBook'); +$app->get('/signatureBook/users/{userId}/groups/{groupId}/baskets/{basketId}/resources', \SignatureBook\controllers\SignatureBookController::class . ':getResources'); +$app->get('/signatureBook/users/{userId}/groups/{groupId}/baskets/{basketId}/resources/{resId}', \SignatureBook\controllers\SignatureBookController::class . ':getSignatureBook'); $app->get('/signatureBook/{resId}/attachments', \SignatureBook\controllers\SignatureBookController::class . ':getAttachmentsById'); $app->get('/signatureBook/{resId}/incomingMailAttachments', \SignatureBook\controllers\SignatureBookController::class . ':getIncomingMailAndAttachmentsById'); $app->put('/signatureBook/{resId}/unsign', \SignatureBook\controllers\SignatureBookController::class . ':unsignFile'); diff --git a/src/app/resource/controllers/ResourceListController.php b/src/app/resource/controllers/ResourceListController.php index 5ff09815bcf6a9b85bf087d9708c935240e93de7..905f69bcd88b83791c1c7fa0546cefb9926710dd 100644 --- a/src/app/resource/controllers/ResourceListController.php +++ b/src/app/resource/controllers/ResourceListController.php @@ -211,7 +211,9 @@ class ResourceListController 'where' => ['basket_id = ?', 'group_id = ?', 'default_action_list = ?'], 'data' => [$basket['basket_id'], $group['group_id'], 'Y'] ]); - $defaultAction = ActionModel::getById(['select' => ['id', 'label_action', 'component'], 'id' => $defaultAction[0]['id_action']]); + if (!empty($defaultAction[0]['id_action'])) { + $defaultAction = ActionModel::getById(['select' => ['id', 'label_action', 'component'], 'id' => $defaultAction[0]['id_action']]); + } return $response->withJson(['resources' => $formattedResources, 'count' => $count, 'basketLabel' => $basket['basket_name'], 'basket_id' => $basket['basket_id'], 'allResources' => $allResources, 'defaultAction' => $defaultAction]); } diff --git a/src/app/signatureBook/controllers/SignatureBookController.php b/src/app/signatureBook/controllers/SignatureBookController.php index 2e196eef180571867f0f0d30eb64a322f8c8973d..49cfcbec1f1929eee8e45cca39e99e019918528c 100755 --- a/src/app/signatureBook/controllers/SignatureBookController.php +++ b/src/app/signatureBook/controllers/SignatureBookController.php @@ -27,6 +27,7 @@ use Link\models\LinkModel; use Note\models\NoteModel; use Priority\models\PriorityModel; use Resource\controllers\ResController; +use Resource\controllers\ResourceListController; use Resource\models\ResModel; use Respect\Validation\Validator; use Slim\Http\Request; @@ -376,25 +377,34 @@ class SignatureBookController return array_values($attachments); } - public function getDetailledResList(Request $request, Response $response, array $aArgs) + public function getResources(Request $request, Response $response, array $aArgs) { - $resList = BasketModel::getResListById([ - 'basketId' => $aArgs['basketId'], - 'userId' => $GLOBALS['userId'], - 'select' => ['res_id', 'alt_identifier', 'subject', 'creation_date', 'process_limit_date', 'priority', 'contact_id', 'address_id', 'user_lastname', 'user_firstname'] + $currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]); + $errors = ResourceListController::listControl(['groupId' => $aArgs['groupId'], 'userId' => $aArgs['userId'], 'basketId' => $aArgs['basketId'], 'currentUserId' => $currentUser['id']]); + if (!empty($errors['errors'])) { + return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]); + } + + $basket = BasketModel::getById(['id' => $aArgs['basketId'], 'select' => ['basket_clause', 'basket_id', 'basket_name']]); + + $user = UserModel::getById(['id' => $aArgs['userId'], 'select' => ['user_id']]); + $whereClause = PreparedClauseController::getPreparedClause(['clause' => $basket['basket_clause'], 'login' => $user['user_id']]); + $resources = ResModel::getOnView([ + 'select' => ['res_id', 'alt_identifier', 'subject', 'creation_date', 'process_limit_date', 'priority', 'contact_id', 'address_id', 'user_lastname', 'user_firstname'], + 'where' => [$whereClause] ]); $resListForAttachments = []; - $resListForRequest = []; - foreach ($resList as $key => $value) { + $resIds = []; + foreach ($resources as $value) { $resListForAttachments[$value['res_id']] = null; - $resListForRequest[] = $value['res_id']; + $resIds[] = $value['res_id']; } $attachmentsInResList = AttachmentModel::getOnView([ 'select' => ['res_id_master', 'status', 'attachment_type'], 'where' => ['res_id_master in (?)', "attachment_type not in ('incoming_mail_attachment', 'print_folder', 'converted_pdf', 'signed_response')", "status not in ('DEL', 'TMP', 'OBS')"], - 'data' => [$resListForRequest] + 'data' => [$resIds] ]); $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); @@ -407,24 +417,24 @@ class SignatureBookController } } - foreach ($resList as $key => $value) { + foreach ($resources as $key => $value) { if (!empty($value['contact_id'])) { - $resList[$key]['sender'] = ContactModel::getLabelledContactWithAddress(['contactId' => $value['contact_id'], 'addressId' => $value['address_id']]); + $resources[$key]['sender'] = ContactModel::getLabelledContactWithAddress(['contactId' => $value['contact_id'], 'addressId' => $value['address_id']]); } else { - $resList[$key]['sender'] = $value['user_firstname'] . ' ' . $value['user_lastname']; + $resources[$key]['sender'] = $value['user_firstname'] . ' ' . $value['user_lastname']; } $priority = PriorityModel::getById(['id' => $value['priority'], 'select' => ['color', 'label']]); - $resList[$key]['creation_date'] = date(DATE_ATOM, strtotime($resList[$key]['creation_date'])); - $resList[$key]['process_limit_date'] = (empty($resList[$key]['process_limit_date']) ? null : date(DATE_ATOM, strtotime($resList[$key]['process_limit_date']))); - $resList[$key]['allSigned'] = ($resListForAttachments[$value['res_id']] === null ? false : $resListForAttachments[$value['res_id']]); + $resources[$key]['creation_date'] = date(DATE_ATOM, strtotime($resources[$key]['creation_date'])); + $resources[$key]['process_limit_date'] = (empty($resources[$key]['process_limit_date']) ? null : date(DATE_ATOM, strtotime($resources[$key]['process_limit_date']))); + $resources[$key]['allSigned'] = ($resListForAttachments[$value['res_id']] === null ? false : $resListForAttachments[$value['res_id']]); if (!empty($priority)) { - $resList[$key]['priorityColor'] = $priority['color']; - $resList[$key]['priorityLabel'] = $priority['label']; + $resources[$key]['priorityColor'] = $priority['color']; + $resources[$key]['priorityLabel'] = $priority['label']; } - unset($resList[$key]['priority'], $resList[$key]['contact_id'], $resList[$key]['address_id'], $resList[$key]['user_lastname'], $resList[$key]['user_firstname']); + unset($resources[$key]['priority'], $resources[$key]['contact_id'], $resources[$key]['address_id'], $resources[$key]['user_lastname'], $resources[$key]['user_firstname']); } - return $response->withJson(['resList' => $resList]); + return $response->withJson(['resources' => $resources]); } } diff --git a/src/frontend/app/signature-book.component.ts b/src/frontend/app/signature-book.component.ts index 9a3e7e6358b5cd0251094f6ca8e20a46ef3b6e27..bb4fbac28caf6b3dd7219586cec278afcf286fc6 100755 --- a/src/frontend/app/signature-book.component.ts +++ b/src/frontend/app/signature-book.component.ts @@ -255,10 +255,11 @@ export class SignatureBookComponent implements OnInit { } else { this.rightContentWidth = "44%"; this.leftContentWidth = "44%"; - if (this.signatureBook.resList.length == 0 || this.signatureBook.resList[0].allSigned == null) { + if (this.signatureBook.resList.length == 0 || typeof this.signatureBook.resList[0].creation_date === 'undefined') { + //TODO change route /signatureBook/users/{userId}/groups/{groupId}/baskets/{basketId}/resources this.http.get(this.coreUrl + 'rest/' + this.basketId + '/signatureBook/resList/details') .subscribe((data : any) => { - this.signatureBook.resList = data.resList; + this.signatureBook.resList = data.resources; this.signatureBook.resList.forEach((value: any, index: number) => { if (value.res_id == this.resId) { this.signatureBook.resListIndex = index;