Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs: several tabs on the same index. #283

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class RecordSearchComponent implements OnInit, OnDestroy {
types: {
key: string,
label: string,
index?: string,
component?: Component,
total?: number,
canAdd?: any,
Expand All @@ -86,6 +87,7 @@ export class RecordSearchComponent implements OnInit, OnDestroy {
canRead?: any,
permissions?: any,
aggregations?: any,
preFilters?: any,
listHeaders?: any,
itemHeaders?: any,
aggregationsOrder?: Array<string>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ describe('RecordSearchComponent', () => {
});

it('should resolve detail url', async(() => {
component.changeType(new Event('click'), 'documents');
component['currentType'] = 'documents';
component.detailUrl = '/custom/url/for/detail/:type/:pid';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
types: {
key: string,
label: string,
index?: string,
component?: Component,
total?: number,
canAdd?: any,
Expand All @@ -89,6 +90,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
canRead?: any,
permissions?: any,
aggregations?: any,
preFilters?: any,
listHeaders?: any,
itemHeaders?: any,
aggregationsOrder?: Array<string>,
Expand Down Expand Up @@ -231,9 +233,9 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
// Load totals for each resource type
for (const type of this.types) {
this._recordService.getRecords(
type.key, '', 1, 1, [],
this._config.preFilters || {},
this._config.listHeaders || null).subscribe((records: Record) => {
type.index ? type.index : type.key, '', 1, 1, [],
type.preFilters || {},
type.listHeaders || null).subscribe((records: Record) => {
type.total = this._recordService.totalHits(records.hits.total);
});
}
Expand Down Expand Up @@ -611,7 +613,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
const url = { link: `detail/${record.metadata.pid}`, external: false };

if (this.detailUrl) {
url.link = this.detailUrl.replace(':type', this.currentType).replace(':pid', record.metadata.pid);
url.link = this.detailUrl.replace(':type', this._currentIndex()).replace(':pid', record.metadata.pid);
url.external = true;
}

Expand Down Expand Up @@ -671,7 +673,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
const q = this._buildQueryString();

this._recordService.getRecords(
this.currentType,
this._currentIndex(),
q,
this.page,
this.size,
Expand Down Expand Up @@ -709,7 +711,8 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
q: this.q,
page: this.page,
size: this.size,
currentType: this.currentType,
currentType: this._config.key,
index: this._config.index,
aggregationsFilters: this.aggregationsFilters,
sort: this.sort
});
Expand Down Expand Up @@ -765,7 +768,8 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
});

return JSON.stringify({
currentType: this.currentType,
currentType: this._config.key,
index: this._config.index,
q: this.q,
page: this.page,
size: this.size,
Expand Down Expand Up @@ -816,4 +820,13 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {

return queries.join(' ');
}

/**
* Return the name of the index defined either by the index key or key.
*
* @return string, current index defined by keys index or key
*/
private _currentIndex() {
return this._config.index ? this._config.index : this._config.key;
}
}