Updated logs viewer component

- now by default last 50 lines are showed
- added copy to clipboard button
- added loading spinner to indicate to users when the logs are loading

app.get('/api/logs') is now app.post to allow for additional parameters (such as lines to retrieve)
This commit is contained in:
Isaac Grynsztein
2020-07-03 03:46:58 -04:00
parent 3732d13562
commit a9f197e46d
11 changed files with 45 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, AfterViewInit } from '@angular/core';
import { PostsService } from '../../posts.services';
@Component({
@@ -9,7 +9,8 @@ import { PostsService } from '../../posts.services';
export class LogsViewerComponent implements OnInit {
logs: string = null;
requested_lines = 50;
logs_loading = false;
constructor(private postsService: PostsService) { }
ngOnInit(): void {
@@ -17,16 +18,23 @@ export class LogsViewerComponent implements OnInit {
}
getLogs() {
this.postsService.getLogs().subscribe(res => {
if (!this.logs) { this.logs_loading = true; } // only show loading spinner at the first load
this.postsService.getLogs(this.requested_lines !== 0 ? this.requested_lines : null).subscribe(res => {
this.logs_loading = false;
if (res['logs']) {
this.logs = res['logs'];
} else {
this.postsService.openSnackBar('Failed to retrieve logs!');
}
}, err => {
this.logs_loading = false;
console.error(err);
this.postsService.openSnackBar('Failed to retrieve logs!');
});
}
copiedLogsToClipboard() {
this.postsService.openSnackBar('Logs copied to clipboard!');
}
}