diff --git a/docs/en/UI/Angular/Environment.md b/docs/en/UI/Angular/Environment.md index 86978cfa16..402e110f94 100644 --- a/docs/en/UI/Angular/Environment.md +++ b/docs/en/UI/Angular/Environment.md @@ -1,6 +1,6 @@ # Environment -Every application needs some ** environment ** variables. In Angular world, this is usually managed by `environment.ts`, `environment.prod.ts` and so on. It is the same for ABP as well. +Every application needs some **environment** variables. In Angular world, this is usually managed by `environment.ts`, `environment.prod.ts` and so on. It is the same for ABP as well. Current `Environment` configuration holds sub config classes as follows: diff --git a/docs/en/UI/Angular/Service-Proxies.md b/docs/en/UI/Angular/Service-Proxies.md index 40fb18f45d..5466d64182 100644 --- a/docs/en/UI/Angular/Service-Proxies.md +++ b/docs/en/UI/Angular/Service-Proxies.md @@ -1,5 +1,7 @@ ## Service Proxies +> THIS DOCUMENT IS OUTDATED. IT IS BEING UPDATED. MEANWHILE, YOU CAN [SEE THIS ARTICLE](https://github.com/abpframework/abp/blob/dev/docs/en/Blog-Posts/2020-09-07%20Angular-Service-Proxies/POST.md) TO LEARN HOW TO USE THE ABP ANGULAR SERVICE PROXIES. + It is common to call a REST endpoint in the server from our Angular applications. In this case, we generally create **services** (those have methods for each service method on the server side) and **model objects** (matches to [DTOs](../../Data-Transfer-Objects) in the server side). In addition to manually creating such server-interacting services, we could use tools like [NSWAG](https://github.com/RicoSuter/NSwag) to generate service proxies for us. But NSWAG has the following problems we've experienced: diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index 2aaf7a3bc2..ec9ccd6749 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -9,6 +9,7 @@ import { RestOccurError } from '../actions/rest.actions'; import { SetLanguage } from '../actions/session.actions'; import { ApplicationConfiguration } from '../models/application-configuration'; import { Config } from '../models/config'; +import { interpolate } from '../utils/string-utils'; import { SessionState } from './session.state'; @State({ @@ -180,14 +181,12 @@ export class ConfigState { return defaultValue || sourceKey; } + // [TODO]: next line should be removed in v3.2, breaking change!!! interpolateParams = interpolateParams.filter(params => params != null); - if (localization && interpolateParams && interpolateParams.length) { - interpolateParams.forEach(param => { - localization = localization.replace(/[\'\"]?\{[\d]+\}[\'\"]?/, param); - }); - } + if (localization) localization = interpolate(localization, interpolateParams); if (typeof localization !== 'string') localization = ''; + return localization || defaultValue || (key as string); }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/string-utils.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/string-utils.spec.ts index a0642e43ee..c2f7a3c601 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/string-utils.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/string-utils.spec.ts @@ -1,4 +1,4 @@ -import { createTokenParser } from '../utils/string-utils'; +import { createTokenParser, interpolate } from '../utils/string-utils'; describe('String Utils', () => { describe('#createTokenParser', () => { @@ -19,4 +19,28 @@ describe('String Utils', () => { }, ); }); + + describe('#interpolate', () => { + test.each` + text | params | expected + ${'This is {0} and {1} example.'} | ${['foo', 'bar']} | ${'This is foo and bar example.'} + ${'This is {1} and {0} example.'} | ${['foo', 'bar']} | ${'This is bar and foo example.'} + ${'This is {0} and {0} example.'} | ${['foo', 'bar']} | ${'This is foo and foo example.'} + ${'This is {1} and {1} example.'} | ${['foo', 'bar']} | ${'This is bar and bar example.'} + ${'This is "{0}" and "{1}" example.'} | ${['foo', 'bar']} | ${'This is foo and bar example.'} + ${"This is '{1}' and '{0}' example."} | ${['foo', 'bar']} | ${'This is bar and foo example.'} + ${'This is { 0 } and {0} example.'} | ${['foo', 'bar']} | ${'This is foo and foo example.'} + ${'This is {1} and { 1 } example.'} | ${['foo', 'bar']} | ${'This is bar and bar example.'} + ${'This is {0}, {3}, {1}, and {2} example.'} | ${['foo', 'bar', 'baz', 'qux']} | ${'This is foo, qux, bar, and baz example.'} + ${'This is {0} with 0 example.'} | ${['foo']} | ${'This is foo with 0 example.'} + ${'This is {0} and {1} example.'} | ${['foo']} | ${'This is foo and {1} example.'} + ${'This is {0} and {1} example.'} | ${[]} | ${'This is {0} and {1} example.'} + ${'This is {0} example.'} | ${[null]} | ${'This is {0} example.'} + `( + 'should return $expected when text is $text and params are $params', + ({ text, params, expected }) => { + expect(interpolate(text, params)).toBe(expected); + }, + ); + }); }); diff --git a/npm/ng-packs/packages/core/src/lib/utils/string-utils.ts b/npm/ng-packs/packages/core/src/lib/utils/string-utils.ts index 00db697325..7404dceab7 100644 --- a/npm/ng-packs/packages/core/src/lib/utils/string-utils.ts +++ b/npm/ng-packs/packages/core/src/lib/utils/string-utils.ts @@ -15,3 +15,9 @@ export function createTokenParser(format: string) { }, {} as Record); }; } + +export function interpolate(text: string, params: string[]) { + return text + .replace(/(['"]?\{\s*(\d+)\s*\}['"]?)/g, (_, match, digit) => params[digit] ?? match) + .replace(/\s+/g, ' '); +} diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts index 2ac5949050..0e472e64d3 100644 --- a/npm/ng-packs/packages/schematics/src/utils/model.ts +++ b/npm/ng-packs/packages/schematics/src/utils/model.ts @@ -133,7 +133,11 @@ export function createImportRefToInterfaceReducerCreator(params: ModelGeneratorP return _interface.properties .reduce((refs, prop) => { - prop.refs.forEach(type => !types[type]?.isEnum && refs.push(type)); + prop.refs.forEach(type => { + if (types[type]?.isEnum || type === _interface.ref) return; + refs.push(type); + }); + return refs; }, []) .concat(base ? parseGenerics(typeDef.baseType!).toGenerics() : [])