diff --git a/docs/content-services/services/document-list.service.md b/docs/content-services/services/document-list.service.md
index 34d0e40cdc..75ec50f9f7 100644
--- a/docs/content-services/services/document-list.service.md
+++ b/docs/content-services/services/document-list.service.md
@@ -5,57 +5,76 @@ Status: Active
Last reviewed: 2019-01-16
---
-# [Document List service](../../../lib/content-services/src/lib/document-list/services/document-list.service.ts "Defined in document-list.service.ts")
+# Document List Service
-Implements node operations used by the [Document List component](../components/document-list.component.md).
+`service`
-## Class members
+Implements operations used by the [Document List component](../components/document-list.component.md).
+
+## Usage
+
+```typescript
+import { DocumentListService } from '@alfresco/adf-core';
+```
+
+## API
+
+### Events
+
+| Name | Description |
+|-------------------|-------------------------------------------------|
+| `reload$` | Emits when the document list should be reloaded |
+| `resetSelection$` | Emits when the selection should be reset |
### Methods
-- **copyNode**(nodeId: `string`, targetParentId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md)`>`
+- **reload**(): `void`
+ Reloads the document list.
+- **resetSelection**(): `void`
+ Resets the selection.
+- **copyNode**(nodeId: `string`, targetParentId: `string`): `Observable`
Copy a node to destination node
- _nodeId:_ `string` - The id of the node to be copied
- _targetParentId:_ `string` - The id of the folder where the node will be copied
- - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md)`>` - NodeEntry for the copied node
-- **deleteNode**(nodeId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)``
+ - **Returns** `Observable` - NodeEntry for the copied node
+- **deleteNode**(nodeId: `string`): `Observable`
Deletes a node.
- _nodeId:_ `string` - ID of the node to delete
- - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`` - Empty response when the operation is complete
-- **getFolder**(folder: `string`, opts?: `any`, includeFields: `string[]` = `[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`NodePaging`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/NodePaging.md)`>`
+ - **Returns** `Observable` - Empty response when the operation is complete
+- **getFolder**(folder: `string`, opts?: `any`, includeFields: `string[]` = `[]`): `Observable`
Gets the folder node with the specified relative name path below the root node.
- _folder:_ `string` - Path to folder.
- _opts:_ `any` - (Optional) Options.
- _includeFields:_ `string[]` - Extra information to include (available options are "aspectNames", "isLink" and "association")
- - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`NodePaging`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/NodePaging.md)`>` - Details of the folder
-- **getFolderNode**(nodeId: `string`, includeFields: `string[]` = `[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md)`>`
+ - **Returns** `Observable` - Details of the folder
+- **getFolderNode**(nodeId: `string`, includeFields: `string[]` = `[]`): `Observable`
Gets a folder node via its node ID.
- _nodeId:_ `string` - ID of the folder node
- _includeFields:_ `string[]` - Extra information to include (available options are "aspectNames", "isLink" and "association")
- - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md)`>` - Details of the folder
-- **getNode**(nodeId: `string`, includeFields: `string[]` = `[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`MinimalNode`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeMinimalEntry.md)`>`
+ - **Returns** `Observable` - Details of the folder
+- **getNode**(nodeId: `string`, includeFields: `string[]` = `[]`): `Observable`
Gets a node via its node ID.
- _nodeId:_ `string` - ID of the target node
- _includeFields:_ `string[]` - Extra information to include (available options are "aspectNames", "isLink" and "association")
- - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`MinimalNode`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeMinimalEntry.md)`>` - Details of the folder
+ - **Returns** `Observable` - Details of the folder
- **isCustomSourceService**(nodeId: `any`): `boolean`
- _nodeId:_ `any` -
- **Returns** `boolean` -
-- **loadFolderByNodeId**(nodeId: `string`, pagination: [`PaginationModel`](../../../lib/core/src/lib/models/pagination.model.ts), includeFields: `string[]`, where?: `string`, orderBy?: `string[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`DocumentLoaderNode`](../../../lib/content-services/src/lib/document-list/models/document-folder.model.ts)`>`
+- **loadFolderByNodeId**(nodeId: `string`, pagination: `PaginationModel`, includeFields: `string[]`, where?: `string`, orderBy?: `string[]`): `Observable`
Load a folder by Node Id.
- _nodeId:_ `string` - ID of the folder node
- - _pagination:_ [`PaginationModel`](../../../lib/core/src/lib/models/pagination.model.ts) -
+ - _pagination:_ `PaginationModel` - pagination model
- _includeFields:_ `string[]` - List of data field names to include in the results
- _where:_ `string` - (Optional) Optionally filter the list
- _orderBy:_ `string[]` - (Optional) order by node property
- - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`DocumentLoaderNode`](../../../lib/content-services/src/lib/document-list/models/document-folder.model.ts)`>` - Details of the folder
-- **moveNode**(nodeId: `string`, targetParentId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md)`>`
+ - **Returns** `Observable` - Details of the folder
+- **moveNode**(nodeId: `string`, targetParentId: `string`): `Observable`
Moves a node to destination node.
- _nodeId:_ `string` - The id of the node to be moved
- _targetParentId:_ `string` - The id of the folder where the node will be moved
- - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md)`>` - NodeEntry for the moved node
+ - **Returns** `Observable` - NodeEntry for the moved node
## Details
diff --git a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts
index 2e7b5fb918..b5abb445e8 100644
--- a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts
+++ b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts
@@ -126,6 +126,44 @@ describe('DocumentList', () => {
fixture.destroy();
});
+ it('should reset selection and reload on documentListService reload$', () => {
+ spyOn(documentList, 'resetSelection').and.callThrough();
+ spyOn(documentList, 'reload').and.callThrough();
+
+ documentListService.reload();
+
+ expect(documentList.resetSelection).toHaveBeenCalled();
+ expect(documentList.reload).toHaveBeenCalled();
+ });
+
+ it('should not reset selection or reload after component is destroyed', () => {
+ spyOn(documentList, 'resetSelection').and.callThrough();
+ spyOn(documentList, 'reload').and.callThrough();
+
+ documentList.ngOnDestroy();
+ documentListService.reload();
+
+ expect(documentList.resetSelection).not.toHaveBeenCalled();
+ expect(documentList.reload).not.toHaveBeenCalled();
+ });
+
+ it('should reset selection when resetSelection$ is emitted', () => {
+ spyOn(documentList, 'resetSelection').and.callThrough();
+
+ documentListService.resetSelection();
+
+ expect(documentList.resetSelection).toHaveBeenCalled();
+ });
+
+ it('should not reset selection after component is destroyed', () => {
+ spyOn(documentList, 'resetSelection').and.callThrough();
+
+ documentList.ngOnDestroy();
+ documentListService.resetSelection();
+
+ expect(documentList.resetSelection).not.toHaveBeenCalled();
+ });
+
describe('presets', () => {
const validatePreset = (keys: string[]) => {
const columns = documentList.data.getColumns();
diff --git a/lib/content-services/src/lib/document-list/components/document-list.component.ts b/lib/content-services/src/lib/document-list/components/document-list.component.ts
index 5c159cad41..6a4ee625fe 100644
--- a/lib/content-services/src/lib/document-list/components/document-list.component.ts
+++ b/lib/content-services/src/lib/document-list/components/document-list.component.ts
@@ -517,6 +517,15 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
if (this.columnsPresetKey) {
this.setPresetKey(this.columnsPresetKey);
}
+
+ this.documentListService.reload$.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
+ this.resetSelection();
+ this.reload();
+ });
+
+ this.documentListService.resetSelection$.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
+ this.resetSelection();
+ });
}
ngAfterContentInit() {
diff --git a/lib/content-services/src/lib/document-list/services/document-list.service.spec.ts b/lib/content-services/src/lib/document-list/services/document-list.service.spec.ts
index dd49acf175..20d8d4c091 100644
--- a/lib/content-services/src/lib/document-list/services/document-list.service.spec.ts
+++ b/lib/content-services/src/lib/document-list/services/document-list.service.spec.ts
@@ -74,6 +74,20 @@ describe('DocumentListService', () => {
jasmine.Ajax.install();
});
+ it('should emit resetSelection$ when resetSelection is called', (done) => {
+ service.resetSelection$.subscribe(() => {
+ done();
+ });
+ service.resetSelection();
+ });
+
+ it('should emit reload$ when reload is called', (done) => {
+ service.reload$.subscribe(() => {
+ done();
+ });
+ service.reload();
+ });
+
afterEach(() => {
jasmine.Ajax.uninstall();
});
diff --git a/lib/content-services/src/lib/document-list/services/document-list.service.ts b/lib/content-services/src/lib/document-list/services/document-list.service.ts
index 1819c55f3d..929b23f068 100644
--- a/lib/content-services/src/lib/document-list/services/document-list.service.ts
+++ b/lib/content-services/src/lib/document-list/services/document-list.service.ts
@@ -17,10 +17,10 @@
import { AlfrescoApiService, PaginationModel } from '@alfresco/adf-core';
import { NodesApiService } from '../../common/services/nodes-api.service';
-import { Injectable } from '@angular/core';
+import { inject, Injectable } from '@angular/core';
import { Node, NodeEntry, NodePaging, NodesApi } from '@alfresco/js-api';
import { DocumentLoaderNode } from '../models/document-folder.model';
-import { Observable, from, forkJoin } from 'rxjs';
+import { Observable, from, forkJoin, Subject } from 'rxjs';
import { map } from 'rxjs/operators';
import { DocumentListLoader } from '../interfaces/document-list-loader.interface';
import { CustomResourcesService } from './custom-resources.service';
@@ -31,17 +31,34 @@ const ROOT_ID = '-root-';
providedIn: 'root'
})
export class DocumentListService implements DocumentListLoader {
+ private nodesApiService = inject(NodesApiService);
+ private apiService = inject(AlfrescoApiService);
+ private customResourcesService = inject(CustomResourcesService);
+
private _nodesApi: NodesApi;
get nodes(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
return this._nodesApi;
}
- constructor(
- private nodesApiService: NodesApiService,
- private apiService: AlfrescoApiService,
- private customResourcesService: CustomResourcesService
- ) {}
+ private _reload = new Subject();
+ private _resetSelection = new Subject();
+
+ /** Gets an observable that emits when the document list should be reloaded. */
+ reload$ = this._reload.asObservable();
+
+ /** Gets an observable that emits when the selection should be reset. */
+ resetSelection$ = this._resetSelection.asObservable();
+
+ /** Reloads the document list. */
+ reload() {
+ this._reload.next();
+ }
+
+ /** Resets the selection. */
+ resetSelection() {
+ this._resetSelection.next();
+ }
/**
* Deletes a node.