-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample-create-meta.html
156 lines (137 loc) · 4.95 KB
/
sample-create-meta.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
149
150
151
152
153
154
155
156
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<title>VXG AI Meta loader</title>
<!-- frameworks -->
<script src="frw/jquery.min.js"></script>
<script src="frw/jquery-ui.min.js"></script>
<script src="frw/jquery.formatDateTime.js"></script>
<script src="frw/datetimepicker.full.min.js"></script>
<link rel="stylesheet" type="text/css" href="frw/bootstrap.min.css">
<script src="frw/bootstrap.min.js"></script>
<style>
#tokenContainer {
width: 700px;
}
.btn {
color: white;
background-color: #a0cf4d;
}
table td {
text-align: center;
padding: 5px;
}
td.middle-color > div {
width: 40px;
height: 40px;
}
.subitem {
display: inline-block;
width: fit-content;
}
.container > div {
margin-top: 30px;
}
.rm-btn {
background-color: white;
border-color: white;
font-size: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Create Meta</h1>
<div class="form-inline" role="form">
<h3>Select a camera</h3>
<div class="form-group ">
<div class="input-group ">
<input id="tokenContainer" type="text" class="form-control" placeholder="Enter access token"
value="token">
</div>
</div>
</div>
<h3>Fill meta</h3>
<div>
<h4>Timestamp</h4>
<input type="datetime-local" name="timestamp" step="2" required
class="form-control form-control-lg subitem">
</div>
<div>
<h4>Key - value</h4>
<div id="key-value-container"></div>
<input type="button" class="btn btn-default subitem" value="Add" onclick="addItem()">
</div>
<div>
<h4>Raw data</h4>
<textarea class="form-control" style="width: 50%" rows="3"></textarea>
</div>
<div style="margin-top:10px;">
<button id="send" class="btn btn-default" onclick="sendMeta()">Add meta</button>
<div id="result"></div>
</div><br/>
<div id="result-container"></div>
</div>
<script>
let currentId = 1;
const changeValueType = (select) => {
if (select.value === 'string') {
select.parentNode.querySelector('[name=value]').type = 'text';
} else if (select.value === 'long') {
select.parentNode.querySelector('[name=value]').type = 'number';
select.parentNode.querySelector('[name=value]').step = '1';
} else if (select.value === 'float') {
select.parentNode.querySelector('[name=value]').type = 'number';
select.parentNode.querySelector('[name=value]').step = '0.00001';
}
};
const addItem = () => {
$('#key-value-container').append(`
<div class="form-group item" id="item-${currentId}">
<select name="type" class="form-control subitem" onchange="changeValueType(this)">
<option value="long">Long</option>
<option value="float">Float</option>
<option value="string">String</option>
</select>
<input type="text" name="key" placeholder="Key" class="form-control form-control-lg subitem">
<input type="number" step="1" placeholder="value" name="value" class="form-control form-control-lg subitem">
<input type="button" value="❌" onclick="$('#item-${currentId}').remove()" class="rm-btn">
</div>
`);
currentId++;
};
const drawResult = (r) => {
let k = r['objects'][0], t;
if (k.status === 201) t = `<div>✓ ${k['id']}</div>`;
else t = `<div>❌ ${JSON.stringify(k)}</div>`;
$('#result-container').append(t)
}
const sendMeta = () => {
let data = {
timestamp: $('[name=timestamp]').val(),
long: {}, float: {}, string: {},
}
for (let elem of Array.from($('.item'))) {
let [type, key, value] = ['type', 'key', 'value'].map((r) => {
return elem.querySelector('[name=' + r + ']').value
});
if (type !== 'string') value = Number(value);
data[type][key] = value;
}
return $.post({
url: 'https://web.skyvr.videoexpertsgroup.com/api/v4/meta/',
dataType: 'json',
data: JSON.stringify([data]),
headers: {
'Authorization': 'Acc ' + $('#tokenContainer').val(),
'Content-Type': 'application/json',
'Accept': 'application/json',
},
}).then(drawResult)
};
document.addEventListener("DOMContentLoaded", () => { // Add first item
addItem()
});
</script>
</body>