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';
|
2023-09-18 17:10:18 +07:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-changelog',
|
|
|
|
|
standalone: true,
|
|
|
|
|
templateUrl: './changelog.component.html',
|
2023-09-19 15:21:08 +07:00
|
|
|
styleUrls: ['./changelog.component.css'],
|
2023-10-03 15:06:50 +07:00
|
|
|
imports: [CommonModule, MergeComponent],
|
2023-09-18 17:10:18 +07:00
|
|
|
})
|
|
|
|
|
export class ChangelogComponent {
|
2023-09-21 16:12:28 +07:00
|
|
|
public displayableLogs: string[] = [];
|
2023-09-22 16:54:52 +07:00
|
|
|
public displayableMergeJson: string[] = [];
|
2023-10-03 15:06:50 +07:00
|
|
|
showLogModal: boolean = false;
|
|
|
|
|
showMergeModal: boolean = false;
|
2023-09-21 16:12:28 +07:00
|
|
|
|
2023-10-04 11:47:49 +07:00
|
|
|
constructor(private httpClient: HttpClient) {
|
2023-09-21 16:12:28 +07:00
|
|
|
this.fetchLoglist();
|
2023-10-03 15:06:50 +07:00
|
|
|
// this.translateLogDirToString();
|
2023-09-21 16:12:28 +07:00
|
|
|
}
|
|
|
|
|
|
2023-10-03 15:06:50 +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")
|
2023-10-03 15:06:50 +07:00
|
|
|
let dirlist: any[] = [];
|
2023-09-22 16:54:52 +07:00
|
|
|
|
2023-10-04 11:47:49 +07:00
|
|
|
// this.wss.connect(environment.wsapi + '/listFileInDir');
|
|
|
|
|
// this.wss.send({
|
|
|
|
|
// topic: 'changelog',
|
|
|
|
|
// });
|
2023-09-22 16:54:52 +07:00
|
|
|
|
2023-10-04 11:47:49 +07:00
|
|
|
// let response = this.wss.data;
|
|
|
|
|
// console.log(response);
|
2023-09-25 16:17:21 +07:00
|
|
|
|
2023-10-04 11:47:49 +07:00
|
|
|
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);
|
2023-09-25 16:17:21 +07:00
|
|
|
|
2023-10-04 11:47:49 +07:00
|
|
|
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-25 16:17:21 +07:00
|
|
|
|
2023-09-21 16:12:28 +07:00
|
|
|
return dirlist;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-03 15:06:50 +07:00
|
|
|
public translateLogDirToString() {
|
|
|
|
|
console.log('LogDirList: ', this.displayableLogs);
|
|
|
|
|
let dirSelector = document.getElementById('log-dir-list');
|
2023-09-21 16:12:28 +07:00
|
|
|
// 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[])
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-03 15:06:50 +07:00
|
|
|
refreshLogList() {
|
2023-09-21 16:12:28 +07:00
|
|
|
this.fetchLoglist();
|
|
|
|
|
this.translateLogDirToString();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-03 15:06:50 +07:00
|
|
|
viewLog(name: string) {
|
2023-09-22 09:54:07 +07:00
|
|
|
let cli = new FetchLogService(this.httpClient);
|
2023-10-04 16:19:59 +07:00
|
|
|
// this.showLogModal = !this.showLogModal;
|
2023-10-03 15:06:50 +07:00
|
|
|
cli.fetchLogsToDisplay('changelog', true, false, name);
|
|
|
|
|
cli.fetchLogsToDisplay('changelog', false, false, name);
|
2023-09-22 09:54:07 +07:00
|
|
|
}
|
|
|
|
|
|
2023-10-03 15:06:50 +07:00
|
|
|
viewJson(name: string) {
|
2023-09-22 16:54:52 +07:00
|
|
|
let cli = new FetchLogService(this.httpClient);
|
|
|
|
|
this.showMergeModal = !this.showMergeModal;
|
2023-10-03 15:06:50 +07:00
|
|
|
cli.fetchLogsToDisplay('merge', false, true, name);
|
2023-09-22 16:54:52 +07:00
|
|
|
// cli.fetchLogsToDisplay("", false, false, name);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-03 15:06:50 +07:00
|
|
|
toggleLogModal(target: string) {
|
|
|
|
|
if (target == 'merge') {
|
2023-09-22 16:54:52 +07:00
|
|
|
this.showMergeModal = !this.showMergeModal;
|
|
|
|
|
} else {
|
|
|
|
|
this.showLogModal = !this.showLogModal;
|
|
|
|
|
}
|
2023-09-19 15:21:08 +07:00
|
|
|
}
|
2023-09-18 17:10:18 +07:00
|
|
|
}
|