Skip to content

Commit

Permalink
fix: formdata select file error
Browse files Browse the repository at this point in the history
  • Loading branch information
scarqin committed Aug 10, 2022
1 parent 91dabd3 commit 123ab48
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 31 deletions.
16 changes: 13 additions & 3 deletions src/workbench/browser/src/app/pages/api/api-tab.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export class ApiTabService {
return;
}
this.bindChildComponentChangeEvent();
console.log('updatechildview');
//?Why should use getCurrentTab()?
//Because maybe current tab has't finish init
const currentTab = this.apiTabComponent.getTabByUrl(url);
Expand Down Expand Up @@ -175,7 +174,7 @@ export class ApiTabService {
replaceTab.isFixed = true;
}
//Has tested set fixed
if(currentTab.pathname === '/home/api/test'&&model.testStartTime!==undefined){
if (currentTab.pathname === '/home/api/test' && model.testStartTime !== undefined) {
replaceTab.isFixed = true;
}

Expand All @@ -199,7 +198,7 @@ export class ApiTabService {
*
* @param inData.url get component fit tab data
*/
afterContentChanged(inData: { when: 'init' | 'editing' |'saved'; url: string; model: any }) {
afterContentChanged(inData: { when: 'init' | 'editing' | 'saved'; url: string; model: any }) {
if (!this.apiTabComponent) {
console.warn(`EO_WARNING:apiTabComponent hasn't init yet!`);
return;
Expand All @@ -211,4 +210,15 @@ export class ApiTabService {
}
this.updateTab(currentTab, inData);
}
handleDataBeforeCache(tabsByID) {
Object.values(tabsByID).forEach((val: TabItem) => {
if (val.pathname === '/home/api/test'&&val.content?.test?.testResult) {
val.content.test.testResult = {
request: {},
response: {},
};
}
});
return tabsByID;
}
}
2 changes: 1 addition & 1 deletion src/workbench/browser/src/app/pages/api/api.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<nz-content>
<div class="inner-content">
<div class="flex items-center tabs-bar">
<eo-api-tab class="fg1" [list]="apiTab.BASIC_TBAS" (beforeClose)="apiTab.beforeTabClose($event)" #apiTabComponent></eo-api-tab>
<eo-api-tab class="fg1" [list]="apiTab.BASIC_TBAS" [handleDataBeforeCache]="apiTab.handleDataBeforeCache" (beforeClose)="apiTab.beforeTabClose($event)" #apiTabComponent></eo-api-tab>
<div class="flex items-center fix-mt">
<nz-select
[(ngModel)]="envUuid"
Expand Down
10 changes: 9 additions & 1 deletion src/workbench/browser/src/app/pages/api/api.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { Injectable } from '@angular/core';
import { ApiData, StorageRes, StorageResStatus } from '../../shared/services/storage/index.model';
import { EoMessageService } from 'eo/workbench/browser/src/app/eoui/message/eo-message.service';
import { MessageService } from '../../shared/services/message';
import { StorageService } from '../../shared/services/storage';
import { Router } from '@angular/router';
@Injectable()
export class ApiService {
constructor(private messageService: MessageService, private router: Router, private storage: StorageService) {}
constructor(
private messageService: MessageService,
private message: EoMessageService,
private router: Router,
private storage: StorageService
) {}
get(uuid): Promise<ApiData> {
return new Promise((resolve) => {
this.storage.run('apiDataLoad', [uuid], (result: StorageRes) => {
if (result.status === StorageResStatus.success) {
resolve(result.data);
} else {
this.message.error(`Can't find this api`);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class ApiTabOperateService {
private message: EoMessageService,
private modal: ModalService
) {
this.watchPageLeave();
}
//Init tab info
//Maybe from tab cache info or router url
Expand Down Expand Up @@ -223,8 +222,8 @@ export class ApiTabOperateService {

//same tab content,selected it
if (existTab) {
this.selectedIndex = sameContentIndex;
this.updateChildView();
this.selectedIndex = sameContentIndex;
this.updateChildView();
return;
}
//If has same content tab (same {params.uuid}),replace it and merge data
Expand Down Expand Up @@ -315,10 +314,5 @@ export class ApiTabOperateService {
private updateChildView() {
this.messageService.send({ type: 'tabContentInit', data: {} });
}
private watchPageLeave() {
const that = this;
window.addEventListener('beforeunload', function(e) {
that.tabStorage.setPersistenceStorage(that.selectedIndex);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ export class ApiTabStorageService {
* @param tab
* @param data
*/
setPersistenceStorage(selectedIndex) {
const tabsByID = Object.fromEntries(this.tabsByID);
setPersistenceStorage(selectedIndex, opts) {
let tabsByID = Object.fromEntries(this.tabsByID);
Object.values(tabsByID).forEach((val) => {
if (!val.hasChanged) {
['baseContent', 'content'].forEach((keyName) => {
val[keyName]=null;
val[keyName] = null;
});
}
});
if (opts.handleDataBeforeCache) {
tabsByID = opts.handleDataBeforeCache(tabsByID);
}
window.localStorage.setItem(
this.cacheName,
JSON.stringify({
Expand Down
24 changes: 17 additions & 7 deletions src/workbench/browser/src/app/pages/api/tab/api-tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { KeyValue } from '@angular/common';
})
export class ApiTabComponent implements OnInit, OnDestroy {
@Input() list;
@Input() handleDataBeforeCache;
@Output() beforeClose = new EventEmitter<boolean>();
MAX_TAB_LIMIT = 15;
routerSubscribe: Subscription;
Expand All @@ -27,6 +28,7 @@ export class ApiTabComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.tabOperate.init(this.list);
this.watchRouterChange();
this.watchPageLeave();
}
newTab() {
if (this.tabStorage.tabOrder.length >= this.MAX_TAB_LIMIT) {
Expand Down Expand Up @@ -93,12 +95,12 @@ export class ApiTabComponent implements OnInit, OnDestroy {
}
tabs.push({
uuid: tab.uuid,
type:tab.type,
type: tab.type,
title: tab.title,
pathname: tab.pathname,
params: tab.params,
isFixed:tab.isFixed,
hasChanged: tab.hasChanged
isFixed: tab.isFixed,
hasChanged: tab.hasChanged,
});
});
return tabs;
Expand All @@ -117,10 +119,10 @@ export class ApiTabComponent implements OnInit, OnDestroy {
getTabByUrl(url: string): TabItem | null {
const tabItem = this.tabOperate.getBaiscTabFromUrl(url);
const existTabIndex = this.tabOperate.getSameContentTabIndex(tabItem);
if (existTabIndex === -1) {
return null;
if (existTabIndex !== -1) {
return this.tabStorage.tabsByID.get(this.tabStorage.tabOrder[existTabIndex]);
}
return this.tabStorage.tabsByID.get(this.tabStorage.tabOrder[existTabIndex]);
return this.tabStorage.tabsByID.get(tabItem.uuid)||null;
}
getCurrentTab() {
return this.tabOperate.getCurrentTab();
Expand Down Expand Up @@ -150,7 +152,9 @@ export class ApiTabComponent implements OnInit, OnDestroy {
* Cache tab header/tabs content for restore when page close or component destroy
*/
cacheData() {
this.tabStorage.setPersistenceStorage(this.tabOperate.selectedIndex);
this.tabStorage.setPersistenceStorage(this.tabOperate.selectedIndex, {
handleDataBeforeCache: this.handleDataBeforeCache,
});
}
/**
* Tab Close Operate
Expand All @@ -171,4 +175,10 @@ export class ApiTabComponent implements OnInit, OnDestroy {
this.routerSubscribe?.unsubscribe();
this.cacheData();
}
private watchPageLeave() {
const that = this;
window.addEventListener('beforeunload', function(e) {
that.cacheData();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ export class ApiTestUtilService {
* @returns apiData
*/
formatEditingApiData(formData): ApiTestData {
const result = formData;
const result = structuredClone(formData);
['requestBody', 'queryParams', 'restParams', 'requestHeaders'].forEach((tableName) => {
if (whatType(result[tableName]) !== 'array') {
return;
}
result[tableName] = (result[tableName] || []).filter((val) => val.name || val.value);
});
return formData;
return result;
}
/**
* Transfer test data/test history to api data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export class ApiTestBodyComponent implements OnInit, OnChanges, AfterViewInit, O
this.modelChange.emit(this.model);
},
importFile: (inputArg) => {
console.log('importFile',inputArg);
if (inputArg.file.length === 0) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<span i18n>Unable to preview non-text type data, you can</span>
<button class="eo_theme_btn_default mlr5" type="button" (click)="downloadResponseText()"
i18n="@@downloadResponse">
download back result
download response
</button>
<span i18n>and open it with other programs.</span>
</div>
Expand All @@ -34,15 +34,15 @@
</div>
<nz-dropdown-menu #menu="nzDropdownMenu">
<ul nz-menu>
<li nz-menu-item i18n="@@downloadResponse" (click)="downloadResponseText()">download back result</li>
<li nz-menu-item i18n="@@downloadResponse" (click)="downloadResponseText()">download response</li>
</ul>
</nz-dropdown-menu>
</div>
<div class="text-center" *ngSwitchCase="'longText'">
<span i18n>The response result exceeds the previewable size, you can</span>
<button i18n="@@downloadResponse" class="eo_theme_btn_default mlr5" type="button"
(click)="downloadResponseText()">
download back result
download response
</button>
<!-- or
<button class="eo_theme_btn_default" type="button" (click)="newTabResponseText()">在新标签页中显示返回结果</button>
Expand Down
1 change: 1 addition & 0 deletions src/workbench/browser/src/ng1/component/list-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ function listBlockController($rootScope, $element, $scope) {
}
};
$scope.importFile = function (inputArg, inputEvent) {
console.log('importFile')
inputArg.$index = this.$parent.$index;
inputArg.item = vm.list[inputArg.$index];
vm.mainObject.baseFun.importFile(inputArg);
Expand Down
2 changes: 1 addition & 1 deletion src/workbench/browser/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ body {
padding: 0;

height: 100%;
font-family: Arial, Helvetica, sans-serif;
font-family: Arial, Helvetica, sans-serif,"Source Sans Pro", "Helvetica Neue", Arial, sans-serif;
}
:root {
--NAVBAR_HEIGHT: 50px;
Expand Down
2 changes: 1 addition & 1 deletion src/workbench/browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"emitDecoratorMetadata": false,
"experimentalDecorators": true,
"baseUrl": "../../../",
"paths": {
Expand Down

0 comments on commit 123ab48

Please sign in to comment.