Skip to content

Commit c8e9e5f

Browse files
committed
ang client upd
1 parent 95ba5ff commit c8e9e5f

2 files changed

Lines changed: 90 additions & 20 deletions

File tree

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,67 @@
1-
<h1 class="container h1">Cells</h1>
1+
<div class="container">
2+
<h1 class="container h1 m-2"></h1>
3+
</div>
4+
25
<div class="container mb-2">
3-
<button class="btn btn-light" (click)="this.clearCells()">
4-
clearCells
5-
</button>
6-
<button class="btn btn-light ml-2" (click)="this.generateCells()">
7-
generateCells
8-
</button>
6+
<div class="row text-center">
7+
<div class="col-sm m-2">
8+
<button class="btn btn-light p-2 m-0 w-100 h-100" (click)="this.clearCells()">
9+
clearCells
10+
</button>
11+
</div>
12+
<div class="col-sm m-2">
13+
<button class="btn btn-light p-2 m-0 w-100 h-100" (click)="this.generateCells()">
14+
generateCells
15+
</button>
16+
</div>
17+
<div class="col-sm m-2">
18+
<div class="alert bg-light p-2 m-0 w-100 h-100">
19+
<span>Connections = {{connections}}</span>
20+
</div>
21+
</div>
22+
</div>
23+
24+
</div>
25+
<div class="container">
26+
<p class="m-2">W: {{this.size[0]}} H: {{this.size[1]}}</p>
27+
</div>
28+
29+
30+
<div class="container mb-3">
31+
<div class="progress m-2">
32+
<div class="bg-danger progress-bar progress-bar-striped progress-bar-animated" role="progressbar"
33+
[ngStyle]="{'width':(100*colors[0]/(colors[0]+colors[1]+colors[2]))+'%'}" aria-valuemin="0" aria-valuemax="100">
34+
</div>
35+
</div>
36+
<div class="progress m-2">
37+
<div class="bg-success progress-bar progress-bar-striped progress-bar-animated" role="progressbar"
38+
[ngStyle]="{'width':(100*colors[1]/(colors[0]+colors[1]+colors[2]))+'%'}" aria-valuemin="0" aria-valuemax="100">
39+
</div>
40+
</div>
41+
<div class="progress m-2">
42+
<div class="bg-primary progress-bar progress-bar-striped progress-bar-animated" role="progressbar"
43+
[ngStyle]="{'width':(100*colors[2]/(colors[0]+colors[1]+colors[2]))+'%'}" aria-valuemin="0" aria-valuemax="100">
44+
</div>
45+
</div>
946
</div>
10-
<p class="container">W: {{this.size[0]}} H: {{this.size[1]}}</p>
11-
<ul class="container">
12-
<li *ngFor="let item of this.frame">
13-
<span>{{item.color}} </span>
14-
<span class="ml-2">Size {{item.size}} </span>
15-
<span class="ml-2">X {{item.x}} </span>
16-
<span class="ml-2">Y {{item.y}} </span>
17-
</li>
18-
</ul>
47+
48+
<div class="container mt-3">
49+
<table class="table">
50+
<thead>
51+
<tr>
52+
<th scope="col">Color</th>
53+
<th scope="col-3">Size</th>
54+
<th scope="col-2">X</th>
55+
<th scope="col-2">Y</th>
56+
</tr>
57+
</thead>
58+
<tbody>
59+
<tr *ngFor="let item of this.frame">
60+
<th>{{item.color}}</th>
61+
<td>{{item.size}}</td>
62+
<td>{{item.x}}</td>
63+
<td>{{item.y}}</td>
64+
</tr>
65+
</tbody>
66+
</table>
67+
</div>

WebCellLifeSimulationApp/ClientApp/src/app/home/home.component.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ export class HomeComponent {
1212
http: HttpClient;
1313
baseUrl: string;
1414
size: number[] = [2, 2];
15+
colors: number[] = [0,0,0];
16+
17+
connections:number=0;
1518

1619
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
1720
this.http = http;
1821
this.baseUrl = baseUrl;
1922

2023
this.http.get<number[]>(this.baseUrl + 'api/Simulation/getSize').subscribe(this.setSize, error => console.error(error));
2124
this.initWebSocket(new URL(this.baseUrl).host);
25+
26+
2227
}
2328

29+
requestConnections = ()=>this.http.get<number>(this.baseUrl + `wsserver/getConnections`).subscribe(this.setConnectionsCounter, error => console.error(error));
30+
setConnectionsCounter=(num:number)=>this.connections=num;
31+
2432
clearCells = () => {
2533
this.http.get(this.baseUrl + `api/Simulation/clearCells`).subscribe();
2634
}
@@ -35,16 +43,29 @@ export class HomeComponent {
3543

3644
initWebSocket = (host: string) => {
3745
this.socket = new WebSocket("ws://" + host + "/ws");
38-
this.socket.onopen = () => { console.log("success");};
46+
this.socket.onopen = () => { console.log("success");this.requestConnections();};
3947
this.socket.onmessage = (msg) => this.onUpdate(msg);
4048
this.socket.onclose = () => { console.log("closed"); };
4149
this.socket.onerror = () => { console.log("error"); };
4250
}
4351

4452
onUpdate = (msg: ISocketMessage) => {
45-
console.log("income msg", msg.data);
46-
let framearr: IDrawEntity[] = this.parseDrawEntities(msg.data);
47-
this.frame = framearr;
53+
//console.log("income msg", msg.data);
54+
this.frame = this.parseDrawEntities(msg.data);
55+
this.calccolors();
56+
}
57+
58+
calccolors= ()=>{
59+
this.colors=[0,0,0];
60+
this.frame.forEach(element => {
61+
if(element.color=="Color [Red]"){
62+
this.colors[0]++;
63+
}else if(element.color=="Color [Green]"){
64+
this.colors[1]++;
65+
}else if(element.color=="Color [Blue]"){
66+
this.colors[2]++;
67+
}
68+
});
4869
}
4970

5071
parseDrawEntities(value: string): IDrawEntity[] {

0 commit comments

Comments
 (0)