diff --git a/rest/index.php b/rest/index.php index e5196ab89e494c924a6de59251bbbd685d1ae4cc..612fa511ae7496bea9ec12f7b6df01ab24f3ce63 100755 --- a/rest/index.php +++ b/rest/index.php @@ -651,6 +651,7 @@ $app->get('/documents/{id}/maarchParapheurWorkflow', \ExternalSignatoryBook\cont $app->get('/maarchParapheur/user/{id}/picture', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getUserPicture'); $app->get('/externalSignatureBooks/enabled', \ExternalSignatoryBook\controllers\ExternalSignatureBookController::class . ':getEnabledSignatureBook'); $app->get('/externalSummary/{resId}', \ExternalSummary\controllers\SummaryController::class . ':getByResId'); +$app->get('/ixbus/natureDetails/{natureId}', \ExternalSignatoryBook\controllers\IxbusController::class . ':getNatureDetails'); $app->get('/externalConnectionsEnabled', \SrcCore\controllers\CoreController::class . ':externalConnectionsEnabled'); diff --git a/src/app/external/externalSignatoryBook/controllers/IxbusController.php b/src/app/external/externalSignatoryBook/controllers/IxbusController.php index 8931e888a02b1e849c63ccf8a4beb7c2fdff6c6a..1a30e638183df0b88d4c391e66a359fe2e48004f 100755 --- a/src/app/external/externalSignatoryBook/controllers/IxbusController.php +++ b/src/app/external/externalSignatoryBook/controllers/IxbusController.php @@ -23,6 +23,9 @@ use Resource\controllers\StoreController; use Resource\models\ResModel; use SrcCore\models\CurlModel; use SrcCore\models\TextFormatModel; +use Slim\Http\Request; +use Slim\Http\Response; +use SrcCore\models\CoreConfigModel; /** * @codeCoverageIgnore @@ -30,39 +33,12 @@ use SrcCore\models\TextFormatModel; class IxbusController { public static function getInitializeDatas($config) - { - $natures = IxbusController::getNature(['config' => $config]); - if (!empty($natures['error'])) { - return ['error' => $natures['error']]; - } - - $rawResponse['natures'] = $natures['natures']; - $rawResponse['messagesModel'] = []; - - foreach ($natures['natures'] as $nature) { - $messagesModels = IxbusController::getMessagesModel(['config' => $config, 'natureId' => $nature['identifiant']]); - if (!empty($messagesModels['error'])) { - return ['error' => $messagesModels['error']]; - } - $rawResponse['messagesModel'][$nature['identifiant']] = $messagesModels['messageModels']; - - $users = IxbusController::getNatureUsers(['config' => $config, 'natureId' => $nature['identifiant']]); - if (!empty($users['error'])) { - return ['error' => $users['error']]; - } - $rawResponse['users'][$nature['identifiant']] = $users['users']; - } - - return $rawResponse; - } - - public static function getNature($aArgs) { $curlResponse = CurlModel::exec([ - 'url' => rtrim($aArgs['config']['data']['url'], '/') . '/api/parapheur/v1/nature', - 'headers' => ['IXBUS_API:' . $aArgs['config']['data']['tokenAPI']], - 'method' => 'GET' - ]); + 'url' => rtrim($config['data']['url'], '/') . '/api/parapheur/v1/nature', + 'headers' => ['IXBUS_API:' . $config['data']['tokenAPI']], + 'method' => 'GET' + ]); if (!empty($curlResponse['response']['error'])) { return ['error' => $curlResponse['message']]; @@ -74,38 +50,56 @@ class IxbusController return ['natures' => $curlResponse['response']['payload']]; } - public static function getMessagesModel($aArgs) + public static function getNatureDetails(Request $request, Response $response, array $args) { + $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/visa/xml/remoteSignatoryBooks.xml']); + if (empty($loadedXml)) { + return $response->withStatus(500)->withJson(['errors' => 'remote signatory book: no configuration file found']); + } + $config = ['id' => (string)$loadedXml->signatoryBookEnabled]; + if ($config['id'] != 'ixbus') { + return $response->withStatus(400)->withJson(['errors' => 'ixbus is disabled']); + } + foreach ($loadedXml->signatoryBook as $value) { + if ($value->id == $config['id']) { + $config['data'] = (array)$value; + break; + } + } + if (empty($config['data']['url'])) { + return $response->withStatus(500)->withJson(['errors' => 'no ixbus url configured']); + } + $curlResponse = CurlModel::exec([ - 'url' => rtrim($aArgs['config']['data']['url'], '/') . '/api/parapheur/v1/circuit/' . $aArgs['natureId'], - 'headers' => ['IXBUS_API:' . $aArgs['config']['data']['tokenAPI']], - 'method' => 'GET' + 'method' => 'GET', + 'url' => rtrim($config['data']['url'], '/') . '/api/parapheur/v1/circuit/' . $args['natureId'], + 'headers' => ['IXBUS_API:' . $config['data']['tokenAPI']] ]); - if (!empty($curlResponse['response']['error'])) { - return ['error' => $curlResponse['message']]; + if (empty($curlResponse['response']['payload']) || !empty($curlResponse['response']['error'])) { + return $response->withStatus(500)->withJson(['errors' => $curlResponse['message'] ?? "HTTP {$curlResponse['code']} while contacting ixbus"]); } foreach ($curlResponse['response']['payload'] as $key => $value) { unset($curlResponse['response']['payload'][$key]['etapes']); unset($curlResponse['response']['payload'][$key]['options']); } - return ['messageModels' => $curlResponse['response']['payload']]; - } - public static function getNatureUsers($aArgs) - { + $return = ['messageModels' => $curlResponse['response']['payload']]; + $curlResponse = CurlModel::exec([ - 'url' => rtrim($aArgs['config']['data']['url'], '/') . '/api/parapheur/v1/nature/' . $aArgs['natureId'] . '/redacteur', - 'headers' => ['IXBUS_API:' . $aArgs['config']['data']['tokenAPI']], + 'url' => rtrim($config['data']['url'], '/') . '/api/parapheur/v1/nature/' . $args['natureId'] . '/redacteur', + 'headers' => ['IXBUS_API:' . $config['data']['tokenAPI']], 'method' => 'GET' ]); - if (!empty($curlResponse['response']['error'])) { - return ['error' => $curlResponse['message']]; + if (empty($curlResponse['response']['payload']) || !empty($curlResponse['response']['error'])) { + return $response->withStatus(500)->withJson(['errors' => $curlResponse['message'] ?? "HTTP {$curlResponse['code']} while contacting ixbus"]); } - return ['users' => $curlResponse['response']['payload']]; + $return['users'] = $curlResponse['response']['payload']; + + return $response->withJson($return); } public static function sendDatas($aArgs) diff --git a/src/frontend/app/actions/send-external-signatory-book-action/ixbus-paraph/ixbus-paraph.component.html b/src/frontend/app/actions/send-external-signatory-book-action/ixbus-paraph/ixbus-paraph.component.html index 9590bca4588fe753c69ce4133c337e10a8a6222f..1c9f8de59bee6625a9e985d9f6221bc0fea711f7 100755 --- a/src/frontend/app/actions/send-external-signatory-book-action/ixbus-paraph/ixbus-paraph.component.html +++ b/src/frontend/app/actions/send-external-signatory-book-action/ixbus-paraph/ixbus-paraph.component.html @@ -16,7 +16,7 @@ <div class="col-sm-12"> <plugin-select-search [showLabel]="true" [class]="''" [label]="'lang.natureIxbusParapheur' | translate" [placeholderLabel]="'lang.natureIxbusParapheur' | translate" [formControlSelect]="selectNature" - [datas]="natures" (afterSelected)="ixbusDatas.nature = selectNature.value;changeModel(selectNature.value)" + [datas]="natures" (afterSelected)="ixbusDatas.nature = selectNature.value; changeModel(selectNature.value)" style="width:100%;" [required]="true"> </plugin-select-search> </div> @@ -25,7 +25,7 @@ <div class="col-sm-12"> <plugin-select-search [showLabel]="true" [class]="''" [label]="'lang.workflowModelIxbus' | translate" [placeholderLabel]="'lang.workflowModelIxbus' | translate" [formControlSelect]="selectWorkflow" - [datas]="messagesModel" (afterSelected)="ixbusDatas.messageModel = selectWorkflow.value" + [datas]="messagesModel" [disabled]="messagesModel.length === 0" (afterSelected)="ixbusDatas.messageModel = selectWorkflow.value" style="width:100%;" [required]="true"> </plugin-select-search> </div> @@ -34,7 +34,7 @@ <div class="col-sm-12"> <plugin-select-search [showLabel]="true" [class]="''" [label]="'lang.loginIxbus' | translate" [placeholderLabel]="'lang.loginIxbus' | translate" [formControlSelect]="selectUser" - [datas]="users" (afterSelected)="ixbusDatas.userId = selectUser.value" + [datas]="users" [disabled]="users.length === 0" (afterSelected)="ixbusDatas.userId = selectUser.value" style="width:100%;" [required]="true"> </plugin-select-search> </div> diff --git a/src/frontend/app/actions/send-external-signatory-book-action/ixbus-paraph/ixbus-paraph.component.ts b/src/frontend/app/actions/send-external-signatory-book-action/ixbus-paraph/ixbus-paraph.component.ts index 7d936baca4117f92bd6bd77b2c3baf829fbec064..530f0a225d1cf9ba37bad756ecb401092eae53e1 100755 --- a/src/frontend/app/actions/send-external-signatory-book-action/ixbus-paraph/ixbus-paraph.component.ts +++ b/src/frontend/app/actions/send-external-signatory-book-action/ixbus-paraph/ixbus-paraph.component.ts @@ -4,6 +4,10 @@ import { HttpClient } from '@angular/common/http'; import { FormControl } from '@angular/forms'; import { LocalStorageService } from '@service/local-storage.service'; import { HeaderService } from '@service/header.service'; +import { catchError, tap } from 'rxjs/operators'; +import { NotificationService } from '@service/notification/notification.service'; +import { of } from 'rxjs'; +import { FunctionsService } from '@service/functions.service'; @Component({ selector: 'app-ixbus-paraph', @@ -42,7 +46,9 @@ export class IxbusParaphComponent implements OnInit { public translate: TranslateService, public http: HttpClient, public headerService: HeaderService, - private localStorage: LocalStorageService + public functions: FunctionsService, + private localStorage: LocalStorageService, + private notifications: NotificationService ) { } ngOnInit(): void { @@ -58,15 +64,26 @@ export class IxbusParaphComponent implements OnInit { } changeModel(natureId: string) { - this.messagesModel = []; - this.additionalsInfos.ixbus.messagesModel[natureId].forEach((element: any) => { - this.messagesModel.push({id: element.identifiant, label: element.nom}); - }); - - this.users = []; - this.additionalsInfos.ixbus.users[natureId].forEach((element: any) => { - this.users.push({id: element.identifiant, label: element.prenom + ' ' + element.nom}); - }); + this.http.get(`../rest/ixbus/natureDetails/${natureId}`).pipe( + tap((data: any) => { + if (!this.functions.empty(data.messageModels)) { + this.messagesModel = data.messageModels.map((message: any) => ({ + id: message.identifiant, + label: message.nom + })); + } + if (!this.functions.empty(data.users)) { + this.users = data.users.map((user: any) => ({ + id: user.identifiant, + label: `${user.prenom} ${user.nom}` + })); + } + }), + catchError((err: any) => { + this.notifications.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); } isValidParaph() { diff --git a/src/frontend/plugins/select-search/select-search.component.html b/src/frontend/plugins/select-search/select-search.component.html index 82c893ccdd82e5566f8fa287a0ede1c11a7ca62b..644e5ccdf982b1159b1f0b79ea9dd28d8d7590cc 100644 --- a/src/frontend/plugins/select-search/select-search.component.html +++ b/src/frontend/plugins/select-search/select-search.component.html @@ -1,7 +1,7 @@ <mat-form-field [class]="class + ' search-select'" [appearance]="appearance" [floatLabel]="appService.getViewMode() || showLabel ? '' : 'never'"> <mat-label *ngIf="appService.getViewMode() || showLabel">{{label}}</mat-label> <mat-select [id]="id" [formControl]="formControlSelect" [placeholder]="placeholderLabel" #test - (selectionChange)="launchEvent($event)" [required]="required" [multiple]="multiple" + (selectionChange)="launchEvent($event)" [required]="required" [multiple]="multiple" [disabled]="disabled" [title]="functions.empty(formControlSelect.value) ? '' : getLabel(formControlSelect.value)"> <mat-select-trigger *ngIf="multiple"> {{formControlSelect.value.length > 0 ? getFirstDataLabel() : ''}} diff --git a/src/frontend/plugins/select-search/select-search.component.ts b/src/frontend/plugins/select-search/select-search.component.ts index 019faa1d7bf88b794f8b6d832c22ba0f78f6f643..4aabb4427acda17dafa1b897aed8fca3361eb9c4 100755 --- a/src/frontend/plugins/select-search/select-search.component.ts +++ b/src/frontend/plugins/select-search/select-search.component.ts @@ -50,6 +50,8 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView @Input() optGroupTarget: string = null; + @Input() disabled: boolean = false; + /** * ex : [ { id : 'group1' , label: 'Group 1'} ] */