[ADF-1420] - Fix for 1420, 1425, 1426 and 1428 issues (#2231)

* Fix for ADF-1420 & ADF-1428

* Fix for ADF-1425 & ADF-1426
This commit is contained in:
Popovics András 2017-08-18 20:38:45 +02:00 committed by Mario Romano
parent 1aeedde442
commit f6f94fbd0c
3 changed files with 86 additions and 24 deletions

View File

@ -57,6 +57,7 @@
[allowDropFiles]="false" [allowDropFiles]="false"
[enablePagination]="!showingSearchResults" [enablePagination]="!showingSearchResults"
(folderChange)="onFolderChange($event)" (folderChange)="onFolderChange($event)"
(ready)="onFolderLoaded()"
data-automation-id="content-node-selector-document-list"> data-automation-id="content-node-selector-document-list">
<empty-folder-content> <empty-folder-content>
<ng-template> <ng-template>

View File

@ -476,6 +476,33 @@ describe('ContentNodeSelectorComponent', () => {
}); });
})); }));
it('should reload the original documentlist when clearing the search input', async(() => {
typeToSearchBox('shenron');
respondWithSearchResults(ONE_FOLDER_RESULT);
fixture.whenStable().then(() => {
typeToSearchBox('');
fixture.detectChanges();
let documentList = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-document-list"]'));
expect(documentList.componentInstance.currentFolderId).toBe('cat-girl-nuku-nuku');
});
}));
it('should set the folderIdToShow to the default "currentFolderId" if siteId is undefined', () => {
component.siteChanged(<SiteModel> { guid: 'Kame-Sennin Muten Roshi' });
fixture.detectChanges();
let documentList = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-document-list"]'));
expect(documentList.componentInstance.currentFolderId).toBe('Kame-Sennin Muten Roshi');
component.siteChanged(<SiteModel> { guid: undefined });
fixture.detectChanges();
documentList = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-document-list"]'));
expect(documentList.componentInstance.currentFolderId).toBe('cat-girl-nuku-nuku');
});
xit('should do something with pagination or with many results', () => { xit('should do something with pagination or with many results', () => {
}); });
@ -510,6 +537,26 @@ describe('ContentNodeSelectorComponent', () => {
expect(chooseButton.nativeElement.disabled).toBe(true); expect(chooseButton.nativeElement.disabled).toBe(true);
}); });
it('should become enabled after loading node with the necessary permissions', () => {
hasPermission = true;
component.documentList.folderNode = entry;
component.documentList.ready.emit();
fixture.detectChanges();
let chooseButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-choose"]'));
expect(chooseButton.nativeElement.disabled).toBe(false);
});
it('should remain disabled after loading node without the necessary permissions', () => {
hasPermission = false;
component.documentList.folderNode = entry;
component.documentList.ready.emit();
fixture.detectChanges();
let chooseButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-choose"]'));
expect(chooseButton.nativeElement.disabled).toBe(true);
});
it('should be enabled when clicking on a node (with the right permissions) in the list (onNodeSelect)', () => { it('should be enabled when clicking on a node (with the right permissions) in the list (onNodeSelect)', () => {
hasPermission = true; hasPermission = true;
@ -543,18 +590,6 @@ describe('ContentNodeSelectorComponent', () => {
expect(chooseButton.nativeElement.disabled).toBe(true); expect(chooseButton.nativeElement.disabled).toBe(true);
}); });
it('should become disabled when changing directory after previously selecting a right node', () => {
hasPermission = true;
component.onNodeSelect({ detail: { node: { entry } } });
fixture.detectChanges();
component.onFolderChange();
fixture.detectChanges();
let chooseButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-choose"]'));
expect(chooseButton.nativeElement.disabled).toBe(true);
});
it('should be disabled when resetting the chosen node', () => { it('should be disabled when resetting the chosen node', () => {
hasPermission = true; hasPermission = true;
component.onNodeSelect({ detail: { node: { entry: <MinimalNodeEntryEntity> {} } } }); component.onNodeSelect({ detail: { node: { entry: <MinimalNodeEntryEntity> {} } } });

View File

@ -95,7 +95,7 @@ export class ContentNodeSelectorComponent implements OnInit {
*/ */
siteChanged(chosenSite: SiteModel): void { siteChanged(chosenSite: SiteModel): void {
this.siteId = chosenSite.guid; this.siteId = chosenSite.guid;
this.querySearch(); this.updateResults();
} }
/** /**
@ -105,9 +105,12 @@ export class ContentNodeSelectorComponent implements OnInit {
*/ */
search(searchTerm: string): void { search(searchTerm: string): void {
this.searchTerm = searchTerm; this.searchTerm = searchTerm;
this.querySearch(); this.updateResults();
} }
/**
* Returns whether breadcrumb has to be shown or not
*/
needBreadcrumbs() { needBreadcrumbs() {
const whenInFolderNavigation = !this.showingSearchResults, const whenInFolderNavigation = !this.showingSearchResults,
whenInSelectingSearchResult = this.showingSearchResults && this.chosenNode; whenInSelectingSearchResult = this.showingSearchResults && this.chosenNode;
@ -137,6 +140,17 @@ export class ContentNodeSelectorComponent implements OnInit {
this.folderIdToShow = this.currentFolderId; this.folderIdToShow = this.currentFolderId;
} }
/**
* Update the result list depending on the criterias
*/
private updateResults() {
if (this.searchTerm.length === 0) {
this.folderIdToShow = this.siteId || this.currentFolderId;
} else {
this.querySearch();
}
}
/** /**
* Perform the call to searchService with the proper parameters * Perform the call to searchService with the proper parameters
*/ */
@ -153,8 +167,7 @@ export class ContentNodeSelectorComponent implements OnInit {
maxItems: 200, maxItems: 200,
orderBy: null orderBy: null
}; };
this.searchService this.searchService.getNodeQueryResults(searchTerm, searchOpts)
.getNodeQueryResults(searchTerm, searchOpts)
.subscribe( .subscribe(
results => { results => {
this.showingSearchResults = true; this.showingSearchResults = true;
@ -181,12 +194,7 @@ export class ContentNodeSelectorComponent implements OnInit {
* @param event CustomEvent for node-select * @param event CustomEvent for node-select
*/ */
onNodeSelect(event: any): void { onNodeSelect(event: any): void {
const entry: MinimalNodeEntryEntity = event.detail.node.entry; this.attemptNodeSelection(event.detail.node.entry);
if (this.contentService.hasPermission(entry, 'update')) {
this.chosenNode = entry;
} else {
this.resetChosenNode();
}
} }
/** /**
@ -194,7 +202,26 @@ export class ContentNodeSelectorComponent implements OnInit {
*/ */
onFolderChange() { onFolderChange() {
this.showingSearchResults = false; this.showingSearchResults = false;
this.chosenNode = null; }
/**
* Attempts to set the currently loaded node
*/
onFolderLoaded() {
this.attemptNodeSelection(this.documentList.folderNode);
}
/**
* Selects node as choosen if it has the right permission, clears the selection otherwise
*
* @param entry
*/
private attemptNodeSelection(entry: MinimalNodeEntryEntity): void {
if (this.contentService.hasPermission(entry, 'update')) {
this.chosenNode = entry;
} else {
this.resetChosenNode();
}
} }
/** /**
@ -208,7 +235,6 @@ export class ContentNodeSelectorComponent implements OnInit {
* Emit event with the chosen node * Emit event with the chosen node
*/ */
choose(): void { choose(): void {
// Multiple selections to be implemented...
this.select.next([this.chosenNode]); this.select.next([this.chosenNode]);
} }