mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
66391: Fixed the valse positive chevron indicating node is expandable
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { combineLatest as observableCombineLatest } from 'rxjs/internal/observable/combineLatest';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { CommunityDataService } from '../core/data/community-data.service';
|
||||
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
||||
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
||||
import { catchError, filter, map, switchMap, take, tap } from 'rxjs/operators';
|
||||
import { Community } from '../core/shared/community.model';
|
||||
import { Collection } from '../core/shared/collection.model';
|
||||
import { hasValue, isNotEmpty } from '../shared/empty.util';
|
||||
import { RemoteData } from '../core/data/remote-data';
|
||||
import { PaginatedList } from '../core/data/paginated-list';
|
||||
import { getCommunityPageRoute } from '../+community-page/community-page-routing.module';
|
||||
import { getCollectionPageRoute } from '../+collection-page/collection-page-routing.module';
|
||||
import { CollectionDataService } from '../core/data/collection-data.service';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {combineLatest as observableCombineLatest} from 'rxjs/internal/observable/combineLatest';
|
||||
import {Observable, of as observableOf} from 'rxjs';
|
||||
import {CommunityDataService} from '../core/data/community-data.service';
|
||||
import {PaginationComponentOptions} from '../shared/pagination/pagination-component-options.model';
|
||||
import {SortDirection, SortOptions} from '../core/cache/models/sort-options.model';
|
||||
import {catchError, filter, map, switchMap, take} from 'rxjs/operators';
|
||||
import {Community} from '../core/shared/community.model';
|
||||
import {Collection} from '../core/shared/collection.model';
|
||||
import {hasValue, isNotEmpty} from '../shared/empty.util';
|
||||
import {RemoteData} from '../core/data/remote-data';
|
||||
import {PaginatedList} from '../core/data/paginated-list';
|
||||
import {getCommunityPageRoute} from '../+community-page/community-page-routing.module';
|
||||
import {getCollectionPageRoute} from '../+collection-page/collection-page-routing.module';
|
||||
import {CollectionDataService} from '../core/data/collection-data.service';
|
||||
|
||||
export interface FlatNode {
|
||||
isExpandable: boolean;
|
||||
isExpandable$: Observable<boolean>;
|
||||
name: string;
|
||||
id: string;
|
||||
level: number;
|
||||
@@ -39,12 +39,12 @@ export const combineAndFlatten = (obsList: Array<Observable<FlatNode[]>>): Obser
|
||||
|
||||
export const toFlatNode = (
|
||||
c: Community | Collection,
|
||||
isExpandable: boolean,
|
||||
isExpandable: Observable<boolean>,
|
||||
level: number,
|
||||
isExpanded: boolean,
|
||||
parent?: FlatNode
|
||||
): FlatNode => ({
|
||||
isExpandable: isExpandable,
|
||||
isExpandable$: isExpandable,
|
||||
name: c.name,
|
||||
id: c.id,
|
||||
level: level,
|
||||
@@ -60,7 +60,7 @@ export const showMoreFlatNode = (
|
||||
level: number,
|
||||
parent: FlatNode
|
||||
): FlatNode => ({
|
||||
isExpandable: false,
|
||||
isExpandable$: observableOf(false),
|
||||
name: 'Show More Flatnode',
|
||||
id: id,
|
||||
level: level,
|
||||
@@ -194,9 +194,9 @@ export class CommunityListService {
|
||||
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])];
|
||||
|
||||
@@ -232,7 +232,7 @@ export class CommunityListService {
|
||||
take(1),
|
||||
map((rd: RemoteData<PaginatedList<Collection>>) => {
|
||||
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) {
|
||||
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
|
||||
* 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)
|
||||
*/
|
||||
public getIsExpandable(community: Community): boolean {
|
||||
let isExpandable = true;
|
||||
let nrOfSubcoms;
|
||||
let nrOfColl;
|
||||
this.communityDataService.findByParent(community.uuid, { elementsPerPage: 0 })
|
||||
public getIsExpandable(community: Community): Observable<boolean> {
|
||||
let hasSubcoms$: Observable<boolean>;
|
||||
let hasColls$: Observable<boolean>;
|
||||
hasSubcoms$ = this.communityDataService.findByParent(community.uuid, {elementsPerPage: 1})
|
||||
.pipe(
|
||||
filter((rd: RemoteData<PaginatedList<Community>>) => rd.hasSucceeded),
|
||||
take(1),
|
||||
)
|
||||
.subscribe((result) => {
|
||||
if (result.payload.totalElements === 0) {
|
||||
nrOfSubcoms = result.payload.totalElements;
|
||||
}
|
||||
;
|
||||
});
|
||||
map((results) => results.payload.totalElements > 0),
|
||||
);
|
||||
|
||||
this.collectionDataService.findByParent(community.uuid, { elementsPerPage: 0 })
|
||||
hasColls$ = this.collectionDataService.findByParent(community.uuid, {elementsPerPage: 1})
|
||||
.pipe(
|
||||
filter((rd: RemoteData<PaginatedList<Collection>>) => rd.hasSucceeded),
|
||||
filter((rd: RemoteData<PaginatedList<Community>>) => rd.hasSucceeded),
|
||||
take(1),
|
||||
)
|
||||
.subscribe((result) => {
|
||||
if (result.payload.totalElements === 0) {
|
||||
nrOfColl = result.payload.totalElements;
|
||||
map((results) => results.payload.totalElements > 0),
|
||||
);
|
||||
|
||||
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 isExpandable;
|
||||
})
|
||||
);
|
||||
|
||||
return hasChildren$;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@
|
||||
<button type="button" class="btn btn-default" cdkTreeNodeToggle
|
||||
[attr.aria-label]="'toggle ' + node.name"
|
||||
(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'}}"
|
||||
aria-hidden="true"></span>
|
||||
</button>
|
||||
|
@@ -14,7 +14,7 @@ export class CommunityListComponent implements OnInit {
|
||||
public loadingNode: FlatNode;
|
||||
|
||||
treeControl = new FlatTreeControl<FlatNode>(
|
||||
(node) => node.level, (node) => node.isExpandable
|
||||
(node) => node.level, (node) => true
|
||||
);
|
||||
|
||||
dataSource: CommunityListDatasource;
|
||||
@@ -29,7 +29,7 @@ export class CommunityListComponent implements OnInit {
|
||||
|
||||
// whether or not this node has children (subcommunities or collections)
|
||||
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
|
||||
@@ -68,7 +68,6 @@ export class CommunityListComponent implements OnInit {
|
||||
getNextPage(node: FlatNode): void {
|
||||
this.loadingNode = node;
|
||||
if (node.parent != null) {
|
||||
if (node.parent.isExpandable) {
|
||||
if (node.id === 'collection') {
|
||||
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
||||
parentNodeInExpandedNodes.currentCollectionPage++;
|
||||
@@ -77,7 +76,6 @@ export class CommunityListComponent implements OnInit {
|
||||
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
||||
parentNodeInExpandedNodes.currentCommunityPage++;
|
||||
}
|
||||
}
|
||||
this.dataSource.loadCommunities(this.expandedNodes);
|
||||
} else {
|
||||
this.communityListService.getNextPageTopCommunities();
|
||||
|
Reference in New Issue
Block a user