Skip to content

Commit c45b1db

Browse files
David Martínez RosDavid Martínez Ros
authored andcommitted
first version stable, with the correct generation of the tree
1 parent 9626512 commit c45b1db

File tree

6 files changed

+53
-19
lines changed

6 files changed

+53
-19
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
div {
2+
background: #363ca1;
3+
border-radius: 4px;
4+
box-shadow: 0 1px 2px 1px rgba(0, 0, 0, 0.25);
5+
will-change: transform;
6+
cursor: pointer;
7+
padding: 0 0 0 0;
8+
margin: 0 0 0 0;
9+
}
10+
11+
.images {
12+
float: left;
13+
display: block;
14+
padding: 0 0 0 0;
15+
margin: 0 0 0 0;
16+
}
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
<div id="{{ node.id }}">
2-
<span *ngIf="parents.length > 0">
3-
<span *ngFor="let p of parents">
4-
<img *ngIf="!p.lastParentNode" src="../assets/line_continue.png"/>
5-
<img *ngIf="p.lastParentNode" src="../assets/blank_node.png"/>
2+
<span class="images">
3+
<span *ngIf="node.parents.length > 0" class="images">
4+
<span *ngFor="let p of node.parents" class="images">
5+
<img *ngIf="!p.lastNode" src="../assets/line_continue.png"/>
6+
<img *ngIf="p.lastNode" src="../assets/blank_node.png"/>
7+
</span>
68
</span>
9+
10+
<img *ngIf="!node.lastNode" src="../assets/line_node_and_continue.png"/>
11+
<img *ngIf="node.lastNode" src="../assets/line_node_and_end.png"/>
12+
<img *ngIf="!node.sheet && node.expand" src="../assets/collapse_icon.png" (click)="clickExpandCollapse()"/>
13+
<img *ngIf="!node.sheet && !node.expand" src="../assets/expand_icon.png" (click)="clickExpandCollapse()"/>
14+
<img *ngIf="node.sheet" src="../assets/line_sheet.png" (click)="clickExpandCollapse()"/>
715
</span>
8-
9-
<img *ngIf="!node.lastNode" src="../assets/line_node_and_continue.png"/>
10-
<img *ngIf="node.lastNode" src="../assets/line_node_and_end.png"/>
11-
<img *ngIf="!node.sheet && node.expand" src="../assets/collapse_icon.png" (click)="clickExpandCollapse()"/>
12-
<img *ngIf="!node.sheet && !node.expand" src="../assets/expand_icon.png" (click)="clickExpandCollapse()"/>
13-
<img *ngIf="node.sheet" src="../assets/line_sheet.png" (click)="clickExpandCollapse()"/>
1416

1517
<span><b>{{ node.name }}</b> el seu pare es: {{ node.idParent }}</span>
1618
</div>
1719
<div *ngIf="!node.sheet">
1820
<div *ngIf="node.expand">
1921
<div *ngFor="let child of node.childs; let lastNodeChild = last">
20-
<app-node-tree [node]="child" [parents]="[node,parents]" [lastParentNode]="node.lastNode" [lastNode]="lastNodeChild"></app-node-tree>
22+
<app-node-tree [node]="child" [parent]="node" [lastNode]="lastNodeChild"></app-node-tree>
2123
</div>
2224
</div>
2325
</div>

src/app/node-tree/node-tree.component.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ export class NodeTreeComponent implements OnInit {
1111

1212
@Input() node: Node;
1313

14-
@Input() parents: Node[];
14+
@Input() parent: Node;
1515

1616
@Input() lastNode;
1717

18-
@Input() lastParentNode;
19-
2018
constructor() { }
2119

2220
ngOnInit() {
@@ -29,8 +27,22 @@ export class NodeTreeComponent implements OnInit {
2927

3028
loadNode() {
3129
this.node.lastNode = this.lastNode;
32-
this.node.lastParentNode = this.lastParentNode;
33-
console.log('el node ' + this.node.name + " te " + this.parents.length + " parents.");
30+
console.log("el node " + this.node.name + " te lastNode " + this.node.lastNode);
31+
if(this.node.parents == null) {
32+
this.node.parents = [];
33+
}
34+
if(this.parent != null) {
35+
for(let p of this.parent.parents) {
36+
if(!this.node.parents.filter(x => x.id === p.id)[0]) {
37+
this.node.parents.push(p);
38+
}
39+
}
40+
if(!this.node.parents.filter(x => x.id === this.parent.id)[0]) {
41+
this.node.parents.push(this.parent);
42+
}
43+
console.log("afegim parent " + this.parent.name + " amnb lastNode " + this.parent.lastNode);
44+
}
45+
console.log('el node ' + this.node.name + " te " + this.node.parents.length + " parents.");
3446
}
3547

3648
}

src/app/node.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export class Node {
1010

1111
lastNode: boolean;
1212

13-
lastParentNode: boolean;
13+
parents: Node[];
1414
}

src/app/tree/tree.component.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
div {
2+
padding: 0 0 0 0;
3+
margin: 0 0 0 0;
4+
}

src/app/tree/tree.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<div *ngFor="let node of tree | async; let lastParentNode = last">
2-
<app-node-tree [node]="node" [parents]="[]" [lastParentNode]="true" [lastNode]="lastParentNode"></app-node-tree>
1+
<div *ngFor="let node of tree | async; let lastNode = last">
2+
<app-node-tree [node]="node" [parent]="" [lastNode]="lastNode"></app-node-tree>
33

44
<!--
55
haure de fer algo aixi

0 commit comments

Comments
 (0)