Skip to content

Commit

Permalink
feat: api history list support remote server
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Aug 15, 2022
1 parent 649ae42 commit e2ac152
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { StorageService } from 'eo/workbench/browser/src/app/shared/services/storage';
import { StorageRes, StorageResStatus } from 'eo/workbench/browser/src/app/shared/services/storage/index.model';
import { IndexedDBStorage } from '../../../../../../../workbench/browser/src/app/shared/services/storage/IndexedDB/lib/index';
import { MessageService } from '../../../shared/services/message';

Expand All @@ -11,24 +13,31 @@ import { MessageService } from '../../../shared/services/message';
export class HistoryComponent implements OnInit {
historyList = [];
colorHash = new Map().set('get', 'green').set('post', 'blue').set('delete', 'red').set('put', 'pink');
constructor(public storageInstance: IndexedDBStorage, private router: Router, private message: MessageService) {}
ngOnInit() {
const observer = this.loadAllTest();
observer.subscribe((result: any) => {
// console.log(result.data);
this.historyList = result.data.reverse();
});
this.message.get().subscribe(({ type }) => {
constructor(private storage: StorageService, private router: Router, private message: MessageService) {}
async ngOnInit() {
const result = await this.loadAllTest();
this.historyList = result.reverse();
console.log('this.historyList', this.historyList);
this.message.get().subscribe(async ({ type }) => {
if (type === 'updateHistory') {
this.loadAllTest().subscribe((result: any) => {
this.historyList = result.data.reverse();
});
const data = await this.loadAllTest();
this.historyList = data.reverse();
}
});
}

loadAllTest() {
return this.storageInstance.apiTestHistoryLoadAllByProjectID(1);
// return this.storageInstance.apiTestHistoryLoadAllByProjectID(1);
return new Promise<any[]>((resolve) => {
this.storage.run('apiTestHistoryLoadAllByProjectID', [1], (result: StorageRes) => {
if (result.status === StorageResStatus.success) {
resolve(result.data);
} else {
console.error(result.data);
resolve(result.data);
}
});
});
}

methodColor(type) {
Expand All @@ -38,15 +47,22 @@ export class HistoryComponent implements OnInit {
gotoTestHistory(data) {
this.router.navigate(['home/api/test'], {
queryParams: {
uuid:`history_${data.uuid}`
uuid: `history_${data.uuid}`,
},
});
}

clearAllHistory() {
const uuids = this.historyList.map((it) => it.uuid);
this.historyList = [];
this.storageInstance.apiTestHistoryBulkRemove(uuids);
// this.storageInstance.apiTestHistoryBulkRemove(uuids);
this.storage.run('apiTestHistoryBulkRemove', [uuids], (result: StorageRes) => {
// if (result.status === StorageResStatus.success) {
// resolve(result.data);
// } else {
// console.error(result.data);
// }
});
}
cancel() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,9 @@ export class IndexedDBStorage extends Dexie implements StorageInterface {
*
* @param uuid
*/
apiTestHistoryLoad(uuid: number | string): Observable<object> {
apiTestHistoryLoad = (uuid: number | string): Observable<object> => {
return this.load(this.apiTestHistory, uuid);
}
};

/**
* Load all apiTestHistory items by apiDataID.
Expand Down Expand Up @@ -691,7 +691,7 @@ export class IndexedDBStorage extends Dexie implements StorageInterface {
return new Observable((obs) => {
const fun = async () => {
const result = {};
const tables = ['environment', 'group', 'project', 'apiData'];
const tables = ['environment', 'group', 'project', 'apiData'];
for (let i = 0; i < tables.length; i++) {
const tableName = tables[i];
if (tableName === 'project') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ export class HttpStorage implements StorageInterface {
apiTestHistoryBulkRemove(uuids: Array<number | string>) {
return this.http.delete(`/api_test_history?uuids=[${uuids}]`) as Observable<object>;
}
apiTestHistoryLoad: (uuid: number | string) => Observable<object>;
apiTestHistoryLoad(uuid: number | string) {
return this.http.get(`/api_test_history/${uuid}`) as Observable<object>;
}
apiTestHistoryBulkLoad: (uuids: Array<number | string>) => Observable<object>;
apiTestHistoryLoadAllByProjectID: (projectID: number | string) => Observable<object>;
apiTestHistoryLoadAllByProjectID(projectID: number | string) {
return this.http.get(`/api_test_history?projectID=${projectID}`) as Observable<object>;
}
apiTestHistoryLoadAllByApiDataID(apiDataID: number | string) {
return this.http.get(`/api_test_history?apiDataID=${apiDataID}`) as Observable<object>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class StorageService {
data: undefined,
callback,
};
console.log('this.instance', this.instance, action);
if (!this.instance[action]) {
throw Error(`Lack request API: ${action}`);
}
Expand Down

0 comments on commit e2ac152

Please sign in to comment.