62180: fixed issues wih 404 pages

This commit is contained in:
lotte
2019-05-09 11:43:37 +02:00
parent 487339d9ef
commit ee5a9c7df5
7 changed files with 45 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
import { CollectionDataService } from '../core/data/collection-data.service';
@@ -19,7 +19,7 @@ import { PaginationComponentOptions } from '../shared/pagination/pagination-comp
import { combineLatest, filter, first, flatMap, map } from 'rxjs/operators';
import { SearchService } from '../+search-page/search-service/search.service';
import { PaginatedSearchOptions } from '../+search-page/paginated-search-options.model';
import { toDSpaceObjectListRD } from '../core/shared/operators';
import { renderPageNotFoundOn404, toDSpaceObjectListRD } from '../core/shared/operators';
import { DSpaceObjectType } from '../core/shared/dspace-object-type.model';
@Component({
@@ -45,7 +45,8 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
private collectionDataService: CollectionDataService,
private itemDataService: ItemDataService,
private metadata: MetadataService,
private route: ActivatedRoute
private route: ActivatedRoute,
private router: Router
) {
this.paginationConfig = new PaginationComponentOptions();
this.paginationConfig.id = 'collection-page-pagination';
@@ -56,7 +57,8 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.collectionRD$ = this.route.data.pipe(
map((data) => data.collection),
map((data) => data.collection as RemoteData<Collection>),
renderPageNotFoundOn404(this.router),
first()
);
this.logoRD$ = this.collectionRD$.pipe(

View File

@@ -4,7 +4,8 @@ import { Collection } from '../core/shared/collection.model';
import { Observable } from 'rxjs';
import { CollectionDataService } from '../core/data/collection-data.service';
import { RemoteData } from '../core/data/remote-data';
import { getSucceededRemoteData } from '../core/shared/operators';
import { find } from 'rxjs/operators';
import { hasValue } from '../shared/empty.util';
/**
* This class represents a resolver that requests a specific collection before the route is activated
@@ -22,7 +23,7 @@ export class CollectionPageResolver implements Resolve<RemoteData<Collection>> {
*/
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Collection>> {
return this.collectionService.findById(route.params.id).pipe(
getSucceededRemoteData()
find((RD) => hasValue(RD.error) || RD.hasSucceeded),
);
}
}

View File

@@ -1,6 +1,6 @@
import { mergeMap, filter, map } from 'rxjs/operators';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription, Observable } from 'rxjs';
import { CommunityDataService } from '../core/data/community-data.service';
@@ -13,6 +13,7 @@ import { MetadataService } from '../core/metadata/metadata.service';
import { fadeInOut } from '../shared/animations/fade';
import { hasValue } from '../shared/empty.util';
import { renderPageNotFoundOn404 } from '../core/shared/operators';
@Component({
selector: 'ds-community-page',
@@ -37,13 +38,17 @@ export class CommunityPageComponent implements OnInit {
constructor(
private communityDataService: CommunityDataService,
private metadata: MetadataService,
private route: ActivatedRoute
private route: ActivatedRoute,
private router: Router
) {
}
ngOnInit(): void {
this.communityRD$ = this.route.data.pipe(map((data) => data.community));
this.communityRD$ = this.route.data.pipe(
map((data) => data.community as RemoteData<Community>),
renderPageNotFoundOn404(this.router)
);
this.logoRD$ = this.communityRD$.pipe(
map((rd: RemoteData<Community>) => rd.payload),
filter((community: Community) => hasValue(community)),

View File

@@ -2,9 +2,10 @@ import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { RemoteData } from '../core/data/remote-data';
import { getSucceededRemoteData } from '../core/shared/operators';
import { Community } from '../core/shared/community.model';
import { CommunityDataService } from '../core/data/community-data.service';
import { find } from 'rxjs/operators';
import { hasValue } from '../shared/empty.util';
/**
* This class represents a resolver that requests a specific community before the route is activated
@@ -22,7 +23,7 @@ export class CommunityPageResolver implements Resolve<RemoteData<Community>> {
*/
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Community>> {
return this.communityService.findById(route.params.id).pipe(
getSucceededRemoteData()
find((RD) => hasValue(RD.error) || RD.hasSucceeded),
);
}
}

View File

@@ -15,6 +15,7 @@ import { MetadataService } from '../../core/metadata/metadata.service';
import { fadeInOut } from '../../shared/animations/fade';
import { hasValue } from '../../shared/empty.util';
import { ItemViewMode } from '../../shared/items/item-type-decorator';
import { renderPageNotFoundOn404 } from '../../core/shared/operators';
/**
* This component renders a simple item page.
@@ -58,12 +59,10 @@ export class ItemPageComponent implements OnInit {
) { }
ngOnInit(): void {
this.itemRD$ = this.route.data.pipe(map((data) => data.item));
this.itemRD$.pipe(take(1)).subscribe((itemRD: RemoteData<Item>) => {
if (itemRD.hasFailed && itemRD.error.statusCode === 404) {
this.router.navigateByUrl('/404', { skipLocationChange: true });
}
});
this.itemRD$ = this.route.data.pipe(
map((data) => data.item as RemoteData<Item>),
renderPageNotFoundOn404(this.router)
);
this.metadataService.processRemoteData(this.itemRD$);
this.thumbnail$ = this.itemRD$.pipe(
map((rd: RemoteData<Item>) => rd.payload),

View File

@@ -1,5 +1,5 @@
import { Observable } from 'rxjs';
import { filter, find, flatMap, map, tap } from 'rxjs/operators';
import { filter, find, flatMap, map, take, tap } from 'rxjs/operators';
import { hasValue, hasValueOperator, isNotEmpty } from '../../shared/empty.util';
import { DSOSuccessResponse, RestResponse } from '../cache/response.models';
import { RemoteData } from '../data/remote-data';
@@ -10,6 +10,8 @@ import { BrowseDefinition } from './browse-definition.model';
import { DSpaceObject } from './dspace-object.model';
import { PaginatedList } from '../data/paginated-list';
import { SearchResult } from '../../+search-page/search-result.model';
import { Item } from './item.model';
import { Router } from '@angular/router';
/**
* This file contains custom RxJS operators that can be used in multiple places
@@ -62,6 +64,15 @@ export const getSucceededRemoteData = () =>
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
source.pipe(find((rd: RemoteData<T>) => rd.hasSucceeded));
export const renderPageNotFoundOn404 = (router: Router) =>
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
source.pipe(
tap((rd: RemoteData<T>) => {
if (rd.hasFailed && rd.error.statusCode === 404) {
router.navigateByUrl('/404', { skipLocationChange: true });
}
}));
export const getFinishedRemoteData = () =>
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
source.pipe(find((rd: RemoteData<T>) => !rd.isLoading));

View File

@@ -1,6 +1,12 @@
import { distinctUntilChanged, map, mergeMap, filter } from 'rxjs/operators';
import { distinctUntilChanged, filter, map, mergeMap } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Params, Router, RouterStateSnapshot, } from '@angular/router';
import {
ActivatedRoute,
NavigationEnd,
Params,
Router,
RouterStateSnapshot,
} from '@angular/router';
import { Observable } from 'rxjs';
import { select, Store } from '@ngrx/store';
@@ -136,5 +142,4 @@ export class RouteService {
map((history: string[]) => history[history.length - 2] || '')
);
}
}