diff --git a/src/app/eoui/editor/eo-editor/eo-editor.component.ts b/src/app/eoui/editor/eo-editor/eo-editor.component.ts
index 2abfaaa7..e071d7a5 100644
--- a/src/app/eoui/editor/eo-editor/eo-editor.component.ts
+++ b/src/app/eoui/editor/eo-editor/eo-editor.component.ts
@@ -1,4 +1,4 @@
-import { Component, Input, Output, EventEmitter, OnChanges, AfterViewInit, ViewChild } from '@angular/core';
+import { Component, Input, Output, EventEmitter, OnChanges, AfterViewInit, ViewChild, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { AceConfigInterface, AceComponent, AceDirective } from 'ngx-ace-wrapper';
import { whatTextType } from '../../../utils';
@@ -44,7 +44,7 @@ const eventHash = new Map()
templateUrl: './eo-editor.component.html',
styleUrls: ['./eo-editor.component.scss'],
})
-export class EoEditorComponent implements AfterViewInit, OnChanges {
+export class EoEditorComponent implements AfterViewInit, OnInit, OnChanges {
@Input() eventList: EventType[] = [];
@Input() hiddenList: string[] = [];
@Input() code: string;
@@ -82,15 +82,7 @@ export class EoEditorComponent implements AfterViewInit, OnChanges {
constructor(private message: NzMessageService) {}
- ngAfterViewInit(): void {
- // To get the Ace instance:
- this.buttonList = this.eventList
- .filter((it) => it !== 'type')
- .map((it) => ({
- event: it,
- ...eventHash.get(it),
- }));
- }
+ ngAfterViewInit(): void {}
ngOnChanges() {
// * update root type
if (this.eventList.includes('type') && !this.hiddenList.includes('type')) {
@@ -101,6 +93,15 @@ export class EoEditorComponent implements AfterViewInit, OnChanges {
}
}
}
+ ngOnInit() {
+ // To get the Ace instance:
+ this.buttonList = this.eventList
+ .filter((it) => it !== 'type')
+ .map((it) => ({
+ event: it,
+ ...eventHash.get(it),
+ }));
+ }
log(event, txt) {
console.log('ace event', event, txt);
}
diff --git a/src/app/pages/api/api.component.html b/src/app/pages/api/api.component.html
index beb873c2..b2929d1a 100644
--- a/src/app/pages/api/api.component.html
+++ b/src/app/pages/api/api.component.html
@@ -20,15 +20,16 @@
-
-
- 文档
-
-
- 编辑
-
-
- 测试
+
+
+ {{ tab.title }}
diff --git a/src/app/pages/api/api.component.ts b/src/app/pages/api/api.component.ts
index 2ae48323..6aa4cab6 100644
--- a/src/app/pages/api/api.component.ts
+++ b/src/app/pages/api/api.component.ts
@@ -1,9 +1,8 @@
-import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
+import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { NzFormatEmitEvent, NzTreeNode } from 'ng-zorro-antd/tree';
import { Message, MessageService } from '../../shared/services/message';
-import { ApiTabComponent } from './tab/api-tab.component';
import { GroupService } from '../../shared/services/group/group.service';
import { NzModalService } from 'ng-zorro-antd/modal';
import { ApiDataService } from '../../shared/services/api-data/api-data.service';
@@ -13,15 +12,15 @@ import { GroupApiDataModel, GroupTreeItem } from '../../shared/models';
import { ApiData } from '../../shared/services/api-data/api-data.model';
import { Group } from '../../shared/services/group/group.model';
-import { Subject } from 'rxjs';
+import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
+import { ApiTabService } from './tab/api-tab.service';
@Component({
selector: 'eo-api',
templateUrl: './api.component.html',
styleUrls: ['./api.component.scss'],
})
export class ApiComponent implements OnInit, OnDestroy {
- @ViewChild(ApiTabComponent) apiTabComponent: ApiTabComponent;
/**
* Default projectID.
*/
@@ -49,13 +48,28 @@ export class ApiComponent implements OnInit, OnDestroy {
*/
id: number;
+ TABS = [
+ {
+ routerLink: 'detail',
+ title: '文档',
+ },
+ {
+ routerLink: 'edit',
+ title: '编辑',
+ },
+ {
+ routerLink: 'test',
+ title: '测试',
+ },
+ ];
private destroy$: Subject = new Subject();
constructor(
private route: ActivatedRoute,
private groupService: GroupService,
private apiDataService: ApiDataService,
private messageService: MessageService,
- private modalService: NzModalService
+ private modalService: NzModalService,
+ private tabSerive: ApiTabService
) {}
ngOnInit(): void {
@@ -93,7 +107,7 @@ export class ApiComponent implements OnInit, OnDestroy {
}
getApis() {
this.apiDataService.loadAllByProjectID(this.projectID).subscribe((items: Array) => {
- let apiItems={};
+ let apiItems = {};
items.forEach((item) => {
delete item.updatedAt;
apiItems[item.uuid] = item;
@@ -106,7 +120,7 @@ export class ApiComponent implements OnInit, OnDestroy {
isLeaf: true,
});
});
- this.apiDataItems=apiItems;
+ this.apiDataItems = apiItems;
this.generateGroupTreeData();
});
}
@@ -119,6 +133,9 @@ export class ApiComponent implements OnInit, OnDestroy {
this.id = Number(params.get('uuid'));
});
}
+ clickContentMenu(data) {
+ this.tabSerive.apiEvent$.next({ action: 'beforeChangeRouter', data: data });
+ }
/**
* Event emit from group tree component.
*
@@ -132,27 +149,16 @@ export class ApiComponent implements OnInit, OnDestroy {
case 'loadAllGroup':
this.buildGroupTreeData();
break;
- case 'testApi':
- this.testApi(event.node);
- break;
- case 'detailApi':
- this.detailApi(event.node);
- break;
- case 'editApi':
- this.editApi(event.node);
- break;
case 'copyApi':
this.copyApi(event.node);
break;
case 'deleteApi':
this.deleteApi(event.node);
break;
- case 'newApi':
- this.newApi(event.node);
- break;
- case 'newApiTest':
- this.newApiTest();
+ default: {
+ this.tabSerive.apiEvent$.next({ action: event.eventName, data: event.node });
break;
+ }
}
}
@@ -165,42 +171,29 @@ export class ApiComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.destroy$))
.subscribe((data: Message) => {
switch (data.type) {
- case 'apiAdd':
- case 'editApi':
+ case 'addApi':
+ case 'editApi':
+ {
+ this.tabSerive.apiEvent$.next({ action: `${data.type}Finish`,data:data.data});
+ this.buildGroupTreeData();
+ break;
+ }
case 'groupAdd':
case 'groupEdit':
case 'groupDelete':
this.buildGroupTreeData();
break;
case 'apiDelete':
- this.watchApiDelete(data.data);
+ let tmpApi = data.data;
+ this.tabSerive.apiEvent$.next({ action: 'removeApiDataTabs', data: [tmpApi.uuid] });
+ this.buildGroupTreeData();
break;
case 'apiBatchDelete':
- this.watchApiBatchDelete(data.data);
+ this.tabSerive.apiEvent$.next({ action: 'removeApiDataTabs', data: data.data.uuids });
break;
}
});
}
-
- /**
- * Delete api data tabs after item removed.
- *
- * @param data object
- */
- watchApiDelete(data) {
- this.apiTabComponent.removeApiDataTabs([data.uuid]);
- this.buildGroupTreeData();
- }
-
- /**
- * Delete api data tabs after items removed.
- *
- * @param data object
- */
- watchApiBatchDelete(data) {
- this.apiTabComponent.removeApiDataTabs(data.uuids);
- }
-
/**
* Generate group tree nodes.
*/
@@ -209,51 +202,6 @@ export class ApiComponent implements OnInit, OnDestroy {
this.treeNodes = [];
listToTree(this.treeItems, this.treeNodes, 0);
}
-
- /**
- * Create a new tab of add new api data.
- *
- * @param item GroupTreeItem
- */
- newApi(node?: NzTreeNode): void {
- console.log('newApi',node)
- this.apiTabComponent.appendTab('edit', node ? { groupID: node.key } : {});
- }
-
- /**
- * Create a new tab of add new api test.
- */
- newApiTest(): void {
- this.apiTabComponent.appendTab('test');
- }
-
- /**
- * Test api data.
- *
- * @param node NzTreeNode
- */
- testApi(node: NzTreeNode): void {
- this.apiTabComponent.appendTab('test', node.origin);
- }
-
- /**
- * View api data.
- *
- * @param node NzTreeNode
- */
- detailApi(node: NzTreeNode): void {
- this.apiTabComponent.appendTab('detail', node.origin);
- }
-
- /**
- * Edit api data.
- *
- * @param node NzTreeNode
- */
- editApi(node: NzTreeNode): void {
- this.apiTabComponent.appendTab('edit', node.origin);
- }
-
/**
* Copy api data.
*
@@ -264,13 +212,9 @@ export class ApiComponent implements OnInit, OnDestroy {
delete data.uuid;
delete data.createdAt;
data.name += ' Copy';
- this.apiDataService.create(data).subscribe((result: ApiData) => {
- this.buildGroupTreeData();
- this.apiTabComponent.appendTab('edit', {
- title: result.name,
- key: result.uuid,
- method: result.method,
- });
+ window.sessionStorage.setItem('apiDataWillbeSave', JSON.stringify(data));
+ this.tabSerive.apiEvent$.next({
+ action: 'newApi',
});
}
diff --git a/src/app/pages/api/demo.json b/src/app/pages/api/demo.json
deleted file mode 100644
index 8b137891..00000000
--- a/src/app/pages/api/demo.json
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/src/app/pages/api/detail/api-detail.component.html b/src/app/pages/api/detail/api-detail.component.html
index 6ed51b2a..81ff1eb9 100644
--- a/src/app/pages/api/detail/api-detail.component.html
+++ b/src/app/pages/api/detail/api-detail.component.html
@@ -17,7 +17,7 @@
Rest 参数
-
+
Body 请求参数
{{ CONST.BODY_TYPE[apiData.requestBodyType] }}
最外层结构为:{{ CONST.JSON_ROOT_TYPE[apiData.requestBodyJsonType] }}
diff --git a/src/app/pages/api/edit/api-edit.component.html b/src/app/pages/api/edit/api-edit.component.html
index 6c54fce1..106879ea 100644
--- a/src/app/pages/api/edit/api-edit.component.html
+++ b/src/app/pages/api/edit/api-edit.component.html
@@ -51,7 +51,9 @@
请求头部
- {{ apiData.requestHeaders | apiParamsNum }}
+ {{
+ apiData.requestHeaders | apiParamsNum
+ }}
@@ -59,7 +61,14 @@
请求体
- {{ apiData.requestBody | apiParamsNum }}
+
Query 参数
- {{ apiData.queryParams | apiParamsNum }}
+ {{
+ apiData.queryParams | apiParamsNum
+ }}
REST 参数
- {{ apiData.restParams | apiParamsNum }}
+ {{
+ apiData.restParams | apiParamsNum
+ }}
-
+
-
-
- {{ panel.nzActive ? '收缩' : '展开' }}
-
+
+
+ {{ panelRes.nzActive ? '收缩' : '展开' }}
+
返回头部
- {{ apiData.responseHeaders | apiParamsNum }}
+ {{
+ apiData.responseHeaders | apiParamsNum
+ }}
返回结果
- {{ apiData.responseBody | apiParamsNum }}
+
;
private destroy$: Subject = new Subject();
private changeGroupID$: Subject = new Subject();
@@ -41,10 +42,10 @@ export class ApiEditComponent implements OnInit, OnDestroy {
private storage: ApiDataService,
private route: ActivatedRoute,
private fb: FormBuilder,
- private router: Router,
private message: NzMessageService,
private messageService: MessageService,
- private groupService: GroupService
+ private groupService: GroupService,
+ private apiTab: ApiTabService
) {}
getApiGroup() {
this.groups = [];
@@ -115,22 +116,37 @@ export class ApiEditComponent implements OnInit, OnDestroy {
this.editApi(formData);
}
-
+ bindGetApiParamNum(params) {
+ return new ApiParamsNumPipe().transform(params);
+ }
ngOnInit(): void {
this.getApiGroup();
- this.resetApi();
+ this.initApi(Number(this.route.snapshot.queryParams.uuid));
+ this.watchTabChange();
+ this.watchGroupIDChange();
+ this.watchUri();
+ }
+
+ ngOnDestroy() {
+ this.destroy$.next();
+ this.destroy$.complete();
+ }
+ private initApi(id) {
+ this.resetForm();
this.initBasicForm();
- if (this.route.snapshot.queryParams.uuid) {
- //Edit
- this.watchQueryChange();
- } else {
- let testData = window.sessionStorage.getItem('testDataToAPI');
- if (testData) {
- //Add From Test
- Object.assign(
- this.apiData,
- JSON.parse(testData)
- );
+ //recovery from tab
+ if (this.apiTab.currentTab && this.apiTab.tabCache[this.apiTab.tabID]) {
+ let tabData = this.apiTab.tabCache[this.apiTab.tabID];
+ this.apiData = tabData.apiData;
+ return;
+ }
+ if (!id) {
+ let tmpApiData = window.sessionStorage.getItem('apiDataWillbeSave');
+ if (tmpApiData) {
+ //Add From Test|Copy Api
+ window.sessionStorage.removeItem('apiDataWillbeSave');
+ Object.assign(this.apiData, JSON.parse(tmpApiData));
+ this.validateForm.patchValue(this.apiData);
} else {
//Add directly
Object.assign(this.apiData, {
@@ -146,70 +162,56 @@ export class ApiEditComponent implements OnInit, OnDestroy {
responseBody: [],
});
}
+ } else {
+ this.getApi(id);
}
-
+ }
+ private watchTabChange() {
+ this.apiTab.tabChange$
+ .pipe(
+ pairwise(),
+ //actually change tab,not init tab
+ filter((data) => data[0].uuid !== data[1].uuid),
+ takeUntil(this.destroy$)
+ )
+ .subscribe(([nowTab, nextTab]) => {
+ this.apiTab.saveTabData$.next({
+ tab: nowTab,
+ data: {
+ apiData: this.apiData,
+ },
+ });
+ this.initApi(nextTab.key);
+ });
+ }
+ private watchGroupIDChange() {
this.changeGroupID$.pipe(debounceTime(500), take(1)).subscribe((id) => {
this.apiData.groupID = (this.apiData.groupID === 0 ? -1 : this.apiData.groupID).toString();
this.expandGroup();
});
- this.validateForm
- .get('uri')
- .valueChanges.pipe(debounceTime(500), takeUntil(this.destroy$))
- .subscribe((url) => {
- this.changeUri(url);
- });
- }
-
- ngOnDestroy() {
- this.destroy$.next();
- this.destroy$.complete();
- }
- private watchQueryChange() {
- this.api$ = this.route.queryParamMap.pipe(
- switchMap((params) => {
- const id = Number(params.get('uuid'));
- if (!id) {
- const groupID = params.get('groupID');
- if (groupID) {
- return of({
- groupID,
- });
- }
- return of();
- }
- return of({ id });
- }),
- takeUntil(this.destroy$)
- );
- this.api$.subscribe({
- next: (inArg: any = {}) => {
- if (inArg.id) {
- this.getApi(inArg.id);
- }
- if (inArg.groupID) {
- this.apiData.groupID = inArg.groupID;
- this.changeGroupID$.next(this.apiData.groupID);
- }
- },
- });
}
/**
* Generate Rest Param From Url
*/
- private changeUri(url) {
- const rests = getRest(url);
- rests.forEach((newRest) => {
- if (this.apiData.restParams.find((val: ApiEditRest) => val.name === newRest)) {
- return;
- }
- const restItem: ApiEditRest = {
- name: newRest,
- required: true,
- example: '',
- description: '',
- };
- this.apiData.restParams.splice(this.apiData.restParams.length - 1, 0, restItem);
- });
+ private watchUri() {
+ this.validateForm
+ .get('uri')
+ .valueChanges.pipe(debounceTime(500), takeUntil(this.destroy$))
+ .subscribe((url) => {
+ const rests = getRest(url);
+ rests.forEach((newRest) => {
+ if (this.apiData.restParams.find((val: ApiEditRest) => val.name === newRest)) {
+ return;
+ }
+ const restItem: ApiEditRest = {
+ name: newRest,
+ required: true,
+ example: '',
+ description: '',
+ };
+ this.apiData.restParams.splice(this.apiData.restParams.length - 1, 0, restItem);
+ });
+ });
}
/**
* Reset Group ID after group list load
@@ -250,25 +252,24 @@ export class ApiEditComponent implements OnInit, OnDestroy {
/**
* Init API data structure
*/
- private resetApi() {
+ private resetForm() {
this.apiData = {
name: '',
projectID: 1,
uri: '/',
- groupID: this.route.snapshot.queryParams.groupID||'-1',
+ groupID: this.route.snapshot.queryParams.groupID || '-1',
protocol: RequestProtocol.HTTP,
method: RequestMethod.POST,
};
}
private editApi(formData) {
- const busEvent = formData.uuid ? 'editApi' : 'apiAdd';
+ const busEvent = formData.uuid ? 'editApi' : 'addApi';
const title = busEvent === 'editApi' ? '编辑成功' : '新增成功';
this.storage[busEvent === 'editApi' ? 'update' : 'create'](formData, this.apiData.uuid).subscribe(
(result: ApiData) => {
this.message.success(title);
this.messageService.send({ type: busEvent, data: result });
- this.router.navigate(['/home/api/detail'], { queryParams: { uuid: result.uuid } });
}
);
}
diff --git a/src/app/pages/api/edit/api-edit.service.ts b/src/app/pages/api/edit/api-edit.service.ts
index a8a380d6..25585fb2 100644
--- a/src/app/pages/api/edit/api-edit.service.ts
+++ b/src/app/pages/api/edit/api-edit.service.ts
@@ -213,11 +213,12 @@ export class ApiEditService {
{
key: '插入',
operateName: 'insert',
- itemExpression: `ng-if="!($ctrl.mainObject.setting.munalHideOperateColumn&&$first)"`,
+ itemExpression: `ng-if="!($ctrl.mainObject.setting.munalHideOperateColumn&&$first)"`
},
{
key: '删除',
operateName: 'delete',
+ itemExpression: 'ng-if="!($ctrl.mainObject.setting.munalHideOperateColumn&&$first)"'
},
],
},
diff --git a/src/app/pages/api/group/tree/api-group-tree.component.html b/src/app/pages/api/group/tree/api-group-tree.component.html
index 49900c31..b1dc2554 100644
--- a/src/app/pages/api/group/tree/api-group-tree.component.html
+++ b/src/app/pages/api/group/tree/api-group-tree.component.html
@@ -22,7 +22,7 @@
@@ -48,7 +48,7 @@
- {{ node.title }}
+ {{ node.title }}