forked from inspirehep/record-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use record resouce and use route resolvers
* Referencing inspirehep#307
- Loading branch information
1 parent
3d4f06a
commit f58c445
Showing
11 changed files
with
177 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of record-editor. | ||
* Copyright (C) 2018 CERN. | ||
* | ||
* record-editor is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation; either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* record-editor is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with record-editor; if not, write to the Free Software Foundation, Inc., | ||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
* In applying this license, CERN does not | ||
* waive the privileges and immunities granted to it by virtue of its status | ||
* as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
*/ | ||
|
||
import { Resolve, ActivatedRouteSnapshot, Router } from '@angular/router'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs/Observable'; | ||
|
||
import { RecordApiService } from '../core/services'; | ||
import { RecordResources } from '../shared/interfaces'; | ||
import { ApiError } from '../shared/classes'; | ||
|
||
@Injectable() | ||
export class RecordResourcesResolver implements Resolve<RecordResources> { | ||
constructor(private router: Router, | ||
private apiService: RecordApiService) { } | ||
|
||
resolve(route: ActivatedRouteSnapshot): Observable<RecordResources> { | ||
const params = route.params; | ||
return this.apiService | ||
.fetchRecordResources(params.type, params.recid) | ||
.take(1) | ||
.catch((error: ApiError) => { | ||
this.router.navigate(['error', error.status]); | ||
return null; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This file is part of record-editor. | ||
* Copyright (C) 2018 CERN. | ||
* | ||
* record-editor is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation; either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* record-editor is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with record-editor; if not, write to the Free Software Foundation, Inc., | ||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
* In applying this license, CERN does not | ||
* waive the privileges and immunities granted to it by virtue of its status | ||
* as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
*/ | ||
|
||
import { Resolve, ActivatedRouteSnapshot, Router } from '@angular/router'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs/Observable'; | ||
|
||
import { RecordResourcesResolver } from './record-resources.resolver'; | ||
import { RecordSearchService } from '../core/services'; | ||
import { RecordResources } from '../shared/interfaces'; | ||
import { ApiError } from '../shared/classes'; | ||
|
||
@Injectable() | ||
export class RecordSearchResolver implements Resolve<Array<number>> { | ||
constructor(private router: Router, | ||
private recordSearchService: RecordSearchService) { } | ||
|
||
resolve(route: ActivatedRouteSnapshot): Observable<Array<number>> { | ||
if (!route.queryParams.query) { | ||
return Observable.of([]); | ||
} | ||
|
||
return this.recordSearchService | ||
.search(route.params.type, route.queryParams.query) | ||
.take(1) | ||
.catch((error: ApiError) => { | ||
this.router.navigate(['error', error.status]); | ||
return null; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { JSONSchema } from 'ng2-json-editor'; | ||
|
||
export interface RecordResources { | ||
schema: JSONSchema; | ||
record: object; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export interface SearchParams { | ||
query: string; | ||
cursor?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters