Compare commits

...

23 Commits

Author SHA1 Message Date
CI
ae7f4edf4a chore: release version v1.52.0
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / Manual Approval (push) Blocked by required conditions
Build / 🛠 Build (1.17, 18.x, 27) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/arm64) (push) Blocked by required conditions
Build / merge (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2025-02-19 20:24:25 +00:00
Dmitry Popov
52eab28f27 feat(Map): Added map characters view 2025-02-19 21:12:51 +01:00
Dmitry Popov
6098d32bce chore: release version v1.51.3 2025-02-19 17:48:13 +01:00
CI
1839834771 chore: release version v1.51.3
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / Manual Approval (push) Blocked by required conditions
Build / 🛠 Build (1.17, 18.x, 27) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/arm64) (push) Blocked by required conditions
Build / merge (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2025-02-19 09:11:12 +00:00
guarzo
7cdfb87853 fix issue with deselection and linked sig splash filters (#187) 2025-02-19 12:23:22 +04:00
guarzo
3d54783a3e fix: pending deletion working again (#185)
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / Manual Approval (push) Blocked by required conditions
Build / 🛠 Build (1.17, 18.x, 27) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/arm64) (push) Blocked by required conditions
Build / merge (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2025-02-19 02:24:15 +04:00
CI
f965461820 chore: release version v1.51.2 2025-02-18 17:36:51 +00:00
Dmitry Popov
6d67f87d4b Sigs character name (#182)
* feat(Signatures): Added character names
2025-02-18 21:12:46 +04:00
CI
60697a50c2 chore: release version v1.51.1
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / Manual Approval (push) Blocked by required conditions
Build / 🛠 Build (1.17, 18.x, 27) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/arm64) (push) Blocked by required conditions
Build / merge (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2025-02-18 07:56:02 +00:00
guarzo
778d23da06 updates to acl api (#179) 2025-02-18 11:24:14 +04:00
CI
0ee9a15d5d chore: release version v1.51.0
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / Manual Approval (push) Blocked by required conditions
Build / 🛠 Build (1.17, 18.x, 27) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/arm64) (push) Blocked by required conditions
Build / merge (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2025-02-17 22:44:07 +00:00
guarzo
24bb902bb9 feat: add undo deletion for signatures (#155)
* feat: add undo for signature deletion and addition
2025-02-18 02:29:40 +04:00
CI
32fe6395a1 chore: release version v1.50.0
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / Manual Approval (push) Blocked by required conditions
Build / 🛠 Build (1.17, 18.x, 27) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/arm64) (push) Blocked by required conditions
Build / merge (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2025-02-17 00:09:15 +00:00
guarzo
5f506bf4b2 feat: allow addition of characters to acl without preregistration (#176) 2025-02-17 03:52:47 +04:00
CI
0127ebfe46 chore: release version v1.49.0
Some checks failed
Build / 🚀 Deploy to test env (fly.io) (push) Has been cancelled
Build / Manual Approval (push) Has been cancelled
Build / 🛠 Build (1.17, 18.x, 27) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/amd64) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/arm64) (push) Has been cancelled
Build / merge (push) Has been cancelled
Build / 🏷 Create Release (push) Has been cancelled
2025-02-15 08:37:43 +00:00
guarzo
8c5366fd9b feat: add api for acl management (#171) 2025-02-15 12:16:42 +04:00
CI
dbcad892a9 chore: release version v1.48.1
Some checks failed
Build / 🚀 Deploy to test env (fly.io) (push) Has been cancelled
Build / Manual Approval (push) Has been cancelled
Build / 🛠 Build (1.17, 18.x, 27) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/amd64) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/arm64) (push) Has been cancelled
Build / merge (push) Has been cancelled
Build / 🏷 Create Release (push) Has been cancelled
2025-02-13 17:40:15 +00:00
Dmitry Popov
6da3096db1 chore: release version v1.48.0 2025-02-13 18:04:28 +01:00
CI
cd8efcd6e3 chore: release version v1.48.0
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / Manual Approval (push) Blocked by required conditions
Build / 🛠 Build (1.17, 18.x, 27) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🛠 Build Docker Images (linux/arm64) (push) Blocked by required conditions
Build / merge (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2025-02-12 22:46:57 +00:00
Dmitry Popov
b52471ae5e chore: release version v1.47.6 2025-02-12 23:37:54 +01:00
Dmitry Popov
438fecb61f chore: release version v1.47.6 2025-02-12 23:07:45 +01:00
guarzo
70b589a359 System Kills cleanup (#166)
* fix: styling and count of kills tooltip
2025-02-13 01:23:36 +04:00
guarzo
cf7069b3b2 feat: autosize local character tooltip and increase hover target (#165) 2025-02-13 01:11:40 +04:00
79 changed files with 3561 additions and 1330 deletions

View File

@@ -1,7 +1,12 @@
{
"name": "wanderer-dev",
"dockerComposeFile": ["./docker-compose.yml"],
"extensions": ["jakebecker.elixir-ls"],
"extensions": [
"jakebecker.elixir-ls",
"JakeBecker.elixir-ls",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
],
"service": "wanderer",
"workspaceFolder": "/app",
"shutdownAction": "stopCompose",

View File

@@ -7,4 +7,5 @@ export EVE_CLIENT_WITH_WALLET_SECRET="<EVE_CLIENT_WITH_WALLET_SECRET>"
export GIT_SHA="1111"
export WANDERER_INVITES="false"
export WANDERER_PUBLIC_API_DISABLED="false"
export WANDERER_CHARACTER_API_DISABLED="false"
export WANDERER_ZKILL_PRELOAD_DISABLED="false"

View File

@@ -2,6 +2,77 @@
<!-- changelog -->
## [v1.52.0](https://github.com/wanderer-industries/wanderer/compare/v1.51.3...v1.52.0) (2025-02-19)
### Features:
* Map: Added map characters view
## [v1.51.3](https://github.com/wanderer-industries/wanderer/compare/v1.51.2...v1.51.3) (2025-02-19)
### Bug Fixes:
* pending deletion working again (#185)
## [v1.51.2](https://github.com/wanderer-industries/wanderer/compare/v1.51.1...v1.51.2) (2025-02-18)
## [v1.51.1](https://github.com/wanderer-industries/wanderer/compare/v1.51.0...v1.51.1) (2025-02-18)
## [v1.51.0](https://github.com/wanderer-industries/wanderer/compare/v1.50.0...v1.51.0) (2025-02-17)
### Features:
* add undo deletion for signatures (#155)
* add undo for signature deletion and addition
## [v1.50.0](https://github.com/wanderer-industries/wanderer/compare/v1.49.0...v1.50.0) (2025-02-17)
### Features:
* allow addition of characters to acl without preregistration (#176)
## [v1.49.0](https://github.com/wanderer-industries/wanderer/compare/v1.48.1...v1.49.0) (2025-02-15)
### Features:
* add api for acl management (#171)
## [v1.48.1](https://github.com/wanderer-industries/wanderer/compare/v1.48.0...v1.48.1) (2025-02-13)
## [v1.48.0](https://github.com/wanderer-industries/wanderer/compare/v1.47.6...v1.48.0) (2025-02-12)
### Features:
* autosize local character tooltip and increase hover target (#165)
## [v1.47.6](https://github.com/wanderer-industries/wanderer/compare/v1.47.5...v1.47.6) (2025-02-12)

View File

@@ -936,3 +936,66 @@ body > div:first-of-type {
width: 16px;
height: 16px;
}
.verticalTabsContainer {
display: flex;
width: 100%;
min-height: 300px;
}
.verticalTabsContainer .p-tabview {
width: 100%;
display: flex;
align-items: flex-start;
}
.verticalTabsContainer .p-tabview-panels {
padding: 6px 1rem !important;
flex-grow: 1;
height: 100%;
}
.verticalTabsContainer .p-tabview-nav-container {
border-right: none;
height: 100%;
}
.verticalTabsContainer .p-tabview-nav {
flex-direction: column;
width: 150px;
min-height: 100%;
border: none;
}
.verticalTabsContainer .p-tabview-nav li {
width: 100%;
border-right: 4px solid var(--surface-hover);
background-color: var(--surface-card);
transition:
background-color 200ms,
border-right-color 200ms;
}
.verticalTabsContainer .p-tabview-nav li:hover {
background-color: var(--surface-hover);
border-right: 4px solid var(--surface-100);
}
.verticalTabsContainer .p-tabview-nav li .p-tabview-nav-link {
transition: color 200ms;
justify-content: flex-end;
padding: 10px;
background-color: initial;
border: none;
color: var(--gray-400);
border-radius: initial;
font-weight: 400;
margin: 0;
}
.verticalTabsContainer .p-tabview-nav li.p-tabview-selected {
background-color: var(--surface-50);
border-right: 4px solid var(--primary-color);
}
.verticalTabsContainer .p-tabview-nav li.p-tabview-selected .p-tabview-nav-link {
font-weight: 600;
color: var(--primary-color);
}
.verticalTabsContainer .p-tabview-nav li.p-tabview-selected:hover {
border-right: 4px solid var(--primary-color);
}
.verticalTabsContainer .p-tabview-panel {
flex-grow: 1;
}

View File

@@ -37,7 +37,7 @@ const INITIAL_DATA: MapData = {
userPermissions: {},
systemSignatures: {} as Record<string, SystemSignature[]>,
options: {} as Record<string, string | boolean>,
is_subscription_active: false,
isSubscriptionActive: false,
};
export interface MapContextProps {

View File

@@ -11,35 +11,27 @@ type KillsBookmarkTooltipProps = {
systemId: string;
className?: string;
size?: TooltipSize;
timeRange?: number;
} & WithChildren &
WithClassName;
export const KillsCounter = ({
killsCount,
systemId,
className,
children,
size = 'xs',
timeRange = 1,
}: KillsBookmarkTooltipProps) => {
export const KillsCounter = ({ killsCount, systemId, className, children, size = 'xs' }: KillsBookmarkTooltipProps) => {
const { isLoading, kills: detailedKills, systemNameMap } = useKillsCounter({ realSystemId: systemId });
if (!killsCount || detailedKills.length === 0 || !systemId || isLoading) return null;
const tooltipContent = (
<SystemKillsContent
kills={detailedKills}
systemNameMap={systemNameMap}
compact={true}
onlyOneSystem={true}
autoSize={true}
timeRange={timeRange}
/>
<div style={{ width: '100%', minWidth: '300px', overflow: 'hidden' }}>
<SystemKillsContent
kills={detailedKills}
systemNameMap={systemNameMap}
onlyOneSystem={true}
autoSize={true}
limit={killsCount}
/>
</div>
);
return (
// @ts-ignore
<WdTooltipWrapper content={tooltipContent} className={className} size={size} interactive={true}>
{children}
</WdTooltipWrapper>

View File

@@ -4,6 +4,12 @@
z-index: 3;
}
.hoverTarget {
padding: 0.5rem;
margin: -0.5rem;
display: inline-block;
}
.localCounter {
mix-blend-mode: screen;
display: flex;

View File

@@ -24,13 +24,12 @@ export const LocalCounter = ({ localCounterCharacters, hasUserCharacters, showIc
return (
<div
style={{
width: '300px',
overflowX: 'hidden',
overflowY: 'auto',
height: '300px',
width: '100%',
minWidth: '300px',
overflow: 'hidden',
}}
>
<LocalCharactersList items={localCounterCharacters} itemTemplate={itemTemplate} itemSize={26} />
<LocalCharactersList items={localCounterCharacters} itemTemplate={itemTemplate} itemSize={26} autoSize={true} />
</div>
);
}, [localCounterCharacters, itemTemplate]);
@@ -45,19 +44,16 @@ export const LocalCounter = ({ localCounterCharacters, hasUserCharacters, showIc
[classes.Pathfinder]: theme === AvailableThemes.pathfinder,
})}
>
<WdTooltipWrapper
// @ts-ignore
content={pilotTooltipContent}
position={TooltipPosition.right}
offset={0}
>
<div
className={clsx(classes.localCounter, {
[classes.hasUserCharacters]: hasUserCharacters,
})}
>
{showIcon && <i className="pi pi-users" />}
<span>{localCounterCharacters.length}</span>
<WdTooltipWrapper content={pilotTooltipContent} position={TooltipPosition.right} offset={0} interactive={true}>
<div className={clsx(classes.hoverTarget)}>
<div
className={clsx(classes.localCounter, {
[classes.hasUserCharacters]: hasUserCharacters,
})}
>
{showIcon && <i className="pi pi-users" />}
<span>{localCounterCharacters.length}</span>
</div>
</div>
</WdTooltipWrapper>
</div>

View File

@@ -90,11 +90,7 @@ $tooltip-bg: #202020;
&.eve-system-status-home {
border: 1px solid var(--eve-solar-system-status-color-home-dark30);
background-image: linear-gradient(
45deg,
var(--eve-solar-system-status-color-background),
transparent
);
background-image: linear-gradient(45deg, var(--eve-solar-system-status-color-background), transparent);
&.selected {
border-color: var(--eve-solar-system-status-color-home);
}
@@ -102,11 +98,7 @@ $tooltip-bg: #202020;
&.eve-system-status-friendly {
border: 1px solid var(--eve-solar-system-status-color-friendly-dark20);
background-image: linear-gradient(
275deg,
var(--eve-solar-system-status-friendly-dark30),
transparent
);
background-image: linear-gradient(275deg, var(--eve-solar-system-status-friendly-dark30), transparent);
&.selected {
border-color: var(--eve-solar-system-status-color-friendly-dark5);
}
@@ -121,27 +113,15 @@ $tooltip-bg: #202020;
}
&.eve-system-status-warning {
background-image: linear-gradient(
275deg,
var(--eve-solar-system-status-warning),
transparent
);
background-image: linear-gradient(275deg, var(--eve-solar-system-status-warning), transparent);
}
&.eve-system-status-dangerous {
background-image: linear-gradient(
275deg,
var(--eve-solar-system-status-dangerous),
transparent
);
background-image: linear-gradient(275deg, var(--eve-solar-system-status-dangerous), transparent);
}
&.eve-system-status-target {
background-image: linear-gradient(
275deg,
var(--eve-solar-system-status-target),
transparent
);
background-image: linear-gradient(275deg, var(--eve-solar-system-status-target), transparent);
}
}
@@ -254,7 +234,7 @@ $tooltip-bg: #202020;
font-size: 11px;
font-weight: 500;
text-shadow: 0 0 2px rgba(231, 146, 52, 0.73);
color: var(--rf-tag-color, #38BDF8);
color: var(--rf-tag-color, #38bdf8);
}
/* Firefox kostyl */
@@ -263,7 +243,6 @@ $tooltip-bg: #202020;
font-weight: bold;
}
}
}
.BottomRow {
@@ -376,4 +355,3 @@ $tooltip-bg: #202020;
}
}
}

View File

@@ -3,11 +3,13 @@ import { VirtualScroller, VirtualScrollerTemplateOptions } from 'primereact/virt
import clsx from 'clsx';
import { CharItemProps } from './types';
type LocalCharactersListProps = {
export type LocalCharactersListProps = {
items: Array<CharItemProps>;
itemSize: number;
itemTemplate: (char: CharItemProps, options: VirtualScrollerTemplateOptions) => React.ReactNode;
containerClassName?: string;
style?: React.CSSProperties;
autoSize?: boolean;
};
export const LocalCharactersList = ({
@@ -15,7 +17,19 @@ export const LocalCharactersList = ({
itemSize,
itemTemplate,
containerClassName,
style = {},
autoSize = false,
}: LocalCharactersListProps) => {
const computedHeight = autoSize ? `${Math.max(items.length, 1) * itemSize}px` : style.height || '100%';
const localStyle: React.CSSProperties = {
...style,
height: computedHeight,
width: '100%',
boxSizing: 'border-box',
overflowX: 'hidden',
};
return (
<VirtualScroller
items={items}
@@ -23,6 +37,8 @@ export const LocalCharactersList = ({
orientation="vertical"
className={clsx('w-full h-full', containerClassName)}
itemTemplate={itemTemplate}
autoSize={autoSize}
style={localStyle}
/>
);
};

View File

@@ -91,10 +91,8 @@ export const SystemKills: React.FC = React.memo(() => {
) : (
<div className="w-full h-full" style={{ height: '100%' }}>
<SystemKillsContent
key={settings.compact ? 'compact' : 'normal'}
kills={filteredKills}
systemNameMap={systemNameMap}
compact={settings.compact}
onlyOneSystem={!visible}
timeRange={settings.timeRange}
/>

View File

@@ -1,18 +1,12 @@
.TableRowCompact {
height: 8px;
max-height: 8px;
font-size: 12px !important;
line-height: 8px;
.wrapper {
overflow-x: hidden;
box-sizing: border-box;
}
.Table {
font-size: 12px;
border-collapse: collapse;
}
.Tooltip {
white-space: pre-line;
line-height: 1.2rem;
.scrollerContent {
width: 100%;
box-sizing: border-box;
overflow-x: hidden;
}
.VirtualScroller {

View File

@@ -2,57 +2,54 @@ import React, { useMemo, useRef, useEffect, useState } from 'react';
import clsx from 'clsx';
import { DetailedKill } from '@/hooks/Mapper/types/kills';
import { VirtualScroller } from 'primereact/virtualscroller';
import { useSystemKillsItemTemplate } from '../hooks/useSystemKillsTemplate';
import { useSystemKillsItemTemplate } from '../hooks/useSystemKillsItemTemplate';
import classes from './SystemKillsContent.module.scss';
export const ITEM_HEIGHT = 35;
export const CONTENT_MARGINS = 5;
export interface SystemKillsContentProps {
kills: DetailedKill[];
systemNameMap: Record<string, string>;
compact?: boolean;
onlyOneSystem?: boolean;
autoSize?: boolean;
timeRange: number;
timeRange?: number;
limit?: number;
}
export const SystemKillsContent: React.FC<SystemKillsContentProps> = ({
kills,
systemNameMap,
compact = false,
onlyOneSystem = false,
autoSize = false,
timeRange = 1,
timeRange = 4,
limit,
}) => {
const processedKills = useMemo(() => {
const validKills = kills.filter(kill => kill.kill_time);
const sortedKills = kills
.filter(k => k.kill_time)
.sort((a, b) => new Date(b.kill_time!).getTime() - new Date(a.kill_time!).getTime());
const sortedKills = validKills.sort((a, b) => {
const timeA = a.kill_time ? new Date(a.kill_time).getTime() : 0;
const timeB = b.kill_time ? new Date(b.kill_time).getTime() : 0;
return timeB - timeA;
});
if (limit !== undefined) {
return sortedKills.slice(0, limit);
} else {
const now = Date.now();
const cutoff = now - timeRange * 60 * 60 * 1000;
return sortedKills.filter(k => new Date(k.kill_time!).getTime() >= cutoff);
}
}, [kills, timeRange, limit]);
const now = Date.now();
const cutoff = now - timeRange * 60 * 60 * 1000;
return sortedKills.filter(kill => {
if (!kill.kill_time) return false;
const killTime = new Date(kill.kill_time).getTime();
return killTime >= cutoff;
});
}, [kills, timeRange]);
const itemSize = compact ? 35 : 50;
const computedHeight = autoSize ? Math.max(processedKills.length, 1) * itemSize + 5 : undefined;
const computedHeight = autoSize ? Math.max(processedKills.length, 1) * ITEM_HEIGHT + CONTENT_MARGINS : undefined;
const containerRef = useRef<HTMLDivElement>(null);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const scrollerRef = useRef<any>(null);
const scrollerRef = useRef<VirtualScroller | null>(null);
const [containerHeight, setContainerHeight] = useState<number>(0);
useEffect(() => {
if (!autoSize && containerRef.current) {
const measure = () => {
const newHeight = containerRef.current?.clientHeight ?? 0;
const newHeight = containerRef.current?.clientHeight || 0;
setContainerHeight(newHeight);
scrollerRef.current?.refresh?.();
};
measure();
@@ -67,18 +64,27 @@ export const SystemKillsContent: React.FC<SystemKillsContentProps> = ({
}
}, [autoSize]);
const itemTemplate = useSystemKillsItemTemplate(systemNameMap, compact, onlyOneSystem);
const itemTemplate = useSystemKillsItemTemplate(systemNameMap, onlyOneSystem);
const scrollerHeight = autoSize ? `${computedHeight}px` : containerHeight ? `${containerHeight}px` : '100%';
return (
<div ref={autoSize ? undefined : containerRef} className="w-full h-full">
<div ref={autoSize ? undefined : containerRef} className={clsx('w-full h-full', classes.wrapper)}>
<VirtualScroller
ref={autoSize ? undefined : scrollerRef}
items={processedKills}
itemSize={itemSize}
itemSize={ITEM_HEIGHT}
itemTemplate={itemTemplate}
autoSize={autoSize}
style={{ height: autoSize ? `${computedHeight}px` : containerHeight ? `${containerHeight}px` : '100%' }}
className={clsx('w-full h-full overflow-x-hidden overflow-y-auto custom-scrollbar select-none')}
scrollWidth="100%"
style={{ height: scrollerHeight }}
className={clsx('w-full h-full custom-scrollbar select-none overflow-x-hidden overflow-y-auto', {
[classes.VirtualScroller]: !autoSize,
})}
pt={{
content: {
className: classes.scrollerContent,
},
}}
/>
</div>
);

View File

@@ -1,214 +0,0 @@
import React from 'react';
import clsx from 'clsx';
import { DetailedKill } from '@/hooks/Mapper/types/kills';
import {
formatISK,
formatTimeMixed,
zkillLink,
getAttackerSubscript,
buildVictimImageUrls,
buildAttackerImageUrls,
getPrimaryLogoAndTooltip,
getAttackerPrimaryImageAndTooltip,
} from '../helpers';
import { VictimRowSubInfo } from './VictimRowSubInfo';
import { WdTooltipWrapper } from '../../../../ui-kit/WdTooltipWrapper';
import classes from './SystemKillRow.module.scss';
import { TooltipPosition } from '@/hooks/Mapper/components/ui-kit';
export interface FullKillRowProps {
killDetails: DetailedKill;
systemName: string;
onlyOneSystem: boolean;
}
export const FullKillRow: React.FC<FullKillRowProps> = ({ killDetails, systemName, onlyOneSystem }) => {
const {
killmail_id = 0,
// Victim data
victim_char_name = '',
victim_alliance_ticker = '',
victim_corp_ticker = '',
victim_ship_name = '',
victim_char_id = 0,
victim_corp_id = 0,
victim_alliance_id = 0,
victim_ship_type_id = 0,
victim_corp_name = '',
victim_alliance_name = '',
// Attacker data
final_blow_char_id = 0,
final_blow_char_name = '',
final_blow_alliance_ticker = '',
final_blow_corp_ticker = '',
final_blow_corp_name = '',
final_blow_alliance_name = '',
final_blow_corp_id = 0,
final_blow_alliance_id = 0,
final_blow_ship_name = '',
final_blow_ship_type_id = 0,
total_value = 0,
kill_time = '',
} = killDetails || {};
const attackerIsNpc = final_blow_char_id === 0;
const victimAffiliation = victim_alliance_ticker || victim_corp_ticker || null;
const attackerAffiliation = attackerIsNpc ? '' : final_blow_alliance_ticker || final_blow_corp_ticker || '';
const killValueFormatted = total_value != null && total_value > 0 ? `${formatISK(total_value)} ISK` : null;
const killTimeAgo = kill_time ? formatTimeMixed(kill_time) : '0h ago';
// Build victim images
const { victimPortraitUrl, victimCorpLogoUrl, victimAllianceLogoUrl, victimShipUrl } = buildVictimImageUrls({
victim_char_id,
victim_ship_type_id,
victim_corp_id,
victim_alliance_id,
});
// Build attacker images
const { attackerPortraitUrl, attackerCorpLogoUrl, attackerAllianceLogoUrl } = buildAttackerImageUrls({
final_blow_char_id,
final_blow_corp_id,
final_blow_alliance_id,
});
// Primary image for victim
const { url: victimPrimaryImageUrl, tooltip: victimPrimaryTooltip } = getPrimaryLogoAndTooltip(
victimAllianceLogoUrl,
victimCorpLogoUrl,
victim_alliance_name,
victim_corp_name,
'Victim',
);
// Primary image for attacker
const { url: attackerPrimaryImageUrl, tooltip: attackerPrimaryTooltip } = getAttackerPrimaryImageAndTooltip(
attackerIsNpc,
attackerAllianceLogoUrl,
attackerCorpLogoUrl,
final_blow_alliance_name,
final_blow_corp_name,
final_blow_ship_type_id,
);
const attackerSubscript = getAttackerSubscript(killDetails);
return (
<div className={clsx(classes.killRowContainer, 'w-full text-sm py-1 px-2', 'flex flex-col sm:flex-row')}>
<div className="w-full flex flex-col sm:flex-row items-start gap-2">
{/* Victim Section */}
<div className="flex items-start gap-1 min-w-0">
{victimShipUrl && (
<div className="relative shrink-0 w-12 h-12 sm:w-14 sm:h-14 overflow-hidden">
<a
href={zkillLink('kill', killmail_id)}
target="_blank"
rel="noopener noreferrer"
className="block w-full h-full"
>
<img
src={victimShipUrl}
alt="VictimShip"
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
/>
</a>
</div>
)}
{victimPrimaryImageUrl && (
<WdTooltipWrapper content={victimPrimaryTooltip} position={TooltipPosition.top}>
<div className="relative shrink-0 w-12 h-12 sm:w-14 sm:h-14 overflow-hidden">
<a
href={zkillLink('kill', killmail_id)}
target="_blank"
rel="noopener noreferrer"
className="block w-full h-full"
>
<img
src={victimPrimaryImageUrl}
alt="VictimPrimaryLogo"
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
/>
</a>
</div>
</WdTooltipWrapper>
)}
<VictimRowSubInfo
victimCharName={victim_char_name}
victimCharacterId={victim_char_id}
victimPortraitUrl={victimPortraitUrl}
/>
<div className="flex flex-col flex-1 text-stone-200 leading-4 min-w-0 overflow-hidden">
<div className="truncate font-semibold">
{victim_char_name}
{victimAffiliation && <span className="ml-1 text-stone-400">/ {victimAffiliation}</span>}
</div>
<div className="truncate text-stone-300">
{victim_ship_name}
{killValueFormatted && (
<>
<span className="ml-1 text-stone-400">/</span>
<span className="ml-1 text-green-400">{killValueFormatted}</span>
</>
)}
</div>
<div className="truncate text-stone-400">{!onlyOneSystem && systemName && <span>{systemName}</span>}</div>
</div>
</div>
<div className="flex items-start gap-1 min-w-0 sm:ml-auto">
<div className="flex flex-col flex-1 items-end leading-4 min-w-0 overflow-hidden text-right">
{!attackerIsNpc && (
<div className="truncate font-semibold">
{final_blow_char_name}
{attackerAffiliation && <span className="ml-1 text-stone-400">/ {attackerAffiliation}</span>}
</div>
)}
{!attackerIsNpc && final_blow_ship_name && (
<div className="truncate text-stone-300">{final_blow_ship_name}</div>
)}
<div className="truncate text-red-400">{killTimeAgo}</div>
</div>
{!attackerIsNpc && attackerPortraitUrl && final_blow_char_id &&final_blow_char_id > 0 && (
<div className="relative shrink-0 w-12 h-12 sm:w-14 sm:h-14 overflow-hidden">
<a
href={zkillLink('character', final_blow_char_id)}
target="_blank"
rel="noopener noreferrer"
className="block w-full h-full"
>
<img
src={attackerPortraitUrl}
alt="AttackerPortrait"
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
/>
</a>
</div>
)}
{attackerPrimaryImageUrl && (
<WdTooltipWrapper content={attackerPrimaryTooltip} position={TooltipPosition.top}>
<div className="relative shrink-0 w-12 h-12 sm:w-14 sm:h-14 overflow-hidden">
<a
href={zkillLink('kill', killmail_id)}
target="_blank"
rel="noopener noreferrer"
className="block w-full h-full"
>
<img
src={attackerPrimaryImageUrl}
alt={attackerIsNpc ? 'NpcShip' : 'AttackerPrimaryLogo'}
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
/>
{attackerSubscript && (
<span className={clsx(attackerSubscript.cssClass, classes.attackerCountLabel)}>
{attackerSubscript.label}
</span>
)}
</a>
</div>
</WdTooltipWrapper>
)}
</div>
</div>
</div>
);
};

View File

@@ -5,7 +5,6 @@ import clsx from 'clsx';
export function KillItemTemplate(
systemNameMap: Record<string, string>,
compact: boolean,
onlyOneSystem: boolean,
kill: DetailedKill,
options: VirtualScrollerTemplateOptions,
@@ -15,7 +14,7 @@ export function KillItemTemplate(
return (
<div style={{ height: `${options.props.itemSize}px` }} className={clsx({ 'bg-gray-900': options.odd })}>
<KillRow killDetails={kill} systemName={systemName} isCompact={compact} onlyOneSystem={onlyOneSystem} />
<KillRow killDetails={kill} systemName={systemName} onlyOneSystem={onlyOneSystem} />
</div>
);
}

View File

@@ -11,8 +11,8 @@ import {
getPrimaryLogoAndTooltip,
getAttackerPrimaryImageAndTooltip,
} from '../helpers';
import { WdTooltipWrapper } from '../../../../ui-kit/WdTooltipWrapper';
import classes from './SystemKillRow.module.scss';
import { WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit';
import classes from './KillRowDetail.module.scss';
import { TooltipPosition } from '@/hooks/Mapper/components/ui-kit';
export interface CompactKillRowProps {
@@ -21,10 +21,10 @@ export interface CompactKillRowProps {
onlyOneSystem: boolean;
}
export const CompactKillRow: React.FC<CompactKillRowProps> = ({ killDetails, systemName, onlyOneSystem }) => {
export const KillRowDetail: React.FC<CompactKillRowProps> = ({ killDetails, systemName, onlyOneSystem }) => {
const {
killmail_id = 0,
// Victim
// Victim data
victim_char_name = 'Unknown Pilot',
victim_alliance_ticker = '',
victim_corp_ticker = '',
@@ -35,7 +35,7 @@ export const CompactKillRow: React.FC<CompactKillRowProps> = ({ killDetails, sys
victim_corp_id = 0,
victim_alliance_id = 0,
victim_ship_type_id = 0,
// Attacker
// Attacker data
final_blow_char_id = 0,
final_blow_char_name = '',
final_blow_alliance_ticker = '',
@@ -51,11 +51,12 @@ export const CompactKillRow: React.FC<CompactKillRowProps> = ({ killDetails, sys
const attackerIsNpc = final_blow_char_id === 0;
// Define victim affiliation ticker.
const victimAffiliationTicker = victim_alliance_ticker || victim_corp_ticker || 'No Ticker';
const killValueFormatted = total_value != null && total_value > 0 ? `${formatISK(total_value)} ISK` : null;
const attackerName = attackerIsNpc ? '' : final_blow_char_name;
const attackerTicker = attackerIsNpc ? '' : final_blow_alliance_ticker || final_blow_corp_ticker || '';
const killTimeAgo = kill_time ? formatTimeMixed(kill_time) : '0h ago';
const attackerSubscript = getAttackerSubscript(killDetails);
const { victimCorpLogoUrl, victimAllianceLogoUrl, victimShipUrl } = buildVictimImageUrls({
@@ -88,6 +89,12 @@ export const CompactKillRow: React.FC<CompactKillRowProps> = ({ killDetails, sys
final_blow_ship_type_id,
);
// Define attackerTicker to use the alliance ticker if available, otherwise the corp ticker.
const attackerTicker = attackerIsNpc ? '' : final_blow_alliance_ticker || final_blow_corp_ticker || '';
// For the attacker image link: if the attacker is not an NPC, link to the character page; otherwise, link to the kill page.
const attackerLink = attackerIsNpc ? zkillLink('kill', killmail_id) : zkillLink('character', final_blow_char_id);
return (
<div
className={clsx(
@@ -95,6 +102,7 @@ export const CompactKillRow: React.FC<CompactKillRowProps> = ({ killDetails, sys
'text-xs whitespace-nowrap overflow-hidden leading-none',
)}
>
{/* Victim Section */}
<div className="flex items-center gap-1">
{victimShipUrl && (
<div className="relative shrink-0 w-8 h-8 overflow-hidden">
@@ -106,7 +114,7 @@ export const CompactKillRow: React.FC<CompactKillRowProps> = ({ killDetails, sys
>
<img
src={victimShipUrl}
alt="VictimShip"
alt="Victim Ship"
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
/>
</a>
@@ -122,7 +130,7 @@ export const CompactKillRow: React.FC<CompactKillRowProps> = ({ killDetails, sys
>
<img
src={victimPrimaryLogoUrl}
alt="VictimPrimaryLogo"
alt="Victim Primary Logo"
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
/>
</a>
@@ -146,10 +154,10 @@ export const CompactKillRow: React.FC<CompactKillRowProps> = ({ killDetails, sys
</div>
<div className="flex items-center ml-auto gap-2">
<div className="flex flex-col items-end flex-1 min-w-0 overflow-hidden text-right leading-[1rem]">
{!attackerIsNpc && (attackerName || attackerTicker) && (
{!attackerIsNpc && (final_blow_char_name || attackerTicker) && (
<div className="truncate text-stone-200">
{attackerName}
{attackerTicker && <span className="ml-1 text-stone-400">/ {attackerTicker}</span>}
{final_blow_char_name}
{!attackerIsNpc && attackerTicker && <span className="ml-1 text-stone-400">/ {attackerTicker}</span>}
</div>
)}
<div className="truncate text-stone-400">
@@ -165,14 +173,14 @@ export const CompactKillRow: React.FC<CompactKillRowProps> = ({ killDetails, sys
{attackerPrimaryImageUrl && (
<WdTooltipWrapper content={attackerPrimaryTooltip} position={TooltipPosition.top}>
<a
href={zkillLink('kill', killmail_id)}
href={attackerLink}
target="_blank"
rel="noopener noreferrer"
className="relative block shrink-0 w-8 h-8 overflow-hidden"
>
<img
src={attackerPrimaryImageUrl}
alt={attackerIsNpc ? 'NpcShip' : 'AttackerPrimaryLogo'}
alt={attackerIsNpc ? 'NPC Ship' : 'Attacker Primary Logo'}
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
/>
{attackerSubscript && (

View File

@@ -1,25 +1,15 @@
import React from 'react';
import { DetailedKill } from '@/hooks/Mapper/types/kills';
import { CompactKillRow } from './CompactKillRow';
import { FullKillRow } from './FullKillRow';
import { KillRowDetail } from './KillRowDetail.tsx';
export interface KillRowProps {
killDetails: DetailedKill;
systemName: string;
isCompact?: boolean;
onlyOneSystem?: boolean;
}
const KillRowComponent: React.FC<KillRowProps> = ({
killDetails,
systemName,
isCompact = false,
onlyOneSystem = false,
}) => {
if (isCompact) {
return <CompactKillRow killDetails={killDetails} systemName={systemName} onlyOneSystem={onlyOneSystem} />;
}
return <FullKillRow killDetails={killDetails} systemName={systemName} onlyOneSystem={onlyOneSystem} />;
const KillRowComponent: React.FC<KillRowProps> = ({ killDetails, systemName, onlyOneSystem = false }) => {
return <KillRowDetail killDetails={killDetails} systemName={systemName} onlyOneSystem={onlyOneSystem} />;
};
export const KillRow = React.memo(KillRowComponent);

View File

@@ -1,14 +1,14 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Dialog } from 'primereact/dialog';
import { Button } from 'primereact/button';
import { InputSwitch } from 'primereact/inputswitch';
import { WdImgButton, SystemView, TooltipPosition } from '@/hooks/Mapper/components/ui-kit';
import { WdImgButton } from '@/hooks/Mapper/components/ui-kit';
import { PrimeIcons } from 'primereact/api';
import { useKillsWidgetSettings } from '../hooks/useKillsWidgetSettings';
import {
AddSystemDialog,
SearchOnSubmitCallback,
} from '@/hooks/Mapper/components/mapInterface/components/AddSystemDialog';
import { SystemView, TooltipPosition } from '@/hooks/Mapper/components/ui-kit';
interface KillsSettingsDialogProps {
visible: boolean;
@@ -18,7 +18,6 @@ interface KillsSettingsDialogProps {
export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visible, setVisible }) => {
const [globalSettings, setGlobalSettings] = useKillsWidgetSettings();
const localRef = useRef({
compact: globalSettings.compact,
showAll: globalSettings.showAll,
whOnly: globalSettings.whOnly,
excludedSystems: globalSettings.excludedSystems || [],
@@ -31,7 +30,6 @@ export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visibl
useEffect(() => {
if (visible) {
localRef.current = {
compact: globalSettings.compact,
showAll: globalSettings.showAll,
whOnly: globalSettings.whOnly,
excludedSystems: globalSettings.excludedSystems || [],
@@ -41,14 +39,6 @@ export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visibl
}
}, [visible, globalSettings]);
const handleCompactChange = useCallback((checked: boolean) => {
localRef.current = {
...localRef.current,
compact: checked,
};
forceRender(n => n + 1);
}, []);
const handleWHChange = useCallback((checked: boolean) => {
localRef.current = {
...localRef.current,
@@ -57,8 +47,7 @@ export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visibl
forceRender(n => n + 1);
}, []);
// Updated handler to set time range as a number: 1 or 24
const handleTimeRangeChange = useCallback((newTimeRange: 1 | 24) => {
const handleTimeRangeChange = useCallback((newTimeRange: number) => {
localRef.current = {
...localRef.current,
timeRange: newTimeRange,
@@ -99,22 +88,11 @@ export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visibl
const localData = localRef.current;
const excluded = localData.excludedSystems || [];
const timeRangeOptions = [4, 12, 24];
return (
<Dialog header="Kills Settings" visible={visible} style={{ width: '440px' }} draggable={false} onHide={handleHide}>
<div className="flex flex-col gap-3 p-2.5">
<div className="flex items-center gap-2">
<input
type="checkbox"
id="kills-compact-mode"
checked={localData.compact}
onChange={e => handleCompactChange(e.target.checked)}
/>
<label htmlFor="kills-compact-mode" className="cursor-pointer">
Use compact mode
</label>
</div>
<div className="flex items-center gap-2">
<input
type="checkbox"
@@ -127,13 +105,25 @@ export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visibl
</label>
</div>
{/* Time Range Toggle using InputSwitch */}
<div className="flex items-center gap-2">
<div className="flex flex-col gap-1">
<span className="text-sm">Time Range:</span>
<InputSwitch checked={localData.timeRange === 24} onChange={e => handleTimeRangeChange(e.value ? 24 : 1)} />
<span className="text-sm">{localData.timeRange === 24 ? '24 Hours' : '1 Hour'}</span>
<div className="flex flex-wrap gap-2">
{timeRangeOptions.map(option => (
<label key={option} className="cursor-pointer flex items-center gap-1">
<input
type="radio"
name="timeRange"
value={option}
checked={localData.timeRange === option}
onChange={() => handleTimeRangeChange(option)}
/>
<span className="text-sm">{option} Hours</span>
</label>
))}
</div>
</div>
{/* Excluded Systems */}
<div className="flex flex-col gap-1">
<div className="flex items-center justify-between">
<label className="text-sm text-stone-400">Excluded Systems</label>
@@ -146,8 +136,7 @@ export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visibl
{excluded.length === 0 && <div className="text-stone-500 text-xs italic">No systems excluded.</div>}
{excluded.map(sysId => (
<div key={sysId} className="flex items-center justify-between border-b border-stone-600 py-1 px-1 text-xs">
<SystemView systemId={sysId.toString()} hideRegion compact />
<SystemView systemId={sysId.toString()} hideRegion />
<WdImgButton
className={PrimeIcons.TRASH}
onClick={() => handleRemoveSystem(sysId)}

View File

@@ -1,39 +0,0 @@
import React from 'react';
import clsx from 'clsx';
import { zkillLink } from '../helpers';
import classes from './SystemKillRow.module.scss';
interface VictimRowSubInfoProps {
victimCharacterId: number | null;
victimPortraitUrl: string | null;
victimCharName?: string;
}
export const VictimRowSubInfo: React.FC<VictimRowSubInfoProps> = ({
victimCharacterId = 0,
victimPortraitUrl,
victimCharName,
}) => {
if (!victimPortraitUrl || !victimCharacterId || victimCharacterId <= 0) {
return null;
}
return (
<div className="flex items-start gap-1">
<div className="relative shrink-0 w-12 h-12 sm:w-14 sm:h-14 overflow-hidden">
<a
href={zkillLink('character', victimCharacterId)}
target="_blank"
rel="noopener noreferrer"
className="block w-full h-full"
>
<img
src={victimPortraitUrl}
alt={victimCharName || 'Victim Portrait'}
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
/>
</a>
</div>
</div>
);
};

View File

@@ -2,7 +2,6 @@ import { useMemo, useCallback } from 'react';
import useLocalStorageState from 'use-local-storage-state';
export interface KillsWidgetSettings {
compact: boolean;
showAll: boolean;
whOnly: boolean;
excludedSystems: number[];
@@ -11,11 +10,10 @@ export interface KillsWidgetSettings {
}
export const DEFAULT_KILLS_WIDGET_SETTINGS: KillsWidgetSettings = {
compact: true,
showAll: false,
whOnly: true,
excludedSystems: [],
version: 1,
version: 2,
timeRange: 1,
};

View File

@@ -4,14 +4,10 @@ import { VirtualScrollerTemplateOptions } from 'primereact/virtualscroller';
import { DetailedKill } from '@/hooks/Mapper/types/kills';
import { KillItemTemplate } from '../components/KillItemTemplate';
export function useSystemKillsItemTemplate(
systemNameMap: Record<string, string>,
compact: boolean,
onlyOneSystem: boolean,
) {
export function useSystemKillsItemTemplate(systemNameMap: Record<string, string>, onlyOneSystem: boolean) {
return useCallback(
(kill: DetailedKill, options: VirtualScrollerTemplateOptions) =>
KillItemTemplate(systemNameMap, compact, onlyOneSystem, kill, options),
[systemNameMap, compact, onlyOneSystem],
KillItemTemplate(systemNameMap, onlyOneSystem, kill, options),
[systemNameMap, onlyOneSystem],
);
}

View File

@@ -1,3 +1,4 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Widget } from '@/hooks/Mapper/components/mapInterface/components';
import {
InfoDrawer,
@@ -19,28 +20,29 @@ import {
STRUCTURE,
SystemSignatureSettingsDialog,
} from './SystemSignatureSettingsDialog';
import { SignatureGroup } from '@/hooks/Mapper/types';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { SignatureGroup, SystemSignature } from '@/hooks/Mapper/types';
import { PrimeIcons } from 'primereact/api';
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
import { CheckboxChangeEvent } from 'primereact/checkbox';
import useMaxWidth from '@/hooks/Mapper/hooks/useMaxWidth.ts';
import useMaxWidth from '@/hooks/Mapper/hooks/useMaxWidth';
import { WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit/WdTooltipWrapper';
import { useHotkey } from '@/hooks/Mapper/hooks';
import { COMPACT_MAX_WIDTH } from './constants';
const SIGNATURE_SETTINGS_KEY = 'wanderer_system_signature_settings_v5_2';
const SIGNATURE_SETTINGS_KEY = 'wanderer_system_signature_settings_v5_5';
export const SHOW_DESCRIPTION_COLUMN_SETTING = 'show_description_column_setting';
export const SHOW_UPDATED_COLUMN_SETTING = 'SHOW_UPDATED_COLUMN_SETTING';
export const SHOW_CHARACTER_COLUMN_SETTING = 'SHOW_CHARACTER_COLUMN_SETTING';
export const LAZY_DELETE_SIGNATURES_SETTING = 'LAZY_DELETE_SIGNATURES_SETTING';
export const KEEP_LAZY_DELETE_SETTING = 'KEEP_LAZY_DELETE_ENABLED_SETTING';
const settings: Setting[] = [
const SETTINGS: Setting[] = [
{ key: SHOW_UPDATED_COLUMN_SETTING, name: 'Show Updated Column', value: false, isFilter: false },
{ key: SHOW_DESCRIPTION_COLUMN_SETTING, name: 'Show Description Column', value: false, isFilter: false },
{ key: SHOW_CHARACTER_COLUMN_SETTING, name: 'Show Character Column', value: false, isFilter: false },
{ key: LAZY_DELETE_SIGNATURES_SETTING, name: 'Lazy Delete Signatures', value: false, isFilter: false },
{ key: KEEP_LAZY_DELETE_SETTING, name: 'Keep "Lazy Delete" Enabled', value: false, isFilter: false },
{ key: COSMIC_ANOMALY, name: 'Show Anomalies', value: true, isFilter: true },
{ key: COSMIC_SIGNATURE, name: 'Show Cosmic Signatures', value: true, isFilter: true },
{ key: DEPLOYABLE, name: 'Show Deployables', value: true, isFilter: true },
@@ -56,121 +58,160 @@ const settings: Setting[] = [
{ key: SignatureGroup.CombatSite, name: 'Show Combat Sites', value: true, isFilter: true },
];
const defaultSettings = () => {
return [...settings];
};
const getDefaultSettings = (): Setting[] => [...SETTINGS];
export const SystemSignatures = () => {
export const SystemSignatures: React.FC = () => {
const {
data: { selectedSystems },
} = useMapRootState();
const [visible, setVisible] = useState(false);
const [settings, setSettings] = useState<Setting[]>(defaultSettings);
const [currentSettings, setCurrentSettings] = useState<Setting[]>(() => {
const stored = localStorage.getItem(SIGNATURE_SETTINGS_KEY);
if (stored) {
try {
return JSON.parse(stored) as Setting[];
} catch (error) {
console.error('Error parsing stored settings', error);
}
}
return getDefaultSettings();
});
useEffect(() => {
localStorage.setItem(SIGNATURE_SETTINGS_KEY, JSON.stringify(currentSettings));
}, [currentSettings]);
const [sigCount, setSigCount] = useState<number>(0);
const [pendingSigs, setPendingSigs] = useState<SystemSignature[]>([]);
const [undoPending, setUndoPending] = useState<() => void>(() => () => {});
const handleSigCountChange = useCallback((count: number) => {
setSigCount(count);
}, []);
const [systemId] = selectedSystems;
const isNotSelectedSystem = selectedSystems.length !== 1;
const lazyDeleteValue = useMemo(() => {
return settings.find(setting => setting.key === LAZY_DELETE_SIGNATURES_SETTING)!.value;
}, [settings]);
const lazyDeleteValue = useMemo(
() => currentSettings.find(setting => setting.key === LAZY_DELETE_SIGNATURES_SETTING)?.value || false,
[currentSettings],
);
const handleSettingsChange = useCallback((settings: Setting[]) => {
setSettings(settings);
localStorage.setItem(SIGNATURE_SETTINGS_KEY, JSON.stringify(settings));
const handleSettingsChange = useCallback((newSettings: Setting[]) => {
setCurrentSettings(newSettings);
setVisible(false);
}, []);
const handleLazyDeleteChange = useCallback((value: boolean) => {
setSettings(settings => {
const lazyDelete = settings.find(setting => setting.key === LAZY_DELETE_SIGNATURES_SETTING)!;
lazyDelete.value = value;
localStorage.setItem(SIGNATURE_SETTINGS_KEY, JSON.stringify(settings));
return [...settings];
});
setCurrentSettings(prevSettings =>
prevSettings.map(setting => (setting.key === LAZY_DELETE_SIGNATURES_SETTING ? { ...setting, value } : setting)),
);
}, []);
useEffect(() => {
const restoredSettings = localStorage.getItem(SIGNATURE_SETTINGS_KEY);
const containerRef = useRef<HTMLDivElement>(null);
const isCompact = useMaxWidth(containerRef, COMPACT_MAX_WIDTH);
if (restoredSettings) {
setSettings(JSON.parse(restoredSettings));
useHotkey(true, ['z'], (event: KeyboardEvent) => {
if (pendingSigs.length > 0) {
event.preventDefault();
event.stopPropagation();
undoPending();
setPendingSigs([]);
}
});
const handleUndoClick = useCallback(() => {
undoPending();
setPendingSigs([]);
}, [undoPending]);
const handleSettingsButtonClick = useCallback(() => {
setVisible(true);
}, []);
const ref = useRef<HTMLDivElement>(null);
const compact = useMaxWidth(ref, 260);
const renderLabel = () => (
<div className="flex justify-between items-center text-xs w-full h-full" ref={containerRef}>
<div className="flex justify-between items-center gap-1">
{!isCompact && (
<div className="flex whitespace-nowrap text-ellipsis overflow-hidden text-stone-400">
{sigCount ? `[${sigCount}] ` : ''}Signatures {isNotSelectedSystem ? '' : 'in'}
</div>
)}
{!isNotSelectedSystem && <SystemView systemId={systemId} className="select-none text-center" hideRegion />}
</div>
<LayoutEventBlocker className="flex gap-2.5">
<WdTooltipWrapper content="Enable Lazy delete">
<WdCheckbox
size="xs"
labelSide="left"
label={isCompact ? '' : 'Lazy delete'}
value={lazyDeleteValue}
classNameLabel="text-stone-400 hover:text-stone-200 transition duration-300 whitespace-nowrap text-ellipsis overflow-hidden"
onChange={(event: CheckboxChangeEvent) => handleLazyDeleteChange(!!event.checked)}
/>
</WdTooltipWrapper>
{pendingSigs.length > 0 && (
<WdImgButton
className={PrimeIcons.UNDO}
style={{ color: 'red' }}
tooltip={{ content: `Undo pending changes (${pendingSigs.length})` }}
onClick={handleUndoClick}
/>
)}
<WdImgButton
className={PrimeIcons.QUESTION_CIRCLE}
tooltip={{
position: TooltipPosition.left,
content: (
<div className="flex flex-col gap-1">
<InfoDrawer title={<b className="text-slate-50">How to add/update signature?</b>}>
In game you need to select one or more signatures <br /> in the list in{' '}
<b className="text-sky-500">Probe scanner</b>. <br /> Use next hotkeys:
<br />
<b className="text-sky-500">Shift + LMB</b> or <b className="text-sky-500">Ctrl + LMB</b>
<br /> or <b className="text-sky-500">Ctrl + A</b> for select all
<br /> and then use <b className="text-sky-500">Ctrl + C</b>, after you need to go <br />
here, select Solar system and paste it with <b className="text-sky-500">Ctrl + V</b>
</InfoDrawer>
<InfoDrawer title={<b className="text-slate-50">How to select?</b>}>
For selecting any signature, click on it <br /> with hotkeys{' '}
<b className="text-sky-500">Shift + LMB</b> or <b className="text-sky-500">Ctrl + LMB</b>
</InfoDrawer>
<InfoDrawer title={<b className="text-slate-50">How to delete?</b>}>
To delete any signature, first select it <br /> and then press <b className="text-sky-500">Del</b>
</InfoDrawer>
</div>
) as React.ReactNode,
}}
/>
<WdImgButton className={PrimeIcons.SLIDERS_H} onClick={handleSettingsButtonClick} />
</LayoutEventBlocker>
</div>
);
return (
<Widget
label={
<div className="flex justify-between items-center text-xs w-full h-full" ref={ref}>
<div className="flex justify-between items-center gap-1">
{!compact && (
<div className="flex whitespace-nowrap text-ellipsis overflow-hidden text-stone-400">
Signatures {isNotSelectedSystem ? '' : 'in'}
</div>
)}
{!isNotSelectedSystem && <SystemView systemId={systemId} className="select-none text-center" hideRegion />}
</div>
<LayoutEventBlocker className="flex gap-2.5">
<WdTooltipWrapper content="Enable Lazy delete">
<WdCheckbox
size="xs"
labelSide="left"
label={compact ? '' : 'Lazy delete'}
value={lazyDeleteValue}
classNameLabel="text-stone-400 hover:text-stone-200 transition duration-300 whitespace-nowrap text-ellipsis overflow-hidden"
onChange={(event: CheckboxChangeEvent) => handleLazyDeleteChange(!!event.checked)}
/>
</WdTooltipWrapper>
<WdImgButton
className={PrimeIcons.QUESTION_CIRCLE}
tooltip={{
position: TooltipPosition.left,
// @ts-ignore
content: (
<div className="flex flex-col gap-1">
<InfoDrawer title={<b className="text-slate-50">How to add/update signature?</b>}>
In game you need select one or more signatures <br /> in list in{' '}
<b className="text-sky-500">Probe scanner</b>. <br /> Use next hotkeys:
<br />
<b className="text-sky-500">Shift + LMB</b> or <b className="text-sky-500">Ctrl + LMB</b>
<br /> or <b className="text-sky-500">Ctrl + A</b> for select all
<br />
and then use <b className="text-sky-500">Ctrl + C</b>, after you need to go <br />
here select Solar system and paste it with <b className="text-sky-500">Ctrl + V</b>
</InfoDrawer>
<InfoDrawer title={<b className="text-slate-50">How to select?</b>}>
For select any signature need click on that, <br /> with hotkeys{' '}
<b className="text-sky-500">Shift + LMB</b> or <b className="text-sky-500">Ctrl + LMB</b>
</InfoDrawer>
<InfoDrawer title={<b className="text-slate-50">How to delete?</b>}>
For delete any signature first of all you need select before
<br /> and then use <b className="text-sky-500">Del</b>
</InfoDrawer>
</div>
) as React.ReactNode,
}}
/>
<WdImgButton className={PrimeIcons.SLIDERS_H} onClick={() => setVisible(true)} />
</LayoutEventBlocker>
</div>
}
>
<Widget label={renderLabel()}>
{isNotSelectedSystem ? (
<div className="w-full h-full flex justify-center items-center select-none text-center text-stone-400/80 text-sm">
System is not selected
</div>
) : (
<SystemSignaturesContent systemId={systemId} settings={settings} onLazyDeleteChange={handleLazyDeleteChange} />
<SystemSignaturesContent
systemId={systemId}
settings={currentSettings}
onLazyDeleteChange={handleLazyDeleteChange}
onCountChange={handleSigCountChange}
onPendingChange={(pending, undo) => {
setPendingSigs(pending);
setUndoPending(() => undo);
}}
/>
)}
{visible && (
<SystemSignatureSettingsDialog
settings={settings}
settings={currentSettings}
onCancel={() => setVisible(false)}
onSave={handleSettingsChange}
/>
@@ -178,3 +219,5 @@ export const SystemSignatures = () => {
</Widget>
);
};
export default SystemSignatures;

View File

@@ -1,10 +0,0 @@
.TableRowCompact {
height: 8px;
max-height: 8px;
font-size: 12px !important;
line-height: 8px;
}
.Table {
}

View File

@@ -1,29 +1,27 @@
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
import { parseSignatures } from '@/hooks/Mapper/helpers';
import { Commands, OutCommand } from '@/hooks/Mapper/types/mapHandlers.ts';
import { WdTooltip, WdTooltipHandlers } from '@/hooks/Mapper/components/ui-kit';
import {
getGroupIdByRawGroup,
GROUPS_LIST,
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts';
import { useEffect, useMemo, useRef, useState, useCallback } from 'react';
import { DataTable, DataTableRowClickEvent, DataTableRowMouseEvent, SortOrder } from 'primereact/datatable';
import { Column } from 'primereact/column';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import useRefState from 'react-usestateref';
import { Setting } from '../SystemSignatureSettingsDialog';
import { useHotkey } from '@/hooks/Mapper/hooks';
import useMaxWidth from '@/hooks/Mapper/hooks/useMaxWidth.ts';
import { useClipboard } from '@/hooks/Mapper/hooks/useClipboard';
import { PrimeIcons } from 'primereact/api';
import useLocalStorageState from 'use-local-storage-state';
import classes from './SystemSignaturesContent.module.scss';
import clsx from 'clsx';
import { SystemSignature } from '@/hooks/Mapper/types';
import { SignatureGroup, SystemSignature } from '@/hooks/Mapper/types';
import { SignatureSettings } from '@/hooks/Mapper/components/mapRootContent/components/SignatureSettings';
import { WdTooltip, WdTooltipHandlers, WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit';
import { SignatureView } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/SignatureView';
import {
getActualSigs,
getRowColorByTimeLeft,
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/helpers';
COMPACT_MAX_WIDTH,
GROUPS_LIST,
MEDIUM_MAX_WIDTH,
OTHER_COLUMNS_WIDTH,
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants';
import {
KEEP_LAZY_DELETE_SETTING,
LAZY_DELETE_SIGNATURES_SETTING,
SHOW_DESCRIPTION_COLUMN_SETTING,
SHOW_UPDATED_COLUMN_SETTING,
SHOW_CHARACTER_COLUMN_SETTING,
} from '../SystemSignatures';
import { COSMIC_SIGNATURE } from '../SystemSignatureSettingsDialog';
import {
renderAddedTimeLeft,
renderDescription,
@@ -31,18 +29,12 @@ import {
renderInfoColumn,
renderUpdatedTimeLeft,
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/renders';
import useLocalStorageState from 'use-local-storage-state';
import { PrimeIcons } from 'primereact/api';
import { SignatureSettings } from '@/hooks/Mapper/components/mapRootContent/components/SignatureSettings';
import { useMapEventListener } from '@/hooks/Mapper/events';
import { WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit/WdTooltipWrapper';
import { COSMIC_SIGNATURE } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/SystemSignatureSettingsDialog';
import {
SHOW_DESCRIPTION_COLUMN_SETTING,
SHOW_UPDATED_COLUMN_SETTING,
LAZY_DELETE_SIGNATURES_SETTING,
KEEP_LAZY_DELETE_SETTING,
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures';
import { ExtendedSystemSignature } from '../helpers/contentHelpers';
import { useSystemSignaturesData } from '../hooks/useSystemSignaturesData';
import { getSignatureRowClass } from '../helpers/rowStyles';
import useMaxWidth from '@/hooks/Mapper/hooks/useMaxWidth';
import { useClipboard, useHotkey } from '@/hooks/Mapper/hooks';
type SystemSignaturesSortSettings = {
sortField: string;
sortOrder: SortOrder;
@@ -55,391 +47,292 @@ const SORT_DEFAULT_VALUES: SystemSignaturesSortSettings = {
interface SystemSignaturesContentProps {
systemId: string;
settings: Setting[];
settings: { key: string; value: boolean }[];
hideLinkedSignatures?: boolean;
selectable?: boolean;
onSelect?: (signature: SystemSignature) => void;
onLazyDeleteChange?: (value: boolean) => void;
onCountChange?: (count: number) => void;
onPendingChange?: (pending: ExtendedSystemSignature[], undo: () => void) => void;
}
export const SystemSignaturesContent = ({
const headerInlineStyle = { padding: '2px', fontSize: '12px', lineHeight: '1.333' };
export function SystemSignaturesContent({
systemId,
settings,
hideLinkedSignatures,
selectable,
onSelect,
onLazyDeleteChange,
}: SystemSignaturesContentProps) => {
const { outCommand } = useMapRootState();
const [signatures, setSignatures, signaturesRef] = useRefState<SystemSignature[]>([]);
const [selectedSignatures, setSelectedSignatures] = useState<SystemSignature[]>([]);
const [nameColumnWidth, setNameColumnWidth] = useState('auto');
const [selectedSignature, setSelectedSignature] = useState<SystemSignature | null>(null);
const [hoveredSig, setHoveredSig] = useState<SystemSignature | null>(null);
const [sortSettings, setSortSettings] = useLocalStorageState<SystemSignaturesSortSettings>('window:signatures:sort', {
defaultValue: SORT_DEFAULT_VALUES,
});
const tableRef = useRef<HTMLDivElement>(null);
const compact = useMaxWidth(tableRef, 260);
const medium = useMaxWidth(tableRef, 380);
const refData = useRef({ selectable });
refData.current = { selectable };
const tooltipRef = useRef<WdTooltipHandlers>(null);
const { clipboardContent, setClipboardContent } = useClipboard();
const lazyDeleteValue = useMemo(() => {
return settings.find(setting => setting.key === LAZY_DELETE_SIGNATURES_SETTING)?.value ?? false;
}, [settings]);
const keepLazyDeleteValue = useMemo(() => {
return settings.find(setting => setting.key === KEEP_LAZY_DELETE_SETTING)?.value ?? false;
}, [settings]);
const handleResize = useCallback(() => {
if (tableRef.current) {
const tableWidth = tableRef.current.offsetWidth;
const otherColumnsWidth = 276;
const availableWidth = tableWidth - otherColumnsWidth;
setNameColumnWidth(`${availableWidth}px`);
}
}, []);
const groupSettings = useMemo(() => settings.filter(s => (GROUPS_LIST as string[]).includes(s.key)), [settings]);
const showDescriptionColumn = useMemo(
() => settings.find(s => s.key === SHOW_DESCRIPTION_COLUMN_SETTING)?.value,
[settings],
);
const showUpdatedColumn = useMemo(() => settings.find(s => s.key === SHOW_UPDATED_COLUMN_SETTING)?.value, [settings]);
const filteredSignatures = useMemo(() => {
return signatures
.filter(x => {
if (hideLinkedSignatures && !!x.linked_system) {
return false;
}
const isCosmicSignature = x.kind === COSMIC_SIGNATURE;
const preparedGroup = getGroupIdByRawGroup(x.group);
if (isCosmicSignature) {
const showCosmicSignatures = settings.find(y => y.key === COSMIC_SIGNATURE)?.value;
if (showCosmicSignatures) {
return !x.group || groupSettings.find(y => y.key === preparedGroup)?.value;
} else {
return !!x.group && groupSettings.find(y => y.key === preparedGroup)?.value;
}
}
return settings.find(y => y.key === x.kind)?.value;
})
.sort((a, b) => {
return new Date(b.updated_at || 0).getTime() - new Date(a.updated_at || 0).getTime();
});
}, [signatures, settings, groupSettings, hideLinkedSignatures]);
const handleGetSignatures = useCallback(async () => {
const { signatures } = await outCommand({
type: OutCommand.getSignatures,
data: { system_id: systemId },
onCountChange,
onPendingChange,
}: SystemSignaturesContentProps) {
const { signatures, selectedSignatures, setSelectedSignatures, handleDeleteSelected, handleSelectAll, handlePaste } =
useSystemSignaturesData({
systemId,
settings,
onCountChange,
onPendingChange,
onLazyDeleteChange,
});
setSignatures(signatures);
}, [outCommand, systemId]);
const handleUpdateSignatures = useCallback(
async (newSignatures: SystemSignature[], updateOnly: boolean, skipUpdateUntouched?: boolean) => {
const { added, updated, removed } = getActualSigs(
signaturesRef.current,
newSignatures,
updateOnly,
skipUpdateUntouched,
);
const { signatures: updatedSignatures } = await outCommand({
type: OutCommand.updateSignatures,
data: {
system_id: systemId,
added,
updated,
removed,
},
});
setSignatures(() => updatedSignatures);
setSelectedSignatures([]);
},
[outCommand, systemId],
const [sortSettings, setSortSettings] = useLocalStorageState<{ sortField: string; sortOrder: SortOrder }>(
'window:signatures:sort',
{ defaultValue: SORT_DEFAULT_VALUES },
);
const handleDeleteSelected = useCallback(
async (e: KeyboardEvent) => {
if (selectable) {
return;
}
if (selectedSignatures.length === 0) {
return;
}
const tableRef = useRef<HTMLDivElement>(null);
const tooltipRef = useRef<WdTooltipHandlers>(null);
const [hoveredSignature, setHoveredSignature] = useState<SystemSignature | null>(null);
e.preventDefault();
e.stopPropagation();
const isCompact = useMaxWidth(tableRef, COMPACT_MAX_WIDTH);
const isMedium = useMaxWidth(tableRef, MEDIUM_MAX_WIDTH);
const selectedSignaturesEveIds = selectedSignatures.map(x => x.eve_id);
await handleUpdateSignatures(
signatures.filter(x => !selectedSignaturesEveIds.includes(x.eve_id)),
false,
true,
);
},
[handleUpdateSignatures, selectable, signatures, selectedSignatures],
);
const handleSelectAll = useCallback(() => {
setSelectedSignatures(signatures);
}, [signatures]);
const handleSelectSignatures = useCallback(
// TODO still will be good to define types if we use typescript
// @ts-ignore
e => {
if (selectable) {
onSelect?.(e.value);
} else {
setSelectedSignatures(e.value);
}
},
[onSelect, selectable],
);
const handlePaste = async (clipboardContent: string) => {
const newSignatures = parseSignatures(
clipboardContent,
settings.map(x => x.key),
);
handleUpdateSignatures(newSignatures, !lazyDeleteValue);
if (lazyDeleteValue && !keepLazyDeleteValue) {
onLazyDeleteChange?.(false);
}
};
const handleEnterRow = useCallback(
(e: DataTableRowMouseEvent) => {
setHoveredSig(filteredSignatures[e.index]);
tooltipRef.current?.show(e.originalEvent);
},
[filteredSignatures],
);
const handleLeaveRow = useCallback((e: DataTableRowMouseEvent) => {
tooltipRef.current?.hide(e.originalEvent);
setHoveredSig(null);
}, []);
const lazyDeleteEnabled = settings.find(s => s.key === LAZY_DELETE_SIGNATURES_SETTING)?.value ?? false;
const keepLazyDeleteEnabled = settings.find(s => s.key === KEEP_LAZY_DELETE_SETTING)?.value ?? false;
const { clipboardContent, setClipboardContent } = useClipboard();
useEffect(() => {
if (refData.current.selectable) {
return;
}
if (!clipboardContent?.text) {
return;
}
if (selectable) return;
if (!clipboardContent?.text) return;
handlePaste(clipboardContent.text);
if (lazyDeleteEnabled && !keepLazyDeleteEnabled) {
onLazyDeleteChange?.(false);
}
setClipboardContent(null);
}, [clipboardContent, selectable, lazyDeleteValue, keepLazyDeleteValue]);
}, [
selectable,
clipboardContent,
handlePaste,
setClipboardContent,
lazyDeleteEnabled,
keepLazyDeleteEnabled,
onLazyDeleteChange,
]);
useHotkey(true, ['a'], handleSelectAll);
useHotkey(false, ['Backspace', 'Delete'], handleDeleteSelected);
useEffect(() => {
if (!systemId) {
setSignatures([]);
return;
}
handleGetSignatures();
}, [systemId]);
useMapEventListener(event => {
switch (event.name) {
case Commands.signaturesUpdated:
if (event.data?.toString() !== systemId.toString()) {
return;
}
handleGetSignatures();
return true;
}
useHotkey(false, ['Backspace', 'Delete'], (event: KeyboardEvent) => {
event.preventDefault();
event.stopPropagation();
handleDeleteSelected();
});
useEffect(() => {
const observer = new ResizeObserver(handleResize);
if (tableRef.current) {
observer.observe(tableRef.current);
}
handleResize(); // Call on mount to set initial width
return () => {
if (tableRef.current) {
observer.unobserve(tableRef.current);
}
};
const [nameColumnWidth, setNameColumnWidth] = useState('auto');
const handleResize = useCallback(() => {
if (!tableRef.current) return;
const tableWidth = tableRef.current.offsetWidth;
const otherColumnsWidth = OTHER_COLUMNS_WIDTH;
setNameColumnWidth(`${tableWidth - otherColumnsWidth}px`);
}, []);
useEffect(() => {
if (!tableRef.current) return;
const observer = new ResizeObserver(handleResize);
observer.observe(tableRef.current);
handleResize();
return () => {
observer.disconnect();
};
}, [handleResize]);
const renderToolbar = (/*row: SystemSignature*/) => {
return (
<div className="flex justify-end items-center gap-2 mr-[4px]">
<WdTooltipWrapper content="To Edit Signature do double click">
<span className={clsx(PrimeIcons.PENCIL, 'text-[10px]')}></span>
</WdTooltipWrapper>
</div>
);
};
const [selectedSignatureForDialog, setSelectedSignatureForDialog] = useState<SystemSignature | null>(null);
const [showSignatureSettings, setShowSignatureSettings] = useState(false);
const handleRowClick = (e: DataTableRowClickEvent) => {
setSelectedSignature(e.data as SystemSignature);
setSelectedSignatureForDialog(e.data as SystemSignature);
setShowSignatureSettings(true);
};
return (
<>
<div ref={tableRef} className={'h-full '}>
{filteredSignatures.length === 0 ? (
<div className="w-full h-full flex justify-center items-center select-none text-stone-400/80 text-sm">
No signatures
</div>
) : (
<>
{/* @ts-ignore */}
<DataTable
className={classes.Table}
value={filteredSignatures}
size="small"
selectionMode={selectable ? 'single' : 'multiple'}
selection={selectedSignatures}
metaKeySelection
onSelectionChange={handleSelectSignatures}
dataKey="eve_id"
tableClassName="w-full select-none"
resizableColumns={false}
onRowDoubleClick={handleRowClick}
rowHover
selectAll
sortField={sortSettings.sortField}
sortOrder={sortSettings.sortOrder}
onSort={event => setSortSettings(() => ({ sortField: event.sortField, sortOrder: event.sortOrder }))}
onRowMouseEnter={compact || medium ? handleEnterRow : undefined}
onRowMouseLeave={compact || medium ? handleLeaveRow : undefined}
rowClassName={row => {
if (selectedSignatures.some(x => x.eve_id === row.eve_id)) {
return clsx(classes.TableRowCompact, 'bg-amber-500/50 hover:bg-amber-500/70 transition duration-200');
}
const dateClass = getRowColorByTimeLeft(row.inserted_at ? new Date(row.inserted_at) : undefined);
if (!dateClass) {
return clsx(classes.TableRowCompact, 'hover:bg-purple-400/20 transition duration-200');
}
return clsx(classes.TableRowCompact, dateClass);
}}
>
<Column
bodyClassName="p-0 px-1"
field="group"
body={x => renderIcon(x)}
style={{ maxWidth: 26, minWidth: 26, width: 26, height: 25 }}
></Column>
<Column
field="eve_id"
header="Id"
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
style={{ maxWidth: 72, minWidth: 72, width: 72 }}
sortable
></Column>
<Column
field="group"
header="Group"
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
hidden={compact}
style={{ maxWidth: 110, minWidth: 110, width: 110 }}
sortable
></Column>
<Column
field="info"
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
body={renderInfoColumn}
style={{ maxWidth: nameColumnWidth }}
hidden={compact || medium}
></Column>
{showDescriptionColumn && (
<Column
field="description"
header="Description"
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
body={renderDescription}
hidden={compact}
sortable
></Column>
)}
<Column
field="inserted_at"
header="Added"
dataType="date"
bodyClassName="w-[70px] text-ellipsis overflow-hidden whitespace-nowrap"
body={renderAddedTimeLeft}
sortable
></Column>
{showUpdatedColumn && (
<Column
field="updated_at"
header="Updated"
dataType="date"
bodyClassName="w-[70px] text-ellipsis overflow-hidden whitespace-nowrap"
body={renderUpdatedTimeLeft}
sortable
></Column>
)}
{!selectable && (
<Column
bodyClassName="p-0 pl-1 pr-2"
field="group"
body={renderToolbar}
// headerClassName={headerClasses}
style={{ maxWidth: 26, minWidth: 26, width: 26 }}
></Column>
)}
</DataTable>
</>
)}
<WdTooltip
className="bg-stone-900/95 text-slate-50"
ref={tooltipRef}
content={hoveredSig ? <SignatureView {...hoveredSig} /> : null}
/>
{showSignatureSettings && (
<SignatureSettings
systemId={systemId}
show
onHide={() => setShowSignatureSettings(false)}
signatureData={selectedSignature}
/>
)}
</div>
</>
const handleSelectSignatures = useCallback(
(e: { value: SystemSignature[] }) => {
if (selectable) {
onSelect?.(e.value[0]);
} else {
setSelectedSignatures(e.value as ExtendedSystemSignature[]);
}
},
[selectable, onSelect, setSelectedSignatures],
);
};
const showDescriptionColumn = settings.find(s => s.key === SHOW_DESCRIPTION_COLUMN_SETTING)?.value;
const showUpdatedColumn = settings.find(s => s.key === SHOW_UPDATED_COLUMN_SETTING)?.value;
const showCharacterColumn = settings.find(s => s.key === SHOW_CHARACTER_COLUMN_SETTING)?.value;
const enabledGroups = settings
.filter(s => GROUPS_LIST.includes(s.key as SignatureGroup) && s.value === true)
.map(s => s.key);
const filteredSignatures = useMemo<ExtendedSystemSignature[]>(() => {
return signatures.filter(sig => {
if (hideLinkedSignatures && sig.linked_system) {
return false;
}
if (sig.kind === COSMIC_SIGNATURE) {
const showCosmic = settings.find(y => y.key === COSMIC_SIGNATURE)?.value;
if (!showCosmic) return false;
if (sig.group) {
return enabledGroups.includes(sig.group);
}
return true;
} else {
return settings.find(y => y.key === sig.kind)?.value;
}
});
}, [signatures, hideLinkedSignatures, settings, enabledGroups]);
return (
<div ref={tableRef} className="h-full">
{filteredSignatures.length === 0 ? (
<div className="w-full h-full flex justify-center items-center select-none text-stone-400/80 text-sm">
No signatures
</div>
) : (
<DataTable
value={filteredSignatures}
size="small"
selectionMode="multiple"
selection={selectedSignatures}
metaKeySelection
onSelectionChange={handleSelectSignatures}
dataKey="eve_id"
className="w-full select-none"
resizableColumns={false}
rowHover
selectAll
onRowDoubleClick={handleRowClick}
sortField={sortSettings.sortField}
sortOrder={sortSettings.sortOrder}
onSort={e => setSortSettings({ sortField: e.sortField, sortOrder: e.sortOrder })}
onRowMouseEnter={
isCompact || isMedium
? (e: DataTableRowMouseEvent) => {
setHoveredSignature(filteredSignatures[e.index]);
tooltipRef.current?.show(e.originalEvent);
}
: undefined
}
onRowMouseLeave={
isCompact || isMedium
? () => {
setHoveredSignature(null);
tooltipRef.current?.hide();
}
: undefined
}
rowClassName={rowData => getSignatureRowClass(rowData as ExtendedSystemSignature, selectedSignatures)}
>
<Column
field="icon"
header=""
headerStyle={headerInlineStyle}
body={sig => renderIcon(sig)}
bodyClassName="p-0 px-1"
style={{ maxWidth: 26, minWidth: 26, width: 26 }}
/>
<Column
field="eve_id"
header="Id"
headerStyle={headerInlineStyle}
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
style={{ maxWidth: 72, minWidth: 72, width: 72 }}
sortable
/>
<Column
field="group"
header="Group"
headerStyle={headerInlineStyle}
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
style={{ maxWidth: 110, minWidth: 110, width: 110 }}
body={sig => sig.group ?? ''}
hidden={isCompact}
sortable
/>
<Column
field="info"
header="Info"
headerStyle={headerInlineStyle}
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
style={{ maxWidth: nameColumnWidth }}
hidden={isCompact || isMedium}
body={renderInfoColumn}
/>
{showDescriptionColumn && (
<Column
field="description"
header="Description"
headerStyle={headerInlineStyle}
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
hidden={isCompact}
body={renderDescription}
sortable
/>
)}
<Column
field="inserted_at"
header="Added"
headerStyle={headerInlineStyle}
dataType="date"
body={renderAddedTimeLeft}
style={{ minWidth: 70, maxWidth: 80 }}
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
sortable
/>
{showUpdatedColumn && (
<Column
field="updated_at"
header="Updated"
headerStyle={headerInlineStyle}
dataType="date"
body={renderUpdatedTimeLeft}
style={{ minWidth: 70, maxWidth: 80 }}
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
sortable
/>
)}
{showCharacterColumn && (
<Column
field="character_name"
header="Character"
bodyClassName="w-[70px] text-ellipsis overflow-hidden whitespace-nowrap"
sortable
></Column>
)}
{!selectable && (
<Column
header=""
headerStyle={headerInlineStyle}
body={() => (
<div className="flex justify-end items-center gap-2 mr-[4px]">
<WdTooltipWrapper content="Double-click a row to edit signature">
<span className={PrimeIcons.PENCIL + ' text-[10px]'} />
</WdTooltipWrapper>
</div>
)}
style={{ maxWidth: 26, minWidth: 26, width: 26 }}
bodyClassName="p-0 pl-1 pr-2"
/>
)}
</DataTable>
)}
<WdTooltip
className="bg-stone-900/95 text-slate-50"
ref={tooltipRef}
content={hoveredSignature ? <SignatureView {...hoveredSignature} /> : null}
/>
{showSignatureSettings && (
<SignatureSettings
systemId={systemId}
show
onHide={() => setShowSignatureSettings(false)}
signatureData={selectedSignatureForDialog || undefined}
/>
)}
</div>
);
}

View File

@@ -10,6 +10,13 @@ import {
export const TIME_ONE_MINUTE = 1000 * 60;
export const TIME_TEN_MINUTES = 1000 * 60 * 10;
export const TIME_ONE_DAY = 24 * 60 * 60 * 1000;
export const TIME_ONE_WEEK = 7 * TIME_ONE_DAY;
export const FINAL_DURATION_MS = 10000;
export const COMPACT_MAX_WIDTH = 260;
export const MEDIUM_MAX_WIDTH = 380;
export const OTHER_COLUMNS_WIDTH = 276;
export const GROUPS_LIST = [
SignatureGroup.GasSite,

View File

@@ -0,0 +1,94 @@
import { SystemSignature } from '@/hooks/Mapper/types';
import { FINAL_DURATION_MS } from '../constants';
export interface ExtendedSystemSignature extends SystemSignature {
pendingDeletion?: boolean;
pendingAddition?: boolean;
pendingUntil?: number;
}
export function prepareUpdatePayload(
systemId: string,
added: ExtendedSystemSignature[],
updated: ExtendedSystemSignature[],
removed: ExtendedSystemSignature[],
) {
return {
system_id: systemId,
added: added.map(s => ({ ...s })),
updated: updated.map(s => ({ ...s })),
removed: removed.map(s => ({ ...s })),
};
}
export function schedulePendingAdditionForSig(
sig: ExtendedSystemSignature,
finalDuration: number,
setSignatures: React.Dispatch<React.SetStateAction<ExtendedSystemSignature[]>>,
pendingAdditionMapRef: React.MutableRefObject<Record<string, { finalUntil: number; finalTimeoutId: number }>>,
setPendingUndoAdditions: React.Dispatch<React.SetStateAction<ExtendedSystemSignature[]>>,
) {
setPendingUndoAdditions(prev => [...prev, sig]);
const now = Date.now();
const finalTimeoutId = window.setTimeout(() => {
setSignatures(prev =>
prev.map(x => (x.eve_id === sig.eve_id ? { ...x, pendingAddition: false, pendingUntil: undefined } : x)),
);
const clone = { ...pendingAdditionMapRef.current };
delete clone[sig.eve_id];
pendingAdditionMapRef.current = clone;
setPendingUndoAdditions(prev => prev.filter(x => x.eve_id !== sig.eve_id));
}, finalDuration);
pendingAdditionMapRef.current = {
...pendingAdditionMapRef.current,
[sig.eve_id]: {
finalUntil: now + finalDuration,
finalTimeoutId,
},
};
setSignatures(prev =>
prev.map(x => (x.eve_id === sig.eve_id ? { ...x, pendingAddition: true, pendingUntil: now + finalDuration } : x)),
);
}
export function mergeLocalPendingAdditions(
serverSigs: ExtendedSystemSignature[],
localSigs: ExtendedSystemSignature[],
): ExtendedSystemSignature[] {
const now = Date.now();
const pendingAdditions = localSigs.filter(sig => sig.pendingAddition && sig.pendingUntil && sig.pendingUntil > now);
const mergedMap = new Map<string, ExtendedSystemSignature>();
serverSigs.forEach(sig => mergedMap.set(sig.eve_id, sig));
pendingAdditions.forEach(sig => {
if (!mergedMap.has(sig.eve_id)) {
mergedMap.set(sig.eve_id, sig);
}
});
return Array.from(mergedMap.values());
}
export function scheduleLazyDeletionTimers(
toRemove: ExtendedSystemSignature[],
setPendingMap: React.Dispatch<React.SetStateAction<Record<string, { finalUntil: number; finalTimeoutId: number }>>>,
finalizeRemoval: (sig: ExtendedSystemSignature) => Promise<void>,
finalDuration = FINAL_DURATION_MS,
) {
const now = Date.now();
toRemove.forEach(sig => {
const finalTimeoutId = window.setTimeout(async () => {
await finalizeRemoval(sig);
}, finalDuration);
setPendingMap(prev => ({
...prev,
[sig.eve_id]: {
finalUntil: now + finalDuration,
finalTimeoutId,
},
}));
});
}

View File

@@ -1,25 +1,67 @@
import { SystemSignature } from '@/hooks/Mapper/types';
import { GROUPS_LIST } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts';
import { getState } from './getState.ts';
import { GROUPS_LIST } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants';
import { getState } from './getState';
/**
* Compare two lists of signatures and return which are added, updated, or removed.
*
* @param oldSignatures existing signatures (in memory or from server)
* @param newSignatures newly parsed or incoming signatures from user input
* @param updateOnly if true, do NOT remove old signatures not found in newSignatures
* @param skipUpdateUntouched if true, do NOT push unmodified signatures into the `updated` array
*/
export const getActualSigs = (
oldSignatures: SystemSignature[],
newSignatures: SystemSignature[],
updateOnly: boolean,
updateOnly?: boolean,
skipUpdateUntouched?: boolean,
): { added: SystemSignature[]; updated: SystemSignature[]; removed: SystemSignature[] } => {
const updated: SystemSignature[] = [];
const removed: SystemSignature[] = [];
const added: SystemSignature[] = [];
oldSignatures.forEach(oldSig => {
// if old sigs is not contains in newSigs we need mark it as removed
// otherwise we check
const newSig = newSignatures.find(s => s.eve_id === oldSig.eve_id);
if (newSig) {
// we take new sig and now we need check that sig has been updated
const isNeedUpgrade = getState(GROUPS_LIST, newSig) > getState(GROUPS_LIST, oldSig);
if (isNeedUpgrade) {
updated.push({ ...oldSig, group: newSig.group, name: newSig.name });
const needUpgrade = getState(GROUPS_LIST, newSig) > getState(GROUPS_LIST, oldSig);
const mergedSig = { ...oldSig };
let changed = false;
if (needUpgrade) {
mergedSig.group = newSig.group;
mergedSig.name = newSig.name;
changed = true;
}
if (newSig.description && newSig.description !== oldSig.description) {
mergedSig.description = newSig.description;
changed = true;
}
try {
const oldInfo = JSON.parse(oldSig.custom_info || '{}');
const newInfo = JSON.parse(newSig.custom_info || '{}');
let infoChanged = false;
for (const key in newInfo) {
if (oldInfo[key] !== newInfo[key]) {
oldInfo[key] = newInfo[key];
infoChanged = true;
}
}
if (infoChanged) {
mergedSig.custom_info = JSON.stringify(oldInfo);
changed = true;
}
} catch (e) {
console.error(`getActualSigs: Error merging custom_info for ${oldSig.eve_id}`, e);
}
if (newSig.updated_at !== oldSig.updated_at) {
mergedSig.updated_at = newSig.updated_at;
changed = true;
}
if (changed) {
updated.push(mergedSig);
} else if (!skipUpdateUntouched) {
updated.push({ ...oldSig });
}
@@ -30,8 +72,12 @@ export const getActualSigs = (
}
});
const oldSignaturesIds = oldSignatures.map(x => x.eve_id);
const added = newSignatures.filter(s => !oldSignaturesIds.includes(s.eve_id));
const oldIds = new Set(oldSignatures.map(x => x.eve_id));
newSignatures.forEach(s => {
if (!oldIds.has(s.eve_id)) {
added.push(s);
}
});
return { added, updated, removed };
};

View File

@@ -3,9 +3,9 @@ import {
TIME_TEN_MINUTES,
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts';
export const getRowColorByTimeLeft = (date: Date | undefined) => {
export const getRowBackgroundColor = (date: Date | undefined): string => {
if (!date) {
return null;
return '';
}
const currentDate = new Date();
@@ -18,4 +18,6 @@ export const getRowColorByTimeLeft = (date: Date | undefined) => {
if (diff < TIME_TEN_MINUTES) {
return 'bg-lime-700/40 transition hover:bg-lime-700/50';
}
return '';
};

View File

@@ -1,11 +1,8 @@
import { SystemSignature } from '@/hooks/Mapper/types';
// also we need detect changes, we need understand that sigs has states
// first state when kind is Cosmic Signature or Cosmic Anomaly and group is empty
// and we should detect it for ungrade sigs
export const getState = (_: string[], newSig: SystemSignature) => {
let state = -1;
if (!newSig.group || newSig.group === '') {
if (!newSig.group) {
state = 0;
} else if (!newSig.name || newSig.name === '') {
state = 1;

View File

@@ -1,3 +1,5 @@
export * from './getState';
export * from './getRowColorByTimeLeft';
export * from './getRowBackgroundColor';
export * from './getActualSigs';
export * from './contentHelpers';
export * from './rowStyles';

View File

@@ -0,0 +1,34 @@
.pendingDeletion {
background-color: #f87171;
transition: background-color 0.2s ease;
}
.pendingDeletion td {
background-color: #f87171;
transition: background-color 0.2s ease;
}
.pendingDeletion {
background-color: #f87171;
transition: background-color 0.2s ease;
}
.Table thead tr {
font-size: 12px !important;
line-height: 1.333;
}
.TableRowCompact {
font-size: 12px !important;
line-height: 1.333;
}
.Table td {
padding: 2px;
height: 25px;
border: 1px solid #383838;
box-sizing: border-box;
}

View File

@@ -0,0 +1,20 @@
import clsx from 'clsx';
import { ExtendedSystemSignature } from './contentHelpers';
import { getRowBackgroundColor } from './getRowBackgroundColor';
import classes from './rowStyles.module.scss';
export function getSignatureRowClass(
row: ExtendedSystemSignature,
selectedSignatures: ExtendedSystemSignature[],
): string {
const isSelected = selectedSignatures.some(s => s.eve_id === row.eve_id);
return clsx(
classes.TableRowCompact,
'p-selectable-row',
isSelected && 'bg-amber-500/50 hover:bg-amber-500/70 transition duration-200',
!isSelected && row.pendingDeletion && classes.pendingDeletion,
!isSelected && getRowBackgroundColor(row.inserted_at ? new Date(row.inserted_at) : undefined),
'hover:bg-purple-400/20 transition duration-200',
);
}

View File

@@ -0,0 +1,26 @@
import { ExtendedSystemSignature } from '../helpers/contentHelpers';
export interface UseSystemSignaturesDataProps {
systemId: string;
settings: { key: string; value: boolean }[];
hideLinkedSignatures?: boolean;
onCountChange?: (count: number) => void;
onPendingChange?: (pending: ExtendedSystemSignature[], undo: () => void) => void;
onLazyDeleteChange?: (value: boolean) => void;
}
export interface UseFetchingParams {
systemId: string;
signaturesRef: React.MutableRefObject<ExtendedSystemSignature[]>;
setSignatures: React.Dispatch<React.SetStateAction<ExtendedSystemSignature[]>>;
localPendingDeletions: ExtendedSystemSignature[];
}
export interface UsePendingDeletionParams {
systemId: string;
setSignatures: React.Dispatch<React.SetStateAction<ExtendedSystemSignature[]>>;
}
export interface UsePendingAdditionParams {
setSignatures: React.Dispatch<React.SetStateAction<ExtendedSystemSignature[]>>;
}

View File

@@ -0,0 +1,53 @@
import { useState, useCallback, useRef } from 'react';
import { ExtendedSystemSignature, schedulePendingAdditionForSig } from '../helpers/contentHelpers';
import { UsePendingAdditionParams } from './types';
import { FINAL_DURATION_MS } from '../constants';
export function usePendingAdditions({ setSignatures }: UsePendingAdditionParams) {
const [pendingUndoAdditions, setPendingUndoAdditions] = useState<ExtendedSystemSignature[]>([]);
const pendingAdditionMapRef = useRef<Record<string, { finalUntil: number; finalTimeoutId: number }>>({});
const processAddedSignatures = useCallback(
(added: ExtendedSystemSignature[]) => {
if (!added.length) return;
const now = Date.now();
setSignatures(prev => [
...prev,
...added.map(sig => ({
...sig,
pendingAddition: true,
pendingUntil: now + FINAL_DURATION_MS,
})),
]);
added.forEach(sig => {
schedulePendingAdditionForSig(
sig,
FINAL_DURATION_MS,
setSignatures,
pendingAdditionMapRef,
setPendingUndoAdditions,
);
});
},
[setSignatures],
);
const clearPendingAdditions = useCallback(() => {
Object.values(pendingAdditionMapRef.current).forEach(({ finalTimeoutId }) => {
clearTimeout(finalTimeoutId);
});
pendingAdditionMapRef.current = {};
setSignatures(prev =>
prev.map(x => (x.pendingAddition ? { ...x, pendingAddition: false, pendingUntil: undefined } : x)),
);
setPendingUndoAdditions([]);
}, [setSignatures]);
return {
pendingUndoAdditions,
setPendingUndoAdditions,
pendingAdditionMapRef,
processAddedSignatures,
clearPendingAdditions,
};
}

View File

@@ -0,0 +1,79 @@
import { useState, useCallback } from 'react';
import { OutCommand } from '@/hooks/Mapper/types/mapHandlers';
import { ExtendedSystemSignature, prepareUpdatePayload, scheduleLazyDeletionTimers } from '../helpers';
import { UsePendingDeletionParams } from './types';
import { FINAL_DURATION_MS } from '../constants';
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
export function usePendingDeletions({ systemId, setSignatures }: UsePendingDeletionParams) {
const { outCommand } = useMapRootState();
const [localPendingDeletions, setLocalPendingDeletions] = useState<ExtendedSystemSignature[]>([]);
const [pendingDeletionMap, setPendingDeletionMap] = useState<
Record<string, { finalUntil: number; finalTimeoutId: number }>
>({});
const processRemovedSignatures = useCallback(
async (
removed: ExtendedSystemSignature[],
added: ExtendedSystemSignature[],
updated: ExtendedSystemSignature[],
) => {
if (!removed.length) return;
const now = Date.now();
const processedRemoved = removed.map(r => ({
...r,
pendingDeletion: true,
pendingAddition: false,
pendingUntil: now + FINAL_DURATION_MS,
}));
setLocalPendingDeletions(prev => [...prev, ...processedRemoved]);
outCommand({
type: OutCommand.updateSignatures,
data: prepareUpdatePayload(systemId, added, updated, []),
});
setSignatures(prev =>
prev.map(sig => {
if (processedRemoved.find(r => r.eve_id === sig.eve_id)) {
return { ...sig, pendingDeletion: true, pendingUntil: now + FINAL_DURATION_MS };
}
return sig;
}),
);
scheduleLazyDeletionTimers(
processedRemoved,
setPendingDeletionMap,
async sig => {
await outCommand({
type: OutCommand.updateSignatures,
data: prepareUpdatePayload(systemId, [], [], [sig]),
});
setLocalPendingDeletions(prev => prev.filter(x => x.eve_id !== sig.eve_id));
setSignatures(prev => prev.filter(x => x.eve_id !== sig.eve_id));
},
FINAL_DURATION_MS,
);
},
[systemId, outCommand, setSignatures],
);
const clearPendingDeletions = useCallback(() => {
Object.values(pendingDeletionMap).forEach(({ finalTimeoutId }) => clearTimeout(finalTimeoutId));
setPendingDeletionMap({});
setSignatures(prev =>
prev.map(x => (x.pendingDeletion ? { ...x, pendingDeletion: false, pendingUntil: undefined } : x)),
);
setLocalPendingDeletions([]);
}, [pendingDeletionMap, setSignatures]);
return {
localPendingDeletions,
setLocalPendingDeletions,
pendingDeletionMap,
setPendingDeletionMap,
processRemovedSignatures,
clearPendingDeletions,
};
}

View File

@@ -0,0 +1,75 @@
import { useCallback } from 'react';
import { SystemSignature } from '@/hooks/Mapper/types';
import { OutCommand } from '@/hooks/Mapper/types/mapHandlers';
import { ExtendedSystemSignature, prepareUpdatePayload, getActualSigs, mergeLocalPendingAdditions } from '../helpers';
import { UseFetchingParams } from './types';
import { FINAL_DURATION_MS } from '../constants';
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
export function useSignatureFetching({
systemId,
signaturesRef,
setSignatures,
localPendingDeletions,
}: UseFetchingParams) {
const {
data: { characters },
outCommand,
} = useMapRootState();
const handleGetSignatures = useCallback(async () => {
if (!systemId) {
setSignatures([]);
return;
}
if (localPendingDeletions.length) {
return;
}
const resp = await outCommand({
type: OutCommand.getSignatures,
data: { system_id: systemId },
});
const serverSigs = (resp.signatures ?? []) as SystemSignature[];
const extended = serverSigs.map(s => ({
...s,
character_name: characters.find(c => c.eve_id === s.character_eve_id)?.name,
})) as ExtendedSystemSignature[];
setSignatures(prev => mergeLocalPendingAdditions(extended, prev));
}, [characters, systemId, localPendingDeletions, outCommand, setSignatures]);
const handleUpdateSignatures = useCallback(
async (newList: ExtendedSystemSignature[], updateOnly: boolean, skipUpdateUntouched?: boolean) => {
const { added, updated, removed } = getActualSigs(
signaturesRef.current,
newList,
updateOnly,
skipUpdateUntouched,
);
if (added.length > 0) {
const now = Date.now();
setSignatures(prev => [
...prev,
...added.map(a => ({
...a,
pendingAddition: true,
pendingUntil: now + FINAL_DURATION_MS,
})),
]);
}
await outCommand({
type: OutCommand.updateSignatures,
data: prepareUpdatePayload(systemId, added, updated, removed),
});
},
[systemId, outCommand, signaturesRef, setSignatures],
);
return {
handleGetSignatures,
handleUpdateSignatures,
};
}

View File

@@ -0,0 +1,204 @@
import { useCallback, useEffect, useState } from 'react';
import useRefState from 'react-usestateref';
import { useMapEventListener } from '@/hooks/Mapper/events';
import { Commands, SystemSignature } from '@/hooks/Mapper/types';
import { OutCommand } from '@/hooks/Mapper/types/mapHandlers';
import { parseSignatures } from '@/hooks/Mapper/helpers';
import {
KEEP_LAZY_DELETE_SETTING,
LAZY_DELETE_SIGNATURES_SETTING,
} from '@/hooks/Mapper/components/mapInterface/widgets';
import { ExtendedSystemSignature, getActualSigs, mergeLocalPendingAdditions } from '../helpers';
import { useSignatureFetching } from './useSignatureFetching';
import { usePendingAdditions } from './usePendingAdditions';
import { usePendingDeletions } from './usePendingDeletions';
import { UseSystemSignaturesDataProps } from './types';
import { TIME_ONE_DAY, TIME_ONE_WEEK } from '../constants';
import { SignatureGroup } from '@/hooks/Mapper/types';
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
export function useSystemSignaturesData({
systemId,
settings,
onCountChange,
onPendingChange,
onLazyDeleteChange,
}: UseSystemSignaturesDataProps) {
const { outCommand } = useMapRootState();
const [signatures, setSignatures, signaturesRef] = useRefState<ExtendedSystemSignature[]>([]);
const [selectedSignatures, setSelectedSignatures] = useState<ExtendedSystemSignature[]>([]);
const { localPendingDeletions, setLocalPendingDeletions, processRemovedSignatures, clearPendingDeletions } =
usePendingDeletions({
systemId,
setSignatures,
});
const { pendingUndoAdditions, setPendingUndoAdditions, processAddedSignatures, clearPendingAdditions } =
usePendingAdditions({
setSignatures,
});
const { handleGetSignatures, handleUpdateSignatures } = useSignatureFetching({
systemId,
signaturesRef,
setSignatures,
localPendingDeletions,
});
const handlePaste = useCallback(
async (clipboardString: string) => {
const lazyDeleteValue = settings.find(s => s.key === LAZY_DELETE_SIGNATURES_SETTING)?.value ?? false;
const incomingSignatures = parseSignatures(
clipboardString,
settings.map(s => s.key),
) as ExtendedSystemSignature[];
const current = signaturesRef.current;
const currentNonPending = lazyDeleteValue
? current.filter(sig => !sig.pendingDeletion)
: current.filter(sig => !sig.pendingDeletion && !sig.pendingAddition);
const { added, updated, removed } = getActualSigs(currentNonPending, incomingSignatures, !lazyDeleteValue, true);
if (added.length > 0) {
processAddedSignatures(added);
}
if (removed.length > 0) {
await processRemovedSignatures(removed, added, updated);
} else {
const resp = await outCommand({
type: OutCommand.updateSignatures,
data: {
system_id: systemId,
added,
updated,
removed: [],
},
});
if (resp) {
const finalSigs = (resp.signatures ?? []) as SystemSignature[];
setSignatures(prev =>
mergeLocalPendingAdditions(
finalSigs.map(x => ({ ...x })),
prev,
),
);
}
}
const keepLazy = settings.find(s => s.key === KEEP_LAZY_DELETE_SETTING)?.value ?? false;
if (lazyDeleteValue && !keepLazy) {
setTimeout(() => {
onLazyDeleteChange?.(false);
}, 0);
}
},
[
settings,
signaturesRef,
processAddedSignatures,
processRemovedSignatures,
outCommand,
systemId,
setSignatures,
onLazyDeleteChange,
],
);
const handleDeleteSelected = useCallback(async () => {
if (!selectedSignatures.length) return;
const selectedIds = selectedSignatures.map(s => s.eve_id);
const finalList = signatures.filter(s => !selectedIds.includes(s.eve_id));
await handleUpdateSignatures(finalList, false, true);
setSelectedSignatures([]);
}, [selectedSignatures, signatures, handleUpdateSignatures]);
const handleSelectAll = useCallback(() => {
setSelectedSignatures(signatures);
}, [signatures]);
const undoPending = useCallback(() => {
clearPendingDeletions();
clearPendingAdditions();
setSignatures(prev =>
prev.map(x => (x.pendingDeletion ? { ...x, pendingDeletion: false, pendingUntil: undefined } : x)),
);
if (pendingUndoAdditions.length) {
pendingUndoAdditions.forEach(async sig => {
await outCommand({
type: OutCommand.updateSignatures,
data: {
system_id: systemId,
added: [],
updated: [],
removed: [sig],
},
});
});
setSignatures(prev => prev.filter(x => !pendingUndoAdditions.some(u => u.eve_id === x.eve_id)));
setPendingUndoAdditions([]);
}
setLocalPendingDeletions([]);
}, [
clearPendingDeletions,
clearPendingAdditions,
pendingUndoAdditions,
setPendingUndoAdditions,
setLocalPendingDeletions,
setSignatures,
outCommand,
systemId,
]);
useEffect(() => {
const combined = [...localPendingDeletions, ...pendingUndoAdditions];
onPendingChange?.(combined, undoPending);
}, [localPendingDeletions, pendingUndoAdditions, onPendingChange, undoPending]);
useEffect(() => {
if (!systemId) return;
const now = Date.now();
const oldOnes = signaturesRef.current.filter(sig => {
if (!sig.inserted_at) return false;
const inserted = new Date(sig.inserted_at).getTime();
const threshold = sig.group === SignatureGroup.Wormhole ? TIME_ONE_DAY : TIME_ONE_WEEK;
return now - inserted > threshold;
});
if (oldOnes.length) {
const remain = signaturesRef.current.filter(x => !oldOnes.includes(x));
handleUpdateSignatures(remain, false, true);
}
}, [systemId, handleUpdateSignatures, signaturesRef]);
useMapEventListener(event => {
if (event.name === Commands.signaturesUpdated && String(event.data) === String(systemId)) {
handleGetSignatures();
return true;
}
});
useEffect(() => {
if (!systemId) {
setSignatures([]);
return;
}
handleGetSignatures();
}, [systemId, handleGetSignatures, setSignatures]);
useEffect(() => {
onCountChange?.(signatures.length);
}, [signatures, onCountChange]);
return {
signatures,
selectedSignatures,
setSelectedSignatures,
handleDeleteSelected,
handleSelectAll,
handlePaste,
};
}

View File

@@ -24,6 +24,12 @@ export const renderInfoColumn = (row: SystemSignature) => {
</WdTooltipWrapper>
)}
{customInfo.isCrit && (
<WdTooltipWrapper offset={5} position={TooltipPosition.top} content="Signature marked as Crit">
<div className="pi pi-clock text-fuchsia-400 text-[11px] mr-[2px]"></div>
</WdTooltipWrapper>
)}
{row.type && (
<WHClassView
className="text-[11px]"

View File

@@ -17,7 +17,7 @@ export interface MapSettingsProps {
systemId: string;
show: boolean;
onHide: () => void;
signatureData: SystemSignature | null;
signatureData: SystemSignature | undefined;
}
export const SignatureSettings = ({ systemId, show, onHide, signatureData }: MapSettingsProps) => {

View File

@@ -2,12 +2,13 @@ import { WORMHOLES_ADDITIONAL_INFO } from '@/hooks/Mapper/components/map/constan
import { WormholeDataRaw } from '@/hooks/Mapper/types';
export const sortWHClasses = (wormholesData: Record<string, WormholeDataRaw>, statics: string[]) => {
if (!statics) {
if (!statics || !wormholesData) {
return [];
}
return statics
.map(x => wormholesData[x])
.filter(x => !!x)
.map(x => ({ name: x.name, ...WORMHOLES_ADDITIONAL_INFO[x.dest] }))
.sort((a, b) => a.wormholeClassID - b.wormholeClassID)
.map(x => x.name);

View File

@@ -66,6 +66,7 @@ export type CommandInit = {
routes: RoutesList;
options: Record<string, string | boolean>;
reset?: boolean;
is_subscription_active?: boolean;
};
export type CommandAddSystems = SolarSystemRawType[];
export type CommandUpdateSystems = SolarSystemRawType[];

View File

@@ -1,4 +1,4 @@
import { SolarSystemStaticInfoRaw } from '@/hooks/Mapper/types';
import { CharacterTypeRaw, SolarSystemStaticInfoRaw } from '@/hooks/Mapper/types';
export enum SignatureGroup {
CosmicSignature = 'Cosmic Signature',
@@ -33,6 +33,8 @@ export type SignatureCustomInfo = {
export type SystemSignature = {
eve_id: string;
character_eve_id: string;
character_name?: string;
kind: SignatureKind;
name: string;
// SignatureCustomInfo

View File

@@ -1,18 +1,31 @@
import { useCallback, useRef, useState } from 'react';
import { useCallback, useRef, useState, useEffect } from 'react';
import { ContextStoreDataOpts, ProvideConstateDataReturnType, ContextStoreDataUpdate } from './types';
import { ContextStoreDataOpts, ProvideConstateDataReturnType, ContextStoreDataUpdate, UpdateFunc } from './types';
export const useContextStore = <T>(
initialValue: T,
{ notNeedRerender = false, handleBeforeUpdate, onAfterAUpdate }: ContextStoreDataOpts<T> = {},
): ProvideConstateDataReturnType<T> => {
const ref = useRef<T>(initialValue);
const queueRef = useRef<{ valOrFunc: Partial<T> | UpdateFunc<T>; force: boolean }[]>([]);
const [, setRerenderKey] = useState(0);
const refWrapper = useRef({ notNeedRerender, handleBeforeUpdate, onAfterAUpdate });
refWrapper.current = { notNeedRerender, handleBeforeUpdate, onAfterAUpdate };
const update: ContextStoreDataUpdate<T> = useCallback((valOrFunc, force = false) => {
queueRef.current.push({ valOrFunc, force });
}, []);
const processNextQueue = useCallback(() => {
const next = queueRef.current.shift();
if (!next) {
return;
}
const { valOrFunc, force } = next;
// It need to force prevent unnecessary rerendering
// update will create once
const { notNeedRerender, handleBeforeUpdate, onAfterAUpdate } = refWrapper.current;
@@ -76,5 +89,19 @@ export const useContextStore = <T>(
onAfterAUpdate?.(ref.current);
}, []);
useEffect(() => {
let requestId: number;
const process = () => {
processNextQueue();
requestId = requestAnimationFrame(process);
};
process();
return () => {
cancelAnimationFrame(requestId);
};
});
return { update, ref: ref.current };
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -53,6 +53,11 @@ public_api_disabled =
|> get_var_from_path_or_env("WANDERER_PUBLIC_API_DISABLED", "false")
|> String.to_existing_atom()
character_api_disabled =
config_dir
|> get_var_from_path_or_env("WANDERER_CHARACTER_API_DISABLED", "false")
|> String.to_existing_atom()
zkill_preload_disabled =
config_dir
|> get_var_from_path_or_env("WANDERER_ZKILL_PRELOAD_DISABLED", "false")
@@ -123,6 +128,7 @@ config :wanderer_app,
corp_id: System.get_env("WANDERER_CORP_ID", "-1") |> String.to_integer(),
corp_wallet: System.get_env("WANDERER_CORP_WALLET", ""),
public_api_disabled: public_api_disabled,
character_api_disabled: character_api_disabled,
zkill_preload_disabled: zkill_preload_disabled,
map_subscriptions_enabled: map_subscriptions_enabled,
map_connection_auto_expire_hours: map_connection_auto_expire_hours,

View File

@@ -12,7 +12,6 @@ defmodule WandererApp.Api.AccessList do
code_interface do
define(:create, action: :create)
define(:available, action: :available)
define(:new, action: :new)
define(:read, action: :read)
@@ -39,7 +38,8 @@ defmodule WandererApp.Api.AccessList do
end
create :new do
accept [:name, :description, :owner_id]
# Added :api_key to the accepted attributes
accept [:name, :description, :owner_id, :api_key]
primary?(true)
argument :owner_id, :uuid, allow_nil?: false
@@ -48,7 +48,7 @@ defmodule WandererApp.Api.AccessList do
end
update :update do
accept [:name, :description, :owner_id]
accept [:name, :description, :owner_id, :api_key]
primary?(true)
end
@@ -68,6 +68,10 @@ defmodule WandererApp.Api.AccessList do
allow_nil? true
end
attribute :api_key, :string do
allow_nil? true
end
create_timestamp(:inserted_at)
update_timestamp(:updated_at)
end

View File

@@ -11,6 +11,7 @@ defmodule WandererApp.Env do
def invites, do: get_key(:invites, false)
def map_subscriptions_enabled?, do: get_key(:map_subscriptions_enabled, false)
def public_api_disabled?, do: get_key(:public_api_disabled, false)
def character_api_disabled?, do: get_key(:character_api_disabled, false)
def zkill_preload_disabled?, do: get_key(:zkill_preload_disabled, false)
def wallet_tracking_enabled?, do: get_key(:wallet_tracking_enabled, false)
def admins, do: get_key(:admins, [])

View File

@@ -237,6 +237,12 @@ defmodule WandererApp.Map.Server do
|> map_pid!
|> GenServer.cast({&Impl.update_connection_custom_info/2, [connection_info]})
def update_signatures(map_id, signatures_update) when is_binary(map_id),
do:
map_id
|> map_pid!
|> GenServer.cast({&Impl.update_signatures/2, [signatures_update]})
@impl true
def handle_continue(:load_state, state),
do: {:noreply, state |> Impl.load_state(), {:continue, :start_map}}

View File

@@ -4,7 +4,13 @@ defmodule WandererApp.Map.Server.Impl do
"""
require Logger
alias WandererApp.Map.Server.{AclsImpl, CharactersImpl, ConnectionsImpl, SystemsImpl}
alias WandererApp.Map.Server.{
AclsImpl,
CharactersImpl,
ConnectionsImpl,
SystemsImpl,
SignaturesImpl
}
@enforce_keys [
:map_id
@@ -180,7 +186,9 @@ defmodule WandererApp.Map.Server.Impl do
defdelegate update_connection_locked(state, connection_update), to: ConnectionsImpl
defdelegate update_connection_custom_info(state, connection_update), to: ConnectionsImpl
defdelegate update_connection_custom_info(state, signatures_update), to: ConnectionsImpl
defdelegate update_signatures(state, signatures_update), to: SignaturesImpl
def import_settings(%{map_id: map_id} = state, settings, user_id) do
WandererApp.Cache.put(

View File

@@ -0,0 +1,150 @@
defmodule WandererApp.Map.Server.SignaturesImpl do
@moduledoc false
require Logger
alias WandererApp.Map.Server.{Impl, ConnectionsImpl, SystemsImpl}
def update_signatures(
%{map_id: map_id} = state,
%{
solar_system_id: solar_system_id,
character: character,
user_id: user_id,
delete_connection_with_sigs: delete_connection_with_sigs,
added_signatures: added_signatures,
updated_signatures: updated_signatures,
removed_signatures: removed_signatures
} =
_signatures_update
) do
WandererApp.Api.MapSystem.read_by_map_and_solar_system(%{
map_id: map_id,
solar_system_id: solar_system_id
})
|> case do
{:ok, system} ->
character_eve_id = character.eve_id
case not is_nil(character_eve_id) do
true ->
added_signatures =
added_signatures
|> parse_signatures(character_eve_id, system.id)
updated_signatures =
updated_signatures
|> parse_signatures(character_eve_id, system.id)
updated_signatures_eve_ids =
updated_signatures
|> Enum.map(fn s -> s.eve_id end)
removed_signatures_eve_ids =
removed_signatures
|> parse_signatures(character_eve_id, system.id)
|> Enum.map(fn s -> s.eve_id end)
WandererApp.Api.MapSystemSignature.by_system_id!(system.id)
|> Enum.filter(fn s -> s.eve_id in removed_signatures_eve_ids end)
|> Enum.each(fn s ->
if delete_connection_with_sigs && not is_nil(s.linked_system_id) do
state
|> ConnectionsImpl.delete_connection(%{
solar_system_source_id: system.solar_system_id,
solar_system_target_id: s.linked_system_id
})
end
if not is_nil(s.linked_system_id) do
state
|> SystemsImpl.update_system_linked_sig_eve_id(%{
solar_system_id: s.linked_system_id,
linked_sig_eve_id: nil
})
end
s
|> Ash.destroy!()
end)
WandererApp.Api.MapSystemSignature.by_system_id!(system.id)
|> Enum.filter(fn s -> s.eve_id in updated_signatures_eve_ids end)
|> Enum.each(fn s ->
updated = updated_signatures |> Enum.find(fn u -> u.eve_id == s.eve_id end)
if not is_nil(updated) do
s
|> WandererApp.Api.MapSystemSignature.update(
updated
|> Map.put(:updated, System.os_time())
)
end
end)
added_signatures
|> Enum.each(fn s ->
s |> WandererApp.Api.MapSystemSignature.create!()
end)
added_signatures_eve_ids =
added_signatures
|> Enum.map(fn s -> s.eve_id end)
if not is_nil(character) &&
not (added_signatures_eve_ids |> Enum.empty?()) do
WandererApp.User.ActivityTracker.track_map_event(:signatures_added, %{
character_id: character.id,
user_id: user_id,
map_id: map_id,
solar_system_id: system.solar_system_id,
signatures: added_signatures_eve_ids
})
end
if not is_nil(character) &&
not (removed_signatures_eve_ids |> Enum.empty?()) do
WandererApp.User.ActivityTracker.track_map_event(:signatures_removed, %{
character_id: character.id,
user_id: user_id,
map_id: map_id,
solar_system_id: system.solar_system_id,
signatures: removed_signatures_eve_ids
})
end
Impl.broadcast!(map_id, :signatures_updated, system.solar_system_id)
state
_ ->
state
end
_ ->
state
end
end
defp parse_signatures(signatures, character_eve_id, system_id),
do:
signatures
|> Enum.map(fn %{
"eve_id" => eve_id,
"name" => name,
"kind" => kind,
"group" => group
} = signature ->
%{
system_id: system_id,
eve_id: eve_id,
name: name,
description: Map.get(signature, "description"),
kind: kind,
group: group,
type: Map.get(signature, "type"),
custom_info: Map.get(signature, "custom_info"),
character_eve_id: character_eve_id
}
end)
end

View File

@@ -278,7 +278,7 @@ defmodule WandererApp.Map.Server.SystemsImpl do
linked_system_ids
|> Enum.each(fn linked_system_id ->
WandererApp.Map.Server.update_system_linked_sig_eve_id(map_id, %{
update_system_linked_sig_eve_id(state, %{
solar_system_id: linked_system_id,
linked_sig_eve_id: nil
})

View File

@@ -295,4 +295,34 @@ defmodule WandererApp.Maps do
character_eve_ids |> Enum.any?(fn eve_id -> eve_id in acl_roles_eve_ids end)
end
def check_user_can_delete_map(map_slug, current_user) do
map_slug
|> WandererApp.Api.Map.get_map_by_slug()
|> Ash.load([:owner, :acls, :user_permissions], actor: current_user)
|> case do
{:ok,
%{
user_permissions: user_permissions,
owner_id: owner_id
} = map} ->
user_permissions =
WandererApp.Permissions.get_map_permissions(
user_permissions,
owner_id,
current_user.characters |> Enum.map(& &1.id)
)
case user_permissions.delete_map do
true ->
{:ok, map}
_ ->
{:error, :not_authorized}
end
error ->
{:error, error}
end
end
end

View File

@@ -64,6 +64,18 @@ defmodule WandererAppWeb.Layouts do
"""
end
def donate_container(assigns) do
~H"""
<.link
href="https://www.patreon.com/WandererLtd"
target="_blank"
class="flex flex-col p-4 items-center absolute bottom-52 left-1 gap-2 tooltip tooltip-right text-gray-400 hover:text-white"
>
<.icon name="hero-banknotes-solid" class="h-4 w-4" />
</.link>
"""
end
def feedback_container(assigns) do
~H"""
<.link

View File

@@ -17,6 +17,7 @@
/>
</aside>
<.ping_container rtt_class={@rtt_class} />
<.donate_container />
<.feedback_container />
<.new_version_banner app_version={@app_version} />
</div>

View File

@@ -0,0 +1,84 @@
defmodule WandererAppWeb.MapCharacters do
use WandererAppWeb, :live_component
use LiveViewEvents
@impl true
def mount(socket) do
{:ok, socket}
end
@impl true
def update(
assigns,
socket
) do
{:ok,
socket
|> handle_info_or_assign(assigns)}
end
# attr(:groups, :any, required: true)
# attr(:character_settings, :any, required: true)
def render(assigns) do
~H"""
<div id={@id}>
<ul :for={group <- @groups} class="space-y-4 border-t border-b border-gray-200 py-4">
<li :for={character <- group.characters}>
<div class="flex items-center justify-between w-full space-x-2 p-1 hover:bg-gray-900">
<.character_entry character={character} character_settings={@character_settings} />
<button
phx-click="untrack"
phx-value-event-data={character.id}
class="btn btn-sm btn-icon"
>
<.icon name="hero-eye-slash" class="h-5 w-5" /> Untrack
</button>
</div>
</li>
</ul>
</div>
"""
end
attr(:character, :any, required: true)
attr(:character_settings, :any, required: true)
defp character_entry(assigns) do
~H"""
<div class="flex items-center gap-3 text-sm w-[450px]">
<span
:if={is_tracked?(@character.id, @character_settings)}
class="text-green-500 rounded-full px-2 py-1"
>
Tracked
</span>
<div class="avatar">
<div class="rounded-md w-8 h-8">
<img src={member_icon_url(@character.eve_id)} alt={@character.name} />
</div>
</div>
<span><%= @character.name %></span>
<span :if={@character.alliance_ticker}>[<%= @character.alliance_ticker %>]</span>
<span :if={@character.corporation_ticker}>[<%= @character.corporation_ticker %>]</span>
</div>
"""
end
@impl true
def handle_event("undo", %{"event-data" => event_data} = _params, socket) do
# notify_to(socket.assigns.notify_to, socket.assigns.event_name, map_slug)
{:noreply, socket}
end
defp is_tracked?(character_id, character_settings) do
Enum.any?(character_settings, fn setting ->
setting.character_id == character_id && setting.tracked
end)
end
defp get_event_name(name), do: name
defp get_event_data(_name, data), do: Jason.encode!(data)
end

View File

@@ -0,0 +1,259 @@
defmodule WandererAppWeb.MapAccessListAPIController do
@moduledoc """
API endpoints for managing Access Lists.
Endpoints:
- GET /api/map/acls?map_id=... or ?slug=... (list ACLs)
- POST /api/map/acls (create ACL)
- GET /api/acls/:id (show ACL)
- PUT /api/acls/:id (update ACL)
ACL members are managed via a separate controller.
"""
use WandererAppWeb, :controller
alias WandererApp.Api.{AccessList, Character}
alias WandererAppWeb.UtilAPIController, as: Util
import Ash.Query
require Logger
@doc """
GET /api/map/acls?map_id=... or ?slug=...
Lists the ACLs for a given map.
"""
def index(conn, params) do
case Util.fetch_map_id(params) do
{:ok, map_identifier} ->
with {:ok, map} <- get_map(map_identifier),
# Load ACLs and each ACL's :owner in a single pass:
{:ok, loaded_map} <- Ash.load(map, acls: [:owner]) do
acls = loaded_map.acls || []
json(conn, %{data: Enum.map(acls, &acl_to_list_json/1)})
else
{:error, :map_not_found} ->
conn
|> put_status(:not_found)
|> json(%{error: "Map not found"})
{:error, error} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: inspect(error)})
end
{:error, msg} ->
conn
|> put_status(:bad_request)
|> json(%{error: msg})
end
end
@doc """
POST /api/map/acls
Creates a new ACL for a map.
"""
def create(conn, params) do
with {:ok, map_identifier} <- Util.fetch_map_id(params),
{:ok, map} <- get_map(map_identifier),
%{"acl" => acl_params} <- params,
owner_eve_id when not is_nil(owner_eve_id) <- Map.get(acl_params, "owner_eve_id"),
owner_eve_id_str = to_string(owner_eve_id),
{:ok, character} <- find_character_by_eve_id(owner_eve_id_str),
{:ok, new_api_key} <- {:ok, UUID.uuid4()},
new_params <-
acl_params
|> Map.delete("owner_eve_id")
|> Map.put("owner_id", character.id)
|> Map.put("api_key", new_api_key),
{:ok, new_acl} <- AccessList.new(new_params),
{:ok, _updated_map} <- associate_acl_with_map(map, new_acl) do
json(conn, %{data: acl_to_json(new_acl)})
else
nil ->
conn
|> put_status(:bad_request)
|> json(%{error: "Missing required field: owner_eve_id"})
{:error, "owner_eve_id does not match any existing character"} = error ->
conn
|> put_status(:bad_request)
|> json(%{error: inspect(error)})
# For any other error, also a bad request—adjust if you want a different code
error ->
conn
|> put_status(:bad_request)
|> json(%{error: inspect(error)})
end
end
@doc """
GET /api/acls/:id
Shows a specific ACL (with its members).
"""
def show(conn, %{"id" => id}) do
query =
AccessList
|> Ash.Query.new()
|> filter(id == ^id)
case WandererApp.Api.read(query) do
{:ok, [acl]} ->
# We load members for a single ACL
case Ash.load(acl, :members) do
{:ok, loaded_acl} ->
json(conn, %{data: acl_to_json(loaded_acl)})
{:error, error} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: "Failed to load ACL members: #{inspect(error)}"})
end
{:ok, []} ->
conn
|> put_status(:not_found)
|> json(%{error: "ACL not found"})
{:error, error} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: "Error reading ACL: #{inspect(error)}"})
end
end
@doc """
PUT /api/acls/:id
Updates an ACL.
"""
def update(conn, %{"id" => id, "acl" => acl_params}) do
with {:ok, acl} <- AccessList.by_id(id),
{:ok, updated_acl} <- AccessList.update(acl, acl_params),
{:ok, updated_acl} <- Ash.load(updated_acl, :members) do
json(conn, %{data: acl_to_json(updated_acl)})
else
{:error, error} ->
conn
|> put_status(:bad_request)
|> json(%{error: "Failed to update ACL: #{inspect(error)}"})
end
end
# ---------------------------------------------------------------------------
# Private / Helper Functions
# ---------------------------------------------------------------------------
defp get_map(map_identifier) do
# If your WandererApp.Api.Map.by_id/1 returns :map_not_found or
# returns {:ok, map}/{:error, ...}, you can handle that here
WandererApp.Api.Map.by_id(map_identifier)
end
defp acl_to_json(acl) do
members =
case acl.members do
%Ash.NotLoaded{} -> []
list when is_list(list) -> Enum.map(list, &member_to_json/1)
_ -> []
end
%{
id: acl.id,
name: acl.name,
description: acl.description,
owner_id: acl.owner_id,
api_key: acl.api_key,
inserted_at: acl.inserted_at,
updated_at: acl.updated_at,
members: members
}
end
defp acl_to_list_json(acl) do
# Because we loaded :owner for each ACL in index/2, we can reference it here
owner_eve_id =
case acl.owner do
%Character{eve_id: eid} -> eid
_ -> nil
end
%{
id: acl.id,
name: acl.name,
description: acl.description,
owner_eve_id: owner_eve_id,
inserted_at: acl.inserted_at,
updated_at: acl.updated_at
}
end
defp member_to_json(member) do
%{
id: member.id,
name: member.name,
role: member.role,
eve_character_id: member.eve_character_id,
inserted_at: member.inserted_at,
updated_at: member.updated_at
}
end
# Helper to find a character by external EVE id.
defp find_character_by_eve_id(eve_id) do
query =
Character
|> Ash.Query.new()
|> filter(eve_id == ^eve_id)
case WandererApp.Api.read(query) do
{:ok, [character]} ->
{:ok, character}
{:ok, []} ->
{:error, "owner_eve_id does not match any existing character"}
other ->
other
end
end
# Helper to find a character by internal id.
defp find_character_by_id(id) do
query =
Character
|> Ash.Query.new()
|> filter(id == ^id)
case WandererApp.Api.read(query) do
{:ok, [character]} -> {:ok, character}
{:ok, []} -> {:error, "Character not found"}
other -> other
end
end
# Helper to associate a new ACL with a map.
defp associate_acl_with_map(map, new_acl) do
with {:ok, api_map} <- WandererApp.Api.Map.by_id(map.id),
{:ok, loaded_map} <- Ash.load(api_map, :acls) do
new_acl_id = if is_binary(new_acl), do: new_acl, else: new_acl.id
current_acls = loaded_map.acls || []
updated_acls = current_acls ++ [new_acl_id]
case WandererApp.Api.Map.update_acls(loaded_map, %{acls: updated_acls}) do
{:ok, updated_map} ->
{:ok, updated_map}
{:error, error} ->
Logger.error("Failed to update map #{loaded_map.id} with new ACL: #{inspect(error)}")
{:error, error}
end
else
error ->
Logger.error("Error loading map ACLs: #{inspect(error)}")
{:error, error}
end
end
end

View File

@@ -0,0 +1,218 @@
defmodule WandererAppWeb.AccessListMemberAPIController do
@moduledoc """
Handles creation, role updates, and deletion of individual ACL members.
This controller supports creation of members by accepting one of the following keys:
- "eve_character_id"
- "eve_corporation_id"
- "eve_alliance_id"
For corporation and alliance members, roles "admin" and "manager" are disallowed.
"""
use WandererAppWeb, :controller
alias WandererApp.Api.AccessListMember
import Ash.Query
require Logger
@doc """
POST /api/acls/:acl_id/members
"""
def create(conn, %{"acl_id" => acl_id, "member" => member_params}) do
chosen =
cond do
Map.has_key?(member_params, "eve_corporation_id") ->
{"eve_corporation_id", "corporation"}
Map.has_key?(member_params, "eve_alliance_id") ->
{"eve_alliance_id", "alliance"}
Map.has_key?(member_params, "eve_character_id") ->
{"eve_character_id", "character"}
true ->
nil
end
if is_nil(chosen) do
conn
|> put_status(:bad_request)
|> json(%{
error:
"Missing one of eve_character_id, eve_corporation_id, or eve_alliance_id in payload"
})
else
{key, type} = chosen
raw_id = Map.get(member_params, key)
id_str = to_string(raw_id) # handle string/integer input
role = Map.get(member_params, "role", "viewer")
if type in ["corporation", "alliance"] and role in ["admin", "manager"] do
conn
|> put_status(:bad_request)
|> json(%{
error:
"#{String.capitalize(type)} members cannot have an admin or manager role"
})
else
info_fetcher =
case type do
"character" -> &WandererApp.Esi.get_character_info/1
"corporation" -> &WandererApp.Esi.get_corporation_info/1
"alliance" -> &WandererApp.Esi.get_alliance_info/1
end
with {:ok, entity_info} <- info_fetcher.(id_str) do
member_name = Map.get(entity_info, "name")
new_params =
member_params
|> Map.drop(["eve_corporation_id", "eve_alliance_id", "eve_character_id"])
|> Map.put(key, id_str)
|> Map.put("name", member_name)
|> Map.put("access_list_id", acl_id)
case AccessListMember.create(new_params) do
{:ok, new_member} ->
json(conn, %{data: member_to_json(new_member)})
{:error, error} ->
conn
|> put_status(:bad_request)
|> json(%{error: "Creation failed: #{inspect(error)}"})
end
else
{:error, error} ->
conn
|> put_status(:bad_request)
|> json(%{error: "Entity lookup failed: #{inspect(error)}"})
end
end
end
end
@doc """
PUT /api/acls/:acl_id/members/:member_id
"""
def update_role(conn, %{
"acl_id" => acl_id,
"member_id" => external_id,
"member" => member_params
}) do
# Convert external_id to string if you expect it may come in as integer
external_id_str = to_string(external_id)
membership_query =
AccessListMember
|> Ash.Query.new()
|> filter(access_list_id == ^acl_id)
|> filter(
eve_character_id == ^external_id_str or
eve_corporation_id == ^external_id_str or
eve_alliance_id == ^external_id_str
)
case WandererApp.Api.read(membership_query) do
{:ok, [membership]} ->
new_role = Map.get(member_params, "role", membership.role)
member_type =
cond do
membership.eve_corporation_id -> "corporation"
membership.eve_alliance_id -> "alliance"
membership.eve_character_id -> "character"
true -> "character"
end
if member_type in ["corporation", "alliance"] and new_role in ["admin", "manager"] do
conn
|> put_status(:bad_request)
|> json(%{
error:
"#{String.capitalize(member_type)} members cannot have an admin or manager role"
})
else
case AccessListMember.update_role(membership, member_params) do
{:ok, updated_membership} ->
json(conn, %{data: member_to_json(updated_membership)})
{:error, error} ->
conn
|> put_status(:bad_request)
|> json(%{error: inspect(error)})
end
end
{:ok, []} ->
conn
|> put_status(:not_found)
|> json(%{error: "Membership not found for given ACL and external id"})
{:error, error} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: inspect(error)})
end
end
@doc """
DELETE /api/acls/:acl_id/members/:member_id
"""
def delete(conn, %{"acl_id" => acl_id, "member_id" => external_id}) do
external_id_str = to_string(external_id)
membership_query =
AccessListMember
|> Ash.Query.new()
|> filter(access_list_id == ^acl_id)
|> filter(
eve_character_id == ^external_id_str or
eve_corporation_id == ^external_id_str or
eve_alliance_id == ^external_id_str
)
case WandererApp.Api.read(membership_query) do
{:ok, [membership]} ->
case AccessListMember.destroy(membership) do
:ok ->
json(conn, %{ok: true})
{:error, error} ->
conn
|> put_status(:bad_request)
|> json(%{error: inspect(error)})
end
{:ok, []} ->
conn
|> put_status(:not_found)
|> json(%{error: "Membership not found for given ACL and external id"})
{:error, error} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: inspect(error)})
end
end
# ---------------------------------------------------------------------------
# Private Helpers
# ---------------------------------------------------------------------------
@doc false
defp member_to_json(member) do
base = %{
id: member.id,
name: member.name,
role: member.role,
inserted_at: member.inserted_at,
updated_at: member.updated_at
}
cond do
member.eve_character_id -> Map.put(base, :eve_character_id, member.eve_character_id)
member.eve_corporation_id -> Map.put(base, :eve_corporation_id, member.eve_corporation_id)
member.eve_alliance_id -> Map.put(base, :eve_alliance_id, member.eve_alliance_id)
true -> base
end
end
end

View File

@@ -0,0 +1,39 @@
defmodule WandererAppWeb.CharactersAPIController do
@moduledoc """
Exposes an endpoint for listing ALL characters in the database
Endpoint:
GET /api/characters
"""
use WandererAppWeb, :controller
alias WandererApp.Api.Character
@doc """
GET /api/characters
Lists ALL characters in the database
Returns an array of objects, each with `id`, `eve_id`, `name`, etc.
"""
def index(conn, _params) do
case WandererApp.Api.read(Character) do
{:ok, characters} ->
result =
characters
|> Enum.map(&%{
id: &1.id,
eve_id: &1.eve_id,
name: &1.name,
corporation_name: &1.corporation_name,
alliance_name: &1.alliance_name
})
json(conn, %{data: result})
{:error, error} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: inspect(error)})
end
end
end

View File

@@ -0,0 +1,55 @@
defmodule WandererAppWeb.Plugs.CheckAclApiKey do
@moduledoc """
A plug that checks the "Authorization: Bearer <token>" header
against the ACLs stored api_key.
"""
import Plug.Conn
alias WandererApp.Repo
alias WandererApp.Api.AccessList
def init(opts), do: opts
def call(conn, _opts) do
header = get_req_header(conn, "authorization") |> List.first()
case header do
"Bearer " <> incoming_token ->
acl_id = conn.params["id"] || conn.params["acl_id"]
if acl_id do
case Repo.get(AccessList, acl_id) do
nil ->
conn
|> send_resp(404, "ACL not found")
|> halt()
acl ->
cond do
is_nil(acl.api_key) ->
conn
|> send_resp(401, "Unauthorized (no API key set for ACL)")
|> halt()
acl.api_key == incoming_token ->
conn
true ->
conn
|> send_resp(401, "Unauthorized (invalid API key for ACL)")
|> halt()
end
end
else
conn
|> send_resp(400, "ACL ID not provided")
|> halt()
end
_ ->
conn
|> send_resp(401, "Missing or invalid 'Bearer' token")
|> halt()
end
end
end

View File

@@ -0,0 +1,15 @@
defmodule WandererAppWeb.Plugs.CheckCharacterApiDisabled do
import Plug.Conn
def init(opts), do: opts
def call(conn, _opts) do
if WandererApp.Env.character_api_disabled?() do
conn
|> send_resp(403, "Character API is disabled")
|> halt()
else
conn
end
end
end

View File

@@ -5,6 +5,7 @@ defmodule WandererAppWeb.Plugs.CheckMapApiKey do
"""
import Plug.Conn
alias WandererAppWeb.UtilAPIController, as: Util
def init(opts), do: opts
@@ -37,10 +38,7 @@ defmodule WandererAppWeb.Plugs.CheckMapApiKey do
end
defp fetch_map(query_params) do
case fetch_map_id(query_params) do
{:ok, {:map, map}} ->
{:ok, map}
case Util.fetch_map_id(query_params) do
{:ok, map_id} ->
WandererApp.Api.Map.by_id(map_id)
@@ -48,20 +46,4 @@ defmodule WandererAppWeb.Plugs.CheckMapApiKey do
error
end
end
defp fetch_map_id(%{"map_id" => mid}) when is_binary(mid) and mid != "" do
{:ok, mid}
end
defp fetch_map_id(%{"slug" => slug}) when is_binary(slug) and slug != "" do
case WandererApp.Api.Map.get_map_by_slug(slug) do
{:ok, map} ->
{:ok, {:map, map}}
{:error, _reason} ->
{:error, "No map found for slug=#{slug}"}
end
end
defp fetch_map_id(_), do: {:error, "Must provide either ?map_id=UUID or ?slug=SLUG"}
end

View File

@@ -314,6 +314,24 @@ defmodule WandererAppWeb.AccessListsLive do
end
end
def handle_event("generate-api-key", _params, socket) do
new_api_key = UUID.uuid4()
new_params = Map.put(socket.assigns.form.params || %{}, "api_key", new_api_key)
form = AshPhoenix.Form.validate(socket.assigns.form, new_params)
{:noreply, assign(socket, form: form)}
end
@impl true
def handle_event("noop", _, socket) do
{:noreply, socket}
end
@impl true
def handle_event(event, body, socket) do
Logger.warning(fn -> "unhandled event: #{event} #{inspect(body)}" end)
{:noreply, socket}
end
@impl true
def handle_info(
{"update_role", %{member_id: member_id, role: role}},
@@ -328,17 +346,6 @@ defmodule WandererAppWeb.AccessListsLive do
{:noreply, socket |> maybe_update_role(member, role_atom, access_list)}
end
@impl true
def handle_event("noop", _, socket) do
{:noreply, socket}
end
@impl true
def handle_event(event, body, socket) do
Logger.warning(fn -> "unhandled event: #{event} #{inspect(body)}" end)
{:noreply, socket}
end
@impl true
def handle_info({:search, text}, socket) do
active_character_id =

View File

@@ -142,6 +142,50 @@
placeholder="Select an owner"
options={Enum.map(@characters, fn character -> {character.label, character.id} end)}
/>
<!-- Divider between above inputs and the API key section -->
<hr class="my-4 border-gray-600" />
<!-- API Key Section with grid layout -->
<div class="mt-2">
<label class="block text-sm font-medium text-gray-200 mb-1">ACL API key</label>
<div class="grid grid-cols-12 gap-2">
<div class="col-span-7">
<.input
type="text"
field={f[:api_key]}
placeholder="No API Key yet"
readonly
class="w-full"
/>
</div>
<div class="col-span-3">
<.button
type="button"
phx-click="generate-api-key"
class="p-button p-component p-button-primary w-full"
style="min-width: 0;"
>
<span class="p-button-label">Generate</span>
</.button>
</div>
<div class="col-span-2">
<.button
type="button"
phx-hook="CopyToClipboard"
id="copy-acl-api-key"
data-url={f[:api_key].value}
disabled={is_nil(f[:api_key].value) or f[:api_key].value == ""}
class={"p-button p-component w-full " <> if(is_nil(f[:api_key].value) or f[:api_key].value == "", do: "p-disabled", else: "")}
>
<span class="p-button-label">Copy</span>
</.button>
</div>
</div>
</div>
<hr class="my-4 border-gray-600" />
<div class="modal-action">
<.button class="mt-2" type="submit" phx-disable-with="Saving...">
<%= (@live_action == :create && "Create") || "Save" %>

View File

@@ -89,132 +89,30 @@ defmodule WandererAppWeb.MapSignaturesEventHandler do
}
} = socket
) do
WandererApp.Api.MapSystem.read_by_map_and_solar_system(%{
map_id: map_id,
solar_system_id: solar_system_id |> String.to_integer()
first_character_eve_id =
user_characters |> List.first()
character =
current_user.characters
|> Enum.find(fn c -> c.eve_id === first_character_eve_id end)
delete_connection_with_sigs =
map_user_settings
|> WandererApp.MapUserSettingsRepo.to_form_data!()
|> WandererApp.MapUserSettingsRepo.get_boolean_setting("delete_connection_with_sigs")
map_id
|> WandererApp.Map.Server.update_signatures(%{
solar_system_id: solar_system_id |> String.to_integer(),
character: character,
user_id: current_user.id,
delete_connection_with_sigs: delete_connection_with_sigs,
added_signatures: added_signatures,
updated_signatures: updated_signatures,
removed_signatures: removed_signatures
})
|> case do
{:ok, system} ->
first_character_eve_id =
user_characters |> List.first()
case not is_nil(first_character_eve_id) do
true ->
added_signatures =
added_signatures
|> parse_signatures(first_character_eve_id, system.id)
updated_signatures =
updated_signatures
|> parse_signatures(first_character_eve_id, system.id)
updated_signatures_eve_ids =
updated_signatures
|> Enum.map(fn s -> s.eve_id end)
removed_signatures_eve_ids =
removed_signatures
|> parse_signatures(first_character_eve_id, system.id)
|> Enum.map(fn s -> s.eve_id end)
delete_connection_with_sigs =
map_user_settings
|> WandererApp.MapUserSettingsRepo.to_form_data!()
|> WandererApp.MapUserSettingsRepo.get_boolean_setting(
"delete_connection_with_sigs"
)
WandererApp.Api.MapSystemSignature.by_system_id!(system.id)
|> Enum.filter(fn s -> s.eve_id in removed_signatures_eve_ids end)
|> Enum.each(fn s ->
if delete_connection_with_sigs && not is_nil(s.linked_system_id) do
map_id
|> WandererApp.Map.Server.delete_connection(%{
solar_system_source_id: system.solar_system_id,
solar_system_target_id: s.linked_system_id
})
end
if not is_nil(s.linked_system_id) do
map_id
|> WandererApp.Map.Server.update_system_linked_sig_eve_id(%{
solar_system_id: s.linked_system_id,
linked_sig_eve_id: nil
})
end
s
|> Ash.destroy!()
end)
WandererApp.Api.MapSystemSignature.by_system_id!(system.id)
|> Enum.filter(fn s -> s.eve_id in updated_signatures_eve_ids end)
|> Enum.each(fn s ->
updated = updated_signatures |> Enum.find(fn u -> u.eve_id == s.eve_id end)
if not is_nil(updated) do
s
|> WandererApp.Api.MapSystemSignature.update(
updated
|> Map.put(:updated, System.os_time())
)
end
end)
added_signatures
|> Enum.each(fn s ->
s |> WandererApp.Api.MapSystemSignature.create!()
end)
added_signatures_eve_ids =
added_signatures
|> Enum.map(fn s -> s.eve_id end)
first_tracked_character =
current_user.characters
|> Enum.find(fn c -> c.eve_id === first_character_eve_id end)
if not is_nil(first_tracked_character) &&
not (added_signatures_eve_ids |> Enum.empty?()) do
WandererApp.User.ActivityTracker.track_map_event(:signatures_added, %{
character_id: first_tracked_character.id,
user_id: current_user.id,
map_id: map_id,
solar_system_id: system.solar_system_id,
signatures: added_signatures_eve_ids
})
end
if not is_nil(first_tracked_character) &&
not (removed_signatures_eve_ids |> Enum.empty?()) do
WandererApp.User.ActivityTracker.track_map_event(:signatures_removed, %{
character_id: first_tracked_character.id,
user_id: current_user.id,
map_id: map_id,
solar_system_id: system.solar_system_id,
signatures: removed_signatures_eve_ids
})
end
Phoenix.PubSub.broadcast!(WandererApp.PubSub, map_id, %{
event: :signatures_updated,
payload: system.solar_system_id
})
{:reply, %{signatures: get_system_signatures(system.id)}, socket}
_ ->
{:reply, %{signatures: []},
socket
|> put_flash(
:error,
"You should enable tracking for at least one character to work with signatures."
)}
end
_ ->
{:noreply, socket}
end
{:noreply, socket}
end
def handle_ui_event(
@@ -377,6 +275,7 @@ defmodule WandererAppWeb.MapSignaturesEventHandler do
s
|> Map.take([
:eve_id,
:character_eve_id,
:name,
:description,
:kind,
@@ -388,26 +287,4 @@ defmodule WandererAppWeb.MapSignaturesEventHandler do
|> Map.put(:inserted_at, inserted_at |> Calendar.strftime("%Y/%m/%d %H:%M:%S"))
|> Map.put(:updated_at, updated_at |> Calendar.strftime("%Y/%m/%d %H:%M:%S"))
end)
defp parse_signatures(signatures, character_eve_id, system_id),
do:
signatures
|> Enum.map(fn %{
"eve_id" => eve_id,
"name" => name,
"kind" => kind,
"group" => group
} = signature ->
%{
system_id: system_id,
eve_id: eve_id,
name: name,
description: Map.get(signature, "description"),
kind: kind,
group: group,
type: Map.get(signature, "type"),
custom_info: Map.get(signature, "custom_info"),
character_eve_id: character_eve_id
}
end)
end

View File

@@ -10,57 +10,38 @@ defmodule WandererAppWeb.MapAuditLive do
def mount(
%{"slug" => map_slug, "period" => period, "activity" => activity} = _params,
_session,
socket
%{assigns: %{current_user: current_user}} = socket
) do
current_user = socket.assigns.current_user
map_slug
|> WandererApp.Api.Map.get_map_by_slug()
|> Ash.load([:acls, :user_permissions], actor: current_user)
WandererApp.Maps.check_user_can_delete_map(map_slug, current_user)
|> case do
{:ok,
%{
id: map_id,
user_permissions: user_permissions,
name: map_name,
owner_id: owner_id
name: map_name
} = _map} ->
user_permissions =
WandererApp.Permissions.get_map_permissions(
user_permissions,
owner_id,
current_user.characters |> Enum.map(& &1.id)
)
{:ok, is_subscription_active} = map_id |> WandererApp.Map.is_subscription_active?()
case user_permissions.delete_map do
true ->
{:ok, is_subscription_active} = map_id |> WandererApp.Map.is_subscription_active?()
{:ok,
socket
|> assign(
map_id: map_id,
map_name: map_name,
map_slug: map_slug,
map_subscription_active: is_subscription_active,
activity: activity,
can_undo_types: [:systems_removed],
period: period || "1H",
page: 1,
per_page: 25,
end_of_stream?: false
)
|> stream(:activity, [])}
_ ->
{:ok,
socket
|> put_flash(:error, "You don't have an access.")
|> push_navigate(to: ~p"/maps")}
end
{:ok,
socket
|> assign(
map_id: map_id,
map_name: map_name,
map_slug: map_slug,
map_subscription_active: is_subscription_active,
activity: activity,
can_undo_types: [:systems_removed],
period: period || "1H",
page: 1,
per_page: 25,
end_of_stream?: false
)
|> stream(:activity, [])}
_ ->
{:ok, socket}
{:ok,
socket
|> put_flash(:error, "You don't have an access.")
|> push_navigate(to: ~p"/maps")}
end
end

View File

@@ -0,0 +1,151 @@
defmodule WandererAppWeb.MapCharactersLive do
use WandererAppWeb, :live_view
require Logger
alias WandererAppWeb.MapCharacters
def mount(
%{"slug" => map_slug} = _params,
_session,
%{assigns: %{current_user: current_user}} = socket
) do
WandererApp.Maps.check_user_can_delete_map(map_slug, current_user)
|> case do
{:ok,
%{
id: map_id,
name: map_name
} = _map} ->
{:ok,
socket
|> assign(
map_id: map_id,
map_name: map_name,
map_slug: map_slug
)
|> assign(:groups, [])}
_ ->
{:ok,
socket
|> put_flash(:error, "You don't have an access.")
|> push_navigate(to: ~p"/maps")}
end
end
@impl true
def mount(_params, _session, socket) do
{:ok, socket |> assign(user_id: nil)}
end
@impl true
def handle_params(params, _url, socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
end
@impl true
def handle_info(
_event,
socket
) do
{:noreply, socket}
end
def handle_event(
"untrack",
%{"event-data" => character_id},
%{
assigns: %{
map_id: map_id,
current_user: _current_user,
character_settings: character_settings
}
} = socket
) do
socket =
character_settings
|> Enum.find(&(&1.character_id == character_id))
|> case do
nil ->
socket
character_setting ->
case character_setting.tracked do
true ->
{:ok, map_character_settings} =
character_setting
|> WandererApp.MapCharacterSettingsRepo.untrack()
WandererApp.Map.Server.remove_character(map_id, map_character_settings.character_id)
socket |> put_flash(:info, "Character untracked!") |> load_characters()
_ ->
socket
end
end
{:noreply, socket}
end
@impl true
def handle_event("noop", _, socket) do
{:noreply, socket}
end
@impl true
def handle_event(event, body, socket) do
Logger.warning(fn -> "unhandled event: #{event} #{inspect(body)}" end)
{:noreply, socket}
end
defp apply_action(socket, :index, _params) do
socket
|> assign(:active_page, :map_characters)
|> assign(:page_title, "Map - Characters")
|> load_characters()
end
defp load_characters(%{assigns: %{map_id: map_id}} = socket) do
map_characters =
map_id
|> WandererApp.Map.list_characters()
|> Enum.map(&map_ui_character/1)
groups =
map_characters
|> Enum.group_by(& &1.user_id)
|> Enum.reduce([], fn {user_id, values}, acc ->
acc ++ [%{id: user_id, characters: values}]
end)
{:ok, character_settings} =
case WandererApp.MapCharacterSettingsRepo.get_all_by_map(map_id) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
end
socket
|> assign(:character_settings, character_settings)
|> assign(:characters_count, map_characters |> length())
|> assign(:groups, groups)
end
defp map_ui_character(character),
do:
character
|> Map.take([
:id,
:user_id,
:eve_id,
:name,
:online,
:corporation_id,
:corporation_name,
:corporation_ticker,
:alliance_id,
:alliance_name,
:alliance_ticker
])
end

View File

@@ -0,0 +1,23 @@
<nav class="fixed top-0 z-100 px-6 pl-20 flex items-center justify-between w-full h-12 pointer-events-auto border-b border-stone-800 bg-opacity-70 bg-neutral-900">
<span className="w-full font-medium text-sm">
<.link navigate={~p"/#{@map_slug}"} class="text-neutral-100">
<%= @map_name %>
</.link>
- Characters [<%= @characters_count %>]
</span>
</nav>
<main
id="map-character-list"
class="pt-20 w-full h-full col-span-2 lg:col-span-1 p-4 pl-20 pb-20 overflow-auto"
>
<div class="flex flex-col gap-4 w-full">
<.live_component
module={MapCharacters}
id="map-characters"
notify_to={self()}
groups={@groups}
character_settings={@character_settings}
event_name="character_event"
/>
</div>
</main>

View File

@@ -166,6 +166,17 @@ defmodule WandererAppWeb.MapEventHandler do
when event_name in @map_kills_events,
do: MapKillsEventHandler.handle_server_event(event, socket)
def handle_event(
%{
assigns: %{
is_subscription_active?: false
}
} = socket,
%{event: event_name} = _event
)
when event_name in @map_kills_events,
do: socket
def handle_event(socket, {ref, result}) when is_reference(ref) do
Process.demonitor(ref, [:flush])

View File

@@ -29,6 +29,15 @@
>
<.icon name="hero-key-solid" class="w-6 h-6" />
</.link>
<.link
:if={(@user_permissions || %{}) |> Map.get(:delete_map, false)}
id={"map-characters-#{@map_slug}"}
class="h-8 w-8 hover:text-white"
navigate={~p"/#{@map_slug}/characters"}
>
<.icon name="hero-user-group-solid" class="w-6 h-6" />
</.link>
</div>
<.modal

View File

@@ -37,7 +37,14 @@ defmodule WandererAppWeb.MapsLive do
@impl true
def mount(_params, _session, socket) do
{:ok, socket |> assign(maps: [], characters: [], location: nil)}
{:ok,
socket
|> assign(
maps: [],
characters: [],
location: nil,
map_subscriptions: []
)}
end
@impl true
@@ -88,99 +95,119 @@ defmodule WandererAppWeb.MapsLive do
end
end
defp apply_action(socket, :edit, %{"slug" => map_slug} = _params, url) do
map =
map_slug
|> WandererApp.Api.Map.get_map_by_slug!()
|> Ash.load!([:owner, :acls])
|> map_map()
defp apply_action(
%{assigns: %{current_user: current_user}} = socket,
:edit,
%{"slug" => map_slug} = _params,
url
) do
WandererApp.Maps.check_user_can_delete_map(map_slug, current_user)
|> case do
{:ok, map} ->
map = map |> map_map()
socket
|> assign(:active_page, :maps)
|> assign(:uri, URI.parse(url) |> Map.put(:path, ~p"/"))
|> assign(:page_title, "Maps - Edit")
|> assign(:scopes, ["wormholes", "stargates", "none", "all"])
|> assign(:map_slug, map_slug)
|> assign(
:characters,
[map.owner |> map_character() | socket.assigns.characters] |> Enum.uniq()
)
|> assign(
:form,
map |> AshPhoenix.Form.for_update(:update, forms: [auto?: true])
)
|> load_access_lists()
socket
|> assign(:active_page, :maps)
|> assign(:uri, URI.parse(url) |> Map.put(:path, ~p"/"))
|> assign(:page_title, "Maps - Edit")
|> assign(:scopes, ["wormholes", "stargates", "none", "all"])
|> assign(:map_slug, map_slug)
|> assign(
:characters,
[map.owner |> map_character() | socket.assigns.characters] |> Enum.uniq()
)
|> assign(
:form,
map |> AshPhoenix.Form.for_update(:update, forms: [auto?: true])
)
|> load_access_lists()
_ ->
socket
|> put_flash(:error, "You don't have an access.")
|> push_navigate(to: ~p"/maps")
end
end
defp apply_action(socket, :settings, %{"slug" => map_slug} = _params, _url) do
map =
map_slug
|> WandererApp.Api.Map.get_map_by_slug!()
|> Ash.load!([:owner, :acls])
defp apply_action(
%{assigns: %{current_user: current_user}} = socket,
:settings,
%{"slug" => map_slug} = _params,
_url
) do
WandererApp.Maps.check_user_can_delete_map(map_slug, current_user)
|> case do
{:ok, map} ->
{:ok, export_settings} =
map
|> WandererApp.Map.Server.get_export_settings()
{:ok, export_settings} =
map
|> WandererApp.Map.Server.get_export_settings()
{:ok, map_balance} = WandererApp.Map.SubscriptionManager.get_balance(map)
{:ok, map_balance} = WandererApp.Map.SubscriptionManager.get_balance(map)
{:ok, map_subscriptions} =
WandererApp.Map.SubscriptionManager.get_map_subscriptions(map.id)
{:ok, map_subscriptions} = WandererApp.Map.SubscriptionManager.get_map_subscriptions(map.id)
subscription_form = %{
"plan" => "omega",
"period" => "1",
"characters_limit" => "100",
"hubs_limit" => "10",
"auto_renew?" => true
}
subscription_form = %{
"plan" => "omega",
"period" => "1",
"characters_limit" => "100",
"hubs_limit" => "10",
"auto_renew?" => true
}
{:ok, options_form_data} = WandererApp.MapRepo.options_to_form_data(map)
{:ok, options_form_data} = WandererApp.MapRepo.options_to_form_data(map)
{:ok, estimated_price, discount} =
WandererApp.Map.SubscriptionManager.estimate_price(subscription_form, false)
{:ok, estimated_price, discount} =
WandererApp.Map.SubscriptionManager.estimate_price(subscription_form, false)
socket
|> assign(:active_page, :maps)
|> assign(:page_title, "Maps - Settings")
|> assign(:map_slug, map_slug)
|> assign(:map_id, map.id)
|> assign(:public_api_key, map.public_api_key)
|> assign(:map, map)
|> assign(
export_settings: export_settings |> _get_export_map_data(),
import_form: to_form(%{}),
importing: false,
show_settings?: true,
is_topping_up?: false,
active_settings_tab: "general",
is_adding_subscription?: false,
selected_subscription: nil,
options_form: options_form_data |> to_form(),
map_subscriptions: map_subscriptions,
subscription_form: subscription_form |> to_form(),
estimated_price: estimated_price,
discount: discount,
map_balance: map_balance,
topup_form: %{} |> to_form(),
subscription_plans: ["omega", "advanced"],
subscription_periods: [
{"1 Month", "1"},
{"3 Months", "3"},
{"6 Months", "6"},
{"1 Year", "12"}
],
layout_options: [
{"Left To Right", "left_to_right"},
{"Top To Bottom", "top_to_bottom"}
]
)
|> allow_upload(:settings,
accept: ~w(.json),
max_entries: 1,
max_file_size: 10_000_000,
auto_upload: true,
progress: &handle_progress/3
)
socket
|> assign(:active_page, :maps)
|> assign(:page_title, "Maps - Settings")
|> assign(:map_slug, map_slug)
|> assign(:map_id, map.id)
|> assign(:public_api_key, map.public_api_key)
|> assign(:map, map)
|> assign(
export_settings: export_settings |> _get_export_map_data(),
import_form: to_form(%{}),
importing: false,
show_settings?: true,
is_topping_up?: false,
active_settings_tab: "general",
is_adding_subscription?: false,
selected_subscription: nil,
options_form: options_form_data |> to_form(),
map_subscriptions: map_subscriptions,
subscription_form: subscription_form |> to_form(),
estimated_price: estimated_price,
discount: discount,
map_balance: map_balance,
topup_form: %{} |> to_form(),
subscription_plans: ["omega", "advanced"],
subscription_periods: [
{"1 Month", "1"},
{"3 Months", "3"},
{"6 Months", "6"},
{"1 Year", "12"}
],
layout_options: [
{"Left To Right", "left_to_right"},
{"Top To Bottom", "top_to_bottom"}
]
)
|> allow_upload(:settings,
accept: ~w(.json),
max_entries: 1,
max_file_size: 10_000_000,
auto_upload: true,
progress: &handle_progress/3
)
_ ->
socket
|> put_flash(:error, "You don't have an access.")
|> push_navigate(to: ~p"/maps")
end
end
defp allow_map_creation(),
@@ -296,11 +323,17 @@ defmodule WandererAppWeb.MapsLive do
|> push_patch(to: ~p"/maps/#{slug}/edit")}
end
def handle_event("open_audit", %{"data" => slug}, socket) do
{:noreply,
socket
|> push_navigate(to: ~p"/#{slug}/audit?period=1H&activity=all")}
end
def handle_event("open_audit", %{"data" => slug}, socket),
do:
{:noreply,
socket
|> push_navigate(to: ~p"/#{slug}/audit?period=1H&activity=all")}
def handle_event("open_characters", %{"data" => slug}, socket),
do:
{:noreply,
socket
|> push_navigate(to: ~p"/#{slug}/characters")}
def handle_event("open_settings", %{"data" => slug}, socket) do
{:noreply,

View File

@@ -7,7 +7,7 @@
class="card h-[250px] rounded-none bg-gradient-to-l from-stone-950 to-stone-900 hover:text-white transform transition duration-500"
patch={~p"/maps/new"}
>
<div class="card-body justify-center items-center ">
<div class="card-body justify-center items-center">
<.icon name="hero-plus-solid" class="w-20 h-20" />
<h3 class="card-title text-center text-md">Create Map</h3>
</div>
@@ -74,6 +74,16 @@
</span>
</h2>
<div class="flex gap-2 justify-end">
<button
:if={WandererApp.Maps.can_edit?(map, @current_user)}
id={"map-characters-#{map.slug}"}
phx-hook="MapAction"
data-event="open_characters"
data-data={map.slug}
class="h-8 w-8 hover:text-white"
>
<.icon name="hero-user-group-solid" class="w-6 h-6" />
</button>
<button
:if={WandererApp.Maps.can_edit?(map, @current_user)}
id={"map-audit-#{map.slug}"}
@@ -125,6 +135,7 @@
<% end %>
</main>
</div>
<.modal
:if={@is_connected? && @live_action in [:create, :edit]}
title={"#{(@live_action == :create && "Create") || "Edit"} Map"}
@@ -185,7 +196,7 @@
</.modal>
<.modal
:if={@live_action in [:settings]}
:if={@live_action in [:settings] && not is_nil(assigns[:map])}
title="Map Settings"
class="!min-w-[700px]"
id="map-settings-modal"
@@ -194,7 +205,7 @@
>
<div class="flex flex-col gap-3">
<div class="flex flex-col gap-2">
<div class="_verticalTabsContainer_1o01l_2">
<div class="verticalTabsContainer">
<div class="p-tabview p-component" data-pc-name="tabview" data-pc-section="root">
<div class="p-tabview-nav-container" data-pc-section="navcontainer">
<div class="p-tabview-nav-content" data-pc-section="navcontent">
@@ -306,14 +317,6 @@
</span>
</a>
</li>
<li
aria-hidden="true"
role="presentation"
class="p-tabview-ink-bar"
data-pc-section="inkbar"
style="width: 146px; left: 0px;"
>
</li>
<li
:if={not WandererApp.Env.public_api_disabled?()}
class={[
@@ -447,29 +450,28 @@
/>
</div>
<div class="flex items-center gap-2">
<.button class="btn btn-primary rounded-md" phx-click="generate-map-api-key">
Generate
<.button
type="button"
phx-click="generate-map-api-key"
class="p-button p-component p-button-primary"
style="min-width: 120px;"
>
<span class="p-button-label">Generate</span>
</.button>
<.button
type="button"
phx-hook="CopyToClipboard"
id="copy-map-api-key"
data-url={@public_api_key}
disabled={is_nil(@public_api_key)}
class={
if is_nil(@public_api_key) do
"copy-link btn rounded-md transition-colors duration-300
bg-gray-500 hover:bg-gray-500 text-gray-300 cursor-not-allowed"
else
"copy-link btn rounded-md transition-colors duration-300
bg-blue-600 hover:bg-blue-700 text-white cursor-pointer"
end
}
class={"p-button p-component " <> if(is_nil(@public_api_key), do: "p-disabled", else: "")}
>
Copy
<span class="p-button-label">Copy</span>
</.button>
</div>
</div>
</div>
<div :if={@active_settings_tab == "balance"}>
<div class="stats w-full bg-primary text-primary-content">
<div class="stat">

View File

@@ -4,6 +4,7 @@ defmodule WandererAppWeb.Router do
use Plug.ErrorHandler
import PlugDynamic.Builder
import Logger
import WandererAppWeb.UserAuth,
warn: false,
@@ -118,6 +119,14 @@ defmodule WandererAppWeb.Router do
plug WandererAppWeb.Plugs.CheckApiDisabled
end
pipeline :api_character do
plug WandererAppWeb.Plugs.CheckCharacterApiDisabled
end
pipeline :api_acl do
plug WandererAppWeb.Plugs.CheckAclApiKey
end
scope "/api/map/systems-kills", WandererAppWeb do
pipe_through [:api, :api_map, :api_kills]
@@ -126,66 +135,76 @@ defmodule WandererAppWeb.Router do
scope "/api/map", WandererAppWeb do
pipe_through [:api, :api_map]
# GET /api/map/systems?map_id=... or ?slug=...
get "/systems", MapAPIController, :list_systems
# GET /api/map/system?id=... plus either map_id=... or slug=...
get "/system", MapAPIController, :show_system
# GET /api/map/characters?map_id=... or slug=...
get "/characters", MapAPIController, :tracked_characters_with_info
# GET /api/map/structure-timers?map_id=... or slug=... and optionally ?system_id=...
get "/structure-timers", MapAPIController, :show_structure_timers
get "/acls", MapAccessListAPIController, :index
post "/acls", MapAccessListAPIController, :create
end
scope "/api/characters", WandererAppWeb do
pipe_through [:api, :api_character]
get "/", CharactersAPIController, :index
end
scope "/api/acls", WandererAppWeb do
pipe_through [:api, :api_acl]
get "/:id", MapAccessListAPIController, :show
put "/:id", MapAccessListAPIController, :update
post "/:acl_id/members", AccessListMemberAPIController, :create
put "/:acl_id/members/:member_id", AccessListMemberAPIController, :update_role
delete "/:acl_id/members/:member_id", AccessListMemberAPIController, :delete
end
scope "/api/common", WandererAppWeb do
pipe_through [:api]
# GET /api/common/system-static-info?id=...
get "/system-static-info", CommonAPIController, :show_system_static
end
#
# Browser / blog stuff
#
scope "/", WandererAppWeb do
pipe_through [:browser, :blog, :redirect_if_user_is_authenticated]
get "/welcome", BlogController, :index
end
scope "/contacts", WandererAppWeb do
pipe_through [:browser, :blog]
get "/", BlogController, :contacts
end
scope "/changelog", WandererAppWeb do
pipe_through [:browser, :blog]
get "/", BlogController, :changelog
end
scope "/news", WandererAppWeb do
pipe_through [:browser, :blog]
get "/:slug", BlogController, :show
get "/", BlogController, :list
end
scope "/license", WandererAppWeb do
pipe_through [:browser, :blog]
get "/", BlogController, :license
end
#
# Auth
#
scope "/auth", WandererAppWeb do
pipe_through :browser
get "/signout", AuthController, :signout
get "/:provider", AuthController, :request
get "/:provider/callback", AuthController, :callback
end
#
# Admin
#
scope "/admin", WandererAppWeb do
pipe_through(:browser)
pipe_through(:admin_bauth)
@@ -207,53 +226,50 @@ defmodule WandererAppWeb.Router do
)
end
#
# Additional routes / Live sessions
#
scope "/", WandererAppWeb do
pipe_through(:browser)
get "/", RedirectController, :redirect_authenticated
get("/last", MapsController, :last)
get "/last", MapsController, :last
live_session :authenticated,
on_mount: [
{WandererAppWeb.UserAuth, :ensure_authenticated},
WandererAppWeb.Nav
] do
live("/access-lists/new", AccessListsLive, :create)
live("/access-lists/:id/edit", AccessListsLive, :edit)
live("/access-lists/:id/add-members", AccessListsLive, :add_members)
live("/access-lists/:id", AccessListsLive, :members)
live("/access-lists", AccessListsLive, :index)
live("/coming-soon", ComingLive, :index)
live("/tracking/:slug", CharactersTrackingLive, :characters)
live("/tracking", CharactersTrackingLive, :index)
live("/characters", CharactersLive, :index)
live("/characters/authorize", CharactersLive, :authorize)
live("/maps/new", MapsLive, :create)
live("/maps/:slug/edit", MapsLive, :edit)
live("/maps/:slug/settings", MapsLive, :settings)
live("/maps", MapsLive, :index)
live("/profile", ProfileLive, :index)
live("/profile/deposit", ProfileLive, :deposit)
live("/profile/subscribe", ProfileLive, :subscribe)
live("/:slug/audit", MapAuditLive, :index)
live("/:slug", MapLive, :index)
live "/access-lists/new", AccessListsLive, :create
live "/access-lists/:id/edit", AccessListsLive, :edit
live "/access-lists/:id/add-members", AccessListsLive, :add_members
live "/access-lists/:id", AccessListsLive, :members
live "/access-lists", AccessListsLive, :index
live "/coming-soon", ComingLive, :index
live "/tracking/:slug", CharactersTrackingLive, :characters
live "/tracking", CharactersTrackingLive, :index
live "/characters", CharactersLive, :index
live "/characters/authorize", CharactersLive, :authorize
live "/maps/new", MapsLive, :create
live "/maps/:slug/edit", MapsLive, :edit
live "/maps/:slug/settings", MapsLive, :settings
live "/maps", MapsLive, :index
live "/profile", ProfileLive, :index
live "/profile/deposit", ProfileLive, :deposit
live "/profile/subscribe", ProfileLive, :subscribe
live "/:slug/audit", MapAuditLive, :index
live "/:slug/characters", MapCharactersLive, :index
live "/:slug", MapLive, :index
end
end
# Enable LiveDashboard and Swoosh mailbox preview in development
if Application.compile_env(:wanderer_app, :dev_routes) do
# If you want to use the LiveDashboard in production, you should put
# it behind authentication and allow only admins to access it.
# If your application does not have an admins-only section yet,
# you can use Plug.BasicAuth to set up some basic authentication
# as long as you are also using SSL (which you should anyway).
import Phoenix.LiveDashboard.Router
scope "/dev" do
pipe_through(:browser)
error_tracker_dashboard("/errors", as: :error_tracker_dev_dashboard)
live_dashboard("/dashboard", metrics: WandererAppWeb.Telemetry)
end
end

View File

@@ -3,7 +3,7 @@ defmodule WandererApp.MixProject do
@source_url "https://github.com/wanderer-industries/wanderer"
@version "1.47.6"
@version "1.52.0"
def project do
[

View File

@@ -0,0 +1,425 @@
%{
title: "User Guide: Characters & ACL API Endpoints",
author: "Wanderer Team",
cover_image_uri: "/images/news/02-20-acl-api/generate-key.png",
tags: ~w(acl characters guide interface),
description: "Learn how to retrieve and manage Access Lists and Characters through the Wanderer public APIs. This guide covers available endpoints, request examples, and sample responses."
}
---
## Introduction
Wanderers expanded public API now lets you retrieve **all characters** in the system and manage “Access Lists” (ACLs) for controlling visibility or permissions. These endpoints allow you to:
- Fetch a list of **all** EVE characters known to the system.
- List ACLs for a given map.
- Create new ACLs for maps (with automatic API key generation).
- Update existing ACLs.
- Add, remove, and change the roles of ACL members.
This guide provides step-by-step instructions, request/response examples, and details on how to authenticate each call.
---
## Authentication
Unless otherwise noted, these endpoints require a valid **Bearer** token. Pass it in the `Authorization` header:
```bash
Authorization: Bearer <REDACTED_TOKEN>
```
If the token is missing or invalid, youll receive a `401 Unauthorized` error.
_(No API key is required for some “common” endpoints, but ACL- and character-related endpoints require a valid token.)_
There are two types of tokens in use:
1. **Map API Token:** Available in the map settings. This token is used for map-specific endpoints (e.g. listing ACLs for a map and creating ACLs).
![Generate Map API Key](/images/news/01-05-map-public-api/generate-key.png "Generate Map API Key")
2. **ACL API Token:** Available in the create/edit ACL screen. This token is used for ACL member management endpoints.
![Generate ACL API Key](/images/news/02-20-acl-api/generate-key.png "Generate ACL API Key")
---
## Endpoints Overview
### 1. List **All** Characters
```bash
GET /api/characters
```
- **Description:** Returns a list of **all** characters known to Wanderer.
- **Toggle:** Controlled by the environment variable `WANDERER_CHARACTER_API_DISABLED` (default is `false`).
- **Example Request:**
```bash
curl -H "Authorization: Bearer <REDACTED_TOKEN>" \
"https://wanderer.example.com/api/characters"
```
- **Example Response (redacted):**
```json
{
"data": [
{
"id": "b374d9e6-47a7-4e20-85ad-d608809827b5",
"name": "Some Character",
"eve_id": "2122825111",
"corporation_name": "School of Applied Knowledge",
"alliance_name": null
},
{
"id": "6963bee6-eaa1-40e2-8200-4bc2fcbd7350",
"name": "Other Character",
"eve_id": "2122019111",
"corporation_name": "Some Corporation",
"alliance_name": null
}
...
]
}
```
Use the `eve_id` when referencing a character in ACL operations.
---
### 2. List ACLs for a Given Map
```bash
GET /api/map/acls?map_id=<UUID>
GET /api/map/acls?slug=<map-slug>
```
- **Description:** Lists all ACLs associated with a map, specified by either `map_id` (UUID) or `slug` (map slug).
- **Authentication:** Requires the Map API Token (available in map settings).
- **Example Request (using slug):**
```bash
curl -H "Authorization: Bearer <REDACTED_TOKEN>" \
"https://wanderer.example.com/api/map/acls?slug=mapname"
```
- **Example Response (redacted):**
```json
{
"data": [
{
"id": "19712899-ec3a-47b1-b73b-2bae221c5513",
"name": "aclName",
"description": null,
"owner_eve_id": "11111111111",
"inserted_at": "2025-02-13T03:32:25.144403Z",
"updated_at": "2025-02-13T03:32:25.144403Z"
}
]
}
```
---
### 3. Show a Specific ACL (Including Members)
```bash
GET /api/acls/:id
```
- **Description:** Fetches a single ACL by ID, with its members preloaded.
- **Authentication:** Requires the ACL API Token.
- **Example Request:**
```bash
curl -H "Authorization: Bearer <REDACTED_TOKEN>" \
"https://wanderer.example.com/api/acls/19712899-ec3a-47b1-b73b-2bae221c5513"
```
- **Example Response (redacted):**
```json
{
"data": {
"id": "19712899-ec3a-47b1-b73b-2bae221c5513",
"name": "aclName",
"description": null,
"owner_id": "d43a9083-2705-40c9-a314-f7f412346661",
"members": [
{
"id": "8d63ab1e-b44f-4e81-8227-8fb8d928dad8",
"name": "Other Character",
"role": "admin",
"inserted_at": "2025-02-13T03:33:32.332598Z",
"updated_at": "2025-02-13T03:33:36.644520Z"
},
...
]
}
}
```
---
### 4. Create a New ACL Associated with a Map
```bash
POST /api/map/acls
```
- **Description:** Creates a new ACL for a map and generates a new ACL API key. The map record tracks its ACLs.
- **Required Query Parameter:** Either `map_id` (UUID) or `slug` (map slug).
- **Request Body Example:**
```json
{
"acl": {
"name": "New ACL",
"description": "Optional description",
"owner_eve_id": "EXTERNAL_EVE_ID"
}
}
```
- `owner_eve_id` must be the external EVE id (the `eve_id` from `/api/characters`).
- **Example Request (using map slug):**
```bash
curl -X POST \
-H "Authorization: Bearer <MAP_API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"acl": {
"name": "New ACL",
"description": "Optional description",
"owner_eve_id": "EXTERNAL_EVE_ID"
}
}' \
"https://wanderer.example.com/api/map/acls?slug=mapname"
```
- **Example Request (using map UUID):**
```bash
curl -X POST \
-H "Authorization: Bearer <MAP_API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"acl": {
"name": "New ACL",
"description": "Optional description",
"owner_eve_id": "EXTERNAL_EVE_ID"
}
}' \
"https://wanderer.example.com/api/map/acls?map_id=YOUR_MAP_UUID"
```
- **Example Response (redacted):**
```json
{
"data": {
"id": "NEW_ACL_UUID",
"name": "New ACL",
"description": "Optional description",
"owner_id": "OWNER_ID",
"api_key": "GENERATED_ACL_API_KEY",
"inserted_at": "2025-02-14T17:00:00Z",
"updated_at": "2025-02-14T17:00:00Z",
"members": []
}
}
```
---
### 5. Update an ACL
```bash
PUT /api/acls/:id
```
- **Description:** Updates an existing ACL (e.g. name, description, api_key).
The update endpoint fetches the ACL record first and then applies the update.
- **Authentication:** Requires the ACL API Token.
- **Example Request:**
```bash
curl -X PUT \
-H "Authorization: Bearer <ACL_API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"acl": {
"name": "Updated ACL Name",
"description": "This is the updated description",
"api_key": "EXISTING_ACL_API_KEY"
}
}' \
"https://wanderer.example.com/api/acls/ACL_UUID"
```
- **Example Response (redacted):**
```json
{
"data": {
"id": "ACL_UUID",
"name": "Updated ACL Name",
"description": "This is the updated description",
"owner_id": "OWNER_ID",
"api_key": "EXISTING_ACL_API_KEY",
"inserted_at": "2025-02-14T16:49:13.423556Z",
"updated_at": "2025-02-14T17:22:51.343784Z",
"members": []
}
}
```
---
### 6. Add a Member to an ACL
```bash
POST /api/acls/:acl_id/members
```
- **Description:** Adds a new member (character, corporation, or alliance) to the specified ACL.
- **Authentication:** Requires the ACL API Token.
- **Request Body Example:**
For **character** membership, use `eve_character_id`. For **corporation**, use `eve_corporation_id`. For **alliance**, use `eve_alliance_id`.
```json
{
"member": {
"name": "New Member",
"eve_character_id": "EXTERNAL_EVE_ID",
"role": "viewer"
}
}
```
- **Example Request:**
```bash
curl -X POST \
-H "Authorization: Bearer <ACL_API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"member": {
"name": "New Member",
"eve_character_id": "EXTERNAL_EVE_ID",
"role": "viewer"
}
}' \
"https://wanderer.example.com/api/acls/ACL_UUID/members"
```
- **Example Response (redacted):**
```json
{
"data": {
"id": "MEMBERSHIP_UUID",
"name": "New Member",
"role": "viewer",
"inserted_at": "...",
"updated_at": "..."
}
}
```
---
### 7. Change a Members Role
```bash
PUT /api/acls/:acl_id/members/:member_id
```
- **Description:** Updates an ACL members role (e.g. from `viewer` to `admin`).
The `:member_id` is the external EVE id (or corp/alliance id) used when creating the membership.
- **Authentication:** Requires the ACL API Token.
- **Request Body Example:**
```json
{
"member": {
"role": "admin"
}
}
```
- **Example Request:**
```bash
curl -X PUT \
-H "Authorization: Bearer <ACL_API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"member": {
"role": "admin"
}
}' \
"https://wanderer.example.com/api/acls/ACL_UUID/members/EXTERNAL_EVE_ID"
```
- **Example Response (redacted):**
```json
{
"data": {
"id": "MEMBERSHIP_UUID",
"name": "New Member",
"role": "admin",
...
}
}
```
---
### 8. Remove a Member from an ACL
```bash
DELETE /api/acls/:acl_id/members/:member_id
```
- **Description:** Removes the member with the specified external EVE id (or corp/alliance id) from the ACL.
- **Authentication:** Requires the ACL API Token.
- **Example Request:**
```bash
curl -X DELETE \
-H "Authorization: Bearer <ACL_API_TOKEN>" \
"https://wanderer.example.com/api/acls/ACL_UUID/members/EXTERNAL_EVE_ID"
```
- **Example Response:**
```json
{ "ok": true }
```
---
## Conclusion
This guide outlines how to:
1. **List** all characters (`GET /api/characters`) so you can pick a valid character to add to your ACL.
2. **List** ACLs for a specified map (`GET /api/map/acls?map_id=<UUID>` or `?slug=<map-slug>`).
3. **Show** ACL details, including its members (`GET /api/acls/:id`).
4. **Create** a new ACL for a map (`POST /api/map/acls`), which generates a new ACL API key.
5. **Update** an existing ACL (`PUT /api/acls/:id`).
6. **Add** members (characters, corporations, alliances) to an ACL (`POST /api/acls/:acl_id/members`).
7. **Change** a members role (`PUT /api/acls/:acl_id/members/:member_id`).
8. **Remove** a member from an ACL (`DELETE /api/acls/:acl_id/members/:member_id`).
By following these request patterns, you can manage your ACL resources in a fully programmatic fashion. If you have any questions, feel free to reach out to the Wanderer Team.
Fly safe,
**WANDERER TEAM**

View File

@@ -0,0 +1,21 @@
defmodule WandererApp.Repo.Migrations.AddAclApiKey do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_postgres.generate_migrations`
"""
use Ecto.Migration
def up do
alter table(:access_lists_v1) do
add :api_key, :text
end
end
def down do
alter table(:access_lists_v1) do
remove :api_key
end
end
end

View File

@@ -0,0 +1,108 @@
{
"attributes": [
{
"allow_nil?": false,
"default": "fragment(\"gen_random_uuid()\")",
"generated?": false,
"primary_key?": true,
"references": null,
"size": null,
"source": "id",
"type": "uuid"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "name",
"type": "text"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "description",
"type": "text"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "api_key",
"type": "text"
},
{
"allow_nil?": false,
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "inserted_at",
"type": "utc_datetime_usec"
},
{
"allow_nil?": false,
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "updated_at",
"type": "utc_datetime_usec"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": {
"deferrable": false,
"destination_attribute": "id",
"destination_attribute_default": null,
"destination_attribute_generated": null,
"index?": false,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "access_lists_v1_owner_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "character_v1"
},
"size": null,
"source": "owner_id",
"type": "uuid"
}
],
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "5118AF0DEBEEED63DC30565ECFFEDF682876FAD476AF2796E973C6883E4054E0",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.WandererApp.Repo",
"schema": null,
"table": "access_lists_v1"
}

198
test/manual/test_api_calls.sh Executable file
View File

@@ -0,0 +1,198 @@
#!/usr/bin/env bash
#
# Example script to test your Map & ACL endpoints using curl.
# Requires `jq` to parse JSON responses.
# If any command fails, this script will exit immediately
set -e
#############################################
# Environment Variables (must be set before)
#############################################
: "${BASE_URL:?Need to set BASE_URL, e.g. http://localhost:4444}"
: "${MAP_TOKEN:?Need to set MAP_TOKEN (Bearer token for map requests)}"
: "${MAP_SLUG:?Need to set MAP_SLUG (slug for the map to test)}"
: "${EVE_CHARACTER_ID:?Need to set EVE_CHARACTER_ID (e.g. from /api/characters)}"
echo "Using BASE_URL = $BASE_URL"
echo "Using MAP_TOKEN = $MAP_TOKEN"
echo "Using MAP_SLUG = $MAP_SLUG"
echo "Using EVE_CHARACTER_ID = $EVE_CHARACTER_ID"
echo "-------------------------------------"
#############################################
# 1) Get list of characters (just to confirm they exist)
#############################################
echo
echo "=== 1) Get All Characters (for reference) ==="
curl -s "$BASE_URL/api/characters" | jq
#############################################
# 2) Get ACLs for the given map slug
#############################################
echo
echo "=== 2) List ACLs for Map Slug '$MAP_SLUG' ==="
ACL_LIST_JSON=$(curl -s -H "Authorization: Bearer $MAP_TOKEN" \
"$BASE_URL/api/map/acls?slug=$MAP_SLUG")
echo "$ACL_LIST_JSON" | jq
# Attempt to parse out the first ACL ID and token from the JSON data array:
FIRST_ACL_ID=$(echo "$ACL_LIST_JSON" | jq -r '.data[0].id // empty')
FIRST_ACL_TOKEN=$(echo "$ACL_LIST_JSON" | jq -r '.data[0].api_key // empty')
#############################################
# 3) Decide whether to use an existing ACL or create a new one
#############################################
if [ -z "$FIRST_ACL_ID" ] || [ "$FIRST_ACL_ID" = "null" ]; then
echo "No existing ACL found for map slug: $MAP_SLUG."
USE_EXISTING_ACL=false
else
# We found at least one ACL. But does it have a token?
if [ -z "$FIRST_ACL_TOKEN" ] || [ "$FIRST_ACL_TOKEN" = "null" ]; then
echo "Found an ACL with ID $FIRST_ACL_ID but no api_key in the response."
echo "We cannot do membership actions on it without a token."
USE_EXISTING_ACL=false
else
echo "Parsed ACL_ID from existing ACL: $FIRST_ACL_ID"
echo "Parsed ACL_TOKEN from existing ACL: $FIRST_ACL_TOKEN"
USE_EXISTING_ACL=true
fi
fi
#############################################
# 4) If we cannot use an existing ACL, create a new one
#############################################
if [ "$USE_EXISTING_ACL" = false ]; then
echo
echo "=== Creating a new ACL for membership testing ==="
NEW_ACL_RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer $MAP_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"acl": {
"name": "Auto-Created ACL",
"description": "Created because none with a token was found",
"owner_eve_id": "'"$EVE_CHARACTER_ID"'"
}
}' \
"$BASE_URL/api/map/acls?slug=$MAP_SLUG")
echo "New ACL creation response:"
echo "$NEW_ACL_RESPONSE" | jq
ACL_ID=$(echo "$NEW_ACL_RESPONSE" | jq -r '.data.id // empty')
ACL_TOKEN=$(echo "$NEW_ACL_RESPONSE" | jq -r '.data.api_key // empty')
if [ -z "$ACL_ID" ] || [ "$ACL_ID" = "null" ] || \
[ -z "$ACL_TOKEN" ] || [ "$ACL_TOKEN" = "null" ]; then
echo "Failed to create an ACL with a valid token. Exiting..."
exit 1
fi
echo "Newly created ACL_ID: $ACL_ID"
echo "Newly created ACL_TOKEN: $ACL_TOKEN"
else
# Use the existing ACL's details
ACL_ID="$FIRST_ACL_ID"
ACL_TOKEN="$FIRST_ACL_TOKEN"
fi
#############################################
# 5) Show the details of that ACL
#############################################
echo
echo "=== 5) Show ACL Details ==="
ACL_DETAILS=$(curl -s \
-H "Authorization: Bearer $ACL_TOKEN" \
"$BASE_URL/api/acls/$ACL_ID")
echo "$ACL_DETAILS" | jq || {
echo "ACL details response is not valid JSON. Raw response:"
echo "$ACL_DETAILS"
exit 1
}
#############################################
# 6) Create a new ACL member (viewer)
#############################################
echo
echo "=== 6) Create a New ACL Member (viewer) ==="
CREATE_MEMBER_RESP=$(curl -s -X POST \
-H "Authorization: Bearer $ACL_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"member": {
"eve_character_id": "'"$EVE_CHARACTER_ID"'",
"role": "viewer"
}
}' \
"$BASE_URL/api/acls/$ACL_ID/members")
echo "$CREATE_MEMBER_RESP" | jq || {
echo "Create member response is not valid JSON. Raw response:"
echo "$CREATE_MEMBER_RESP"
exit 1
}
#############################################
# 7) Update the member's role (e.g., admin)
#############################################
echo
echo "=== 7) Update Member Role to 'admin' ==="
UPDATE_MEMBER_RESP=$(curl -s -X PUT \
-H "Authorization: Bearer $ACL_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"member": {
"role": "admin"
}
}' \
"$BASE_URL/api/acls/$ACL_ID/members/$EVE_CHARACTER_ID")
echo "$UPDATE_MEMBER_RESP" | jq || {
echo "Update member response is not valid JSON. Raw response:"
echo "$UPDATE_MEMBER_RESP"
exit 1
}
#############################################
# 8) Delete the member
#############################################
echo
echo "=== 8) Delete the Member ==="
DELETE_MEMBER_RESP=$(curl -s -X DELETE \
-H "Authorization: Bearer $ACL_TOKEN" \
"$BASE_URL/api/acls/$ACL_ID/members/$EVE_CHARACTER_ID")
echo "$DELETE_MEMBER_RESP" | jq || {
echo "Delete member response is not valid JSON. Raw response:"
echo "$DELETE_MEMBER_RESP"
exit 1
}
#############################################
# 9) (Optional) Update the ACL itself
#############################################
echo
echo "=== 9) Update the ACLs name/description ==="
UPDATED_ACL=$(curl -s -X PUT \
-H "Authorization: Bearer $ACL_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"acl": {
"name": "Updated ACL Name (script)",
"description": "An updated description from test script"
}
}' \
"$BASE_URL/api/acls/$ACL_ID")
echo "$UPDATED_ACL" | jq || {
echo "Update ACL response is not valid JSON. Raw response:"
echo "$UPDATED_ACL"
exit 1
}
echo
echo "=== Done! ==="