Skip to content

Commit 2457a58

Browse files
committed
replace jquery by async
1 parent 92cb549 commit 2457a58

8 files changed

+24
-28
lines changed

activityStats2.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
<body>
1111
<script src="lib/echarts-5.4.2.min.js"></script>
12-
<script src="lib/jquery-3.7.0.min.js"></script>
1312
<select id="sel-date-agg">
1413
<option value="year">Year</option>
1514
<option value="quarter">Quarter</option>
@@ -37,7 +36,7 @@
3736
<div id="div-chart" style="width: 100%;height:600px;"></div>
3837
<div id="div-chart-act-count" style="width: 100%;height:600px;"></div>
3938
<script>
40-
const session = "SessionIDPlaceholder";
39+
const session = "SessionIdPlaceholder";
4140
</script>
4241
<script src="activityStats2.js"></script>
4342
</body>

activityStats2.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ const promises = []; // array of promises for async fetching
2222
//
2323
// Data fetching
2424
//
25-
function fetch_data(session, date_agg) {
25+
const fetch_data = async (session, date_agg) => {
2626
const url = `https://entorb.net/strava/download/${session}/activityStats2_${date_agg}.json`;
27-
return $.getJSON(url)
28-
.done(function (data) {
29-
console.log("done data download " + date_agg);
30-
data_all[date_agg] = data;
31-
})
32-
.fail(function () {
33-
console.log("failed data download " + date_agg);
34-
});
35-
}
27+
try {
28+
const response = await fetch(url);
29+
const data = await response.json();
30+
console.log(`done data download ${date_agg}`);
31+
data_all[date_agg] = data;
32+
} catch (error) {
33+
console.log(`failed data download ${date_agg}`);
34+
}
35+
};
3636

3737
// Start the async fetching
3838
promises.push(fetch_data(session, "month"));

activityStats2.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
my $cont = do { local $/ = undef; <$fhIn> };
7070
close $fhIn;
7171
$cont =~ s/^.*<body>(.*)<\/body>.*/$1/s;
72-
$cont =~ s/SessionIDPlaceholder/$s{'session'}/s;
72+
$cont =~ s/SessionIdPlaceholder/$s{'session'}/s;
7373
say $cont;
7474
} ## end if ( $res->code() == 200)
7575
else {

activityTable.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99

1010
<body>
1111
<div id="table-activity-list"></div>
12-
<script src="lib/jquery-3.7.0.min.js"></script>
1312
<link href="lib/tabulator.min.css" rel="stylesheet">
1413
<script src="lib/tabulator-5.4.min.js"></script>
1514
<script src="./activityTable.js"></script>
1615
<script>
17-
const session = "SessionIDPlaceholder";
16+
const session = "SessionIdPlaceholder";
1817
</script>
1918
</body>
2019

activityTable.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable camelcase */
22
/* eslint-disable require-jsdoc */
3-
("use strict");
3+
"use strict";
44

55
// eslint-disable-next-line no-unused-vars
66
function defineTable() {
@@ -260,15 +260,13 @@ function defineTable() {
260260

261261
const table = defineTable();
262262

263-
table.on("tableBuilt", function () {
264-
table.setData(
265-
"https://entorb.net/strava/./download/" + session + "/activityList.json"
266-
);
263+
table.on("tableBuilt", () => {
264+
table.setData(`https://entorb.net/strava/download/${session}/activityList.json`);
267265
});
268266

269-
table.on("cellClick", function (e, cell) {
267+
table.on("cellClick", (e, cell) => {
270268
const row = cell.getRow();
271269
const rowData = row.getData();
272-
const activityUrl = rowData["x_url"];
270+
const activityUrl = rowData.x_url;
273271
window.open(activityUrl);
274272
});

activityTable.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
my $cont = do { local $/ = undef; <$fhIn> };
4141
close $fhIn;
4242
$cont =~ s/^.*<body>(.*)<\/body>.*/$1/s;
43-
$cont =~ s/SessionIDPlaceholder/$s{'session'}/s;
43+
$cont =~ s/SessionIdPlaceholder/$s{'session'}/s;
4444

4545
say $cont;
4646

scripts/download_libs.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ mv tmp-dl/tabulator-$ver/dist/js/tabulator.min.js.map lib/tabulator.min.js.map
2626
mv tmp-dl/tabulator-$ver/dist/css/tabulator.min.css lib/tabulator.min.css
2727
mv tmp-dl/tabulator-$ver/dist/css/tabulator.min.css.map lib/tabulator.min.css.map
2828

29-
# JQuery
30-
ver=3.7.0
31-
wget -q https://code.jquery.com/jquery-$ver.min.js -O lib/jquery-$ver.min.js
32-
wget -q https://code.jquery.com/jquery-$ver.min.map -O lib/jquery-$ver.min.map
29+
# # JQuery
30+
# ver=3.7.0
31+
# wget -q https://code.jquery.com/jquery-$ver.min.js -O lib/jquery-$ver.min.js
32+
# wget -q https://code.jquery.com/jquery-$ver.min.map -O lib/jquery-$ver.min.map
3333

3434
# Cleanup
3535
rm -r tmp-dl

scripts/sync_from_server.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
script_dir=$(cd $(dirname $0) && pwd)
55
cd $script_dir/..
66

7-
rm *.pl *.pm *.html gnuplot/*
7+
# rm *.pl *.pm *.html gnuplot/*
88
rsync -rvhu --exclude=download [email protected]:html/strava/ ./

0 commit comments

Comments
 (0)