mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-3362][ADF-3361] Search on document picker with custom site list - fix (#3592)
* [ADF-3362] Search on document picker with custom site list - fix * refactor & fix ADF-3361 & ADF-3362 * [ADF-3361][ADF-3362] set spy on the right method * [ADF-3361][ADF-3362] fix tests * [ADF-3361][ADF-3362] set constant * [ADF-3361][ADF-3362] remove unused method * [ADF-3361][ADF-3362] more relevant tests related to the fix * [ADF-3362] refactor method * [ADF-3362] fix tslint errors * remove pagination override
This commit is contained in:
committed by
Eugenio Romano
parent
cacf93ad2f
commit
cc9548b25a
@@ -27,7 +27,7 @@ import {
|
||||
} from '@alfresco/adf-core';
|
||||
|
||||
import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging } from 'alfresco-js-api';
|
||||
import { Observable, Subject, BehaviorSubject, Subscription, of } from 'rxjs';
|
||||
import { Subject, BehaviorSubject, Subscription, of } from 'rxjs';
|
||||
import { ShareDataRow } from './../data/share-data-row.model';
|
||||
import { ShareDataTableAdapter } from './../data/share-datatable-adapter';
|
||||
import { presetsDefaultModel } from '../models/preset.model';
|
||||
@@ -813,22 +813,6 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
this.pagination.value.skipCount = 0;
|
||||
}
|
||||
|
||||
// TODO: remove it from here
|
||||
getCorrespondingNodeIds(nodeId: string): Observable<string[]> {
|
||||
if (this.customResourcesService.isCustomSource(nodeId)) {
|
||||
return this.customResourcesService.getCorrespondingNodeIds(nodeId, this.pagination.getValue());
|
||||
} else if (nodeId) {
|
||||
return new Observable(observer => {
|
||||
this.documentListService.getFolderNode(nodeId, this.includeFields)
|
||||
.subscribe((node: MinimalNodeEntryEntity) => {
|
||||
observer.next([node.id]);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach(s => s.unsubscribe());
|
||||
this.subscriptions = [];
|
||||
|
@@ -30,7 +30,7 @@ import {
|
||||
} from 'alfresco-js-api';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, from, of, throwError } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class CustomResourcesService {
|
||||
@@ -261,6 +261,17 @@ export class CustomResourcesService {
|
||||
return isCustomSources;
|
||||
}
|
||||
|
||||
isSupportedSource(folderId: string): boolean {
|
||||
let isSupportedSources = false;
|
||||
const sources = ['-my-', '-root-', '-shared-'];
|
||||
|
||||
if (sources.indexOf(folderId) > -1) {
|
||||
isSupportedSources = true;
|
||||
}
|
||||
|
||||
return isSupportedSources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a folder's contents.
|
||||
* @param nodeId ID of the target folder node
|
||||
@@ -292,42 +303,37 @@ export class CustomResourcesService {
|
||||
* @param pagination Specifies how to paginate the results
|
||||
* @returns List of node IDs
|
||||
*/
|
||||
getCorrespondingNodeIds(nodeId: string, pagination: PaginationModel): Observable<string[]> {
|
||||
if (nodeId === '-trashcan-') {
|
||||
return from(this.apiService.nodesApi.getDeletedNodes()
|
||||
.then(result => result.list.entries.map(node => node.entry.id)));
|
||||
getCorrespondingNodeIds(nodeId: string, pagination: PaginationModel = {}): Observable<string[]> {
|
||||
if (this.isCustomSource(nodeId)) {
|
||||
|
||||
} else if (nodeId === '-sharedlinks-') {
|
||||
return from(this.apiService.sharedLinksApi.findSharedLinks()
|
||||
.then(result => result.list.entries.map(node => node.entry.nodeId)));
|
||||
return this.loadFolderByNodeId(nodeId, pagination, [])
|
||||
.pipe(map(result => result.list.entries.map((node: any) => {
|
||||
if (nodeId === '-sharedlinks-') {
|
||||
return node.entry.nodeId;
|
||||
|
||||
} else if (nodeId === '-sites-') {
|
||||
return from(this.apiService.sitesApi.getSites()
|
||||
.then(result => result.list.entries.map(node => node.entry.guid)));
|
||||
} else if (nodeId === '-sites-' || nodeId === '-mysites-') {
|
||||
return node.entry.guid;
|
||||
|
||||
} else if (nodeId === '-mysites-') {
|
||||
return from(this.apiService.peopleApi.getSiteMembership('-me-')
|
||||
.then(result => result.list.entries.map(node => node.entry.guid)));
|
||||
} else if (nodeId === '-favorites-') {
|
||||
return node.entry.targetGuid;
|
||||
}
|
||||
|
||||
} else if (nodeId === '-favorites-') {
|
||||
return from(this.apiService.favoritesApi.getFavorites('-me-')
|
||||
.then(result => result.list.entries.map(node => node.entry.targetGuid)));
|
||||
|
||||
} else if (nodeId === '-recent-') {
|
||||
return new Observable(observer => {
|
||||
this.getRecentFiles('-me-', pagination)
|
||||
.subscribe((recentFiles) => {
|
||||
let recentFilesIdS = recentFiles.list.entries.map(node => node.entry.id);
|
||||
observer.next(recentFilesIdS);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
return node.entry.id;
|
||||
})));
|
||||
|
||||
} else if (nodeId) {
|
||||
// cases when nodeId is '-my-', '-root-' or '-shared-'
|
||||
return from(this.apiService.nodesApi.getNode(nodeId)
|
||||
.then(node => [node.entry.id]));
|
||||
}
|
||||
|
||||
return of([]);
|
||||
}
|
||||
|
||||
hasCorrespondingNodeIds(nodeId: string): boolean {
|
||||
return this.isCustomSource(nodeId) || this.isSupportedSource(nodeId);
|
||||
}
|
||||
|
||||
private getIncludesFields(includeFields: string[]): string[] {
|
||||
return ['path', 'properties', 'allowableOperations', 'permissions', ...includeFields]
|
||||
.filter((element, index, array) => index === array.indexOf(element));
|
||||
|
Reference in New Issue
Block a user