Dawnline 0.11.0
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Canceled after 0s
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Canceled after 0s
CI / ucode static checks (push) Canceled after 0s
CI / ShellCheck (push) Canceled after 0s
CI / Web (format, types, tests, bundles) (push) Canceled after 0s
Build packages / CI (push) Canceled after 0s
Build packages / Version (push) Canceled after 0s
Build packages / Build apk (push) Canceled after 0s
Build packages / Build ipk (push) Canceled after 0s
Build packages / Release (push) Canceled after 0s
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Canceled after 0s
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Canceled after 0s
CI / ucode static checks (push) Canceled after 0s
CI / ShellCheck (push) Canceled after 0s
CI / Web (format, types, tests, bundles) (push) Canceled after 0s
Build packages / CI (push) Canceled after 0s
Build packages / Version (push) Canceled after 0s
Build packages / Build apk (push) Canceled after 0s
Build packages / Build ipk (push) Canceled after 0s
Build packages / Release (push) Canceled after 0s
- Russian translation. The admin pages, the LuCI menu and the router's messages (errors, Health checks, update steps, the service log) come in Russian with the new luci-i18n-dawnline-ru package, released beside the app. LuCI shows it when its language is Russian, or "auto" with a Russian browser - The translation installs with install.sh when LuCI is in Russian (or with --lang ru), follows every Dawnline update and rollback, and can be added or removed in Components → Dawnline → Translation - The portal speaks the visitor's language: it opens in the system's language and switches between English and Russian in place, from the language pill beside its QR code. It carries its own translation and needs no package - Set-up steps quote the apps' own menus word for word, in Russian too: AmneziaVPN is "+ → Insert → Continue" (it has no "Add server"), and the Mac and Windows menus of WireGuard and AmneziaWG have their real names - Questions in the portal (Reconnect, Remove) read from the left edge and close with Cancel, without × - Numbers, sizes and dates follow the page's language. A server that can't start says why in one sentence; event details and service log lines read as whole sentences - README in Russian (README_ru.md). rules/i18n.md: how strings are written and translated; CI checks the catalogs (npm run i18n:check)
This commit is contained in:
1 parent
caed976e63
commit
2f2aaf6c34
173 files changed
+25645
-2823
No files matched your search
@@ -4,6 +4,7 @@ import { E } from '../../e';
|
||||
import { button } from '../../ui/button';
|
||||
import { dropdown } from '../../ui/menu';
|
||||
import { icon } from '../../../shared/icons';
|
||||
import { fill, fmt, num, plural } from '../../../shared/i18n';
|
||||
import { ConnectionMap, rangeControl } from '../../map';
|
||||
import { eventRow, eventText } from '../../events/render';
|
||||
import { clearLogDialog, exportEvents } from '../../logs';
|
||||
@@ -13,11 +14,11 @@ import type { PersonPage } from './index';
|
||||
function mapCard(page: PersonPage): HTMLElement {
|
||||
const st = page.st;
|
||||
const head = E('div', { class: 'dl-panel-head pad' }, [
|
||||
E('h3', {}, 'Locations'),
|
||||
E('h3', {}, _('Locations')),
|
||||
E('span', { class: 'dl-spacer' }),
|
||||
st.geo.enabled ? rangeControl('30d', (r) => page.map?.setRange(r), false) : '',
|
||||
button(
|
||||
'Hide',
|
||||
_('Hide'),
|
||||
() => {
|
||||
page.mapOpen = false;
|
||||
page.map?.destroy();
|
||||
@@ -30,11 +31,11 @@ function mapCard(page: PersonPage): HTMLElement {
|
||||
if (!st.geo.enabled)
|
||||
return E('div', { class: 'dl-panel flush' }, [
|
||||
head,
|
||||
E('div', { class: 'dl-map-off' }, [
|
||||
'Locations are off. ',
|
||||
E('a', { href: L.url('admin/network/dawnline/settings') }, 'Turn them on in Settings'),
|
||||
'.',
|
||||
]),
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-map-off' },
|
||||
fill(_('Locations are off. %s.'), E('a', { href: L.url('admin/network/dawnline/settings') }, _('Turn them on in Settings'))),
|
||||
),
|
||||
]);
|
||||
const map = new ConnectionMap(
|
||||
{
|
||||
@@ -59,11 +60,11 @@ export function placesPart(page: PersonPage): HTMLElement | null {
|
||||
return E('div', { class: 'dl-places' }, [
|
||||
icon('pin'),
|
||||
E('div', { class: 'dl-stack' }, [
|
||||
E('span', {}, 'Locations are off'),
|
||||
E('span', { class: 'dl-sub' }, 'City-level, from the client IP'),
|
||||
E('span', {}, _('Locations are off')),
|
||||
E('span', { class: 'dl-sub' }, _('City-level, from the client IP')),
|
||||
]),
|
||||
E('span', { class: 'dl-spacer' }),
|
||||
E('a', { class: 'cbi-button cbi-button-neutral', href: L.url('admin/network/dawnline/settings') }, 'Turn on'),
|
||||
E('a', { class: 'cbi-button cbi-button-neutral', href: L.url('admin/network/dawnline/settings') }, _('Turn on')),
|
||||
]);
|
||||
if (page.mapOpen) return page.map && page.parts.places.contains(page.map.el) ? null : mapCard(page);
|
||||
const since = st.now - 30 * 86400;
|
||||
@@ -73,19 +74,19 @@ export function placesPart(page: PersonPage): HTMLElement | null {
|
||||
return E('div', { class: 'dl-places' }, [
|
||||
icon('pin'),
|
||||
E('div', { class: 'dl-stack' }, [
|
||||
E('span', {}, last ? last.city || last.country : 'No locations yet'),
|
||||
E('span', {}, last ? last.city || last.country : _('No locations yet')),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
last
|
||||
? `${places.length} place${places.length === 1 ? '' : 's'} in 30 days${last.org ? ` · ${last.org}` : ''}`
|
||||
: 'Shown after a device connects',
|
||||
? [plural(places.length, '%s place in 30 days', '%s places in 30 days'), last.org].filter(Boolean).join(' · ')
|
||||
: _('Shown after a device connects'),
|
||||
),
|
||||
]),
|
||||
E('span', { class: 'dl-spacer' }),
|
||||
pts.length
|
||||
? button(
|
||||
'Show map',
|
||||
_('Show map'),
|
||||
() => {
|
||||
page.mapOpen = true;
|
||||
page.paintPlaces();
|
||||
@@ -110,7 +111,7 @@ export function activityPart(page: PersonPage): HTMLElement {
|
||||
const row = eventRow(st, e, { server: false });
|
||||
if (n > 1) {
|
||||
const main = row.querySelector('.dl-row-main') as HTMLElement;
|
||||
dom.content(main, [...eventText(st, e).slice(0, 3), E('span', { class: 'dl-muted' }, `${n} times`)]);
|
||||
dom.content(main, [...eventText(st, e).slice(0, 3), E('span', { class: 'dl-muted' }, plural(n, '%s time', '%s times'))]);
|
||||
main.title = latest
|
||||
.slice(i, i + n)
|
||||
.map((x) => x.detail ?? '')
|
||||
@@ -123,29 +124,32 @@ export function activityPart(page: PersonPage): HTMLElement {
|
||||
[icon('more')],
|
||||
() =>
|
||||
dropdown(more, [
|
||||
{ label: 'Export CSV', icon: icon('download'), run: () => exportEvents(st, all, 'csv', p.id) },
|
||||
{ label: 'Export JSON', icon: icon('download'), run: () => exportEvents(st, all, 'json', p.id) },
|
||||
{ label: _('Export CSV'), icon: icon('download'), run: () => exportEvents(st, all, 'csv', p.id) },
|
||||
{ label: _('Export JSON'), icon: icon('download'), run: () => exportEvents(st, all, 'json', p.id) },
|
||||
null,
|
||||
{
|
||||
label: `Clear ${p.name}'s activity`,
|
||||
label: fmt(_("Clear %s's activity"), p.name),
|
||||
icon: icon('trash'),
|
||||
danger: true,
|
||||
run: () =>
|
||||
clearLogDialog(`Clear ${p.name}'s activity`, `Removes events about ${p.name} and their devices.`, { person: p.id }, () =>
|
||||
page.refresh(),
|
||||
clearLogDialog(
|
||||
fmt(_("Clear %s's activity"), p.name),
|
||||
fmt(_('Removes events about %s and their devices.'), p.name),
|
||||
{ person: p.id },
|
||||
() => page.refresh(),
|
||||
),
|
||||
},
|
||||
]),
|
||||
'neutral',
|
||||
{ title: 'Export or clear', class: 'cbi-button cbi-button-neutral dl-icon-only' },
|
||||
{ title: _('Export or clear'), class: 'cbi-button cbi-button-neutral dl-icon-only' },
|
||||
);
|
||||
return E('div', { class: 'dl-panel flush' }, [
|
||||
E('div', { class: 'dl-panel-head pad' }, [
|
||||
E('h3', {}, 'Activity'),
|
||||
E('span', { class: 'dl-sub' }, all.length > 10 ? `latest 10 of ${all.length}` : ''),
|
||||
E('h3', {}, _('Activity')),
|
||||
E('span', { class: 'dl-sub' }, all.length > 10 ? fmt(_('latest 10 of %s'), num(all.length)) : ''),
|
||||
E('span', { class: 'dl-spacer' }),
|
||||
more,
|
||||
]),
|
||||
rows.length ? rows : E('div', { class: 'dl-row dl-muted' }, 'Nothing yet.'),
|
||||
rows.length ? rows : E('div', { class: 'dl-row dl-muted' }, _('Nothing yet.')),
|
||||
]);
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import { downloadFile } from '../../ui/files';
|
||||
import { attempt, notify } from '../../ui/toast';
|
||||
import { deviceStatus } from '../../ui/badges';
|
||||
import { icon } from '../../../shared/icons';
|
||||
import { KIND_LABEL, ago, byDeviceState, bytes } from '../../../shared/format';
|
||||
import { kindLabel, ago, byDeviceState, bytes } from '../../../shared/format';
|
||||
import { fmt, num } from '../../../shared/i18n';
|
||||
import { addDevice, openDevice, quickMenu } from '../../device';
|
||||
import { dayBars } from '../../widgets/tiles';
|
||||
import type { PersonPage } from './index';
|
||||
@@ -18,14 +19,14 @@ import type { PersonPage } from './index';
|
||||
async function showDeviceQr(page: PersonPage, d: Device) {
|
||||
const cfg = await attempt(() => api.deviceConfig(d.id));
|
||||
if (!cfg) return;
|
||||
modal(`Set up ${d.name}`, [await page.core.connectBlock(cfg, 'qr')], [cancelButton('Close')]);
|
||||
modal(fmt(_('Set up %s'), d.name), [await page.core.connectBlock(cfg, 'qr')], [cancelButton(_('Close'))]);
|
||||
}
|
||||
|
||||
async function downloadConfig(page: PersonPage, d: Device) {
|
||||
const cfg = await attempt(() => api.deviceConfig(d.id));
|
||||
if (!cfg) return;
|
||||
if (!cfg.has_private_key) {
|
||||
notify('This device made its own keys in the browser; its configuration only exists there.', 'warning');
|
||||
notify(_('This device made its own keys in the browser; its configuration only exists there.'), 'warning');
|
||||
return;
|
||||
}
|
||||
const f = page.core.file.make(cfg);
|
||||
@@ -42,7 +43,7 @@ export function devicesPart(page: PersonPage): HTMLElement {
|
||||
};
|
||||
const more = (d: Device) =>
|
||||
button([icon('more')], (ev: MouseEvent) => quickMenu(ev.currentTarget as HTMLElement, p, d, page.deviceOpts()), 'neutral', {
|
||||
title: 'QR, file, key, rename, new keys, remove',
|
||||
title: _('QR, file, key, rename, new keys, remove'),
|
||||
class: 'cbi-button cbi-button-neutral dl-icon-only',
|
||||
});
|
||||
const cards = byDeviceState(p.devices).map((d) => {
|
||||
@@ -51,12 +52,12 @@ export function devicesPart(page: PersonPage): HTMLElement {
|
||||
E('button', { type: 'button', class: 'dl-dcard-title', click: () => open(d) }, [
|
||||
E('b', {}, d.name),
|
||||
deviceStatus(d, now, undefined, p),
|
||||
d.config_stale ? E('span', { class: 'dl-pill warn dl-stale' }, 'Update config') : '',
|
||||
d.config_stale ? E('span', { class: 'dl-pill warn dl-stale' }, _('Update config')) : '',
|
||||
]),
|
||||
more(d),
|
||||
]);
|
||||
const trend = E('div', { class: 'dl-dcard-trend' }, [
|
||||
E('div', { class: 'dl-stack' }, [E('b', {}, bytes(d.month[0] + d.month[1])), E('span', { class: 'dl-sub' }, 'this month')]),
|
||||
E('div', { class: 'dl-stack' }, [E('b', {}, bytes(d.month[0] + d.month[1])), E('span', { class: 'dl-sub' }, _('this month'))]),
|
||||
dayBars(page.devSeries[d.id] ?? []),
|
||||
]);
|
||||
return E('article', { class: `dl-dcard clickable${d.online ? ' online' : ''}${d.disabled ? ' off' : ''}`, click: clickCard(d) }, [
|
||||
@@ -67,11 +68,11 @@ export function devicesPart(page: PersonPage): HTMLElement {
|
||||
? E(
|
||||
'div',
|
||||
{ class: 'dl-sub' },
|
||||
`${KIND_LABEL[d.kind]} · created ${ago(d.created, now)} ${d.created_by === 'portal' ? 'in the portal' : 'by you'}.`,
|
||||
`${kindLabel(d.kind)} · ${fmt(d.created_by === 'portal' ? _('created %s in the portal.') : _('created %s by you.'), ago(d.created, now))}`,
|
||||
)
|
||||
: E('div', { class: 'dl-chips-row' }, [
|
||||
E('button', { type: 'button', class: 'dl-chipbtn', click: () => showDeviceQr(page, d) }, [icon('qr'), 'Show QR']),
|
||||
E('button', { type: 'button', class: 'dl-chipbtn', click: () => downloadConfig(page, d) }, [icon('download'), 'Config']),
|
||||
E('button', { type: 'button', class: 'dl-chipbtn', click: () => showDeviceQr(page, d) }, [icon('qr'), _('Show QR')]),
|
||||
E('button', { type: 'button', class: 'dl-chipbtn', click: () => downloadConfig(page, d) }, [icon('download'), _('Config')]),
|
||||
]),
|
||||
]);
|
||||
});
|
||||
@@ -81,17 +82,19 @@ export function devicesPart(page: PersonPage): HTMLElement {
|
||||
E('button', { type: 'button', class: 'dl-dslot add', click: () => addDevice(p, page.deviceOpts()) }, [
|
||||
E('span', { class: 'dl-dslot-ic' }, icon('plus')),
|
||||
E('span', { class: 'dl-stack' }, [
|
||||
E('b', {}, 'Add device'),
|
||||
E('b', {}, _('Add device')),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
over ? `Over the limit · ${p.devices.length} of ${p.device_limit}` : `${p.devices.length} of ${p.device_limit}`,
|
||||
over
|
||||
? `${_('Over the limit')} · ${fmt(_('%s of %s'), p.devices.length, p.device_limit)}`
|
||||
: fmt(_('%s of %s'), p.devices.length, p.device_limit),
|
||||
),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
return E('section', { class: 'dl-devsec' }, [
|
||||
E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Devices'), E('span', { class: 'dl-sub' }, `${p.online} online`)]),
|
||||
E('div', { class: 'dl-panel-head' }, [E('h3', {}, _('Devices')), E('span', { class: 'dl-sub' }, fmt(_('%s online'), num(p.online)))]),
|
||||
E('div', { class: 'dl-dgrid' }, cards),
|
||||
]);
|
||||
}
|
||||
@@ -10,13 +10,14 @@ import { liveField } from '../../ui/layout';
|
||||
import { nameHelp } from '../../netcheck';
|
||||
import { inviteCard } from '../../invite';
|
||||
import { peopleUrl } from '../../urls';
|
||||
import { fmt, plural } from '../../../shared/i18n';
|
||||
import type { PersonPage } from './index';
|
||||
|
||||
const field = (label: string, el: Node) =>
|
||||
E('div', { class: 'cbi-value' }, [E('label', { class: 'cbi-value-title' }, label), E('div', { class: 'cbi-value-field' }, el)]);
|
||||
|
||||
export function invite(page: PersonPage) {
|
||||
const server = page.st.servers.find((s) => s.id === page.p.server)?.name ?? 'Home';
|
||||
const server = page.st.servers.find((s) => s.id === page.p.server)?.name ?? _('Home');
|
||||
void inviteCard(page.p, server);
|
||||
}
|
||||
|
||||
@@ -32,10 +33,10 @@ export async function newLink(page: PersonPage) {
|
||||
const boxes = suspect.map(
|
||||
(d) => E('input', { type: 'checkbox', id: `dl-rm-${d.id}`, checked: 'checked', 'data-id': d.id }) as HTMLInputElement,
|
||||
);
|
||||
const body: Node[] = [E('p', {}, 'The old link stops working right away.')];
|
||||
const body: Node[] = [E('p', {}, _('The old link stops working right away.'))];
|
||||
if (suspect.length)
|
||||
body.push(
|
||||
E('p', {}, 'Devices added through the old link keep working until they are removed. Remove them too:'),
|
||||
E('p', {}, _('Devices added through the old link keep working until they are removed. Remove them too:')),
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-checklist' },
|
||||
@@ -46,33 +47,35 @@ export async function newLink(page: PersonPage) {
|
||||
const remove = boxes.filter((b) => b.checked).map((b) => b.dataset.id as string);
|
||||
const r = await attempt(
|
||||
() => api.personRegen(p.id, remove),
|
||||
remove.length ? `New link created, ${remove.length} device${remove.length === 1 ? '' : 's'} removed` : 'New link created',
|
||||
remove.length
|
||||
? plural(remove.length, 'New link created, %s device removed', 'New link created, %s devices removed')
|
||||
: _('New link created'),
|
||||
);
|
||||
if (!r) return;
|
||||
closeModal();
|
||||
if (remove.length) await page.refresh();
|
||||
if (r.link) await copyText(r.link, 'New link copied');
|
||||
if (r.link) await copyText(r.link, _('New link copied'));
|
||||
};
|
||||
modal('Create a new link?', body, [cancelButton(), ' ', button('Create new link', go, 'negative')]);
|
||||
modal(_('Create a new link?'), body, [cancelButton(), ' ', button(_('Create new link'), go, 'negative')]);
|
||||
}
|
||||
|
||||
export function editNote(page: PersonPage) {
|
||||
const input = E(
|
||||
'textarea',
|
||||
{ class: 'cbi-input-textarea dl-note-input', rows: 3, maxlength: 500, placeholder: 'Only you see this' },
|
||||
{ class: 'cbi-input-textarea dl-note-input', rows: 3, maxlength: 500, placeholder: _('Only you see this') },
|
||||
page.p.note ?? '',
|
||||
) as HTMLTextAreaElement;
|
||||
modal(
|
||||
'Note',
|
||||
_('Note'),
|
||||
[input],
|
||||
[
|
||||
cancelButton(),
|
||||
' ',
|
||||
button(
|
||||
'Save',
|
||||
_('Save'),
|
||||
async () => {
|
||||
closeModal();
|
||||
await page.patch({ note: input.value.trim() }, input.value.trim() ? 'Note saved' : 'Note removed');
|
||||
await page.patch({ note: input.value.trim() }, input.value.trim() ? _('Note saved') : _('Note removed'));
|
||||
},
|
||||
'positive',
|
||||
),
|
||||
@@ -84,9 +87,9 @@ export function editNote(page: PersonPage) {
|
||||
export function endSettings(page: PersonPage) {
|
||||
const p = page.p;
|
||||
const act = E('select', { class: 'cbi-input-select' }, [
|
||||
E('option', { value: 'pause', selected: p.expire_action === 'pause' ? 'selected' : null }, 'Pause access'),
|
||||
E('option', { value: 'notify', selected: p.expire_action === 'notify' ? 'selected' : null }, 'Keep access'),
|
||||
E('option', { value: 'remove', selected: p.expire_action === 'remove' ? 'selected' : null }, 'Remove their devices'),
|
||||
E('option', { value: 'pause', selected: p.expire_action === 'pause' ? 'selected' : null }, _('Pause access')),
|
||||
E('option', { value: 'notify', selected: p.expire_action === 'notify' ? 'selected' : null }, _('Keep access')),
|
||||
E('option', { value: 'remove', selected: p.expire_action === 'remove' ? 'selected' : null }, _('Remove their devices')),
|
||||
]) as HTMLSelectElement;
|
||||
const warn = E(
|
||||
'select',
|
||||
@@ -95,19 +98,19 @@ export function endSettings(page: PersonPage) {
|
||||
E(
|
||||
'option',
|
||||
{ value: n, selected: p.expire_warn === n ? 'selected' : null },
|
||||
n ? `${n} day${n === 1 ? '' : 's'} before` : 'Don’t warn',
|
||||
n ? plural(n, '%s day before', '%s days before') : _('Don’t warn'),
|
||||
),
|
||||
),
|
||||
) as HTMLSelectElement;
|
||||
modal(
|
||||
'When access ends',
|
||||
_('When access ends'),
|
||||
[
|
||||
field('Then', act),
|
||||
field(_('Then'), act),
|
||||
E('div', { class: 'cbi-value' }, [
|
||||
E('label', { class: 'cbi-value-title' }, 'Warn'),
|
||||
E('label', { class: 'cbi-value-title' }, _('Warn')),
|
||||
E('div', { class: 'cbi-value-field' }, [
|
||||
warn,
|
||||
E('div', { class: 'cbi-value-description' }, 'Shown in their portal and on the Overview.'),
|
||||
E('div', { class: 'cbi-value-description' }, _('Shown in their portal and on the Overview.')),
|
||||
]),
|
||||
]),
|
||||
],
|
||||
@@ -115,10 +118,10 @@ export function endSettings(page: PersonPage) {
|
||||
cancelButton(),
|
||||
' ',
|
||||
button(
|
||||
'Save',
|
||||
_('Save'),
|
||||
async () => {
|
||||
closeModal();
|
||||
await page.patch({ expire_action: act.value, expire_warn: warn.value }, 'Saved');
|
||||
await page.patch({ expire_action: act.value, expire_warn: warn.value }, _('Saved'));
|
||||
},
|
||||
'positive',
|
||||
),
|
||||
@@ -128,15 +131,15 @@ export function endSettings(page: PersonPage) {
|
||||
|
||||
export function rename(page: PersonPage) {
|
||||
const input = E('input', { type: 'text', class: 'cbi-input-text', value: page.p.name, maxlength: 48 }) as HTMLInputElement;
|
||||
const nameRow = liveField('Name', input, () => nameHelp(input.value, [], 'Shown in their portal and apps.'));
|
||||
const nameRow = liveField(_('Name', 'person'), input, () => nameHelp(input.value, [], _('Shown in their portal and apps.')));
|
||||
modal(
|
||||
'Rename',
|
||||
_('Rename'),
|
||||
[nameRow],
|
||||
[
|
||||
cancelButton(),
|
||||
' ',
|
||||
button(
|
||||
'Save',
|
||||
_('Save'),
|
||||
async () => {
|
||||
const h = nameRow.help();
|
||||
if (h.bad) {
|
||||
@@ -144,7 +147,7 @@ export function rename(page: PersonPage) {
|
||||
return;
|
||||
}
|
||||
// The dialog stays open on a refusal, with the name still typed.
|
||||
if (await page.patch({ name: input.value.trim() }, 'Renamed')) closeModal();
|
||||
if (await page.patch({ name: input.value.trim() }, _('Renamed'))) closeModal();
|
||||
},
|
||||
'positive',
|
||||
),
|
||||
@@ -160,30 +163,36 @@ export function moveToServer(page: PersonPage) {
|
||||
const sel = E(
|
||||
'select',
|
||||
{ class: 'cbi-input-select' },
|
||||
others.map((s) => E('option', { value: s.id }, `${s.name} · ${s.endpoint || 'no address'}:${s.port}`)),
|
||||
others.map((s) => E('option', { value: s.id }, `${s.name} · ${s.endpoint || _('no address')}:${s.port}`)),
|
||||
) as HTMLSelectElement;
|
||||
const n = p.devices.length;
|
||||
modal(
|
||||
`Move ${p.name} to another server`,
|
||||
fmt(_('Move %s to another server'), p.name),
|
||||
[
|
||||
field('Server', sel),
|
||||
field(_('Server'), sel),
|
||||
E(
|
||||
'p',
|
||||
{ class: 'dl-muted' },
|
||||
n
|
||||
? `${n} device${n === 1 ? ' gets a new address and stops' : 's get new addresses and stop'} connecting until ${n === 1 ? 'it imports its' : 'they import their'} configuration again (from the personal link or from you). Circles and home networks of the old server are left behind.`
|
||||
: 'They have no devices yet: nothing else changes.',
|
||||
? plural(
|
||||
n,
|
||||
'%s device gets a new address and stops connecting until it imports its configuration again (from the personal link or from you). Circles and home networks of the old server are left behind.',
|
||||
'%s devices get new addresses and stop connecting until they import their configuration again (from the personal link or from you). Circles and home networks of the old server are left behind.',
|
||||
)
|
||||
: _('They have no devices yet: nothing else changes.'),
|
||||
),
|
||||
],
|
||||
[
|
||||
cancelButton(),
|
||||
' ',
|
||||
button(
|
||||
'Move',
|
||||
_('Move'),
|
||||
async () => {
|
||||
if (await page.patch({ server: sel.value }, `Moved to ${others.find((s) => s.id === sel.value)?.name ?? 'the server'}`)) {
|
||||
if (
|
||||
await page.patch({ server: sel.value }, fmt(_('Moved to %s'), others.find((s) => s.id === sel.value)?.name ?? _('the server')))
|
||||
) {
|
||||
closeModal();
|
||||
if (n) notify('Devices are marked “Update config” until they import again.', 'info', 6000);
|
||||
if (n) notify(_('Devices are marked “Update config” until they import again.'), 'info', 6000);
|
||||
}
|
||||
},
|
||||
'positive',
|
||||
@@ -195,10 +204,14 @@ export function moveToServer(page: PersonPage) {
|
||||
export async function remove(page: PersonPage) {
|
||||
const p = page.p;
|
||||
const ok = await confirmDialog(
|
||||
`Delete ${p.name}?`,
|
||||
`All ${p.devices.length} devices are disconnected immediately and the personal link stops working.`,
|
||||
'Delete',
|
||||
fmt(_('Delete %s?'), p.name),
|
||||
plural(
|
||||
p.devices.length,
|
||||
'%s device is disconnected immediately and the personal link stops working.',
|
||||
'All %s devices are disconnected immediately and the personal link stops working.',
|
||||
),
|
||||
_('Delete'),
|
||||
true,
|
||||
);
|
||||
if (ok && (await attempt(() => api.personDelete(p.id), 'Deleted'))) location.href = peopleUrl(p.server);
|
||||
if (ok && (await attempt(() => api.personDelete(p.id), _('Deleted')))) location.href = peopleUrl(p.server);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { dropdown, type MenuItem } from '../../ui/menu';
|
||||
import { statePill } from '../../ui/badges';
|
||||
import { icon } from '../../../shared/icons';
|
||||
import { ago, bytes, date, initials, isoDay } from '../../../shared/format';
|
||||
import { fmt } from '../../../shared/i18n';
|
||||
import { copyPersonLink } from '../../invite';
|
||||
import { daysTile, speedTile } from '../../widgets/tiles';
|
||||
import { editNote, invite, moveToServer, newLink, remove, rename } from './dialogs';
|
||||
@@ -14,26 +15,26 @@ import type { PersonPage } from './index';
|
||||
export function headPart(page: PersonPage): HTMLElement {
|
||||
const p = page.p;
|
||||
const st = page.st;
|
||||
const lastSeen = p.online ? 'online now' : p.last_seen ? `last seen ${ago(p.last_seen, st.now)}` : 'never connected';
|
||||
const added = p.created ? `Added ${date(isoDay(new Date(p.created * 1000)))}` : '';
|
||||
const lastSeen = p.online ? _('online now') : p.last_seen ? fmt(_('last seen %s'), ago(p.last_seen, st.now)) : _('never connected');
|
||||
const added = p.created ? fmt(_('Added %s', 'date'), date(isoDay(new Date(p.created * 1000)))) : '';
|
||||
// The personal link is not in the status: its actions ask for it while there is one.
|
||||
const portal = p.has_link ?? st.settings.portal_enabled;
|
||||
const menu: (MenuItem | null)[] = [
|
||||
{ label: 'Rename', icon: icon('edit'), run: () => rename(page) },
|
||||
{ label: p.note ? 'Edit note' : 'Add note', icon: icon('file'), run: () => editNote(page) },
|
||||
{ label: _('Rename'), icon: icon('edit'), run: () => rename(page) },
|
||||
{ label: p.note ? _('Edit note') : _('Add note'), icon: icon('file'), run: () => editNote(page) },
|
||||
// With one server there is nowhere to move to.
|
||||
...(st.servers.length > 1 ? [{ label: 'Move to server…', icon: icon('server'), run: () => moveToServer(page) }] : []),
|
||||
...(st.servers.length > 1 ? [{ label: _('Move to server…'), icon: icon('server'), run: () => moveToServer(page) }] : []),
|
||||
...(portal
|
||||
? [
|
||||
null,
|
||||
{ label: 'Invite card', icon: icon('qr'), run: () => invite(page) },
|
||||
{ label: 'New link', icon: icon('key'), run: () => newLink(page) },
|
||||
{ label: _('Invite card'), icon: icon('qr'), run: () => invite(page) },
|
||||
{ label: _('New link'), icon: icon('key'), run: () => newLink(page) },
|
||||
]
|
||||
: []),
|
||||
null,
|
||||
// While paused, Resume is the page's own button (as the server's Turn on).
|
||||
...(p.paused ? [] : [{ label: 'Pause', icon: icon('pause'), warn: true, run: () => page.patch({ paused: true }, 'Paused') }]),
|
||||
{ label: 'Delete', icon: icon('trash'), danger: true, run: () => remove(page) },
|
||||
...(p.paused ? [] : [{ label: _('Pause'), icon: icon('pause'), warn: true, run: () => page.patch({ paused: true }, _('Paused')) }]),
|
||||
{ label: _('Delete'), icon: icon('trash'), danger: true, run: () => remove(page) },
|
||||
];
|
||||
return E('div', { class: 'dl-person-head' }, [
|
||||
E('div', { class: 'dl-pagehead' }, [
|
||||
@@ -41,19 +42,23 @@ export function headPart(page: PersonPage): HTMLElement {
|
||||
E('span', { class: `dl-avatar lg${p.online ? ' online' : ''}` }, initials(p.name)),
|
||||
E('div', { class: 'dl-stack' }, [
|
||||
E('div', { class: 'dl-title-row' }, [E('h2', { class: 'dl-h1' }, p.name), statePill(p)]),
|
||||
E('span', { class: 'dl-faint', title: added }, `${p.devices.length} of ${p.device_limit} devices · ${lastSeen}`),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-faint', title: added },
|
||||
`${fmt(N_(p.device_limit, '%s of %s device', '%s of %s devices'), p.devices.length, p.device_limit)} · ${lastSeen}`,
|
||||
),
|
||||
]),
|
||||
]),
|
||||
E('div', { class: 'dl-pcard-actions' }, [
|
||||
// White, as the server's Turn on.
|
||||
p.paused ? button([icon('play'), ' Resume'], () => page.patch({ paused: false }, 'Resumed'), 'add') : '',
|
||||
portal ? iconButton('link', 'Copy link', () => copyPersonLink(p.id), 'neutral', 'dl-icon-only') : '',
|
||||
iconButton('more', 'More', (ev: MouseEvent) => dropdown(ev.currentTarget as HTMLElement, menu), 'neutral', 'dl-icon-only'),
|
||||
p.paused ? button([icon('play'), ` ${_('Resume')}`], () => page.patch({ paused: false }, _('Resumed')), 'add') : '',
|
||||
portal ? iconButton('link', _('Copy link'), () => copyPersonLink(p.id), 'neutral', 'dl-icon-only') : '',
|
||||
iconButton('more', _('More'), (ev: MouseEvent) => dropdown(ev.currentTarget as HTMLElement, menu), 'neutral', 'dl-icon-only'),
|
||||
]),
|
||||
]),
|
||||
// Under the name block, not inside it, so the avatar centres on name + status; indented to the name.
|
||||
p.note
|
||||
? E('button', { type: 'button', class: 'dl-pnote', title: 'Edit note', click: () => editNote(page) }, [
|
||||
? E('button', { type: 'button', class: 'dl-pnote', title: _('Edit note'), click: () => editNote(page) }, [
|
||||
icon('file'),
|
||||
E('span', {}, p.note),
|
||||
])
|
||||
@@ -68,6 +73,6 @@ export function trafficPart(page: PersonPage): HTMLElement {
|
||||
const todayUse = page.series[page.series.length - 1];
|
||||
return E('div', { class: `dl-person-live${p.online ? '' : ' solo'}` }, [
|
||||
p.online ? speedTile(p.rate ?? [], page.st.now, todayUse ? [todayUse.rx, todayUse.tx] : [0, 0]) : '',
|
||||
daysTile(page.series, `${bytes(p.month[0] + p.month[1])} this month`),
|
||||
daysTile(page.series, fmt(_('%s this month'), bytes(p.month[0] + p.month[1]))),
|
||||
]);
|
||||
}
|
||||
@@ -64,9 +64,9 @@ export class PersonPage {
|
||||
const p = this.st.people.find((x) => x.id === this.id);
|
||||
if (!p)
|
||||
return E('div', { class: 'dl-empty' }, [
|
||||
E('h3', {}, 'Person not found'),
|
||||
E('p', {}, 'They may have been removed.'),
|
||||
E('a', { class: 'cbi-button', href: L.url('admin/network/dawnline/server') }, 'Back to Servers'),
|
||||
E('h3', {}, _('Person not found')),
|
||||
E('p', {}, _('They may have been removed.')),
|
||||
E('a', { class: 'cbi-button', href: L.url('admin/network/dawnline/server') }, _('Back to Servers')),
|
||||
]);
|
||||
this.p = p;
|
||||
for (const k of ['crumbs', 'head', 'devices', 'traffic', 'places', 'activity', 'limits'] as Part[]) this.parts[k] = E('div', {});
|
||||
@@ -173,10 +173,10 @@ export class PersonPage {
|
||||
/** Server / People / name: the server changes when the person is moved. */
|
||||
private crumbs(): HTMLElement {
|
||||
const p = this.p;
|
||||
return E('nav', { class: 'dl-crumbs', 'aria-label': 'Breadcrumb' }, [
|
||||
E('a', { href: peopleUrl(p.server) }, this.st.servers.find((x) => x.id === p.server)?.name ?? 'Servers'),
|
||||
return E('nav', { class: 'dl-crumbs', 'aria-label': _('Breadcrumb') }, [
|
||||
E('a', { href: peopleUrl(p.server) }, this.st.servers.find((x) => x.id === p.server)?.name ?? _('Servers')),
|
||||
E('span', {}, '/'),
|
||||
E('a', { href: peopleUrl(p.server) }, 'People'),
|
||||
E('a', { href: peopleUrl(p.server) }, _('People')),
|
||||
E('span', {}, '/'),
|
||||
E('span', {}, p.name),
|
||||
]);
|
||||
|
||||
@@ -11,18 +11,21 @@ import { liveField } from '../../ui/layout';
|
||||
import { quotaHelp } from '../../netcheck';
|
||||
import { attachTip } from '../../ui/tooltip';
|
||||
import { icon } from '../../../shared/icons';
|
||||
import { ACCESS_LABEL, bytes, date, daysLeft, endsSoon, shiftDay } from '../../../shared/format';
|
||||
import { accessLabel, bytes, date, daysLeft, endsSoon, shiftDay } from '../../../shared/format';
|
||||
import { fmt, num, plural } from '../../../shared/i18n';
|
||||
import { resetUsageDialog } from '../../logs';
|
||||
import { homeAccess } from '../../access';
|
||||
import { endSettings } from './dialogs';
|
||||
import { circleTile, devTile, dnsPicker, netsPicker, servicesPicker } from './pickers';
|
||||
import type { PersonPage } from './index';
|
||||
|
||||
const ACCESS_TEXT: Record<Person['access'], string> = {
|
||||
internet: 'Browse the internet through your router. No access to devices at home, and home cannot reach theirs.',
|
||||
lan: 'Reach devices at home, and home reaches theirs. Internet stays on their own connection.',
|
||||
both: 'Home devices and the internet, all through your router. Home reaches their devices too.',
|
||||
};
|
||||
function accessText(a: Person['access']): string {
|
||||
return {
|
||||
internet: _('Browse the internet through your router. No access to devices at home, and home cannot reach theirs.'),
|
||||
lan: _('Reach devices at home, and home reaches theirs. Internet stays on their own connection.'),
|
||||
both: _('Home devices and the internet, all through your router. Home reaches their devices too.'),
|
||||
}[a];
|
||||
}
|
||||
|
||||
const TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
|
||||
|
||||
@@ -39,19 +42,19 @@ function endTile(page: PersonPage): HTMLElement {
|
||||
}) as HTMLInputElement;
|
||||
dateInput.addEventListener(
|
||||
'change',
|
||||
() => dateInput.value && page.patch({ expires: dateInput.value }, `Access until ${date(dateInput.value)}`),
|
||||
() => dateInput.value && page.patch({ expires: dateInput.value }, fmt(_('Access until %s'), date(dateInput.value))),
|
||||
);
|
||||
// Extend from the current end, or from today when there is none or it has passed.
|
||||
const extend = (step: 'week' | 'month' | 'year', n: number) => {
|
||||
const next = shiftDay(p.expires && (left ?? -1) >= 0 ? p.expires : '', step, n, today);
|
||||
void page.patch({ expires: next }, `Access until ${date(next)}`);
|
||||
void page.patch({ expires: next }, fmt(_('Access until %s'), date(next)));
|
||||
};
|
||||
const ext = (
|
||||
[
|
||||
['week', 1, '+1 week'],
|
||||
['month', 1, '+1 month'],
|
||||
['month', 3, '+3 months'],
|
||||
['year', 1, '+1 year'],
|
||||
['week', 1, _('+1 week')],
|
||||
['month', 1, _('+1 month')],
|
||||
['month', 3, _('+3 months')],
|
||||
['year', 1, _('+1 year')],
|
||||
] as const
|
||||
).map(([step, n, label]) => E('button', { type: 'button', class: 'dl-chipbtn', click: () => extend(step, n) }, label));
|
||||
// The native date input stays hidden behind the chip and only opens its picker. It takes the
|
||||
@@ -71,34 +74,40 @@ function endTile(page: PersonPage): HTMLElement {
|
||||
}
|
||||
},
|
||||
},
|
||||
[icon('calendar'), p.expires ? date(p.expires) : 'Date'],
|
||||
[icon('calendar'), p.expires ? date(p.expires) : _('Date')],
|
||||
),
|
||||
dateInput,
|
||||
]);
|
||||
const action = { pause: 'pause access', notify: 'keep access', remove: 'remove their devices' }[p.expire_action];
|
||||
const action = { pause: _('pause access'), notify: _('keep access'), remove: _('remove their devices') }[p.expire_action];
|
||||
return E('div', { class: 'dl-tile2' }, [
|
||||
E('div', { class: 'dl-tile2-label' }, [
|
||||
E('span', {}, 'Access ends'),
|
||||
E('span', {}, _('Access ends')),
|
||||
p.expires
|
||||
? E(
|
||||
'span',
|
||||
{ class: left != null && left < 0 ? 'dl-bad' : endsSoon(p, left) ? 'dl-warn' : 'dl-ok' },
|
||||
left != null && left < 0 ? 'ended' : `${left} day${left === 1 ? '' : 's'} left`,
|
||||
left != null && left < 0 ? _('ended') : plural(left ?? 0, '%s day left', '%s days left'),
|
||||
)
|
||||
: E('span', { class: 'dl-faint' }, 'no end date'),
|
||||
: E('span', { class: 'dl-faint' }, _('no end date')),
|
||||
]),
|
||||
E('div', { class: 'dl-chips-row' }, [
|
||||
...ext,
|
||||
pick,
|
||||
p.expires
|
||||
? E('button', { type: 'button', class: 'dl-chipbtn', click: () => page.patch({ expires: '' }, 'No end date') }, 'No end')
|
||||
? E('button', { type: 'button', class: 'dl-chipbtn', click: () => page.patch({ expires: '' }, _('No end date')) }, _('No end'))
|
||||
: '',
|
||||
]),
|
||||
E('div', { class: 'dl-tile2-foot' }, [
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-muted' },
|
||||
`When it ends: ${action}${p.expire_warn ? `, warn ${p.expire_warn} day${p.expire_warn === 1 ? '' : 's'} before` : ''}`,
|
||||
p.expire_warn
|
||||
? fmt(
|
||||
N_(p.expire_warn, 'When it ends: %s, warn %s day before', 'When it ends: %s, warn %s days before'),
|
||||
action,
|
||||
num(p.expire_warn),
|
||||
)
|
||||
: fmt(_('When it ends: %s'), action),
|
||||
),
|
||||
E(
|
||||
'a',
|
||||
@@ -109,7 +118,7 @@ function endTile(page: PersonPage): HTMLElement {
|
||||
endSettings(page);
|
||||
},
|
||||
},
|
||||
'Change',
|
||||
_('Change'),
|
||||
),
|
||||
]),
|
||||
]);
|
||||
@@ -121,26 +130,26 @@ function dataTile(page: PersonPage): HTMLElement {
|
||||
const pct = p.quota_limit ? Math.min(100, (p.quota_used / p.quota_limit) * 100) : 0;
|
||||
const bar = E('div', { class: `dl-meter${pct >= 100 ? ' bad' : pct >= 90 ? ' warn' : ''}` }, [
|
||||
E('i'),
|
||||
p.quota_limit ? E('span', { class: 'mark', title: 'Alert at 90%' }) : '',
|
||||
p.quota_limit ? E('span', { class: 'mark', title: _('Alert at 90%') }) : '',
|
||||
]);
|
||||
(bar.firstChild as HTMLElement).style.width = `${pct}%`;
|
||||
if (p.quota_limit)
|
||||
attachTip(bar, () => [
|
||||
E('div', { class: 'dl-tip-title' }, `${pct.toFixed(1)}% used`),
|
||||
E('div', { class: 'dl-tip-title' }, fmt(_('%s%% used'), num(pct, 1))),
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-muted' },
|
||||
`${bytes(p.quota_used)} of ${bytes(p.quota_limit)} · ${bytes(Math.max(0, p.quota_limit - p.quota_used))} left`,
|
||||
`${fmt(_('%s of %s'), bytes(p.quota_used), bytes(p.quota_limit))} · ${fmt(_('%s left'), bytes(Math.max(0, p.quota_limit - p.quota_used)))}`,
|
||||
),
|
||||
E('div', { class: 'dl-faint' }, 'Alert at 90%'),
|
||||
E('div', { class: 'dl-faint' }, _('Alert at 90%')),
|
||||
]);
|
||||
const period = seg(
|
||||
[
|
||||
['month', 'Monthly'],
|
||||
['total', 'Total'],
|
||||
['month', _('Monthly')],
|
||||
['total', _('Total')],
|
||||
],
|
||||
p.quota_period,
|
||||
{ label: 'Data limit period', cls: 'sm', optimistic: false, onChange: (v) => page.patch({ quota_period: v }) },
|
||||
{ label: _('Data limit period'), cls: 'sm', optimistic: false, onChange: (v) => page.patch({ quota_period: v }) },
|
||||
);
|
||||
const presets = [10, 50, 100].map((gb) =>
|
||||
E(
|
||||
@@ -148,16 +157,16 @@ function dataTile(page: PersonPage): HTMLElement {
|
||||
{
|
||||
type: 'button',
|
||||
class: `dl-chipbtn${p.quota_gb === gb ? ' on' : ''}`,
|
||||
click: () => page.patch({ quota_gb: String(gb) }, `Data limit ${gb} GB`),
|
||||
click: () => page.patch({ quota_gb: String(gb) }, fmt(_('Data limit %s GB'), num(gb))),
|
||||
},
|
||||
`${gb} GB`,
|
||||
`${num(gb)} ${_('GB')}`,
|
||||
),
|
||||
);
|
||||
presets.push(
|
||||
E(
|
||||
'button',
|
||||
{ type: 'button', class: `dl-chipbtn${!p.quota_gb ? ' on' : ''}`, click: () => page.patch({ quota_gb: '' }, 'No data limit') },
|
||||
'Unlimited',
|
||||
{ type: 'button', class: `dl-chipbtn${!p.quota_gb ? ' on' : ''}`, click: () => page.patch({ quota_gb: '' }, _('No data limit')) },
|
||||
_('Unlimited'),
|
||||
),
|
||||
);
|
||||
presets.push(
|
||||
@@ -174,15 +183,15 @@ function dataTile(page: PersonPage): HTMLElement {
|
||||
step: 'any',
|
||||
value: p.quota_gb ? String(p.quota_gb) : '',
|
||||
}) as HTMLInputElement;
|
||||
const row = liveField('Data limit (GB)', inp, () => quotaHelp(inp.value, p.quota_period === 'month'));
|
||||
const row = liveField(_('Data limit (GB)'), inp, () => quotaHelp(inp.value, p.quota_period === 'month'));
|
||||
modal(
|
||||
'Data limit',
|
||||
_('Data limit'),
|
||||
[row],
|
||||
[
|
||||
cancelButton(),
|
||||
' ',
|
||||
button(
|
||||
'Save',
|
||||
_('Save'),
|
||||
async () => {
|
||||
const h = row.help();
|
||||
if (h.bad) {
|
||||
@@ -190,7 +199,10 @@ function dataTile(page: PersonPage): HTMLElement {
|
||||
return;
|
||||
}
|
||||
const v = inp.value.trim();
|
||||
if (await page.patch({ quota_gb: v }, v && Number(v) > 0 ? `Data limit ${v} GB` : 'No data limit')) closeModal();
|
||||
if (
|
||||
await page.patch({ quota_gb: v }, v && Number(v) > 0 ? fmt(_('Data limit %s GB'), num(Number(v))) : _('No data limit'))
|
||||
)
|
||||
closeModal();
|
||||
},
|
||||
'positive',
|
||||
),
|
||||
@@ -199,38 +211,44 @@ function dataTile(page: PersonPage): HTMLElement {
|
||||
setTimeout(() => inp.select(), 50);
|
||||
},
|
||||
},
|
||||
'Custom',
|
||||
_('Custom'),
|
||||
),
|
||||
);
|
||||
return E('div', { class: 'dl-tile2' }, [
|
||||
E('div', { class: 'dl-tile2-label' }, [E('span', {}, 'Data'), period]),
|
||||
E('div', { class: 'dl-tile2-label' }, [E('span', {}, _('Data')), period]),
|
||||
E('div', { class: 'dl-tile2-row' }, [
|
||||
E('span', { class: 'dl-tile2-value' }, [
|
||||
bytes(used),
|
||||
p.quota_limit ? E('span', { class: 'dl-faint' }, ` of ${bytes(p.quota_limit)}`) : E('span', { class: 'dl-faint' }, ' · no limit'),
|
||||
p.quota_limit
|
||||
? E('span', { class: 'dl-faint' }, ` ${fmt(_('of %s'), bytes(p.quota_limit))}`)
|
||||
: E('span', { class: 'dl-faint' }, ` · ${_('no limit')}`),
|
||||
]),
|
||||
p.quota_period === 'month' ? E('span', { class: 'dl-sub' }, 'resets on the 1st') : '',
|
||||
p.quota_period === 'month' ? E('span', { class: 'dl-sub' }, _('resets on the 1st')) : '',
|
||||
]),
|
||||
p.quota_limit ? bar : '',
|
||||
E('div', { class: 'dl-chips-row' }, presets),
|
||||
p.quota_gb && p.quota_period === 'month'
|
||||
? E('div', { class: 'dl-tile2-foot' }, [
|
||||
E('span', { class: 'dl-muted' }, p.bonus_gb ? `Includes +${p.bonus_gb} GB extra this month` : 'Need a little more this month?'),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-muted' },
|
||||
p.bonus_gb ? fmt(_('Includes +%s GB extra this month'), num(p.bonus_gb)) : _('Need a little more this month?'),
|
||||
),
|
||||
E(
|
||||
'a',
|
||||
{
|
||||
href: '#',
|
||||
click: (ev: Event) => {
|
||||
ev.preventDefault();
|
||||
void page.patch({ bonus_gb: String((p.bonus_gb || 0) + 10) }, '+10 GB this month');
|
||||
void page.patch({ bonus_gb: String((p.bonus_gb || 0) + 10) }, _('+10 GB this month'));
|
||||
},
|
||||
},
|
||||
'+10 GB this month',
|
||||
_('+10 GB this month'),
|
||||
),
|
||||
])
|
||||
: '',
|
||||
E('div', { class: 'dl-tile2-foot' }, [
|
||||
E('span', { class: 'dl-muted' }, `${bytes(p.total[0] + p.total[1])} in total`),
|
||||
E('span', { class: 'dl-muted' }, fmt(_('%s in total'), bytes(p.total[0] + p.total[1]))),
|
||||
E(
|
||||
'button',
|
||||
{
|
||||
@@ -238,7 +256,7 @@ function dataTile(page: PersonPage): HTMLElement {
|
||||
class: 'dl-linkbtn danger',
|
||||
click: () => resetUsageDialog('person', p.id, p.name, () => setTimeout(() => page.refresh(), 300)),
|
||||
},
|
||||
'Reset usage',
|
||||
_('Reset usage'),
|
||||
),
|
||||
]),
|
||||
]);
|
||||
@@ -253,15 +271,15 @@ function hoursTile(page: PersonPage): HTMLElement {
|
||||
const p = page.p;
|
||||
const hoursOn = !!p.hours;
|
||||
const [h1, h2] = (p.hours || '07:00-23:00').split('-');
|
||||
const from = E('input', { type: 'time', class: 'cbi-input-text', value: h1, 'aria-label': 'From' }) as HTMLInputElement;
|
||||
const to = E('input', { type: 'time', class: 'cbi-input-text', value: h2, 'aria-label': 'To' }) as HTMLInputElement;
|
||||
const times = E('div', { class: 'dl-tile2-row' }, [from, E('span', { class: 'dl-faint' }, 'to'), to]);
|
||||
const from = E('input', { type: 'time', class: 'cbi-input-text', value: h1, 'aria-label': _('From') }) as HTMLInputElement;
|
||||
const to = E('input', { type: 'time', class: 'cbi-input-text', value: h2, 'aria-label': _('To') }) as HTMLInputElement;
|
||||
const times = E('div', { class: 'dl-tile2-row' }, [from, E('span', { class: 'dl-faint' }, _('to', 'time range')), to]);
|
||||
const commit = () => {
|
||||
const v = `${from.value}-${to.value}`;
|
||||
if (v === p.hours) return;
|
||||
if (!TIME.test(from.value) || !TIME.test(to.value)) return notify('Enter both times, like 07:00 and 23:00.', 'warning');
|
||||
if (from.value === to.value) return notify('The start and the end must differ.', 'warning');
|
||||
void page.patch({ hours: v }, `Allowed ${from.value}–${to.value}`);
|
||||
if (!TIME.test(from.value) || !TIME.test(to.value)) return notify(_('Enter both times, like 07:00 and 23:00.'), 'warning');
|
||||
if (from.value === to.value) return notify(_('The start and the end must differ.'), 'warning');
|
||||
void page.patch({ hours: v }, fmt(_('Allowed %s–%s'), from.value, to.value));
|
||||
};
|
||||
times.addEventListener('focusout', (ev: FocusEvent) => {
|
||||
if (!times.contains(ev.relatedTarget as Node | null)) commit();
|
||||
@@ -280,23 +298,23 @@ function hoursTile(page: PersonPage): HTMLElement {
|
||||
role: 'switch',
|
||||
'aria-checked': hoursOn ? 'true' : 'false',
|
||||
class: `dl-switch${hoursOn ? ' on' : ''}`,
|
||||
'aria-label': 'Limit hours',
|
||||
'aria-label': _('Limit hours'),
|
||||
// Turning on shows the times to set; nothing is enforced until they are saved.
|
||||
click: () => {
|
||||
if (hoursOn) return page.patch({ hours: '' }, 'Any time');
|
||||
if (hoursOn) return page.patch({ hours: '' }, _('Any time'));
|
||||
sw.classList.add('on');
|
||||
sw.setAttribute('aria-checked', 'true');
|
||||
label.textContent = 'Set the hours, then press Enter';
|
||||
label.textContent = _('Set the hours, then press Enter');
|
||||
tile.appendChild(times);
|
||||
from.focus();
|
||||
},
|
||||
},
|
||||
E('i'),
|
||||
);
|
||||
const label = E('span', {}, hoursOn ? `${h1} – ${h2} (router time)` : 'Any time');
|
||||
const label = E('span', {}, hoursOn ? fmt(_('%s – %s (router time)'), h1, h2) : _('Any time'));
|
||||
const tile = E('div', { class: 'dl-tile2' }, [
|
||||
E('div', { class: 'dl-tile2-row' }, [
|
||||
E('div', { class: 'dl-stack' }, [E('span', { class: 'dl-tile2-label' }, 'Allowed hours'), label]),
|
||||
E('div', { class: 'dl-stack' }, [E('span', { class: 'dl-tile2-label' }, _('Allowed hours')), label]),
|
||||
sw,
|
||||
]),
|
||||
hoursOn ? times : '',
|
||||
@@ -309,19 +327,27 @@ export function limitsPart(page: PersonPage): HTMLElement {
|
||||
const access = seg(
|
||||
(['internet', 'lan', 'both'] as const).map((a) => [
|
||||
a,
|
||||
[icon(a === 'internet' ? 'globe' : a === 'lan' ? 'home' : 'shield'), a === 'internet' ? 'Internet' : a === 'lan' ? 'Home' : 'Both'],
|
||||
[
|
||||
icon(a === 'internet' ? 'globe' : a === 'lan' ? 'home' : 'shield'),
|
||||
a === 'internet' ? _('Internet') : a === 'lan' ? _('Home') : _('Both'),
|
||||
],
|
||||
]),
|
||||
p.access,
|
||||
{ label: 'Access', cls: 'wide', optimistic: false, onChange: (a) => page.patch({ access: a }, `Access: ${ACCESS_LABEL[a]}`) },
|
||||
{
|
||||
label: _('Access'),
|
||||
cls: 'wide',
|
||||
optimistic: false,
|
||||
onChange: (a) => page.patch({ access: a }, fmt(_('Access: %s'), accessLabel(a))),
|
||||
},
|
||||
);
|
||||
// Heading above the card, like "Devices", so both columns line up (as on the portal).
|
||||
return E('section', { class: 'dl-devsec', 'aria-label': 'Access and limits' }, [
|
||||
E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Access & limits')]),
|
||||
return E('section', { class: 'dl-devsec', 'aria-label': _('Access and limits') }, [
|
||||
E('div', { class: 'dl-panel-head' }, [E('h3', {}, _('Access & limits'))]),
|
||||
E('div', { class: 'dl-panel' }, [
|
||||
E('div', { class: 'dl-stack gap8' }, [
|
||||
E('span', { class: 'dl-tile2-label' }, 'Can reach'),
|
||||
E('span', { class: 'dl-tile2-label' }, _('Can reach')),
|
||||
access,
|
||||
E('span', { class: 'dl-sub' }, ACCESS_TEXT[p.access]),
|
||||
E('span', { class: 'dl-sub' }, accessText(p.access)),
|
||||
p.access === 'lan' && page.st.services.length ? servicesPicker(page) : '',
|
||||
homeAccess(p) ? netsPicker(page) : '',
|
||||
p.access === 'lan' ? dnsPicker(page) : '',
|
||||
|
||||
@@ -8,6 +8,7 @@ import { dropdown } from '../../ui/menu';
|
||||
import { attachTip } from '../../ui/tooltip';
|
||||
import { icon } from '../../../shared/icons';
|
||||
import { ago, initials } from '../../../shared/format';
|
||||
import { fill, fmt, plural } from '../../../shared/i18n';
|
||||
import { circleDialog, circleDot, homeAccess } from '../../access';
|
||||
import type { PersonPage } from './index';
|
||||
|
||||
@@ -19,8 +20,8 @@ export function dnsPicker(page: PersonPage): HTMLElement {
|
||||
const p = page.p;
|
||||
const choice = seg(
|
||||
[
|
||||
['device', 'Device’s own DNS'],
|
||||
['home', 'Home names'],
|
||||
['device', _('Device’s own DNS')],
|
||||
['home', _('Home names')],
|
||||
],
|
||||
p.dns_mode,
|
||||
{
|
||||
@@ -30,7 +31,9 @@ export function dnsPicker(page: PersonPage): HTMLElement {
|
||||
onChange: (v) =>
|
||||
page.patch(
|
||||
{ dns_mode: v },
|
||||
v === 'home' ? 'Home names on — devices need their configuration again' : 'Device DNS — devices need their configuration again',
|
||||
v === 'home'
|
||||
? _('Home names on - devices need their configuration again')
|
||||
: _('Device DNS - devices need their configuration again'),
|
||||
),
|
||||
},
|
||||
);
|
||||
@@ -41,15 +44,19 @@ export function dnsPicker(page: PersonPage): HTMLElement {
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
p.dns_mode === 'home'
|
||||
? [
|
||||
'Names like ',
|
||||
E('span', { class: 'dl-mono' }, `nas.${page.st.settings.domain}`),
|
||||
' work. Internet names are resolved at home, so they depend on the tunnel',
|
||||
fb
|
||||
? [' (', E('span', { class: 'dl-mono' }, fb), ' takes over when it is down).']
|
||||
: ' — with no fallback set, they stop when it is down.',
|
||||
]
|
||||
: 'Internet keeps working exactly as without the VPN. Reach home devices by IP address.',
|
||||
? fb
|
||||
? fill(
|
||||
_('Names like %s work. Internet names are resolved at home, so they depend on the tunnel (%s takes over when it is down).'),
|
||||
E('span', { class: 'dl-mono' }, `nas.${page.st.settings.domain}`),
|
||||
E('span', { class: 'dl-mono' }, fb),
|
||||
)
|
||||
: fill(
|
||||
_(
|
||||
'Names like %s work. Internet names are resolved at home, so they depend on the tunnel - with no fallback set, they stop when it is down.',
|
||||
),
|
||||
E('span', { class: 'dl-mono' }, `nas.${page.st.settings.domain}`),
|
||||
)
|
||||
: _('Internet keeps working exactly as without the VPN. Reach home devices by IP address.'),
|
||||
),
|
||||
]);
|
||||
}
|
||||
@@ -72,11 +79,11 @@ export function netsPicker(page: PersonPage): HTMLElement | '' {
|
||||
() => {
|
||||
const next = new Set(picked);
|
||||
if (!next.delete(h.dev)) next.add(h.dev);
|
||||
if (!next.size) return notify('Keep at least one network, or choose Internet only.', 'warning', 5000);
|
||||
if (!next.size) return notify(_('Keep at least one network, or choose Internet only.'), 'warning', 5000);
|
||||
const list = next.size === all.length ? [] : [...next];
|
||||
void page.patch(
|
||||
{ home_nets: list },
|
||||
list.length ? `${p.name} reaches ${list.join(', ')}` : `${p.name} reaches every home network`,
|
||||
list.length ? fmt(_('%s reaches %s'), p.name, list.join(', ')) : fmt(_('%s reaches every home network'), p.name),
|
||||
);
|
||||
},
|
||||
{ title: h.nets.join(', ') },
|
||||
@@ -87,8 +94,8 @@ export function netsPicker(page: PersonPage): HTMLElement | '' {
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
p.home_nets?.length
|
||||
? `Home networks ${p.name} reaches. Networks added to the server later stay out.`
|
||||
: `Home networks ${p.name} reaches: all of them. Untick one to keep ${p.name} out of it.`,
|
||||
? fmt(_('Home networks %s reaches. Networks added to the server later stay out.'), p.name)
|
||||
: fmt(_('Home networks %s reaches: all of them. Untick one to keep %s out of it.'), p.name, p.name),
|
||||
),
|
||||
]);
|
||||
}
|
||||
@@ -108,7 +115,7 @@ export function servicesPicker(page: PersonPage): HTMLElement {
|
||||
// A copy: the chips show the saved choice until the router has it (a failed save changes nothing).
|
||||
const next = new Set(chosen);
|
||||
if (!next.delete(sv.id)) next.add(sv.id);
|
||||
void page.patch({ services: [...next] }, next.size ? 'Home services updated' : 'Whole home network');
|
||||
void page.patch({ services: [...next] }, next.size ? _('Home services updated') : _('Whole home network'));
|
||||
},
|
||||
{ title: `${sv.address}${sv.ports.length ? ` · ${sv.ports.join(', ')}` : ''}` },
|
||||
),
|
||||
@@ -117,7 +124,7 @@ export function servicesPicker(page: PersonPage): HTMLElement {
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
chosen.size ? 'Only the selected services at home.' : 'Whole home network. Pick services to narrow it down.',
|
||||
chosen.size ? _('Only the selected services at home.') : _('Whole home network. Pick services to narrow it down.'),
|
||||
),
|
||||
]);
|
||||
}
|
||||
@@ -141,20 +148,22 @@ export function circleTile(page: PersonPage): HTMLElement | '' {
|
||||
...circles.map((c) => ({
|
||||
label: c.name,
|
||||
icon: circleDot(c),
|
||||
run: () => c.id !== p.circle && page.patch({ circle: c.id }, `${p.name} is in ${c.name}`),
|
||||
run: () => c.id !== p.circle && page.patch({ circle: c.id }, fmt(_('%s is in %s'), p.name, c.name)),
|
||||
})),
|
||||
p.circle ? { label: 'No circle', icon: icon('x'), run: () => page.patch({ circle: '' }, `${p.name} is in no circle`) } : null,
|
||||
{ label: 'New circle', icon: icon('plus'), run: () => circleDialog(st, p.server, null, () => page.refresh()) },
|
||||
p.circle
|
||||
? { label: _('No circle'), icon: icon('x'), run: () => page.patch({ circle: '' }, fmt(_('%s is in no circle'), p.name)) }
|
||||
: null,
|
||||
{ label: _('New circle'), icon: icon('plus'), run: () => circleDialog(st, p.server, null, () => page.refresh()) },
|
||||
]),
|
||||
},
|
||||
'Change',
|
||||
_('Change'),
|
||||
);
|
||||
// As the other tiles: the name is the value; who is in it as avatars.
|
||||
const people = ci ? st.people.filter((x) => x.circle === ci.id && homeAccess(x)) : [p];
|
||||
return E('div', { class: 'dl-tile2' }, [
|
||||
E('div', { class: 'dl-tile2-label' }, [E('span', {}, 'Devices see each other'), change]),
|
||||
E('div', { class: 'dl-tile2-label' }, [E('span', {}, _('Devices see each other')), change]),
|
||||
E('div', { class: 'dl-tile2-row' }, [
|
||||
E('span', { class: 'dl-tile2-value' }, ci ? ci.name : 'No circle'),
|
||||
E('span', { class: 'dl-tile2-value' }, ci ? ci.name : _('No circle')),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-avstack', title: people.map((x) => x.name).join(', ') },
|
||||
@@ -164,7 +173,11 @@ export function circleTile(page: PersonPage): HTMLElement | '' {
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
!ci ? `Only ${p.name}'s own devices` : mates.length ? [p.name, ...mates].join(', ') : `Nobody else in ${ci.name} yet`,
|
||||
!ci
|
||||
? fmt(_("Only %s's own devices"), p.name)
|
||||
: mates.length
|
||||
? [p.name, ...mates].join(', ')
|
||||
: fmt(_('Nobody else in %s yet'), ci.name),
|
||||
),
|
||||
]);
|
||||
}
|
||||
@@ -180,11 +193,17 @@ export function devTile(page: PersonPage): HTMLElement {
|
||||
const over = i >= p.device_limit;
|
||||
const slot = E('i', { class: over ? 'over' : d ? 'used' : '' });
|
||||
attachTip(slot, () => [
|
||||
E('div', { class: 'dl-tip-title' }, d ? `${d.name}${over ? ' · over the limit' : ''}` : 'Free slot'),
|
||||
E('div', { class: 'dl-tip-title' }, d ? `${d.name}${over ? ` · ${_('over the limit')}` : ''}` : _('Free slot')),
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-muted' },
|
||||
d ? (d.online ? 'Connected' : d.handshake ? `Last seen ${ago(d.handshake, now)}` : 'Not set up yet') : 'They can add a device here',
|
||||
d
|
||||
? d.online
|
||||
? _('Connected')
|
||||
: d.handshake
|
||||
? fmt(_('Last seen %s'), ago(d.handshake, now))
|
||||
: _('Not set up yet')
|
||||
: _('They can add a device here'),
|
||||
),
|
||||
]);
|
||||
slots.appendChild(slot);
|
||||
@@ -194,7 +213,7 @@ export function devTile(page: PersonPage): HTMLElement {
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
'aria-label': 'Allow fewer devices',
|
||||
'aria-label': _('Allow fewer devices'),
|
||||
disabled: p.device_limit <= floor ? 'disabled' : null,
|
||||
click: () => page.patch({ device_limit: String(p.device_limit - 1) }),
|
||||
},
|
||||
@@ -202,11 +221,11 @@ export function devTile(page: PersonPage): HTMLElement {
|
||||
);
|
||||
if (p.device_limit <= floor && p.devices.length > 1)
|
||||
attachTip(minus, () => [
|
||||
E('div', { class: 'dl-tip-title' }, `${p.devices.length} devices in use`),
|
||||
E('div', { class: 'dl-muted' }, 'Remove a device first to lower the limit'),
|
||||
E('div', { class: 'dl-tip-title' }, plural(p.devices.length, '%s device in use', '%s devices in use')),
|
||||
E('div', { class: 'dl-muted' }, _('Remove a device first to lower the limit')),
|
||||
]);
|
||||
return E('div', { class: 'dl-tile2' }, [
|
||||
E('div', { class: 'dl-tile2-label' }, 'Devices'),
|
||||
E('div', { class: 'dl-tile2-label' }, _('Devices')),
|
||||
E('div', { class: 'dl-tile2-row' }, [
|
||||
E('span', { class: 'dl-tile2-value' }, [String(p.devices.length), E('span', { class: 'dl-faint' }, ` / ${p.device_limit}`)]),
|
||||
E('div', { class: 'dl-stepper' }, [
|
||||
@@ -215,7 +234,7 @@ export function devTile(page: PersonPage): HTMLElement {
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
'aria-label': 'Allow more devices',
|
||||
'aria-label': _('Allow more devices'),
|
||||
disabled: p.device_limit >= 32 ? 'disabled' : null,
|
||||
click: () => page.patch({ device_limit: String(p.device_limit + 1) }),
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user