Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enhance documentation of the rules engine #1736

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 5 additions & 8 deletions apps/showcase/src/app/rules-engine/rules-engine.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AsyncPipe } from '@angular/common';
import { AfterViewInit, ChangeDetectionStrategy, Component, QueryList, ViewChildren, ViewEncapsulation } from '@angular/core';
import { RouterModule } from '@angular/router';
import { NgbNav, NgbNavContent, NgbNavItem, NgbNavLink, NgbNavOutlet } from '@ng-bootstrap/ng-bootstrap';
import { Store } from '@ngrx/store';
import { ApplicationDevtoolsModule } from '@o3r/application';
import { ComponentsDevtoolsModule } from '@o3r/components';
import { ConfigOverrideStoreModule, ConfigurationBaseServiceModule, ConfigurationDevtoolsModule } from '@o3r/configuration';
Expand All @@ -23,8 +22,7 @@ import {
RulesEngineDevtoolsModule,
RulesEngineRunnerModule,
RulesEngineRunnerService,
RulesetsStore,
setRulesetsEntities,
Ruleset,
UnaryOperator
} from '@o3r/rules-engine';
import { firstValueFrom } from 'rxjs';
Expand Down Expand Up @@ -84,9 +82,8 @@ export class RulesEngineComponent implements AfterViewInit {
private readonly inPageNavPresService: InPageNavPresService,
private readonly dynamicContentService: DynamicContentService,
private readonly tripFactsService: TripFactsService,
private readonly rulesEngineService: RulesEngineRunnerService,
public currentTimeFactsService: CurrentTimeFactsService,
private readonly store: Store<RulesetsStore>,
rulesEngineService: RulesEngineRunnerService,
configHandle: ConfigurationRulesEngineActionHandler,
assetsHandler: AssetRulesEngineActionHandler,
localizationHandler: LocalizationRulesEngineActionHandler
Expand Down Expand Up @@ -119,15 +116,15 @@ export class RulesEngineComponent implements AfterViewInit {
);

const resultCall = await fetch(path);
const result = await resultCall.json();
const result = await resultCall.json() as {rulesets: Ruleset[]};

this.store.dispatch(setRulesetsEntities({ entities: result.rulesets }));
this.rulesEngineService.upsertRulesets(result.rulesets);
const [
newYorkAvailableRule,
helloNewYorkRule,
summerOtterRule,
lateOtterRule
] = result.rulesets[0].rules as Rule[];
] = result.rulesets[0].rules;
this.newYorkAvailableRule = JSON.stringify(this.formatRule(newYorkAvailableRule), null, 2);
this.helloNewYorkRule = JSON.stringify(this.formatRule(helloNewYorkRule), null, 2);
this.summerOtterRule = JSON.stringify(this.formatRule(summerOtterRule), null, 2);
Expand Down
3 changes: 2 additions & 1 deletion apps/showcase/src/assets/locales/en-GB.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"o3r-rules-engine-pres.whenQuestion": "When do you want to go?"
"o3r-rules-engine-pres.whenQuestion": "When do you want to go?",
"o3r-rules-engine-pres.hurry-up-question": "You are leaving soon, where will you go?"
}
105 changes: 97 additions & 8 deletions apps/showcase/src/assets/rules/rulesets.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@
"id": "6194b61a-1bf3-4c02-8b7c-20f782d68324",
"name": "rules-engine",
"disabled": false,
"validityRange": {
"from": "09/01/2021",
"to": "11/01/2025"
},

"linkedComponents": {
"or": [{
"library": "showcase",
"name": "RulesEnginePresConfig"
}]
},
"rules": [
{
"id": "5467e501-b9ff-414f-8026-56885d0d7a4b",
"name": "New-York availability",
"disabled": false,
"outputRuntimeFacts": [],
"inputRuntimeFacts": [],
"inputFacts": ["outboundDate"],
"rootElement": {
"elementType": "RULE_BLOCK",
"blockType": "IF_ELSE",
Expand Down Expand Up @@ -41,11 +53,19 @@
"library": "showcase",
"property": "destinations",
"value": [
{ "cityCode": "LON", "available": true },
{ "cityCode": "PAR", "available": true },
{ "cityCode": "NYC", "available": true }
{
"cityCode": "LON",
"available": true
},
{
"cityCode": "PAR",
"available": true
},
{
"cityCode": "NYC",
"available": true
}
]

}
],
"failureElements": []
Expand Down Expand Up @@ -79,12 +99,79 @@
"value": "o3r-rules-engine-pres.whenQuestion"
}
],
"failureElements": [
{
"elementType": "RULE_BLOCK",
"blockType": "IF_ELSE",
"condition": {
"any": [
{
"lhs": {
"type": "FACT",
"value": "outboundDate"
},
"rhs": {
"type": "LITERAL",
"value": "2880"
},
"operator": "dateInNextMinutes"
}
]
},
"successElements": [
{
"elementType": "ACTION",
"actionType": "UPDATE_LOCALISATION",
"key": "o3r-rules-engine-pres.question",
"value": "o3r-rules-engine-pres.hurry-up-question"
}
],
"failureElements": []
}
]
}
},
{
"id": "5467e501-b9ff-414f-8026-56885d0d7a4d",
"name": "The otter is on vacation",
"disabled": false,
"outputRuntimeFacts": [],
"inputRuntimeFacts": [],
"rootElement": {
"elementType": "RULE_BLOCK",
"blockType": "IF_ELSE",
"condition": {
"all": [
{
"lhs": {
"type": "FACT",
"value": "outboundDate"
},
"operator": "isDefined"
},
{
"lhs": {
"type": "FACT",
"value": "outboundDate"
},
"operator": "duringSummer"
}
]
},
"successElements": [
{
"elementType": "ACTION",
"actionType": "UPDATE_ASSET",
"asset": "otter.svg",
"value": "otter-summer.svg"
}
],
"failureElements": []
}
},
{
"id": "5467e501-b9ff-414f-8026-56885d0d7a4d",
"name":"The otter is on vacation",
"name": "The otter is on vacation 2",
"disabled": false,
"outputRuntimeFacts": [],
"inputRuntimeFacts": [],
Expand Down Expand Up @@ -116,6 +203,7 @@
"asset": "otter.svg",
"value": "otter-summer.svg"
}

],
"failureElements": []
}
Expand All @@ -137,8 +225,8 @@
"value": "outboundDate"
},
"rhs": {
"type": "LITERAL",
"value": "2880"
"type": "LITERAL",
"value": "2880"
},
"operator": "dateInNextMinutes"
}
Expand All @@ -155,7 +243,8 @@
"failureElements": []
}
}
]
],
"description": ""
},
{
"id": "5945e501-b9ff-414f-8025-56885d0d7a4b-5945e501-b9ff-414f-8025-56885d0d7a4b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConfigObserver, ConfigurationBaseService, ConfigurationObserver, Dynami
import { O3rComponent } from '@o3r/core';
import { DynamicContentModule } from '@o3r/dynamic-content';
import { Localization, LocalizationModule, LocalizationService, Translatable } from '@o3r/localization';
import { RulesEngineRunnerModule } from '@o3r/rules-engine';
import {RulesEngineRunnerModule, RulesEngineRunnerService} from '@o3r/rules-engine';
import { distinctUntilChanged, map, Observable, Subscription } from 'rxjs';
import { TripFactsService } from '../../../facts/trip/trip.facts';
import { DatePickerInputPresComponent } from '../../utilities';
Expand Down Expand Up @@ -65,6 +65,7 @@ export class RulesEnginePresComponent implements OnDestroy, OnChanges, DynamicCo
@Optional() configurationService: ConfigurationBaseService,
fb: FormBuilder,
tripService: TripFactsService,
public readonly rulesService: RulesEngineRunnerService,
localizationService: LocalizationService
) {
this.dynamicConfig$ = new ConfigurationObserver<RulesEnginePresConfig>(RULES_ENGINE_PRES_CONFIG_ID, RULES_ENGINE_PRES_DEFAULT_CONFIG, configurationService);
Expand Down Expand Up @@ -110,12 +111,17 @@ export class RulesEnginePresComponent implements OnDestroy, OnChanges, DynamicCo
private formatDate(dateTime: number) {
return formatDate(dateTime, 'yyyy-MM-dd', 'en-GB');
}
public ngOnInit() {
this.rulesService.enableRuleSetFor(RULES_ENGINE_PRES_CONFIG_ID);

}
public ngOnChanges(changes: SimpleChanges) {
if (changes.config) {
this.dynamicConfig$.next(this.config);
}
}
public ngOnDestroy() {
this.rulesService.disableRuleSetFor(RULES_ENGINE_PRES_CONFIG_ID);
this.subscription.unsubscribe();
}

Expand Down