mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
66391: Fixed the valse positive chevron indicating node is expandable
This commit is contained in:
@@ -4,7 +4,7 @@ import { Observable, of as observableOf } from 'rxjs';
|
|||||||
import {CommunityDataService} from '../core/data/community-data.service';
|
import {CommunityDataService} from '../core/data/community-data.service';
|
||||||
import {PaginationComponentOptions} from '../shared/pagination/pagination-component-options.model';
|
import {PaginationComponentOptions} from '../shared/pagination/pagination-component-options.model';
|
||||||
import {SortDirection, SortOptions} from '../core/cache/models/sort-options.model';
|
import {SortDirection, SortOptions} from '../core/cache/models/sort-options.model';
|
||||||
import { catchError, filter, map, switchMap, take, tap } from 'rxjs/operators';
|
import {catchError, filter, map, switchMap, take} from 'rxjs/operators';
|
||||||
import {Community} from '../core/shared/community.model';
|
import {Community} from '../core/shared/community.model';
|
||||||
import {Collection} from '../core/shared/collection.model';
|
import {Collection} from '../core/shared/collection.model';
|
||||||
import {hasValue, isNotEmpty} from '../shared/empty.util';
|
import {hasValue, isNotEmpty} from '../shared/empty.util';
|
||||||
@@ -15,7 +15,7 @@ import { getCollectionPageRoute } from '../+collection-page/collection-page-rout
|
|||||||
import {CollectionDataService} from '../core/data/collection-data.service';
|
import {CollectionDataService} from '../core/data/collection-data.service';
|
||||||
|
|
||||||
export interface FlatNode {
|
export interface FlatNode {
|
||||||
isExpandable: boolean;
|
isExpandable$: Observable<boolean>;
|
||||||
name: string;
|
name: string;
|
||||||
id: string;
|
id: string;
|
||||||
level: number;
|
level: number;
|
||||||
@@ -39,12 +39,12 @@ export const combineAndFlatten = (obsList: Array<Observable<FlatNode[]>>): Obser
|
|||||||
|
|
||||||
export const toFlatNode = (
|
export const toFlatNode = (
|
||||||
c: Community | Collection,
|
c: Community | Collection,
|
||||||
isExpandable: boolean,
|
isExpandable: Observable<boolean>,
|
||||||
level: number,
|
level: number,
|
||||||
isExpanded: boolean,
|
isExpanded: boolean,
|
||||||
parent?: FlatNode
|
parent?: FlatNode
|
||||||
): FlatNode => ({
|
): FlatNode => ({
|
||||||
isExpandable: isExpandable,
|
isExpandable$: isExpandable,
|
||||||
name: c.name,
|
name: c.name,
|
||||||
id: c.id,
|
id: c.id,
|
||||||
level: level,
|
level: level,
|
||||||
@@ -60,7 +60,7 @@ export const showMoreFlatNode = (
|
|||||||
level: number,
|
level: number,
|
||||||
parent: FlatNode
|
parent: FlatNode
|
||||||
): FlatNode => ({
|
): FlatNode => ({
|
||||||
isExpandable: false,
|
isExpandable$: observableOf(false),
|
||||||
name: 'Show More Flatnode',
|
name: 'Show More Flatnode',
|
||||||
id: id,
|
id: id,
|
||||||
level: level,
|
level: level,
|
||||||
@@ -194,9 +194,9 @@ export class CommunityListService {
|
|||||||
isExpanded = hasValue(expandedNodes.find((node) => (node.id === community.id)));
|
isExpanded = hasValue(expandedNodes.find((node) => (node.id === community.id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const isExpandable = this.getIsExpandable(community);
|
const isExpandable$ = this.getIsExpandable(community);
|
||||||
|
|
||||||
const communityFlatNode = toFlatNode(community, isExpandable, level, isExpanded, parent);
|
const communityFlatNode = toFlatNode(community, isExpandable$, level, isExpanded, parent);
|
||||||
|
|
||||||
let obsList = [observableOf([communityFlatNode])];
|
let obsList = [observableOf([communityFlatNode])];
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ export class CommunityListService {
|
|||||||
take(1),
|
take(1),
|
||||||
map((rd: RemoteData<PaginatedList<Collection>>) => {
|
map((rd: RemoteData<PaginatedList<Collection>>) => {
|
||||||
let nodes = rd.payload.page
|
let nodes = rd.payload.page
|
||||||
.map((collection: Collection) => toFlatNode(collection, false, level + 1, false, communityFlatNode));
|
.map((collection: Collection) => toFlatNode(collection, observableOf(false), level + 1, false, communityFlatNode));
|
||||||
if ((rd.payload.elementsPerPage * currentCollectionPage) < rd.payload.totalElements && rd.payload.currentPage > currentCollectionPage) {
|
if ((rd.payload.elementsPerPage * currentCollectionPage) < rd.payload.totalElements && rd.payload.currentPage > currentCollectionPage) {
|
||||||
nodes = [...nodes, showMoreFlatNode('collection', level + 1, communityFlatNode)];
|
nodes = [...nodes, showMoreFlatNode('collection', level + 1, communityFlatNode)];
|
||||||
}
|
}
|
||||||
@@ -249,40 +249,40 @@ export class CommunityListService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a community has subcommunities or collections by querying the respective services with a pageSize = 0
|
* Checks if a community has subcommunities or collections by querying the respective services with a pageSize = 0
|
||||||
* If it does, it is expandable => returns true, false if not
|
* Returns an observable that combines the result.payload.totalElements fo the observables that the
|
||||||
|
* respective services return when queried
|
||||||
* @param community Community being checked whether it is expandable (if it has subcommunities or collections)
|
* @param community Community being checked whether it is expandable (if it has subcommunities or collections)
|
||||||
*/
|
*/
|
||||||
public getIsExpandable(community: Community): boolean {
|
public getIsExpandable(community: Community): Observable<boolean> {
|
||||||
let isExpandable = true;
|
let hasSubcoms$: Observable<boolean>;
|
||||||
let nrOfSubcoms;
|
let hasColls$: Observable<boolean>;
|
||||||
let nrOfColl;
|
hasSubcoms$ = this.communityDataService.findByParent(community.uuid, {elementsPerPage: 1})
|
||||||
this.communityDataService.findByParent(community.uuid, { elementsPerPage: 0 })
|
|
||||||
.pipe(
|
.pipe(
|
||||||
filter((rd: RemoteData<PaginatedList<Community>>) => rd.hasSucceeded),
|
filter((rd: RemoteData<PaginatedList<Community>>) => rd.hasSucceeded),
|
||||||
take(1),
|
take(1),
|
||||||
)
|
map((results) => results.payload.totalElements > 0),
|
||||||
.subscribe((result) => {
|
);
|
||||||
if (result.payload.totalElements === 0) {
|
|
||||||
nrOfSubcoms = result.payload.totalElements;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.collectionDataService.findByParent(community.uuid, { elementsPerPage: 0 })
|
hasColls$ = this.collectionDataService.findByParent(community.uuid, {elementsPerPage: 1})
|
||||||
.pipe(
|
.pipe(
|
||||||
filter((rd: RemoteData<PaginatedList<Collection>>) => rd.hasSucceeded),
|
filter((rd: RemoteData<PaginatedList<Community>>) => rd.hasSucceeded),
|
||||||
take(1),
|
take(1),
|
||||||
)
|
map((results) => results.payload.totalElements > 0),
|
||||||
.subscribe((result) => {
|
);
|
||||||
if (result.payload.totalElements === 0) {
|
|
||||||
nrOfColl = result.payload.totalElements;
|
let hasChildren$: Observable<boolean>;
|
||||||
|
hasChildren$ = observableCombineLatest(hasSubcoms$, hasColls$).pipe(
|
||||||
|
take(1),
|
||||||
|
map((result: [boolean]) => {
|
||||||
|
if (result[0] || result[1]) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
;
|
})
|
||||||
});
|
);
|
||||||
if (nrOfSubcoms === 0 && nrOfColl === 0) {
|
|
||||||
isExpandable = false;
|
return hasChildren$;
|
||||||
}
|
|
||||||
return isExpandable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
<button type="button" class="btn btn-default" cdkTreeNodeToggle
|
<button type="button" class="btn btn-default" cdkTreeNodeToggle
|
||||||
[attr.aria-label]="'toggle ' + node.name"
|
[attr.aria-label]="'toggle ' + node.name"
|
||||||
(click)="toggleExpanded(node)"
|
(click)="toggleExpanded(node)"
|
||||||
[ngClass]="node.isExpandable ? 'visible' : 'invisible'">
|
[ngClass]="(node.isExpandable$ | async) ? 'visible' : 'invisible'">
|
||||||
<span class="{{node.isExpanded ? 'fa fa-chevron-down' : 'fa fa-chevron-right'}}"
|
<span class="{{node.isExpanded ? 'fa fa-chevron-down' : 'fa fa-chevron-right'}}"
|
||||||
aria-hidden="true"></span>
|
aria-hidden="true"></span>
|
||||||
</button>
|
</button>
|
||||||
|
@@ -14,7 +14,7 @@ export class CommunityListComponent implements OnInit {
|
|||||||
public loadingNode: FlatNode;
|
public loadingNode: FlatNode;
|
||||||
|
|
||||||
treeControl = new FlatTreeControl<FlatNode>(
|
treeControl = new FlatTreeControl<FlatNode>(
|
||||||
(node) => node.level, (node) => node.isExpandable
|
(node) => node.level, (node) => true
|
||||||
);
|
);
|
||||||
|
|
||||||
dataSource: CommunityListDatasource;
|
dataSource: CommunityListDatasource;
|
||||||
@@ -29,7 +29,7 @@ export class CommunityListComponent implements OnInit {
|
|||||||
|
|
||||||
// whether or not this node has children (subcommunities or collections)
|
// whether or not this node has children (subcommunities or collections)
|
||||||
hasChild(_: number, node: FlatNode) {
|
hasChild(_: number, node: FlatNode) {
|
||||||
return node.isExpandable;
|
return node.isExpandable$;
|
||||||
}
|
}
|
||||||
|
|
||||||
// whether or not it is a show more node (contains no data, but is indication that there are more topcoms, subcoms or collections
|
// whether or not it is a show more node (contains no data, but is indication that there are more topcoms, subcoms or collections
|
||||||
@@ -68,7 +68,6 @@ export class CommunityListComponent implements OnInit {
|
|||||||
getNextPage(node: FlatNode): void {
|
getNextPage(node: FlatNode): void {
|
||||||
this.loadingNode = node;
|
this.loadingNode = node;
|
||||||
if (node.parent != null) {
|
if (node.parent != null) {
|
||||||
if (node.parent.isExpandable) {
|
|
||||||
if (node.id === 'collection') {
|
if (node.id === 'collection') {
|
||||||
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
||||||
parentNodeInExpandedNodes.currentCollectionPage++;
|
parentNodeInExpandedNodes.currentCollectionPage++;
|
||||||
@@ -77,7 +76,6 @@ export class CommunityListComponent implements OnInit {
|
|||||||
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
||||||
parentNodeInExpandedNodes.currentCommunityPage++;
|
parentNodeInExpandedNodes.currentCommunityPage++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.dataSource.loadCommunities(this.expandedNodes);
|
this.dataSource.loadCommunities(this.expandedNodes);
|
||||||
} else {
|
} else {
|
||||||
this.communityListService.getNextPageTopCommunities();
|
this.communityListService.getNextPageTopCommunities();
|
||||||
|
Reference in New Issue
Block a user