-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
198 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/workbench/browser/src/app/shared/components/api-script/api-script.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div class="flex eo-api-script"> | ||
<div class="w-[240px] h-[300px]"> | ||
<nz-tree-view [nzTreeControl]="treeControl" [nzDataSource]="dataSource" [nzBlockNode]="true"> | ||
<nz-tree-node *nzTreeNodeDef="let node" nzTreeNodePadding> | ||
<nz-tree-node-toggle nzTreeNodeNoopToggle></nz-tree-node-toggle> | ||
<nz-tree-node-option [nzDisabled]="node.disabled" [nzSelected]="false" (nzClick)="insertCode(node)"> | ||
{{ node.name }} | ||
</nz-tree-node-option> | ||
</nz-tree-node> | ||
|
||
<nz-tree-node *nzTreeNodeDef="let node; when: hasChild" nzTreeNodePadding> | ||
<nz-tree-node-toggle> | ||
<i nz-icon nzType="caret-down" nzTreeNodeToggleRotateIcon></i> | ||
</nz-tree-node-toggle> | ||
<nz-tree-node-option [nzDisabled]="node.disabled" [nzSelected]="false"> | ||
{{ node.name }} | ||
</nz-tree-node-option> | ||
</nz-tree-node> | ||
</nz-tree-view> | ||
</div> | ||
<div class="flex-1 h-[300px]"> | ||
<eo-editor [(code)]="model" editorType="javascript" [eventList]="[ 'format', 'copy', 'search', 'replace']"> | ||
</eo-editor> | ||
</div> | ||
</div> |
Empty file.
23 changes: 23 additions & 0 deletions
23
src/workbench/browser/src/app/shared/components/api-script/api-script.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ApiScriptComponent } from './api-script.component'; | ||
|
||
describe('ApiScriptComponent', () => { | ||
let component: ApiScriptComponent; | ||
let fixture: ComponentFixture<ApiScriptComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ ApiScriptComponent ] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ApiScriptComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
83 changes: 83 additions & 0 deletions
83
src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
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, OnInit, 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'; | ||
|
||
interface TreeNode { | ||
name: string; | ||
code?: string; | ||
children?: TreeNode[]; | ||
} | ||
|
||
const TREE_DATA: TreeNode[] = [ | ||
{ | ||
name: 'HTTP API 请求', | ||
children: [ | ||
{ | ||
name: '获取响应结果', | ||
code: 'eo.http.response.get();', | ||
}, | ||
{ | ||
name: '设置响应结果', | ||
code: 'eo.http.response.set("response_value");', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
interface FlatNode extends TreeNode { | ||
expandable: boolean; | ||
name: string; | ||
level: number; | ||
disabled: boolean; | ||
} | ||
|
||
@Component({ | ||
selector: 'eo-api-script', | ||
templateUrl: './api-script.component.html', | ||
styleUrls: ['./api-script.component.scss'], | ||
}) | ||
export class ApiScriptComponent implements OnInit { | ||
@ViewChild(EoEditorComponent, { static: false }) eoEditor?: EoEditorComponent; | ||
|
||
private transformer = (node: TreeNode, level: number): FlatNode => ({ | ||
...node, | ||
expandable: !!node.children && node.children.length > 0, | ||
name: node.name, | ||
level, | ||
disabled: false, | ||
}); | ||
selectListSelection = new SelectionModel<FlatNode>(true); | ||
|
||
treeControl = new FlatTreeControl<FlatNode, any>( | ||
(node) => node.level, | ||
(node) => node.expandable | ||
); | ||
|
||
treeFlattener = new NzTreeFlattener( | ||
this.transformer, | ||
(node) => node.level, | ||
(node) => node.expandable, | ||
(node) => node.children | ||
); | ||
|
||
// @ts-ignore | ||
dataSource = new NzTreeFlatDataSource(this.treeControl, this.treeFlattener); | ||
|
||
model = ''; | ||
constructor() { | ||
this.dataSource.setData(TREE_DATA); | ||
this.treeControl.expandAll(); | ||
} | ||
|
||
ngOnInit(): void {} | ||
|
||
hasChild = (_: number, node: FlatNode): boolean => node.expandable; | ||
|
||
insertCode = (node: FlatNode) => { | ||
this.eoEditor.handleInsert(node.code); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,16 +205,7 @@ | |
dependencies: | ||
tslib "^2.3.0" | ||
|
||
"@angular/[email protected]": | ||
version "14.0.3" | ||
resolved "https://registry.yarnpkg.com/@angular/cdk/-/cdk-14.0.3.tgz#eaa0b0736481bc9c1d24ad88e19dd20874506032" | ||
integrity sha512-XN5+WVUFx13lW2x9gnzJprHGqcvSpKQaoXxFvlcn16i0P6Iy1jldVZm6q6chEhgX9rEi7P31nfE88OJzHmkEyw== | ||
dependencies: | ||
tslib "^2.3.0" | ||
optionalDependencies: | ||
parse5 "^5.0.0" | ||
|
||
"@angular/cdk@^13.0.1": | ||
"@angular/[email protected]", "@angular/cdk@^13.0.1": | ||
version "13.3.9" | ||
resolved "https://registry.npmmirror.com/@angular/cdk/-/cdk-13.3.9.tgz#a177196e872e29be3f84d3a50f778d361c689ff7" | ||
integrity sha512-XCuCbeuxWFyo3EYrgEYx7eHzwl76vaWcxtWXl00ka8d+WAOtMQ6Tf1D98ybYT5uwF9889fFpXAPw98mVnlo3MA== | ||
|