Skip to content

Commit

Permalink
feat: done env
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfuboy committed Jun 27, 2022
1 parent df8ef87 commit f9c5e21
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/workbench/browser/src/app/pages/api/api.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@
<div class="inner-content">
<div class="tabs-bar f_row">
<eo-api-tab class="fg1"></eo-api-tab>
<!-- <div class="env">
<eo-env></eo-env>
</div> -->
<nz-select
[(ngModel)]="envUuid"
[(nzOpen)]="isOpen"
(nzOpenChange)="handleEnvSelectStatus($event)"
nzAllowClear
nzPlaceHolder="Environment"
>
<nz-option *ngFor="let item of envList" [nzValue]="item.uuid" [nzLabel]="item.name"></nz-option>
</nz-select>
</div>
<div class="content_container {{ this.id ? 'has_tab_page' : '' }}">
<nz-tabset class="inside_page_tab" [nzAnimated]="false" *ngIf="this.id" nzLinkRouter>
Expand Down
4 changes: 4 additions & 0 deletions src/workbench/browser/src/app/pages/api/api.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ nz-content {
background-color: var(--MAIN_BG);
}

nz-select {
width: 120px;
}

nz-sider {
width: 250px;
background-color: #fff;
Expand Down
57 changes: 55 additions & 2 deletions src/workbench/browser/src/app/pages/api/api.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { StorageRes, StorageResStatus } from '../../shared/services/storage/index.model';
import { Subject, takeUntil } from 'rxjs';
import { Store } from '@ngxs/store';
import { Message, MessageService } from '../../shared/services/message';
import { ApiService } from './api.service';
import { StorageService } from '../../shared/services/storage';
import { Change } from '../../shared/store/env.state';
import { RemoteService } from 'eo/workbench/browser/src/app/shared/services/remote/remote.service';

@Component({
Expand Down Expand Up @@ -31,16 +34,34 @@ export class ApiComponent implements OnInit, OnDestroy {
title: '测试',
},
];
isOpen = false;
envInfo: any = {};
envList: Array<any> = [];
activeUuid: number | string = 0;
private destroy$: Subject<void> = new Subject<void>();

constructor(
private route: ActivatedRoute,
private apiService: ApiService,
private messageService: MessageService,
private storage: StorageService,
private remoteService: RemoteService
private remoteService: RemoteService,
private store: Store
) {}

get envUuid(): number {
return Number(localStorage.getItem('env:selected')) || 0;
}
set envUuid(value) {
this.activeUuid = value;
if (value !== null) {
localStorage.setItem('env:selected', value == null ? '' : value.toString());
} else {
localStorage.removeItem('env:selected');
}
this.changeStoreEnv(value);
}

ngOnInit(): void {
this.watchChangeRouter();
this.watchApiAction();
Expand All @@ -51,6 +72,11 @@ export class ApiComponent implements OnInit, OnDestroy {
title: 'Mock',
});
}
this.envUuid = Number(localStorage.getItem('env:selected'));
// * load All env
this.getAllEnv().then((result: any[]) => {
this.envList = result || [];
});
}
ngOnDestroy() {
this.destroy$.next();
Expand Down Expand Up @@ -98,6 +124,33 @@ export class ApiComponent implements OnInit, OnDestroy {
});
}
clickContentMenu(data) {
this.messageService.send({ type: 'beforeChangeRouter', data: data });
this.messageService.send({ type: 'beforeChangeRouter', data });
}

getAllEnv(uuid?: number) {
const projectID = 1;
return new Promise((resolve) => {
this.storage.run('environmentLoadAllByProjectID', [projectID], async (result: StorageRes) => {
if (result.status === StorageResStatus.success) {
return resolve(result.data || []);
}
return resolve([]);
});
});
}

private changeStoreEnv(uuid) {
if (uuid == null) {
this.store.dispatch(new Change(null));
return;
}
this.storage.run('environmentLoadAllByProjectID', [1], (result: StorageRes) => {
if (result.status === StorageResStatus.success) {
const data = result.data.find((val) => val.uuid === Number(uuid));
this.store.dispatch(new Change(data));
}
});
}

handleEnvSelectStatus(event: boolean) {}
}
2 changes: 2 additions & 0 deletions src/workbench/browser/src/app/pages/api/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { NzInputModule } from 'ng-zorro-antd/input';
import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
import { NzDividerModule } from 'ng-zorro-antd/divider';
import { NzCardModule } from 'ng-zorro-antd/card';
import { NzSelectModule } from 'ng-zorro-antd/select';
import { NzModalModule } from 'ng-zorro-antd/modal';
import { NzPopconfirmModule } from 'ng-zorro-antd/popconfirm';

Expand Down Expand Up @@ -81,6 +82,7 @@ const COMPONENTS = [
EnvModule,
NzCardModule,
NzModalModule,
NzSelectModule,
NzPopconfirmModule,
],
declarations: [...COMPONENTS],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<nz-tabset [(nzSelectedIndex)]="selectedIndex" nzType="editable-card" nzHideAdd="true" (nzClose)="closeTab($event)"
(nzSelectChange)="pickTab()" [nzTabBarExtraContent]="extraTemplate">
<nz-tabset
[(nzSelectedIndex)]="selectedIndex"
nzType="editable-card"
nzHideAdd="true"
(nzClose)="closeTab($event)"
(nzSelectChange)="pickTab()"
[nzTabBarExtraContent]="extraTemplate"
>
<nz-tab *ngFor="let tab of tabSerive.tabs; let i = index" nzClosable [nzTitle]="titleTemplate">
<ng-template #titleTemplate>
<span class="mr5 method_text_{{ tab.method }}" *ngIf="tab.method">{{ tab.method }}</span>
Expand Down

0 comments on commit f9c5e21

Please sign in to comment.