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

records: Fix external link issue #41

Merged
merged 1 commit into from
Nov 6, 2019
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: 1 addition & 3 deletions projects/ng-core-tester/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { of, Observable } from 'rxjs';

import { HomeComponent } from './home/home.component';
import { DocumentComponent } from './record/document/document.component';
import { InstitutionComponent } from './record/institution/institution.component';
import { DetailComponent } from './record/document/detail/detail.component';
import { EditorComponent } from '@rero/ng-core';
import { RecordSearchComponent } from '@rero/ng-core';
Expand Down Expand Up @@ -213,8 +212,7 @@ const routes: Routes = [
},
{
key: 'institutions',
label: 'Organisations',
component: InstitutionComponent
label: 'Organisations'
}
]
}
Expand Down
5 changes: 1 addition & 4 deletions projects/ng-core-tester/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { CoreModule, RecordModule, SharedModule } from '@rero/ng-core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { DocumentComponent } from './record/document/document.component';
import { InstitutionComponent } from './record/institution/institution.component';
import { HomeComponent } from './home/home.component';
import { DetailComponent } from './record/document/detail/detail.component';
import { CoreConfigService } from '@rero/ng-core';
Expand All @@ -36,7 +35,6 @@ import { SearchBarComponent } from './search-bar/search-bar.component';
declarations: [
AppComponent,
DocumentComponent,
InstitutionComponent,
HomeComponent,
DetailComponent,
SearchBarComponent
Expand All @@ -60,8 +58,7 @@ import { SearchBarComponent } from './search-bar/search-bar.component';
],
bootstrap: [AppComponent],
entryComponents: [
DocumentComponent,
InstitutionComponent
DocumentComponent
]
})
export class AppModule { }
4 changes: 1 addition & 3 deletions projects/ng-core-tester/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component } from '@angular/core';

import { DialogService, ApiService, TranslateLanguageService } from '@rero/ng-core';
import { DocumentComponent } from '../record/document/document.component';
import { InstitutionComponent } from '../record/institution/institution.component';
import { ToastrService } from 'ngx-toastr';

@Component({
Expand All @@ -21,8 +20,7 @@ export class HomeComponent {
},
{
key: 'institutions',
label: 'Organisations',
component: InstitutionComponent
label: 'Organisations'
}
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<h5>
<a href [routerLink]="detailUrl" *ngIf="detailUrl; else titleWithoutLink">{{ record.metadata.title }}</a>
<ng-container *ngIf="detailUrl; else titleWithoutLink">
<a [routerLink]="detailUrl.link" *ngIf="detailUrl.external === false; else hrefLink">
{{ record.metadata.title }}
</a>
<ng-template #hrefLink>
<a [href]="detailUrl.link">
{{ record.metadata.title }}
</a>
</ng-template>
</ng-container>
<ng-template #titleWithoutLink>
{{ record.metadata.title }}
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export class DocumentComponent implements ResultItem {
type: string;

@Input()
detailUrl: string;
detailUrl: { link: string, external: boolean };
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ describe('RecordSearchComponent', () => {

it('should resolve detail url', async(() => {
component.resolveDetailUrl({ metadata: { pid: 100 } }).subscribe((result: any) => {
expect(result).toBe('/custom/url/for/detail/documents/100');
expect(result.link).toBe('/custom/url/for/detail/documents/100');
});

component.detailUrl = null;

component.resolveDetailUrl({ metadata: { pid: 100 } }).subscribe((result: any) => {
expect(result).toBe('detail/100');
expect(result.link).toBe('detail/100');
});

component.types = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,13 @@ export class RecordSearchComponent implements OnInit {
* In case record cannot be read, returns null.
* @param record - Generate detail URL for this record.
*/
resolveDetailUrl(record: any) {
const url = this.detailUrl ?
this.detailUrl.replace(':type', this.currentType).replace(':pid', record.metadata.pid) :
`detail/${record.metadata.pid}`;
resolveDetailUrl(record: any): Observable<any> {
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.external = true;
}

if (!this.config.canRead) {
return of(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ import { ResultItem } from './result-item';
@Component({
template: `
{{ record|json }}
<div class="mt-3" *ngIf="detailUrl">
<a class="btn btn-primary btn-sm" [routerLink]="detailUrl.link" *ngIf="detailUrl.external === false; else hrefLink">
<i class="fa fa-file-o mr-2"></i>{{ 'Show' | translate }}
</a>
<ng-template #hrefLink>
<a class="btn btn-primary btn-sm" [href]="detailUrl.link">
<i class="fa fa-file-o mr-2"></i>{{ 'Show' | translate }}
</a>
</ng-template>
</div>
`
})
export class JsonComponent implements ResultItem {
Expand All @@ -31,5 +41,5 @@ export class JsonComponent implements ResultItem {
type: string;

@Input()
detailUrl: string;
detailUrl: { link: string, external: boolean };
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
export interface ResultItem {
record: any;
type: string;
detailUrl: string;
detailUrl: { link: string, external: boolean };
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,21 @@
<ng-template ngCoreRecordSearchResult></ng-template>
</div>
<div class="col-2 text-right">
<a href class="btn btn-link p-0 ml-2" [title]="'Show'|translate" [routerLink]="detailUrl" *ngIf="detailUrl">
<i class="fa fa-file-o"></i>
</a>
<a href class="btn btn-link p-0 ml-2" [title]="'Edit'|translate" routerLink="edit/{{ record.metadata.pid }}"
*ngIf="inRouting && adminMode && updateStatus && updateStatus.can">
<i class="fa fa-pencil"></i>
</a>
<span class="ml-2" *ngIf="adminMode && deleteStatus">
<button class="btn btn-link p-0" [title]="'Delete'|translate" (click)="deleteRecord(record.metadata.pid)" *ngIf="deleteStatus.can; else deleteMessageLink">
<button class="btn btn-link p-0" [title]="'Delete'|translate" (click)="deleteRecord(record.metadata.pid)"
*ngIf="deleteStatus.can; else deleteMessageLink">
<i class="fa fa-trash"></i>
</button>
<ng-template #deleteMessageLink>
<button class="btn btn-link p-0 text-muted" [title]="'Delete'|translate" (click)="showDeleteMessage(deleteStatus.message)" *ngIf="deleteStatus.message">
<button class="btn btn-link p-0 text-muted" [title]="'Delete'|translate"
(click)="showDeleteMessage(deleteStatus.message)" *ngIf="deleteStatus.message">
<i class="fa fa-trash"></i>
</button>
</ng-template>

</span>

</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class RecordSearchResultComponent implements OnInit {
/**
* Detail URL value, resolved by observable property detailUrl$.
*/
detailUrl: string;
detailUrl: { link: string, external: boolean };

/**
* Record to display
Expand Down Expand Up @@ -100,7 +100,7 @@ export class RecordSearchResultComponent implements OnInit {
* Observable emitting current value of record URL.
*/
@Input()
detailUrl$: Observable<string> = null;
detailUrl$: Observable<{ link: string, external: boolean }> = null;

/**
* Event emitted when a record is deleted
Expand Down Expand Up @@ -139,7 +139,7 @@ export class RecordSearchResultComponent implements OnInit {
}

if (this.detailUrl$) {
this.detailUrl$.subscribe((url: string) => {
this.detailUrl$.subscribe((url: { link: string, external: boolean }) => {
this.detailUrl = url;
});
}
Expand Down