-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
148 lines (126 loc) · 3.69 KB
/
index.html
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
146
147
148
<html>
<head>
<title>Tweet Sentiments Live Wall</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script>
window.apiBaseUrl = 'http://localhost:7071';
</script>
<style>
.slide-fade-enter-active,
.slide-fade-leave-active {
transition: all 1s ease;
}
.slide-fade-enter,
.slide-fade-leave-to {
height: 0px;
overflow-y: hidden;
opacity: 0;
}
.bar {
background: #17a2b8;
height: 100%;
transition: width 1s ease;
position: relative;
}
.bar span {
position: absolute;
right: 0;
transform: translate(50%, 250%)
}
</style>
</head>
<body>
<p> </p>
<div id="app" class="container">
<h3>Tweet Sentiments Live Wall</h3>
<div class="row" v-if="ready">
<div class="signalr-demo col-sm">
<hr />
</div>
</div>
<div class="row" v-if="!ready">
<div class="col-sm">
<div>Loading...</div>
</div>
</div>
<div v-if="ready">
<p style="text-align: center">
Keyword: <b>{{ keyword }}</b>
</br>
Score avg: {{ scoreAvg }}
</p>
<div style="border: 1px solid #17a2b833; background: #17a2b833; height: 50px; margin-bottom: 40px">
<div class="bar" :style="{ width: (scoreAvg * 100) + '%' }">
<span>{{(scoreAvg * 100).toFixed(2)}}%</span>
</div>
</div>
<transition-group name="slide-fade" tag="div">
<div class="row" v-for="message in messages" v-bind:key="message.id">
<div class="col-sm">
<hr />
<div>
<div style="display: inline-block; padding-left: 12px;">
<div>
<span class="text-info small"><strong>{{ message.sender }}</strong></span>
</div>
<div>
{{ message.text }}
</div>
<div>
Score: {{ message.score }}
</div>
</div>
</div>
</div>
</div>
</div>
</transition-group>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@aspnet/[email protected]/dist/browser/signalr.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js"></script>
<script>
const data = {
newMessage: '',
messages: [],
ready: false,
scoreAvg: 0,
keyword: ''
};
const app = new Vue({
el: '#app',
data: data,
methods: {}
});
const apiBaseUrl = prompt('Enter the Azure Function app base URL', window.apiBaseUrl);
const connection = new signalR.HubConnectionBuilder()
.withUrl(`${apiBaseUrl}/api`)
.configureLogging(signalR.LogLevel.Information)
.build();
connection.on('newMessage', newMessage);
connection.onclose(() => console.log('disconnected'));
console.log('connecting...');
connection.start()
.then(() => data.ready = true)
.catch(console.error);
let counter = 0;
function newMessage(message) {
console.log('new message received!');
console.log(message);
message.id = counter++; // vue transitions need an id
data.messages.unshift(message);
console.log(data.messages);
data.keyword = message.keyword;
refreshScoreAverage();
}
function refreshScoreAverage() {
var sum = 0;
for (var i = 0; i < data.messages.length; i++) {
sum += parseFloat(data.messages[i].score);
}
data.scoreAvg = sum / data.messages.length;
console.log('Score avg: ' + data.scoreAvg);
}
</script>
</body>
</html>