-
Notifications
You must be signed in to change notification settings - Fork 24
/
peer.js
149 lines (123 loc) · 4.75 KB
/
peer.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var Template =`
<div class="col-sm-3 min-h-500">
<section class="panel" v-bind:class="[deadPeer ? 'panel-danger' : 'panel-default']" >
<header class="panel-heading bg-light no-border">
<div class="clearfix">
<div class="clear">
<a href="#" class="btn btn-xs btn-rounded btn-danger m-xs pull-right" v-on:click="removePeer">X</a>
<input class="h5" v-model="state.tag" v-on:keyup.enter="editTag" v-bind:class="[updating ? '' : 'tag-disabled']" :disabled="updating == 1 ? false : true" v-bind:size="state.tag.length">
<i v-on:click="editTag" v-bind:class="[updating ? 'fa fa-2x fa-check text-success' : 'fa fa-2x fa-pencil text-black-lt']"></i>
<div class="text-info text-md">{{state.connectionType}}://{{state.address}}</div>
</div>
</div>
</header>
<div class="spark">
<canvas :id="id" width="200" height="180" ></canvas>
</div>
<div class="list-group-alt no-radius">
<div class="list-group-item" href="#"> <span class="badge bg-success">{{state.numberOfSentTransactions}}</span>Sent Transactions</div>
<div class="list-group-item" href="#"> <span class="badge bg-success">{{state.numberOfAllTransactions}}</span>Received Transactions</div>
<div class="list-group-item" href="#"> <span class="badge bg-success">{{state.numberOfNewTransactions}}</span>Received New Transactions</div>
<div class="list-group-item" href="#"> <span class="badge bg-success">{{state.numberOfRandomTransactionRequests}}</span>Received Random Transaction Requests</div>
<div class="list-group-item" href="#"> <span class="badge bg-success">{{state.numberOfInvalidTransactions}}</span>Received Invalid Transactions</div>
</div>
</section>
</div>
`;
var peer = Vue.component('peer', {
props: ['state'],
template: Template,
data: function (){
return {
updating: false,
id : this._uid
};
},
computed: {
deadPeer: function()
{
if (!this.state) return false;
var data = this.state.history.datasets[0].data;
if (data.length < 10) return false;
return !_.without(data, data[0]).length;
}
},
mounted () {
//this.chartData.labels.push("");
//this.chartData.datasets.data.push(1);
//this.chartData = {};
var ctx = document.getElementById(this._uid).getContext('2d');
this.myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
datasets: [
{
label: 'Rec TX',
data: []
},
{
label: 'New TX',
data: []
},
{
label: 'Sent TX',
data: []
},
]
},
options: {
responsive: true, maintainAspectRatio: false, lineTension: 0,
scales:
{
xAxes: [{
display: false
}]
},
legend: {
display: true,
labels: {
boxWidth :10
}
}
}
});
},
watch: {
// whenever question changes, this function will run
'state.history': function (newData) {
//Object.assign(this.chartData,newData);
Object.assign(this.myChart.data,newData);
this.myChart.update();
},
'state.tag': function (newData, oldData) {
//Object.assign(this.chartData,newData);
socket.emit('updateTag', { address: this.state.address, tag:newData });
},
},
methods: {
editTag: function (event) {
this.updating = !this.updating;
},
removePeer: function (event) {
// `this` inside methods points to the Vue instance
swal({
title: 'Are you sure?',
text: 'Removing Peer ' + this.state.connectionType +"://"+this.state.address + '!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete peer!'
}).then(function () {
socket.emit('removePeer', { address: this.state.connectionType +"://"+this.state.address });
swal(
'Deleted!',
'Your peer has been deleted. Please also update your IRI config file (if required)' ,
'success'
)
//this.$destroy();
}.bind(this))
}
}
})