Skip to content

Commit 1c338ae

Browse files
authored
Purge jQuery dependency (#55)
Now the configuration UI only uses native JavaScript. This means we expect no ancient browsers to be used for configuring this application, and also removed the jQuery dependency. Also update to use ACAP SDK 12.6. Signed-off-by: Joakim Roubert <[email protected]>
1 parent a71648c commit 1c338ae

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG ARCH=aarch64
2-
ARG SDK_VERSION=12.2.0
2+
ARG SDK_VERSION=12.6.0
33
ARG SDK_IMAGE=docker.io/axisecp/acap-native-sdk
44
ARG DEBUG_WRITE
55
ARG BUILD_DIR=/opt/build

html/js/jquery-3.6.1.min.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

html/js/opcuagaugereader.js

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright (C) 2025, Axis Communications AB, Lund, Sweden
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
const w = 640;
218
const h = 360;
319
const msize = 5;
@@ -7,9 +23,10 @@ const State = {
723
Min: Symbol(2),
824
Max: Symbol(3)
925
}
26+
const paramappname = 'Opcuagaugereader';
1027
const parambaseurl = '/axis-cgi/param.cgi?action=';
11-
const paramgeturl = parambaseurl + 'list&group=opcuagaugereader.';
12-
const paramseturl = parambaseurl + 'update&opcuagaugereader.';
28+
const paramgeturl = `${parambaseurl}list&group=${paramappname}.`;
29+
const paramseturl = `${parambaseurl}update&${paramappname}.`;
1330
var points = {};
1431
points['centerX'] = 0;
1532
points['centerY'] = 0;
@@ -19,7 +36,7 @@ points['maxX'] = 0;
1936
points['maxY'] = 0;
2037

2138
function getPointText(param) {
22-
return param + ': (' + points[param + 'X'] + ', ' + points[param + 'Y'] + ')';
39+
return `${param}: (${points[`${param}X`]}, ${points[`${param}Y`]})`;
2340
}
2441

2542
function drawMarker(X, Y, color) {
@@ -31,7 +48,7 @@ function drawMarker(X, Y, color) {
3148
ctx.arc(X, Y, msize, 1, 2 * Math.PI, false);
3249
ctx.stroke();
3350
document.getElementById("values").textContent =
34-
getPointText('center') + ' ' + getPointText('min') + ' ' + getPointText('max');
51+
`${getPointText('center')} ${getPointText('min')} ${getPointText('max')}`;
3552
}
3653

3754
function drawCenter() {
@@ -54,25 +71,35 @@ function drawDefaultPoints() {
5471
}
5572

5673
function getCurrentValue(param) {
57-
$.get(paramgeturl + param)
58-
.done(function(data) {
59-
points[param] = data.split('=')[1];
60-
console.log('Got ' + param + ' value ' + points[param]);
61-
drawDefaultPoints();
74+
return fetch(`${paramgeturl}${param}`)
75+
.then(response => {
76+
if (!response.ok) {
77+
throw new Error(`Getting parameter value, the network response was not ok: ${response.status} ${response.statusText}`);
78+
}
79+
return response.text();
80+
})
81+
.then(data => {
82+
var value = data.split('=')[1];
83+
console.log(`Got ${param} value ${value}`);
84+
return Number(value);
6285
})
63-
.fail(function(data) {
64-
alert('FAILED to get ' + param);
86+
.catch(error => {
87+
alert(`FAILED to get ${param}`);
88+
throw error;
6589
});
6690
}
6791

6892
function setParam(param, value) {
6993
points[param] = value;
70-
$.get(paramseturl + param + '=' + value)
71-
.done(function(data) {
72-
console.log('Set ' + param + ' to ' + value);
94+
fetch(`${paramseturl}${param}=${value}`)
95+
.then(response => {
96+
if (!response.ok) {
97+
throw new Error(`Setting parameter value, the network response was not ok: ${response.status} ${response.statusText}`);
98+
}
99+
console.log(`Set ${param} to ${value}`);
73100
})
74-
.fail(function(jqXHR, textStatus, errorThrown) {
75-
alert('FAILED to set ' + param);
101+
.catch(error => {
102+
alert(`FAILED to set ${param}: ${error.message}`);
76103
});
77104
}
78105

@@ -129,7 +156,7 @@ var draw = document.getElementById('draw');
129156
var infoTxt = document.getElementById('info');
130157
preview.width = preview.style.width = draw.width = w;
131158
preview.height = preview.style.height = draw.height = h;
132-
preview.src = '/axis-cgi/mjpg/video.cgi?resolution=' + w + 'x' + h;
159+
preview.src = `/axis-cgi/mjpg/video.cgi?resolution=${w}x${h}`;
133160
var ctx = draw.getContext('2d');
134161
initWithCurrentValues();
135162
handleCoord(0, 0);

html/settings.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ <h1>Gauge Reader Settings</h1>
3232
<p id="values" style="font-style: italic;">x: , y:</p>
3333
</div>
3434

35-
<script src="js/jquery-3.6.1.min.js"></script>
3635
<script src="js/opcuagaugereader.js"></script>
3736
</body>
3837
</html>

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"schemaVersion": "1.7.3",
2+
"schemaVersion": "1.7.4",
33
"acapPackageConf": {
44
"setup": {
55
"friendlyName": "OPC UA Gauge Reader",
@@ -8,7 +8,7 @@
88
"embeddedSdkVersion": "3.0",
99
"vendorUrl": "https://www.axis.com/",
1010
"runMode": "respawn",
11-
"version": "2.0.8"
11+
"version": "2.1.0"
1212
},
1313
"configuration": {
1414
"settingPage": "settings.html",

0 commit comments

Comments
 (0)