mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-03 06:22:48 +00:00
Compare commits
2 Commits
v1.51.3
...
design-and
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba5b2fb8d9 | ||
|
|
deb47b66f6 |
@@ -1,12 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "wanderer-dev",
|
"name": "wanderer-dev",
|
||||||
"dockerComposeFile": ["./docker-compose.yml"],
|
"dockerComposeFile": ["./docker-compose.yml"],
|
||||||
"extensions": [
|
"extensions": ["jakebecker.elixir-ls"],
|
||||||
"jakebecker.elixir-ls",
|
|
||||||
"JakeBecker.elixir-ls",
|
|
||||||
"dbaeumer.vscode-eslint",
|
|
||||||
"esbenp.prettier-vscode"
|
|
||||||
],
|
|
||||||
"service": "wanderer",
|
"service": "wanderer",
|
||||||
"workspaceFolder": "/app",
|
"workspaceFolder": "/app",
|
||||||
"shutdownAction": "stopCompose",
|
"shutdownAction": "stopCompose",
|
||||||
|
|||||||
@@ -7,5 +7,4 @@ export EVE_CLIENT_WITH_WALLET_SECRET="<EVE_CLIENT_WITH_WALLET_SECRET>"
|
|||||||
export GIT_SHA="1111"
|
export GIT_SHA="1111"
|
||||||
export WANDERER_INVITES="false"
|
export WANDERER_INVITES="false"
|
||||||
export WANDERER_PUBLIC_API_DISABLED="false"
|
export WANDERER_PUBLIC_API_DISABLED="false"
|
||||||
export WANDERER_CHARACTER_API_DISABLED="false"
|
|
||||||
export WANDERER_ZKILL_PRELOAD_DISABLED="false"
|
export WANDERER_ZKILL_PRELOAD_DISABLED="false"
|
||||||
|
|||||||
23
.github/workflows/build.yml
vendored
23
.github/workflows/build.yml
vendored
@@ -1,6 +1,8 @@
|
|||||||
name: Build
|
name: Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened, labeled, unlabeled]
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
@@ -39,28 +41,8 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
|
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
|
||||||
|
|
||||||
manual-approval:
|
|
||||||
name: Manual Approval
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: deploy-test
|
|
||||||
if: success()
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
issues: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Await Manual Approval
|
|
||||||
uses: trstringer/manual-approval@v1
|
|
||||||
with:
|
|
||||||
secret: ${{ github.TOKEN }}
|
|
||||||
approvers: DmitryPopov
|
|
||||||
minimum-approvals: 1
|
|
||||||
issue-title: "Manual Approval Required for Release"
|
|
||||||
issue-body: "Please approve or deny the deployment."
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: 🛠 Build
|
name: 🛠 Build
|
||||||
needs: manual-approval
|
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
if: ${{ (github.ref == 'refs/heads/main') && github.event_name == 'push' }}
|
if: ${{ (github.ref == 'refs/heads/main') && github.event_name == 'push' }}
|
||||||
permissions:
|
permissions:
|
||||||
@@ -158,6 +140,7 @@ jobs:
|
|||||||
platform:
|
platform:
|
||||||
- linux/amd64
|
- linux/amd64
|
||||||
- linux/arm64
|
- linux/arm64
|
||||||
|
- linux/arm64/v8
|
||||||
steps:
|
steps:
|
||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
132
CHANGELOG.md
132
CHANGELOG.md
@@ -2,138 +2,6 @@
|
|||||||
|
|
||||||
<!-- changelog -->
|
<!-- changelog -->
|
||||||
|
|
||||||
## [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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [v1.47.5](https://github.com/wanderer-industries/wanderer/compare/v1.47.4...v1.47.5) (2025-02-12)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes:
|
|
||||||
|
|
||||||
* sync kills count bookmark and the kills widget (#160)
|
|
||||||
|
|
||||||
* lazy load kills widget
|
|
||||||
|
|
||||||
## [v1.47.4](https://github.com/wanderer-industries/wanderer/compare/v1.47.3...v1.47.4) (2025-02-11)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [v1.47.3](https://github.com/wanderer-industries/wanderer/compare/v1.47.2...v1.47.3) (2025-02-11)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [v1.47.2](https://github.com/wanderer-industries/wanderer/compare/v1.47.1...v1.47.2) (2025-02-11)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes:
|
|
||||||
|
|
||||||
* lazy load kills widget (#157)
|
|
||||||
|
|
||||||
* lazy load kills widget
|
|
||||||
|
|
||||||
* updates for eslint and pr feedback
|
|
||||||
|
|
||||||
## [v1.47.1](https://github.com/wanderer-industries/wanderer/compare/v1.47.0...v1.47.1) (2025-02-09)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes:
|
|
||||||
|
|
||||||
* Connections: Fixed connections auto-refresh after update
|
|
||||||
|
|
||||||
## [v1.47.0](https://github.com/wanderer-industries/wanderer/compare/v1.46.1...v1.47.0) (2025-02-09)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Features:
|
|
||||||
|
|
||||||
* Map: Added check for active map subscription to using Map APIs
|
|
||||||
|
|
||||||
## [v1.46.1](https://github.com/wanderer-industries/wanderer/compare/v1.46.0...v1.46.1) (2025-02-09)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes:
|
|
||||||
|
|
||||||
* Map: Fixed a lot of design and architect issues after last milli⦠(#154)
|
|
||||||
|
|
||||||
* Map: Fixed a lot of design and architect issues after last million PRs
|
|
||||||
|
|
||||||
* Map: removed unnecessary hooks styles
|
|
||||||
|
|
||||||
## [v1.46.0](https://github.com/wanderer-industries/wanderer/compare/v1.45.5...v1.46.0) (2025-02-08)
|
## [v1.46.0](https://github.com/wanderer-industries/wanderer/compare/v1.45.5...v1.46.0) (2025-02-08)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -936,66 +936,3 @@ body > div:first-of-type {
|
|||||||
width: 16px;
|
width: 16px;
|
||||||
height: 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;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ interface MapCompProps {
|
|||||||
onCommand: OutCommandHandler;
|
onCommand: OutCommandHandler;
|
||||||
onSelectionChange: OnMapSelectionChange;
|
onSelectionChange: OnMapSelectionChange;
|
||||||
onManualDelete(systems: string[]): void;
|
onManualDelete(systems: string[]): void;
|
||||||
|
canRemoveConnection?(connectionId: string): boolean;
|
||||||
onConnectionInfoClick?(e: SolarSystemConnection): void;
|
onConnectionInfoClick?(e: SolarSystemConnection): void;
|
||||||
onAddSystem?: OnMapAddSystemCallback;
|
onAddSystem?: OnMapAddSystemCallback;
|
||||||
onSelectionContextMenu?: NodeSelectionMouseHandler;
|
onSelectionContextMenu?: NodeSelectionMouseHandler;
|
||||||
@@ -113,8 +114,9 @@ const MapComp = ({
|
|||||||
isSoftBackground,
|
isSoftBackground,
|
||||||
theme,
|
theme,
|
||||||
onAddSystem,
|
onAddSystem,
|
||||||
|
canRemoveConnection,
|
||||||
}: MapCompProps) => {
|
}: MapCompProps) => {
|
||||||
const { getNode, getNodes } = useReactFlow();
|
const { getEdge, getNode, getNodes } = useReactFlow();
|
||||||
const [nodes, , onNodesChange] = useNodesState<Node<SolarSystemRawType>>(initialNodes);
|
const [nodes, , onNodesChange] = useNodesState<Node<SolarSystemRawType>>(initialNodes);
|
||||||
const [edges, , onEdgesChange] = useEdgesState<Edge<SolarSystemConnection>>(initialEdges);
|
const [edges, , onEdgesChange] = useEdgesState<Edge<SolarSystemConnection>>(initialEdges);
|
||||||
|
|
||||||
@@ -222,6 +224,40 @@ const MapComp = ({
|
|||||||
[getNode, getNodes, onManualDelete, onNodesChange],
|
[getNode, getNodes, onManualDelete, onNodesChange],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleEdgesChange = useCallback(
|
||||||
|
(changes: EdgeChange[]) => {
|
||||||
|
const nextChanges = changes.reduce((acc, change) => {
|
||||||
|
if (change.type !== 'remove') {
|
||||||
|
return [...acc, change];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canRemoveConnection?.(change.id)) {
|
||||||
|
return [...acc, change];
|
||||||
|
}
|
||||||
|
|
||||||
|
const edge = getEdge(change.id);
|
||||||
|
if (!edge) {
|
||||||
|
return [...acc, change];
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceNode = getNode(edge.source);
|
||||||
|
const targetNode = getNode(edge.target);
|
||||||
|
if (!sourceNode || !targetNode) {
|
||||||
|
return [...acc, change];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceNode.data.locked || targetNode.data.locked) {
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...acc, change];
|
||||||
|
}, [] as EdgeChange[]);
|
||||||
|
|
||||||
|
onEdgesChange(nextChanges);
|
||||||
|
},
|
||||||
|
[canRemoveConnection, getEdge, getNode, onEdgesChange],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
update(x => ({
|
update(x => ({
|
||||||
...x,
|
...x,
|
||||||
@@ -237,7 +273,7 @@ const MapComp = ({
|
|||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
edges={edges}
|
edges={edges}
|
||||||
onNodesChange={handleNodesChange}
|
onNodesChange={handleNodesChange}
|
||||||
onEdgesChange={onEdgesChange}
|
onEdgesChange={handleEdgesChange}
|
||||||
onConnect={onConnect}
|
onConnect={onConnect}
|
||||||
// TODO we need save into session all of this
|
// TODO we need save into session all of this
|
||||||
// and on any action do either
|
// and on any action do either
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { SystemKillsContent } from '../../../mapInterface/widgets/SystemKills/SystemKillsContent/SystemKillsContent';
|
import { SystemKillsContent } from '../../../mapInterface/widgets/SystemKills/SystemKillsContent/SystemKillsContent';
|
||||||
import { useKillsCounter } from '../../hooks/useKillsCounter';
|
import { useKillsCounter } from '../../hooks/useKillsCounter';
|
||||||
import { WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit/WdTooltipWrapper';
|
import { WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit/WdTooltipWrapper';
|
||||||
import { WithChildren, WithClassName } from '@/hooks/Mapper/types/common';
|
import { WithChildren, WithClassName } from '@/hooks/Mapper/types/common.ts';
|
||||||
|
|
||||||
type TooltipSize = 'xs' | 'sm' | 'md' | 'lg';
|
type TooltipSize = 'xs' | 'sm' | 'md' | 'lg';
|
||||||
|
|
||||||
@@ -20,18 +20,11 @@ export const KillsCounter = ({ killsCount, systemId, className, children, size =
|
|||||||
if (!killsCount || detailedKills.length === 0 || !systemId || isLoading) return null;
|
if (!killsCount || detailedKills.length === 0 || !systemId || isLoading) return null;
|
||||||
|
|
||||||
const tooltipContent = (
|
const tooltipContent = (
|
||||||
<div style={{ width: '100%', minWidth: '300px', overflow: 'hidden' }}>
|
<SystemKillsContent kills={detailedKills} systemNameMap={systemNameMap} compact={true} onlyOneSystem={true} />
|
||||||
<SystemKillsContent
|
|
||||||
kills={detailedKills}
|
|
||||||
systemNameMap={systemNameMap}
|
|
||||||
onlyOneSystem={true}
|
|
||||||
autoSize={true}
|
|
||||||
limit={killsCount}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
// @ts-ignore
|
||||||
<WdTooltipWrapper content={tooltipContent} className={className} size={size} interactive={true}>
|
<WdTooltipWrapper content={tooltipContent} className={className} size={size} interactive={true}>
|
||||||
{children}
|
{children}
|
||||||
</WdTooltipWrapper>
|
</WdTooltipWrapper>
|
||||||
|
|||||||
@@ -4,12 +4,6 @@
|
|||||||
z-index: 3;
|
z-index: 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hoverTarget {
|
|
||||||
padding: 0.5rem;
|
|
||||||
margin: -0.5rem;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.localCounter {
|
.localCounter {
|
||||||
mix-blend-mode: screen;
|
mix-blend-mode: screen;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -24,12 +24,13 @@ export const LocalCounter = ({ localCounterCharacters, hasUserCharacters, showIc
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '300px',
|
||||||
minWidth: '300px',
|
overflowX: 'hidden',
|
||||||
overflow: 'hidden',
|
overflowY: 'auto',
|
||||||
|
height: '300px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LocalCharactersList items={localCounterCharacters} itemTemplate={itemTemplate} itemSize={26} autoSize={true} />
|
<LocalCharactersList items={localCounterCharacters} itemTemplate={itemTemplate} itemSize={26} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}, [localCounterCharacters, itemTemplate]);
|
}, [localCounterCharacters, itemTemplate]);
|
||||||
@@ -44,16 +45,19 @@ export const LocalCounter = ({ localCounterCharacters, hasUserCharacters, showIc
|
|||||||
[classes.Pathfinder]: theme === AvailableThemes.pathfinder,
|
[classes.Pathfinder]: theme === AvailableThemes.pathfinder,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<WdTooltipWrapper content={pilotTooltipContent} position={TooltipPosition.right} offset={0} interactive={true}>
|
<WdTooltipWrapper
|
||||||
<div className={clsx(classes.hoverTarget)}>
|
// @ts-ignore
|
||||||
<div
|
content={pilotTooltipContent}
|
||||||
className={clsx(classes.localCounter, {
|
position={TooltipPosition.right}
|
||||||
[classes.hasUserCharacters]: hasUserCharacters,
|
offset={0}
|
||||||
})}
|
>
|
||||||
>
|
<div
|
||||||
{showIcon && <i className="pi pi-users" />}
|
className={clsx(classes.localCounter, {
|
||||||
<span>{localCounterCharacters.length}</span>
|
[classes.hasUserCharacters]: hasUserCharacters,
|
||||||
</div>
|
})}
|
||||||
|
>
|
||||||
|
{showIcon && <i className="pi pi-users" />}
|
||||||
|
<span>{localCounterCharacters.length}</span>
|
||||||
</div>
|
</div>
|
||||||
</WdTooltipWrapper>
|
</WdTooltipWrapper>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -90,7 +90,11 @@ $tooltip-bg: #202020;
|
|||||||
|
|
||||||
&.eve-system-status-home {
|
&.eve-system-status-home {
|
||||||
border: 1px solid var(--eve-solar-system-status-color-home-dark30);
|
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 {
|
&.selected {
|
||||||
border-color: var(--eve-solar-system-status-color-home);
|
border-color: var(--eve-solar-system-status-color-home);
|
||||||
}
|
}
|
||||||
@@ -98,7 +102,11 @@ $tooltip-bg: #202020;
|
|||||||
|
|
||||||
&.eve-system-status-friendly {
|
&.eve-system-status-friendly {
|
||||||
border: 1px solid var(--eve-solar-system-status-color-friendly-dark20);
|
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 {
|
&.selected {
|
||||||
border-color: var(--eve-solar-system-status-color-friendly-dark5);
|
border-color: var(--eve-solar-system-status-color-friendly-dark5);
|
||||||
}
|
}
|
||||||
@@ -113,15 +121,27 @@ $tooltip-bg: #202020;
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.eve-system-status-warning {
|
&.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 {
|
&.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 {
|
&.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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +254,7 @@ $tooltip-bg: #202020;
|
|||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
text-shadow: 0 0 2px rgba(231, 146, 52, 0.73);
|
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 */
|
/* Firefox kostyl */
|
||||||
@@ -243,6 +263,7 @@ $tooltip-bg: #202020;
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.BottomRow {
|
.BottomRow {
|
||||||
@@ -355,3 +376,4 @@ $tooltip-bg: #202020;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Handle, NodeProps, Position } from 'reactflow';
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import classes from './SolarSystemNodeDefault.module.scss';
|
import classes from './SolarSystemNodeDefault.module.scss';
|
||||||
import { PrimeIcons } from 'primereact/api';
|
import { PrimeIcons } from 'primereact/api';
|
||||||
import { useLocalCounter, useSolarSystemNode, useNodeKillsCount } from '../../hooks/useSolarSystemLogic';
|
import { useLocalCounter, useSolarSystemNode } from '../../hooks/useSolarSystemLogic';
|
||||||
import {
|
import {
|
||||||
EFFECT_BACKGROUND_STYLES,
|
EFFECT_BACKGROUND_STYLES,
|
||||||
MARKER_BOOKMARK_BG_STYLES,
|
MARKER_BOOKMARK_BG_STYLES,
|
||||||
@@ -18,7 +18,6 @@ import { KillsCounter } from './SolarSystemKillsCounter';
|
|||||||
export const SolarSystemNodeDefault = memo((props: NodeProps<MapSolarSystemType>) => {
|
export const SolarSystemNodeDefault = memo((props: NodeProps<MapSolarSystemType>) => {
|
||||||
const nodeVars = useSolarSystemNode(props);
|
const nodeVars = useSolarSystemNode(props);
|
||||||
const { localCounterCharacters } = useLocalCounter(nodeVars);
|
const { localCounterCharacters } = useLocalCounter(nodeVars);
|
||||||
const localKillsCount = useNodeKillsCount(nodeVars.solarSystemId, nodeVars.killsCount);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -36,9 +35,9 @@ export const SolarSystemNodeDefault = memo((props: NodeProps<MapSolarSystemType>
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{localKillsCount && localKillsCount > 0 && nodeVars.solarSystemId && (
|
{nodeVars.killsCount && nodeVars.killsCount > 0 && nodeVars.solarSystemId && (
|
||||||
<KillsCounter
|
<KillsCounter
|
||||||
killsCount={localKillsCount}
|
killsCount={nodeVars.killsCount}
|
||||||
systemId={nodeVars.solarSystemId}
|
systemId={nodeVars.solarSystemId}
|
||||||
size="lg"
|
size="lg"
|
||||||
killsActivityType={nodeVars.killsActivityType}
|
killsActivityType={nodeVars.killsActivityType}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Handle, NodeProps, Position } from 'reactflow';
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import classes from './SolarSystemNodeTheme.module.scss';
|
import classes from './SolarSystemNodeTheme.module.scss';
|
||||||
import { PrimeIcons } from 'primereact/api';
|
import { PrimeIcons } from 'primereact/api';
|
||||||
import { useLocalCounter, useNodeKillsCount, useSolarSystemNode } from '../../hooks/useSolarSystemLogic';
|
import { useLocalCounter, useSolarSystemNode } from '../../hooks/useSolarSystemLogic';
|
||||||
import {
|
import {
|
||||||
EFFECT_BACKGROUND_STYLES,
|
EFFECT_BACKGROUND_STYLES,
|
||||||
MARKER_BOOKMARK_BG_STYLES,
|
MARKER_BOOKMARK_BG_STYLES,
|
||||||
@@ -18,7 +18,6 @@ import { KillsCounter } from './SolarSystemKillsCounter';
|
|||||||
export const SolarSystemNodeTheme = memo((props: NodeProps<MapSolarSystemType>) => {
|
export const SolarSystemNodeTheme = memo((props: NodeProps<MapSolarSystemType>) => {
|
||||||
const nodeVars = useSolarSystemNode(props);
|
const nodeVars = useSolarSystemNode(props);
|
||||||
const { localCounterCharacters } = useLocalCounter(nodeVars);
|
const { localCounterCharacters } = useLocalCounter(nodeVars);
|
||||||
const localKillsCount = useNodeKillsCount(nodeVars.solarSystemId, nodeVars.killsCount);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -36,9 +35,9 @@ export const SolarSystemNodeTheme = memo((props: NodeProps<MapSolarSystemType>)
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{localKillsCount && localKillsCount > 0 && nodeVars.solarSystemId && (
|
{nodeVars.killsCount && nodeVars.killsCount > 0 && nodeVars.solarSystemId && (
|
||||||
<KillsCounter
|
<KillsCounter
|
||||||
killsCount={localKillsCount}
|
killsCount={nodeVars.killsCount}
|
||||||
systemId={nodeVars.solarSystemId}
|
systemId={nodeVars.solarSystemId}
|
||||||
size="lg"
|
size="lg"
|
||||||
killsActivityType={nodeVars.killsActivityType}
|
killsActivityType={nodeVars.killsActivityType}
|
||||||
|
|||||||
@@ -10,6 +10,5 @@ export const convertSystem2Node = (sys: SolarSystemRawType): Node => {
|
|||||||
position: sys.position,
|
position: sys.position,
|
||||||
data: sys,
|
data: sys,
|
||||||
draggable: !sys.locked,
|
draggable: !sys.locked,
|
||||||
deletable: !sys.locked,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { MapSolarSystemType } from '../map.types';
|
import { MapSolarSystemType } from '../map.types';
|
||||||
import { NodeProps } from 'reactflow';
|
import { NodeProps } from 'reactflow';
|
||||||
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
|
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
|
||||||
@@ -10,9 +10,8 @@ import { isWormholeSpace } from '@/hooks/Mapper/components/map/helpers/isWormhol
|
|||||||
import { getSystemClassStyles, prepareUnsplashedChunks } from '@/hooks/Mapper/components/map/helpers';
|
import { getSystemClassStyles, prepareUnsplashedChunks } from '@/hooks/Mapper/components/map/helpers';
|
||||||
import { sortWHClasses } from '@/hooks/Mapper/helpers';
|
import { sortWHClasses } from '@/hooks/Mapper/helpers';
|
||||||
import { LabelsManager } from '@/hooks/Mapper/utils/labelsManager';
|
import { LabelsManager } from '@/hooks/Mapper/utils/labelsManager';
|
||||||
import { CharacterTypeRaw, Commands, OutCommand, SystemSignature } from '@/hooks/Mapper/types';
|
import { CharacterTypeRaw, OutCommand, SystemSignature } from '@/hooks/Mapper/types';
|
||||||
import { LABELS_INFO, LABELS_ORDER } from '@/hooks/Mapper/components/map/constants';
|
import { LABELS_INFO, LABELS_ORDER } from '@/hooks/Mapper/components/map/constants';
|
||||||
import { useMapEventListener } from '@/hooks/Mapper/events';
|
|
||||||
|
|
||||||
export type LabelInfo = {
|
export type LabelInfo = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -196,6 +195,7 @@ export function useSolarSystemNode(props: NodeProps<MapSolarSystemType>): SolarS
|
|||||||
kind: s.kind,
|
kind: s.kind,
|
||||||
name: s.name,
|
name: s.name,
|
||||||
group: s.group,
|
group: s.group,
|
||||||
|
sig_id: s.eve_id, // Add a unique key property
|
||||||
})) as UnsplashedSignatureType[],
|
})) as UnsplashedSignatureType[],
|
||||||
);
|
);
|
||||||
}, [isShowUnsplashedSignatures, systemSigs]);
|
}, [isShowUnsplashedSignatures, systemSigs]);
|
||||||
@@ -281,25 +281,3 @@ export interface SolarSystemNodeVars {
|
|||||||
classTitle: string | null;
|
classTitle: string | null;
|
||||||
temporaryName?: string | null;
|
temporaryName?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useNodeKillsCount(systemId: number | string, initialKillsCount: number | null): number | null {
|
|
||||||
const [killsCount, setKillsCount] = useState<number | null>(initialKillsCount);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setKillsCount(initialKillsCount);
|
|
||||||
}, [initialKillsCount]);
|
|
||||||
|
|
||||||
useMapEventListener(event => {
|
|
||||||
if (event.name === Commands.killsUpdated && event.data?.toString() === systemId.toString()) {
|
|
||||||
//@ts-ignore
|
|
||||||
if (event.payload && typeof event.payload.kills === 'number') {
|
|
||||||
// @ts-ignore
|
|
||||||
setKillsCount(event.payload.kills);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
return killsCount;
|
|
||||||
}
|
|
||||||
@@ -3,13 +3,11 @@ import { VirtualScroller, VirtualScrollerTemplateOptions } from 'primereact/virt
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { CharItemProps } from './types';
|
import { CharItemProps } from './types';
|
||||||
|
|
||||||
export type LocalCharactersListProps = {
|
type LocalCharactersListProps = {
|
||||||
items: Array<CharItemProps>;
|
items: Array<CharItemProps>;
|
||||||
itemSize: number;
|
itemSize: number;
|
||||||
itemTemplate: (char: CharItemProps, options: VirtualScrollerTemplateOptions) => React.ReactNode;
|
itemTemplate: (char: CharItemProps, options: VirtualScrollerTemplateOptions) => React.ReactNode;
|
||||||
containerClassName?: string;
|
containerClassName?: string;
|
||||||
style?: React.CSSProperties;
|
|
||||||
autoSize?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LocalCharactersList = ({
|
export const LocalCharactersList = ({
|
||||||
@@ -17,19 +15,7 @@ export const LocalCharactersList = ({
|
|||||||
itemSize,
|
itemSize,
|
||||||
itemTemplate,
|
itemTemplate,
|
||||||
containerClassName,
|
containerClassName,
|
||||||
style = {},
|
|
||||||
autoSize = false,
|
|
||||||
}: LocalCharactersListProps) => {
|
}: 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 (
|
return (
|
||||||
<VirtualScroller
|
<VirtualScroller
|
||||||
items={items}
|
items={items}
|
||||||
@@ -37,8 +23,6 @@ export const LocalCharactersList = ({
|
|||||||
orientation="vertical"
|
orientation="vertical"
|
||||||
className={clsx('w-full h-full', containerClassName)}
|
className={clsx('w-full h-full', containerClassName)}
|
||||||
itemTemplate={itemTemplate}
|
itemTemplate={itemTemplate}
|
||||||
autoSize={autoSize}
|
|
||||||
style={localStyle}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ import { useKillsWidgetSettings } from './hooks/useKillsWidgetSettings';
|
|||||||
import { useSystemKills } from './hooks/useSystemKills';
|
import { useSystemKills } from './hooks/useSystemKills';
|
||||||
import { KillsSettingsDialog } from './components/SystemKillsSettingsDialog';
|
import { KillsSettingsDialog } from './components/SystemKillsSettingsDialog';
|
||||||
import { isWormholeSpace } from '@/hooks/Mapper/components/map/helpers/isWormholeSpace';
|
import { isWormholeSpace } from '@/hooks/Mapper/components/map/helpers/isWormholeSpace';
|
||||||
import { SolarSystemRawType } from '@/hooks/Mapper/types';
|
|
||||||
|
|
||||||
export const SystemKills: React.FC = React.memo(() => {
|
export const SystemKills: React.FC = () => {
|
||||||
const {
|
const {
|
||||||
data: { selectedSystems, systems, isSubscriptionActive },
|
data: { selectedSystems, systems, isSubscriptionActive },
|
||||||
outCommand,
|
outCommand,
|
||||||
@@ -26,16 +25,6 @@ export const SystemKills: React.FC = React.memo(() => {
|
|||||||
return map;
|
return map;
|
||||||
}, [systems]);
|
}, [systems]);
|
||||||
|
|
||||||
const systemBySolarSystemId = useMemo(() => {
|
|
||||||
const map: Record<number, SolarSystemRawType> = {};
|
|
||||||
systems.forEach(sys => {
|
|
||||||
if (sys.system_static_info?.solar_system_id != null) {
|
|
||||||
map[sys.system_static_info.solar_system_id] = sys;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return map;
|
|
||||||
}, [systems]);
|
|
||||||
|
|
||||||
const [settings] = useKillsWidgetSettings();
|
const [settings] = useKillsWidgetSettings();
|
||||||
const visible = settings.showAll;
|
const visible = settings.showAll;
|
||||||
|
|
||||||
@@ -51,59 +40,78 @@ export const SystemKills: React.FC = React.memo(() => {
|
|||||||
const filteredKills = useMemo(() => {
|
const filteredKills = useMemo(() => {
|
||||||
if (!settings.whOnly || !visible) return kills;
|
if (!settings.whOnly || !visible) return kills;
|
||||||
return kills.filter(kill => {
|
return kills.filter(kill => {
|
||||||
const system = systemBySolarSystemId[kill.solar_system_id];
|
const system = systems.find(
|
||||||
|
sys => sys.system_static_info.solar_system_id === kill.solar_system_id
|
||||||
|
);
|
||||||
if (!system) {
|
if (!system) {
|
||||||
console.warn(`System with id ${kill.solar_system_id} not found.`);
|
console.warn(`System with id ${kill.solar_system_id} not found.`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return isWormholeSpace(system.system_static_info.system_class);
|
return isWormholeSpace(system.system_static_info.system_class);
|
||||||
});
|
});
|
||||||
}, [kills, settings.whOnly, systemBySolarSystemId, visible]);
|
}, [kills, settings.whOnly, systems]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex flex-col min-h-0">
|
<div className="h-full flex flex-col min-h-0">
|
||||||
<div className="flex flex-col flex-1 min-h-0">
|
<div className="flex flex-col flex-1 min-h-0">
|
||||||
<Widget label={<KillsHeader systemId={systemId} onOpenSettings={() => setSettingsDialogVisible(true)} />}>
|
<Widget
|
||||||
{!isSubscriptionActive ? (
|
label={
|
||||||
<div className="w-full h-full flex items-center justify-center">
|
<KillsHeader
|
||||||
<span className="select-none text-center text-stone-400/80 text-sm">
|
systemId={systemId}
|
||||||
Kills available with 'Active' map subscription only (contact map administrators)
|
onOpenSettings={() => setSettingsDialogVisible(true)}
|
||||||
</span>
|
/>
|
||||||
</div>
|
}
|
||||||
) : isNothingSelected ? (
|
>
|
||||||
<div className="w-full h-full flex items-center justify-center">
|
<div className="relative h-full">
|
||||||
<span className="select-none text-center text-stone-400/80 text-sm">
|
{!isSubscriptionActive ? (
|
||||||
No system selected (or toggle “Show all systems”)
|
<div className="absolute inset-0 flex items-center justify-center">
|
||||||
</span>
|
<span className="select-none text-center text-stone-400/80 text-sm">
|
||||||
</div>
|
Kills available with 'Active' map subscription only (contact map administrators)
|
||||||
) : showLoading ? (
|
</span>
|
||||||
<div className="w-full h-full flex items-center justify-center">
|
</div>
|
||||||
<span className="select-none text-center text-stone-400/80 text-sm">Loading Kills...</span>
|
) : isNothingSelected ? (
|
||||||
</div>
|
<div className="absolute inset-0 flex items-center justify-center">
|
||||||
) : error ? (
|
<span className="select-none text-center text-stone-400/80 text-sm">
|
||||||
<div className="w-full h-full flex items-center justify-center">
|
No system selected (or toggle “Show all systems”)
|
||||||
<span className="select-none text-center text-red-400 text-sm">{error}</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
) : !filteredKills || filteredKills.length === 0 ? (
|
) : showLoading ? (
|
||||||
<div className="w-full h-full flex items-center justify-center">
|
<div className="absolute inset-0 flex items-center justify-center">
|
||||||
<span className="select-none text-center text-stone-400/80 text-sm">No kills found</span>
|
<span className="select-none text-center text-stone-400/80 text-sm">
|
||||||
</div>
|
Loading Kills...
|
||||||
) : (
|
</span>
|
||||||
<div className="w-full h-full" style={{ height: '100%' }}>
|
</div>
|
||||||
<SystemKillsContent
|
) : error ? (
|
||||||
kills={filteredKills}
|
<div className="absolute inset-0 flex items-center justify-center">
|
||||||
systemNameMap={systemNameMap}
|
<span className="select-none text-center text-red-400 text-sm">
|
||||||
onlyOneSystem={!visible}
|
{error}
|
||||||
timeRange={settings.timeRange}
|
</span>
|
||||||
/>
|
</div>
|
||||||
</div>
|
) : !filteredKills || filteredKills.length === 0 ? (
|
||||||
)}
|
<div className="absolute inset-0 flex items-center justify-center">
|
||||||
|
<span className="select-none text-center text-stone-400/80 text-sm">
|
||||||
|
No kills found
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="h-full overflow-y-auto">
|
||||||
|
<SystemKillsContent
|
||||||
|
key={settings.compact ? 'compact' : 'normal'}
|
||||||
|
kills={filteredKills}
|
||||||
|
systemNameMap={systemNameMap}
|
||||||
|
compact={settings.compact}
|
||||||
|
onlyOneSystem={!visible}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</Widget>
|
</Widget>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{settingsDialogVisible && <KillsSettingsDialog visible setVisible={setSettingsDialogVisible} />}
|
<KillsSettingsDialog
|
||||||
|
visible={settingsDialogVisible}
|
||||||
|
setVisible={setSettingsDialogVisible}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
SystemKills.displayName = 'SystemKills';
|
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
.wrapper {
|
.TableRowCompact {
|
||||||
overflow-x: hidden;
|
height: 8px;
|
||||||
box-sizing: border-box;
|
max-height: 8px;
|
||||||
|
font-size: 12px !important;
|
||||||
|
line-height: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.scrollerContent {
|
.Table {
|
||||||
width: 100%;
|
font-size: 12px;
|
||||||
box-sizing: border-box;
|
border-collapse: collapse;
|
||||||
overflow-x: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.VirtualScroller {
|
.Tooltip {
|
||||||
height: 100% !important;
|
white-space: pre-line;
|
||||||
|
line-height: 1.2rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,91 +1,50 @@
|
|||||||
import React, { useMemo, useRef, useEffect, useState } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { DetailedKill } from '@/hooks/Mapper/types/kills';
|
import { DetailedKill } from '@/hooks/Mapper/types/kills';
|
||||||
import { VirtualScroller } from 'primereact/virtualscroller';
|
import { KillRow } from '../components/SystemKillsRow';
|
||||||
import { useSystemKillsItemTemplate } from '../hooks/useSystemKillsItemTemplate';
|
|
||||||
import classes from './SystemKillsContent.module.scss';
|
|
||||||
|
|
||||||
export const ITEM_HEIGHT = 35;
|
interface SystemKillsContentProps {
|
||||||
export const CONTENT_MARGINS = 5;
|
|
||||||
|
|
||||||
export interface SystemKillsContentProps {
|
|
||||||
kills: DetailedKill[];
|
kills: DetailedKill[];
|
||||||
systemNameMap: Record<string, string>;
|
systemNameMap: Record<string, string>;
|
||||||
|
compact?: boolean;
|
||||||
onlyOneSystem?: boolean;
|
onlyOneSystem?: boolean;
|
||||||
autoSize?: boolean;
|
|
||||||
timeRange?: number;
|
|
||||||
limit?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SystemKillsContent: React.FC<SystemKillsContentProps> = ({
|
export const SystemKillsContent: React.FC<SystemKillsContentProps> = ({
|
||||||
kills,
|
kills,
|
||||||
systemNameMap,
|
systemNameMap,
|
||||||
|
compact = false,
|
||||||
onlyOneSystem = false,
|
onlyOneSystem = false,
|
||||||
autoSize = false,
|
|
||||||
timeRange = 4,
|
|
||||||
limit,
|
|
||||||
}) => {
|
}) => {
|
||||||
const processedKills = useMemo(() => {
|
const sortedKills = useMemo(() => {
|
||||||
const sortedKills = kills
|
return [...kills].sort((a, b) => {
|
||||||
.filter(k => k.kill_time)
|
const timeA = a.kill_time ? new Date(a.kill_time).getTime() : 0;
|
||||||
.sort((a, b) => new Date(b.kill_time!).getTime() - new Date(a.kill_time!).getTime());
|
const timeB = b.kill_time ? new Date(b.kill_time).getTime() : 0;
|
||||||
|
return timeB - timeA;
|
||||||
if (limit !== undefined) {
|
});
|
||||||
return sortedKills.slice(0, limit);
|
}, [kills]);
|
||||||
} 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 computedHeight = autoSize ? Math.max(processedKills.length, 1) * ITEM_HEIGHT + CONTENT_MARGINS : undefined;
|
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement>(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;
|
|
||||||
setContainerHeight(newHeight);
|
|
||||||
};
|
|
||||||
|
|
||||||
measure();
|
|
||||||
const observer = new ResizeObserver(measure);
|
|
||||||
observer.observe(containerRef.current);
|
|
||||||
window.addEventListener('resize', measure);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
observer.disconnect();
|
|
||||||
window.removeEventListener('resize', measure);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, [autoSize]);
|
|
||||||
|
|
||||||
const itemTemplate = useSystemKillsItemTemplate(systemNameMap, onlyOneSystem);
|
|
||||||
const scrollerHeight = autoSize ? `${computedHeight}px` : containerHeight ? `${containerHeight}px` : '100%';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={autoSize ? undefined : containerRef} className={clsx('w-full h-full', classes.wrapper)}>
|
<div
|
||||||
<VirtualScroller
|
className={clsx(
|
||||||
ref={autoSize ? undefined : scrollerRef}
|
'flex flex-col w-full text-stone-200 text-xs transition-all duration-300',
|
||||||
items={processedKills}
|
compact ? 'p-1' : 'p-1'
|
||||||
itemSize={ITEM_HEIGHT}
|
)}
|
||||||
itemTemplate={itemTemplate}
|
>
|
||||||
autoSize={autoSize}
|
{sortedKills.map(kill => {
|
||||||
scrollWidth="100%"
|
const systemIdStr = String(kill.solar_system_id);
|
||||||
style={{ height: scrollerHeight }}
|
const systemName = systemNameMap[systemIdStr] || `System ${systemIdStr}`;
|
||||||
className={clsx('w-full h-full custom-scrollbar select-none overflow-x-hidden overflow-y-auto', {
|
|
||||||
[classes.VirtualScroller]: !autoSize,
|
return (
|
||||||
})}
|
<KillRow
|
||||||
pt={{
|
key={kill.killmail_id}
|
||||||
content: {
|
killDetails={kill}
|
||||||
className: classes.scrollerContent,
|
systemName={systemName}
|
||||||
},
|
isCompact={compact}
|
||||||
}}
|
onlyOneSystem={onlyOneSystem}
|
||||||
/>
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import {
|
|||||||
getPrimaryLogoAndTooltip,
|
getPrimaryLogoAndTooltip,
|
||||||
getAttackerPrimaryImageAndTooltip,
|
getAttackerPrimaryImageAndTooltip,
|
||||||
} from '../helpers';
|
} from '../helpers';
|
||||||
import { WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit';
|
import { WdTooltipWrapper } from '../../../../ui-kit/WdTooltipWrapper';
|
||||||
import classes from './KillRowDetail.module.scss';
|
import classes from './SystemKillRow.module.scss';
|
||||||
import { TooltipPosition } from '@/hooks/Mapper/components/ui-kit';
|
import { TooltipPosition } from '@/hooks/Mapper/components/ui-kit';
|
||||||
|
|
||||||
export interface CompactKillRowProps {
|
export interface CompactKillRowProps {
|
||||||
@@ -21,10 +21,15 @@ export interface CompactKillRowProps {
|
|||||||
onlyOneSystem: boolean;
|
onlyOneSystem: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const KillRowDetail: React.FC<CompactKillRowProps> = ({ killDetails, systemName, onlyOneSystem }) => {
|
export const CompactKillRow: React.FC<CompactKillRowProps> = ({
|
||||||
|
killDetails,
|
||||||
|
systemName,
|
||||||
|
onlyOneSystem,
|
||||||
|
}) => {
|
||||||
const {
|
const {
|
||||||
killmail_id = 0,
|
killmail_id = 0,
|
||||||
// Victim data
|
|
||||||
|
// Victim
|
||||||
victim_char_name = 'Unknown Pilot',
|
victim_char_name = 'Unknown Pilot',
|
||||||
victim_alliance_ticker = '',
|
victim_alliance_ticker = '',
|
||||||
victim_corp_ticker = '',
|
victim_corp_ticker = '',
|
||||||
@@ -35,7 +40,8 @@ export const KillRowDetail: React.FC<CompactKillRowProps> = ({ killDetails, syst
|
|||||||
victim_corp_id = 0,
|
victim_corp_id = 0,
|
||||||
victim_alliance_id = 0,
|
victim_alliance_id = 0,
|
||||||
victim_ship_type_id = 0,
|
victim_ship_type_id = 0,
|
||||||
// Attacker data
|
|
||||||
|
// Attacker
|
||||||
final_blow_char_id = 0,
|
final_blow_char_id = 0,
|
||||||
final_blow_char_name = '',
|
final_blow_char_name = '',
|
||||||
final_blow_alliance_ticker = '',
|
final_blow_alliance_ticker = '',
|
||||||
@@ -45,64 +51,72 @@ export const KillRowDetail: React.FC<CompactKillRowProps> = ({ killDetails, syst
|
|||||||
final_blow_corp_id = 0,
|
final_blow_corp_id = 0,
|
||||||
final_blow_corp_name = '',
|
final_blow_corp_name = '',
|
||||||
final_blow_ship_type_id = 0,
|
final_blow_ship_type_id = 0,
|
||||||
|
|
||||||
kill_time = '',
|
kill_time = '',
|
||||||
total_value = 0,
|
total_value = 0,
|
||||||
} = killDetails || {};
|
} = killDetails || {};
|
||||||
|
|
||||||
const attackerIsNpc = final_blow_char_id === 0;
|
const attackerIsNpc = final_blow_char_id === 0;
|
||||||
|
|
||||||
// Define victim affiliation ticker.
|
// Tickers & strings
|
||||||
const victimAffiliationTicker = victim_alliance_ticker || victim_corp_ticker || 'No 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 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 killTimeAgo = kill_time ? formatTimeMixed(kill_time) : '0h ago';
|
||||||
|
|
||||||
const attackerSubscript = getAttackerSubscript(killDetails);
|
const attackerSubscript = getAttackerSubscript(killDetails);
|
||||||
|
|
||||||
const { victimCorpLogoUrl, victimAllianceLogoUrl, victimShipUrl } = buildVictimImageUrls({
|
// Victim images, including the ship
|
||||||
|
const {
|
||||||
|
victimCorpLogoUrl,
|
||||||
|
victimAllianceLogoUrl,
|
||||||
|
victimShipUrl,
|
||||||
|
} = buildVictimImageUrls({
|
||||||
victim_char_id,
|
victim_char_id,
|
||||||
victim_ship_type_id,
|
victim_ship_type_id,
|
||||||
victim_corp_id,
|
victim_corp_id,
|
||||||
victim_alliance_id,
|
victim_alliance_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Attacker corp/alliance
|
||||||
const { attackerCorpLogoUrl, attackerAllianceLogoUrl } = buildAttackerImageUrls({
|
const { attackerCorpLogoUrl, attackerAllianceLogoUrl } = buildAttackerImageUrls({
|
||||||
final_blow_char_id,
|
final_blow_char_id,
|
||||||
final_blow_corp_id,
|
final_blow_corp_id,
|
||||||
final_blow_alliance_id,
|
final_blow_alliance_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { url: victimPrimaryLogoUrl, tooltip: victimPrimaryTooltip } = getPrimaryLogoAndTooltip(
|
// Victim corp/alliance logo
|
||||||
victimAllianceLogoUrl,
|
const { url: victimPrimaryLogoUrl, tooltip: victimPrimaryTooltip } =
|
||||||
victimCorpLogoUrl,
|
getPrimaryLogoAndTooltip(
|
||||||
victim_alliance_name,
|
victimAllianceLogoUrl,
|
||||||
victim_corp_name,
|
victimCorpLogoUrl,
|
||||||
'Victim',
|
victim_alliance_name,
|
||||||
);
|
victim_corp_name,
|
||||||
|
'Victim'
|
||||||
|
);
|
||||||
|
|
||||||
const { url: attackerPrimaryImageUrl, tooltip: attackerPrimaryTooltip } = getAttackerPrimaryImageAndTooltip(
|
// Attacker corp/alliance or NPC ship
|
||||||
attackerIsNpc,
|
const { url: attackerPrimaryImageUrl, tooltip: attackerPrimaryTooltip } =
|
||||||
attackerAllianceLogoUrl,
|
getAttackerPrimaryImageAndTooltip(
|
||||||
attackerCorpLogoUrl,
|
attackerIsNpc,
|
||||||
final_blow_alliance_name,
|
attackerAllianceLogoUrl,
|
||||||
final_blow_corp_name,
|
attackerCorpLogoUrl,
|
||||||
final_blow_ship_type_id,
|
final_blow_alliance_name,
|
||||||
);
|
final_blow_corp_name,
|
||||||
|
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 (
|
return (
|
||||||
<div
|
<div
|
||||||
className={clsx(
|
className={clsx(
|
||||||
'h-10 flex items-center border-b border-stone-800',
|
'h-10 flex items-center border-b border-stone-800',
|
||||||
'text-xs whitespace-nowrap overflow-hidden leading-none',
|
'text-xs whitespace-nowrap overflow-hidden leading-none'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{/* Victim Section */}
|
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
{victimShipUrl && (
|
{victimShipUrl && (
|
||||||
<div className="relative shrink-0 w-8 h-8 overflow-hidden">
|
<div className="relative shrink-0 w-8 h-8 overflow-hidden">
|
||||||
@@ -114,14 +128,20 @@ export const KillRowDetail: React.FC<CompactKillRowProps> = ({ killDetails, syst
|
|||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src={victimShipUrl}
|
src={victimShipUrl}
|
||||||
alt="Victim Ship"
|
alt="VictimShip"
|
||||||
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
|
className={clsx(
|
||||||
|
classes.killRowImage,
|
||||||
|
'w-full h-full object-contain'
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{victimPrimaryLogoUrl && (
|
{victimPrimaryLogoUrl && (
|
||||||
<WdTooltipWrapper content={victimPrimaryTooltip} position={TooltipPosition.top}>
|
<WdTooltipWrapper
|
||||||
|
content={victimPrimaryTooltip}
|
||||||
|
position={TooltipPosition.top}
|
||||||
|
>
|
||||||
<a
|
<a
|
||||||
href={zkillLink('kill', killmail_id)}
|
href={zkillLink('kill', killmail_id)}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -130,14 +150,17 @@ export const KillRowDetail: React.FC<CompactKillRowProps> = ({ killDetails, syst
|
|||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src={victimPrimaryLogoUrl}
|
src={victimPrimaryLogoUrl}
|
||||||
alt="Victim Primary Logo"
|
alt="VictimPrimaryLogo"
|
||||||
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
|
className={clsx(
|
||||||
|
classes.killRowImage,
|
||||||
|
'w-full h-full object-contain'
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
</WdTooltipWrapper>
|
</WdTooltipWrapper>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col ml-2 flex-1 min-w-0 overflow-hidden leading-[1rem]">
|
<div className="flex flex-col ml-2 min-w-0 overflow-hidden leading-[1rem]">
|
||||||
<div className="truncate text-stone-200">
|
<div className="truncate text-stone-200">
|
||||||
{victim_char_name}
|
{victim_char_name}
|
||||||
<span className="text-stone-400"> / {victimAffiliationTicker}</span>
|
<span className="text-stone-400"> / {victimAffiliationTicker}</span>
|
||||||
@@ -153,17 +176,20 @@ export const KillRowDetail: React.FC<CompactKillRowProps> = ({ killDetails, syst
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center ml-auto gap-2">
|
<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]">
|
<div className="flex flex-col items-end min-w-0 overflow-hidden text-right leading-[1rem]">
|
||||||
{!attackerIsNpc && (final_blow_char_name || attackerTicker) && (
|
{!attackerIsNpc && (attackerName || attackerTicker) && (
|
||||||
<div className="truncate text-stone-200">
|
<div className="truncate text-stone-200">
|
||||||
{final_blow_char_name}
|
{attackerName}
|
||||||
{!attackerIsNpc && attackerTicker && <span className="ml-1 text-stone-400">/ {attackerTicker}</span>}
|
{attackerTicker && (
|
||||||
|
<span className="ml-1 text-stone-400">/ {attackerTicker}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="truncate text-stone-400">
|
<div className="truncate text-stone-400">
|
||||||
{!onlyOneSystem && systemName ? (
|
{!onlyOneSystem && systemName ? (
|
||||||
<>
|
<>
|
||||||
{systemName} / <span className="ml-1 text-red-400">{killTimeAgo}</span>
|
{systemName} /{' '}
|
||||||
|
<span className="ml-1 text-red-400">{killTimeAgo}</span>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-red-400">{killTimeAgo}</span>
|
<span className="text-red-400">{killTimeAgo}</span>
|
||||||
@@ -171,24 +197,30 @@ export const KillRowDetail: React.FC<CompactKillRowProps> = ({ killDetails, syst
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{attackerPrimaryImageUrl && (
|
{attackerPrimaryImageUrl && (
|
||||||
<WdTooltipWrapper content={attackerPrimaryTooltip} position={TooltipPosition.top}>
|
<WdTooltipWrapper
|
||||||
|
content={attackerPrimaryTooltip}
|
||||||
|
position={TooltipPosition.top}
|
||||||
|
>
|
||||||
<a
|
<a
|
||||||
href={attackerLink}
|
href={zkillLink('kill', killmail_id)}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="relative block shrink-0 w-8 h-8 overflow-hidden"
|
className="relative block shrink-0 w-8 h-8 overflow-hidden"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src={attackerPrimaryImageUrl}
|
src={attackerPrimaryImageUrl}
|
||||||
alt={attackerIsNpc ? 'NPC Ship' : 'Attacker Primary Logo'}
|
alt={attackerIsNpc ? 'NpcShip' : 'AttackerPrimaryLogo'}
|
||||||
className={clsx(classes.killRowImage, 'w-full h-full object-contain')}
|
className={clsx(
|
||||||
|
classes.killRowImage,
|
||||||
|
'w-full h-full object-contain'
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
{attackerSubscript && (
|
{attackerSubscript && (
|
||||||
<span
|
<span
|
||||||
className={clsx(
|
className={clsx(
|
||||||
classes.attackerCountLabel,
|
classes.attackerCountLabel,
|
||||||
attackerSubscript.cssClass,
|
attackerSubscript.cssClass,
|
||||||
'text-[0.6rem] leading-none px-[2px]',
|
'text-[0.6rem] leading-none px-[2px]'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{attackerSubscript.label}
|
{attackerSubscript.label}
|
||||||
@@ -0,0 +1,268 @@
|
|||||||
|
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 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>
|
||||||
|
{/* Attacker Section */}
|
||||||
|
<div className="flex items-start gap-1 min-w-0 sm:ml-auto">
|
||||||
|
<div className="flex flex-col 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 > 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>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { DetailedKill } from '@/hooks/Mapper/types/kills';
|
|
||||||
import { VirtualScrollerTemplateOptions } from 'primereact/virtualscroller';
|
|
||||||
import { KillRow } from './SystemKillsRow';
|
|
||||||
import clsx from 'clsx';
|
|
||||||
|
|
||||||
export function KillItemTemplate(
|
|
||||||
systemNameMap: Record<string, string>,
|
|
||||||
onlyOneSystem: boolean,
|
|
||||||
kill: DetailedKill,
|
|
||||||
options: VirtualScrollerTemplateOptions,
|
|
||||||
) {
|
|
||||||
const systemIdStr = String(kill.solar_system_id);
|
|
||||||
const systemName = systemNameMap[systemIdStr] || `System ${systemIdStr}`;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ height: `${options.props.itemSize}px` }} className={clsx({ 'bg-gray-900': options.odd })}>
|
|
||||||
<KillRow killDetails={kill} systemName={systemName} onlyOneSystem={onlyOneSystem} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,24 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { DetailedKill } from '@/hooks/Mapper/types/kills';
|
import { DetailedKill } from '@/hooks/Mapper/types/kills';
|
||||||
import { KillRowDetail } from './KillRowDetail.tsx';
|
import { CompactKillRow } from './CompactKillRow';
|
||||||
|
import { FullKillRow } from './FullKillRow';
|
||||||
|
|
||||||
export interface KillRowProps {
|
export interface KillRowProps {
|
||||||
killDetails: DetailedKill;
|
killDetails: DetailedKill;
|
||||||
systemName: string;
|
systemName: string;
|
||||||
|
isCompact?: boolean;
|
||||||
onlyOneSystem?: boolean;
|
onlyOneSystem?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const KillRowComponent: React.FC<KillRowProps> = ({ killDetails, systemName, onlyOneSystem = false }) => {
|
export const KillRow: React.FC<KillRowProps> = ({
|
||||||
return <KillRowDetail killDetails={killDetails} systemName={systemName} onlyOneSystem={onlyOneSystem} />;
|
killDetails,
|
||||||
};
|
systemName,
|
||||||
|
isCompact = false,
|
||||||
|
onlyOneSystem = false,
|
||||||
|
}) => {
|
||||||
|
if (isCompact) {
|
||||||
|
return <CompactKillRow killDetails={killDetails} systemName={systemName} onlyOneSystem={onlyOneSystem} />;
|
||||||
|
}
|
||||||
|
|
||||||
export const KillRow = React.memo(KillRowComponent);
|
return <FullKillRow killDetails={killDetails} systemName={systemName} onlyOneSystem={onlyOneSystem} />;
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { Dialog } from 'primereact/dialog';
|
import { Dialog } from 'primereact/dialog';
|
||||||
import { Button } from 'primereact/button';
|
import { Button } from 'primereact/button';
|
||||||
import { WdImgButton } from '@/hooks/Mapper/components/ui-kit';
|
import { WdImgButton, SystemView, TooltipPosition } from '@/hooks/Mapper/components/ui-kit';
|
||||||
import { PrimeIcons } from 'primereact/api';
|
import { PrimeIcons } from 'primereact/api';
|
||||||
import { useKillsWidgetSettings } from '../hooks/useKillsWidgetSettings';
|
import { useKillsWidgetSettings } from '../hooks/useKillsWidgetSettings';
|
||||||
import {
|
import {
|
||||||
AddSystemDialog,
|
AddSystemDialog,
|
||||||
SearchOnSubmitCallback,
|
SearchOnSubmitCallback,
|
||||||
} from '@/hooks/Mapper/components/mapInterface/components/AddSystemDialog';
|
} from '@/hooks/Mapper/components/mapInterface/components/AddSystemDialog';
|
||||||
import { SystemView, TooltipPosition } from '@/hooks/Mapper/components/ui-kit';
|
|
||||||
|
|
||||||
interface KillsSettingsDialogProps {
|
interface KillsSettingsDialogProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
@@ -18,39 +17,40 @@ interface KillsSettingsDialogProps {
|
|||||||
export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visible, setVisible }) => {
|
export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visible, setVisible }) => {
|
||||||
const [globalSettings, setGlobalSettings] = useKillsWidgetSettings();
|
const [globalSettings, setGlobalSettings] = useKillsWidgetSettings();
|
||||||
const localRef = useRef({
|
const localRef = useRef({
|
||||||
|
compact: globalSettings.compact,
|
||||||
showAll: globalSettings.showAll,
|
showAll: globalSettings.showAll,
|
||||||
whOnly: globalSettings.whOnly,
|
whOnly: globalSettings.whOnly,
|
||||||
excludedSystems: globalSettings.excludedSystems || [],
|
excludedSystems: globalSettings.excludedSystems || [],
|
||||||
timeRange: globalSettings.timeRange,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [, forceRender] = useState(0);
|
const [, forceRender] = useState(0);
|
||||||
|
|
||||||
const [addSystemDialogVisible, setAddSystemDialogVisible] = useState(false);
|
const [addSystemDialogVisible, setAddSystemDialogVisible] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
localRef.current = {
|
localRef.current = {
|
||||||
|
compact: globalSettings.compact,
|
||||||
showAll: globalSettings.showAll,
|
showAll: globalSettings.showAll,
|
||||||
whOnly: globalSettings.whOnly,
|
whOnly: globalSettings.whOnly,
|
||||||
excludedSystems: globalSettings.excludedSystems || [],
|
excludedSystems: globalSettings.excludedSystems || [],
|
||||||
timeRange: globalSettings.timeRange,
|
|
||||||
};
|
};
|
||||||
forceRender(n => n + 1);
|
forceRender(n => n + 1);
|
||||||
}
|
}
|
||||||
}, [visible, globalSettings]);
|
}, [visible, globalSettings]);
|
||||||
|
|
||||||
const handleWHChange = useCallback((checked: boolean) => {
|
const handleCompactChange = useCallback((checked: boolean) => {
|
||||||
localRef.current = {
|
localRef.current = {
|
||||||
...localRef.current,
|
...localRef.current,
|
||||||
whOnly: checked,
|
compact: checked,
|
||||||
};
|
};
|
||||||
forceRender(n => n + 1);
|
forceRender(n => n + 1);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleTimeRangeChange = useCallback((newTimeRange: number) => {
|
const handleWHChange = useCallback((checked: boolean) => {
|
||||||
localRef.current = {
|
localRef.current = {
|
||||||
...localRef.current,
|
...localRef.current,
|
||||||
timeRange: newTimeRange,
|
whOnly: checked,
|
||||||
};
|
};
|
||||||
forceRender(n => n + 1);
|
forceRender(n => n + 1);
|
||||||
}, []);
|
}, []);
|
||||||
@@ -88,11 +88,22 @@ export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visibl
|
|||||||
|
|
||||||
const localData = localRef.current;
|
const localData = localRef.current;
|
||||||
const excluded = localData.excludedSystems || [];
|
const excluded = localData.excludedSystems || [];
|
||||||
const timeRangeOptions = [4, 12, 24];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog header="Kills Settings" visible={visible} style={{ width: '440px' }} draggable={false} onHide={handleHide}>
|
<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 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">
|
<div className="flex items-center gap-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
@@ -100,30 +111,11 @@ export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visibl
|
|||||||
checked={localData.whOnly}
|
checked={localData.whOnly}
|
||||||
onChange={e => handleWHChange(e.target.checked)}
|
onChange={e => handleWHChange(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="kills-wormhole-only-mode" className="cursor-pointer">
|
<label htmlFor="kills-wh-only-mode" className="cursor-pointer">
|
||||||
Only show wormhole kills
|
Only show wormhole kills
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-1">
|
|
||||||
<span className="text-sm">Time Range:</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 flex-col gap-1">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<label className="text-sm text-stone-400">Excluded Systems</label>
|
<label className="text-sm text-stone-400">Excluded Systems</label>
|
||||||
@@ -136,7 +128,8 @@ export const KillsSettingsDialog: React.FC<KillsSettingsDialogProps> = ({ visibl
|
|||||||
{excluded.length === 0 && <div className="text-stone-500 text-xs italic">No systems excluded.</div>}
|
{excluded.length === 0 && <div className="text-stone-500 text-xs italic">No systems excluded.</div>}
|
||||||
{excluded.map(sysId => (
|
{excluded.map(sysId => (
|
||||||
<div key={sysId} className="flex items-center justify-between border-b border-stone-600 py-1 px-1 text-xs">
|
<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 />
|
<SystemView systemId={sysId.toString()} hideRegion compact/>
|
||||||
|
|
||||||
<WdImgButton
|
<WdImgButton
|
||||||
className={PrimeIcons.TRASH}
|
className={PrimeIcons.TRASH}
|
||||||
onClick={() => handleRemoveSystem(sysId)}
|
onClick={() => handleRemoveSystem(sysId)}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
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>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -2,19 +2,19 @@ import { useMemo, useCallback } from 'react';
|
|||||||
import useLocalStorageState from 'use-local-storage-state';
|
import useLocalStorageState from 'use-local-storage-state';
|
||||||
|
|
||||||
export interface KillsWidgetSettings {
|
export interface KillsWidgetSettings {
|
||||||
|
compact: boolean;
|
||||||
showAll: boolean;
|
showAll: boolean;
|
||||||
whOnly: boolean;
|
whOnly: boolean;
|
||||||
excludedSystems: number[];
|
excludedSystems: number[];
|
||||||
version: number;
|
version: number;
|
||||||
timeRange: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_KILLS_WIDGET_SETTINGS: KillsWidgetSettings = {
|
export const DEFAULT_KILLS_WIDGET_SETTINGS: KillsWidgetSettings = {
|
||||||
|
compact: true,
|
||||||
showAll: false,
|
showAll: false,
|
||||||
whOnly: true,
|
whOnly: true,
|
||||||
excludedSystems: [],
|
excludedSystems: [],
|
||||||
version: 2,
|
version: 0,
|
||||||
timeRange: 1,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function mergeWithDefaults(settings?: Partial<KillsWidgetSettings>): KillsWidgetSettings {
|
function mergeWithDefaults(settings?: Partial<KillsWidgetSettings>): KillsWidgetSettings {
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
// useSystemKillsItemTemplate.tsx
|
|
||||||
import { useCallback } from 'react';
|
|
||||||
import { VirtualScrollerTemplateOptions } from 'primereact/virtualscroller';
|
|
||||||
import { DetailedKill } from '@/hooks/Mapper/types/kills';
|
|
||||||
import { KillItemTemplate } from '../components/KillItemTemplate';
|
|
||||||
|
|
||||||
export function useSystemKillsItemTemplate(systemNameMap: Record<string, string>, onlyOneSystem: boolean) {
|
|
||||||
return useCallback(
|
|
||||||
(kill: DetailedKill, options: VirtualScrollerTemplateOptions) =>
|
|
||||||
KillItemTemplate(systemNameMap, onlyOneSystem, kill, options),
|
|
||||||
[systemNameMap, onlyOneSystem],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
||||||
import { Widget } from '@/hooks/Mapper/components/mapInterface/components';
|
import { Widget } from '@/hooks/Mapper/components/mapInterface/components';
|
||||||
import {
|
import {
|
||||||
InfoDrawer,
|
InfoDrawer,
|
||||||
@@ -20,29 +19,28 @@ import {
|
|||||||
STRUCTURE,
|
STRUCTURE,
|
||||||
SystemSignatureSettingsDialog,
|
SystemSignatureSettingsDialog,
|
||||||
} from './SystemSignatureSettingsDialog';
|
} from './SystemSignatureSettingsDialog';
|
||||||
import { SignatureGroup, SystemSignature } from '@/hooks/Mapper/types';
|
import { SignatureGroup } from '@/hooks/Mapper/types';
|
||||||
|
|
||||||
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { PrimeIcons } from 'primereact/api';
|
import { PrimeIcons } from 'primereact/api';
|
||||||
|
|
||||||
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
|
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
|
||||||
import { CheckboxChangeEvent } from 'primereact/checkbox';
|
import { CheckboxChangeEvent } from 'primereact/checkbox';
|
||||||
import useMaxWidth from '@/hooks/Mapper/hooks/useMaxWidth';
|
import useMaxWidth from '@/hooks/Mapper/hooks/useMaxWidth.ts';
|
||||||
import { WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit/WdTooltipWrapper';
|
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_5';
|
const SIGNATURE_SETTINGS_KEY = 'wanderer_system_signature_settings_v5_2';
|
||||||
export const SHOW_DESCRIPTION_COLUMN_SETTING = 'show_description_column_setting';
|
export const SHOW_DESCRIPTION_COLUMN_SETTING = 'show_description_column_setting';
|
||||||
export const SHOW_UPDATED_COLUMN_SETTING = 'SHOW_UPDATED_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 LAZY_DELETE_SIGNATURES_SETTING = 'LAZY_DELETE_SIGNATURES_SETTING';
|
||||||
export const KEEP_LAZY_DELETE_SETTING = 'KEEP_LAZY_DELETE_ENABLED_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_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_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: 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: 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_ANOMALY, name: 'Show Anomalies', value: true, isFilter: true },
|
||||||
{ key: COSMIC_SIGNATURE, name: 'Show Cosmic Signatures', value: true, isFilter: true },
|
{ key: COSMIC_SIGNATURE, name: 'Show Cosmic Signatures', value: true, isFilter: true },
|
||||||
{ key: DEPLOYABLE, name: 'Show Deployables', value: true, isFilter: true },
|
{ key: DEPLOYABLE, name: 'Show Deployables', value: true, isFilter: true },
|
||||||
@@ -58,160 +56,121 @@ const SETTINGS: Setting[] = [
|
|||||||
{ key: SignatureGroup.CombatSite, name: 'Show Combat Sites', value: true, isFilter: true },
|
{ key: SignatureGroup.CombatSite, name: 'Show Combat Sites', value: true, isFilter: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
const getDefaultSettings = (): Setting[] => [...SETTINGS];
|
const defaultSettings = () => {
|
||||||
|
return [...settings];
|
||||||
|
};
|
||||||
|
|
||||||
export const SystemSignatures: React.FC = () => {
|
export const SystemSignatures = () => {
|
||||||
const {
|
const {
|
||||||
data: { selectedSystems },
|
data: { selectedSystems },
|
||||||
} = useMapRootState();
|
} = useMapRootState();
|
||||||
|
|
||||||
const [visible, setVisible] = useState(false);
|
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 [systemId] = selectedSystems;
|
||||||
|
|
||||||
const isNotSelectedSystem = selectedSystems.length !== 1;
|
const isNotSelectedSystem = selectedSystems.length !== 1;
|
||||||
|
|
||||||
const lazyDeleteValue = useMemo(
|
const lazyDeleteValue = useMemo(() => {
|
||||||
() => currentSettings.find(setting => setting.key === LAZY_DELETE_SIGNATURES_SETTING)?.value || false,
|
return settings.find(setting => setting.key === LAZY_DELETE_SIGNATURES_SETTING)!.value;
|
||||||
[currentSettings],
|
}, [settings]);
|
||||||
);
|
|
||||||
|
|
||||||
const handleSettingsChange = useCallback((newSettings: Setting[]) => {
|
const handleSettingsChange = useCallback((settings: Setting[]) => {
|
||||||
setCurrentSettings(newSettings);
|
setSettings(settings);
|
||||||
|
localStorage.setItem(SIGNATURE_SETTINGS_KEY, JSON.stringify(settings));
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleLazyDeleteChange = useCallback((value: boolean) => {
|
const handleLazyDeleteChange = useCallback((value: boolean) => {
|
||||||
setCurrentSettings(prevSettings =>
|
setSettings(settings => {
|
||||||
prevSettings.map(setting => (setting.key === LAZY_DELETE_SIGNATURES_SETTING ? { ...setting, value } : setting)),
|
const lazyDelete = settings.find(setting => setting.key === LAZY_DELETE_SIGNATURES_SETTING)!;
|
||||||
);
|
lazyDelete.value = value;
|
||||||
|
localStorage.setItem(SIGNATURE_SETTINGS_KEY, JSON.stringify(settings));
|
||||||
|
return [...settings];
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
useEffect(() => {
|
||||||
const isCompact = useMaxWidth(containerRef, COMPACT_MAX_WIDTH);
|
const restoredSettings = localStorage.getItem(SIGNATURE_SETTINGS_KEY);
|
||||||
|
|
||||||
useHotkey(true, ['z'], (event: KeyboardEvent) => {
|
if (restoredSettings) {
|
||||||
if (pendingSigs.length > 0) {
|
setSettings(JSON.parse(restoredSettings));
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
undoPending();
|
|
||||||
setPendingSigs([]);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const handleUndoClick = useCallback(() => {
|
|
||||||
undoPending();
|
|
||||||
setPendingSigs([]);
|
|
||||||
}, [undoPending]);
|
|
||||||
|
|
||||||
const handleSettingsButtonClick = useCallback(() => {
|
|
||||||
setVisible(true);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const renderLabel = () => (
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
<div className="flex justify-between items-center text-xs w-full h-full" ref={containerRef}>
|
const compact = useMaxWidth(ref, 260);
|
||||||
<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 (
|
return (
|
||||||
<Widget label={renderLabel()}>
|
<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>
|
||||||
|
}
|
||||||
|
>
|
||||||
{isNotSelectedSystem ? (
|
{isNotSelectedSystem ? (
|
||||||
<div className="w-full h-full flex justify-center items-center select-none text-center text-stone-400/80 text-sm">
|
<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
|
System is not selected
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<SystemSignaturesContent
|
<SystemSignaturesContent systemId={systemId} settings={settings} onLazyDeleteChange={handleLazyDeleteChange} />
|
||||||
systemId={systemId}
|
|
||||||
settings={currentSettings}
|
|
||||||
onLazyDeleteChange={handleLazyDeleteChange}
|
|
||||||
onCountChange={handleSigCountChange}
|
|
||||||
onPendingChange={(pending, undo) => {
|
|
||||||
setPendingSigs(pending);
|
|
||||||
setUndoPending(() => undo);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
{visible && (
|
{visible && (
|
||||||
<SystemSignatureSettingsDialog
|
<SystemSignatureSettingsDialog
|
||||||
settings={currentSettings}
|
settings={settings}
|
||||||
onCancel={() => setVisible(false)}
|
onCancel={() => setVisible(false)}
|
||||||
onSave={handleSettingsChange}
|
onSave={handleSettingsChange}
|
||||||
/>
|
/>
|
||||||
@@ -219,5 +178,3 @@ export const SystemSignatures: React.FC = () => {
|
|||||||
</Widget>
|
</Widget>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SystemSignatures;
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
.TableRowCompact {
|
||||||
|
height: 8px;
|
||||||
|
max-height: 8px;
|
||||||
|
font-size: 12px !important;
|
||||||
|
line-height: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Table {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,27 +1,29 @@
|
|||||||
import { useEffect, useMemo, useRef, useState, useCallback } from 'react';
|
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 { DataTable, DataTableRowClickEvent, DataTableRowMouseEvent, SortOrder } from 'primereact/datatable';
|
import { DataTable, DataTableRowClickEvent, DataTableRowMouseEvent, SortOrder } from 'primereact/datatable';
|
||||||
import { Column } from 'primereact/column';
|
import { Column } from 'primereact/column';
|
||||||
import { PrimeIcons } from 'primereact/api';
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import useLocalStorageState from 'use-local-storage-state';
|
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 { SignatureGroup, SystemSignature } from '@/hooks/Mapper/types';
|
import classes from './SystemSignaturesContent.module.scss';
|
||||||
import { SignatureSettings } from '@/hooks/Mapper/components/mapRootContent/components/SignatureSettings';
|
import clsx from 'clsx';
|
||||||
import { WdTooltip, WdTooltipHandlers, WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit';
|
import { SystemSignature } from '@/hooks/Mapper/types';
|
||||||
import { SignatureView } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/SignatureView';
|
import { SignatureView } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/SignatureView';
|
||||||
import {
|
import {
|
||||||
COMPACT_MAX_WIDTH,
|
getActualSigs,
|
||||||
GROUPS_LIST,
|
getRowColorByTimeLeft,
|
||||||
MEDIUM_MAX_WIDTH,
|
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/helpers';
|
||||||
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 {
|
import {
|
||||||
renderAddedTimeLeft,
|
renderAddedTimeLeft,
|
||||||
renderDescription,
|
renderDescription,
|
||||||
@@ -29,12 +31,18 @@ import {
|
|||||||
renderInfoColumn,
|
renderInfoColumn,
|
||||||
renderUpdatedTimeLeft,
|
renderUpdatedTimeLeft,
|
||||||
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/renders';
|
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/renders';
|
||||||
import { ExtendedSystemSignature } from '../helpers/contentHelpers';
|
import useLocalStorageState from 'use-local-storage-state';
|
||||||
import { useSystemSignaturesData } from '../hooks/useSystemSignaturesData';
|
import { PrimeIcons } from 'primereact/api';
|
||||||
import { getSignatureRowClass } from '../helpers/rowStyles';
|
import { SignatureSettings } from '@/hooks/Mapper/components/mapRootContent/components/SignatureSettings';
|
||||||
import useMaxWidth from '@/hooks/Mapper/hooks/useMaxWidth';
|
import { useMapEventListener } from '@/hooks/Mapper/events';
|
||||||
import { useClipboard, useHotkey } from '@/hooks/Mapper/hooks';
|
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';
|
||||||
type SystemSignaturesSortSettings = {
|
type SystemSignaturesSortSettings = {
|
||||||
sortField: string;
|
sortField: string;
|
||||||
sortOrder: SortOrder;
|
sortOrder: SortOrder;
|
||||||
@@ -47,292 +55,391 @@ const SORT_DEFAULT_VALUES: SystemSignaturesSortSettings = {
|
|||||||
|
|
||||||
interface SystemSignaturesContentProps {
|
interface SystemSignaturesContentProps {
|
||||||
systemId: string;
|
systemId: string;
|
||||||
settings: { key: string; value: boolean }[];
|
settings: Setting[];
|
||||||
hideLinkedSignatures?: boolean;
|
hideLinkedSignatures?: boolean;
|
||||||
selectable?: boolean;
|
selectable?: boolean;
|
||||||
onSelect?: (signature: SystemSignature) => void;
|
onSelect?: (signature: SystemSignature) => void;
|
||||||
onLazyDeleteChange?: (value: boolean) => 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,
|
systemId,
|
||||||
settings,
|
settings,
|
||||||
hideLinkedSignatures,
|
hideLinkedSignatures,
|
||||||
selectable,
|
selectable,
|
||||||
onSelect,
|
onSelect,
|
||||||
onLazyDeleteChange,
|
onLazyDeleteChange,
|
||||||
onCountChange,
|
}: SystemSignaturesContentProps) => {
|
||||||
onPendingChange,
|
const { outCommand } = useMapRootState();
|
||||||
}: SystemSignaturesContentProps) {
|
|
||||||
const { signatures, selectedSignatures, setSelectedSignatures, handleDeleteSelected, handleSelectAll, handlePaste } =
|
|
||||||
useSystemSignaturesData({
|
|
||||||
systemId,
|
|
||||||
settings,
|
|
||||||
onCountChange,
|
|
||||||
onPendingChange,
|
|
||||||
onLazyDeleteChange,
|
|
||||||
});
|
|
||||||
|
|
||||||
const [sortSettings, setSortSettings] = useLocalStorageState<{ sortField: string; sortOrder: SortOrder }>(
|
const [signatures, setSignatures, signaturesRef] = useRefState<SystemSignature[]>([]);
|
||||||
'window:signatures:sort',
|
const [selectedSignatures, setSelectedSignatures] = useState<SystemSignature[]>([]);
|
||||||
{ defaultValue: SORT_DEFAULT_VALUES },
|
const [nameColumnWidth, setNameColumnWidth] = useState('auto');
|
||||||
);
|
const [selectedSignature, setSelectedSignature] = useState<SystemSignature | null>(null);
|
||||||
|
|
||||||
const tableRef = useRef<HTMLDivElement>(null);
|
const [hoveredSig, setHoveredSig] = useState<SystemSignature | null>(null);
|
||||||
const tooltipRef = useRef<WdTooltipHandlers>(null);
|
|
||||||
const [hoveredSignature, setHoveredSignature] = useState<SystemSignature | null>(null);
|
|
||||||
|
|
||||||
const isCompact = useMaxWidth(tableRef, COMPACT_MAX_WIDTH);
|
const [sortSettings, setSortSettings] = useLocalStorageState<SystemSignaturesSortSettings>('window:signatures:sort', {
|
||||||
const isMedium = useMaxWidth(tableRef, MEDIUM_MAX_WIDTH);
|
defaultValue: SORT_DEFAULT_VALUES,
|
||||||
|
|
||||||
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 (selectable) return;
|
|
||||||
if (!clipboardContent?.text) return;
|
|
||||||
|
|
||||||
handlePaste(clipboardContent.text);
|
|
||||||
|
|
||||||
if (lazyDeleteEnabled && !keepLazyDeleteEnabled) {
|
|
||||||
onLazyDeleteChange?.(false);
|
|
||||||
}
|
|
||||||
setClipboardContent(null);
|
|
||||||
}, [
|
|
||||||
selectable,
|
|
||||||
clipboardContent,
|
|
||||||
handlePaste,
|
|
||||||
setClipboardContent,
|
|
||||||
lazyDeleteEnabled,
|
|
||||||
keepLazyDeleteEnabled,
|
|
||||||
onLazyDeleteChange,
|
|
||||||
]);
|
|
||||||
|
|
||||||
useHotkey(true, ['a'], handleSelectAll);
|
|
||||||
useHotkey(false, ['Backspace', 'Delete'], (event: KeyboardEvent) => {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
handleDeleteSelected();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [nameColumnWidth, setNameColumnWidth] = useState('auto');
|
const tableRef = useRef<HTMLDivElement>(null);
|
||||||
const handleResize = useCallback(() => {
|
const compact = useMaxWidth(tableRef, 260);
|
||||||
if (!tableRef.current) return;
|
const medium = useMaxWidth(tableRef, 380);
|
||||||
const tableWidth = tableRef.current.offsetWidth;
|
const refData = useRef({ selectable });
|
||||||
const otherColumnsWidth = OTHER_COLUMNS_WIDTH;
|
refData.current = { selectable };
|
||||||
setNameColumnWidth(`${tableWidth - otherColumnsWidth}px`);
|
|
||||||
}, []);
|
const tooltipRef = useRef<WdTooltipHandlers>(null);
|
||||||
useEffect(() => {
|
|
||||||
if (!tableRef.current) return;
|
const { clipboardContent, setClipboardContent } = useClipboard();
|
||||||
const observer = new ResizeObserver(handleResize);
|
|
||||||
observer.observe(tableRef.current);
|
const lazyDeleteValue = useMemo(() => {
|
||||||
handleResize();
|
return settings.find(setting => setting.key === LAZY_DELETE_SIGNATURES_SETTING)?.value ?? false;
|
||||||
return () => {
|
}, [settings]);
|
||||||
observer.disconnect();
|
|
||||||
};
|
const keepLazyDeleteValue = useMemo(() => {
|
||||||
}, [handleResize]);
|
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 },
|
||||||
|
});
|
||||||
|
|
||||||
|
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 handleDeleteSelected = useCallback(
|
||||||
|
async (e: KeyboardEvent) => {
|
||||||
|
if (selectable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (selectedSignatures.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (refData.current.selectable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!clipboardContent?.text) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePaste(clipboardContent.text);
|
||||||
|
setClipboardContent(null);
|
||||||
|
}, [clipboardContent, selectable, lazyDeleteValue, keepLazyDeleteValue]);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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 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 [showSignatureSettings, setShowSignatureSettings] = useState(false);
|
||||||
|
|
||||||
const handleRowClick = (e: DataTableRowClickEvent) => {
|
const handleRowClick = (e: DataTableRowClickEvent) => {
|
||||||
setSelectedSignatureForDialog(e.data as SystemSignature);
|
setSelectedSignature(e.data as SystemSignature);
|
||||||
setShowSignatureSettings(true);
|
setShowSignatureSettings(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
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 (
|
return (
|
||||||
<div ref={tableRef} className="h-full">
|
<>
|
||||||
{filteredSignatures.length === 0 ? (
|
<div ref={tableRef} className={'h-full '}>
|
||||||
<div className="w-full h-full flex justify-center items-center select-none text-stone-400/80 text-sm">
|
{filteredSignatures.length === 0 ? (
|
||||||
No signatures
|
<div className="w-full h-full flex justify-center items-center select-none text-stone-400/80 text-sm">
|
||||||
</div>
|
No signatures
|
||||||
) : (
|
</div>
|
||||||
<DataTable
|
) : (
|
||||||
value={filteredSignatures}
|
<>
|
||||||
size="small"
|
{/* @ts-ignore */}
|
||||||
selectionMode="multiple"
|
<DataTable
|
||||||
selection={selectedSignatures}
|
className={classes.Table}
|
||||||
metaKeySelection
|
value={filteredSignatures}
|
||||||
onSelectionChange={handleSelectSignatures}
|
size="small"
|
||||||
dataKey="eve_id"
|
selectionMode={selectable ? 'single' : 'multiple'}
|
||||||
className="w-full select-none"
|
selection={selectedSignatures}
|
||||||
resizableColumns={false}
|
metaKeySelection
|
||||||
rowHover
|
onSelectionChange={handleSelectSignatures}
|
||||||
selectAll
|
dataKey="eve_id"
|
||||||
onRowDoubleClick={handleRowClick}
|
tableClassName="w-full select-none"
|
||||||
sortField={sortSettings.sortField}
|
resizableColumns={false}
|
||||||
sortOrder={sortSettings.sortOrder}
|
onRowDoubleClick={handleRowClick}
|
||||||
onSort={e => setSortSettings({ sortField: e.sortField, sortOrder: e.sortOrder })}
|
rowHover
|
||||||
onRowMouseEnter={
|
selectAll
|
||||||
isCompact || isMedium
|
sortField={sortSettings.sortField}
|
||||||
? (e: DataTableRowMouseEvent) => {
|
sortOrder={sortSettings.sortOrder}
|
||||||
setHoveredSignature(filteredSignatures[e.index]);
|
onSort={event => setSortSettings(() => ({ sortField: event.sortField, sortOrder: event.sortOrder }))}
|
||||||
tooltipRef.current?.show(e.originalEvent);
|
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');
|
||||||
}
|
}
|
||||||
: undefined
|
|
||||||
}
|
const dateClass = getRowColorByTimeLeft(row.inserted_at ? new Date(row.inserted_at) : undefined);
|
||||||
onRowMouseLeave={
|
if (!dateClass) {
|
||||||
isCompact || isMedium
|
return clsx(classes.TableRowCompact, 'hover:bg-purple-400/20 transition duration-200');
|
||||||
? () => {
|
|
||||||
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 && (
|
return clsx(classes.TableRowCompact, dateClass);
|
||||||
<Column
|
}}
|
||||||
field="character_name"
|
>
|
||||||
header="Character"
|
<Column
|
||||||
bodyClassName="w-[70px] text-ellipsis overflow-hidden whitespace-nowrap"
|
bodyClassName="p-0 px-1"
|
||||||
sortable
|
field="group"
|
||||||
></Column>
|
body={x => renderIcon(x)}
|
||||||
)}
|
style={{ maxWidth: 26, minWidth: 26, width: 26, height: 25 }}
|
||||||
|
></Column>
|
||||||
|
|
||||||
{!selectable && (
|
<Column
|
||||||
<Column
|
field="eve_id"
|
||||||
header=""
|
header="Id"
|
||||||
headerStyle={headerInlineStyle}
|
bodyClassName="text-ellipsis overflow-hidden whitespace-nowrap"
|
||||||
body={() => (
|
style={{ maxWidth: 72, minWidth: 72, width: 72 }}
|
||||||
<div className="flex justify-end items-center gap-2 mr-[4px]">
|
sortable
|
||||||
<WdTooltipWrapper content="Double-click a row to edit signature">
|
></Column>
|
||||||
<span className={PrimeIcons.PENCIL + ' text-[10px]'} />
|
<Column
|
||||||
</WdTooltipWrapper>
|
field="group"
|
||||||
</div>
|
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>
|
||||||
)}
|
)}
|
||||||
style={{ maxWidth: 26, minWidth: 26, width: 26 }}
|
|
||||||
bodyClassName="p-0 pl-1 pr-2"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</DataTable>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<WdTooltip
|
<Column
|
||||||
className="bg-stone-900/95 text-slate-50"
|
field="inserted_at"
|
||||||
ref={tooltipRef}
|
header="Added"
|
||||||
content={hoveredSignature ? <SignatureView {...hoveredSignature} /> : null}
|
dataType="date"
|
||||||
/>
|
bodyClassName="w-[70px] text-ellipsis overflow-hidden whitespace-nowrap"
|
||||||
|
body={renderAddedTimeLeft}
|
||||||
|
sortable
|
||||||
|
></Column>
|
||||||
|
|
||||||
{showSignatureSettings && (
|
{showUpdatedColumn && (
|
||||||
<SignatureSettings
|
<Column
|
||||||
systemId={systemId}
|
field="updated_at"
|
||||||
show
|
header="Updated"
|
||||||
onHide={() => setShowSignatureSettings(false)}
|
dataType="date"
|
||||||
signatureData={selectedSignatureForDialog || undefined}
|
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}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
{showSignatureSettings && (
|
||||||
|
<SignatureSettings
|
||||||
|
systemId={systemId}
|
||||||
|
show
|
||||||
|
onHide={() => setShowSignatureSettings(false)}
|
||||||
|
signatureData={selectedSignature}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -10,13 +10,6 @@ import {
|
|||||||
|
|
||||||
export const TIME_ONE_MINUTE = 1000 * 60;
|
export const TIME_ONE_MINUTE = 1000 * 60;
|
||||||
export const TIME_TEN_MINUTES = 1000 * 60 * 10;
|
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 = [
|
export const GROUPS_LIST = [
|
||||||
SignatureGroup.GasSite,
|
SignatureGroup.GasSite,
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
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,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,67 +1,25 @@
|
|||||||
import { SystemSignature } from '@/hooks/Mapper/types';
|
import { SystemSignature } from '@/hooks/Mapper/types';
|
||||||
import { GROUPS_LIST } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants';
|
import { GROUPS_LIST } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts';
|
||||||
import { getState } from './getState';
|
import { getState } from './getState.ts';
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 = (
|
export const getActualSigs = (
|
||||||
oldSignatures: SystemSignature[],
|
oldSignatures: SystemSignature[],
|
||||||
newSignatures: SystemSignature[],
|
newSignatures: SystemSignature[],
|
||||||
updateOnly?: boolean,
|
updateOnly: boolean,
|
||||||
skipUpdateUntouched?: boolean,
|
skipUpdateUntouched?: boolean,
|
||||||
): { added: SystemSignature[]; updated: SystemSignature[]; removed: SystemSignature[] } => {
|
): { added: SystemSignature[]; updated: SystemSignature[]; removed: SystemSignature[] } => {
|
||||||
const updated: SystemSignature[] = [];
|
const updated: SystemSignature[] = [];
|
||||||
const removed: SystemSignature[] = [];
|
const removed: SystemSignature[] = [];
|
||||||
const added: SystemSignature[] = [];
|
|
||||||
|
|
||||||
oldSignatures.forEach(oldSig => {
|
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);
|
const newSig = newSignatures.find(s => s.eve_id === oldSig.eve_id);
|
||||||
if (newSig) {
|
if (newSig) {
|
||||||
const needUpgrade = getState(GROUPS_LIST, newSig) > getState(GROUPS_LIST, oldSig);
|
// we take new sig and now we need check that sig has been updated
|
||||||
const mergedSig = { ...oldSig };
|
const isNeedUpgrade = getState(GROUPS_LIST, newSig) > getState(GROUPS_LIST, oldSig);
|
||||||
let changed = false;
|
if (isNeedUpgrade) {
|
||||||
|
updated.push({ ...oldSig, group: newSig.group, name: newSig.name });
|
||||||
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) {
|
} else if (!skipUpdateUntouched) {
|
||||||
updated.push({ ...oldSig });
|
updated.push({ ...oldSig });
|
||||||
}
|
}
|
||||||
@@ -72,12 +30,8 @@ export const getActualSigs = (
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const oldIds = new Set(oldSignatures.map(x => x.eve_id));
|
const oldSignaturesIds = oldSignatures.map(x => x.eve_id);
|
||||||
newSignatures.forEach(s => {
|
const added = newSignatures.filter(s => !oldSignaturesIds.includes(s.eve_id));
|
||||||
if (!oldIds.has(s.eve_id)) {
|
|
||||||
added.push(s);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return { added, updated, removed };
|
return { added, updated, removed };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import {
|
|||||||
TIME_TEN_MINUTES,
|
TIME_TEN_MINUTES,
|
||||||
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts';
|
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts';
|
||||||
|
|
||||||
export const getRowBackgroundColor = (date: Date | undefined): string => {
|
export const getRowColorByTimeLeft = (date: Date | undefined) => {
|
||||||
if (!date) {
|
if (!date) {
|
||||||
return '';
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
@@ -18,6 +18,4 @@ export const getRowBackgroundColor = (date: Date | undefined): string => {
|
|||||||
if (diff < TIME_TEN_MINUTES) {
|
if (diff < TIME_TEN_MINUTES) {
|
||||||
return 'bg-lime-700/40 transition hover:bg-lime-700/50';
|
return 'bg-lime-700/40 transition hover:bg-lime-700/50';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
|
||||||
};
|
};
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
import { SystemSignature } from '@/hooks/Mapper/types';
|
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) => {
|
export const getState = (_: string[], newSig: SystemSignature) => {
|
||||||
let state = -1;
|
let state = -1;
|
||||||
if (!newSig.group) {
|
if (!newSig.group || newSig.group === '') {
|
||||||
state = 0;
|
state = 0;
|
||||||
} else if (!newSig.name || newSig.name === '') {
|
} else if (!newSig.name || newSig.name === '') {
|
||||||
state = 1;
|
state = 1;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
export * from './getState';
|
export * from './getState';
|
||||||
export * from './getRowBackgroundColor';
|
export * from './getRowColorByTimeLeft';
|
||||||
export * from './getActualSigs';
|
export * from './getActualSigs';
|
||||||
export * from './contentHelpers';
|
|
||||||
export * from './rowStyles';
|
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
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',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
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[]>>;
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,204 +0,0 @@
|
|||||||
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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -24,12 +24,6 @@ export const renderInfoColumn = (row: SystemSignature) => {
|
|||||||
</WdTooltipWrapper>
|
</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 && (
|
{row.type && (
|
||||||
<WHClassView
|
<WHClassView
|
||||||
className="text-[11px]"
|
className="text-[11px]"
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export interface MapSettingsProps {
|
|||||||
systemId: string;
|
systemId: string;
|
||||||
show: boolean;
|
show: boolean;
|
||||||
onHide: () => void;
|
onHide: () => void;
|
||||||
signatureData: SystemSignature | undefined;
|
signatureData: SystemSignature | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SignatureSettings = ({ systemId, show, onHide, signatureData }: MapSettingsProps) => {
|
export const SignatureSettings = ({ systemId, show, onHide, signatureData }: MapSettingsProps) => {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export const MapWrapper = () => {
|
|||||||
const {
|
const {
|
||||||
update,
|
update,
|
||||||
outCommand,
|
outCommand,
|
||||||
data: { selectedConnections, selectedSystems, hubs, systems, linkSignatureToSystem },
|
data: { selectedConnections, selectedSystems, hubs, systems, connections, linkSignatureToSystem },
|
||||||
interfaceSettings: {
|
interfaceSettings: {
|
||||||
isShowMenu,
|
isShowMenu,
|
||||||
isShowMinimap = STORED_INTERFACE_DEFAULT_VALUES.isShowMinimap,
|
isShowMinimap = STORED_INTERFACE_DEFAULT_VALUES.isShowMinimap,
|
||||||
@@ -56,8 +56,8 @@ export const MapWrapper = () => {
|
|||||||
const [openAddSystem, setOpenAddSystem] = useState<XYPosition | null>(null);
|
const [openAddSystem, setOpenAddSystem] = useState<XYPosition | null>(null);
|
||||||
const [selectedConnection, setSelectedConnection] = useState<SolarSystemConnection | null>(null);
|
const [selectedConnection, setSelectedConnection] = useState<SolarSystemConnection | null>(null);
|
||||||
|
|
||||||
const ref = useRef({ selectedConnections, selectedSystems, systemContextProps, systems, deleteSystems });
|
const ref = useRef({ selectedConnections, selectedSystems, systemContextProps, systems, connections, deleteSystems });
|
||||||
ref.current = { selectedConnections, selectedSystems, systemContextProps, systems, deleteSystems };
|
ref.current = { selectedConnections, selectedSystems, systemContextProps, systems, connections, deleteSystems };
|
||||||
|
|
||||||
useMapEventListener(event => {
|
useMapEventListener(event => {
|
||||||
runCommand(event);
|
runCommand(event);
|
||||||
@@ -125,6 +125,11 @@ export const MapWrapper = () => {
|
|||||||
setOpenAddSystem(coordinates);
|
setOpenAddSystem(coordinates);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const canRemoveConnection = useCallback((connectionId: string) => {
|
||||||
|
const { connections } = ref.current;
|
||||||
|
return !connections.some(x => x.id === connectionId);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleSubmitAddSystem: SearchOnSubmitCallback = useCallback(
|
const handleSubmitAddSystem: SearchOnSubmitCallback = useCallback(
|
||||||
async item => {
|
async item => {
|
||||||
if (ref.current.systems.some(x => x.system_static_info.solar_system_id === item.value)) {
|
if (ref.current.systems.some(x => x.system_static_info.solar_system_id === item.value)) {
|
||||||
@@ -161,6 +166,7 @@ export const MapWrapper = () => {
|
|||||||
isSoftBackground={isSoftBackground}
|
isSoftBackground={isSoftBackground}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
onAddSystem={onAddSystem}
|
onAddSystem={onAddSystem}
|
||||||
|
canRemoveConnection={canRemoveConnection}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{openSettings != null && (
|
{openSettings != null && (
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ import { WORMHOLES_ADDITIONAL_INFO } from '@/hooks/Mapper/components/map/constan
|
|||||||
import { WormholeDataRaw } from '@/hooks/Mapper/types';
|
import { WormholeDataRaw } from '@/hooks/Mapper/types';
|
||||||
|
|
||||||
export const sortWHClasses = (wormholesData: Record<string, WormholeDataRaw>, statics: string[]) => {
|
export const sortWHClasses = (wormholesData: Record<string, WormholeDataRaw>, statics: string[]) => {
|
||||||
if (!statics || !wormholesData) {
|
if (!statics) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return statics
|
return statics
|
||||||
.map(x => wormholesData[x])
|
.map(x => wormholesData[x])
|
||||||
.filter(x => !!x)
|
|
||||||
.map(x => ({ name: x.name, ...WORMHOLES_ADDITIONAL_INFO[x.dest] }))
|
.map(x => ({ name: x.name, ...WORMHOLES_ADDITIONAL_INFO[x.dest] }))
|
||||||
.sort((a, b) => a.wormholeClassID - b.wormholeClassID)
|
.sort((a, b) => a.wormholeClassID - b.wormholeClassID)
|
||||||
.map(x => x.name);
|
.map(x => x.name);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export interface DetailedKill {
|
|||||||
victim_ship_type_id?: number | null;
|
victim_ship_type_id?: number | null;
|
||||||
victim_ship_name?: string;
|
victim_ship_name?: string;
|
||||||
|
|
||||||
|
|
||||||
final_blow_char_id?: number | null;
|
final_blow_char_id?: number | null;
|
||||||
final_blow_char_name?: string;
|
final_blow_char_name?: string;
|
||||||
final_blow_corp_id?: number | null;
|
final_blow_corp_id?: number | null;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CharacterTypeRaw, SolarSystemStaticInfoRaw } from '@/hooks/Mapper/types';
|
import { SolarSystemStaticInfoRaw } from '@/hooks/Mapper/types';
|
||||||
|
|
||||||
export enum SignatureGroup {
|
export enum SignatureGroup {
|
||||||
CosmicSignature = 'Cosmic Signature',
|
CosmicSignature = 'Cosmic Signature',
|
||||||
@@ -33,8 +33,6 @@ export type SignatureCustomInfo = {
|
|||||||
|
|
||||||
export type SystemSignature = {
|
export type SystemSignature = {
|
||||||
eve_id: string;
|
eve_id: string;
|
||||||
character_eve_id: string;
|
|
||||||
character_name?: string;
|
|
||||||
kind: SignatureKind;
|
kind: SignatureKind;
|
||||||
name: string;
|
name: string;
|
||||||
// SignatureCustomInfo
|
// SignatureCustomInfo
|
||||||
|
|||||||
@@ -1,31 +1,18 @@
|
|||||||
import { useCallback, useRef, useState, useEffect } from 'react';
|
import { useCallback, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { ContextStoreDataOpts, ProvideConstateDataReturnType, ContextStoreDataUpdate, UpdateFunc } from './types';
|
import { ContextStoreDataOpts, ProvideConstateDataReturnType, ContextStoreDataUpdate } from './types';
|
||||||
|
|
||||||
export const useContextStore = <T>(
|
export const useContextStore = <T>(
|
||||||
initialValue: T,
|
initialValue: T,
|
||||||
{ notNeedRerender = false, handleBeforeUpdate, onAfterAUpdate }: ContextStoreDataOpts<T> = {},
|
{ notNeedRerender = false, handleBeforeUpdate, onAfterAUpdate }: ContextStoreDataOpts<T> = {},
|
||||||
): ProvideConstateDataReturnType<T> => {
|
): ProvideConstateDataReturnType<T> => {
|
||||||
const ref = useRef<T>(initialValue);
|
const ref = useRef<T>(initialValue);
|
||||||
const queueRef = useRef<{ valOrFunc: Partial<T> | UpdateFunc<T>; force: boolean }[]>([]);
|
|
||||||
const [, setRerenderKey] = useState(0);
|
const [, setRerenderKey] = useState(0);
|
||||||
|
|
||||||
const refWrapper = useRef({ notNeedRerender, handleBeforeUpdate, onAfterAUpdate });
|
const refWrapper = useRef({ notNeedRerender, handleBeforeUpdate, onAfterAUpdate });
|
||||||
refWrapper.current = { notNeedRerender, handleBeforeUpdate, onAfterAUpdate };
|
refWrapper.current = { notNeedRerender, handleBeforeUpdate, onAfterAUpdate };
|
||||||
|
|
||||||
const update: ContextStoreDataUpdate<T> = useCallback((valOrFunc, force = false) => {
|
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
|
// It need to force prevent unnecessary rerendering
|
||||||
// update will create once
|
// update will create once
|
||||||
const { notNeedRerender, handleBeforeUpdate, onAfterAUpdate } = refWrapper.current;
|
const { notNeedRerender, handleBeforeUpdate, onAfterAUpdate } = refWrapper.current;
|
||||||
@@ -89,19 +76,5 @@ export const useContextStore = <T>(
|
|||||||
onAfterAUpdate?.(ref.current);
|
onAfterAUpdate?.(ref.current);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let requestId: number;
|
|
||||||
const process = () => {
|
|
||||||
processNextQueue();
|
|
||||||
requestId = requestAnimationFrame(process);
|
|
||||||
};
|
|
||||||
|
|
||||||
process();
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
cancelAnimationFrame(requestId);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return { update, ref: ref.current };
|
return { update, ref: ref.current };
|
||||||
};
|
};
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB |
@@ -53,11 +53,6 @@ public_api_disabled =
|
|||||||
|> get_var_from_path_or_env("WANDERER_PUBLIC_API_DISABLED", "false")
|
|> get_var_from_path_or_env("WANDERER_PUBLIC_API_DISABLED", "false")
|
||||||
|> String.to_existing_atom()
|
|> 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 =
|
zkill_preload_disabled =
|
||||||
config_dir
|
config_dir
|
||||||
|> get_var_from_path_or_env("WANDERER_ZKILL_PRELOAD_DISABLED", "false")
|
|> get_var_from_path_or_env("WANDERER_ZKILL_PRELOAD_DISABLED", "false")
|
||||||
@@ -128,7 +123,6 @@ config :wanderer_app,
|
|||||||
corp_id: System.get_env("WANDERER_CORP_ID", "-1") |> String.to_integer(),
|
corp_id: System.get_env("WANDERER_CORP_ID", "-1") |> String.to_integer(),
|
||||||
corp_wallet: System.get_env("WANDERER_CORP_WALLET", ""),
|
corp_wallet: System.get_env("WANDERER_CORP_WALLET", ""),
|
||||||
public_api_disabled: public_api_disabled,
|
public_api_disabled: public_api_disabled,
|
||||||
character_api_disabled: character_api_disabled,
|
|
||||||
zkill_preload_disabled: zkill_preload_disabled,
|
zkill_preload_disabled: zkill_preload_disabled,
|
||||||
map_subscriptions_enabled: map_subscriptions_enabled,
|
map_subscriptions_enabled: map_subscriptions_enabled,
|
||||||
map_connection_auto_expire_hours: map_connection_auto_expire_hours,
|
map_connection_auto_expire_hours: map_connection_auto_expire_hours,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ defmodule WandererApp.Api.AccessList do
|
|||||||
|
|
||||||
code_interface do
|
code_interface do
|
||||||
define(:create, action: :create)
|
define(:create, action: :create)
|
||||||
|
|
||||||
define(:available, action: :available)
|
define(:available, action: :available)
|
||||||
define(:new, action: :new)
|
define(:new, action: :new)
|
||||||
define(:read, action: :read)
|
define(:read, action: :read)
|
||||||
@@ -38,8 +39,7 @@ defmodule WandererApp.Api.AccessList do
|
|||||||
end
|
end
|
||||||
|
|
||||||
create :new do
|
create :new do
|
||||||
# Added :api_key to the accepted attributes
|
accept [:name, :description, :owner_id]
|
||||||
accept [:name, :description, :owner_id, :api_key]
|
|
||||||
primary?(true)
|
primary?(true)
|
||||||
|
|
||||||
argument :owner_id, :uuid, allow_nil?: false
|
argument :owner_id, :uuid, allow_nil?: false
|
||||||
@@ -48,7 +48,7 @@ defmodule WandererApp.Api.AccessList do
|
|||||||
end
|
end
|
||||||
|
|
||||||
update :update do
|
update :update do
|
||||||
accept [:name, :description, :owner_id, :api_key]
|
accept [:name, :description, :owner_id]
|
||||||
primary?(true)
|
primary?(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -68,10 +68,6 @@ defmodule WandererApp.Api.AccessList do
|
|||||||
allow_nil? true
|
allow_nil? true
|
||||||
end
|
end
|
||||||
|
|
||||||
attribute :api_key, :string do
|
|
||||||
allow_nil? true
|
|
||||||
end
|
|
||||||
|
|
||||||
create_timestamp(:inserted_at)
|
create_timestamp(:inserted_at)
|
||||||
update_timestamp(:updated_at)
|
update_timestamp(:updated_at)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ defmodule WandererApp.Env do
|
|||||||
def invites, do: get_key(:invites, false)
|
def invites, do: get_key(:invites, false)
|
||||||
def map_subscriptions_enabled?, do: get_key(:map_subscriptions_enabled, false)
|
def map_subscriptions_enabled?, do: get_key(:map_subscriptions_enabled, false)
|
||||||
def public_api_disabled?, do: get_key(:public_api_disabled, 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 zkill_preload_disabled?, do: get_key(:zkill_preload_disabled, false)
|
||||||
def wallet_tracking_enabled?, do: get_key(:wallet_tracking_enabled, false)
|
def wallet_tracking_enabled?, do: get_key(:wallet_tracking_enabled, false)
|
||||||
def admins, do: get_key(:admins, [])
|
def admins, do: get_key(:admins, [])
|
||||||
|
|||||||
@@ -237,12 +237,6 @@ defmodule WandererApp.Map.Server do
|
|||||||
|> map_pid!
|
|> map_pid!
|
||||||
|> GenServer.cast({&Impl.update_connection_custom_info/2, [connection_info]})
|
|> 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
|
@impl true
|
||||||
def handle_continue(:load_state, state),
|
def handle_continue(:load_state, state),
|
||||||
do: {:noreply, state |> Impl.load_state(), {:continue, :start_map}}
|
do: {:noreply, state |> Impl.load_state(), {:continue, :start_map}}
|
||||||
|
|||||||
@@ -4,13 +4,7 @@ defmodule WandererApp.Map.Server.Impl do
|
|||||||
"""
|
"""
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
alias WandererApp.Map.Server.{
|
alias WandererApp.Map.Server.{AclsImpl, CharactersImpl, ConnectionsImpl, SystemsImpl}
|
||||||
AclsImpl,
|
|
||||||
CharactersImpl,
|
|
||||||
ConnectionsImpl,
|
|
||||||
SystemsImpl,
|
|
||||||
SignaturesImpl
|
|
||||||
}
|
|
||||||
|
|
||||||
@enforce_keys [
|
@enforce_keys [
|
||||||
:map_id
|
:map_id
|
||||||
@@ -186,9 +180,7 @@ defmodule WandererApp.Map.Server.Impl do
|
|||||||
|
|
||||||
defdelegate update_connection_locked(state, connection_update), to: ConnectionsImpl
|
defdelegate update_connection_locked(state, connection_update), to: ConnectionsImpl
|
||||||
|
|
||||||
defdelegate update_connection_custom_info(state, signatures_update), to: ConnectionsImpl
|
defdelegate update_connection_custom_info(state, connection_update), to: ConnectionsImpl
|
||||||
|
|
||||||
defdelegate update_signatures(state, signatures_update), to: SignaturesImpl
|
|
||||||
|
|
||||||
def import_settings(%{map_id: map_id} = state, settings, user_id) do
|
def import_settings(%{map_id: map_id} = state, settings, user_id) do
|
||||||
WandererApp.Cache.put(
|
WandererApp.Cache.put(
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -278,7 +278,7 @@ defmodule WandererApp.Map.Server.SystemsImpl do
|
|||||||
|
|
||||||
linked_system_ids
|
linked_system_ids
|
||||||
|> Enum.each(fn linked_system_id ->
|
|> Enum.each(fn linked_system_id ->
|
||||||
update_system_linked_sig_eve_id(state, %{
|
WandererApp.Map.Server.update_system_linked_sig_eve_id(map_id, %{
|
||||||
solar_system_id: linked_system_id,
|
solar_system_id: linked_system_id,
|
||||||
linked_sig_eve_id: nil
|
linked_sig_eve_id: nil
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -295,34 +295,4 @@ defmodule WandererApp.Maps do
|
|||||||
|
|
||||||
character_eve_ids |> Enum.any?(fn eve_id -> eve_id in acl_roles_eve_ids end)
|
character_eve_ids |> Enum.any?(fn eve_id -> eve_id in acl_roles_eve_ids end)
|
||||||
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
|
end
|
||||||
|
|||||||
@@ -64,18 +64,6 @@ defmodule WandererAppWeb.Layouts do
|
|||||||
"""
|
"""
|
||||||
end
|
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
|
def feedback_container(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.link
|
<.link
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
/>
|
/>
|
||||||
</aside>
|
</aside>
|
||||||
<.ping_container rtt_class={@rtt_class} />
|
<.ping_container rtt_class={@rtt_class} />
|
||||||
<.donate_container />
|
|
||||||
<.feedback_container />
|
<.feedback_container />
|
||||||
<.new_version_banner app_version={@app_version} />
|
<.new_version_banner app_version={@app_version} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,259 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
defmodule WandererAppWeb.Plugs.CheckAclApiKey do
|
|
||||||
@moduledoc """
|
|
||||||
A plug that checks the "Authorization: Bearer <token>" header
|
|
||||||
against the ACL’s 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
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -5,7 +5,6 @@ defmodule WandererAppWeb.Plugs.CheckMapApiKey do
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
alias WandererAppWeb.UtilAPIController, as: Util
|
|
||||||
|
|
||||||
def init(opts), do: opts
|
def init(opts), do: opts
|
||||||
|
|
||||||
@@ -14,19 +13,27 @@ defmodule WandererAppWeb.Plugs.CheckMapApiKey do
|
|||||||
|
|
||||||
case header do
|
case header do
|
||||||
"Bearer " <> incoming_token ->
|
"Bearer " <> incoming_token ->
|
||||||
case fetch_map(conn.query_params) do
|
case fetch_map_id(conn.query_params) do
|
||||||
{:ok, map} ->
|
{:ok, map_id} ->
|
||||||
if map.public_api_key == incoming_token do
|
case WandererApp.Api.Map.by_id(map_id) do
|
||||||
conn
|
{:ok, map} ->
|
||||||
else
|
if map.public_api_key == incoming_token do
|
||||||
conn
|
conn
|
||||||
|> send_resp(401, "Unauthorized (invalid token for map)")
|
else
|
||||||
|> halt()
|
conn
|
||||||
|
|> send_resp(401, "Unauthorized (invalid token for map)")
|
||||||
|
|> halt()
|
||||||
|
end
|
||||||
|
|
||||||
|
{:error, _reason} ->
|
||||||
|
conn
|
||||||
|
|> send_resp(404, "Map not found")
|
||||||
|
|> halt()
|
||||||
end
|
end
|
||||||
|
|
||||||
{:error, _reason} ->
|
{:error, msg} ->
|
||||||
conn
|
conn
|
||||||
|> send_resp(404, "Map not found")
|
|> send_resp(400, msg)
|
||||||
|> halt()
|
|> halt()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,13 +44,19 @@ defmodule WandererAppWeb.Plugs.CheckMapApiKey do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp fetch_map(query_params) do
|
defp fetch_map_id(%{"map_id" => mid}) when is_binary(mid) and mid != "" do
|
||||||
case Util.fetch_map_id(query_params) do
|
{:ok, mid}
|
||||||
{:ok, map_id} ->
|
end
|
||||||
WandererApp.Api.Map.by_id(map_id)
|
|
||||||
|
|
||||||
error ->
|
defp fetch_map_id(%{"slug" => slug}) when is_binary(slug) and slug != "" do
|
||||||
error
|
case WandererApp.Api.Map.get_map_by_slug(slug) do
|
||||||
|
{:ok, map} ->
|
||||||
|
{:ok, map.id}
|
||||||
|
|
||||||
|
{:error, _reason} ->
|
||||||
|
{:error, "No map found for slug=#{slug}"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp fetch_map_id(_), do: {:error, "Must provide either ?map_id=UUID or ?slug=SLUG"}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
defmodule WandererAppWeb.Plugs.CheckMapSubscription do
|
|
||||||
@moduledoc """
|
|
||||||
A plug that checks the Map has active subscription
|
|
||||||
Halts with 401 if no active subscription.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import Plug.Conn
|
|
||||||
|
|
||||||
def init(opts), do: opts
|
|
||||||
|
|
||||||
def call(conn, _opts) do
|
|
||||||
case fetch_map_id(conn.query_params) do
|
|
||||||
{:ok, map_id} ->
|
|
||||||
{:ok, is_subscription_active} = map_id |> WandererApp.Map.is_subscription_active?()
|
|
||||||
|
|
||||||
if is_subscription_active do
|
|
||||||
conn
|
|
||||||
else
|
|
||||||
conn
|
|
||||||
|> send_resp(401, "Unauthorized (map subscription not active)")
|
|
||||||
|> halt()
|
|
||||||
end
|
|
||||||
|
|
||||||
{:error, msg} ->
|
|
||||||
conn
|
|
||||||
|> send_resp(400, msg)
|
|
||||||
|> halt()
|
|
||||||
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.id}
|
|
||||||
|
|
||||||
{: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
|
|
||||||
@@ -314,24 +314,6 @@ defmodule WandererAppWeb.AccessListsLive do
|
|||||||
end
|
end
|
||||||
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
|
@impl true
|
||||||
def handle_info(
|
def handle_info(
|
||||||
{"update_role", %{member_id: member_id, role: role}},
|
{"update_role", %{member_id: member_id, role: role}},
|
||||||
@@ -346,6 +328,17 @@ defmodule WandererAppWeb.AccessListsLive do
|
|||||||
{:noreply, socket |> maybe_update_role(member, role_atom, access_list)}
|
{:noreply, socket |> maybe_update_role(member, role_atom, access_list)}
|
||||||
end
|
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
|
@impl true
|
||||||
def handle_info({:search, text}, socket) do
|
def handle_info({:search, text}, socket) do
|
||||||
active_character_id =
|
active_character_id =
|
||||||
|
|||||||
@@ -142,50 +142,6 @@
|
|||||||
placeholder="Select an owner"
|
placeholder="Select an owner"
|
||||||
options={Enum.map(@characters, fn character -> {character.label, character.id} end)}
|
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">
|
<div class="modal-action">
|
||||||
<.button class="mt-2" type="submit" phx-disable-with="Saving...">
|
<.button class="mt-2" type="submit" phx-disable-with="Saving...">
|
||||||
<%= (@live_action == :create && "Create") || "Save" %>
|
<%= (@live_action == :create && "Create") || "Save" %>
|
||||||
|
|||||||
@@ -89,30 +89,132 @@ defmodule WandererAppWeb.MapSignaturesEventHandler do
|
|||||||
}
|
}
|
||||||
} = socket
|
} = socket
|
||||||
) do
|
) do
|
||||||
first_character_eve_id =
|
WandererApp.Api.MapSystem.read_by_map_and_solar_system(%{
|
||||||
user_characters |> List.first()
|
map_id: map_id,
|
||||||
|
solar_system_id: solar_system_id |> String.to_integer()
|
||||||
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()
|
||||||
|
|
||||||
{:noreply, socket}
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_ui_event(
|
def handle_ui_event(
|
||||||
@@ -275,7 +377,6 @@ defmodule WandererAppWeb.MapSignaturesEventHandler do
|
|||||||
s
|
s
|
||||||
|> Map.take([
|
|> Map.take([
|
||||||
:eve_id,
|
:eve_id,
|
||||||
:character_eve_id,
|
|
||||||
:name,
|
:name,
|
||||||
:description,
|
:description,
|
||||||
:kind,
|
:kind,
|
||||||
@@ -287,4 +388,26 @@ defmodule WandererAppWeb.MapSignaturesEventHandler do
|
|||||||
|> Map.put(:inserted_at, inserted_at |> Calendar.strftime("%Y/%m/%d %H:%M:%S"))
|
|> 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"))
|
|> Map.put(:updated_at, updated_at |> Calendar.strftime("%Y/%m/%d %H:%M:%S"))
|
||||||
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
|
end
|
||||||
|
|||||||
@@ -10,38 +10,57 @@ defmodule WandererAppWeb.MapAuditLive do
|
|||||||
def mount(
|
def mount(
|
||||||
%{"slug" => map_slug, "period" => period, "activity" => activity} = _params,
|
%{"slug" => map_slug, "period" => period, "activity" => activity} = _params,
|
||||||
_session,
|
_session,
|
||||||
%{assigns: %{current_user: current_user}} = socket
|
socket
|
||||||
) do
|
) do
|
||||||
WandererApp.Maps.check_user_can_delete_map(map_slug, current_user)
|
current_user = socket.assigns.current_user
|
||||||
|
|
||||||
|
map_slug
|
||||||
|
|> WandererApp.Api.Map.get_map_by_slug()
|
||||||
|
|> Ash.load([:acls, :user_permissions], actor: current_user)
|
||||||
|> case do
|
|> case do
|
||||||
{:ok,
|
{:ok,
|
||||||
%{
|
%{
|
||||||
id: map_id,
|
id: map_id,
|
||||||
name: map_name
|
user_permissions: user_permissions,
|
||||||
|
name: map_name,
|
||||||
|
owner_id: owner_id
|
||||||
} = _map} ->
|
} = _map} ->
|
||||||
{:ok, is_subscription_active} = map_id |> WandererApp.Map.is_subscription_active?()
|
user_permissions =
|
||||||
|
WandererApp.Permissions.get_map_permissions(
|
||||||
|
user_permissions,
|
||||||
|
owner_id,
|
||||||
|
current_user.characters |> Enum.map(& &1.id)
|
||||||
|
)
|
||||||
|
|
||||||
{:ok,
|
case user_permissions.delete_map do
|
||||||
socket
|
true ->
|
||||||
|> assign(
|
{:ok, is_subscription_active} = map_id |> WandererApp.Map.is_subscription_active?()
|
||||||
map_id: map_id,
|
|
||||||
map_name: map_name,
|
{:ok,
|
||||||
map_slug: map_slug,
|
socket
|
||||||
map_subscription_active: is_subscription_active,
|
|> assign(
|
||||||
activity: activity,
|
map_id: map_id,
|
||||||
can_undo_types: [:systems_removed],
|
map_name: map_name,
|
||||||
period: period || "1H",
|
map_slug: map_slug,
|
||||||
page: 1,
|
map_subscription_active: is_subscription_active,
|
||||||
per_page: 25,
|
activity: activity,
|
||||||
end_of_stream?: false
|
can_undo_types: [:systems_removed],
|
||||||
)
|
period: period || "1H",
|
||||||
|> stream(:activity, [])}
|
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,
|
{:ok, socket}
|
||||||
socket
|
|
||||||
|> put_flash(:error, "You don't have an access.")
|
|
||||||
|> push_navigate(to: ~p"/maps")}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -166,17 +166,6 @@ defmodule WandererAppWeb.MapEventHandler do
|
|||||||
when event_name in @map_kills_events,
|
when event_name in @map_kills_events,
|
||||||
do: MapKillsEventHandler.handle_server_event(event, socket)
|
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
|
def handle_event(socket, {ref, result}) when is_reference(ref) do
|
||||||
Process.demonitor(ref, [:flush])
|
Process.demonitor(ref, [:flush])
|
||||||
|
|
||||||
|
|||||||
@@ -37,14 +37,7 @@ defmodule WandererAppWeb.MapsLive do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, _session, socket) do
|
def mount(_params, _session, socket) do
|
||||||
{:ok,
|
{:ok, socket |> assign(maps: [], characters: [], location: nil)}
|
||||||
socket
|
|
||||||
|> assign(
|
|
||||||
maps: [],
|
|
||||||
characters: [],
|
|
||||||
location: nil,
|
|
||||||
map_subscriptions: []
|
|
||||||
)}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@@ -95,119 +88,99 @@ defmodule WandererAppWeb.MapsLive do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp apply_action(
|
defp apply_action(socket, :edit, %{"slug" => map_slug} = _params, url) do
|
||||||
%{assigns: %{current_user: current_user}} = socket,
|
map =
|
||||||
:edit,
|
map_slug
|
||||||
%{"slug" => map_slug} = _params,
|
|> WandererApp.Api.Map.get_map_by_slug!()
|
||||||
url
|
|> Ash.load!([:owner, :acls])
|
||||||
) do
|
|> map_map()
|
||||||
WandererApp.Maps.check_user_can_delete_map(map_slug, current_user)
|
|
||||||
|> case do
|
|
||||||
{:ok, map} ->
|
|
||||||
map = map |> map_map()
|
|
||||||
|
|
||||||
socket
|
socket
|
||||||
|> assign(:active_page, :maps)
|
|> assign(:active_page, :maps)
|
||||||
|> assign(:uri, URI.parse(url) |> Map.put(:path, ~p"/"))
|
|> assign(:uri, URI.parse(url) |> Map.put(:path, ~p"/"))
|
||||||
|> assign(:page_title, "Maps - Edit")
|
|> assign(:page_title, "Maps - Edit")
|
||||||
|> assign(:scopes, ["wormholes", "stargates", "none", "all"])
|
|> assign(:scopes, ["wormholes", "stargates", "none", "all"])
|
||||||
|> assign(:map_slug, map_slug)
|
|> assign(:map_slug, map_slug)
|
||||||
|> assign(
|
|> assign(
|
||||||
:characters,
|
:characters,
|
||||||
[map.owner |> map_character() | socket.assigns.characters] |> Enum.uniq()
|
[map.owner |> map_character() | socket.assigns.characters] |> Enum.uniq()
|
||||||
)
|
)
|
||||||
|> assign(
|
|> assign(
|
||||||
:form,
|
:form,
|
||||||
map |> AshPhoenix.Form.for_update(:update, forms: [auto?: true])
|
map |> AshPhoenix.Form.for_update(:update, forms: [auto?: true])
|
||||||
)
|
)
|
||||||
|> load_access_lists()
|
|> load_access_lists()
|
||||||
|
|
||||||
_ ->
|
|
||||||
socket
|
|
||||||
|> put_flash(:error, "You don't have an access.")
|
|
||||||
|> push_navigate(to: ~p"/maps")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp apply_action(
|
defp apply_action(socket, :settings, %{"slug" => map_slug} = _params, _url) do
|
||||||
%{assigns: %{current_user: current_user}} = socket,
|
map =
|
||||||
:settings,
|
map_slug
|
||||||
%{"slug" => map_slug} = _params,
|
|> WandererApp.Api.Map.get_map_by_slug!()
|
||||||
_url
|
|> Ash.load!([:owner, :acls])
|
||||||
) 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, map_balance} = WandererApp.Map.SubscriptionManager.get_balance(map)
|
{:ok, export_settings} =
|
||||||
|
map
|
||||||
|
|> WandererApp.Map.Server.get_export_settings()
|
||||||
|
|
||||||
{:ok, map_subscriptions} =
|
{:ok, map_balance} = WandererApp.Map.SubscriptionManager.get_balance(map)
|
||||||
WandererApp.Map.SubscriptionManager.get_map_subscriptions(map.id)
|
|
||||||
|
|
||||||
subscription_form = %{
|
{:ok, map_subscriptions} = WandererApp.Map.SubscriptionManager.get_map_subscriptions(map.id)
|
||||||
"plan" => "omega",
|
|
||||||
"period" => "1",
|
|
||||||
"characters_limit" => "100",
|
|
||||||
"hubs_limit" => "10",
|
|
||||||
"auto_renew?" => true
|
|
||||||
}
|
|
||||||
|
|
||||||
{:ok, options_form_data} = WandererApp.MapRepo.options_to_form_data(map)
|
subscription_form = %{
|
||||||
|
"plan" => "omega",
|
||||||
|
"period" => "1",
|
||||||
|
"characters_limit" => "100",
|
||||||
|
"hubs_limit" => "10",
|
||||||
|
"auto_renew?" => true
|
||||||
|
}
|
||||||
|
|
||||||
{:ok, estimated_price, discount} =
|
{:ok, options_form_data} = WandererApp.MapRepo.options_to_form_data(map)
|
||||||
WandererApp.Map.SubscriptionManager.estimate_price(subscription_form, false)
|
|
||||||
|
|
||||||
socket
|
{:ok, estimated_price, discount} =
|
||||||
|> assign(:active_page, :maps)
|
WandererApp.Map.SubscriptionManager.estimate_price(subscription_form, false)
|
||||||
|> 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
|
||||||
socket
|
|> assign(:active_page, :maps)
|
||||||
|> put_flash(:error, "You don't have an access.")
|
|> assign(:page_title, "Maps - Settings")
|
||||||
|> push_navigate(to: ~p"/maps")
|
|> assign(:map_slug, map_slug)
|
||||||
end
|
|> 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
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp allow_map_creation(),
|
defp allow_map_creation(),
|
||||||
|
|||||||
@@ -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"
|
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"}
|
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" />
|
<.icon name="hero-plus-solid" class="w-20 h-20" />
|
||||||
<h3 class="card-title text-center text-md">Create Map</h3>
|
<h3 class="card-title text-center text-md">Create Map</h3>
|
||||||
</div>
|
</div>
|
||||||
@@ -125,7 +125,6 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<.modal
|
<.modal
|
||||||
:if={@is_connected? && @live_action in [:create, :edit]}
|
:if={@is_connected? && @live_action in [:create, :edit]}
|
||||||
title={"#{(@live_action == :create && "Create") || "Edit"} Map"}
|
title={"#{(@live_action == :create && "Create") || "Edit"} Map"}
|
||||||
@@ -186,7 +185,7 @@
|
|||||||
</.modal>
|
</.modal>
|
||||||
|
|
||||||
<.modal
|
<.modal
|
||||||
:if={@live_action in [:settings] && not is_nil(assigns[:map])}
|
:if={@live_action in [:settings]}
|
||||||
title="Map Settings"
|
title="Map Settings"
|
||||||
class="!min-w-[700px]"
|
class="!min-w-[700px]"
|
||||||
id="map-settings-modal"
|
id="map-settings-modal"
|
||||||
@@ -195,7 +194,7 @@
|
|||||||
>
|
>
|
||||||
<div class="flex flex-col gap-3">
|
<div class="flex flex-col gap-3">
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<div class="verticalTabsContainer">
|
<div class="_verticalTabsContainer_1o01l_2">
|
||||||
<div class="p-tabview p-component" data-pc-name="tabview" data-pc-section="root">
|
<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-container" data-pc-section="navcontainer">
|
||||||
<div class="p-tabview-nav-content" data-pc-section="navcontent">
|
<div class="p-tabview-nav-content" data-pc-section="navcontent">
|
||||||
@@ -257,7 +256,9 @@
|
|||||||
:if={@map_subscriptions_enabled?}
|
:if={@map_subscriptions_enabled?}
|
||||||
class={[
|
class={[
|
||||||
"p-unselectable-text",
|
"p-unselectable-text",
|
||||||
classes("p-tabview-selected p-highlight": @active_settings_tab == "subscription")
|
classes(
|
||||||
|
"p-tabview-selected p-highlight": @active_settings_tab == "subscription"
|
||||||
|
)
|
||||||
]}
|
]}
|
||||||
role="presentation"
|
role="presentation"
|
||||||
data-pc-name=""
|
data-pc-name=""
|
||||||
@@ -305,11 +306,21 @@
|
|||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li
|
||||||
|
aria-hidden="true"
|
||||||
|
role="presentation"
|
||||||
|
class="p-tabview-ink-bar"
|
||||||
|
data-pc-section="inkbar"
|
||||||
|
style="width: 146px; left: 0px;"
|
||||||
|
>
|
||||||
|
</li>
|
||||||
<li
|
<li
|
||||||
:if={not WandererApp.Env.public_api_disabled?()}
|
:if={not WandererApp.Env.public_api_disabled?()}
|
||||||
class={[
|
class={[
|
||||||
"p-unselectable-text",
|
"p-unselectable-text",
|
||||||
classes("p-tabview-selected p-highlight": @active_settings_tab == "public_api")
|
classes(
|
||||||
|
"p-tabview-selected p-highlight": @active_settings_tab == "public_api"
|
||||||
|
)
|
||||||
]}
|
]}
|
||||||
role="presentation"
|
role="presentation"
|
||||||
data-pc-name=""
|
data-pc-name=""
|
||||||
@@ -411,7 +422,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
:if={@active_settings_tab == "public_api" and not WandererApp.Env.public_api_disabled?()}
|
:if={
|
||||||
|
@active_settings_tab == "public_api" and
|
||||||
|
not WandererApp.Env.public_api_disabled?()
|
||||||
|
}
|
||||||
class="p-6"
|
class="p-6"
|
||||||
>
|
>
|
||||||
<h2 class="text-lg font-semibold mb-4">Public API</h2>
|
<h2 class="text-lg font-semibold mb-4">Public API</h2>
|
||||||
@@ -433,28 +447,29 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<.button
|
<.button class="btn btn-primary rounded-md" phx-click="generate-map-api-key">
|
||||||
type="button"
|
Generate
|
||||||
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>
|
||||||
<.button
|
<.button
|
||||||
type="button"
|
|
||||||
phx-hook="CopyToClipboard"
|
phx-hook="CopyToClipboard"
|
||||||
id="copy-map-api-key"
|
id="copy-map-api-key"
|
||||||
data-url={@public_api_key}
|
data-url={@public_api_key}
|
||||||
disabled={is_nil(@public_api_key)}
|
disabled={is_nil(@public_api_key)}
|
||||||
class={"p-button p-component " <> if(is_nil(@public_api_key), do: "p-disabled", else: "")}
|
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
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<span class="p-button-label">Copy</span>
|
Copy
|
||||||
</.button>
|
</.button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div :if={@active_settings_tab == "balance"}>
|
<div :if={@active_settings_tab == "balance"}>
|
||||||
<div class="stats w-full bg-primary text-primary-content">
|
<div class="stats w-full bg-primary text-primary-content">
|
||||||
<div class="stat">
|
<div class="stat">
|
||||||
@@ -680,8 +695,10 @@
|
|||||||
<.button
|
<.button
|
||||||
:if={@active_settings_tab == "subscription" && not @is_adding_subscription?}
|
:if={@active_settings_tab == "subscription" && not @is_adding_subscription?}
|
||||||
type="button"
|
type="button"
|
||||||
disabled={@map_subscriptions |> Enum.at(0) |> Map.get(:status) == :active &&
|
disabled={
|
||||||
@map_subscriptions |> Enum.at(0) |> Map.get(:plan) != :alpha}
|
@map_subscriptions |> Enum.at(0) |> Map.get(:status) == :active &&
|
||||||
|
@map_subscriptions |> Enum.at(0) |> Map.get(:plan) != :alpha
|
||||||
|
}
|
||||||
phx-click="add_subscription"
|
phx-click="add_subscription"
|
||||||
>
|
>
|
||||||
Add subscription
|
Add subscription
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ defmodule WandererAppWeb.Router do
|
|||||||
use Plug.ErrorHandler
|
use Plug.ErrorHandler
|
||||||
|
|
||||||
import PlugDynamic.Builder
|
import PlugDynamic.Builder
|
||||||
import Logger
|
|
||||||
|
|
||||||
import WandererAppWeb.UserAuth,
|
import WandererAppWeb.UserAuth,
|
||||||
warn: false,
|
warn: false,
|
||||||
@@ -25,6 +24,7 @@ defmodule WandererAppWeb.Router do
|
|||||||
@font_src ~w('self' https://fonts.gstatic.com data: https://web.ccpgamescdn.com https://w.appzi.io )
|
@font_src ~w('self' https://fonts.gstatic.com data: https://web.ccpgamescdn.com https://w.appzi.io )
|
||||||
@script_src ~w('self' )
|
@script_src ~w('self' )
|
||||||
|
|
||||||
|
|
||||||
pipeline :admin_bauth do
|
pipeline :admin_bauth do
|
||||||
plug :admin_basic_auth
|
plug :admin_basic_auth
|
||||||
end
|
end
|
||||||
@@ -112,21 +112,12 @@ defmodule WandererAppWeb.Router do
|
|||||||
|
|
||||||
pipeline :api_map do
|
pipeline :api_map do
|
||||||
plug WandererAppWeb.Plugs.CheckMapApiKey
|
plug WandererAppWeb.Plugs.CheckMapApiKey
|
||||||
plug WandererAppWeb.Plugs.CheckMapSubscription
|
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :api_kills do
|
pipeline :api_kills do
|
||||||
plug WandererAppWeb.Plugs.CheckApiDisabled
|
plug WandererAppWeb.Plugs.CheckApiDisabled
|
||||||
end
|
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
|
scope "/api/map/systems-kills", WandererAppWeb do
|
||||||
pipe_through [:api, :api_map, :api_kills]
|
pipe_through [:api, :api_map, :api_kills]
|
||||||
|
|
||||||
@@ -135,77 +126,67 @@ defmodule WandererAppWeb.Router do
|
|||||||
|
|
||||||
scope "/api/map", WandererAppWeb do
|
scope "/api/map", WandererAppWeb do
|
||||||
pipe_through [:api, :api_map]
|
pipe_through [:api, :api_map]
|
||||||
|
|
||||||
|
# GET /api/map/systems?map_id=... or ?slug=...
|
||||||
get "/systems", MapAPIController, :list_systems
|
get "/systems", MapAPIController, :list_systems
|
||||||
|
|
||||||
|
# GET /api/map/system?id=... plus either map_id=... or slug=...
|
||||||
get "/system", MapAPIController, :show_system
|
get "/system", MapAPIController, :show_system
|
||||||
|
|
||||||
|
# GET /api/map/characters?map_id=... or slug=...
|
||||||
get "/characters", MapAPIController, :tracked_characters_with_info
|
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 "/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
|
end
|
||||||
|
|
||||||
scope "/api/common", WandererAppWeb do
|
scope "/api/common", WandererAppWeb do
|
||||||
pipe_through [:api]
|
pipe_through [:api]
|
||||||
|
|
||||||
|
# GET /api/common/system-static-info?id=...
|
||||||
get "/system-static-info", CommonAPIController, :show_system_static
|
get "/system-static-info", CommonAPIController, :show_system_static
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
|
||||||
# Browser / blog stuff
|
|
||||||
#
|
|
||||||
scope "/", WandererAppWeb do
|
scope "/", WandererAppWeb do
|
||||||
pipe_through [:browser, :blog, :redirect_if_user_is_authenticated]
|
pipe_through [:browser, :blog, :redirect_if_user_is_authenticated]
|
||||||
|
|
||||||
get "/welcome", BlogController, :index
|
get "/welcome", BlogController, :index
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/contacts", WandererAppWeb do
|
scope "/contacts", WandererAppWeb do
|
||||||
pipe_through [:browser, :blog]
|
pipe_through [:browser, :blog]
|
||||||
|
|
||||||
get "/", BlogController, :contacts
|
get "/", BlogController, :contacts
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/changelog", WandererAppWeb do
|
scope "/changelog", WandererAppWeb do
|
||||||
pipe_through [:browser, :blog]
|
pipe_through [:browser, :blog]
|
||||||
|
|
||||||
get "/", BlogController, :changelog
|
get "/", BlogController, :changelog
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/news", WandererAppWeb do
|
scope "/news", WandererAppWeb do
|
||||||
pipe_through [:browser, :blog]
|
pipe_through [:browser, :blog]
|
||||||
|
|
||||||
get "/:slug", BlogController, :show
|
get "/:slug", BlogController, :show
|
||||||
get "/", BlogController, :list
|
get "/", BlogController, :list
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/license", WandererAppWeb do
|
scope "/license", WandererAppWeb do
|
||||||
pipe_through [:browser, :blog]
|
pipe_through [:browser, :blog]
|
||||||
|
|
||||||
get "/", BlogController, :license
|
get "/", BlogController, :license
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
|
||||||
# Auth
|
|
||||||
#
|
|
||||||
scope "/auth", WandererAppWeb do
|
scope "/auth", WandererAppWeb do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
get "/signout", AuthController, :signout
|
get "/signout", AuthController, :signout
|
||||||
get "/:provider", AuthController, :request
|
get "/:provider", AuthController, :request
|
||||||
get "/:provider/callback", AuthController, :callback
|
get "/:provider/callback", AuthController, :callback
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
|
||||||
# Admin
|
|
||||||
#
|
|
||||||
scope "/admin", WandererAppWeb do
|
scope "/admin", WandererAppWeb do
|
||||||
pipe_through(:browser)
|
pipe_through(:browser)
|
||||||
pipe_through(:admin_bauth)
|
pipe_through(:admin_bauth)
|
||||||
@@ -227,49 +208,53 @@ defmodule WandererAppWeb.Router do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
|
||||||
# Additional routes / Live sessions
|
|
||||||
#
|
|
||||||
scope "/", WandererAppWeb do
|
scope "/", WandererAppWeb do
|
||||||
pipe_through(:browser)
|
pipe_through(:browser)
|
||||||
|
|
||||||
get "/", RedirectController, :redirect_authenticated
|
get "/", RedirectController, :redirect_authenticated
|
||||||
get "/last", MapsController, :last
|
get("/last", MapsController, :last)
|
||||||
|
|
||||||
live_session :authenticated,
|
live_session :authenticated,
|
||||||
on_mount: [
|
on_mount: [
|
||||||
{WandererAppWeb.UserAuth, :ensure_authenticated},
|
{WandererAppWeb.UserAuth, :ensure_authenticated},
|
||||||
WandererAppWeb.Nav
|
WandererAppWeb.Nav
|
||||||
] do
|
] do
|
||||||
live "/access-lists/new", AccessListsLive, :create
|
live("/access-lists/new", AccessListsLive, :create)
|
||||||
live "/access-lists/:id/edit", AccessListsLive, :edit
|
live("/access-lists/:id/edit", AccessListsLive, :edit)
|
||||||
live "/access-lists/:id/add-members", AccessListsLive, :add_members
|
live("/access-lists/:id/add-members", AccessListsLive, :add_members)
|
||||||
live "/access-lists/:id", AccessListsLive, :members
|
live("/access-lists/:id", AccessListsLive, :members)
|
||||||
live "/access-lists", AccessListsLive, :index
|
live("/access-lists", AccessListsLive, :index)
|
||||||
|
live("/coming-soon", ComingLive, :index)
|
||||||
live "/coming-soon", ComingLive, :index
|
live("/tracking/:slug", CharactersTrackingLive, :characters)
|
||||||
live "/tracking/:slug", CharactersTrackingLive, :characters
|
live("/tracking", CharactersTrackingLive, :index)
|
||||||
live "/tracking", CharactersTrackingLive, :index
|
live("/characters", CharactersLive, :index)
|
||||||
live "/characters", CharactersLive, :index
|
live("/characters/authorize", CharactersLive, :authorize)
|
||||||
live "/characters/authorize", CharactersLive, :authorize
|
live("/maps/new", MapsLive, :create)
|
||||||
live "/maps/new", MapsLive, :create
|
live("/maps/:slug/edit", MapsLive, :edit)
|
||||||
live "/maps/:slug/edit", MapsLive, :edit
|
live("/maps/:slug/settings", MapsLive, :settings)
|
||||||
live "/maps/:slug/settings", MapsLive, :settings
|
live("/maps", MapsLive, :index)
|
||||||
live "/maps", MapsLive, :index
|
live("/profile", ProfileLive, :index)
|
||||||
live "/profile", ProfileLive, :index
|
live("/profile/deposit", ProfileLive, :deposit)
|
||||||
live "/profile/deposit", ProfileLive, :deposit
|
live("/profile/subscribe", ProfileLive, :subscribe)
|
||||||
live "/profile/subscribe", ProfileLive, :subscribe
|
live("/:slug/audit", MapAuditLive, :index)
|
||||||
live "/:slug/audit", MapAuditLive, :index
|
live("/:slug", MapLive, :index)
|
||||||
live "/:slug", MapLive, :index
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Enable LiveDashboard and Swoosh mailbox preview in development
|
||||||
if Application.compile_env(:wanderer_app, :dev_routes) do
|
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
|
import Phoenix.LiveDashboard.Router
|
||||||
|
|
||||||
scope "/dev" do
|
scope "/dev" do
|
||||||
pipe_through(:browser)
|
pipe_through(:browser)
|
||||||
|
|
||||||
error_tracker_dashboard("/errors", as: :error_tracker_dev_dashboard)
|
error_tracker_dashboard("/errors", as: :error_tracker_dev_dashboard)
|
||||||
|
|
||||||
live_dashboard("/dashboard", metrics: WandererAppWeb.Telemetry)
|
live_dashboard("/dashboard", metrics: WandererAppWeb.Telemetry)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
2
mix.exs
2
mix.exs
@@ -3,7 +3,7 @@ defmodule WandererApp.MixProject do
|
|||||||
|
|
||||||
@source_url "https://github.com/wanderer-industries/wanderer"
|
@source_url "https://github.com/wanderer-industries/wanderer"
|
||||||
|
|
||||||
@version "1.51.3"
|
@version "1.46.0"
|
||||||
|
|
||||||
def project do
|
def project do
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -1,425 +0,0 @@
|
|||||||
%{
|
|
||||||
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
|
|
||||||
|
|
||||||
Wanderer’s 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, you’ll 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).
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
2. **ACL API Token:** Available in the create/edit ACL screen. This token is used for ACL member management endpoints.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 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 Member’s Role
|
|
||||||
|
|
||||||
```bash
|
|
||||||
PUT /api/acls/:acl_id/members/:member_id
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Description:** Updates an ACL member’s 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 member’s 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**
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
{
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
#!/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 ACL’s 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! ==="
|
|
||||||
Reference in New Issue
Block a user