UI: Add MVEL script lang support
This commit is contained in:
parent
42832aab8c
commit
00e9fb2c7b
@ -21,6 +21,7 @@ export interface SysParamsState {
|
|||||||
allowedDashboardIds: string[];
|
allowedDashboardIds: string[];
|
||||||
edgesSupportEnabled: boolean;
|
edgesSupportEnabled: boolean;
|
||||||
hasRepository: boolean;
|
hasRepository: boolean;
|
||||||
|
mvelEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AuthPayload extends SysParamsState {
|
export interface AuthPayload extends SysParamsState {
|
||||||
|
|||||||
@ -24,7 +24,8 @@ const emptyUserAuthState: AuthPayload = {
|
|||||||
forceFullscreen: false,
|
forceFullscreen: false,
|
||||||
allowedDashboardIds: [],
|
allowedDashboardIds: [],
|
||||||
edgesSupportEnabled: false,
|
edgesSupportEnabled: false,
|
||||||
hasRepository: false
|
hasRepository: false,
|
||||||
|
mvelEnabled: false
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialState: AuthState = {
|
export const initialState: AuthState = {
|
||||||
|
|||||||
@ -60,6 +60,11 @@ export const selectHasRepository = createSelector(
|
|||||||
(state: AuthState) => state.hasRepository
|
(state: AuthState) => state.hasRepository
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectMvelEnabled = createSelector(
|
||||||
|
selectAuthState,
|
||||||
|
(state: AuthState) => state.mvelEnabled
|
||||||
|
);
|
||||||
|
|
||||||
export function getCurrentAuthState(store: Store<AppState>): AuthState {
|
export function getCurrentAuthState(store: Store<AppState>): AuthState {
|
||||||
let state: AuthState;
|
let state: AuthState;
|
||||||
store.pipe(select(selectAuth), take(1)).subscribe(
|
store.pipe(select(selectAuth), take(1)).subscribe(
|
||||||
|
|||||||
@ -478,11 +478,20 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadMvelEnabled(authUser: AuthUser): Observable<boolean> {
|
||||||
|
if (authUser.authority === Authority.TENANT_ADMIN) {
|
||||||
|
return this.http.get<boolean>('/api/ruleChain/mvelEnabled', defaultHttpOptions());
|
||||||
|
} else {
|
||||||
|
return of(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private loadSystemParams(authPayload: AuthPayload): Observable<SysParamsState> {
|
private loadSystemParams(authPayload: AuthPayload): Observable<SysParamsState> {
|
||||||
const sources = [this.loadIsUserTokenAccessEnabled(authPayload.authUser),
|
const sources = [this.loadIsUserTokenAccessEnabled(authPayload.authUser),
|
||||||
this.fetchAllowedDashboardIds(authPayload),
|
this.fetchAllowedDashboardIds(authPayload),
|
||||||
this.loadIsEdgesSupportEnabled(),
|
this.loadIsEdgesSupportEnabled(),
|
||||||
this.loadHasRepository(authPayload.authUser),
|
this.loadHasRepository(authPayload.authUser),
|
||||||
|
this.loadMvelEnabled(authPayload.authUser),
|
||||||
this.timeService.loadMaxDatapointsLimit()];
|
this.timeService.loadMaxDatapointsLimit()];
|
||||||
return forkJoin(sources)
|
return forkJoin(sources)
|
||||||
.pipe(map((data) => {
|
.pipe(map((data) => {
|
||||||
@ -490,7 +499,8 @@ export class AuthService {
|
|||||||
const allowedDashboardIds: string[] = data[1] as string[];
|
const allowedDashboardIds: string[] = data[1] as string[];
|
||||||
const edgesSupportEnabled: boolean = data[2] as boolean;
|
const edgesSupportEnabled: boolean = data[2] as boolean;
|
||||||
const hasRepository: boolean = data[3] as boolean;
|
const hasRepository: boolean = data[3] as boolean;
|
||||||
return {userTokenAccessEnabled, allowedDashboardIds, edgesSupportEnabled, hasRepository};
|
const mvelEnabled: boolean = data[4] as boolean;
|
||||||
|
return {userTokenAccessEnabled, allowedDashboardIds, edgesSupportEnabled, hasRepository, mvelEnabled};
|
||||||
}, catchError((err) => {
|
}, catchError((err) => {
|
||||||
return of({});
|
return of({});
|
||||||
})));
|
})));
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import { ComponentDescriptorService } from './component-descriptor.service';
|
|||||||
import {
|
import {
|
||||||
IRuleNodeConfigurationComponent,
|
IRuleNodeConfigurationComponent,
|
||||||
LinkLabel,
|
LinkLabel,
|
||||||
RuleNodeComponentDescriptor, RuleNodeConfiguration,
|
RuleNodeComponentDescriptor, RuleNodeConfiguration, ScriptLanguage,
|
||||||
TestScriptInputParams,
|
TestScriptInputParams,
|
||||||
TestScriptResult
|
TestScriptResult
|
||||||
} from '@app/shared/models/rule-node.models';
|
} from '@app/shared/models/rule-node.models';
|
||||||
@ -170,8 +170,12 @@ export class RuleChainService {
|
|||||||
return this.http.get<DebugRuleNodeEventBody>(`/api/ruleNode/${ruleNodeId}/debugIn`, defaultHttpOptionsFromConfig(config));
|
return this.http.get<DebugRuleNodeEventBody>(`/api/ruleNode/${ruleNodeId}/debugIn`, defaultHttpOptionsFromConfig(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
public testScript(inputParams: TestScriptInputParams, config?: RequestConfig): Observable<TestScriptResult> {
|
public testScript(inputParams: TestScriptInputParams, scriptLang?: ScriptLanguage, config?: RequestConfig): Observable<TestScriptResult> {
|
||||||
return this.http.post<TestScriptResult>('/api/ruleChain/testScript', inputParams, defaultHttpOptionsFromConfig(config));
|
let url = '/api/ruleChain/testScript';
|
||||||
|
if (scriptLang) {
|
||||||
|
url += `?scriptLang=${scriptLang}`;
|
||||||
|
}
|
||||||
|
return this.http.post<TestScriptResult>(url, inputParams, defaultHttpOptionsFromConfig(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadRuleNodeComponents(ruleChainType: RuleChainType, config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> {
|
private loadRuleNodeComponents(ruleChainType: RuleChainType, config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> {
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import {
|
|||||||
NodeScriptTestDialogData
|
NodeScriptTestDialogData
|
||||||
} from '@shared/components/dialog/node-script-test-dialog.component';
|
} from '@shared/components/dialog/node-script-test-dialog.component';
|
||||||
import { sortObjectKeys } from '@core/utils';
|
import { sortObjectKeys } from '@core/utils';
|
||||||
|
import { ScriptLanguage } from '@shared/models/rule-node.models';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -35,7 +36,8 @@ export class NodeScriptTestService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testNodeScript(script: string, scriptType: string, functionTitle: string,
|
testNodeScript(script: string, scriptType: string, functionTitle: string,
|
||||||
functionName: string, argNames: string[], ruleNodeId: string, helpId?: string): Observable<string> {
|
functionName: string, argNames: string[], ruleNodeId: string, helpId?: string,
|
||||||
|
scriptLang?: ScriptLanguage): Observable<string> {
|
||||||
if (ruleNodeId) {
|
if (ruleNodeId) {
|
||||||
return this.ruleChainService.getLatestRuleNodeDebugInput(ruleNodeId).pipe(
|
return this.ruleChainService.getLatestRuleNodeDebugInput(ruleNodeId).pipe(
|
||||||
switchMap((debugIn) => {
|
switchMap((debugIn) => {
|
||||||
@ -57,13 +59,14 @@ export class NodeScriptTestService {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return this.openTestScriptDialog(script, scriptType, functionTitle,
|
return this.openTestScriptDialog(script, scriptType, functionTitle,
|
||||||
functionName, argNames, null, null, null, helpId);
|
functionName, argNames, null, null, null, helpId, scriptLang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private openTestScriptDialog(script: string, scriptType: string,
|
private openTestScriptDialog(script: string, scriptType: string,
|
||||||
functionTitle: string, functionName: string, argNames: string[],
|
functionTitle: string, functionName: string, argNames: string[],
|
||||||
msg?: any, metadata?: {[key: string]: string}, msgType?: string, helpId?: string): Observable<string> {
|
msg?: any, metadata?: {[key: string]: string}, msgType?: string, helpId?: string,
|
||||||
|
scriptLang?: ScriptLanguage): Observable<string> {
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
msg = {
|
msg = {
|
||||||
temperature: 22.4,
|
temperature: 22.4,
|
||||||
@ -95,7 +98,8 @@ export class NodeScriptTestService {
|
|||||||
script,
|
script,
|
||||||
scriptType,
|
scriptType,
|
||||||
argNames,
|
argNames,
|
||||||
helpId
|
helpId,
|
||||||
|
scriptLang
|
||||||
}
|
}
|
||||||
}).afterClosed();
|
}).afterClosed();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ import { Router } from '@angular/router';
|
|||||||
import { DialogComponent } from '@shared/components/dialog.component';
|
import { DialogComponent } from '@shared/components/dialog.component';
|
||||||
import { ContentType } from '@shared/models/constants';
|
import { ContentType } from '@shared/models/constants';
|
||||||
import { JsonContentComponent } from '@shared/components/json-content.component';
|
import { JsonContentComponent } from '@shared/components/json-content.component';
|
||||||
import { TestScriptInputParams } from '@shared/models/rule-node.models';
|
import { ScriptLanguage, TestScriptInputParams } from '@shared/models/rule-node.models';
|
||||||
import { RuleChainService } from '@core/http/rule-chain.service';
|
import { RuleChainService } from '@core/http/rule-chain.service';
|
||||||
import { mergeMap } from 'rxjs/operators';
|
import { mergeMap } from 'rxjs/operators';
|
||||||
import { ActionNotificationShow } from '@core/notification/notification.actions';
|
import { ActionNotificationShow } from '@core/notification/notification.actions';
|
||||||
@ -49,6 +49,7 @@ export interface NodeScriptTestDialogData {
|
|||||||
functionTitle: string;
|
functionTitle: string;
|
||||||
functionName: string;
|
functionName: string;
|
||||||
argNames: string[];
|
argNames: string[];
|
||||||
|
scriptLang?: ScriptLanguage;
|
||||||
msg?: any;
|
msg?: any;
|
||||||
metadata?: {[key: string]: string};
|
metadata?: {[key: string]: string};
|
||||||
msgType?: string;
|
msgType?: string;
|
||||||
@ -191,7 +192,8 @@ export class NodeScriptTestDialogComponent extends DialogComponent<NodeScriptTes
|
|||||||
metadata: this.nodeScriptTestFormGroup.get('metadata').value,
|
metadata: this.nodeScriptTestFormGroup.get('metadata').value,
|
||||||
script: this.nodeScriptTestFormGroup.get('script').value
|
script: this.nodeScriptTestFormGroup.get('script').value
|
||||||
};
|
};
|
||||||
return this.ruleChainService.testScript(inputParams).pipe(
|
const scriptLang = this.data.scriptLang ? this.data.scriptLang : ScriptLanguage.JS;
|
||||||
|
return this.ruleChainService.testScript(inputParams, scriptLang).pipe(
|
||||||
mergeMap((result) => {
|
mergeMap((result) => {
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
this.store.dispatch(new ActionNotificationShow(
|
this.store.dispatch(new ActionNotificationShow(
|
||||||
|
|||||||
@ -328,6 +328,11 @@ export interface FcRuleEdge extends FcEdge {
|
|||||||
labels?: string[];
|
labels?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ScriptLanguage {
|
||||||
|
JS = 'JS',
|
||||||
|
MVEL = 'MVEL'
|
||||||
|
}
|
||||||
|
|
||||||
export interface TestScriptInputParams {
|
export interface TestScriptInputParams {
|
||||||
script: string;
|
script: string;
|
||||||
scriptType: string;
|
scriptType: string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user