From fb8923eab77da5d5394240874984d16e3f399964 Mon Sep 17 00:00:00 2001 From: renqian805 <1743369777@qq.com> Date: Thu, 14 Jul 2022 23:09:44 +0800 Subject: [PATCH] fix: pre & after script history issues --- .../editor/eo-editor/eo-editor.component.ts | 23 +++---- .../pages/api/test/api-test.component.html | 14 ++-- .../app/pages/api/test/api-test.component.ts | 34 +++++++++- .../src/app/pages/pages.component.scss | 2 +- .../api-script/api-script.component.html | 21 ++---- .../api-script/api-script.component.ts | 16 ++--- .../shared/components/api-script/constant.ts | 65 ++++--------------- .../services/storage/IndexedDB/lib/index.ts | 4 +- 8 files changed, 75 insertions(+), 104 deletions(-) diff --git a/src/workbench/browser/src/app/eoui/editor/eo-editor/eo-editor.component.ts b/src/workbench/browser/src/app/eoui/editor/eo-editor/eo-editor.component.ts index 1433a43d..96bbd4d9 100644 --- a/src/workbench/browser/src/app/eoui/editor/eo-editor/eo-editor.component.ts +++ b/src/workbench/browser/src/app/eoui/editor/eo-editor/eo-editor.component.ts @@ -13,14 +13,6 @@ import 'brace/mode/html'; import 'brace/mode/xml'; import 'brace/ext/searchbox'; import ace from 'brace'; -import { completions } from 'eo/workbench/browser/src/app/shared/components/api-script/constant'; - -const langTools = ace.acequire('ace/ext/language_tools'); -console.log('langTools', langTools); -langTools.addCompleter({ - // this.aceEditorServiceService.getAutocomplete(this.autocompleteData), - getCompletions: (editor, session, pos, prefix, callback) => callback(null, completions), -}); type EventType = 'format' | 'copy' | 'search' | 'replace' | 'type' | 'download' | 'newTab'; @@ -62,6 +54,7 @@ export class EoEditorComponent implements AfterViewInit, OnInit, OnChanges { @Input() editorType = 'json'; @Input() autoFormat = false; @Input() disabled = false; + @Input() completions = []; @Output() codeChange = new EventEmitter(); @ViewChild(AceComponent, { static: false }) aceRef?: AceComponent; @ViewChild(AceDirective, { static: false }) directiveRef?: AceDirective; @@ -125,19 +118,21 @@ export class EoEditorComponent implements AfterViewInit, OnInit, OnChanges { event: it, ...eventHash.get(it), })); + const langTools = ace.acequire('ace/ext/language_tools'); + langTools.setCompleters([]); + langTools.addCompleter({ + // this.aceEditorServiceService.getAutocomplete(this.autocompleteData), + getCompletions: (editor, session, pos, prefix, callback) => callback(null, this.completions), + }); } log(event, txt) { console.log('ace event', event, txt); } handleBlur() { - setTimeout(() => { - this.codeChange.emit(this.code); - }, 0); + this.codeChange.emit(this.code); } handleChange() { - setTimeout(() => { - this.codeChange.emit(this.code); - }, 0); + this.codeChange.emit(this.code); } formatCode(code, type) { if (type === 'json') { diff --git a/src/workbench/browser/src/app/pages/api/test/api-test.component.html b/src/workbench/browser/src/app/pages/api/test/api-test.component.html index 75604fbd..0c98f90a 100644 --- a/src/workbench/browser/src/app/pages/api/test/api-test.component.html +++ b/src/workbench/browser/src/app/pages/api/test/api-test.component.html @@ -77,20 +77,16 @@ Pre-request Script - {{ - apiData.restParams | apiParamsNum - }} - + After-response Script - {{ - apiData.restParams | apiParamsNum - }} - + @@ -113,7 +109,7 @@ -
- +
diff --git a/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts b/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts index 2d52c70a..e7667485 100644 --- a/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts +++ b/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts @@ -7,7 +7,7 @@ import { EoEditorComponent } from 'eo/workbench/browser/src/app/eoui/editor/eo-e import { NzTreeFlatDataSource, NzTreeFlattener } from 'ng-zorro-antd/tree-view'; import type { TreeNode, FlatNode } from './constant'; -import { BEFORE_DATA } from './constant'; + @Component({ selector: 'eo-api-script', templateUrl: './api-script.component.html', @@ -15,6 +15,8 @@ import { BEFORE_DATA } from './constant'; }) export class ApiScriptComponent implements OnInit { @Input() code = ''; + @Input() treeData = []; + @Input() completions = []; @Output() codeChange: EventEmitter = new EventEmitter(); @ViewChild(EoEditorComponent, { static: false }) eoEditor?: EoEditorComponent; @@ -42,19 +44,17 @@ export class ApiScriptComponent implements OnInit { // @ts-ignore dataSource = new NzTreeFlatDataSource(this.treeControl, this.treeFlattener); - constructor() { - this.dataSource.setData(BEFORE_DATA); + constructor() {} + + ngOnInit(): void { + this.dataSource.setData(this.treeData); this.treeControl.expandAll(); } - ngOnInit(): void {} - hasChild = (_: number, node: FlatNode): boolean => node.expandable; handleChange(code) { - setTimeout(() => { - this.codeChange.emit(code); - }, 0); + this.codeChange.emit(code); } insertCode = (node: FlatNode) => { diff --git a/src/workbench/browser/src/app/shared/components/api-script/constant.ts b/src/workbench/browser/src/app/shared/components/api-script/constant.ts index efa7d603..185d7537 100644 --- a/src/workbench/browser/src/app/shared/components/api-script/constant.ts +++ b/src/workbench/browser/src/app/shared/components/api-script/constant.ts @@ -573,7 +573,6 @@ const COMMON_DATA: TreeNode[] = [ ]; export const BEFORE_DATA: TreeNode[] = [ - ...COMMON_DATA, { name: $localize`HTTP API request`, children: [ @@ -753,10 +752,10 @@ if (raw_api_demo_1_result.response !== "") { }, ], }, + ...COMMON_DATA, ]; export const AFTER_DATA: TreeNode[] = [ - ...COMMON_DATA, { name: $localize`HTTP API request`, children: [ @@ -781,60 +780,18 @@ export const AFTER_DATA: TreeNode[] = [ }, ], }, - { - name: $localize`Custom Global Variable`, - children: [ - { - name: $localize`Set Global Variable`, - caption: 'eo.globals.set', - value: 'eo.globals.set("param_key","param_value")', - note: { - code: 'eo.globals.set("param_key","param_value")', - desc: $localize`Set Global Variable`, - input: [ - { key: 'param_key', value: $localize`parameter name` }, - { key: 'param_value', value: $localize`parameter value` }, - ], - }, - }, - { - name: $localize`Get global variable value`, - caption: 'eo.globals.get', - value: 'eo.globals.get("param_key")', - note: { - code: 'eo.globals.set("param_key","param_value")', - desc: $localize`Get global variable value`, - input: [ - { key: 'param_key', value: $localize`parameter name` }, - { key: 'param_value', value: $localize`parameter value` }, - ], - output: $localize`Global Variable Value`, - }, - }, - { - name: $localize`Delete Global Variable`, - caption: 'eo.globals.unset', - value: 'eo.globals.unset("param_key")', - note: { - code: 'eo.globals.unset("param_key")', - desc: $localize`Delete Global Variable`, - input: [{ key: 'param_key', value: $localize`parameter name` }], - }, - }, - { - name: $localize`Clear All Global Variables`, - caption: 'eo.globals.clear', - value: 'eo.globals.clear()', - note: { - code: 'eo.globals.clear()', - desc: $localize`Clear All Global Variables`, - }, - }, - ], - }, + ...COMMON_DATA, ]; -export const completions: Completion[] = AFTER_DATA.flatMap((n) => n.children).reduce((prev, curr) => { +export const beforeScriptCompletions: Completion[] = BEFORE_DATA.flatMap((n) => n.children).reduce((prev, curr) => { + const { caption, value } = curr; + if (caption) { + prev.push({ caption, value }); + } + return prev; +}, []); + +export const afterScriptCompletions: Completion[] = AFTER_DATA.flatMap((n) => n.children).reduce((prev, curr) => { const { caption, value } = curr; if (caption) { prev.push({ caption, value }); diff --git a/src/workbench/browser/src/app/shared/services/storage/IndexedDB/lib/index.ts b/src/workbench/browser/src/app/shared/services/storage/IndexedDB/lib/index.ts index 34779f13..5bc39f02 100644 --- a/src/workbench/browser/src/app/shared/services/storage/IndexedDB/lib/index.ts +++ b/src/workbench/browser/src/app/shared/services/storage/IndexedDB/lib/index.ts @@ -485,7 +485,7 @@ export class IndexedDBStorage extends Dexie implements StorageInterface { * @param apiDataID */ apiTestHistoryLoadAllByApiDataID(apiDataID: number | string): Observable { - return this.loadAllByConditions(this.apiTestHistory, { apiDataID }); + return this.loadAllByConditions(this.apiTestHistory, { apiDataID: Number(apiDataID) }); } /** @@ -493,7 +493,7 @@ export class IndexedDBStorage extends Dexie implements StorageInterface { * @param apiDataID */ apiMockLoadAllByApiDataID(apiDataID: number | string): Observable { - return this.loadAllByConditions(this.mock, { apiDataID }); + return this.loadAllByConditions(this.mock, { apiDataID: Number(apiDataID) }); } /**