mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-967] evaluate "hostname" and "port" for string settings (#2040)
* evaluate 'hostname' and 'port' in app config strings * update unit tests * fix unit tests * fix unit tests * update readme
This commit is contained in:
committed by
Eugenio Romano
parent
c3561510b9
commit
26fe9ed694
@@ -354,6 +354,27 @@ if (process.env.ENV === 'production') {
|
||||
})
|
||||
```
|
||||
|
||||
### Variable substitution in configuration strings
|
||||
|
||||
The `AppConfigService` also supports a limited set of variable substitutions to greatly simplify certain scenarios.
|
||||
|
||||
```json
|
||||
{
|
||||
"ecmHost": "http://{hostname}:{port}/ecm",
|
||||
"bpmHost": "http://{hostname}:{port}/bpm",
|
||||
"application": {
|
||||
"name": "Alfresco"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The supported variables are:
|
||||
|
||||
| Variable name | Runtime value |
|
||||
| --- | --- |
|
||||
| hostname | `location.hostname` |
|
||||
| port | `location.port` |
|
||||
|
||||
## Notification Service
|
||||
|
||||
The Notification Service is implemented on top of the Angular 2 Material Design snackbar.
|
||||
|
@@ -83,7 +83,7 @@ describe('AlfrescoContentService', () => {
|
||||
|
||||
it('should return a valid content URL', (done) => {
|
||||
authService.login('fake-username', 'fake-password').subscribe(() => {
|
||||
expect(contentService.getContentUrl(node)).toBe('http://localhost:3000/ecm/alfresco/api/' +
|
||||
expect(contentService.getContentUrl(node)).toBe('http://localhost:9876/ecm/alfresco/api/' +
|
||||
'-default-/public/alfresco/versions/1/nodes/fake-node-id/content?attachment=false&alf_ticket=fake-post-ticket');
|
||||
done();
|
||||
});
|
||||
@@ -98,7 +98,7 @@ describe('AlfrescoContentService', () => {
|
||||
it('should return a valid thumbnail URL', (done) => {
|
||||
authService.login('fake-username', 'fake-password').subscribe(() => {
|
||||
expect(contentService.getDocumentThumbnailUrl(node))
|
||||
.toBe('http://localhost:3000/ecm/alfresco/api/-default-/public/alfresco' +
|
||||
.toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco' +
|
||||
'/versions/1/nodes/fake-node-id/renditions/doclib/content?attachment=false&alf_ticket=fake-post-ticket');
|
||||
done();
|
||||
});
|
||||
|
@@ -23,8 +23,8 @@ import { ObjectUtils } from '../utils/object-utils';
|
||||
export class AppConfigService {
|
||||
|
||||
private config: any = {
|
||||
'ecmHost': 'http://localhost:3000/ecm',
|
||||
'bpmHost': 'http://localhost:3000/bpm',
|
||||
'ecmHost': 'http://{hostname}:{port}/ecm',
|
||||
'bpmHost': 'http://{hostname}:{port}/bpm',
|
||||
'application': {
|
||||
'name': 'Alfresco'
|
||||
}
|
||||
@@ -35,7 +35,14 @@ export class AppConfigService {
|
||||
constructor(private http: Http) {}
|
||||
|
||||
get<T>(key: string): T {
|
||||
return <T> ObjectUtils.getValue(this.config, key);
|
||||
let result: any = ObjectUtils.getValue(this.config, key);
|
||||
if (typeof result === 'string') {
|
||||
const map = new Map<string, string>();
|
||||
map.set('hostname', location.hostname);
|
||||
map.set('port', location.port);
|
||||
result = this.formatString(result, map);
|
||||
}
|
||||
return <T> result;
|
||||
}
|
||||
|
||||
load(resource: string = 'app.config.json'): Promise<any> {
|
||||
@@ -54,6 +61,17 @@ export class AppConfigService {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private formatString(str: string, map: Map<string, string>): string {
|
||||
let result = str;
|
||||
|
||||
map.forEach((value, key) => {
|
||||
const expr = new RegExp('{' + key + '}', 'gm');
|
||||
result = result.replace(expr, value);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export function InitAppConfigServiceProvider(resource: string): any {
|
||||
|
@@ -71,7 +71,7 @@ describe('RenditionsService', () => {
|
||||
it('Create redition service should call the server with the ID passed and the asked encoding', (done) => {
|
||||
service.createRendition('fake-node-id', 'pdf').subscribe((res) => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().method).toBe('POST');
|
||||
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://localhost:3000/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
|
||||
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -88,7 +88,7 @@ describe('RenditionsService', () => {
|
||||
service.convert('fake-node-id', 'pdf', 1000);
|
||||
|
||||
expect(jasmine.Ajax.requests.mostRecent().method).toBe('POST');
|
||||
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://localhost:3000/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
|
||||
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user