decompose structure
This commit is contained in:
16
src/entities/current/api.ts
Normal file
16
src/entities/current/api.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { getJson } from '../../shared/api/http';
|
||||
import { cloudApiUrl } from '../../shared/config/env';
|
||||
import type { CurrentResponse } from './types';
|
||||
|
||||
/** Загружает текущие значения показателей для выбранной буровой. */
|
||||
export function getCurrent(edge: string, tags?: string[]): Promise<CurrentResponse> {
|
||||
return getJson<CurrentResponse>(cloudApiUrl, '/current', { edge, tags });
|
||||
}
|
||||
|
||||
/** Формирует URL SSE-потока текущих значений. */
|
||||
export function getCurrentEventsUrl(edge: string, tags?: string[]): string {
|
||||
const url = new URL('/current/events', cloudApiUrl);
|
||||
url.searchParams.set('edge', edge);
|
||||
tags?.forEach((tag) => url.searchParams.append('tags', tag));
|
||||
return url.toString();
|
||||
}
|
||||
22
src/entities/current/types.ts
Normal file
22
src/entities/current/types.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export type CurrentItem = {
|
||||
edge: string;
|
||||
tag: string;
|
||||
value: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
time: string;
|
||||
name: string | null;
|
||||
tagGroup: string | null;
|
||||
min: number | null;
|
||||
max: number | null;
|
||||
comment: string | null;
|
||||
unitOfMeasurement: string | null;
|
||||
precision: number | null;
|
||||
};
|
||||
|
||||
export type CurrentResponse = {
|
||||
edge: string;
|
||||
items: CurrentItem[];
|
||||
};
|
||||
|
||||
export type CurrentEvent = CurrentResponse;
|
||||
22
src/entities/diagram/api.ts
Normal file
22
src/entities/diagram/api.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { getAccessToken } from '../../auth/keycloak';
|
||||
import { getJson } from '../../shared/api/http';
|
||||
import { diagramApiUrl } from '../../shared/config/env';
|
||||
import type { DiagramPageResponse, DiagramPageSummary } from './types';
|
||||
|
||||
/** Выполняет запрос к diagram-service и пробрасывает Bearer-токен, если UI работает с SSO. */
|
||||
async function request<T>(path: string, params?: Record<string, string | undefined>): Promise<T> {
|
||||
const token = await getAccessToken();
|
||||
return getJson<T>(diagramApiUrl, path, params, {
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
/** Возвращает список страниц схем; опубликованность определяется по publishedRevision. */
|
||||
export function listDiagramPages(ownerEdgeId?: string): Promise<DiagramPageSummary[]> {
|
||||
return request<DiagramPageSummary[]>('/diagram/pages', { ownerEdgeId });
|
||||
}
|
||||
|
||||
/** Загружает опубликованную версию страницы схемы. */
|
||||
export function getPublishedDiagramPage(pageKey: string): Promise<DiagramPageResponse> {
|
||||
return request<DiagramPageResponse>(`/diagram/pages/${encodeURIComponent(pageKey)}/published`);
|
||||
}
|
||||
88
src/entities/diagram/types.ts
Normal file
88
src/entities/diagram/types.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
export type DiagramPoint = {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
|
||||
export type DiagramSize = {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
export type DiagramBindingConfig = {
|
||||
stateTagId?: string;
|
||||
alarmTagId?: string;
|
||||
edgeId?: string;
|
||||
sseEdgeId?: string;
|
||||
sseUrl?: string;
|
||||
};
|
||||
|
||||
export type DiagramNode =
|
||||
| {
|
||||
id: string;
|
||||
kind: 'tagWidget';
|
||||
tagId: string;
|
||||
edgeId: string;
|
||||
widgetType: string;
|
||||
position: DiagramPoint;
|
||||
size?: DiagramSize;
|
||||
zIndex?: number;
|
||||
label?: string;
|
||||
displayType?: 'widget' | 'compact' | 'card';
|
||||
style?: Record<string, unknown>;
|
||||
}
|
||||
| {
|
||||
id: string;
|
||||
kind: 'decoration';
|
||||
decorationType: string;
|
||||
position: DiagramPoint;
|
||||
size: DiagramSize;
|
||||
rotation?: number;
|
||||
zIndex?: number;
|
||||
data?: Record<string, unknown>;
|
||||
style?: Record<string, unknown>;
|
||||
bindings?: DiagramBindingConfig;
|
||||
};
|
||||
|
||||
export type DiagramEdge = {
|
||||
id: string;
|
||||
sourceNodeId: string;
|
||||
targetNodeId: string;
|
||||
sourceSide?: 'left' | 'right' | 'top' | 'bottom';
|
||||
targetSide?: 'left' | 'right' | 'top' | 'bottom';
|
||||
kind: 'wire' | 'power' | 'signal' | 'alert';
|
||||
label?: string;
|
||||
animated?: boolean;
|
||||
waypoints?: DiagramPoint[];
|
||||
};
|
||||
|
||||
export type DiagramDocument = {
|
||||
schemaVersion: number;
|
||||
pageKey: string;
|
||||
ownerEdgeId: string;
|
||||
title?: string;
|
||||
viewport?: { x: number; y: number; zoom: number } | null;
|
||||
background?: {
|
||||
url?: string;
|
||||
opacity?: number;
|
||||
fit?: 'contain' | 'cover' | 'stretch';
|
||||
};
|
||||
nodes: DiagramNode[];
|
||||
edges: DiagramEdge[];
|
||||
};
|
||||
|
||||
export type DiagramPageSummary = {
|
||||
pageKey: string;
|
||||
ownerEdgeId: string;
|
||||
title?: string | null;
|
||||
schemaVersion: number;
|
||||
revision: number;
|
||||
status: 'draft' | 'published' | 'archived';
|
||||
publishedRevision?: number;
|
||||
publishedAt?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type DiagramPageResponse = DiagramPageSummary & {
|
||||
document: DiagramDocument;
|
||||
};
|
||||
8
src/entities/edge/api.ts
Normal file
8
src/entities/edge/api.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { getJson } from '../../shared/api/http';
|
||||
import { cloudApiUrl } from '../../shared/config/env';
|
||||
import type { EdgeResponse } from './types';
|
||||
|
||||
/** Возвращает список буровых, доступных в cloud-v3. */
|
||||
export function getEdges(): Promise<EdgeResponse> {
|
||||
return getJson<EdgeResponse>(cloudApiUrl, '/edge');
|
||||
}
|
||||
11
src/entities/edge/types.ts
Normal file
11
src/entities/edge/types.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export type EdgeItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
parentId: string | null;
|
||||
tagIds: string[];
|
||||
tagCount: number;
|
||||
};
|
||||
|
||||
export type EdgeResponse = {
|
||||
items: EdgeItem[];
|
||||
};
|
||||
8
src/entities/health/api.ts
Normal file
8
src/entities/health/api.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { getJson } from '../../shared/api/http';
|
||||
import { cloudApiUrl } from '../../shared/config/env';
|
||||
import type { HealthResponse } from './types';
|
||||
|
||||
/** Запрашивает состояние cloud-v3 и подключенной базы данных. */
|
||||
export function getHealth(): Promise<HealthResponse> {
|
||||
return getJson<HealthResponse>(cloudApiUrl, '/health');
|
||||
}
|
||||
8
src/entities/health/types.ts
Normal file
8
src/entities/health/types.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export type HealthResponse = {
|
||||
status: 'ok';
|
||||
database: {
|
||||
now: string;
|
||||
timescaledb_installed: boolean;
|
||||
timescaledb_version: string | null;
|
||||
};
|
||||
};
|
||||
8
src/entities/history/api.ts
Normal file
8
src/entities/history/api.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { getJson } from '../../shared/api/http';
|
||||
import { cloudApiUrl } from '../../shared/config/env';
|
||||
import type { HistoryRequest, HistoryResponse } from './types';
|
||||
|
||||
/** Запрашивает исторический ряд с avg-линией и min/max-диапазоном для графика. */
|
||||
export function getHistory(params: HistoryRequest): Promise<HistoryResponse> {
|
||||
return getJson<HistoryResponse>(cloudApiUrl, '/history', params);
|
||||
}
|
||||
30
src/entities/history/types.ts
Normal file
30
src/entities/history/types.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export type HistoryPoint = {
|
||||
t: number;
|
||||
min: number;
|
||||
avg: number;
|
||||
max: number;
|
||||
count: number;
|
||||
};
|
||||
|
||||
export type HistorySeries = {
|
||||
edge: string;
|
||||
tag: string;
|
||||
points: HistoryPoint[];
|
||||
};
|
||||
|
||||
export type HistoryResponse = {
|
||||
edge: string;
|
||||
tag: string;
|
||||
granulate: string;
|
||||
series: HistorySeries[];
|
||||
from: string;
|
||||
to: string;
|
||||
};
|
||||
|
||||
export type HistoryRequest = {
|
||||
edge: string;
|
||||
tag: string;
|
||||
from: string;
|
||||
to: string;
|
||||
granulate: string;
|
||||
};
|
||||
8
src/entities/tag/api.ts
Normal file
8
src/entities/tag/api.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { getJson } from '../../shared/api/http';
|
||||
import { cloudApiUrl } from '../../shared/config/env';
|
||||
import type { TagResponse } from './types';
|
||||
|
||||
/** Загружает справочник тегов; tag.name используется как отображаемое имя. */
|
||||
export function getTags(params: { edge?: string; search?: string } = {}): Promise<TagResponse> {
|
||||
return getJson<TagResponse>(cloudApiUrl, '/tag', params);
|
||||
}
|
||||
15
src/entities/tag/types.ts
Normal file
15
src/entities/tag/types.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export type TagItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
tagGroup: string | null;
|
||||
min: number;
|
||||
max: number;
|
||||
comment: string;
|
||||
unitOfMeasurement: string;
|
||||
edgeIds: string[];
|
||||
precision: number | null;
|
||||
};
|
||||
|
||||
export type TagResponse = {
|
||||
items: TagItem[];
|
||||
};
|
||||
Reference in New Issue
Block a user