Skip to content

Commit 6da57d4

Browse files
author
Tim Etchells
committed
Consume logs list changed event
Multilogs is working, requires a little more testing Also add inline enable button
1 parent 5145994 commit 6da57d4

File tree

9 files changed

+107
-43
lines changed

9 files changed

+107
-43
lines changed

dev/package.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@
159159
{
160160
"command": "%cmdID_enable%",
161161
"title": "%cmdTitle_enable%",
162-
"category": "%commandCategory%"
162+
"category": "%commandCategory%",
163+
"icon": {
164+
"light": "res/img/light/play.svg",
165+
"dark": "res/img/dark/play.svg"
166+
}
163167
},
164168
{
165169
"command": "%cmdID_disable%",
@@ -277,7 +281,7 @@
277281
},
278282
{
279283
"command": "%cmdID_refreshConnection%",
280-
"when": "%isActiveConnection%",
284+
"when": "%isConnection%",
281285
"group": "ext.mc.conn.c@1"
282286
},
283287
{
@@ -370,10 +374,20 @@
370374
"when": "%isEnabledAutoBuildOn%",
371375
"group": "ext.mc.e@2"
372376
},
377+
{
378+
"command": "%cmdID_disable%",
379+
"when": "%isEnabledProject%",
380+
"group": "ext.mc.z"
381+
},
373382
{
374383
"command": "%cmdID_enable%",
375384
"when": "%isDisabledProject%",
376385
"group": "ext.mc.z"
386+
},
387+
{
388+
"command": "%cmdID_enable%",
389+
"when": "%isDisabledProject%",
390+
"group": "inline"
377391
}
378392
]
379393
}

dev/res/img/dark/play.svg

Lines changed: 4 additions & 0 deletions
Loading

dev/res/img/light/play.svg

Lines changed: 4 additions & 0 deletions
Loading

dev/src/command/ManageLogsCmd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async function manageLogsInner(project: Project, all?: "show" | "hide"): Promise
8080
};
8181

8282
// https://github.com/Microsoft/vscode/issues/64014
83-
const logsToShow: MCLog[] | undefined = await vscode.window.showQuickPick(logs, options) as (MCLog[] | undefined);
83+
const logsToShow: MCLog[] | undefined = await vscode.window.showQuickPick<MCLog>(logs, options) as (MCLog[] | undefined);
8484
if (logsToShow != null) {
8585
// Log.d("selection", selection);
8686

dev/src/microclimate/connection/MCSocket.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,18 @@ export default class MCSocket implements vscode.Disposable {
169169
}
170170
}
171171

172-
private readonly onLogsListChanged = async (payload: any): Promise<void> => {
172+
private readonly onLogsListChanged = async (payload: SocketEvents.ILogsListChangedEvent): Promise<void> => {
173173
const project = await this.getProject(payload);
174174
if (project == null) {
175175
return;
176176
}
177+
178+
if (!this.connection.is1905OrNewer()) {
179+
Log.e("Received new logs LIST event for a project that should be using the OLD logs API");
180+
return;
181+
}
182+
183+
(project.logManager as MCLogManager).onLogsListChanged(payload);
177184
}
178185

179186
private readonly onLogUpdate = async (payload: SocketEvents.ILogUpdateEvent): Promise<void> => {
@@ -188,8 +195,7 @@ export default class MCSocket implements vscode.Disposable {
188195
}
189196

190197
// Log.d(`Received log ${payload.logName} of length ${payload.logs.length} with reset ${payload.reset}`);
191-
const logManager = project.logManager as MCLogManager;
192-
logManager.onNewLogs(payload);
198+
(project.logManager as MCLogManager).onNewLogs(payload);
193199
}
194200

195201
private readonly onProjectValidated = async (payload: { projectID: string, validationResults: SocketEvents.IValidationResult[] })

dev/src/microclimate/connection/SocketEvents.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ namespace SocketEvents {
7272
readonly reset: boolean;
7373
}
7474

75+
export type ILogsListChangedEvent = { projectID: string } & ILogResponse;
76+
7577
/**
7678
* Socket events we listen for from Microclimate Portal
7779
* See MCSocket
@@ -103,4 +105,14 @@ namespace SocketEvents {
103105
}
104106
}
105107

108+
export interface ILogResponse {
109+
readonly build?: ILogObject[];
110+
readonly app?: ILogObject[];
111+
}
112+
113+
export interface ILogObject {
114+
readonly logName: string;
115+
readonly workspathLogPath?: string;
116+
}
117+
106118
export default SocketEvents;

dev/src/microclimate/project/Requester.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import StringNamespaces from "../../constants/strings/StringNamespaces";
1919
import Translator from "../../constants/strings/translator";
2020
import * as MCUtil from "../../MCUtil";
2121
import EndpointUtil, { ProjectEndpoints, Endpoint, MCEndpoints } from "../../constants/Endpoints";
22+
import { ILogResponse } from "../connection/SocketEvents";
2223

2324
const STRING_NS = StringNamespaces.REQUESTS;
2425

@@ -78,10 +79,10 @@ namespace Requester {
7879
}
7980

8081
export async function requestValidate(project: Project, silent: boolean): Promise<void> {
81-
const [url, body]: [Endpoint, IValidateRequestBody] = assembleValidateRequest(project, false);
82+
const [endpoint, body]: [Endpoint, IValidateRequestBody] = assembleValidateRequest(project, false);
8283

8384
const userOperation = Translator.t(StringNamespaces.CMD_MISC, "validate");
84-
await doProjectRequest(project, url, body, request.post, userOperation, silent);
85+
await doProjectRequest(project, endpoint, body, request.post, userOperation, silent);
8586
}
8687

8788
export async function requestGenerate(project: Project): Promise<void> {
@@ -148,16 +149,6 @@ namespace Requester {
148149
await doProjectRequest(project, ProjectEndpoints.PROPERTES, body, request.post, updateMsg);
149150
}
150151

151-
interface ILogResponse {
152-
readonly build: ILogObject[];
153-
readonly app: ILogObject[];
154-
}
155-
156-
interface ILogObject {
157-
readonly logName: string;
158-
readonly workspathLogPath?: string;
159-
}
160-
161152
export async function requestAvailableLogs(project: Project): Promise<ILogResponse> {
162153
if (!project.state.isEnabled) {
163154
// there are no logs available for disabled projects

dev/src/microclimate/project/logs/MCLog.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,37 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2019 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* IBM Corporation - initial API and implementation
10+
*******************************************************************************/
111
import * as vscode from "vscode";
212

3-
// export enum MCLogTypes {
4-
// "app", "build",
5-
// }
6-
7-
const FW_CONTAINER_LOGS_NAME = "-";
8-
const PORTAL_CONTAINER_LOGS_NAME = "container";
9-
const USER_CONTAINER_LOGS_NAME = "container log";
10-
1113
export default class MCLog implements vscode.QuickPickItem {
1214

1315
public readonly displayName: string;
1416

1517
// quickPickItem
1618
public readonly label: string;
19+
// public readonly detail: string;
1720

1821
private output: vscode.OutputChannel | undefined;
1922

2023
constructor(
2124
projectName: string,
22-
// MUST match the logName provided in the events
25+
// MUST match the logName provided in the log-update events
2326
public readonly logName: string,
24-
// public readonly logType: MCLogTypes,
25-
// path is not used at this time
2627
public readonly logPath?: string,
2728
) {
28-
// portal sends the logName for container logs (in log-update events) as "container", but filewatcher sends "-" (in REST requests)
29-
// so we have to deal with that here, normalize to the portal name
30-
const isContainerLog = logName === FW_CONTAINER_LOGS_NAME;
31-
if (isContainerLog) {
32-
this.logName = PORTAL_CONTAINER_LOGS_NAME;
33-
}
34-
35-
this.displayName = projectName + " - " + (isContainerLog ? USER_CONTAINER_LOGS_NAME : this.logName);
29+
this.displayName = `${projectName} - ${this.logName}`;
3630
this.label = this.displayName;
31+
// this.detail = logPath;
3732
// this.description = `(${this.logType} log)`;
3833

39-
// Log.d(`Initialized log ${this.displayName} internal name ${this.logName}`);
34+
// Log.d(`Initialized log ${this.displayName} internal name ${this.logName} from ${}`);
4035
}
4136

4237
public onNewLogs(reset: boolean, logs: string): void {
@@ -86,7 +81,7 @@ export default class MCLog implements vscode.QuickPickItem {
8681
msg += "Microclimate disconnected.";
8782
}
8883
else {
89-
msg += "the project has been disabled.";
84+
msg += "the project has been disabled. The log will be recreated when there is new output.";
9085
}
9186
this.output.appendLine(msg);
9287
}

dev/src/microclimate/project/logs/MCLogManager.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2019 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* IBM Corporation - initial API and implementation
10+
*******************************************************************************/
11+
// import * as vscode from "vscode";
12+
113
import Project from "../Project";
214
import MCLog from "./MCLog";
315
import Log from "../../../Logger";
416
import Requester from "../Requester";
5-
import SocketEvents from "../../connection/SocketEvents";
17+
import SocketEvents, { ILogResponse } from "../../connection/SocketEvents";
618

719
export default class MCLogManager {
820

@@ -26,9 +38,7 @@ export default class MCLogManager {
2638
// Log.d("Initializing logs");
2739
try {
2840
const availableLogs = await Requester.requestAvailableLogs(this.project);
29-
availableLogs.app.concat(availableLogs.build).forEach((log) => {
30-
this.logs.push(new MCLog(this.project.name, log.logName, log.workspathLogPath));
31-
});
41+
this.onLogsListChanged(availableLogs);
3242
Log.i(`${this.managerName} has finished initializing logs: ${this.logs.map((l) => l.displayName).join(", ") || "<none>"}`);
3343
}
3444
catch (err) {
@@ -41,6 +51,34 @@ export default class MCLogManager {
4151
return this.managerName;
4252
}
4353

54+
public onLogsListChanged(logs: ILogResponse): void {
55+
const appLogs = logs.app || [];
56+
const buildLogs = logs.build || [];
57+
58+
appLogs.concat(buildLogs).forEach((newLogData) => {
59+
// skip useless container log
60+
if (!(newLogData.logName === "-" || newLogData.logName === "container")) {
61+
return;
62+
}
63+
64+
const existingIndex = this.logs.findIndex((l) => l.logName === newLogData.logName);
65+
const existed = existingIndex !== -1;
66+
let openOnCreate = false;
67+
if (existed) {
68+
// destroy the old log and replace it with this one
69+
const existingLog = this.logs.splice(existingIndex, 1)[0];
70+
openOnCreate = existingLog.isOpen;
71+
existingLog.destroy();
72+
}
73+
74+
const newLog = new MCLog(this.project.name, newLogData.logName, newLogData.workspathLogPath);
75+
this.logs.push(newLog);
76+
if (openOnCreate) {
77+
newLog.showOutput();
78+
}
79+
});
80+
}
81+
4482
/**
4583
* @param enable `true` to refresh (ie, restart) all logs for this project, `false` to stop streaming all logs for this project
4684
*/

0 commit comments

Comments
 (0)