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..9e5d7cf0 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,6 +118,12 @@ 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); 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..5a8d1925 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,13 +44,13 @@ 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) { 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) }); } /**