signalk-race-control 0.12.4 → 0.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/app.js +28 -1
- package/public/index.html +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signalk-race-control",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.5",
|
|
4
4
|
"description": "SignalK plugin and webapp for tracking elapsed and handicap-corrected (Time-on-Time) race time, with a per-boat editable TCF and boat names pulled from AIS when available.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Joachim Bakke <github@heiamoss.com>",
|
package/public/app.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
const API = '/plugins/race-control';
|
|
3
3
|
const SK_API = '/signalk/v1/api';
|
|
4
|
+
const SK_API_V2 = '/signalk/v2/api';
|
|
4
5
|
|
|
5
6
|
let races = []; // race summaries from GET /races
|
|
6
7
|
let activeRaceId = null;
|
|
@@ -85,6 +86,8 @@
|
|
|
85
86
|
const addBoatRow = document.getElementById('addBoatRow');
|
|
86
87
|
const addBoatName = document.getElementById('addBoatName');
|
|
87
88
|
const addBoatClass = document.getElementById('addBoatClass');
|
|
89
|
+
const addBoatBuddyLabel = document.getElementById('addBoatBuddyLabel');
|
|
90
|
+
const addBoatBuddy = document.getElementById('addBoatBuddy');
|
|
88
91
|
const addBoatBtn = document.getElementById('addBoatBtn');
|
|
89
92
|
const classSection = document.getElementById('classSection');
|
|
90
93
|
const classToggleBtn = document.getElementById('classToggleBtn');
|
|
@@ -349,6 +352,7 @@
|
|
|
349
352
|
|
|
350
353
|
function selectSuggestion(item) {
|
|
351
354
|
addBoatName.value = item.name;
|
|
355
|
+
addBoatBuddyLabel.hidden = !findMmsiByName(item.name);
|
|
352
356
|
hideSuggestions();
|
|
353
357
|
addBoatName.focus();
|
|
354
358
|
}
|
|
@@ -812,6 +816,7 @@
|
|
|
812
816
|
// per boat afterward, in the table row.
|
|
813
817
|
const mmsi = findMmsiByName(name);
|
|
814
818
|
const classId = addBoatClass.value || null;
|
|
819
|
+
const addAsBuddy = addBoatBuddy.checked && !!mmsi;
|
|
815
820
|
try {
|
|
816
821
|
const boat = await fetchJSON(`${API}/races/${encodeURIComponent(activeRaceId)}/boats`, {
|
|
817
822
|
method: 'POST',
|
|
@@ -820,13 +825,32 @@
|
|
|
820
825
|
});
|
|
821
826
|
raceState.boats[boat.id] = boat;
|
|
822
827
|
addBoatName.value = '';
|
|
828
|
+
addBoatBuddyLabel.hidden = true;
|
|
823
829
|
addBoatName.focus();
|
|
824
830
|
render();
|
|
831
|
+
if (addAsBuddy) addBuddy(mmsi, name);
|
|
825
832
|
} catch (e) {
|
|
826
833
|
setStatus(e.message, true);
|
|
827
834
|
}
|
|
828
835
|
}
|
|
829
836
|
|
|
837
|
+
// Best-effort registration with the (optional, third-party)
|
|
838
|
+
// signalk-buddylist-plugin, so the boat's AIS target is labeled/highlighted
|
|
839
|
+
// for other Signal K clients too. Never blocks adding the boat itself —
|
|
840
|
+
// the plugin may not be installed at all, which shows up as a 404 here.
|
|
841
|
+
async function addBuddy(mmsi, name) {
|
|
842
|
+
try {
|
|
843
|
+
await fetchJSON(`${SK_API_V2}/resources/buddies`, {
|
|
844
|
+
method: 'POST',
|
|
845
|
+
headers: { 'Content-Type': 'application/json' },
|
|
846
|
+
body: JSON.stringify({ urn: `urn:mrn:imo:mmsi:${mmsi}`, name })
|
|
847
|
+
});
|
|
848
|
+
} catch (e) {
|
|
849
|
+
const reason = e.status === 404 ? 'buddy list plugin not installed' : e.message;
|
|
850
|
+
setStatus(`Boat added (buddy list: ${reason})`, true);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
830
854
|
async function addClass() {
|
|
831
855
|
if (!activeRaceId) return;
|
|
832
856
|
const name = addClassName.value.trim();
|
|
@@ -3227,7 +3251,10 @@
|
|
|
3227
3251
|
hideSuggestions();
|
|
3228
3252
|
addBoat();
|
|
3229
3253
|
});
|
|
3230
|
-
addBoatName.addEventListener('input', () =>
|
|
3254
|
+
addBoatName.addEventListener('input', () => {
|
|
3255
|
+
showSuggestionsFor(addBoatName.value);
|
|
3256
|
+
addBoatBuddyLabel.hidden = !findMmsiByName(addBoatName.value);
|
|
3257
|
+
});
|
|
3231
3258
|
addBoatName.addEventListener('focus', () => {
|
|
3232
3259
|
if (addBoatName.value.trim()) showSuggestionsFor(addBoatName.value);
|
|
3233
3260
|
});
|
package/public/index.html
CHANGED
|
@@ -195,6 +195,10 @@
|
|
|
195
195
|
<div id="addBoatSuggestions" class="suggestions" hidden></div>
|
|
196
196
|
</div>
|
|
197
197
|
<select id="addBoatClass" class="class-select" title="Class"></select>
|
|
198
|
+
<label id="addBoatBuddyLabel" class="multi-day-label" title="Also register this boat's MMSI in the Signal K buddy list (requires the signalk-buddylist-plugin)" hidden>
|
|
199
|
+
<input type="checkbox" id="addBoatBuddy" />
|
|
200
|
+
Buddy
|
|
201
|
+
</label>
|
|
198
202
|
<button id="addBoatBtn">Add Boat</button>
|
|
199
203
|
</div>
|
|
200
204
|
<div class="table-scroll">
|