UI: Added global scope variables in javascript functions - refactoring
This commit is contained in:
parent
d08e6dba5d
commit
b29e208b95
@ -44,7 +44,7 @@
|
|||||||
(ngModelChange)="onActionUpdated()"
|
(ngModelChange)="onActionUpdated()"
|
||||||
[fillHeight]="true"
|
[fillHeight]="true"
|
||||||
[functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']"
|
[functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']"
|
||||||
[globalVariables]="functionScopeVariables"
|
[disableUndefinedCheck]="true"
|
||||||
[validationArgs]="[]"
|
[validationArgs]="[]"
|
||||||
[editorCompleter]="customPrettyActionEditorCompleter">
|
[editorCompleter]="customPrettyActionEditorCompleter">
|
||||||
</tb-js-func>
|
</tb-js-func>
|
||||||
|
|||||||
@ -36,7 +36,6 @@ import { AppState } from '@core/core.state';
|
|||||||
import { combineLatest } from 'rxjs';
|
import { combineLatest } from 'rxjs';
|
||||||
import { CustomActionDescriptor } from '@shared/models/widget.models';
|
import { CustomActionDescriptor } from '@shared/models/widget.models';
|
||||||
import { CustomPrettyActionEditorCompleter } from '@home/components/widget/action/custom-action.models';
|
import { CustomPrettyActionEditorCompleter } from '@home/components/widget/action/custom-action.models';
|
||||||
import { WidgetService } from "@core/http/widget.service";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-custom-action-pretty-editor',
|
selector: 'tb-custom-action-pretty-editor',
|
||||||
@ -59,8 +58,6 @@ export class CustomActionPrettyEditorComponent extends PageComponent implements
|
|||||||
|
|
||||||
fullscreen = false;
|
fullscreen = false;
|
||||||
|
|
||||||
functionScopeVariables: string[];
|
|
||||||
|
|
||||||
@ViewChildren('leftPanel')
|
@ViewChildren('leftPanel')
|
||||||
leftPanelElmRef: QueryList<ElementRef<HTMLElement>>;
|
leftPanelElmRef: QueryList<ElementRef<HTMLElement>>;
|
||||||
|
|
||||||
@ -71,10 +68,8 @@ export class CustomActionPrettyEditorComponent extends PageComponent implements
|
|||||||
|
|
||||||
private propagateChange = (_: any) => {};
|
private propagateChange = (_: any) => {};
|
||||||
|
|
||||||
constructor(protected store: Store<AppState>,
|
constructor(protected store: Store<AppState>) {
|
||||||
private widgetService: WidgetService) {
|
|
||||||
super(store);
|
super(store);
|
||||||
this.functionScopeVariables = this.widgetService.getWidgetScopeVariables();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|||||||
@ -94,7 +94,7 @@
|
|||||||
[(ngModel)]="action.customFunction"
|
[(ngModel)]="action.customFunction"
|
||||||
(ngModelChange)="notifyActionUpdated()"
|
(ngModelChange)="notifyActionUpdated()"
|
||||||
[functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']"
|
[functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']"
|
||||||
[globalVariables]="functionScopeVariables"
|
[disableUndefinedCheck]="true"
|
||||||
[validationArgs]="[]"
|
[validationArgs]="[]"
|
||||||
[editorCompleter]="customPrettyActionEditorCompleter">
|
[editorCompleter]="customPrettyActionEditorCompleter">
|
||||||
</tb-js-func>
|
</tb-js-func>
|
||||||
|
|||||||
@ -41,7 +41,6 @@ import { forkJoin, from } from 'rxjs';
|
|||||||
import { map, tap } from 'rxjs/operators';
|
import { map, tap } from 'rxjs/operators';
|
||||||
import { getAce } from '@shared/models/ace/ace.models';
|
import { getAce } from '@shared/models/ace/ace.models';
|
||||||
import { beautifyCss, beautifyHtml } from '@shared/models/beautify.models';
|
import { beautifyCss, beautifyHtml } from '@shared/models/beautify.models';
|
||||||
import { WidgetService } from "@core/http/widget.service";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-custom-action-pretty-resources-tabs',
|
selector: 'tb-custom-action-pretty-resources-tabs',
|
||||||
@ -76,16 +75,12 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl
|
|||||||
cssEditor: Ace.Editor;
|
cssEditor: Ace.Editor;
|
||||||
setValuesPending = false;
|
setValuesPending = false;
|
||||||
|
|
||||||
functionScopeVariables: string[];
|
|
||||||
|
|
||||||
customPrettyActionEditorCompleter = CustomPrettyActionEditorCompleter;
|
customPrettyActionEditorCompleter = CustomPrettyActionEditorCompleter;
|
||||||
|
|
||||||
constructor(protected store: Store<AppState>,
|
constructor(protected store: Store<AppState>,
|
||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
private widgetService: WidgetService,
|
|
||||||
private raf: RafService) {
|
private raf: RafService) {
|
||||||
super(store);
|
super(store);
|
||||||
this.functionScopeVariables = this.widgetService.getWidgetScopeVariables();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import {
|
|||||||
getDefaultProcessLocationFunction,
|
getDefaultProcessLocationFunction,
|
||||||
getDefaultProcessQrCodeFunction
|
getDefaultProcessQrCodeFunction
|
||||||
} from '@home/components/widget/action/mobile-action-editor.models';
|
} from '@home/components/widget/action/mobile-action-editor.models';
|
||||||
import { WidgetService } from "@core/http/widget.service";
|
import { WidgetService } from '@core/http/widget.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-mobile-action-editor',
|
selector: 'tb-mobile-action-editor',
|
||||||
|
|||||||
@ -47,7 +47,7 @@ import { CustomActionEditorCompleter } from '@home/components/widget/action/cust
|
|||||||
import { isDefinedAndNotNull } from '@core/utils';
|
import { isDefinedAndNotNull } from '@core/utils';
|
||||||
import { MobileActionEditorComponent } from '@home/components/widget/action/mobile-action-editor.component';
|
import { MobileActionEditorComponent } from '@home/components/widget/action/mobile-action-editor.component';
|
||||||
import { widgetType } from '@shared/models/widget.models';
|
import { widgetType } from '@shared/models/widget.models';
|
||||||
import { WidgetService } from "@core/http/widget.service";
|
import { WidgetService } from '@core/http/widget.service';
|
||||||
|
|
||||||
export interface WidgetActionDialogData {
|
export interface WidgetActionDialogData {
|
||||||
isAdd: boolean;
|
isAdd: boolean;
|
||||||
|
|||||||
@ -40,7 +40,7 @@ import { map, mergeMap, publishReplay, refCount, tap } from 'rxjs/operators';
|
|||||||
import { alarmFields } from '@shared/models/alarm.models';
|
import { alarmFields } from '@shared/models/alarm.models';
|
||||||
import { JsFuncComponent } from '@shared/components/js-func.component';
|
import { JsFuncComponent } from '@shared/components/js-func.component';
|
||||||
import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models';
|
import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models';
|
||||||
import { WidgetService } from "@core/http/widget.service";
|
import { WidgetService } from '@core/http/widget.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-data-key-config',
|
selector: 'tb-data-key-config',
|
||||||
|
|||||||
@ -85,6 +85,8 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor,
|
|||||||
|
|
||||||
@Input() globalVariables: Array<string>;
|
@Input() globalVariables: Array<string>;
|
||||||
|
|
||||||
|
@Input() disableUndefinedCheck = false;
|
||||||
|
|
||||||
private noValidateValue: boolean;
|
private noValidateValue: boolean;
|
||||||
get noValidate(): boolean {
|
get noValidate(): boolean {
|
||||||
return this.noValidateValue;
|
return this.noValidateValue;
|
||||||
@ -167,6 +169,7 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor,
|
|||||||
this.updateView();
|
this.updateView();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!this.disableUndefinedCheck) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.jsEditor.session.on('changeAnnotation', () => {
|
this.jsEditor.session.on('changeAnnotation', () => {
|
||||||
const annotations = this.jsEditor.session.getAnnotations();
|
const annotations = this.jsEditor.session.getAnnotations();
|
||||||
@ -180,19 +183,20 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor,
|
|||||||
this.propagateChange(this.modelValue);
|
this.propagateChange(this.modelValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (!!this.jsEditor.session.$worker) {
|
if (!!this.jsEditor.session.$worker) {
|
||||||
const jsWorkerOptions = {
|
const jsWorkerOptions = {
|
||||||
undef: true,
|
undef: !this.disableUndefinedCheck,
|
||||||
unused: true,
|
unused: true,
|
||||||
globals: {}
|
globals: {}
|
||||||
};
|
};
|
||||||
if (this.functionArgs) {
|
if (!this.disableUndefinedCheck && this.functionArgs) {
|
||||||
this.functionArgs.forEach(arg => {
|
this.functionArgs.forEach(arg => {
|
||||||
jsWorkerOptions.globals[arg] = false;
|
jsWorkerOptions.globals[arg] = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (this.globalVariables) {
|
if (!this.disableUndefinedCheck && this.globalVariables) {
|
||||||
this.globalVariables.forEach(arg => {
|
this.globalVariables.forEach(arg => {
|
||||||
jsWorkerOptions.globals[arg] = false;
|
jsWorkerOptions.globals[arg] = false;
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user