mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
fixed an issue where the pagination would always open on the first page if you went to the URL of a different page
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
|
import {
|
||||||
|
ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy,
|
||||||
|
OnInit
|
||||||
|
} from '@angular/core';
|
||||||
import { ActivatedRoute, Params } from '@angular/router';
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
|
|
||||||
import { Collection } from "../core/shared/collection.model";
|
import { Collection } from "../core/shared/collection.model";
|
||||||
@@ -11,11 +14,13 @@ import { Item } from "../core/shared/item.model";
|
|||||||
import { SortOptions, SortDirection } from "../core/cache/models/sort-options.model";
|
import { SortOptions, SortDirection } from "../core/cache/models/sort-options.model";
|
||||||
import { PaginationComponentOptions } from "../shared/pagination/pagination-component-options.model";
|
import { PaginationComponentOptions } from "../shared/pagination/pagination-component-options.model";
|
||||||
import { Observable } from "rxjs/Observable";
|
import { Observable } from "rxjs/Observable";
|
||||||
|
import { hasValue } from "../shared/empty.util";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-collection-page',
|
selector: 'ds-collection-page',
|
||||||
styleUrls: ['./collection-page.component.css'],
|
styleUrls: ['./collection-page.component.css'],
|
||||||
templateUrl: './collection-page.component.html',
|
templateUrl: './collection-page.component.html',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
})
|
})
|
||||||
export class CollectionPageComponent implements OnInit, OnDestroy {
|
export class CollectionPageComponent implements OnInit, OnDestroy {
|
||||||
collectionData: RemoteData<Collection>;
|
collectionData: RemoteData<Collection>;
|
||||||
@@ -45,7 +50,7 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.config = new PaginationComponentOptions();
|
this.config = new PaginationComponentOptions();
|
||||||
this.config.id = "collection-browse";
|
this.config.id = "collection-browse";
|
||||||
this.config.pageSizeOptions = [ 5, 10, 20, 40, 60, 80, 100 ];
|
this.config.pageSizeOptions = [ 4 ];
|
||||||
this.config.pageSize = 4;
|
this.config.pageSize = 4;
|
||||||
this.sortConfig = new SortOptions();
|
this.sortConfig = new SortOptions();
|
||||||
|
|
||||||
@@ -55,7 +60,9 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.subs.forEach(sub => sub.unsubscribe());
|
this.subs
|
||||||
|
.filter(sub => hasValue(sub))
|
||||||
|
.forEach(sub => sub.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
universalInit() {
|
universalInit() {
|
||||||
@@ -89,6 +96,6 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
|
|||||||
elementsPerPage: this.config.pageSize,
|
elementsPerPage: this.config.pageSize,
|
||||||
sort: this.sortConfig
|
sort: this.sortConfig
|
||||||
});
|
});
|
||||||
this.ref.detectChanges();
|
// this.ref.detectChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ import { Bitstream } from "../core/shared/bitstream.model";
|
|||||||
import { RemoteData } from "../core/data/remote-data";
|
import { RemoteData } from "../core/data/remote-data";
|
||||||
import { CommunityDataService } from "../core/data/community-data.service";
|
import { CommunityDataService } from "../core/data/community-data.service";
|
||||||
import { Subscription } from "rxjs/Subscription";
|
import { Subscription } from "rxjs/Subscription";
|
||||||
|
import { hasValue } from "../shared/empty.util";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-community-page',
|
selector: 'ds-community-page',
|
||||||
@@ -33,7 +34,9 @@ export class CommunityPageComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.subs.forEach(sub => sub.unsubscribe());
|
this.subs
|
||||||
|
.filter(sub => hasValue(sub))
|
||||||
|
.forEach(sub => sub.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
universalInit() {
|
universalInit() {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
|
import { Component, OnInit, ChangeDetectorRef, ChangeDetectionStrategy } from '@angular/core';
|
||||||
import { RemoteData } from "../../core/data/remote-data";
|
import { RemoteData } from "../../core/data/remote-data";
|
||||||
import { CommunityDataService } from "../../core/data/community-data.service";
|
import { CommunityDataService } from "../../core/data/community-data.service";
|
||||||
import { Community } from "../../core/shared/community.model";
|
import { Community } from "../../core/shared/community.model";
|
||||||
@@ -8,7 +8,8 @@ import { SortOptions, SortDirection } from "../../core/cache/models/sort-options
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-top-level-community-list',
|
selector: 'ds-top-level-community-list',
|
||||||
styleUrls: ['./top-level-community-list.component.css'],
|
styleUrls: ['./top-level-community-list.component.css'],
|
||||||
templateUrl: './top-level-community-list.component.html'
|
templateUrl: './top-level-community-list.component.html',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
})
|
})
|
||||||
export class TopLevelCommunityListComponent implements OnInit {
|
export class TopLevelCommunityListComponent implements OnInit {
|
||||||
topLevelCommunities: RemoteData<Community[]>;
|
topLevelCommunities: RemoteData<Community[]>;
|
||||||
@@ -29,7 +30,7 @@ export class TopLevelCommunityListComponent implements OnInit {
|
|||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.config = new PaginationComponentOptions();
|
this.config = new PaginationComponentOptions();
|
||||||
this.config.id = "top-level-pagination";
|
this.config.id = "top-level-pagination";
|
||||||
this.config.pageSizeOptions = [ 5, 10, 20, 40, 60, 80, 100 ];
|
this.config.pageSizeOptions = [ 4 ];
|
||||||
this.config.pageSize = 4;
|
this.config.pageSize = 4;
|
||||||
this.sortConfig = new SortOptions();
|
this.sortConfig = new SortOptions();
|
||||||
|
|
||||||
@@ -59,6 +60,6 @@ export class TopLevelCommunityListComponent implements OnInit {
|
|||||||
updateResults() {
|
updateResults() {
|
||||||
this.topLevelCommunities = undefined;
|
this.topLevelCommunities = undefined;
|
||||||
this.topLevelCommunities = this.cds.findAll({ currentPage: this.config.currentPage, elementsPerPage: this.config.pageSize, sort: this.sortConfig });
|
this.topLevelCommunities = this.cds.findAll({ currentPage: this.config.currentPage, elementsPerPage: this.config.pageSize, sort: this.sortConfig });
|
||||||
this.ref.detectChanges();
|
// this.ref.detectChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import {
|
|||||||
ViewEncapsulation
|
ViewEncapsulation
|
||||||
} from '@angular/core'
|
} from '@angular/core'
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { Subscription } from "rxjs/Subscription";
|
||||||
import { isNumeric } from "rxjs/util/isNumeric";
|
import { isNumeric } from "rxjs/util/isNumeric";
|
||||||
import 'rxjs/add/operator/switchMap';
|
import 'rxjs/add/operator/switchMap';
|
||||||
import { Observable } from "rxjs";
|
import { Observable } from "rxjs";
|
||||||
@@ -139,11 +140,11 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
*/
|
*/
|
||||||
public paginationControls;
|
public paginationControls;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscriber to observable.
|
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||||
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
private routeSubscription: any;
|
private subs: Subscription[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object that represents pagination details of the current viewed page
|
* An object that represents pagination details of the current viewed page
|
||||||
@@ -153,19 +154,14 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
total: null
|
total: null
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Subscriber to observable.
|
|
||||||
*/
|
|
||||||
private stateSubscription: any;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method provided by Angular. Invoked after the constructor.
|
* Method provided by Angular. Invoked after the constructor.
|
||||||
*/
|
*/
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.stateSubscription = this.hostWindowService.isXs()
|
this.subs.push(this.hostWindowService.isXs()
|
||||||
.subscribe((status: boolean) => {
|
.subscribe((status: boolean) => {
|
||||||
this.isXs = status;
|
this.isXs = status;
|
||||||
});
|
}));
|
||||||
this.checkConfig(this.paginationOptions);
|
this.checkConfig(this.paginationOptions);
|
||||||
this.id = this.paginationOptions.id || null;
|
this.id = this.paginationOptions.id || null;
|
||||||
this.currentPage = this.paginationOptions.currentPage;
|
this.currentPage = this.paginationOptions.currentPage;
|
||||||
@@ -173,7 +169,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
this.pageSizeOptions = this.paginationOptions.pageSizeOptions;
|
this.pageSizeOptions = this.paginationOptions.pageSizeOptions;
|
||||||
this.sortDirection = this.sortOptions.direction;
|
this.sortDirection = this.sortOptions.direction;
|
||||||
this.sortField = this.sortOptions.field;
|
this.sortField = this.sortOptions.field;
|
||||||
this.routeSubscription = this.route.queryParams
|
this.subs.push(this.route.queryParams
|
||||||
.filter(queryParams => hasValue(queryParams))
|
.filter(queryParams => hasValue(queryParams))
|
||||||
.subscribe(queryParams => {
|
.subscribe(queryParams => {
|
||||||
this.currentQueryParams = queryParams;
|
this.currentQueryParams = queryParams;
|
||||||
@@ -185,7 +181,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
) {
|
) {
|
||||||
this.validateParams(queryParams['page'], queryParams['pageSize'], queryParams['sortDirection'], queryParams['sortField']);
|
this.validateParams(queryParams['page'], queryParams['pageSize'], queryParams['sortDirection'], queryParams['sortField']);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
this.setShowingDetail();
|
this.setShowingDetail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,8 +189,9 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
* Method provided by Angular. Invoked when the instance is destroyed.
|
* Method provided by Angular. Invoked when the instance is destroyed.
|
||||||
*/
|
*/
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.stateSubscription.unsubscribe();
|
this.subs
|
||||||
this.routeSubscription.unsubscribe();
|
.filter(sub => hasValue(sub))
|
||||||
|
.forEach(sub => sub.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user