mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[ACS-8695] Getting Agent avatar
This commit is contained in:
parent
92881d063a
commit
3c3961dd82
@ -17,20 +17,21 @@
|
|||||||
|
|
||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||||
import { Agent, AgentPaging, AgentsApi, AgentWithAvatar } from '@alfresco/js-api';
|
|
||||||
import { AgentService } from './agent.service';
|
import { AgentService } from './agent.service';
|
||||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
import { Agent, AgentPaging } from '@alfresco/js-api';
|
||||||
|
|
||||||
const agent1: Agent = {
|
const agent1: Agent = {
|
||||||
id: '1',
|
id: '1',
|
||||||
name: 'HR Agent',
|
name: 'HR Agent',
|
||||||
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.'
|
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.',
|
||||||
|
avatarUrl: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
const agent2: Agent = {
|
const agent2: Agent = {
|
||||||
id: '2',
|
id: '2',
|
||||||
name: 'Policy Agent',
|
name: 'Policy Agent',
|
||||||
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.'
|
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.',
|
||||||
|
avatarUrl: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
const agentPagingObjectMock: AgentPaging = {
|
const agentPagingObjectMock: AgentPaging = {
|
||||||
@ -46,23 +47,10 @@ const agentPagingObjectMock: AgentPaging = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const avatarAgentMock = '';
|
const agentWithAvatarListMock: Agent[] = [agent1, agent2];
|
||||||
|
|
||||||
const agentWithAvatarListMock: AgentWithAvatar[] = [
|
|
||||||
{
|
|
||||||
...agent1,
|
|
||||||
avatar: avatarAgentMock
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...agent2,
|
|
||||||
avatar: avatarAgentMock
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('AgentService', () => {
|
describe('AgentService', () => {
|
||||||
let agentService: AgentService;
|
let agentService: AgentService;
|
||||||
let apiService: AlfrescoApiService;
|
|
||||||
let agentsApi: AgentsApi;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -70,11 +58,6 @@ describe('AgentService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
agentService = TestBed.inject(AgentService);
|
agentService = TestBed.inject(AgentService);
|
||||||
apiService = TestBed.inject(AlfrescoApiService);
|
|
||||||
agentsApi = new AgentsApi(apiService.getInstance());
|
|
||||||
|
|
||||||
spyOn(agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock));
|
|
||||||
spyOn(agentService.agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load agents', (done) => {
|
it('should load agents', (done) => {
|
||||||
@ -86,12 +69,4 @@ describe('AgentService', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get agent avatar', (done) => {
|
|
||||||
agentService.getAgentAvatar('avatarId').subscribe((response) => {
|
|
||||||
expect(response).toEqual(avatarAgentMock);
|
|
||||||
expect(agentService.agentsApi.getAgentAvatar).toHaveBeenCalledWith('avatarId');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { AgentsApi, AgentWithAvatar } from '@alfresco/js-api';
|
import { Agent, AgentsApi } from '@alfresco/js-api';
|
||||||
import { BehaviorSubject, forkJoin, from, Observable, of } from 'rxjs';
|
import { BehaviorSubject, from, Observable, of } from 'rxjs';
|
||||||
import { switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { AlfrescoApiService } from '../../services';
|
import { AlfrescoApiService } from '../../services';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
@ -26,7 +26,7 @@ import { AlfrescoApiService } from '../../services';
|
|||||||
})
|
})
|
||||||
export class AgentService {
|
export class AgentService {
|
||||||
private _agentsApi: AgentsApi;
|
private _agentsApi: AgentsApi;
|
||||||
private agents = new BehaviorSubject<AgentWithAvatar[]>([]);
|
private agents = new BehaviorSubject<Agent[]>([]);
|
||||||
|
|
||||||
get agentsApi(): AgentsApi {
|
get agentsApi(): AgentsApi {
|
||||||
this._agentsApi = this._agentsApi ?? new AgentsApi(this.apiService.getInstance());
|
this._agentsApi = this._agentsApi ?? new AgentsApi(this.apiService.getInstance());
|
||||||
@ -42,35 +42,20 @@ export class AgentService {
|
|||||||
*
|
*
|
||||||
* @returns AgentWithAvatar[] list containing agents.
|
* @returns AgentWithAvatar[] list containing agents.
|
||||||
*/
|
*/
|
||||||
getAgents(): Observable<AgentWithAvatar[]> {
|
getAgents(): Observable<Agent[]> {
|
||||||
return this.agents$.pipe(
|
return this.agents$.pipe(
|
||||||
switchMap((agentsList) => {
|
switchMap((agentsList) => {
|
||||||
if (agentsList.length) {
|
if (agentsList.length) {
|
||||||
return of(agentsList);
|
return of(agentsList);
|
||||||
}
|
}
|
||||||
return from(this.agentsApi.getAgents()).pipe(
|
return from(this.agentsApi.getAgents()).pipe(
|
||||||
switchMap((paging) => {
|
map((paging) => {
|
||||||
const agents = paging.list.entries.map((agentEntry) => agentEntry.entry);
|
const agentEntries = paging.list.entries.map((agentEntry) => agentEntry.entry);
|
||||||
// TODO: fetch avatars https://hyland.atlassian.net/browse/ACS-8695
|
this.agents.next(agentEntries);
|
||||||
return forkJoin({ agents: of(agents), avatars: forkJoin(agents.map(() => of(``))) });
|
return agentEntries;
|
||||||
}),
|
|
||||||
switchMap(({ agents, avatars }) => {
|
|
||||||
const agentsWithAvatar = agents.map((agent, index) => ({ ...agent, avatar: avatars[index] }));
|
|
||||||
this.agents.next(agentsWithAvatar);
|
|
||||||
return of(agentsWithAvatar);
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets agent avatar by agent id.
|
|
||||||
*
|
|
||||||
* @param agentId agent unique id.
|
|
||||||
* @returns string with an image.
|
|
||||||
*/
|
|
||||||
getAgentAvatar(agentId: string): Observable<string> {
|
|
||||||
return from(this._agentsApi.getAgentAvatar(agentId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
| Method | HTTP request | Description |
|
| Method | HTTP request | Description |
|
||||||
|-----------------------------------|----------------------------------------------|--------------------------|
|
|-----------------------------------|----------------------------------------------|--------------------------|
|
||||||
| [getAgents](#getAgents) | **GET** /agents | Gets all agents. |
|
| [getAgents](#getAgents) | **GET** /agents | Gets all agents. |
|
||||||
| [getAgentAvatar](#getAgentAvatar) | **GET** /agents/${agentId}/avatars/-default- | Gets agent avatar by id. |
|
|
||||||
|
|
||||||
## getAgents
|
## getAgents
|
||||||
|
|
||||||
@ -47,31 +46,6 @@ agentsApi.getAgents().then((agents) => {
|
|||||||
|
|
||||||
**Return type**: [AgentPaging](#AgentPaging)
|
**Return type**: [AgentPaging](#AgentPaging)
|
||||||
|
|
||||||
## getAgentAvatar
|
|
||||||
|
|
||||||
Gets agent avatar by agent id.
|
|
||||||
|
|
||||||
**Parameters**
|
|
||||||
|
|
||||||
| Name | Type |
|
|
||||||
|---------------|----------|
|
|
||||||
| **agentId** | string |
|
|
||||||
|
|
||||||
**Example**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { AlfrescoApi, AgentsApi } from '@alfresco/js-api';
|
|
||||||
|
|
||||||
const alfrescoApi = new AlfrescoApi(/*..*/);
|
|
||||||
const agentsApi = new AgentsApi(alfrescoApi);
|
|
||||||
|
|
||||||
agentsApi.getAgentAvatar('agentId').then((agentAvatarImage) => {
|
|
||||||
console.log('API called successfully. Returned data: ' + agentAvatarImage);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
**Return type**: String
|
|
||||||
|
|
||||||
# Models
|
# Models
|
||||||
|
|
||||||
## AgentPaging
|
## AgentPaging
|
||||||
|
@ -19,4 +19,5 @@ export interface Agent {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
avatarUrl?: string;
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @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 { Agent } from './agent';
|
|
||||||
|
|
||||||
export interface AgentWithAvatar extends Agent {
|
|
||||||
avatar: string;
|
|
||||||
}
|
|
@ -28,7 +28,6 @@ export * from './activityEntry';
|
|||||||
export * from './activityPaging';
|
export * from './activityPaging';
|
||||||
export * from './activityPagingList';
|
export * from './activityPagingList';
|
||||||
export * from './agent';
|
export * from './agent';
|
||||||
export * from './agentWithAvatar';
|
|
||||||
export * from './agentEntry';
|
export * from './agentEntry';
|
||||||
export * from './agentPaging';
|
export * from './agentPaging';
|
||||||
export * from './agentPagingList';
|
export * from './agentPagingList';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user