/
component.react.tsx
94 lines (89 loc) · 2.54 KB
/
component.react.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React from 'react';
import { MeasuredSerieModel } from '../../../models/measured-series.model';
import { ReactComponent } from '../../component.react';
import { ListSerieController } from './controller';
export class ListSerieComponent extends ReactComponent {
public $ctrl: ListSerieController = new ListSerieController();
constructor(props) {
super(props);
this.$ctrl.renderView = this.forceUpdate.bind(this);
this.handleEdit.bind(this);
}
private handleEdit(measuredSerie: MeasuredSerieModel) {
this.$ctrl.edit(measuredSerie);
this.forceUpdate();
}
public render() {
const tables: any[] = [];
for (let i = 0; i < this.$ctrl.elements.length; i++) {
tables.push(
<table className="table" key={i}>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Unit</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
{this.$ctrl.measuredSeries.map((serie: MeasuredSerieModel, index: number) => {
return (
<tr key={index}>
<td>{index + 1}</td>
<td>{serie.getId()}</td>
<td>{serie.getTitle()}</td>
<td>{serie.getUnit()}</td>
<td>
<button
className="btn btn-info"
id={`edit-${index}`}
type="button"
onClick={() => {
this.handleEdit(serie);
}}
>
Edit
</button>
</td>
</tr>
);
})}
</tbody>
</table>
);
}
return (
<div>
<h5>List</h5>
<div>
<button
className="btn btn-success"
id="add"
type="button"
onClick={() => {
this.$ctrl.add();
}}
>
Add
</button>
{this.$ctrl.showPerformanceButton && (
<button
className="btn btn-info"
id="start"
type="button"
onClick={() => {
this.$ctrl.onStart();
}}
>
Performance
</button>
)}
</div>
{tables}
<small>Duration: {this.$ctrl.duration} ms</small>
</div>
);
}
}