Taobin-Recipe-Manager/client/src/app/features/changelog/changelog.component.ts

126 lines
3.6 KiB
TypeScript
Raw Normal View History

2023-09-25 16:17:21 +07:00
import { Component, OnInit } from '@angular/core';
2023-09-19 15:21:08 +07:00
import { MergeComponent } from '../merge/merge.component';
2023-09-21 16:12:28 +07:00
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment.development';
import { CommonModule } from '@angular/common';
import { FetchLogService } from 'src/app/shared/services/fetch-log.service';
2023-09-25 16:17:21 +07:00
import { WebsocketService } from 'src/app/shared/services/websocket.service';
@Component({
selector: 'app-changelog',
standalone: true,
templateUrl: './changelog.component.html',
2023-09-19 15:21:08 +07:00
styleUrls: ['./changelog.component.css'],
2023-09-21 16:12:28 +07:00
imports: [CommonModule,MergeComponent]
})
export class ChangelogComponent {
2023-09-21 16:12:28 +07:00
public displayableLogs: string[] = [];
public displayableMergeJson: string[] = [];
2023-09-22 09:54:07 +07:00
showLogModal:boolean = false;
showMergeModal:boolean = false;
2023-09-21 16:12:28 +07:00
constructor(
private httpClient: HttpClient,
2023-09-25 16:17:21 +07:00
private wss: WebsocketService
2023-09-21 16:12:28 +07:00
){
this.fetchLoglist();
2023-09-25 16:17:21 +07:00
// this.translateLogDirToString();
2023-09-21 16:12:28 +07:00
}
2023-09-25 16:17:21 +07:00
2023-09-21 16:12:28 +07:00
public fetchLoglist(): string[]{
2023-09-19 15:21:08 +07:00
// TODO: Fetch changelog.html
2023-09-21 16:12:28 +07:00
// fetch("/changelog")
let dirlist: any[] = []
2023-09-25 16:17:21 +07:00
this.wss.connect(environment.wsapi+"/listFileInDir");
this.wss.send({
"topic": "changelog",
})
2023-09-25 16:17:21 +07:00
let response = this.wss.data;
console.log(response);
// this.httpClient.get(environment.api+"/listFileInDir/changelog", {
// withCredentials: true
// }).subscribe({
// next: (value) => {
// console.log(value)
// if(typeof value === "object" && value !== null){
// if("dirs" in value){
// console.log("dirs", value)
// // dirlist.push(...(value as {dirs: unknown[]})["dirs"]);
// this.displayableLogs = value.dirs as any[];
// }
// }
// },
// error: (err) => {
// console.error('Error fetch json: ',err);
// }
// })
// // console.log(dirlist);
// this.httpClient.get(environment.api+"/listFileInDir/merge", {
// withCredentials: true
// }).subscribe({
// next: (value) => {
// console.log(value)
// if(typeof value === "object" && value !== null){
// if("dirs" in value){
// console.log("dirs", value)
// // dirlist.push(...(value as {dirs: unknown[]})["dirs"]);
// this.displayableMergeJson = value.dirs as any[];
// }
// }
// },
// error: (err) => {
// console.error('Error fetch json: ',err);
// }
// })
2023-09-21 16:12:28 +07:00
return dirlist;
}
public translateLogDirToString(){
console.log("LogDirList: ", this.displayableLogs)
let dirSelector = document.getElementById("log-dir-list")
// for(let dir of this.displayableLogs){
// console.log(dir)
// const p = document.createElement('p');
// p.innerText = dir;
// dirSelector!.appendChild(p);
// dirSelector?.replaceChild(p, dirSelector.children[])
// }
}
refreshLogList(){
this.fetchLoglist();
this.translateLogDirToString();
}
viewLog(name:string){
2023-09-22 09:54:07 +07:00
let cli = new FetchLogService(this.httpClient);
this.showLogModal = !this.showLogModal;
cli.fetchLogsToDisplay("changelog", true, false, name);
cli.fetchLogsToDisplay("changelog", false, false, name);
2023-09-22 09:54:07 +07:00
}
viewJson(name:string){
let cli = new FetchLogService(this.httpClient);
this.showMergeModal = !this.showMergeModal;
cli.fetchLogsToDisplay("merge", false, true, name);
// cli.fetchLogsToDisplay("", false, false, name);
}
toggleLogModal(target:string){
if(target == "merge"){
this.showMergeModal = !this.showMergeModal;
} else {
this.showLogModal = !this.showLogModal;
}
2023-09-19 15:21:08 +07:00
}
}