mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3854] destination picker - exclude site content after rowFilter reset (#4158)
* [ADF-3854] exclude set site content after rowFilter reset * [ADF-3854] fix duplicated call * [ADF-3854] add test * fix unrelated failing test * improve type definition add set get filtering node selector * remove comma * [ADF-3854] demo-shell - case when rowFilter is not set for adf-content-node-selector-panel
This commit is contained in:
committed by
Eugenio Romano
parent
cf922dd46e
commit
08cdb2f7c3
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { Component, ViewEncapsulation } from '@angular/core';
|
import { Component, ViewEncapsulation } from '@angular/core';
|
||||||
import { SitePaging, SiteEntry, MinimalNodeEntryEntity } from '@alfresco/js-api';
|
import { SitePaging, SiteEntry, MinimalNodeEntryEntity } from '@alfresco/js-api';
|
||||||
import { ContentNodeDialogService, ShareDataRow } from '@alfresco/adf-content-services';
|
import { ContentNodeDialogService, ShareDataRow, RowFilter } from '@alfresco/adf-content-services';
|
||||||
import { DataRow, DataColumn, ThumbnailService } from '@alfresco/adf-core';
|
import { DataRow, DataColumn, ThumbnailService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -40,7 +40,7 @@ export class ContentNodeSelectorComponent {
|
|||||||
customSideTitle = '';
|
customSideTitle = '';
|
||||||
actualPageSize = 2;
|
actualPageSize = 2;
|
||||||
|
|
||||||
rowFilterFunction: any = null;
|
rowFilterFunction: RowFilter = null;
|
||||||
excludeSiteContentList: string[] = ContentNodeDialogService.nonDocumentSiteContent;
|
excludeSiteContentList: string[] = ContentNodeDialogService.nonDocumentSiteContent;
|
||||||
customImageResolver: any = null;
|
customImageResolver: any = null;
|
||||||
|
|
||||||
|
@@ -190,8 +190,15 @@ export class ContentServicesPage {
|
|||||||
checkElementsSortedAsc(elements) {
|
checkElementsSortedAsc(elements) {
|
||||||
let sorted = true;
|
let sorted = true;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
let compareNumbers = false;
|
||||||
|
|
||||||
|
if (elements && elements[0] && typeof elements[0] === 'number') {
|
||||||
|
compareNumbers = true;
|
||||||
|
}
|
||||||
while (elements.length > 1 && sorted === true && i < (elements.length - 1)) {
|
while (elements.length > 1 && sorted === true && i < (elements.length - 1)) {
|
||||||
if (JSON.stringify(elements[i]) > JSON.stringify(elements[i + 1])) {
|
const left = compareNumbers ? elements[i] : JSON.stringify(elements[i]);
|
||||||
|
const right = compareNumbers ? elements[i + 1] : JSON.stringify(elements[i + 1]);
|
||||||
|
if (left > right) {
|
||||||
sorted = false;
|
sorted = false;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
@@ -58,7 +58,7 @@
|
|||||||
[showHeader]="false"
|
[showHeader]="false"
|
||||||
[node]="nodes"
|
[node]="nodes"
|
||||||
[maxItems]="pageSize"
|
[maxItems]="pageSize"
|
||||||
[rowFilter]="rowFilter"
|
[rowFilter]="_rowFilter"
|
||||||
[imageResolver]="imageResolver"
|
[imageResolver]="imageResolver"
|
||||||
[currentFolderId]="folderIdToShow"
|
[currentFolderId]="folderIdToShow"
|
||||||
selectionMode="single"
|
selectionMode="single"
|
||||||
|
@@ -29,6 +29,7 @@ import { ContentTestingModule } from '../testing/content.testing.module';
|
|||||||
import { DocumentListService } from '../document-list/services/document-list.service';
|
import { DocumentListService } from '../document-list/services/document-list.service';
|
||||||
import { DocumentListComponent } from '../document-list/components/document-list.component';
|
import { DocumentListComponent } from '../document-list/components/document-list.component';
|
||||||
import { CustomResourcesService } from '../document-list/services/custom-resources.service';
|
import { CustomResourcesService } from '../document-list/services/custom-resources.service';
|
||||||
|
import { ShareDataRow } from '../document-list';
|
||||||
|
|
||||||
const ONE_FOLDER_RESULT = {
|
const ONE_FOLDER_RESULT = {
|
||||||
list: {
|
list: {
|
||||||
@@ -97,6 +98,24 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
|
|
||||||
describe('Parameters', () => {
|
describe('Parameters', () => {
|
||||||
|
|
||||||
|
let documentListService,
|
||||||
|
sitesService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
documentListService = TestBed.get(DocumentListService);
|
||||||
|
sitesService = TestBed.get(SitesService);
|
||||||
|
spyOn(documentListService, 'getFolderNode').and.returnValue(of(<NodeEntry> { entry: { path: { elements: [] } } }));
|
||||||
|
spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test'));
|
||||||
|
spyOn(sitesService, 'getSites').and.returnValue(of({
|
||||||
|
list: {
|
||||||
|
entries: [<SiteEntry> { entry: { guid: 'namek', id: 'namek' } },
|
||||||
|
<SiteEntry> { entry: { guid: 'blog', id: 'blog' } }]
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
component.currentFolderId = 'cat-girl-nuku-nuku';
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
it('should trigger the select event when selection has been made', (done) => {
|
it('should trigger the select event when selection has been made', (done) => {
|
||||||
const expectedNode = <Node> {};
|
const expectedNode = <Node> {};
|
||||||
component.select.subscribe((nodes) => {
|
component.select.subscribe((nodes) => {
|
||||||
@@ -113,7 +132,35 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const testSiteContent = new Node({ id: 'blog-id', properties: { 'st:componentId': 'blog' } });
|
const testSiteContent = new Node({ id: 'blog-id', properties: { 'st:componentId': 'blog' } });
|
||||||
expect(component.rowFilter(<any> { node: { entry: testSiteContent } }, null, null)).toBe(false);
|
expect(component.rowFilter(<any> { node: { entry: testSiteContent } }, null, null))
|
||||||
|
.toBe(false, 'did not filter out blog');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should still be able to filter out the exclude site content after rowFilter changes', () => {
|
||||||
|
const filterFunction1 = () => {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
const filterFunction2 = (row: ShareDataRow) => {
|
||||||
|
const node: Node = row.node.entry;
|
||||||
|
return node.isFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
component.excludeSiteContent = ['blog'];
|
||||||
|
component.rowFilter = filterFunction1;
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const testSiteContent = new Node({
|
||||||
|
id: 'blog-id',
|
||||||
|
properties: { 'st:componentId': 'blog' },
|
||||||
|
isFile: true
|
||||||
|
});
|
||||||
|
expect(component.rowFilter(<any> { node: { entry: testSiteContent } }, null, null))
|
||||||
|
.toBe(false, 'did not filter out blog with filterFunction1');
|
||||||
|
|
||||||
|
component.rowFilter = filterFunction2;
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(component.rowFilter(<any> { node: { entry: testSiteContent } }, null, null))
|
||||||
|
.toBe(false, 'did not filter out blog with filterFunction2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT filter out any site content by default', () => {
|
it('should NOT filter out any site content by default', () => {
|
||||||
@@ -548,15 +595,48 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should pass through the rowFilter to the documentList', () => {
|
it('should pass through the rowFilter to the documentList', () => {
|
||||||
const filter = () => {
|
let filter = (shareDataRow: ShareDataRow) => {
|
||||||
|
if (shareDataRow.node.entry.name === 'impossible-name') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
component.rowFilter = filter;
|
component.rowFilter = filter;
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
let documentList = fixture.debugElement.query(By.directive(DocumentListComponent));
|
let documentList = fixture.debugElement.query(By.directive(DocumentListComponent));
|
||||||
expect(documentList).not.toBeNull('Document list should be shown');
|
expect(documentList).not.toBeNull('Document list should be shown');
|
||||||
expect(documentList.componentInstance.rowFilter).toBe(filter);
|
expect(documentList.componentInstance.rowFilter({
|
||||||
|
node: {
|
||||||
|
entry: new Node({
|
||||||
|
name: 'impossible-name',
|
||||||
|
id: 'name'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.toBe(filter(<ShareDataRow> {
|
||||||
|
node: {
|
||||||
|
entry: new Node({
|
||||||
|
name: 'impossible-name',
|
||||||
|
id: 'name'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pass through the excludeSiteContent to the rowFilter of the documentList', () => {
|
||||||
|
component.excludeSiteContent = ['blog'];
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
let documentList = fixture.debugElement.query(By.directive(DocumentListComponent));
|
||||||
|
expect(documentList).not.toBeNull('Document list should be shown');
|
||||||
|
expect(documentList.componentInstance.rowFilter).toBeTruthy('Document list should have had a rowFilter');
|
||||||
|
|
||||||
|
const testSiteContent = new Node({ id: 'blog-id', properties: { 'st:componentId': 'blog' } });
|
||||||
|
expect(documentList.componentInstance.rowFilter(<any> { node: { entry: testSiteContent } }, null, null))
|
||||||
|
.toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should pass through the imageResolver to the documentList', () => {
|
it('should pass through the imageResolver to the documentList', () => {
|
||||||
|
@@ -60,18 +60,35 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
|
|||||||
@Input()
|
@Input()
|
||||||
dropdownSiteList: SitePaging = null;
|
dropdownSiteList: SitePaging = null;
|
||||||
|
|
||||||
|
_rowFilter: RowFilter = defaultValidation;
|
||||||
|
|
||||||
/** Custom row filter function. See the
|
/** Custom row filter function. See the
|
||||||
* [Document List component](document-list.component.md#custom-row-filter)
|
* [Document List component](document-list.component.md#custom-row-filter)
|
||||||
* for more information.
|
* for more information.
|
||||||
*/
|
*/
|
||||||
@Input()
|
@Input()
|
||||||
rowFilter: RowFilter = null;
|
set rowFilter(rowFilter: RowFilter) {
|
||||||
|
this.createRowFilter(rowFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
get rowFilter(): RowFilter {
|
||||||
|
return this._rowFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
_excludeSiteContent: string[] = [];
|
||||||
|
|
||||||
/** Custom list of site content componentIds.
|
/** Custom list of site content componentIds.
|
||||||
* Used to filter out the corresponding items from the displayed nodes
|
* Used to filter out the corresponding items from the displayed nodes
|
||||||
*/
|
*/
|
||||||
@Input()
|
@Input()
|
||||||
excludeSiteContent: string[] = [];
|
set excludeSiteContent(excludeSiteContent: string[]) {
|
||||||
|
this._excludeSiteContent = excludeSiteContent;
|
||||||
|
this.createRowFilter(this._rowFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
get excludeSiteContent(): string[] {
|
||||||
|
return this._excludeSiteContent;
|
||||||
|
}
|
||||||
|
|
||||||
/** Custom image resolver function. See the
|
/** Custom image resolver function. See the
|
||||||
* [Document List component](document-list.component.md#custom-row-filter)
|
* [Document List component](document-list.component.md#custom-row-filter)
|
||||||
@@ -164,27 +181,25 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
|
|||||||
|
|
||||||
this.breadcrumbTransform = this.breadcrumbTransform ? this.breadcrumbTransform : null;
|
this.breadcrumbTransform = this.breadcrumbTransform ? this.breadcrumbTransform : null;
|
||||||
this.isSelectionValid = this.isSelectionValid ? this.isSelectionValid : defaultValidation;
|
this.isSelectionValid = this.isSelectionValid ? this.isSelectionValid : defaultValidation;
|
||||||
this.excludeSiteContent = this.excludeSiteContent ? this.excludeSiteContent : [];
|
|
||||||
this.rowFilter = this.getRowFilter(this.rowFilter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRowFilter(initialFilterFunction): RowFilter {
|
private createRowFilter(filter?: RowFilter) {
|
||||||
if (!initialFilterFunction) {
|
if (!filter) {
|
||||||
initialFilterFunction = () => true;
|
filter = () => true;
|
||||||
}
|
}
|
||||||
return (value: ShareDataRow, index: number, array: ShareDataRow[]) => {
|
this._rowFilter = (value: ShareDataRow, index: number, array: ShareDataRow[]) => {
|
||||||
return initialFilterFunction(value, index, array) &&
|
return filter(value, index, array) &&
|
||||||
!this.isExcludedSiteContent(value);
|
!this.isExcludedSiteContent(value);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private isExcludedSiteContent(row: ShareDataRow): boolean {
|
private isExcludedSiteContent(row: ShareDataRow): boolean {
|
||||||
const entry = row.node.entry;
|
const entry = row.node.entry;
|
||||||
if (this.excludeSiteContent.length &&
|
if (this._excludeSiteContent.length &&
|
||||||
entry &&
|
entry &&
|
||||||
entry.properties &&
|
entry.properties &&
|
||||||
entry.properties['st:componentId']) {
|
entry.properties['st:componentId']) {
|
||||||
const excludedItem = this.excludeSiteContent.find(
|
const excludedItem = this._excludeSiteContent.find(
|
||||||
(id: string) => entry.properties['st:componentId'] === id
|
(id: string) => entry.properties['st:componentId'] === id
|
||||||
);
|
);
|
||||||
return !!excludedItem;
|
return !!excludedItem;
|
||||||
|
Reference in New Issue
Block a user