refactor: before script & after script

This commit is contained in:
buqiyuan 2022-07-14 14:28:46 +08:00
parent 12925212f2
commit 023d73a0c5
3 changed files with 16 additions and 13 deletions

View File

@ -76,21 +76,21 @@
</nz-tab> </nz-tab>
<nz-tab [nzTitle]="preScriptTitleTmp" [nzForceRender]="true"> <nz-tab [nzTitle]="preScriptTitleTmp" [nzForceRender]="true">
<ng-template #preScriptTitleTmp> <ng-template #preScriptTitleTmp>
Prescript Before script
<span class="eo-tab-icon" *ngIf="bindGetApiParamNum(apiData.restParams)">{{ <span class="eo-tab-icon" *ngIf="bindGetApiParamNum(apiData.restParams)">{{
apiData.restParams | apiParamsNum apiData.restParams | apiParamsNum
}}</span> }}</span>
</ng-template> </ng-template>
<eo-api-script class="eo_theme_iblock bbd"></eo-api-script> <eo-api-script [(code)]="beforeScript" class="eo_theme_iblock bbd"></eo-api-script>
</nz-tab> </nz-tab>
<nz-tab [nzTitle]="suffixScriptTitleTmp" [nzForceRender]="true"> <nz-tab [nzTitle]="suffixScriptTitleTmp" [nzForceRender]="true">
<ng-template #suffixScriptTitleTmp> <ng-template #suffixScriptTitleTmp>
Post script After Script
<span class="eo-tab-icon" *ngIf="bindGetApiParamNum(apiData.restParams)">{{ <span class="eo-tab-icon" *ngIf="bindGetApiParamNum(apiData.restParams)">{{
apiData.restParams | apiParamsNum apiData.restParams | apiParamsNum
}}</span> }}</span>
</ng-template> </ng-template>
<eo-api-script class="eo_theme_iblock bbd"></eo-api-script> <eo-api-script [(code)]="afterScript" class="eo_theme_iblock bbd"></eo-api-script>
</nz-tab> </nz-tab>
</nz-tabset> </nz-tabset>
<!-- Response --> <!-- Response -->

View File

@ -41,6 +41,8 @@ export class ApiTestComponent implements OnInit, OnDestroy {
parameters: [], parameters: [],
hostUri: '', hostUri: '',
}; };
beforeScript = '';
afterScript = '';
status: 'start' | 'testing' | 'tested' = 'start'; status: 'start' | 'testing' | 'tested' = 'start';
waitSeconds = 0; waitSeconds = 0;
tabIndexRes = 0; tabIndexRes = 0;
@ -149,9 +151,13 @@ export class ApiTestComponent implements OnInit, OnDestroy {
this.testServer.send('unitTest', { this.testServer.send('unitTest', {
id: this.apiTab.tabID, id: this.apiTab.tabID,
action: 'ajax', action: 'ajax',
data: this.testServer.formatRequestData(this.apiData, { data: {
env: this.env, beforeScript: this.beforeScript,
}), afterScript: this.afterScript,
...this.testServer.formatRequestData(this.apiData, {
env: this.env,
}),
},
}); });
this.status$.next('testing'); this.status$.next('testing');
} }

View File

@ -1,7 +1,7 @@
import { SelectionModel } from '@angular/cdk/collections'; import { SelectionModel } from '@angular/cdk/collections';
import { FlatTreeControl } from '@angular/cdk/tree'; import { FlatTreeControl } from '@angular/cdk/tree';
// import { FlatTreeControl } from 'ng-zorro-antd/node_modules/@angular/cdk/tree'; // import { FlatTreeControl } from 'ng-zorro-antd/node_modules/@angular/cdk/tree';
import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'; import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { EoEditorComponent } from 'eo/workbench/browser/src/app/eoui/editor/eo-editor/eo-editor.component'; import { EoEditorComponent } from 'eo/workbench/browser/src/app/eoui/editor/eo-editor/eo-editor.component';
import { NzTreeFlatDataSource, NzTreeFlattener } from 'ng-zorro-antd/tree-view'; import { NzTreeFlatDataSource, NzTreeFlattener } from 'ng-zorro-antd/tree-view';
@ -14,11 +14,10 @@ import { TREE_DATA } from './constant';
styleUrls: ['./api-script.component.scss'], styleUrls: ['./api-script.component.scss'],
}) })
export class ApiScriptComponent implements OnInit { export class ApiScriptComponent implements OnInit {
@Output() codeChange = new EventEmitter<string>(); @Input() code = '';
@Output() codeChange: EventEmitter<any> = new EventEmitter();
@ViewChild(EoEditorComponent, { static: false }) eoEditor?: EoEditorComponent; @ViewChild(EoEditorComponent, { static: false }) eoEditor?: EoEditorComponent;
private code = '';
private transformer = (node: TreeNode, level: number): FlatNode => ({ private transformer = (node: TreeNode, level: number): FlatNode => ({
...node, ...node,
expandable: !!node.children && node.children.length > 0, expandable: !!node.children && node.children.length > 0,
@ -43,7 +42,6 @@ export class ApiScriptComponent implements OnInit {
// @ts-ignore // @ts-ignore
dataSource = new NzTreeFlatDataSource(this.treeControl, this.treeFlattener); dataSource = new NzTreeFlatDataSource(this.treeControl, this.treeFlattener);
model = '';
constructor() { constructor() {
this.dataSource.setData(TREE_DATA); this.dataSource.setData(TREE_DATA);
this.treeControl.expandAll(); this.treeControl.expandAll();
@ -54,7 +52,6 @@ export class ApiScriptComponent implements OnInit {
hasChild = (_: number, node: FlatNode): boolean => node.expandable; hasChild = (_: number, node: FlatNode): boolean => node.expandable;
handleChange(code) { handleChange(code) {
this.code = code;
setTimeout(() => { setTimeout(() => {
this.codeChange.emit(code); this.codeChange.emit(code);
}, 0); }, 0);