mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
lightweight actions service
This commit is contained in:
@@ -193,27 +193,28 @@ A collection of Angular components for generic use.
|
|||||||
|
|
||||||
### Services
|
### Services
|
||||||
|
|
||||||
| Name | Description | Source link |
|
| Name | Description | Source link |
|
||||||
| ---- | ----------- | ----------- |
|
|-----------------------------------------------------------------------------| ----------- | ----------- |
|
||||||
| [APS Alfresco Content Service](core/services/activiti-alfresco.service.md) | Gets Alfresco Repository folder content based on a Repository account configured in Alfresco Process Services (APS). | [Source](../lib/process-services/src/lib/form/services/activiti-alfresco.service.ts) |
|
| [Action Service](../lib/core/src/lib/services/action.service.md) | Allows you to subscribe to events and publish events. | [Source](../lib/core/src/lib/services/action.service.ts) |
|
||||||
| [Alfresco Api Service](core/services/alfresco-api.service.md) | Provides access to an initialized AlfrescoJSApi instance. | [Source](../lib/core/src/lib/services/alfresco-api.service.ts) |
|
| [APS Alfresco Content Service](core/services/activiti-alfresco.service.md) | Gets Alfresco Repository folder content based on a Repository account configured in Alfresco Process Services (APS). | [Source](../lib/process-services/src/lib/form/services/activiti-alfresco.service.ts) |
|
||||||
| [App Config service](core/services/app-config.service.md) | Supports app configuration settings, stored server side. | [Source](../lib/core/src/lib/app-config/app-config.service.ts) |
|
| [Alfresco Api Service](core/services/alfresco-api.service.md) | Provides access to an initialized AlfrescoJSApi instance. | [Source](../lib/core/src/lib/services/alfresco-api.service.ts) |
|
||||||
| [Apps Process service](core/services/apps-process.service.md) | Gets details of the Process Services apps that are deployed for the user. | [Source](../lib/process-services/src/lib/services/apps-process.service.ts) |
|
| [App Config service](core/services/app-config.service.md) | Supports app configuration settings, stored server side. | [Source](../lib/core/src/lib/app-config/app-config.service.ts) |
|
||||||
| [Auth Guard Bpm service](core/services/auth-guard-bpm.service.md) | Adds authentication with Process Services to a route within the app. | [Source](../lib/core/src/lib/auth/guard/auth-guard-bpm.service.ts) |
|
| [Apps Process service](core/services/apps-process.service.md) | Gets details of the Process Services apps that are deployed for the user. | [Source](../lib/process-services/src/lib/services/apps-process.service.ts) |
|
||||||
| [Auth Guard Ecm service](core/services/auth-guard-ecm.service.md) | Adds authentication with Content Services to a route within the app. | [Source](../lib/core/src/lib/auth/guard/auth-guard-ecm.service.ts) |
|
| [Auth Guard Bpm service](core/services/auth-guard-bpm.service.md) | Adds authentication with Process Services to a route within the app. | [Source](../lib/core/src/lib/auth/guard/auth-guard-bpm.service.ts) |
|
||||||
|
| [Auth Guard Ecm service](core/services/auth-guard-ecm.service.md) | Adds authentication with Content Services to a route within the app. | [Source](../lib/core/src/lib/auth/guard/auth-guard-ecm.service.ts) |
|
||||||
| [Auth Guard SSO Role service](core/services/auth-guard-sso-role.service.md) | Checks the user roles of a user. | [Source](../lib/core/src/lib/auth/guard/auth-guard-sso-role.service.ts) |
|
| [Auth Guard SSO Role service](core/services/auth-guard-sso-role.service.md) | Checks the user roles of a user. | [Source](../lib/core/src/lib/auth/guard/auth-guard-sso-role.service.ts) |
|
||||||
| [Auth Guard service](core/services/auth-guard.service.md) | Adds authentication to a route within the app. | [Source](../lib/core/src/lib/auth/guard/auth-guard.service.ts) |
|
| [Auth Guard service](core/services/auth-guard.service.md) | Adds authentication to a route within the app. | [Source](../lib/core/src/lib/auth/guard/auth-guard.service.ts) |
|
||||||
| [Authentication Service](core/services/authentication.service.md) | Provides authentication to ACS and APS. | [Source](../lib/core/src/lib/auth/services/authentication.service.ts) |
|
| [Authentication Service](core/services/authentication.service.md) | Provides authentication to ACS and APS. | [Source](../lib/core/src/lib/auth/services/authentication.service.ts) |
|
||||||
| [Bpm User service](core/services/bpm-user.service.md) | Gets information about the current Process Services user. | [Source](../lib/core/src/lib/services/bpm-user.service.ts) |
|
| [Bpm User service](core/services/bpm-user.service.md) | Gets information about the current Process Services user. | [Source](../lib/core/src/lib/services/bpm-user.service.ts) |
|
||||||
| [Card Item Type service](core/services/card-item-types.service.md) | Maps type names to field component types for the Card View component. | [Source](../lib/core/src/lib/card-view/services/card-item-types.service.ts) |
|
| [Card Item Type service](core/services/card-item-types.service.md) | Maps type names to field component types for the Card View component. | [Source](../lib/core/src/lib/card-view/services/card-item-types.service.ts) |
|
||||||
| [Card View Update service](core/services/card-view-update.service.md) | Reports edits and clicks within fields of a Card View component. | |
|
| [Card View Update service](core/services/card-view-update.service.md) | Reports edits and clicks within fields of a Card View component. | |
|
||||||
| Implements BaseCardViewUpdate. | [Source](../lib/core/src/lib/card-view/services/card-view-update.service.ts) | |
|
| Implements BaseCardViewUpdate. | [Source](../lib/core/src/lib/card-view/services/card-view-update.service.ts) | |
|
||||||
| [Clipboard service](core/services/clipboard.service.md) | Copies text to the clipboard. | [Source](../lib/core/src/lib/clipboard/clipboard.service.ts) |
|
| [Clipboard service](core/services/clipboard.service.md) | Copies text to the clipboard. | [Source](../lib/core/src/lib/clipboard/clipboard.service.ts) |
|
||||||
| [Comment Content service](core/services/comment-content.service.md) | Adds and retrieves comments for nodes in Content Services. | [Source](../lib/core/src/lib/services/comment-content.service.ts) |
|
| [Comment Content service](core/services/comment-content.service.md) | Adds and retrieves comments for nodes in Content Services. | [Source](../lib/core/src/lib/services/comment-content.service.ts) |
|
||||||
| [Comment Process service](core/services/comment-process.service.md) | Adds and retrieves comments for task and process instances in Process Services. | [Source](../lib/process-services/src/lib/process-comments/services/comment-process.service.ts) |
|
| [Comment Process service](core/services/comment-process.service.md) | Adds and retrieves comments for task and process instances in Process Services. | [Source](../lib/process-services/src/lib/process-comments/services/comment-process.service.ts) |
|
||||||
| [Content service](core/services/content.service.md) | Accesses app-generated data objects via URLs and file downloads. | [Source](../lib/content-services/src/lib/common/services/content.service.ts) |
|
| [Content service](core/services/content.service.md) | Accesses app-generated data objects via URLs and file downloads. | [Source](../lib/content-services/src/lib/common/services/content.service.ts) |
|
||||||
| [Cookie service](core/services/cookie.service.md) | Stores key-value data items as browser cookies. | [Source](../lib/core/src/lib/common/services/cookie.service.ts) |
|
| [Cookie service](core/services/cookie.service.md) | Stores key-value data items as browser cookies. | [Source](../lib/core/src/lib/common/services/cookie.service.ts) |
|
||||||
| [DataTable service](core/services/datatable.service.md) | If you need to update one row of your datatable you can use the DataTableService to update it. | |
|
| [DataTable service](core/services/datatable.service.md) | If you need to update one row of your datatable you can use the DataTableService to update it. | |
|
||||||
|
|
||||||
To update a single row you can use the rowUpdate subject.
|
To update a single row you can use the rowUpdate subject.
|
||||||
The model to update the DataTable require the ID of the row you want change and the new data Object of the row | [Source](../lib/core/src/lib/datatable/services/datatable.service.ts) |
|
The model to update the DataTable require the ID of the row you want change and the new data Object of the row | [Source](../lib/core/src/lib/datatable/services/datatable.service.ts) |
|
||||||
|
30
lib/core/src/lib/services/action.service.md
Normal file
30
lib/core/src/lib/services/action.service.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Action Service
|
||||||
|
|
||||||
|
`service`
|
||||||
|
|
||||||
|
The Action Service is a service that allows you to subscribe to events and publish events.
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### `dispatch(action: Action): void`
|
||||||
|
|
||||||
|
Dispatch an action. This will notify all subscribers of the action.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
this.actionService.dispatch({ type: 'MY_ACTION', payload: { foo: 'bar' } });
|
||||||
|
```
|
||||||
|
|
||||||
|
### `ofType(type: string): Observable<Action>`
|
||||||
|
|
||||||
|
Subscribe to actions of a specific type.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
this.actionService.ofType('MY_ACTION').subscribe(action => {
|
||||||
|
console.log(action);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
65
lib/core/src/lib/services/action.service.spec.ts
Normal file
65
lib/core/src/lib/services/action.service.spec.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { ActionService } from './action.service';
|
||||||
|
import { take } from 'rxjs/operators';
|
||||||
|
|
||||||
|
describe('ActionService', () => {
|
||||||
|
let service: ActionService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(ActionService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should dispatch and filter actions by type', (done) => {
|
||||||
|
const testAction = { type: 'testAction' };
|
||||||
|
service
|
||||||
|
.ofType('testAction')
|
||||||
|
.pipe(take(1))
|
||||||
|
.subscribe((action) => {
|
||||||
|
expect(action).toEqual(testAction);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
service.dispatch(testAction);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not emit actions of a different type', () => {
|
||||||
|
const testAction = { type: 'testAction' };
|
||||||
|
const otherAction = { type: 'otherAction' };
|
||||||
|
let emitted = false;
|
||||||
|
|
||||||
|
service.ofType(testAction.type).subscribe(() => {
|
||||||
|
emitted = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
service.dispatch(otherAction);
|
||||||
|
expect(emitted).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle dispatching null actions gracefully', () => {
|
||||||
|
expect(() => service.dispatch(null)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should initially emit a startup action', (done) => {
|
||||||
|
service.actions$.pipe(take(1)).subscribe((action) => {
|
||||||
|
expect(action.type).toBe('startup');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
42
lib/core/src/lib/services/action.service.ts
Normal file
42
lib/core/src/lib/services/action.service.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
|
import { filter } from 'rxjs/operators';
|
||||||
|
|
||||||
|
export interface Action {
|
||||||
|
type: string;
|
||||||
|
payload?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class ActionService {
|
||||||
|
private actions = new BehaviorSubject<Action>({ type: 'startup' });
|
||||||
|
|
||||||
|
actions$ = this.actions.asObservable();
|
||||||
|
|
||||||
|
ofType(type: string): Observable<Action> {
|
||||||
|
return this.actions$.pipe(filter((action) => action.type === type));
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(action: Action): void {
|
||||||
|
if (action) {
|
||||||
|
this.actions.next(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user