Skip to content

Commit e878c50

Browse files
committed
Moved model objects into model folder
1 parent 20d47af commit e878c50

File tree

9 files changed

+122
-113
lines changed

9 files changed

+122
-113
lines changed

src/commands/generateDependencyInjectionGraph.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Node, Edge, ShowHierarchyBase, NodeType, ArrowType } from './showHierarchyBase';
1+
import { ShowHierarchyBase } from './showHierarchyBase';
22
import { ModuleManager } from '@src';
3-
import { Component, Project } from '@model';
3+
import { ArrowType, Component, Edge, Node, NodeType, Project } from '@model';
44
import * as fs from 'fs';
55
import * as path from 'path';
66
import * as vscode from 'vscode';

src/commands/showComponentHierarchy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Node, Edge, ShowHierarchyBase } from './showHierarchyBase';
1+
import { ShowHierarchyBase } from './showHierarchyBase';
22
import { Component, ComponentManager } from '@src';
3+
import { Edge, Node } from '@model';
34
import * as fs from 'fs';
45
import * as path from 'path';
56
import * as vscode from 'vscode';

src/commands/showHierarchyBase.ts

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,11 @@
11
import { CommandBase } from '@commands';
22
import { Config, FileSystemUtils } from '@src';
3+
import { Edge, Node } from '@model';
34
import { Base64 } from 'js-base64';
45
import * as fs from 'fs';
56
import * as path from 'path';
67
import * as vscode from 'vscode';
7-
import { Project } from '@model';
88

9-
export enum NodeType {
10-
none,
11-
component,
12-
directive,
13-
injectable,
14-
module,
15-
pipe,
16-
rootNode
17-
}
18-
export class Node {
19-
private config: Config = new Config();
20-
constructor(id: string, name: string, isRoot: boolean, nodeType: NodeType = NodeType.none) {
21-
this.id = id;
22-
this.name = name;
23-
this.isRoot = isRoot;
24-
this.nodeType = nodeType;
25-
}
26-
public id: string;
27-
public name: string;
28-
public isRoot: boolean;
29-
public nodeType: NodeType;
30-
31-
public toJsonString(): string {
32-
let nodeColorAttr = '';
33-
switch (this.nodeType) {
34-
case NodeType.rootNode:
35-
nodeColorAttr = `, color: "${this.config.rootNodeBackgroundColor}", shape: "${this.config.visNodeShape}"`;
36-
break;
37-
case NodeType.component:
38-
nodeColorAttr = `, color: "${this.config.componentNodeBackgroundColor}", shape: "${this.config.componentNodeShape}"`;
39-
break;
40-
case NodeType.module:
41-
nodeColorAttr = `, color: "${this.config.moduleNodeBackgroundColor}", shape: "${this.config.moduleNodeShape}"`;
42-
break;
43-
case NodeType.pipe:
44-
nodeColorAttr = `, color: "${this.config.pipeNodeBackgroundColor}", shape: "${this.config.pipeNodeShape}"`;
45-
break;
46-
case NodeType.directive:
47-
nodeColorAttr = `, color: "${this.config.directiveNodeBackgroundColor}", shape: "${this.config.directiveNodeShape}"`;
48-
break;
49-
default:
50-
nodeColorAttr = '';
51-
break;
52-
}
53-
const label = this.config.maximumNodeLabelLength !== -1 && this.name.length > this.config.maximumNodeLabelLength ? this.name.substr(0, this.config.maximumNodeLabelLength) + '...' : this.name;
54-
return `{id: "${this.id}", label: "${label}" ${nodeColorAttr}}`;
55-
}
56-
57-
public static getNodeType(project: Project, className: string) {
58-
let nodeType = NodeType.none;
59-
if (project.moduleNames.has(className) || className.endsWith('Module') || className.includes("Module.")) {
60-
nodeType = NodeType.module;
61-
}
62-
else if (project.components.has(className) || className.endsWith('Component')) {
63-
nodeType = NodeType.component;
64-
}
65-
else if (project.directives.has(className) || className.endsWith('Directive')) {
66-
nodeType = NodeType.directive;
67-
}
68-
else if (project.pipes.has(className) || className.endsWith('Pipe')) {
69-
nodeType = NodeType.pipe;
70-
}
71-
else if (project.injectables.has(className)) {
72-
nodeType = NodeType.injectable;
73-
}
74-
return nodeType;
75-
}
76-
}
77-
78-
export enum ArrowType {
79-
none = 0,
80-
import = 1,
81-
export = 2,
82-
injectable = 3
83-
}
84-
85-
export class Edge {
86-
private config: Config = new Config();
87-
constructor(id: string, source: string, target: string, arrowType: ArrowType = ArrowType.none) {
88-
this.id = id;
89-
this.source = source;
90-
this.target = target;
91-
this.arrowType = arrowType;
92-
}
93-
public id: string;
94-
public source: string;
95-
public target: string;
96-
public arrowType: ArrowType;
97-
98-
public toJsonString(): string {
99-
let arrowColorAttr = '';
100-
switch (this.arrowType) {
101-
case ArrowType.import:
102-
arrowColorAttr = `, color: "${this.config.importEdgeColor}"`;
103-
break;
104-
case ArrowType.export:
105-
arrowColorAttr = `, color: "${this.config.exportEdgeColor}"`;
106-
break;
107-
default:
108-
arrowColorAttr = '';
109-
break;
110-
}
111-
return `{from: "${this.source}", to: "${this.target}", arrows: arrowAttr ${arrowColorAttr} }`;
112-
}
113-
}
1149

11510
export class ShowHierarchyBase extends CommandBase {
11611
protected fsUtils: FileSystemUtils = new FileSystemUtils();
@@ -166,7 +61,7 @@ export class ShowHierarchyBase extends CommandBase {
16661
}
16762

16863
protected saveAsDgml(dgmlGraphFilename: string, messageText: string) {
169-
64+
17065
}
17166

17267
protected generateHtmlContent(webview: vscode.Webview, outputJsFilename: string): string {

src/commands/showModuleHierarchy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Node, Edge, ShowHierarchyBase, NodeType, ArrowType } from './showHierarchyBase';
1+
import { ShowHierarchyBase } from './showHierarchyBase';
22
import { ModuleManager } from '@src';
3-
import { Project } from '@model';
3+
import { ArrowType, Edge, Node, NodeType, Project } from '@model';
44
import * as fs from 'fs';
55
import * as path from 'path';
66
import * as vscode from 'vscode';

src/model/ArrowType.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export enum ArrowType {
2+
none = 0,
3+
import = 1,
4+
export = 2,
5+
injectable = 3
6+
}

src/model/Edge.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ArrowType } from "@model";
2+
import { Config } from "@src";
3+
4+
export class Edge {
5+
private config: Config = new Config();
6+
constructor(id: string, source: string, target: string, arrowType: ArrowType = ArrowType.none) {
7+
this.id = id;
8+
this.source = source;
9+
this.target = target;
10+
this.arrowType = arrowType;
11+
}
12+
public id: string;
13+
public source: string;
14+
public target: string;
15+
public arrowType: ArrowType;
16+
17+
public toJsonString(): string {
18+
let arrowColorAttr = '';
19+
switch (this.arrowType) {
20+
case ArrowType.import:
21+
arrowColorAttr = `, color: "${this.config.importEdgeColor}"`;
22+
break;
23+
case ArrowType.export:
24+
arrowColorAttr = `, color: "${this.config.exportEdgeColor}"`;
25+
break;
26+
default:
27+
arrowColorAttr = '';
28+
break;
29+
}
30+
return `{from: "${this.source}", to: "${this.target}", arrows: arrowAttr ${arrowColorAttr} }`;
31+
}
32+
}

src/model/Node.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { NodeType, Project } from "@model";
2+
import { Config } from "@src";
3+
4+
export class Node {
5+
private config: Config = new Config();
6+
constructor(id: string, name: string, isRoot: boolean, nodeType: NodeType = NodeType.none) {
7+
this.id = id;
8+
this.name = name;
9+
this.isRoot = isRoot;
10+
this.nodeType = nodeType;
11+
}
12+
public id: string;
13+
public name: string;
14+
public isRoot: boolean;
15+
public nodeType: NodeType;
16+
17+
public toJsonString(): string {
18+
let nodeColorAttr = '';
19+
switch (this.nodeType) {
20+
case NodeType.rootNode:
21+
nodeColorAttr = `, color: "${this.config.rootNodeBackgroundColor}", shape: "${this.config.visNodeShape}"`;
22+
break;
23+
case NodeType.component:
24+
nodeColorAttr = `, color: "${this.config.componentNodeBackgroundColor}", shape: "${this.config.componentNodeShape}"`;
25+
break;
26+
case NodeType.module:
27+
nodeColorAttr = `, color: "${this.config.moduleNodeBackgroundColor}", shape: "${this.config.moduleNodeShape}"`;
28+
break;
29+
case NodeType.pipe:
30+
nodeColorAttr = `, color: "${this.config.pipeNodeBackgroundColor}", shape: "${this.config.pipeNodeShape}"`;
31+
break;
32+
case NodeType.directive:
33+
nodeColorAttr = `, color: "${this.config.directiveNodeBackgroundColor}", shape: "${this.config.directiveNodeShape}"`;
34+
break;
35+
default:
36+
nodeColorAttr = '';
37+
break;
38+
}
39+
const label = this.config.maximumNodeLabelLength !== -1 && this.name.length > this.config.maximumNodeLabelLength ? this.name.substr(0, this.config.maximumNodeLabelLength) + '...' : this.name;
40+
return `{id: "${this.id}", label: "${label}" ${nodeColorAttr}}`;
41+
}
42+
43+
public static getNodeType(project: Project, className: string) {
44+
let nodeType = NodeType.none;
45+
if (project.moduleNames.has(className) || className.endsWith('Module') || className.includes("Module.")) {
46+
nodeType = NodeType.module;
47+
}
48+
else if (project.components.has(className) || className.endsWith('Component')) {
49+
nodeType = NodeType.component;
50+
}
51+
else if (project.directives.has(className) || className.endsWith('Directive')) {
52+
nodeType = NodeType.directive;
53+
}
54+
else if (project.pipes.has(className) || className.endsWith('Pipe')) {
55+
nodeType = NodeType.pipe;
56+
}
57+
else if (project.injectables.has(className)) {
58+
nodeType = NodeType.injectable;
59+
}
60+
return nodeType;
61+
}
62+
}

src/model/NodeType.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export enum NodeType {
2+
none,
3+
component,
4+
directive,
5+
injectable,
6+
module,
7+
pipe,
8+
rootNode
9+
}

src/model/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
export * from './NamedEntity';
1+
export * from './ArrowType';
22
export * from './Component';
3+
export * from './Edge';
4+
export * from './NamedEntity';
5+
export * from './Node';
6+
export * from './NodeType';
37
export * from './Project';

0 commit comments

Comments
 (0)