Skip to content

Commit 586f202

Browse files
committed
Node positions are now persisted corectly when changing to another tab and back again.
1 parent f40c14a commit 586f202

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

src/commands/generateDependencyInjectionGraph.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export class GenerateDependencyInjectionGraph extends ShowHierarchyBase {
2525
const newGraphState: GraphState = JSON.parse(message.text);
2626
this.graphState = newGraphState;
2727
this.setNewState(this.graphState);
28+
this.nodes.forEach(node => {
29+
node.position = this.graphState.nodePositions[node.id];
30+
});
31+
this.addNodesAndEdges(project, this.appendNodes, this.appendEdges);
32+
this.generateAndSaveJavascriptContent(() => { });
2833
return;
2934
}
3035
},
@@ -37,6 +42,15 @@ export class GenerateDependencyInjectionGraph extends ShowHierarchyBase {
3742
this.nodes = [];
3843
this.edges = [];
3944
this.addNodesAndEdges(project, this.appendNodes, this.appendEdges);
45+
let htmlContent = this.generateHtmlContent(webview, this.showModuleHierarchyJsFilename);
46+
// this.fsUtils.writeFile(this.extensionContext?.asAbsolutePath(path.join('out', GenerateDependencyInjectionGraph.commandName + '.html')), htmlContent, () => { }); // For debugging
47+
this.generateAndSaveJavascriptContent(() => { webview.html = htmlContent; });
48+
if (errors.length > 0) {
49+
this.showErrors(errors, `Parsing of ${errors.length > 1 ? 'some' : 'one'} of the project files failed.\n`);
50+
}
51+
}
52+
53+
private generateAndSaveJavascriptContent(callback: () => any) {
4054
const nodesJson = this.nodes
4155
.map((node, index, arr) => { return node.toJsonString(); })
4256
.join(',\n');
@@ -46,23 +60,15 @@ export class GenerateDependencyInjectionGraph extends ShowHierarchyBase {
4660

4761
try {
4862
const jsContent = this.generateJavascriptContent(nodesJson, edgesJson);
49-
const outputJsFilename = this.showModuleHierarchyJsFilename;
50-
let htmlContent = this.generateHtmlContent(webview, this.showModuleHierarchyJsFilename);
51-
this.fsUtils.writeFile(this.extensionContext?.asAbsolutePath(path.join('out', GenerateDependencyInjectionGraph.commandName + '.html')), htmlContent, () => { }); // For debugging
5263
this.fsUtils.writeFile(
53-
this.extensionContext?.asAbsolutePath(path.join('.', outputJsFilename)),
64+
this.extensionContext?.asAbsolutePath(path.join('.', this.showModuleHierarchyJsFilename)),
5465
jsContent,
55-
() => {
56-
webview.html = htmlContent;
57-
}
66+
callback
5867
);
5968
}
6069
catch (ex) {
6170
console.log('Angular Tools Exception:' + ex);
6271
}
63-
if (errors.length > 0) {
64-
this.showErrors(errors, `Parsing of ${errors.length > 1 ? 'some' : 'one'} of the project files failed.\n`);
65-
}
6672
}
6773

6874
generatedComponentNode(component: Component): string {

src/commands/showComponentHierarchy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export class ShowComponentHierarchy extends ShowHierarchyBase {
4646
this.edges = [];
4747
this.addNodesAndEdges(components, this.appendNodes, this.appendEdges);
4848
const htmlContent = this.generateHtmlContent(webview, this.showComponentHierarchyJsFilename);
49-
//this.fsUtils.writeFile(this.extensionContext?.asAbsolutePath(path.join('out', ShowComponentHierarchy.Name + '.html')), htmlContent, () => { }); // For debugging
50-
this.generateAndSaveJavascriptContent(() => { webview.html = htmlContent; });
49+
//this.fsUtils.writeFile(this.extensionContext?.asAbsolutePath(path.join('out', ShowComponentHierarchy.Name + '.html')), htmlContent, () => { }); // For debugging
50+
this.generateAndSaveJavascriptContent(() => { webview.html = htmlContent; });
5151
}
5252

5353
private generateAndSaveJavascriptContent(callback: () => any) {

src/commands/showModuleHierarchy.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export class ShowModuleHierarchy extends ShowHierarchyBase {
2525
const newGraphState: GraphState = JSON.parse(message.text);
2626
this.graphState = newGraphState;
2727
this.setNewState(this.graphState);
28+
this.nodes.forEach(node => {
29+
node.position = this.graphState.nodePositions[node.id];
30+
});
31+
this.addNodesAndEdges(project, this.appendNodes, this.appendEdges);
32+
this.generateAndSaveJavascriptContent(() => { });
2833
return;
2934
}
3035
},
@@ -38,6 +43,15 @@ export class ShowModuleHierarchy extends ShowHierarchyBase {
3843
this.nodes = [];
3944
this.edges = [];
4045
this.addNodesAndEdges(project, this.appendNodes, this.appendEdges);
46+
let htmlContent = this.generateHtmlContent(webview, this.showModuleHierarchyJsFilename);
47+
//this.fsUtils.writeFile(this.extensionContext?.asAbsolutePath(path.join('out', ShowComponentHierarchy.Name + '.html')), htmlContent, () => { }); // For debugging
48+
this.generateAndSaveJavascriptContent(() => { webview.html = htmlContent; });
49+
if (errors.length > 0) {
50+
this.showErrors(errors, `Parsing of ${errors.length > 1 ? 'some' : 'one'} of the modules failed.\n`);
51+
}
52+
}
53+
54+
private generateAndSaveJavascriptContent(callback: () => any) {
4155
const nodesJson = this.nodes
4256
.map((node, index, arr) => { return node.toJsonString(); })
4357
.join(',\n');
@@ -47,23 +61,15 @@ export class ShowModuleHierarchy extends ShowHierarchyBase {
4761

4862
try {
4963
const jsContent = this.generateJavascriptContent(nodesJson, edgesJson);
50-
const outputJsFilename = this.showModuleHierarchyJsFilename;
51-
let htmlContent = this.generateHtmlContent(webview, this.showModuleHierarchyJsFilename);
52-
//this.fsUtils.writeFile(this.extensionContext?.asAbsolutePath(path.join('out', ShowComponentHierarchy.Name + '.html')), htmlContent, () => { }); // For debugging
5364
this.fsUtils.writeFile(
54-
this.extensionContext?.asAbsolutePath(path.join('.', outputJsFilename)),
65+
this.extensionContext?.asAbsolutePath(path.join('.', this.showModuleHierarchyJsFilename)),
5566
jsContent,
56-
() => {
57-
webview.html = htmlContent;
58-
}
67+
callback
5968
);
6069
}
6170
catch (ex) {
6271
console.log('Angular Tools Exception:' + ex);
6372
}
64-
if (errors.length > 0) {
65-
this.showErrors(errors, `Parsing of ${errors.length > 1 ? 'some' : 'one'} of the modules failed.\n`);
66-
}
6773
}
6874

6975
private addNodesAndEdges(project: Project, appendNodes: (nodeList: Node[]) => void, appendEdges: (edgeList: Edge[]) => void) {

0 commit comments

Comments
 (0)