Skip to content

Commit dcc919d

Browse files
author
youncccat
committed
[Feat] add log
1 parent d2e93ee commit dcc919d

File tree

7 files changed

+64
-12
lines changed

7 files changed

+64
-12
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@angular/platform-browser": "~8.2.14",
2222
"@angular/platform-browser-dynamic": "~8.2.14",
2323
"@angular/router": "~8.2.14",
24+
"ansi_up": "^4.0.4",
2425
"rxjs": "~6.4.0",
2526
"tslib": "^1.10.0",
2627
"zone.js": "~0.9.1"

src/app/panel/panel.component.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<mat-card-subtitle>
6060
logs
6161
</mat-card-subtitle>
62-
<mat-card-content>
62+
<mat-card-content class="logger-content">
6363
<mat-button-toggle-group>
6464
<mat-button-toggle
6565
*ngFor="let type of selectedProject.logType"
@@ -70,6 +70,9 @@
7070
{{ type }}
7171
</mat-button-toggle>
7272
</mat-button-toggle-group>
73+
<div class="dispatcher-logs">
74+
<div [innerHTML]="dispatcherLogs"></div>
75+
</div>
7376
</mat-card-content>
7477
</mat-card>
7578
<mat-card class="notify-card">

src/app/panel/panel.component.scss

+21
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ $full-height: calc(100% - 150px);
6262

6363
width: 500px;
6464
height: $full-height;
65+
66+
.logger-content {
67+
height: calc(100% - 80px);
68+
}
6569
}
6670

6771
.notify-card {
@@ -108,6 +112,10 @@ $full-height: calc(100% - 150px);
108112
.task-content {
109113
@include scroll-content;
110114

115+
&::-webkit-scrollbar {
116+
width: 0 !important;
117+
}
118+
111119
.task-item-card {
112120
@include base-card;
113121
@extend .selected;
@@ -119,3 +127,16 @@ $full-height: calc(100% - 150px);
119127
* {
120128
font-weight: 200;
121129
}
130+
131+
.dispatcher-logs {
132+
display: flex;
133+
flex-direction: column-reverse;
134+
height: calc(100% - 60px);
135+
overflow-y: scroll;
136+
margin-top: 10px;
137+
white-space: pre-line;
138+
139+
&::-webkit-scrollbar {
140+
width: 0 !important;
141+
}
142+
}

src/app/panel/panel.component.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, OnInit } from "@angular/core";
2-
import { WebSocketService, HttpInfo } from "src/services";
2+
import { WebSocketService, HttpInfo } from "../../services";
33
import { HttpClient } from "@angular/common/http";
4+
import AnsiUp from "ansi_up";
5+
import { DomSanitizer } from "@angular/platform-browser";
46

57
type LogType = "docker" | "dispatcher";
68

@@ -38,7 +40,8 @@ export class PanelComponent implements OnInit {
3840
constructor(
3941
private websocketService: WebSocketService,
4042
private httpClient: HttpClient,
41-
private httpInfo: HttpInfo
43+
private httpInfo: HttpInfo,
44+
private sanitized: DomSanitizer
4245
) {}
4346

4447
ngOnInit() {}
@@ -66,4 +69,14 @@ export class PanelComponent implements OnInit {
6669
get tasks() {
6770
return this.websocketService.tasks;
6871
}
72+
73+
get dispatcherLogs() {
74+
console.info(
75+
new AnsiUp().ansi_to_html(this.websocketService.dispatcherLogs.join("\n"))
76+
);
77+
78+
return this.sanitized.bypassSecurityTrustHtml(
79+
new AnsiUp().ansi_to_html(this.websocketService.dispatcherLogs.join("\n"))
80+
);
81+
}
6982
}

src/interceptors/auth-interceptor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export class AuthInterceptor implements HttpInterceptor {
1212
req: HttpRequest<any>,
1313
next: HttpHandler
1414
): Observable<HttpEvent<any>> {
15-
console.info("aaaaa");
15+
const { token } = this.userService;
1616

1717
return next.handle(
1818
req.clone({
19-
headers: req.headers.set("Authentication", this.userService.token)
19+
headers: token ? req.headers.set("Authentication", token) : req.headers
2020
})
2121
);
2222
}

src/services/websocket.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export class WebSocketService {
3333
private conn: WebSocket;
3434

3535
notifications: NotifyPayload[] = [];
36-
loggers: LoggerPayload[] = [];
36+
dispatcherLogs: LoggerPayload[] = [];
37+
dockerLogs: LoggerPayload[] = [];
3738
tasks: TaskPayload[] = [];
3839

3940
constructor(private httpInfo: HttpInfo, private httpClient: HttpClient) {
@@ -65,17 +66,25 @@ export class WebSocketService {
6566
return;
6667
}
6768

68-
const CONTAINER_MAP = {
69-
[EventType.LOGGER]: this.loggers,
70-
[EventType.NOTIFY]: this.notifications
71-
};
72-
const container = CONTAINER_MAP[type];
7369
let result = payload;
70+
const LOGGER_MAP = {
71+
[LoggerType.DOCKER]: this.dockerLogs,
72+
[LoggerType.DISPATCHER]: this.dispatcherLogs
73+
};
7474

7575
if (type === EventType.NOTIFY) {
7676
result.type = NOTIFY_CLASS_TYPE[payload.type];
77+
this.notifications.push(result);
78+
79+
return;
7780
}
7881

79-
container.push(result);
82+
if (type === EventType.LOGGER) {
83+
const { logType, content } = payload;
84+
85+
LOGGER_MAP[logType].push(content);
86+
87+
return;
88+
}
8089
}
8190
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,11 @@ ansi-styles@^3.2.1:
12801280
dependencies:
12811281
color-convert "^1.9.0"
12821282

1283+
ansi_up@^4.0.4:
1284+
version "4.0.4"
1285+
resolved "https://registry.npm.taobao.org/ansi_up/download/ansi_up-4.0.4.tgz#5b8c35f0b02e4476f3f18cf89c3bf48d15d054f6"
1286+
integrity sha1-W4w18LAuRHbz8Yz4nDv0jRXQVPY=
1287+
12831288
anymatch@^2.0.0:
12841289
version "2.0.0"
12851290
resolved "https://registry.npm.taobao.org/anymatch/download/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb"

0 commit comments

Comments
 (0)