add fetch all merge logs

This commit is contained in:
pakintada@gmail.com 2023-09-21 16:12:28 +07:00
parent baa66609ee
commit 325020fd37
6 changed files with 205 additions and 70 deletions

View file

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { FetchLogService } from './fetch-log.service';
describe('FetchLogService', () => {
let service: FetchLogService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(FetchLogService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View file

@ -0,0 +1,78 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment.development';
@Injectable({
providedIn: 'root'
})
export class FetchLogService {
constructor(
private httpClient: HttpClient
) {}
public fetchLogsToDisplay(query: string, isDisplayOnly: boolean, requestJson: boolean, filename:string) : Map<string, string> | void{
let additionalParams:string = "?query=";
if(query != ""){
additionalParams += query
} else {
additionalParams = ""
}
let jsontarget;
if(requestJson){
this.httpClient.post(environment.api+"/dllog"+additionalParams, {
htmlfile: isDisplayOnly,
requestJson: requestJson,
filename: filename
}, {
responseType: 'json',
withCredentials: true
}).subscribe({
next: (value: any) => {
jsontarget = value;
},
error: (err: any) => {
console.error('Error fetch json: ',err);
}
});
return jsontarget;
} else {
this.httpClient.post(environment.api+"/dllog"+additionalParams, {
htmlfile: isDisplayOnly,
requestJson: requestJson,
filename: filename
},{
responseType: 'blob',
withCredentials: true,
}).subscribe(
{
next: (value: BlobPart) => {
const blob = new Blob([value], { type: 'application/octet-stream' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'logfile.log';
a.innerText = "Click here to download as `.log` file";
if(isDisplayOnly){
blob.text().then(v => document.getElementById("log-disp-texts")!.innerHTML = v);
} else {
while(document.getElementById("log-dl")?.firstChild){
document.getElementById("log-dl")?.removeChild(document.getElementById("log-dl")!.firstChild!);
}
document.getElementById("log-dl")?.appendChild(a);
document.getElementById("log-dl")!.className = "bg-yellow-500 rounded p-2 sticky top-0";
}
},
error: (err: any) => {
console.error('Error downloading log file: ',err);
}
}
)
}
}
}