Skip to content

Commit

Permalink
fix(document): import with many identifiers
Browse files Browse the repository at this point in the history
If the size of the query exceeds 1024 characters, we truncate
the identifiers and display a warning message to the user.

* Closes rero/rero-ils#3118.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed May 8, 2024
1 parent 92eb92e commit 94d62ea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,36 @@
<h4 class="modal-title pull-left" translate>Import</h4>
</div>
<div class="modal-body">
@if (records.length < 2) {
<h5 translate>A document is available</h5>
} @else {
<h5 translate>Documents are available</h5>
@if (records.length > 0 || warning) {
<h5>{{ 'This document may already exist' | translate }}</h5>
}
<ul class="list-unstyled mb-0">
@for (record of records; track record) {
<li>
<a [routerLink]="['/records', 'documents', 'detail', $any(record).metadata.pid]" (click)="close()">
@if ($any(record).metadata.ui_title_text_responsibility) {
{{ $any(record).metadata.ui_title_text_responsibility }}
} @else {
{{ 'Document' | translate }}
}
</a>
</li>
}
</ul>
<div class="font-weight-bold mt-3" translate>Do you want to import this document?</div>
@if (records.length > 0) {
<ul class="list-unstyled mb-0">
@for (record of records; track record) {
<li>
<a [routerLink]="['/records', 'documents', 'detail', $any(record).metadata.pid]" (click)="close()">
@if ($any(record).metadata.ui_title_text_responsibility) {
{{ $any(record).metadata.ui_title_text_responsibility }}
} @else {
{{ 'Document' | translate }}
}
</a>
</li>
}
</ul>
}
@if (warning) {
<div class="mt-3 row">
<div class="col-1">
<i class="fa fa-exclamation-circle fa-2x text-danger" aria-hidden="true"></i>
</div>
<div class="col-11">
<p class="mb-2 font-weight-bold" translate>Too many identifiers: not all identifiers have been verified.</p>
<p class="mb-2 font-weight-bold" translate>Please make sure that this document does not already exist before importing.</p>
</div>
</div>
}
<div class="font-weight-bold mt-3" translate>Do you really want to import this document?</div>
</div>
<div class="modal-footer">
<button id="modal-cancel-button" type="button" class="btn btn-light" (click)="decline()" translate>Cancel</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class DialogImportComponent {
/** Available record */
records: any[];

/** Show warning message */
warning: boolean = false;

/** Observable for action */
confirmation$: Subject<boolean> = new Subject<boolean>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,23 @@ export class DocumentDetailComponent extends DetailComponent {
this.router.navigate(route, { queryParams: data });
} else {
// Find documents(s) with query params
const query = queryParams.join(' OR ');
let warning = false;
let query = queryParams.join(' OR ');
// If the query exceeds the size of 1024 characters, we truncate it.
if (query.length > 1024) {
query = query.substring(0, query.substring(0, 1024).lastIndexOf('OR') - 1);
warning = true;
}
this.recordService.getRecords(
'documents', query, 1, undefined, undefined, undefined, { accept: 'application/rero+json' }
).subscribe((response: Record) => {
if (this.recordService.totalHits(response.hits.total) === 0) {
if (this.recordService.totalHits(response.hits.total) === 0 && !warning) {
this.router.navigate(route, { queryParams: data });
} else {
const config = {
initialState: {
records: response.hits.hits
records: response.hits.hits,
warning
}
};
const bsModalRef = this.bsModalService.show(DialogImportComponent, config);
Expand Down

0 comments on commit 94d62ea

Please sign in to comment.