[ADF-3854] Destination picker - exclude site content option (#4130)

This commit is contained in:
Suzana Dirla
2019-01-13 20:25:01 +02:00
committed by Eugenio Romano
parent 6be1cf56e3
commit c17241fedc
9 changed files with 98 additions and 3 deletions

View File

@@ -32,6 +32,14 @@ import { switchMap } from 'rxjs/operators';
providedIn: 'root'
})
export class ContentNodeDialogService {
static nonDocumentSiteContent = [
'blog',
'calendar',
'dataLists',
'discussions',
'links',
'wiki'
];
/** Emitted when an error occurs. */
@Output()
@@ -117,9 +125,10 @@ export class ContentNodeDialogService {
* @param action Name of the action (eg, "Copy" or "Move") to show in the title
* @param contentEntry Item to be copied or moved
* @param permission Permission for the operation
* @param excludeSiteContent The site content that should be filtered out
* @returns Information about files that were copied/moved
*/
openCopyMoveDialog(action: string, contentEntry: Node, permission?: string): Observable<Node[]> {
openCopyMoveDialog(action: string, contentEntry: Node, permission?: string, excludeSiteContent?: string[]): Observable<Node[]> {
if (this.contentService.hasPermission(contentEntry, permission)) {
const select = new Subject<Node[]>();
@@ -136,6 +145,7 @@ export class ContentNodeDialogService {
imageResolver: this.imageResolver.bind(this),
rowFilter: this.rowFilter.bind(this, contentEntry.id),
isSelectionValid: this.isCopyMoveSelectionValid.bind(this),
excludeSiteContent: excludeSiteContent || ContentNodeDialogService.nonDocumentSiteContent,
select: select
};

View File

@@ -107,6 +107,21 @@ describe('ContentNodeSelectorComponent', () => {
component.chosenNode = expectedNode;
});
it('should be able to filter out the exclude site content', () => {
component.excludeSiteContent = ['blog'];
fixture.detectChanges();
const testSiteContent = new Node({id: 'blog-id', properties: { 'st:componentId': 'blog' }});
expect(component.rowFilter(<any> {node: {entry: testSiteContent}}, null, null)).toBe(false);
});
it('should NOT filter out any site content by default', () => {
fixture.detectChanges();
const testSiteContent = new Node({id: 'blog-id', properties: { 'st:componentId': 'blog' }});
expect(component.rowFilter(<any> {node: {entry: testSiteContent}}, null, null)).toBe(true);
});
});
describe('Breadcrumbs', () => {

View File

@@ -29,6 +29,7 @@ import { ContentNodeSelectorService } from './content-node-selector.service';
import { debounceTime } from 'rxjs/operators';
import { BehaviorSubject } from 'rxjs';
import { CustomResourcesService } from '../document-list/services/custom-resources.service';
import { ShareDataRow } from '../document-list';
export type ValidationFunction = (entry: Node) => boolean;
@@ -68,6 +69,12 @@ export class ContentNodeSelectorPanelComponent implements OnInit, PaginatedCompo
@Input()
rowFilter: RowFilter = null;
/** Custom list of site content componentIds.
* Used to filter out the corresponding items from the displayed nodes
*/
@Input()
excludeSiteContent: string[] = [];
/** Custom image resolver function. See the
* [Document List component](document-list.component.md#custom-row-filter)
* for more information.
@@ -159,6 +166,32 @@ export class ContentNodeSelectorPanelComponent implements OnInit, PaginatedCompo
this.breadcrumbTransform = this.breadcrumbTransform ? this.breadcrumbTransform : null;
this.isSelectionValid = this.isSelectionValid ? this.isSelectionValid : defaultValidation;
this.excludeSiteContent = this.excludeSiteContent ? this.excludeSiteContent : [];
this.rowFilter = this.getRowFilter(this.rowFilter);
}
private getRowFilter(initialFilterFunction): RowFilter {
if (!initialFilterFunction) {
initialFilterFunction = () => true;
}
return (value: ShareDataRow, index: number, array: ShareDataRow[]) => {
return initialFilterFunction(value, index, array) &&
!this.isExcludedSiteContent(value);
};
}
private isExcludedSiteContent(row: ShareDataRow): boolean {
const entry = row.node.entry;
if (this.excludeSiteContent.length &&
entry &&
entry.properties &&
entry.properties['st:componentId']) {
const excludedItem = this.excludeSiteContent.find(
(id: string) => entry.properties['st:componentId'] === id
);
return !!excludedItem;
}
return false;
}
/**

View File

@@ -28,5 +28,6 @@ export interface ContentNodeSelectorComponentData {
imageResolver?: any;
isSelectionValid?: (entry: Node) => boolean;
breadcrumbTransform?: (node) => any;
excludeSiteContent?: string[];
select: Subject<Node[]>;
}

View File

@@ -12,6 +12,7 @@
[imageResolver]="imageResolver || data?.imageResolver"
[isSelectionValid]="data?.isSelectionValid"
[breadcrumbTransform]="data?.breadcrumbTransform"
[excludeSiteContent]="data?.excludeSiteContent"
(select)="onSelect($event)">
</adf-content-node-selector-panel>
</mat-dialog-content>

View File

@@ -54,7 +54,7 @@ describe('ContentNodeSelectorDialogComponent', () => {
const documentListService: DocumentListService = TestBed.get(DocumentListService);
const sitesService: SitesService = TestBed.get(SitesService);
spyOn(documentListService, 'getFolder').and.returnValue(of({ list: [] }));
spyOn(documentListService, 'getFolderNode').and.returnValue(of({}));
spyOn(documentListService, 'getFolderNode').and.returnValue(of({ entry: {} }));
spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } }));
fixture = TestBed.createComponent(ContentNodeSelectorComponent);