Browse Source

Test script function dialog.

pull/2411/head
Igor Kulikov 7 years ago
parent
commit
72b02eb7d3
  1. 22
      ui-ngx/src/app/core/services/script/node-script-test.service.ts
  2. 7
      ui-ngx/src/app/shared/components/dialog/node-script-test-dialog.component.html
  3. 28
      ui-ngx/src/app/shared/components/dialog/node-script-test-dialog.component.scss
  4. 50
      ui-ngx/src/app/shared/components/dialog/node-script-test-dialog.component.ts
  5. 6
      ui-ngx/src/app/shared/shared.module.ts

22
ui-ngx/src/app/core/services/script/node-script-test.service.ts

@ -18,13 +18,16 @@ import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { RuleChainService } from '@core/http/rule-chain.service'; import { RuleChainService } from '@core/http/rule-chain.service';
import { map, switchMap } from 'rxjs/operators'; import { map, switchMap } from 'rxjs/operators';
import { MatDialog } from '@angular/material';
import { NodeScriptTestDialogComponent, NodeScriptTestDialogData } from '@shared/components/dialog/node-script-test-dialog.component';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class NodeScriptTestService { export class NodeScriptTestService {
constructor(private ruleChainService: RuleChainService) { constructor(private ruleChainService: RuleChainService,
public dialog: MatDialog) {
} }
testNodeScript(script: string, scriptType: string, functionTitle: string, testNodeScript(script: string, scriptType: string, functionTitle: string,
@ -73,8 +76,21 @@ export class NodeScriptTestService {
if (!msgType) { if (!msgType) {
msgType = 'POST_TELEMETRY_REQUEST'; msgType = 'POST_TELEMETRY_REQUEST';
} }
console.log(`testNodeScript TODO: ${script}`); return this.dialog.open<NodeScriptTestDialogComponent, NodeScriptTestDialogData, string>(NodeScriptTestDialogComponent,
return of(script); {
disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog', 'tb-fullscreen-dialog-gt-sm'],
data: {
msg,
metadata,
msgType,
functionTitle,
functionName,
script,
scriptType,
argNames
}
}).afterClosed();
} }
} }

7
ui-ngx/src/app/core/services/script/node-script-test-dialog.component.html → ui-ngx/src/app/shared/components/dialog/node-script-test-dialog.component.html

@ -15,7 +15,8 @@
limitations under the License. limitations under the License.
--> -->
<form #nodeScriptTestForm="ngForm" [formGroup]="nodeScriptTestFormGroup" (ngSubmit)="save()" style="width: 800px;"> <form class="tb-node-script-test-dialog"
#nodeScriptTestForm="ngForm" [formGroup]="nodeScriptTestFormGroup" (ngSubmit)="save()">
<mat-toolbar fxLayout="row" color="primary"> <mat-toolbar fxLayout="row" color="primary">
<h2>{{ 'rulenode.test-script-function' | translate }}</h2> <h2>{{ 'rulenode.test-script-function' | translate }}</h2>
<span fxFlex></span> <span fxFlex></span>
@ -43,8 +44,8 @@
<div tb-toast toastTarget="metadataPanel" class="tb-resize-container"> <div tb-toast toastTarget="metadataPanel" class="tb-resize-container">
<div class="tb-editor-area-title-panel"> <div class="tb-editor-area-title-panel">
<label translate>rulenode.metadata</label> <label translate>rulenode.metadata</label>
TODO: metadataForm
</div> </div>
TODO: metadataForm
</div> </div>
</div> </div>
</div> </div>
@ -72,7 +73,6 @@
<button mat-button mat-raised-button color="primary" <button mat-button mat-raised-button color="primary"
type="button" type="button"
(click)="test()" (click)="test()"
cdkFocusInitial
[disabled]="(isLoading$ | async) || nodeScriptTestFormGroup.invalid"> [disabled]="(isLoading$ | async) || nodeScriptTestFormGroup.invalid">
{{ 'rulenode.test' | translate }} {{ 'rulenode.test' | translate }}
</button> </button>
@ -85,6 +85,7 @@
<button mat-button color="primary" <button mat-button color="primary"
style="margin-right: 20px;" style="margin-right: 20px;"
type="button" type="button"
cdkFocusInitial
[disabled]="(isLoading$ | async)" [disabled]="(isLoading$ | async)"
(click)="cancel()"> (click)="cancel()">
{{ 'action.cancel' | translate }} {{ 'action.cancel' | translate }}

28
ui-ngx/src/app/core/services/script/node-script-test-dialog.component.scss → ui-ngx/src/app/shared/components/dialog/node-script-test-dialog.component.scss

@ -1,4 +1,22 @@
:host { /**
* Copyright © 2016-2019 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.tb-node-script-test-dialog {
width: 100%;
height: 100%;
.tb-split { .tb-split {
box-sizing: border-box; box-sizing: border-box;
overflow-x: hidden; overflow-x: hidden;
@ -10,14 +28,6 @@
padding-left: 5px; padding-left: 5px;
border: 1px solid #c0c0c0; border: 1px solid #c0c0c0;
} }
.gutter {
background-color: #eee;
background-repeat: no-repeat;
background-position: 50%;
}
.gutter { .gutter {
background-color: #eee; background-color: #eee;
background-repeat: no-repeat; background-repeat: no-repeat;

50
ui-ngx/src/app/core/services/script/node-script-test-dialog.component.ts → ui-ngx/src/app/shared/components/dialog/node-script-test-dialog.component.ts

@ -17,41 +17,21 @@
import { import {
AfterViewInit, AfterViewInit,
Component, Component,
ElementRef, ElementRef, HostBinding,
Inject, Inject,
OnInit, OnInit,
QueryList, QueryList,
SkipSelf, SkipSelf,
ViewChild, ViewChildren,
ViewChildren ViewEncapsulation
} from '@angular/core'; } from '@angular/core';
import { ErrorStateMatcher, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; import { ErrorStateMatcher, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms';
FormBuilder, import { combineLatest } from 'rxjs';
FormControl,
FormGroup,
FormGroupDirective,
NgForm,
ValidatorFn,
Validators
} from '@angular/forms';
import { combineLatest, Observable, of } from 'rxjs';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { DialogComponent } from '@app/shared/components/dialog.component'; import { DialogComponent } from '@app/shared/components/dialog.component';
import {
toCustomAction,
WidgetActionCallbacks,
WidgetActionDescriptorInfo,
WidgetActionsData
} from '@home/components/widget/action/manage-widget-actions.component.models';
import { UtilsService } from '@core/services/utils.service';
import { WidgetActionSource, WidgetActionType, widgetActionTypeTranslationMap } from '@shared/models/widget.models';
import { map, mergeMap, startWith, tap } from 'rxjs/operators';
import { DashboardService } from '@core/http/dashboard.service';
import { Dashboard } from '@shared/models/dashboard.models';
import { DashboardUtilsService } from '@core/services/dashboard-utils.service';
export interface NodeScriptTestDialogData { export interface NodeScriptTestDialogData {
script: string; script: string;
@ -68,11 +48,15 @@ export interface NodeScriptTestDialogData {
selector: 'tb-node-script-test-dialog', selector: 'tb-node-script-test-dialog',
templateUrl: './node-script-test-dialog.component.html', templateUrl: './node-script-test-dialog.component.html',
providers: [{provide: ErrorStateMatcher, useExisting: NodeScriptTestDialogComponent}], providers: [{provide: ErrorStateMatcher, useExisting: NodeScriptTestDialogComponent}],
styleUrls: ['./node-script-test-dialog.component.scss'] styleUrls: ['./node-script-test-dialog.component.scss'],
encapsulation: ViewEncapsulation.None
}) })
export class NodeScriptTestDialogComponent extends DialogComponent<NodeScriptTestDialogComponent, export class NodeScriptTestDialogComponent extends DialogComponent<NodeScriptTestDialogComponent,
string> implements OnInit, AfterViewInit, ErrorStateMatcher { string> implements OnInit, AfterViewInit, ErrorStateMatcher {
@HostBinding('style.width') width = '100%';
@HostBinding('style.height') height = '100%';
@ViewChildren('topPanel') @ViewChildren('topPanel')
topPanelElmRef: QueryList<ElementRef<HTMLElement>>; topPanelElmRef: QueryList<ElementRef<HTMLElement>>;
@ -88,7 +72,7 @@ export class NodeScriptTestDialogComponent extends DialogComponent<NodeScriptTes
@ViewChildren('bottomLeftPanel') @ViewChildren('bottomLeftPanel')
bottomLeftPanelElmRef: QueryList<ElementRef<HTMLElement>>; bottomLeftPanelElmRef: QueryList<ElementRef<HTMLElement>>;
@ViewChildren('bottomLeftPanel') @ViewChildren('bottomRightPanel')
bottomRightPanelElmRef: QueryList<ElementRef<HTMLElement>>; bottomRightPanelElmRef: QueryList<ElementRef<HTMLElement>>;
nodeScriptTestFormGroup: FormGroup; nodeScriptTestFormGroup: FormGroup;
@ -108,11 +92,13 @@ export class NodeScriptTestDialogComponent extends DialogComponent<NodeScriptTes
} }
ngOnInit(): void { ngOnInit(): void {
this.nodeScriptTestFormGroup = this.fb.group({}); this.nodeScriptTestFormGroup = this.fb.group({
funcBody: ['', [Validators.required]]
});
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
combineLatest(this.topPanelElmRef.changes, /* combineLatest(this.topPanelElmRef.changes,
this.topLeftPanelElmRef.changes, this.topLeftPanelElmRef.changes,
this.topRightPanelElmRef.changes, this.topRightPanelElmRef.changes,
this.bottomPanelElmRef.changes, this.bottomPanelElmRef.changes,
@ -120,15 +106,15 @@ export class NodeScriptTestDialogComponent extends DialogComponent<NodeScriptTes
this.bottomRightPanelElmRef.changes).subscribe(() => { this.bottomRightPanelElmRef.changes).subscribe(() => {
if (this.topPanelElmRef.length && this.topLeftPanelElmRef.length && if (this.topPanelElmRef.length && this.topLeftPanelElmRef.length &&
this.topRightPanelElmRef.length && this.bottomPanelElmRef.length && this.topRightPanelElmRef.length && this.bottomPanelElmRef.length &&
this.bottomLeftPanelElmRef.length && this.bottomRightPanelElmRef.length) { this.bottomLeftPanelElmRef.length && this.bottomRightPanelElmRef.length) {*/
this.initSplitLayout(this.topPanelElmRef.first.nativeElement, this.initSplitLayout(this.topPanelElmRef.first.nativeElement,
this.topLeftPanelElmRef.first.nativeElement, this.topLeftPanelElmRef.first.nativeElement,
this.topRightPanelElmRef.first.nativeElement, this.topRightPanelElmRef.first.nativeElement,
this.bottomPanelElmRef.first.nativeElement, this.bottomPanelElmRef.first.nativeElement,
this.bottomLeftPanelElmRef.first.nativeElement, this.bottomLeftPanelElmRef.first.nativeElement,
this.bottomRightPanelElmRef.first.nativeElement); this.bottomRightPanelElmRef.first.nativeElement);
} // }
}); //});
} }
private initSplitLayout(topPanel: any, private initSplitLayout(topPanel: any,

6
ui-ngx/src/app/shared/shared.module.ts

@ -114,6 +114,7 @@ import { MaterialIconsDialogComponent } from '@shared/components/dialog/material
import { MaterialIconSelectComponent } from '@shared/components/material-icon-select.component'; import { MaterialIconSelectComponent } from '@shared/components/material-icon-select.component';
import { ImageInputComponent } from './components/image-input.component'; import { ImageInputComponent } from './components/image-input.component';
import { FileInputComponent } from './components/file-input.component'; import { FileInputComponent } from './components/file-input.component';
import { NodeScriptTestDialogComponent } from '@shared/components/dialog/node-script-test-dialog.component';
@NgModule({ @NgModule({
providers: [ providers: [
@ -134,7 +135,8 @@ import { FileInputComponent } from './components/file-input.component';
DashboardSelectPanelComponent, DashboardSelectPanelComponent,
MatSpinner, MatSpinner,
ColorPickerDialogComponent, ColorPickerDialogComponent,
MaterialIconsDialogComponent MaterialIconsDialogComponent,
NodeScriptTestDialogComponent
], ],
declarations: [ declarations: [
FooterComponent, FooterComponent,
@ -182,6 +184,7 @@ import { FileInputComponent } from './components/file-input.component';
MaterialIconsDialogComponent, MaterialIconsDialogComponent,
ColorInputComponent, ColorInputComponent,
MaterialIconSelectComponent, MaterialIconSelectComponent,
NodeScriptTestDialogComponent,
JsonFormComponent, JsonFormComponent,
ImageInputComponent, ImageInputComponent,
FileInputComponent, FileInputComponent,
@ -324,6 +327,7 @@ import { FileInputComponent } from './components/file-input.component';
MaterialIconsDialogComponent, MaterialIconsDialogComponent,
ColorInputComponent, ColorInputComponent,
MaterialIconSelectComponent, MaterialIconSelectComponent,
NodeScriptTestDialogComponent,
JsonFormComponent, JsonFormComponent,
ImageInputComponent, ImageInputComponent,
FileInputComponent, FileInputComponent,

Loading…
Cancel
Save