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

search: fix side effect when the resource type changes #170

Merged
merged 1 commit into from
Apr 8, 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
4 changes: 2 additions & 2 deletions projects/ng-core-tester/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const routes: Routes = [
}
},
{
path: 'usi/record/search',
path: 'unisi/record/search',
loadChildren: () => import('./record-wrapper/record-wrapper.module').then(m => m.RecordWrapperModule),
data: {
showSearchInput: true,
Expand All @@ -156,7 +156,7 @@ const routes: Routes = [
label: 'Documents',
component: DocumentComponent,
preFilters: {
institution: 'usi'
institution: 'unisi'
}
}
]
Expand Down
8 changes: 2 additions & 6 deletions projects/ng-core-tester/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ export class AppComponent implements OnInit {
iconCssClass: 'fa fa-book'
},
{
name: 'USI records',
routerLink: '/usi/record/search/documents'
},
{
name: 'HEVS records',
routerLink: '/hevs/record/search/documents'
name: 'UNISI records',
routerLink: '/unisi/record/search/documents'
},
{
name: 'Backend records',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
 along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<ng-container *ngIf="record">
<h1>{{ record.metadata.title }}</h1>
<h1>{{ record.metadata.title[0].mainTitle[0].value }}</h1>
<p>
<span class="badge badge-primary mr-1" *ngFor="let author of record.metadata.authors">{{ author.name }}</span>
</p>
<div class="text-justify" *ngIf="record.metadata.abstracts">
{{ record.metadata.abstracts[0].value }}
</div>
</ng-container>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
<h5>
<ng-container *ngIf="detailUrl; else titleWithoutLink">
<a [routerLink]="detailUrl.link" *ngIf="detailUrl.external === false; else hrefLink">
{{ record.metadata.title }}
{{ record.metadata.title[0].mainTitle[0].value }}
</a>
<ng-template #hrefLink>
<a [href]="detailUrl.link">
{{ record.metadata.title }}
{{ record.metadata.title[0].mainTitle[0].value }}
</a>
</ng-template>
</ng-container>
<ng-template #titleWithoutLink>
{{ record.metadata.title }}
{{ record.metadata.title[0].mainTitle[0].value }}
</ng-template>
</h5>
<p>
Expand Down
58 changes: 0 additions & 58 deletions projects/ng-core-tester/src/app/routes/documents-hevs-route.ts

This file was deleted.

4 changes: 1 addition & 3 deletions projects/ng-core-tester/src/app/routes/route.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { RouteCollectionService } from '@rero/ng-core';
import { DocumentsRoute } from './documents-route';
import { DocumentsHevsRoute } from './documents-hevs-route';

@Injectable({
providedIn: 'root'
Expand All @@ -41,8 +40,7 @@ export class RouteService {
*/
initializeRoutes() {
this.routeCollectionService
.addRoute(new DocumentsRoute())
.addRoute(new DocumentsHevsRoute());
.addRoute(new DocumentsRoute());

this.routeCollectionService.getRoutes().map((route: any) => {
this.router.config.push(route);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
/**
* Store configuration for type
*/
private _config: any;
private _config: any = null;

/**
* Subscription to aggregationsFilters observable
Expand Down Expand Up @@ -252,8 +252,13 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
this.recordUiService.types = this.types;
}

// Load configuration for changed type
this.loadConfigurationForType(this.currentType);
// if the "type" property is changed in input, but the change is not
// triggered by clicking on a tab (which already load configuration),
// we reload configuration.
// If no configuration is loaded, we load it, too.
if (this._config === null || changes.currentType.currentValue !== this._config.key) {
this.loadConfigurationForType(this.currentType);
}
}

// If it's the first change, we don't do a search, it's delegated to the
Expand Down Expand Up @@ -364,7 +369,14 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
*/
changeType(event: Event, type: string) {
event.preventDefault();

// if records are loading, we prevent to change the type of the resource.
if (this.isLoading === true) {
return;
}

this.currentType = type;
this.loadConfigurationForType(this.currentType);
this.aggregationsFilters = [];
this._getRecords();
this._recordSearchService.setAggregationsFilters([]);
Expand Down