Skip to content

Commit

Permalink
chore: docs and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj committed May 19, 2024
1 parent fda2996 commit ebdd3d5
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 330 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG: Freeboard

### v2.8.0

- **Added**: Option to display laylines when destination is active. (#149)
- **Added**: Support for Signal K server "Features" API.
- **Updated**: Measure function to display both segment and total distance. (#153)
- **Updated**: Clearing an alarm no longer sets the value to `null`, sets alarm state to normal instead.


### v2.7.1

- **Added**: Set a default waypoint name when adding a waypoint at vessel position. (#146)
Expand Down
83 changes: 66 additions & 17 deletions helper/alarms/alarms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
ALARM_STATE,
Path,
PathValue,
Position
Position,
SKVersion
} from '@signalk/server-api';
import { FreeboardHelperApp } from '../index';

Expand All @@ -24,6 +25,7 @@ const STANDARD_ALARMS = [

let server: FreeboardHelperApp;
let pluginId: string;
const ALARM_API_PATH = '/signalk/v1/api/alarms';

export const initAlarms = (app: FreeboardHelperApp, id: string) => {
server = app;
Expand All @@ -48,12 +50,11 @@ export const initAlarms = (app: FreeboardHelperApp, id: string) => {

const initAlarmEndpoints = () => {
server.debug(`** Registering Alarm Action API endpoint(s) **`);
server.put(
'/signalk/v2/api/notifications/:alarmType',

server.post(
`${ALARM_API_PATH}/:alarmType`,
(req: Request, res: Response, next: NextFunction) => {
server.debug(
`** PUT /signalk/v2/api/notifications/${req.params.alarmType}`
);
server.debug(`** POST ${ALARM_API_PATH}/${req.params.alarmType}`);
if (!STANDARD_ALARMS.includes(req.params.alarmType)) {
next();
return;
Expand Down Expand Up @@ -82,12 +83,57 @@ const initAlarmEndpoints = () => {
}
}
);
server.post(
`${ALARM_API_PATH}/:alarmType/silence`,
(req: Request, res: Response) => {
server.debug(`** POST ${req.path}`);
if (!STANDARD_ALARMS.includes(req.params.alarmType)) {
res.status(200).json({
state: 'COMPLETED',
statusCode: 200,
message: `Unsupported Alarm (${req.params.alarmType}).`
});
return;
}
try {
const al = server.getSelfPath(`notifications.${req.params.alarmType}`);
if (al && al.value) {
server.debug('Alarm value....');
if (al.value.method && al.value.method.includes('sound')) {
server.debug('Alarm has sound... silence!!!');
al.value.method = al.value.method.filter((i) => i !== 'sound');
const r = handlePutAlarmState(
'vessels.self',
`notifications.${req.params.alarmType}` as Path,
al.value
);
res.status(200).json(r);
} else {
server.debug('Alarm has no sound... no action required.');
res.status(200).json({
state: 'COMPLETED',
statusCode: 200,
message: `Alarm (${req.params.alarmType}) is already silent.`
});
}
} else {
throw new Error(
`Alarm (${req.params.alarmType}) has no value or was not found!`
);
}
} catch (e) {
res.status(400).json({
state: 'FAILED',
statusCode: 400,
message: (e as Error).message
});
}
}
);
server.delete(
'/signalk/v2/api/notifications/:alarmType',
`${ALARM_API_PATH}/:alarmType`,
(req: Request, res: Response, next: NextFunction) => {
server.debug(
`** DELETE /signalk/v2/api/notifications/${req.params.alarmType}`
);
server.debug(`** DELETE ${ALARM_API_PATH}/${req.params.alarmType}`);
if (!STANDARD_ALARMS.includes(req.params.alarmType)) {
next();
return;
Expand All @@ -96,7 +142,11 @@ const initAlarmEndpoints = () => {
const r = handlePutAlarmState(
'vessels.self',
`notifications.${req.params.alarmType}` as Path,
null
{
message: '',
method: [],
state: ALARM_STATE.normal
}
);
res.status(200).json(r);
} catch (e) {
Expand Down Expand Up @@ -137,16 +187,16 @@ const handlePutAlarmState = (
server.debug(JSON.stringify(alarmType));
let noti: PathValue;
if (value) {
const alm = buildAlarmMessage(value.message);
const alm = value.state === ALARM_STATE.normal ? null : buildAlarmData();
noti = {
path: `notifications.${alarmType}` as Path,
value: {
state: value.state ?? null,
method: value.method ?? null,
message: alm.message
message: value.message
}
};
if (alm.data) {
if (alm && alm.data) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(noti.value as any).data = alm.data;
}
Expand All @@ -171,10 +221,9 @@ const handlePutAlarmState = (
}
};

const buildAlarmMessage = (message: string) => {
const buildAlarmData = () => {
const pos: { value: Position } = server.getSelfPath('navigation.position');
return {
message: message,
data: {
position: pos ? pos.value : null
}
Expand All @@ -186,5 +235,5 @@ const emitNotification = (msg: PathValue) => {
const delta = {
updates: [{ values: [msg] }]
};
server.handleMessage(pluginId, delta);
server.handleMessage(pluginId, delta, SKVersion.v2);
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@signalk/freeboard-sk",
"version": "2.7.1",
"version": "2.8.0",
"description": "Openlayers chart plotter implementation for Signal K",
"keywords": [
"signalk-webapp",
Expand Down Expand Up @@ -87,6 +87,7 @@
"proj4": "2.6.2",
"protractor": "~7.0.0",
"rxjs": "~6.6.3",
"semver": "^7.6.0",
"signalk-client-angular": "^2.0.3",
"signalk-worker-angular": "^1.1.4",
"simplify-ts": "^1.0.2",
Expand All @@ -97,4 +98,4 @@
"xml2js": "^0.6.2",
"zone.js": "~0.14.4"
}
}
}
29 changes: 13 additions & 16 deletions src/app/lib/components/build-route.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,19 @@ import {
(cdkDropListDropped)="dropEventHandler($event)"
>
@for(item of rtepts; track item; let idx = $index) {
<div
class="wpt-box"
mat-background
cdkDrag
>
<div style="width:40px;">
<mat-icon color="primary">room</mat-icon>
</div>
<div class="wpt-text" [matTooltip]="item.name">
{{ item.name }}
</div>
<div style="width:40px;">
<button mat-icon-button (click)="deleteFromRoute(idx)">
<mat-icon color="warn">delete</mat-icon>
</button>
</div>
<div class="wpt-box" mat-background cdkDrag>
<div style="width:40px;">
<mat-icon color="primary">room</mat-icon>
</div>
<div class="wpt-text" [matTooltip]="item.name">
{{ item.name }}
</div>
<div style="width:40px;">
<button mat-icon-button (click)="deleteFromRoute(idx)">
<mat-icon color="warn">delete</mat-icon>
</button>
</div>
</div>
}
</div>
</div>
Expand All @@ -149,6 +145,7 @@ export class BuildRouteComponent {
wpts = [];
rtepts = [];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
@Output() save: EventEmitter<any> = new EventEmitter();

constructor(
Expand Down
5 changes: 2 additions & 3 deletions src/app/lib/components/dial-text.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Text Dial Component **
************************/

import { Component, Input } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';

/*********** Text Dial ***************
title: "<string>" title text,
Expand All @@ -10,6 +10,7 @@ units: "<string>" dsisplay units,
***********************************/
@Component({
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'ap-dial-text',
imports: [],
template: `
Expand All @@ -25,6 +26,4 @@ export class TextDialComponent {
@Input() title: string;
@Input() value: string;
@Input() units: string;

//constructor() {}
}
72 changes: 36 additions & 36 deletions src/app/lib/components/dialogs/common/dialogs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,48 +477,48 @@ export class MessageBarComponent {
<div class="welcome">
<mat-horizontal-stepper [linear]="false" #stepper>
@for(c of data.content; track c; let i = $index) {
<mat-step>
<div style="text-align:center;">
<h3>{{ c.title }}</h3>
<mat-step>
<div style="text-align:center;">
<h3>{{ c.title }}</h3>
</div>
<div style="display:flex;">
<div style="min-width:50px;text-align:left;padding-top: 15%;">
@if(i !== 0 && data.content.length > 1) {
<button
mat-icon-button
(click)="currentPage = currentPage - 1"
color="primary"
matStepperPrevious
>
<mat-icon>keyboard_arrow_left</mat-icon>
</button>
}
</div>
<div style="display:flex;">
<div style="min-width:50px;text-align:left;padding-top: 15%;">
@if(i !== 0 && data.content.length > 1) {
<button
mat-icon-button
(click)="currentPage = currentPage - 1"
color="primary"
matStepperPrevious
>
<mat-icon>keyboard_arrow_left</mat-icon>
</button>
}
</div>
<div style="flex: 1 1 auto;" [innerHTML]="c.message"></div>
<div style="min-width:50px;text-align:right;padding-top: 15%;">
@if(i !== data.content.length - 1) {
<button
mat-icon-button
(click)="currentPage = currentPage + 1"
color="primary"
matStepperNext
>
<mat-icon>keyboard_arrow_right</mat-icon>
</button>
}
</div>
<div style="flex: 1 1 auto;" [innerHTML]="c.message"></div>
<div style="min-width:50px;text-align:right;padding-top: 15%;">
@if(i !== data.content.length - 1) {
<button
mat-icon-button
(click)="currentPage = currentPage + 1"
color="primary"
matStepperNext
>
<mat-icon>keyboard_arrow_right</mat-icon>
</button>
}
</div>
</mat-step>
</div>
</mat-step>
}
</mat-horizontal-stepper>
<div style="text-align:center;font-size:10pt;font-family:roboto;">
@for(c of data.content; track c; let i = $index) {
<mat-icon
[style.color]="currentPage - 1 === i ? 'blue' : 'gray'"
style="font-size:8pt;width:12px;"
>
fiber_manual_record
</mat-icon>
<mat-icon
[style.color]="currentPage - 1 === i ? 'blue' : 'gray'"
style="font-size:8pt;width:12px;"
>
fiber_manual_record
</mat-icon>
}
</div>
<div style="text-align:center;">
Expand Down
Loading

0 comments on commit ebdd3d5

Please sign in to comment.