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 [nzTitle]="preScriptTitleTmp" [nzForceRender]="true">
<ng-template #preScriptTitleTmp>
Prescript
Before script
<span class="eo-tab-icon" *ngIf="bindGetApiParamNum(apiData.restParams)">{{
apiData.restParams | apiParamsNum
}}</span>
</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 [nzTitle]="suffixScriptTitleTmp" [nzForceRender]="true">
<ng-template #suffixScriptTitleTmp>
Post script
After Script
<span class="eo-tab-icon" *ngIf="bindGetApiParamNum(apiData.restParams)">{{
apiData.restParams | apiParamsNum
}}</span>
</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-tabset>
<!-- Response -->

View File

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

View File

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