Skip to content

Commit 12a9a42

Browse files
authored
Merge pull request #9 from bci-oss/feature/add-language-to-rql-request
Feature/add language to rql request
2 parents 8d85e19 + 8aa8edd commit 12a9a42

File tree

6 files changed

+93
-5
lines changed

6 files changed

+93
-5
lines changed
28 KB
Loading

documentation/js-sdk-guide/modules/tooling-guide/pages/table-generation.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ The search input is present allowing you to filter the existing data in the tabl
117117

118118
NOTE: _The search input will filter the data `*ONLY*` by the existing `*STRING*` properties in the chosen Aspect Model._
119119

120+
Once the search functionality has been enabled, the next step is to choose the default language for remote access. This language selection determines the language used in the statement when accessing the system remotely.
121+
122+
image::choose-language.png[width=100%]
123+
120124
=== _Data handling_
121125

122126
After generating a component, you can pass the data from the parent to the child components and also the other way around. There is a prompt present which determines if the data should be handled on the client side or remote via an API call.

src/ng-generate/table-prompter/index.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {Observable, Subject, Subscriber} from 'rxjs';
3232
import {WIZARD_CONFIG_FILE} from '../../utils/file';
3333
import {TemplateHelper} from '../../utils/template-helper';
3434
import {Schema} from '../table/schema';
35+
import * as locale from 'locale-codes';
3536

3637
inquirer.registerPrompt('fuzzypath', require('inquirer-fuzzy-path'));
3738
inquirer.registerPrompt('suggest', require('inquirer-prompt-suggest'));
@@ -176,7 +177,7 @@ function getTtlPaths(promptSubj: Subject<any>, allAnswers: Schema, subscriber: S
176177
// listener
177178
const process = inquirer.prompt(promptSubj as any).ui.process;
178179
process.subscribe(
179-
(singleAnswer: {name: string; answer: any}) => {
180+
(singleAnswer: { name: string; answer: any }) => {
180181
switch (true) {
181182
case singleAnswer.name === createOrImport.name: {
182183
if (singleAnswer.answer) {
@@ -233,7 +234,8 @@ function getTtlPaths(promptSubj: Subject<any>, allAnswers: Schema, subscriber: S
233234
err => {
234235
console.log('Error: ', err);
235236
},
236-
() => {}
237+
() => {
238+
}
237239
);
238240

239241
promptSubj.next(createOrImport);
@@ -335,7 +337,7 @@ function loadSourceProcessResult(allAnswers: any, tree: Tree, options: Schema, p
335337
.then(aspect => {
336338
resolve(
337339
!aspect.isCollectionAspect &&
338-
loader.filterElements((entry: DefaultEntity) => entry instanceof DefaultEntity).length >= 1
340+
loader.filterElements((entry: DefaultEntity) => entry instanceof DefaultEntity).length >= 1
339341
);
340342
})
341343
.catch(error => reject(error));
@@ -637,6 +639,36 @@ function getUserConfigQuestions(allAnswers: any, tree: Tree, options: Schema): Q
637639
default: [],
638640
};
639641

642+
const requestChooseLanguageForSearchAction = {
643+
type: 'list',
644+
name: 'chooseLanguageForSearch',
645+
message: 'Which language should be used for the search functionality?',
646+
when: (answers: any) =>
647+
answers.addCommandBar && new TemplateHelper().isAddCommandBarFunctionSearch(answers.enabledCommandBarFunctions),
648+
choices: () => {
649+
loadAspect(allAnswers, tree).then(aspect => {
650+
const templateHelper = new TemplateHelper();
651+
let selectedElement: Aspect | Entity = aspect;
652+
if (allAnswers.selectedModelElementUrn && allAnswers.selectedModelElementUrn.length > 0) {
653+
selectedElement = loader.findByUrn(allAnswers.selectedModelElementUrn) as Aspect | Entity;
654+
}
655+
656+
const languageCodes = templateHelper.resolveAllLanguageCodes(selectedElement);
657+
const choices = [{name: 'English', value: 'en'}];
658+
659+
660+
languageCodes.forEach(code => {
661+
if (code !== 'en') {
662+
choices.push({name: locale.getByTag(code).name, value: code});
663+
}
664+
});
665+
666+
return choices
667+
})
668+
},
669+
default: 'en',
670+
};
671+
640672
const requestCustomCommandBarActions = {
641673
type: 'suggest',
642674
name: 'customCommandBarActions',
@@ -695,6 +727,7 @@ function getUserConfigQuestions(allAnswers: any, tree: Tree, options: Schema): Q
695727
requestCustomRowActions,
696728
requestAddCommandBar,
697729
requestEnableCommandBarFunctions,
730+
requestChooseLanguageForSearchAction,
698731
requestCustomCommandBarActions,
699732
requestEnableRemoteDataHandling,
700733
requestCustomService,

src/ng-generate/table/generators/ts-component.generator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ export class TsComponentGenerator {
746746
this.customFilterExtension.apply(query);
747747
}
748748
749-
const queryFilter = query.subNodes.length === 0 ? null : new Query({query: query});
749+
const queryFilter = new Query({query: query});
750750
751751
const queryOption = new Query();
752752
if (this.sort.active) {
@@ -770,6 +770,9 @@ export class TsComponentGenerator {
770770
QueryStringifier['encodeRql'] = (value: any) => {
771771
return value;
772772
};
773+
774+
const additionalCondition = new Eq('local', '${this.options.chooseLanguageForSearch ? this.options.chooseLanguageForSearch.toUpperCase() : 'EN'}');
775+
queryFilter?.queryNode.subNodes.push(additionalCondition);
773776
774777
const filterRQLQuery = queryFilter ? QueryStringifier.stringify(queryFilter) : '';
775778
const optionsRQLQuery = QueryStringifier.stringify(queryOption).replace('&', ',');
@@ -999,6 +1002,7 @@ export class TsComponentGenerator {
9991002
AbstractLogicalNode,
10001003
AbstractNode,
10011004
And,
1005+
Eq,
10021006
Ge,
10031007
In,
10041008
Le,

src/ng-generate/table/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface Schema extends ComponentSchema, DefaultSchema {
5454
enableRemoteDataHandling: boolean;
5555
customRemoteService: boolean;
5656
enabledCommandBarFunctions: string[];
57+
chooseLanguageForSearch: string;
5758
customCommandBarActions: string[];
5859
enableVersionSupport: boolean;
5960
excludedProperties: ExcludedProperty[];

src/utils/template-helper.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@
1313

1414
import {
1515
Aspect,
16+
Characteristic,
1617
DefaultAspect,
18+
DefaultCharacteristic,
1719
DefaultCollection,
1820
DefaultEntity,
1921
DefaultEntityInstance,
2022
DefaultEnumeration,
23+
DefaultPropertyInstanceDefinition,
2124
DefaultScalar,
2225
DefaultSingleEntity,
2326
Entity,
2427
Property,
2528
} from '@esmf/aspect-model-loader';
2629
import {dasherize, underscore} from '@angular-devkit/core/src/utils/strings';
2730
import {ExcludedProperty, Schema} from '../ng-generate/table/schema';
31+
import * as locale from 'locale-codes';
2832

2933
export class TemplateHelper {
3034
isAspectSelected(options: Schema | any) {
@@ -193,7 +197,7 @@ export class TemplateHelper {
193197
/**
194198
* Gets the resolved properties of the complex object.
195199
*/
196-
getComplexProperties(complexProp: Property, options: Schema): {complexProp: string; properties: Property[]} {
200+
getComplexProperties(complexProp: Property, options: Schema): { complexProp: string; properties: Property[] } {
197201
const propsToShow = options.complexProps.find(cp => cp.prop === complexProp.name)?.propsToShow;
198202
const properties = this.getProperties({
199203
selectedModelElement: complexProp.effectiveDataType as DefaultEntity,
@@ -203,6 +207,48 @@ export class TemplateHelper {
203207
return {complexProp: complexProp.name, properties: properties};
204208
}
205209

210+
resolveAllLanguageCodes(modelElement: Aspect | Entity): Set<string> {
211+
const allLanguageCodes: Set<string> = new Set();
212+
213+
const processElement = (element: Aspect | Entity | Property | Characteristic) => {
214+
const { localesPreferredNames, localesDescriptions } = element;
215+
216+
localesPreferredNames.forEach(code => allLanguageCodes.add(code));
217+
localesDescriptions.forEach(code => allLanguageCodes.add(code));
218+
219+
this.addLocalized(allLanguageCodes);
220+
221+
if (element instanceof DefaultAspect && element.properties.length >= 1) {
222+
element.properties.forEach(processElement);
223+
}
224+
225+
if (element instanceof DefaultPropertyInstanceDefinition) {
226+
const characteristic = element.characteristic;
227+
if (characteristic) {
228+
processElement(characteristic);
229+
}
230+
}
231+
232+
if (element instanceof DefaultCharacteristic && element.dataType && element.dataType.isComplex) {
233+
processElement(<Entity>element.dataType);
234+
}
235+
236+
if (element instanceof DefaultEntity && element.isComplex && element.properties) {
237+
element.properties.forEach(processElement);
238+
}
239+
};
240+
241+
processElement(modelElement);
242+
243+
return allLanguageCodes;
244+
}
245+
246+
addLocalized(languages: Set<string>): string[] {
247+
return Array.from(languages)
248+
.map(languageCode => locale.getByTag(languageCode).tag)
249+
.filter(e => !!e);
250+
}
251+
206252
resolveType(modelElement: Aspect | Entity): Aspect | Entity {
207253
if (modelElement instanceof DefaultAspect && modelElement.isCollectionAspect) {
208254
const collectionProperty = modelElement.properties.find(prop => prop.characteristic instanceof DefaultCollection);

0 commit comments

Comments
 (0)