Skip to content

Commit e2e5623

Browse files
committed
Initial commit
0 parents  commit e2e5623

File tree

7 files changed

+175
-0
lines changed

7 files changed

+175
-0
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/server"
5+
schedule:
6+
interval: "weekly"
7+
day: "thursday"

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
spring-shell.log
7+
8+
venv
9+
__pycache__
10+
11+
### STS ###
12+
.apt_generated
13+
.classpath
14+
.factorypath
15+
.project
16+
.settings
17+
.springBeans
18+
.sts4-cache
19+
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
25+
26+
### NetBeans ###
27+
/nbproject/private/
28+
/nbbuild/
29+
/dist/
30+
/nbdist/
31+
/.nb-gradle/
32+
build/
33+
!**/src/main/**/build/
34+
!**/src/test/**/build/
35+
36+
### VS Code ###
37+
.vscode/

server/app.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import uuid
2+
3+
from flask import Flask, request, Response, render_template, session
4+
5+
app = Flask(__name__)
6+
app.secret_key = 'really really secret key for a demo'
7+
8+
9+
@app.route('/')
10+
def home():
11+
return render_template('index.html')
12+
13+
14+
@app.route('/analytics', methods=['POST'])
15+
def click():
16+
if 'id' not in session:
17+
session['id'] = uuid.uuid4()
18+
session_id = session['id']
19+
data = request.get_json()
20+
app.logger.info('Event received: %s', data)
21+
data['session'] = session_id.hex
22+
app.logger.info('Event enriched: %s', data)
23+
return Response(status=202)
24+
25+
26+
if __name__ == '__main__':
27+
app.run()

server/requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
click==7.1.2
2+
Flask==1.1.2
3+
itsdangerous==1.1.0
4+
Jinja2==2.11.3
5+
MarkupSafe==1.1.1
6+
virtualenv==20.4.6
7+
Werkzeug==1.0.1

server/static/analytics.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function send(event) {
2+
function payload() {
3+
let json = {};
4+
json['timestamp'] = event.timeStamp;
5+
json['event'] = event.type;
6+
json['instant'] = Date.now();
7+
json['x'] = event.x;
8+
json['y'] = event.y;
9+
if (event.target) {
10+
const target = event.target;
11+
json['component'] = target.id;
12+
let offset = {};
13+
offset['left'] = target.offsetLeft;
14+
offset['height'] = target.offsetHeight;
15+
offset['top'] = target.offsetTop;
16+
offset['width'] = target.offsetWidth;
17+
json['offset'] = offset;
18+
let client = {};
19+
client['left'] = target.clientLeft;
20+
client['height'] = target.clientHeight;
21+
client['top'] = target.clientTop;
22+
client['width'] = target.clientWidth;
23+
json['client'] = client;
24+
let scroll = {};
25+
scroll['left'] = target.scrollLeft;
26+
scroll['height'] = target.scrollHeight;
27+
scroll['top'] = target.scrollTop;
28+
scroll['width'] = target.scrollWidth;
29+
json['scroll'] = scroll;
30+
json['type'] = target.type;
31+
json['value'] = target.value;
32+
}
33+
return json;
34+
}
35+
36+
const xhr = new XMLHttpRequest();
37+
xhr.open('POST', '/analytics');
38+
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
39+
xhr.send(JSON.stringify(payload()));
40+
}
41+
42+
document.getElementById("first-name").onchange = send;
43+
document.getElementById("last-name").onchange = send;
44+
document.getElementById("range").onchange = send;
45+
document.getElementById("first-button").onclick = send;
46+
document.getElementById("success-button").onclick = send;

server/static/hazelcast-logo-bug.svg

Lines changed: 1 addition & 0 deletions
Loading

server/templates/index.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
7+
integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
8+
<title>Hazelcast Click Playground</title>
9+
</head>
10+
<body>
11+
<div class="container">
12+
<nav class="navbar navbar-light" style="background-color: #e3f2fd;">
13+
<div class="container-fluid">
14+
<a class="navbar-brand">
15+
<img src="/static/hazelcast-logo-bug.svg" alt="" width="30" height="24"
16+
class="d-inline-block align-text-top">
17+
Hazelcast Click Playground
18+
</a>
19+
</div>
20+
</nav>
21+
<form>
22+
<div class="mb-3 form-floating">
23+
<input type="text" class="form-control" id="first-name" value="John">
24+
<label for="first-name">First name</label>
25+
</div>
26+
<div class="mb-3 form-floating">
27+
<input class="form-control" id="last-name" value="Doe">
28+
<label for="last-name" class="form-label">Last name</label>
29+
</div>
30+
<div class="mb-3 row">
31+
<div class="col-auto">
32+
<label for="range" class="form-label">Range</label>
33+
</div>
34+
<div class="col">
35+
<input type="range" class="form-range" id="range">
36+
</div>
37+
</div>
38+
<div class="mb-3 row justify-content-evenly">
39+
<div class="col-1">
40+
<input type="button" class="btn btn-success" id="success-button" value="Success">
41+
</div>
42+
<div class="col-1">
43+
<input type="button" class="btn btn-primary" id="first-button" value="Primary">
44+
</div>
45+
</div>
46+
</form>
47+
</div>
48+
<script src="/static/analytics.js"></script>
49+
</body>
50+
</html>

0 commit comments

Comments
 (0)