mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
[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:
parent
1aeedde442
commit
f6f94fbd0c
@ -57,6 +57,7 @@
|
||||
[allowDropFiles]="false"
|
||||
[enablePagination]="!showingSearchResults"
|
||||
(folderChange)="onFolderChange($event)"
|
||||
(ready)="onFolderLoaded()"
|
||||
data-automation-id="content-node-selector-document-list">
|
||||
<empty-folder-content>
|
||||
<ng-template>
|
||||
|
@ -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', () => {
|
||||
|
||||
});
|
||||
@ -510,6 +537,26 @@ describe('ContentNodeSelectorComponent', () => {
|
||||
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)', () => {
|
||||
hasPermission = true;
|
||||
|
||||
@ -543,18 +590,6 @@ describe('ContentNodeSelectorComponent', () => {
|
||||
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', () => {
|
||||
hasPermission = true;
|
||||
component.onNodeSelect({ detail: { node: { entry: <MinimalNodeEntryEntity> {} } } });
|
||||
|
@ -95,7 +95,7 @@ export class ContentNodeSelectorComponent implements OnInit {
|
||||
*/
|
||||
siteChanged(chosenSite: SiteModel): void {
|
||||
this.siteId = chosenSite.guid;
|
||||
this.querySearch();
|
||||
this.updateResults();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,9 +105,12 @@ export class ContentNodeSelectorComponent implements OnInit {
|
||||
*/
|
||||
search(searchTerm: string): void {
|
||||
this.searchTerm = searchTerm;
|
||||
this.querySearch();
|
||||
this.updateResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether breadcrumb has to be shown or not
|
||||
*/
|
||||
needBreadcrumbs() {
|
||||
const whenInFolderNavigation = !this.showingSearchResults,
|
||||
whenInSelectingSearchResult = this.showingSearchResults && this.chosenNode;
|
||||
@ -137,6 +140,17 @@ export class ContentNodeSelectorComponent implements OnInit {
|
||||
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
|
||||
*/
|
||||
@ -153,8 +167,7 @@ export class ContentNodeSelectorComponent implements OnInit {
|
||||
maxItems: 200,
|
||||
orderBy: null
|
||||
};
|
||||
this.searchService
|
||||
.getNodeQueryResults(searchTerm, searchOpts)
|
||||
this.searchService.getNodeQueryResults(searchTerm, searchOpts)
|
||||
.subscribe(
|
||||
results => {
|
||||
this.showingSearchResults = true;
|
||||
@ -181,12 +194,7 @@ export class ContentNodeSelectorComponent implements OnInit {
|
||||
* @param event CustomEvent for node-select
|
||||
*/
|
||||
onNodeSelect(event: any): void {
|
||||
const entry: MinimalNodeEntryEntity = event.detail.node.entry;
|
||||
if (this.contentService.hasPermission(entry, 'update')) {
|
||||
this.chosenNode = entry;
|
||||
} else {
|
||||
this.resetChosenNode();
|
||||
}
|
||||
this.attemptNodeSelection(event.detail.node.entry);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -194,7 +202,26 @@ export class ContentNodeSelectorComponent implements OnInit {
|
||||
*/
|
||||
onFolderChange() {
|
||||
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
|
||||
*/
|
||||
choose(): void {
|
||||
// Multiple selections to be implemented...
|
||||
this.select.next([this.chosenNode]);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user