Compare commits
36 Commits
VORKOUT-8
...
VORKOUT-16
Author | SHA1 | Date | |
---|---|---|---|
6db2821781 | |||
3f87970653 | |||
ee4051f523 | |||
cf6e09d8c1 | |||
|
d9e88d66f7 | ||
|
3c300f7c7a | ||
|
c66c21eb14 | ||
|
a9ecaadad6 | ||
|
e50bb32470 | ||
|
2030d54b2c | ||
|
b82960faf3 | ||
|
e0887c240f | ||
65ed6b9561 | |||
b503bc0bef | |||
5cdb6e460f | |||
5966b7d6f1 | |||
8b0659fc89 | |||
51344ef218 | |||
51171377e2 | |||
943f4ded2d | |||
443293d420 | |||
91c8efe13f | |||
5e3c3b4672 | |||
60160d46be | |||
d03600b23d | |||
82fcd22faf | |||
|
2690843954 | ||
e10430310f | |||
2493cd0d9f | |||
e6589a0950 | |||
a0fcc324fa | |||
|
f65f4caf5c | ||
|
a90a802659 | ||
|
3d5d717962 | ||
|
0bff556b10 | ||
|
f550b86c68 |
@@ -3,44 +3,108 @@ from datetime import datetime, timezone
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy import func, insert, select
|
from sqlalchemy import insert, select, func, or_, and_, asc, desc
|
||||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
from api.db.tables.account import account_table
|
from api.db.tables.account import account_table
|
||||||
from api.schemas.account.account import User
|
from api.schemas.account.account import User
|
||||||
from api.schemas.endpoints.account import all_user_adapter, AllUser, AllUserResponse, UserCreate
|
from api.schemas.endpoints.account import all_user_adapter, AllUser, AllUserResponse, UserCreate, UserFilterDTO
|
||||||
|
|
||||||
|
|
||||||
async def get_user_accaunt_page(connection: AsyncConnection, page, limit) -> Optional[AllUserResponse]:
|
async def get_user_account_page_DTO(
|
||||||
|
connection: AsyncConnection, filter_dto: UserFilterDTO
|
||||||
|
) -> Optional[AllUserResponse]:
|
||||||
"""
|
"""
|
||||||
Получает список ползовелей заданных значениями page, limit.
|
Получает список пользователей с пагинацией, фильтрацией и сортировкой через DTO объект.
|
||||||
|
Поддерживает:
|
||||||
|
- пагинацию
|
||||||
|
- поиск
|
||||||
|
- фильтрацию по полям
|
||||||
|
- сортировку
|
||||||
"""
|
"""
|
||||||
|
|
||||||
first_user = page * limit - (limit)
|
page = filter_dto.pagination.get("page", 1)
|
||||||
|
limit = filter_dto.pagination.get("limit", 10)
|
||||||
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
query = (
|
query = select(
|
||||||
select(
|
|
||||||
account_table.c.id,
|
account_table.c.id,
|
||||||
account_table.c.name,
|
account_table.c.name,
|
||||||
account_table.c.login,
|
account_table.c.login,
|
||||||
account_table.c.email,
|
account_table.c.email,
|
||||||
account_table.c.bind_tenant_id,
|
account_table.c.bind_tenant_id,
|
||||||
account_table.c.role,
|
account_table.c.role,
|
||||||
|
account_table.c.meta,
|
||||||
|
account_table.c.creator_id,
|
||||||
account_table.c.created_at,
|
account_table.c.created_at,
|
||||||
account_table.c.status,
|
account_table.c.status,
|
||||||
)
|
)
|
||||||
.order_by(account_table.c.id)
|
|
||||||
.offset(first_user)
|
# Поиск
|
||||||
.limit(limit)
|
if filter_dto.search:
|
||||||
|
search_term = f"%{filter_dto.search}%"
|
||||||
|
query = query.where(
|
||||||
|
or_(
|
||||||
|
account_table.c.name.ilike(search_term),
|
||||||
|
account_table.c.login.ilike(search_term),
|
||||||
|
account_table.c.email.ilike(search_term),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Фильтрацию
|
||||||
|
filter_conditions = []
|
||||||
|
if filter_dto.filters:
|
||||||
|
for field, values in filter_dto.filters.items():
|
||||||
|
column = getattr(account_table.c, field, None)
|
||||||
|
if column is not None and values:
|
||||||
|
if len(values) == 1:
|
||||||
|
filter_conditions.append(column == values[0])
|
||||||
|
else:
|
||||||
|
filter_conditions.append(column.in_(values))
|
||||||
|
|
||||||
|
if filter_conditions:
|
||||||
|
query = query.where(and_(*filter_conditions))
|
||||||
|
|
||||||
|
# Сортировка
|
||||||
|
if filter_dto.order:
|
||||||
|
order_field = filter_dto.order.get("field", "id")
|
||||||
|
order_direction = filter_dto.order.get("direction", "asc")
|
||||||
|
|
||||||
|
column = getattr(account_table.c, order_field, None)
|
||||||
|
if column is not None:
|
||||||
|
if order_direction.lower() == "desc":
|
||||||
|
query = query.order_by(desc(column))
|
||||||
|
else:
|
||||||
|
query = query.order_by(asc(column))
|
||||||
|
else:
|
||||||
|
query = query.order_by(account_table.c.id)
|
||||||
|
|
||||||
|
query = query.offset(offset).limit(limit)
|
||||||
|
|
||||||
count_query = select(func.count()).select_from(account_table)
|
count_query = select(func.count()).select_from(account_table)
|
||||||
|
|
||||||
|
if filter_dto.search:
|
||||||
|
search_term = f"%{filter_dto.search}%"
|
||||||
|
count_query = count_query.where(
|
||||||
|
or_(
|
||||||
|
account_table.c.name.ilike(search_term),
|
||||||
|
account_table.c.login.ilike(search_term),
|
||||||
|
account_table.c.email.ilike(search_term),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if filter_conditions:
|
||||||
|
count_query = count_query.where(and_(*filter_conditions))
|
||||||
|
|
||||||
result = await connection.execute(query)
|
result = await connection.execute(query)
|
||||||
count_result = await connection.execute(count_query)
|
count_result = await connection.execute(count_query)
|
||||||
|
|
||||||
users_data = result.mappings().all()
|
users_data = result.mappings().all()
|
||||||
total_count = count_result.scalar()
|
total_count = count_result.scalar()
|
||||||
|
|
||||||
|
if not total_count:
|
||||||
|
return None
|
||||||
|
|
||||||
total_pages = math.ceil(total_count / limit)
|
total_pages = math.ceil(total_count / limit)
|
||||||
|
|
||||||
validated_users = all_user_adapter.validate_python(users_data)
|
validated_users = all_user_adapter.validate_python(users_data)
|
||||||
@@ -66,7 +130,7 @@ async def get_user_by_id(connection: AsyncConnection, user_id: int) -> Optional[
|
|||||||
if not user:
|
if not user:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return AllUser.model_validate(user)
|
return User.model_validate(user)
|
||||||
|
|
||||||
|
|
||||||
async def get_user_by_login(connection: AsyncConnection, login: str) -> Optional[User]:
|
async def get_user_by_login(connection: AsyncConnection, login: str) -> Optional[User]:
|
||||||
@@ -76,20 +140,10 @@ async def get_user_by_login(connection: AsyncConnection, login: str) -> Optional
|
|||||||
query = select(account_table).where(account_table.c.login == login)
|
query = select(account_table).where(account_table.c.login == login)
|
||||||
|
|
||||||
user_db_cursor = await connection.execute(query)
|
user_db_cursor = await connection.execute(query)
|
||||||
user_db = user_db_cursor.one_or_none()
|
user_data = user_db_cursor.mappings().one_or_none()
|
||||||
|
if not user_data:
|
||||||
if not user_db:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
user_data = {
|
|
||||||
column.name: (
|
|
||||||
getattr(user_db, column.name).name
|
|
||||||
if isinstance(getattr(user_db, column.name), Enum)
|
|
||||||
else getattr(user_db, column.name)
|
|
||||||
)
|
|
||||||
for column in account_table.columns
|
|
||||||
}
|
|
||||||
|
|
||||||
return User.model_validate(user_data)
|
return User.model_validate(user_data)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -18,20 +18,11 @@ async def get_key_by_id(connection: AsyncConnection, key_id: str) -> Optional[Ac
|
|||||||
query = select(account_keyring_table).where(account_keyring_table.c.key_id == key_id)
|
query = select(account_keyring_table).where(account_keyring_table.c.key_id == key_id)
|
||||||
|
|
||||||
user_db_cursor = await connection.execute(query)
|
user_db_cursor = await connection.execute(query)
|
||||||
user_db = user_db_cursor.one_or_none()
|
|
||||||
|
|
||||||
if not user_db:
|
user_data = user_db_cursor.mappings().one_or_none()
|
||||||
|
if not user_data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
user_data = {
|
|
||||||
column.name: (
|
|
||||||
getattr(user_db, column.name).name
|
|
||||||
if isinstance(getattr(user_db, column.name), Enum)
|
|
||||||
else getattr(user_db, column.name)
|
|
||||||
)
|
|
||||||
for column in account_keyring_table.columns
|
|
||||||
}
|
|
||||||
|
|
||||||
return AccountKeyring.model_validate(user_data)
|
return AccountKeyring.model_validate(user_data)
|
||||||
|
|
||||||
|
|
||||||
|
279
api/api/db/logic/list_events.py
Normal file
279
api/api/db/logic/list_events.py
Normal file
@@ -0,0 +1,279 @@
|
|||||||
|
from typing import Optional
|
||||||
|
import math
|
||||||
|
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
|
||||||
|
from sqlalchemy import insert, select, func, or_, and_, asc, desc
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
|
from api.db.tables.events import list_events_table
|
||||||
|
|
||||||
|
from api.schemas.events.list_events import ListEvent
|
||||||
|
|
||||||
|
from api.schemas.endpoints.list_events import all_list_event_adapter, AllListEventResponse, ListEventFilterDTO
|
||||||
|
|
||||||
|
|
||||||
|
async def get_list_events_page_DTO(
|
||||||
|
connection: AsyncConnection, filter_dto: ListEventFilterDTO
|
||||||
|
) -> Optional[AllListEventResponse]:
|
||||||
|
"""
|
||||||
|
Получает список событий с фильтрацией через DTO объект.
|
||||||
|
Поддерживает:
|
||||||
|
- пагинацию
|
||||||
|
- полнотекстовый поиск (пропускает name при русских буквах)
|
||||||
|
- фильтрацию по полям
|
||||||
|
- сортировку
|
||||||
|
"""
|
||||||
|
page = filter_dto.pagination.get("page", 1)
|
||||||
|
limit = filter_dto.pagination.get("limit", 10)
|
||||||
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
query = select(
|
||||||
|
list_events_table.c.id,
|
||||||
|
list_events_table.c.name,
|
||||||
|
list_events_table.c.title,
|
||||||
|
list_events_table.c.creator_id,
|
||||||
|
list_events_table.c.created_at,
|
||||||
|
list_events_table.c.schema.label("schema_"),
|
||||||
|
list_events_table.c.state,
|
||||||
|
list_events_table.c.status,
|
||||||
|
)
|
||||||
|
|
||||||
|
if filter_dto.search:
|
||||||
|
search_term = f"%{filter_dto.search}%"
|
||||||
|
has_russian = any("\u0400" <= char <= "\u04ff" for char in filter_dto.search)
|
||||||
|
|
||||||
|
if has_russian:
|
||||||
|
query = query.where(list_events_table.c.title.ilike(search_term))
|
||||||
|
else:
|
||||||
|
query = query.where(
|
||||||
|
or_(list_events_table.c.title.ilike(search_term), list_events_table.c.name.ilike(search_term))
|
||||||
|
)
|
||||||
|
|
||||||
|
filter_conditions = []
|
||||||
|
if filter_dto.filters:
|
||||||
|
for field, values in filter_dto.filters.items():
|
||||||
|
column = getattr(list_events_table.c, field, None)
|
||||||
|
if column is not None and values:
|
||||||
|
if len(values) == 1:
|
||||||
|
filter_conditions.append(column == values[0])
|
||||||
|
else:
|
||||||
|
filter_conditions.append(column.in_(values))
|
||||||
|
|
||||||
|
if filter_conditions:
|
||||||
|
query = query.where(and_(*filter_conditions))
|
||||||
|
|
||||||
|
if filter_dto.order:
|
||||||
|
order_field = filter_dto.order.get("field", "id")
|
||||||
|
order_direction = filter_dto.order.get("direction", "asc")
|
||||||
|
|
||||||
|
if order_field.startswith("schema."):
|
||||||
|
json_field = order_field[7:]
|
||||||
|
column = list_events_table.c.schema[json_field].astext
|
||||||
|
else:
|
||||||
|
column = getattr(list_events_table.c, order_field, None)
|
||||||
|
|
||||||
|
if column is not None:
|
||||||
|
if order_direction.lower() == "desc":
|
||||||
|
query = query.order_by(desc(column))
|
||||||
|
else:
|
||||||
|
query = query.order_by(asc(column))
|
||||||
|
else:
|
||||||
|
query = query.order_by(list_events_table.c.id)
|
||||||
|
|
||||||
|
query = query.offset(offset).limit(limit)
|
||||||
|
|
||||||
|
count_query = select(func.count()).select_from(list_events_table)
|
||||||
|
|
||||||
|
if filter_dto.search:
|
||||||
|
search_term = f"%{filter_dto.search}%"
|
||||||
|
has_russian = any("\u0400" <= char <= "\u04ff" for char in filter_dto.search)
|
||||||
|
|
||||||
|
if has_russian:
|
||||||
|
count_query = count_query.where(list_events_table.c.title.ilike(search_term))
|
||||||
|
else:
|
||||||
|
count_query = count_query.where(
|
||||||
|
or_(list_events_table.c.title.ilike(search_term), list_events_table.c.name.ilike(search_term))
|
||||||
|
)
|
||||||
|
|
||||||
|
if filter_conditions:
|
||||||
|
count_query = count_query.where(and_(*filter_conditions))
|
||||||
|
|
||||||
|
result = await connection.execute(query)
|
||||||
|
count_result = await connection.execute(count_query)
|
||||||
|
|
||||||
|
events_data = result.mappings().all()
|
||||||
|
total_count = count_result.scalar()
|
||||||
|
|
||||||
|
if not total_count:
|
||||||
|
return None
|
||||||
|
|
||||||
|
total_pages = math.ceil(total_count / limit)
|
||||||
|
validated_events = all_list_event_adapter.validate_python(events_data)
|
||||||
|
|
||||||
|
return AllListEventResponse(
|
||||||
|
list_event=validated_events,
|
||||||
|
amount_count=total_count,
|
||||||
|
amount_pages=total_pages,
|
||||||
|
current_page=page,
|
||||||
|
limit=limit,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_list_events_page_by_creator_id(
|
||||||
|
connection: AsyncConnection, creator_id: int, page: int, limit: int
|
||||||
|
) -> Optional[AllListEventResponse]:
|
||||||
|
"""
|
||||||
|
Получает список событий заданного создателя по значениям page и limit и creator_id.
|
||||||
|
"""
|
||||||
|
|
||||||
|
first_event = page * limit - limit
|
||||||
|
query = (
|
||||||
|
select(
|
||||||
|
list_events_table.c.id,
|
||||||
|
list_events_table.c.name,
|
||||||
|
list_events_table.c.title,
|
||||||
|
list_events_table.c.creator_id,
|
||||||
|
list_events_table.c.created_at,
|
||||||
|
list_events_table.c.schema,
|
||||||
|
list_events_table.c.state,
|
||||||
|
list_events_table.c.status,
|
||||||
|
)
|
||||||
|
.where(list_events_table.c.creator_id == creator_id) # Фильтрация по creator_id
|
||||||
|
.order_by(list_events_table.c.id)
|
||||||
|
.offset(first_event)
|
||||||
|
.limit(limit)
|
||||||
|
)
|
||||||
|
|
||||||
|
count_query = (
|
||||||
|
select(func.count())
|
||||||
|
.select_from(list_events_table)
|
||||||
|
.where(list_events_table.c.creator_id == creator_id) # Фильтрация по creator_id
|
||||||
|
)
|
||||||
|
|
||||||
|
result = await connection.execute(query)
|
||||||
|
count_result = await connection.execute(count_query)
|
||||||
|
|
||||||
|
events_data = result.mappings().all()
|
||||||
|
total_count = count_result.scalar()
|
||||||
|
total_pages = math.ceil(total_count / limit)
|
||||||
|
|
||||||
|
# Здесь предполагается, что all_list_event_adapter.validate_python корректно обрабатывает данные
|
||||||
|
validated_list_event = all_list_event_adapter.validate_python(events_data)
|
||||||
|
|
||||||
|
return AllListEventResponse(
|
||||||
|
list_event=validated_list_event,
|
||||||
|
amount_count=total_count,
|
||||||
|
amount_pages=total_pages,
|
||||||
|
current_page=page,
|
||||||
|
limit=limit,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_list_events_page(connection: AsyncConnection, page, limit) -> Optional[AllListEventResponse]:
|
||||||
|
"""
|
||||||
|
Получает список событий заданного создателя по значениям page и limit.
|
||||||
|
"""
|
||||||
|
|
||||||
|
first_event = page * limit - (limit)
|
||||||
|
|
||||||
|
query = (
|
||||||
|
select(
|
||||||
|
list_events_table.c.id,
|
||||||
|
list_events_table.c.name,
|
||||||
|
list_events_table.c.title,
|
||||||
|
list_events_table.c.creator_id,
|
||||||
|
list_events_table.c.created_at,
|
||||||
|
list_events_table.c.schema,
|
||||||
|
list_events_table.c.state,
|
||||||
|
list_events_table.c.status,
|
||||||
|
)
|
||||||
|
.order_by(list_events_table.c.id)
|
||||||
|
.offset(first_event)
|
||||||
|
.limit(limit)
|
||||||
|
)
|
||||||
|
|
||||||
|
count_query = select(func.count()).select_from(list_events_table)
|
||||||
|
|
||||||
|
result = await connection.execute(query)
|
||||||
|
count_result = await connection.execute(count_query)
|
||||||
|
|
||||||
|
events_data = result.mappings().all()
|
||||||
|
total_count = count_result.scalar()
|
||||||
|
total_pages = math.ceil(total_count / limit)
|
||||||
|
|
||||||
|
# Здесь предполагается, что all_list_event_adapter.validate_python корректно обрабатывает данные
|
||||||
|
validated_list_event = all_list_event_adapter.validate_python(events_data)
|
||||||
|
|
||||||
|
return AllListEventResponse(
|
||||||
|
list_event=validated_list_event,
|
||||||
|
amount_count=total_count,
|
||||||
|
amount_pages=total_pages,
|
||||||
|
current_page=page,
|
||||||
|
limit=limit,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_list_events_by_name(connection: AsyncConnection, name: str) -> Optional[ListEvent]:
|
||||||
|
"""
|
||||||
|
Получает list events по name.
|
||||||
|
"""
|
||||||
|
query = select(list_events_table).where(list_events_table.c.name == name)
|
||||||
|
|
||||||
|
list_events_db_cursor = await connection.execute(query)
|
||||||
|
|
||||||
|
list_events_data = list_events_db_cursor.mappings().one_or_none()
|
||||||
|
if not list_events_data:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return ListEvent.model_validate(list_events_data)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_list_events_by_id(connection: AsyncConnection, id: int) -> Optional[ListEvent]:
|
||||||
|
"""
|
||||||
|
Получает listevent по id.
|
||||||
|
"""
|
||||||
|
query = select(list_events_table).where(list_events_table.c.id == id)
|
||||||
|
|
||||||
|
list_events_db_cursor = await connection.execute(query)
|
||||||
|
|
||||||
|
list_events_data = list_events_db_cursor.mappings().one_or_none()
|
||||||
|
if not list_events_data:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return ListEvent.model_validate(list_events_data)
|
||||||
|
|
||||||
|
|
||||||
|
async def update_list_events_by_id(connection: AsyncConnection, update_values, list_events):
|
||||||
|
"""
|
||||||
|
Вносит изменеия в нужное поле таблицы list_events_table.
|
||||||
|
"""
|
||||||
|
await connection.execute(
|
||||||
|
list_events_table.update().where(list_events_table.c.id == list_events.id).values(**update_values)
|
||||||
|
)
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
|
||||||
|
async def create_list_events(
|
||||||
|
connection: AsyncConnection, list_events: ListEvent, creator_id: int
|
||||||
|
) -> Optional[ListEvent]:
|
||||||
|
"""
|
||||||
|
Создает нове поле в таблице list_events_table.
|
||||||
|
"""
|
||||||
|
query = insert(list_events_table).values(
|
||||||
|
name=list_events.name,
|
||||||
|
title=list_events.title, # добавлено поле title
|
||||||
|
creator_id=creator_id,
|
||||||
|
created_at=datetime.now(timezone.utc),
|
||||||
|
schema=list_events.schema_, # добавлено поле schema
|
||||||
|
state=list_events.state.value, # добавлено поле state
|
||||||
|
status=list_events.status.value, # добавлено поле status
|
||||||
|
)
|
||||||
|
|
||||||
|
await connection.execute(query)
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
return list_events
|
175
api/api/db/logic/process_schema.py
Normal file
175
api/api/db/logic/process_schema.py
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
from typing import Optional
|
||||||
|
import math
|
||||||
|
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
from sqlalchemy import insert, select, func, or_, and_, asc, desc
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
|
from api.db.tables.process import process_schema_table
|
||||||
|
|
||||||
|
from api.schemas.process.process_schema import ProcessSchema
|
||||||
|
|
||||||
|
from api.schemas.endpoints.process_schema import (
|
||||||
|
all_process_schema_adapter,
|
||||||
|
AllProcessSchemaResponse,
|
||||||
|
ProcessSchemaFilterDTO,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_process_schema_page_DTO(
|
||||||
|
connection: AsyncConnection, filter_dto: ProcessSchemaFilterDTO
|
||||||
|
) -> Optional[AllProcessSchemaResponse]:
|
||||||
|
"""
|
||||||
|
Получает список схем процессов с комплексной фильтрацией через DTO объект.
|
||||||
|
Поддерживает:
|
||||||
|
- пагинацию
|
||||||
|
- поиск
|
||||||
|
- фильтрацию по полям
|
||||||
|
- сортировку
|
||||||
|
"""
|
||||||
|
|
||||||
|
page = filter_dto.pagination.get("page", 1)
|
||||||
|
limit = filter_dto.pagination.get("limit", 10)
|
||||||
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
query = select(
|
||||||
|
process_schema_table.c.id,
|
||||||
|
process_schema_table.c.title,
|
||||||
|
process_schema_table.c.description,
|
||||||
|
process_schema_table.c.owner_id,
|
||||||
|
process_schema_table.c.creator_id,
|
||||||
|
process_schema_table.c.created_at,
|
||||||
|
process_schema_table.c.settings,
|
||||||
|
process_schema_table.c.status,
|
||||||
|
)
|
||||||
|
|
||||||
|
if filter_dto.search:
|
||||||
|
search_term = f"%{filter_dto.search}%"
|
||||||
|
query = query.where(
|
||||||
|
or_(process_schema_table.c.title.ilike(search_term), process_schema_table.c.description.ilike(search_term))
|
||||||
|
)
|
||||||
|
|
||||||
|
if filter_dto.filters:
|
||||||
|
filter_conditions = []
|
||||||
|
for field, values in filter_dto.filters.items():
|
||||||
|
column = getattr(process_schema_table.c, field, None)
|
||||||
|
if column is not None and values:
|
||||||
|
if len(values) == 1:
|
||||||
|
filter_conditions.append(column == values[0])
|
||||||
|
else:
|
||||||
|
filter_conditions.append(column.in_(values))
|
||||||
|
|
||||||
|
if filter_conditions:
|
||||||
|
query = query.where(and_(*filter_conditions))
|
||||||
|
|
||||||
|
if filter_dto.order:
|
||||||
|
order_field = filter_dto.order.get("field", "id")
|
||||||
|
order_direction = filter_dto.order.get("direction", "asc")
|
||||||
|
|
||||||
|
column = getattr(process_schema_table.c, order_field, None)
|
||||||
|
if column is not None:
|
||||||
|
if order_direction.lower() == "desc":
|
||||||
|
query = query.order_by(desc(column))
|
||||||
|
else:
|
||||||
|
query = query.order_by(asc(column))
|
||||||
|
else:
|
||||||
|
query = query.order_by(process_schema_table.c.id)
|
||||||
|
|
||||||
|
query = query.offset(offset).limit(limit)
|
||||||
|
|
||||||
|
count_query = select(func.count()).select_from(process_schema_table)
|
||||||
|
|
||||||
|
if filter_dto.search:
|
||||||
|
search_term = f"%{filter_dto.search}%"
|
||||||
|
count_query = count_query.where(
|
||||||
|
or_(process_schema_table.c.title.ilike(search_term), process_schema_table.c.description.ilike(search_term))
|
||||||
|
)
|
||||||
|
|
||||||
|
if filter_dto.filters and filter_conditions:
|
||||||
|
count_query = count_query.where(and_(*filter_conditions))
|
||||||
|
|
||||||
|
result = await connection.execute(query)
|
||||||
|
count_result = await connection.execute(count_query)
|
||||||
|
|
||||||
|
events_data = result.mappings().all()
|
||||||
|
total_count = count_result.scalar()
|
||||||
|
|
||||||
|
if not total_count:
|
||||||
|
return None
|
||||||
|
|
||||||
|
total_pages = math.ceil(total_count / limit)
|
||||||
|
|
||||||
|
validated_process_schema = all_process_schema_adapter.validate_python(events_data)
|
||||||
|
|
||||||
|
return AllProcessSchemaResponse(
|
||||||
|
process_schema=validated_process_schema,
|
||||||
|
amount_count=total_count,
|
||||||
|
amount_pages=total_pages,
|
||||||
|
current_page=page,
|
||||||
|
limit=limit,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_process_schema_by_title(connection: AsyncConnection, title: str) -> Optional[ProcessSchema]:
|
||||||
|
"""
|
||||||
|
Получает process schema по title.
|
||||||
|
"""
|
||||||
|
query = select(process_schema_table).where(process_schema_table.c.title == title)
|
||||||
|
|
||||||
|
process_schema_db_cursor = await connection.execute(query)
|
||||||
|
|
||||||
|
process_schema_data = process_schema_db_cursor.mappings().one_or_none()
|
||||||
|
if not process_schema_data:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return ProcessSchema.model_validate(process_schema_data)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_process_schema_by_id(connection: AsyncConnection, id: int) -> Optional[ProcessSchema]:
|
||||||
|
"""
|
||||||
|
Получает process_schema по id.
|
||||||
|
"""
|
||||||
|
query = select(process_schema_table).where(process_schema_table.c.id == id)
|
||||||
|
|
||||||
|
process_schema_db_cursor = await connection.execute(query)
|
||||||
|
|
||||||
|
process_schema_data = process_schema_db_cursor.mappings().one_or_none()
|
||||||
|
if not process_schema_data:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return ProcessSchema.model_validate(process_schema_data)
|
||||||
|
|
||||||
|
|
||||||
|
async def update_process_schema_by_id(connection: AsyncConnection, update_values, process_schema):
|
||||||
|
"""
|
||||||
|
Вносит изменеия в нужное поле таблицы process_schema_table.
|
||||||
|
"""
|
||||||
|
await connection.execute(
|
||||||
|
process_schema_table.update().where(process_schema_table.c.id == process_schema.id).values(**update_values)
|
||||||
|
)
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
|
||||||
|
async def create_process_schema(
|
||||||
|
connection: AsyncConnection, process_schema: ProcessSchema, creator_id: int
|
||||||
|
) -> Optional[ProcessSchema]:
|
||||||
|
"""
|
||||||
|
Создает нове поле в таблице process_schema_table.
|
||||||
|
"""
|
||||||
|
query = insert(process_schema_table).values(
|
||||||
|
title=process_schema.title,
|
||||||
|
description=process_schema.description,
|
||||||
|
owner_id=process_schema.owner_id,
|
||||||
|
creator_id=creator_id,
|
||||||
|
created_at=datetime.now(timezone.utc),
|
||||||
|
settings=process_schema.settings,
|
||||||
|
status=process_schema.status.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
await connection.execute(query)
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
return process_schema
|
@@ -3,8 +3,6 @@ import enum
|
|||||||
from sqlalchemy import Table, Column, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index
|
from sqlalchemy import Table, Column, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from api.db.sql_types import UnsignedInt
|
from api.db.sql_types import UnsignedInt
|
||||||
from api.db import metadata
|
from api.db import metadata
|
||||||
|
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
import enum
|
import enum
|
||||||
|
|
||||||
from sqlalchemy import Table, Column, Integer, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index
|
from sqlalchemy import Table, Column, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
from enum import Enum, auto
|
|
||||||
|
|
||||||
from api.db.sql_types import UnsignedInt
|
from api.db.sql_types import UnsignedInt
|
||||||
|
|
||||||
|
@@ -3,7 +3,6 @@ import enum
|
|||||||
from sqlalchemy import (
|
from sqlalchemy import (
|
||||||
Table,
|
Table,
|
||||||
Column,
|
Column,
|
||||||
Integer,
|
|
||||||
String,
|
String,
|
||||||
Text,
|
Text,
|
||||||
Enum as SQLAEnum,
|
Enum as SQLAEnum,
|
||||||
@@ -14,7 +13,7 @@ from sqlalchemy import (
|
|||||||
PrimaryKeyConstraint,
|
PrimaryKeyConstraint,
|
||||||
)
|
)
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
from enum import Enum, auto
|
from enum import Enum
|
||||||
|
|
||||||
from api.db.sql_types import UnsignedInt
|
from api.db.sql_types import UnsignedInt
|
||||||
|
|
||||||
|
@@ -2,8 +2,10 @@ from api.endpoints.auth import api_router as auth_router
|
|||||||
from api.endpoints.profile import api_router as profile_router
|
from api.endpoints.profile import api_router as profile_router
|
||||||
from api.endpoints.account import api_router as account_router
|
from api.endpoints.account import api_router as account_router
|
||||||
from api.endpoints.keyring import api_router as keyring_router
|
from api.endpoints.keyring import api_router as keyring_router
|
||||||
|
from api.endpoints.list_events import api_router as listevents_router
|
||||||
|
from api.endpoints.process_schema import api_router as processschema_router
|
||||||
|
|
||||||
list_of_routes = [auth_router, profile_router, account_router, keyring_router]
|
list_of_routes = [auth_router, profile_router, account_router, keyring_router, listevents_router, processschema_router]
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"list_of_routes",
|
"list_of_routes",
|
||||||
|
@@ -1,15 +1,12 @@
|
|||||||
from fastapi import (
|
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||||
APIRouter,
|
|
||||||
Depends,
|
from typing import Optional, List
|
||||||
HTTPException,
|
|
||||||
status,
|
|
||||||
)
|
|
||||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
from api.db.connection.session import get_connection_dep
|
from api.db.connection.session import get_connection_dep
|
||||||
from api.db.logic.account import (
|
from api.db.logic.account import (
|
||||||
create_user,
|
create_user,
|
||||||
get_user_accaunt_page,
|
get_user_account_page_DTO,
|
||||||
get_user_by_id,
|
get_user_by_id,
|
||||||
get_user_by_login,
|
get_user_by_login,
|
||||||
update_user_by_id,
|
update_user_by_id,
|
||||||
@@ -18,9 +15,8 @@ from api.db.logic.keyring import create_password_key, update_password_key
|
|||||||
from api.db.tables.account import AccountStatus
|
from api.db.tables.account import AccountStatus
|
||||||
from api.schemas.account.account import User
|
from api.schemas.account.account import User
|
||||||
from api.schemas.base import bearer_schema
|
from api.schemas.base import bearer_schema
|
||||||
from api.schemas.endpoints.account import AllUser, AllUserResponse, UserCreate, UserUpdate
|
from api.schemas.endpoints.account import AllUserResponse, UserCreate, UserUpdate, UserFilterDTO
|
||||||
from api.services.auth import get_current_user
|
from api.services.auth import get_current_user
|
||||||
from api.services.update_data_validation import update_user_data_changes
|
|
||||||
from api.services.user_role_validation import db_user_role_validation
|
from api.services.user_role_validation import db_user_role_validation
|
||||||
|
|
||||||
api_router = APIRouter(
|
api_router = APIRouter(
|
||||||
@@ -31,14 +27,33 @@ api_router = APIRouter(
|
|||||||
|
|
||||||
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllUserResponse)
|
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllUserResponse)
|
||||||
async def get_all_account(
|
async def get_all_account(
|
||||||
page: int = 1,
|
page: int = Query(1, description="Page number", gt=0),
|
||||||
limit: int = 10,
|
limit: int = Query(10, description="КNumber of items per page", gt=0),
|
||||||
|
search: Optional[str] = Query(None, description="Search term to filter by name or login or email"),
|
||||||
|
status_filter: Optional[List[str]] = Query(None, description="Filter by status"),
|
||||||
|
role_filter: Optional[List[str]] = Query(None, description="Filter by role"),
|
||||||
|
creator_id: Optional[int] = Query(None, description="Filter by creator id"),
|
||||||
|
order_field: Optional[str] = Query("id", description="Field to sort by"),
|
||||||
|
order_direction: Optional[str] = Query("asc", description="Sort direction (asc/desc)"),
|
||||||
connection: AsyncConnection = Depends(get_connection_dep),
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
current_user=Depends(get_current_user),
|
current_user=Depends(get_current_user),
|
||||||
):
|
):
|
||||||
authorize_user = await db_user_role_validation(connection, current_user)
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
user_list = await get_user_accaunt_page(connection, page, limit)
|
filters = {
|
||||||
|
**({"status": status_filter} if status_filter else {}),
|
||||||
|
**({"role": role_filter} if role_filter else {}),
|
||||||
|
**({"creator_id": [str(creator_id)]} if creator_id else {}),
|
||||||
|
}
|
||||||
|
|
||||||
|
filter_dto = UserFilterDTO(
|
||||||
|
pagination={"page": page, "limit": limit},
|
||||||
|
search=search,
|
||||||
|
order={"field": order_field, "direction": order_direction},
|
||||||
|
filters=filters if filters else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
user_list = await get_user_account_page_DTO(connection, filter_dto)
|
||||||
|
|
||||||
if user_list is None:
|
if user_list is None:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Accounts not found")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Accounts not found")
|
||||||
@@ -46,7 +61,7 @@ async def get_all_account(
|
|||||||
return user_list
|
return user_list
|
||||||
|
|
||||||
|
|
||||||
@api_router.get("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=UserUpdate)
|
@api_router.get("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||||
async def get_account(
|
async def get_account(
|
||||||
user_id: int,
|
user_id: int,
|
||||||
connection: AsyncConnection = Depends(get_connection_dep),
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
@@ -62,7 +77,7 @@ async def get_account(
|
|||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=AllUser)
|
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||||
async def create_account(
|
async def create_account(
|
||||||
user: UserCreate,
|
user: UserCreate,
|
||||||
connection: AsyncConnection = Depends(get_connection_dep),
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
@@ -98,14 +113,12 @@ async def update_account(
|
|||||||
if user_update.password is not None:
|
if user_update.password is not None:
|
||||||
await update_password_key(connection, user.id, user_update.password)
|
await update_password_key(connection, user.id, user_update.password)
|
||||||
|
|
||||||
update_values = update_user_data_changes(user_update, user)
|
updated_values = user_update.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
if update_values is None:
|
if not updated_values:
|
||||||
return user
|
return user
|
||||||
|
|
||||||
user_update_data = UserUpdate.model_validate({**user.model_dump(), **update_values})
|
await update_user_by_id(connection, updated_values, user)
|
||||||
|
|
||||||
await update_user_by_id(connection, update_values, user)
|
|
||||||
|
|
||||||
user = await get_user_by_id(connection, user_id)
|
user = await get_user_by_id(connection, user_id)
|
||||||
|
|
||||||
@@ -126,12 +139,12 @@ async def delete_account(
|
|||||||
|
|
||||||
user_update = UserUpdate(status=AccountStatus.DELETED.value)
|
user_update = UserUpdate(status=AccountStatus.DELETED.value)
|
||||||
|
|
||||||
update_values = update_user_data_changes(user_update, user)
|
updated_values = user_update.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
if update_values is None:
|
if not updated_values:
|
||||||
return user
|
return user
|
||||||
|
|
||||||
await update_user_by_id(connection, update_values, user)
|
await update_user_by_id(connection, updated_values, user)
|
||||||
|
|
||||||
user = await get_user_by_id(connection, user_id)
|
user = await get_user_by_id(connection, user_id)
|
||||||
|
|
||||||
|
@@ -24,7 +24,6 @@ from api.schemas.account.account_keyring import AccountKeyring
|
|||||||
from api.services.auth import get_current_user
|
from api.services.auth import get_current_user
|
||||||
|
|
||||||
from api.services.user_role_validation import db_user_role_validation
|
from api.services.user_role_validation import db_user_role_validation
|
||||||
from api.services.update_data_validation import update_key_data_changes
|
|
||||||
|
|
||||||
|
|
||||||
api_router = APIRouter(
|
api_router = APIRouter(
|
||||||
@@ -87,14 +86,12 @@ async def update_keyring(
|
|||||||
if keyring is None:
|
if keyring is None:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="keyring not found")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="keyring not found")
|
||||||
|
|
||||||
update_values = update_key_data_changes(keyring_update, keyring)
|
updated_values = keyring_update.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
if update_values is None:
|
if not updated_values:
|
||||||
return keyring
|
return keyring
|
||||||
|
|
||||||
keyring_update_data = AccountKeyring.model_validate({**keyring.model_dump(), **update_values})
|
await update_key_by_id(connection, updated_values, keyring)
|
||||||
|
|
||||||
await update_key_by_id(connection, update_values, keyring)
|
|
||||||
|
|
||||||
keyring = await get_key_by_id(connection, key_id)
|
keyring = await get_key_by_id(connection, key_id)
|
||||||
|
|
||||||
@@ -116,12 +113,12 @@ async def delete_keyring(
|
|||||||
|
|
||||||
keyring_update = AccountKeyringUpdate(status=KeyStatus.DELETED.value)
|
keyring_update = AccountKeyringUpdate(status=KeyStatus.DELETED.value)
|
||||||
|
|
||||||
update_values = update_key_data_changes(keyring_update, keyring)
|
updated_values = keyring_update.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
if update_values is None:
|
if not updated_values:
|
||||||
return keyring
|
return keyring
|
||||||
|
|
||||||
await update_key_by_id(connection, update_values, keyring)
|
await update_key_by_id(connection, updated_values, keyring)
|
||||||
|
|
||||||
keyring = await get_key_by_id(connection, key_id)
|
keyring = await get_key_by_id(connection, key_id)
|
||||||
|
|
||||||
|
179
api/api/endpoints/list_events.py
Normal file
179
api/api/endpoints/list_events.py
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||||
|
|
||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
|
from api.db.connection.session import get_connection_dep
|
||||||
|
|
||||||
|
from api.db.logic.account import get_user_by_login
|
||||||
|
|
||||||
|
from api.db.logic.list_events import (
|
||||||
|
get_list_events_by_name,
|
||||||
|
get_list_events_by_id,
|
||||||
|
create_list_events,
|
||||||
|
update_list_events_by_id,
|
||||||
|
get_list_events_page_DTO,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
from api.schemas.events.list_events import ListEvent
|
||||||
|
from api.db.tables.events import EventStatus
|
||||||
|
|
||||||
|
from api.schemas.base import bearer_schema
|
||||||
|
|
||||||
|
from api.schemas.endpoints.list_events import ListEventUpdate, AllListEventResponse, ListEventFilterDTO
|
||||||
|
|
||||||
|
from api.services.auth import get_current_user
|
||||||
|
|
||||||
|
from api.services.user_role_validation import (
|
||||||
|
db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
|
||||||
|
db_user_role_validation_for_list_events_and_process_schema,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
api_router = APIRouter(
|
||||||
|
prefix="/list_events",
|
||||||
|
tags=["list events"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllListEventResponse)
|
||||||
|
async def get_all_list_events(
|
||||||
|
page: int = Query(1, description="Page number", gt=0),
|
||||||
|
limit: int = Query(10, description="Number of items per page", gt=0),
|
||||||
|
search: Optional[str] = Query(None, description="Search term to filter by title or name"),
|
||||||
|
order_field: Optional[str] = Query("id", description="Field to sort by"),
|
||||||
|
order_direction: Optional[str] = Query("asc", description="Sort direction (asc/desc)"),
|
||||||
|
status_filter: Optional[List[str]] = Query(None, description="Filter by status"),
|
||||||
|
state_filter: Optional[List[str]] = Query(None, description="Filter by state"),
|
||||||
|
creator_id: Optional[int] = Query(None, description="Filter by creator id"),
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
filters = {
|
||||||
|
**({"status": status_filter} if status_filter else {}),
|
||||||
|
**({"state": state_filter} if state_filter else {}),
|
||||||
|
**({"creator_id": [str(creator_id)]} if creator_id else {}),
|
||||||
|
}
|
||||||
|
|
||||||
|
filter_dto = ListEventFilterDTO(
|
||||||
|
pagination={"page": page, "limit": limit},
|
||||||
|
search=search,
|
||||||
|
order={"field": order_field, "direction": order_direction},
|
||||||
|
filters=filters if filters else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
authorize_user, page_flag = await db_user_role_validation_for_list_events_and_process_schema(
|
||||||
|
connection, current_user
|
||||||
|
)
|
||||||
|
|
||||||
|
if not page_flag:
|
||||||
|
if filter_dto.filters is None:
|
||||||
|
filter_dto.filters = {}
|
||||||
|
filter_dto.filters["creator_id"] = [str(authorize_user.id)]
|
||||||
|
|
||||||
|
list_events_page = await get_list_events_page_DTO(connection, filter_dto)
|
||||||
|
|
||||||
|
if list_events_page is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
|
||||||
|
|
||||||
|
return list_events_page
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.get("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
|
||||||
|
async def get_list_events(
|
||||||
|
list_events_id: int,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
list_events_validation = await get_list_events_by_id(connection, list_events_id)
|
||||||
|
|
||||||
|
if list_events_validation is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
|
||||||
|
|
||||||
|
authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
|
||||||
|
connection, current_user, list_events_validation.creator_id
|
||||||
|
)
|
||||||
|
|
||||||
|
if list_events_id is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
|
||||||
|
|
||||||
|
return list_events_validation
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
|
||||||
|
async def create_list_events(
|
||||||
|
list_events: ListEventUpdate,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
user_validation = await get_user_by_login(connection, current_user)
|
||||||
|
list_events_validation = await get_list_events_by_name(connection, list_events.name)
|
||||||
|
|
||||||
|
if list_events_validation is None:
|
||||||
|
await create_list_events(connection, list_events, user_validation.id)
|
||||||
|
list_events_new = await get_list_events_by_name(connection, list_events.name)
|
||||||
|
return list_events_new
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST, detail="An List events with this information already exists."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.put("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
|
||||||
|
async def update_list_events(
|
||||||
|
list_events_id: int,
|
||||||
|
list_events_update: ListEventUpdate,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
list_events_validation = await get_list_events_by_id(connection, list_events_id)
|
||||||
|
|
||||||
|
if list_events_validation is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
|
||||||
|
|
||||||
|
authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
|
||||||
|
connection, current_user, list_events_validation.creator_id
|
||||||
|
)
|
||||||
|
|
||||||
|
updated_values = list_events_update.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
|
if not updated_values:
|
||||||
|
return list_events_validation
|
||||||
|
|
||||||
|
await update_list_events_by_id(connection, updated_values, list_events_validation)
|
||||||
|
|
||||||
|
list_events = await get_list_events_by_id(connection, list_events_id)
|
||||||
|
|
||||||
|
return list_events
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.delete("/{list_events_id}", dependencies=[Depends(bearer_schema)], response_model=ListEvent)
|
||||||
|
async def delete_list_events(
|
||||||
|
list_events_id: int,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
list_events_validation = await get_list_events_by_id(connection, list_events_id)
|
||||||
|
|
||||||
|
if list_events_validation is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="List events not found")
|
||||||
|
|
||||||
|
authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
|
||||||
|
connection, current_user, list_events_validation.creator_id
|
||||||
|
)
|
||||||
|
|
||||||
|
list_events_update = ListEventUpdate(status=EventStatus.DELETED.value)
|
||||||
|
|
||||||
|
updated_values = list_events_update.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
|
if not updated_values:
|
||||||
|
return list_events_validation
|
||||||
|
|
||||||
|
await update_list_events_by_id(connection, updated_values, list_events_validation)
|
||||||
|
|
||||||
|
list_events = await get_list_events_by_id(connection, list_events_id)
|
||||||
|
|
||||||
|
return list_events
|
178
api/api/endpoints/process_schema.py
Normal file
178
api/api/endpoints/process_schema.py
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||||
|
|
||||||
|
from typing import Optional, List
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
|
from api.db.connection.session import get_connection_dep
|
||||||
|
|
||||||
|
from api.db.logic.account import get_user_by_login
|
||||||
|
|
||||||
|
from api.db.logic.process_schema import (
|
||||||
|
get_process_schema_by_title,
|
||||||
|
create_process_schema,
|
||||||
|
get_process_schema_by_id,
|
||||||
|
update_process_schema_by_id,
|
||||||
|
get_process_schema_page_DTO,
|
||||||
|
)
|
||||||
|
|
||||||
|
from api.schemas.process.process_schema import ProcessSchema
|
||||||
|
|
||||||
|
from api.db.tables.process import ProcessStatus
|
||||||
|
|
||||||
|
from api.schemas.base import bearer_schema
|
||||||
|
|
||||||
|
from api.schemas.endpoints.process_schema import ProcessSchemaUpdate, AllProcessSchemaResponse, ProcessSchemaFilterDTO
|
||||||
|
|
||||||
|
from api.services.auth import get_current_user
|
||||||
|
|
||||||
|
from api.services.user_role_validation import (
|
||||||
|
db_user_role_validation_for_list_events_and_process_schema_by_list_event_id,
|
||||||
|
db_user_role_validation_for_list_events_and_process_schema,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
api_router = APIRouter(
|
||||||
|
prefix="/process_schema",
|
||||||
|
tags=["process schema"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllProcessSchemaResponse)
|
||||||
|
async def get_all_process_schema(
|
||||||
|
page: int = Query(1, description="Page number", gt=0),
|
||||||
|
limit: int = Query(10, description="Number of items per page", gt=0),
|
||||||
|
search: Optional[str] = Query(None, description="Search term to filter by title or description"),
|
||||||
|
order_field: Optional[str] = Query("id", description="Field to sort by"),
|
||||||
|
order_direction: Optional[str] = Query("asc", description="Sort direction (asc/desc)"),
|
||||||
|
status_filter: Optional[List[str]] = Query(None, description="Filter by status"),
|
||||||
|
owner_id: Optional[List[str]] = Query(None, description="Filter by owner id"),
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
creator_id: Optional[int] = Query(None, description="Filter by creator id"),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
filters = {
|
||||||
|
**({"status": status_filter} if status_filter else {}),
|
||||||
|
**({"owner_id": owner_id} if owner_id else {}),
|
||||||
|
**({"creator_id": [str(creator_id)]} if creator_id else {}),
|
||||||
|
}
|
||||||
|
|
||||||
|
filter_dto = ProcessSchemaFilterDTO(
|
||||||
|
pagination={"page": page, "limit": limit},
|
||||||
|
search=search,
|
||||||
|
order={"field": order_field, "direction": order_direction},
|
||||||
|
filters=filters if filters else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
authorize_user, page_flag = await db_user_role_validation_for_list_events_and_process_schema(
|
||||||
|
connection, current_user
|
||||||
|
)
|
||||||
|
|
||||||
|
if not page_flag:
|
||||||
|
if filter_dto.filters is None:
|
||||||
|
filter_dto.filters = {}
|
||||||
|
filter_dto.filters["creator_id"] = [str(authorize_user.id)]
|
||||||
|
|
||||||
|
process_schema_page = await get_process_schema_page_DTO(connection, filter_dto)
|
||||||
|
|
||||||
|
if process_schema_page is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||||
|
|
||||||
|
return process_schema_page
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.get("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||||
|
async def get_process_schema(
|
||||||
|
process_schema_id: int,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
process_schema_validation = await get_process_schema_by_id(connection, process_schema_id)
|
||||||
|
|
||||||
|
if process_schema_validation is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||||
|
|
||||||
|
authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
|
||||||
|
connection, current_user, process_schema_validation.creator_id
|
||||||
|
)
|
||||||
|
|
||||||
|
if process_schema_id is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||||
|
|
||||||
|
return process_schema_validation
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||||
|
async def create_processschema(
|
||||||
|
process_schema: ProcessSchemaUpdate,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
user_validation = await get_user_by_login(connection, current_user)
|
||||||
|
process_schema_validation = await get_process_schema_by_title(connection, process_schema.title)
|
||||||
|
|
||||||
|
if process_schema_validation is None:
|
||||||
|
await create_process_schema(connection, process_schema, user_validation.id)
|
||||||
|
process_schema_new = await get_process_schema_by_title(connection, process_schema.title)
|
||||||
|
return process_schema_new
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST, detail="An process schema with this information already exists."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.put("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||||
|
async def update_process_schema(
|
||||||
|
process_schema_id: int,
|
||||||
|
process_schema_update: ProcessSchemaUpdate,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
process_schema_validation = await get_process_schema_by_id(connection, process_schema_id)
|
||||||
|
|
||||||
|
if process_schema_validation is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||||
|
|
||||||
|
authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
|
||||||
|
connection, current_user, process_schema_validation.creator_id
|
||||||
|
)
|
||||||
|
|
||||||
|
updated_values = process_schema_update.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
|
if not updated_values:
|
||||||
|
return process_schema_validation
|
||||||
|
|
||||||
|
await update_process_schema_by_id(connection, updated_values, process_schema_validation)
|
||||||
|
|
||||||
|
process_schema = await get_process_schema_by_id(connection, process_schema_id)
|
||||||
|
|
||||||
|
return process_schema
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.delete("/{process_schema_id}", dependencies=[Depends(bearer_schema)], response_model=ProcessSchema)
|
||||||
|
async def delete_process_schema(
|
||||||
|
process_schema_id: int,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
process_schema_validation = await get_process_schema_by_id(connection, process_schema_id)
|
||||||
|
|
||||||
|
if process_schema_validation is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Process schema not found")
|
||||||
|
|
||||||
|
authorize_user = await db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
|
||||||
|
connection, current_user, process_schema_validation.creator_id
|
||||||
|
)
|
||||||
|
|
||||||
|
process_schema_update = ProcessSchemaUpdate(status=ProcessStatus.DELETED.value)
|
||||||
|
|
||||||
|
updated_values = process_schema_update.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
|
if not updated_values:
|
||||||
|
return process_schema_validation
|
||||||
|
|
||||||
|
await update_process_schema_by_id(connection, updated_values, process_schema_validation)
|
||||||
|
|
||||||
|
process_schema = await get_process_schema_by_id(connection, process_schema_id)
|
||||||
|
|
||||||
|
return process_schema
|
@@ -1,11 +1,7 @@
|
|||||||
from fastapi import (
|
from fastapi import (
|
||||||
APIRouter,
|
APIRouter,
|
||||||
Body,
|
|
||||||
Depends,
|
Depends,
|
||||||
Form,
|
|
||||||
HTTPException,
|
HTTPException,
|
||||||
Request,
|
|
||||||
Response,
|
|
||||||
status,
|
status,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,7 +12,6 @@ from api.db.connection.session import get_connection_dep
|
|||||||
from api.db.logic.account import get_user_by_id, update_user_by_id, get_user_by_login
|
from api.db.logic.account import get_user_by_id, update_user_by_id, get_user_by_login
|
||||||
from api.schemas.base import bearer_schema
|
from api.schemas.base import bearer_schema
|
||||||
from api.services.auth import get_current_user
|
from api.services.auth import get_current_user
|
||||||
from api.services.update_data_validation import update_user_data_changes
|
|
||||||
|
|
||||||
from api.schemas.endpoints.account import UserUpdate
|
from api.schemas.endpoints.account import UserUpdate
|
||||||
from api.schemas.account.account import User
|
from api.schemas.account.account import User
|
||||||
@@ -42,7 +37,7 @@ async def get_profile(
|
|||||||
|
|
||||||
@api_router.put("", dependencies=[Depends(bearer_schema)], response_model=User)
|
@api_router.put("", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||||
async def update_profile(
|
async def update_profile(
|
||||||
user_updata: UserUpdate,
|
user_update: UserUpdate,
|
||||||
connection: AsyncConnection = Depends(get_connection_dep),
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
current_user=Depends(get_current_user),
|
current_user=Depends(get_current_user),
|
||||||
):
|
):
|
||||||
@@ -50,13 +45,13 @@ async def update_profile(
|
|||||||
if user is None:
|
if user is None:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
|
||||||
|
|
||||||
if user_updata.role == None and user_updata.login == None:
|
if user_update.role is None and user_update.login is None:
|
||||||
update_values = update_user_data_changes(user_updata, user)
|
updated_values = user_update.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
if update_values is None:
|
if updated_values is None:
|
||||||
return user
|
return user
|
||||||
|
|
||||||
await update_user_by_id(connection, update_values, user)
|
await update_user_by_id(connection, updated_values, user)
|
||||||
|
|
||||||
user = await get_user_by_id(connection, user.id)
|
user = await get_user_by_id(connection, user.id)
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Dict
|
||||||
|
|
||||||
from pydantic import EmailStr, Field, TypeAdapter
|
from pydantic import EmailStr, Field, TypeAdapter
|
||||||
|
|
||||||
@@ -8,7 +8,6 @@ from api.schemas.base import Base
|
|||||||
|
|
||||||
|
|
||||||
class UserUpdate(Base):
|
class UserUpdate(Base):
|
||||||
id: Optional[int] = None
|
|
||||||
name: Optional[str] = Field(None, max_length=100)
|
name: Optional[str] = Field(None, max_length=100)
|
||||||
login: Optional[str] = Field(None, max_length=100)
|
login: Optional[str] = Field(None, max_length=100)
|
||||||
email: Optional[EmailStr] = None
|
email: Optional[EmailStr] = None
|
||||||
@@ -16,8 +15,6 @@ class UserUpdate(Base):
|
|||||||
bind_tenant_id: Optional[str] = Field(None, max_length=40)
|
bind_tenant_id: Optional[str] = Field(None, max_length=40)
|
||||||
role: Optional[AccountRole] = None
|
role: Optional[AccountRole] = None
|
||||||
meta: Optional[dict] = None
|
meta: Optional[dict] = None
|
||||||
creator_id: Optional[int] = None
|
|
||||||
created_at: Optional[datetime] = None
|
|
||||||
status: Optional[AccountStatus] = None
|
status: Optional[AccountStatus] = None
|
||||||
|
|
||||||
|
|
||||||
@@ -39,6 +36,8 @@ class AllUser(Base):
|
|||||||
email: Optional[EmailStr] = None
|
email: Optional[EmailStr] = None
|
||||||
bind_tenant_id: Optional[str] = None
|
bind_tenant_id: Optional[str] = None
|
||||||
role: AccountRole
|
role: AccountRole
|
||||||
|
meta: Optional[dict] = None
|
||||||
|
creator_id: Optional[int] = None
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
status: AccountStatus
|
status: AccountStatus
|
||||||
|
|
||||||
@@ -52,3 +51,10 @@ class AllUserResponse(Base):
|
|||||||
|
|
||||||
|
|
||||||
all_user_adapter = TypeAdapter(List[AllUser])
|
all_user_adapter = TypeAdapter(List[AllUser])
|
||||||
|
|
||||||
|
|
||||||
|
class UserFilterDTO(Base):
|
||||||
|
pagination: Dict[str, int]
|
||||||
|
search: Optional[str] = None
|
||||||
|
order: Optional[Dict[str, str]] = None
|
||||||
|
filters: Optional[Dict[str, List[str]]] = None
|
||||||
|
@@ -1,17 +1,11 @@
|
|||||||
import datetime
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
from datetime import datetime
|
|
||||||
from api.db.tables.account import KeyType, KeyStatus
|
from api.db.tables.account import KeyType, KeyStatus
|
||||||
|
|
||||||
from api.schemas.base import Base
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
class AccountKeyringUpdate(Base):
|
class AccountKeyringUpdate(Base):
|
||||||
owner_id: Optional[int] = None
|
owner_id: Optional[int] = None
|
||||||
key_type: Optional[KeyType] = None
|
key_type: Optional[KeyType] = None
|
||||||
key_id: Optional[str] = Field(None, max_length=40)
|
|
||||||
key_value: Optional[str] = Field(None, max_length=255)
|
key_value: Optional[str] = Field(None, max_length=255)
|
||||||
created_at: Optional[datetime] = None
|
|
||||||
expiry: Optional[datetime] = None
|
|
||||||
status: Optional[KeyStatus] = None
|
status: Optional[KeyStatus] = None
|
||||||
|
44
api/api/schemas/endpoints/list_events.py
Normal file
44
api/api/schemas/endpoints/list_events.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
from pydantic import Field, TypeAdapter
|
||||||
|
from typing import Optional, Dict, Any, List
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
from api.schemas.base import Base
|
||||||
|
from api.db.tables.events import EventState, EventStatus
|
||||||
|
|
||||||
|
|
||||||
|
class ListEventUpdate(Base):
|
||||||
|
name: Optional[str] = Field(None, max_length=40)
|
||||||
|
title: Optional[str] = Field(None, max_length=64)
|
||||||
|
schema_: Optional[Dict[str, Any]] = Field(None, alias="schema")
|
||||||
|
state: Optional[EventState] = None
|
||||||
|
status: Optional[EventStatus] = None
|
||||||
|
|
||||||
|
|
||||||
|
class AllListEvent(Base):
|
||||||
|
id: int
|
||||||
|
name: str
|
||||||
|
title: str
|
||||||
|
creator_id: int
|
||||||
|
created_at: datetime
|
||||||
|
schema_: Dict[str, Any] = Field(default={}, alias="schema")
|
||||||
|
state: EventState
|
||||||
|
status: EventStatus
|
||||||
|
|
||||||
|
|
||||||
|
class AllListEventResponse(Base):
|
||||||
|
list_event: List[AllListEvent]
|
||||||
|
amount_count: int
|
||||||
|
amount_pages: int
|
||||||
|
current_page: int
|
||||||
|
limit: int
|
||||||
|
|
||||||
|
|
||||||
|
all_list_event_adapter = TypeAdapter(List[AllListEvent])
|
||||||
|
|
||||||
|
|
||||||
|
class ListEventFilterDTO(Base):
|
||||||
|
pagination: Dict[str, int]
|
||||||
|
search: Optional[str] = None
|
||||||
|
order: Optional[Dict[str, str]] = None
|
||||||
|
filters: Optional[Dict[str, List[str]]] = None
|
44
api/api/schemas/endpoints/process_schema.py
Normal file
44
api/api/schemas/endpoints/process_schema.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
from pydantic import Field, TypeAdapter
|
||||||
|
from typing import Optional, Dict, Any, List
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
from api.schemas.base import Base
|
||||||
|
from api.db.tables.process import ProcessStatus
|
||||||
|
|
||||||
|
|
||||||
|
class ProcessSchemaUpdate(Base):
|
||||||
|
title: Optional[str] = Field(None, max_length=100)
|
||||||
|
description: Optional[str] = None
|
||||||
|
owner_id: Optional[int] = None
|
||||||
|
settings: Optional[Dict[str, Any]] = None
|
||||||
|
status: Optional[ProcessStatus] = None
|
||||||
|
|
||||||
|
|
||||||
|
class AllProcessSchema(Base):
|
||||||
|
id: int
|
||||||
|
title: str = Field(..., max_length=100)
|
||||||
|
description: str
|
||||||
|
owner_id: int
|
||||||
|
creator_id: int
|
||||||
|
created_at: datetime
|
||||||
|
settings: Dict[str, Any]
|
||||||
|
status: ProcessStatus
|
||||||
|
|
||||||
|
|
||||||
|
class AllProcessSchemaResponse(Base):
|
||||||
|
process_schema: List[AllProcessSchema]
|
||||||
|
amount_count: int
|
||||||
|
amount_pages: int
|
||||||
|
current_page: int
|
||||||
|
limit: int
|
||||||
|
|
||||||
|
|
||||||
|
all_process_schema_adapter = TypeAdapter(List[AllProcessSchema])
|
||||||
|
|
||||||
|
|
||||||
|
class ProcessSchemaFilterDTO(Base):
|
||||||
|
pagination: Dict[str, int]
|
||||||
|
search: Optional[str] = None
|
||||||
|
order: Optional[Dict[str, str]] = None
|
||||||
|
filters: Optional[Dict[str, List[str]]] = None
|
@@ -1,20 +1,9 @@
|
|||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from api.schemas.base import Base
|
from api.schemas.base import Base
|
||||||
|
from api.db.tables.events import EventState, EventStatus
|
||||||
|
|
||||||
class State(Enum):
|
|
||||||
AUTO = "Auto"
|
|
||||||
DESCRIPTED = "Descripted"
|
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
|
||||||
ACTIVE = "Active"
|
|
||||||
DISABLED = "Disabled"
|
|
||||||
DELETED = "Deleted"
|
|
||||||
|
|
||||||
|
|
||||||
class ListEvent(Base):
|
class ListEvent(Base):
|
||||||
@@ -23,6 +12,6 @@ class ListEvent(Base):
|
|||||||
title: str = Field(..., max_length=64)
|
title: str = Field(..., max_length=64)
|
||||||
creator_id: int
|
creator_id: int
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
schema: Dict[str, Any]
|
schema_: Dict[str, Any] = Field(..., alias="schema")
|
||||||
state: State
|
state: EventState
|
||||||
status: Status
|
status: EventStatus
|
||||||
|
@@ -1,16 +1,9 @@
|
|||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from api.schemas.base import Base
|
from api.schemas.base import Base
|
||||||
|
from api.db.tables.process import NodeStatus
|
||||||
|
|
||||||
class Status(Enum):
|
|
||||||
ACTIVE = "Active"
|
|
||||||
STOPPING = "Stopping"
|
|
||||||
STOPPED = "Stopped"
|
|
||||||
DELETED = "Deleted"
|
|
||||||
|
|
||||||
|
|
||||||
class MyModel(Base):
|
class MyModel(Base):
|
||||||
@@ -21,4 +14,4 @@ class MyModel(Base):
|
|||||||
settings: Dict[str, Any]
|
settings: Dict[str, Any]
|
||||||
creator_id: int
|
creator_id: int
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
status: Status
|
status: NodeStatus
|
||||||
|
@@ -1,16 +1,9 @@
|
|||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from api.schemas.base import Base
|
from api.schemas.base import Base
|
||||||
|
from api.db.tables.process import ProcessStatus
|
||||||
|
|
||||||
class Status(Enum):
|
|
||||||
ACTIVE = "Active"
|
|
||||||
STOPPING = "Stopping"
|
|
||||||
STOPPED = "Stopped"
|
|
||||||
DELETED = "Deleted"
|
|
||||||
|
|
||||||
|
|
||||||
class ProcessSchema(Base):
|
class ProcessSchema(Base):
|
||||||
@@ -21,4 +14,4 @@ class ProcessSchema(Base):
|
|||||||
creator_id: int
|
creator_id: int
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
settings: Dict[str, Any]
|
settings: Dict[str, Any]
|
||||||
status: Status
|
status: ProcessStatus
|
||||||
|
@@ -1,18 +1,8 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from api.schemas.base import Base
|
from api.schemas.base import Base
|
||||||
|
from api.db.tables.process import NodeType, NodeStatus
|
||||||
|
|
||||||
class NodeType(Enum):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
|
||||||
ACTIVE = "Active"
|
|
||||||
DISABLED = "Disabled"
|
|
||||||
DELETED = "Deleted"
|
|
||||||
|
|
||||||
|
|
||||||
class Ps_Node(Base):
|
class Ps_Node(Base):
|
||||||
@@ -22,4 +12,4 @@ class Ps_Node(Base):
|
|||||||
settings: dict
|
settings: dict
|
||||||
creator_id: Dict[str, Any]
|
creator_id: Dict[str, Any]
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
status: Status
|
status: NodeStatus
|
||||||
|
@@ -1,74 +0,0 @@
|
|||||||
from enum import Enum
|
|
||||||
from typing import Optional
|
|
||||||
from api.schemas.endpoints.account import UserUpdate
|
|
||||||
from api.db.tables.account import KeyType, KeyStatus
|
|
||||||
from api.schemas.endpoints.account_keyring import AccountKeyringUpdate
|
|
||||||
from api.db.tables.account import AccountRole, AccountStatus
|
|
||||||
|
|
||||||
|
|
||||||
def update_user_data_changes(update_data: UserUpdate, user) -> Optional[dict]:
|
|
||||||
"""
|
|
||||||
Сравнивает данные для обновления с текущими значениями пользователя.
|
|
||||||
Возвращает:
|
|
||||||
- None, если нет изменений
|
|
||||||
- Словарь {поле: новое_значение} для измененных полей
|
|
||||||
"""
|
|
||||||
update_values = {}
|
|
||||||
changes = {}
|
|
||||||
|
|
||||||
for field, value in update_data.model_dump(exclude_unset=True).items():
|
|
||||||
if value is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if isinstance(value, (AccountRole, AccountStatus)):
|
|
||||||
update_values[field] = value.value
|
|
||||||
else:
|
|
||||||
update_values[field] = value
|
|
||||||
|
|
||||||
for field, new_value in update_values.items():
|
|
||||||
if not hasattr(user, field):
|
|
||||||
continue
|
|
||||||
|
|
||||||
current_value = getattr(user, field)
|
|
||||||
|
|
||||||
if isinstance(current_value, Enum):
|
|
||||||
current_value = current_value.value
|
|
||||||
|
|
||||||
if current_value != new_value:
|
|
||||||
changes[field] = new_value
|
|
||||||
|
|
||||||
return changes if changes else None
|
|
||||||
|
|
||||||
|
|
||||||
def update_key_data_changes(update_data: AccountKeyringUpdate, key) -> Optional[dict]:
|
|
||||||
"""
|
|
||||||
Сравнивает данные для обновления с текущими значениями пользователя.
|
|
||||||
Возвращает:
|
|
||||||
- None, если нет изменений
|
|
||||||
- Словарь {поле: новое_значение} для измененных полей
|
|
||||||
"""
|
|
||||||
update_values = {}
|
|
||||||
changes = {}
|
|
||||||
|
|
||||||
for field, value in update_data.model_dump(exclude_unset=True).items():
|
|
||||||
if value is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if isinstance(value, (KeyType, KeyStatus)):
|
|
||||||
update_values[field] = value.value
|
|
||||||
else:
|
|
||||||
update_values[field] = value
|
|
||||||
|
|
||||||
for field, new_value in update_values.items():
|
|
||||||
if not hasattr(key, field):
|
|
||||||
continue
|
|
||||||
|
|
||||||
current_value = getattr(key, field)
|
|
||||||
|
|
||||||
if isinstance(current_value, Enum):
|
|
||||||
current_value = current_value.value
|
|
||||||
|
|
||||||
if current_value != new_value:
|
|
||||||
changes[field] = new_value
|
|
||||||
|
|
||||||
return changes if changes else None
|
|
@@ -11,3 +11,21 @@ async def db_user_role_validation(connection, current_user):
|
|||||||
if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}:
|
if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}:
|
||||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You do not have enough permissions")
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You do not have enough permissions")
|
||||||
return authorize_user
|
return authorize_user
|
||||||
|
|
||||||
|
|
||||||
|
async def db_user_role_validation_for_list_events_and_process_schema_by_list_event_id(
|
||||||
|
connection, current_user, current_listevents_creator_id
|
||||||
|
):
|
||||||
|
authorize_user = await get_user_by_login(connection, current_user)
|
||||||
|
if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}:
|
||||||
|
if authorize_user.id != current_listevents_creator_id:
|
||||||
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You do not have enough permissions")
|
||||||
|
return authorize_user
|
||||||
|
|
||||||
|
|
||||||
|
async def db_user_role_validation_for_list_events_and_process_schema(connection, current_user):
|
||||||
|
authorize_user = await get_user_by_login(connection, current_user)
|
||||||
|
if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}:
|
||||||
|
return authorize_user, False
|
||||||
|
else:
|
||||||
|
return authorize_user, True
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "api"
|
name = "api"
|
||||||
version = "0.0.4"
|
version = "0.0.5"
|
||||||
description = ""
|
description = ""
|
||||||
authors = [{ name = "Vladislav", email = "vlad.dev@heado.ru" }]
|
authors = [{ name = "Vladislav", email = "vlad.dev@heado.ru" }]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
234
client/package-lock.json
generated
234
client/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "client",
|
"name": "client",
|
||||||
"version": "0.0.3",
|
"version": "0.0.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "client",
|
"name": "client",
|
||||||
"version": "0.0.3",
|
"version": "0.0.5",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^5.6.1",
|
"@ant-design/icons": "^5.6.1",
|
||||||
"@testing-library/dom": "^10.4.0",
|
"@testing-library/dom": "^10.4.0",
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
"@types/jest": "^27.5.2",
|
"@types/jest": "^27.5.2",
|
||||||
"@types/react": "^19.0.11",
|
"@types/react": "^19.0.11",
|
||||||
"@types/react-dom": "^19.0.4",
|
"@types/react-dom": "^19.0.4",
|
||||||
|
"@xyflow/react": "^12.8.1",
|
||||||
"antd": "^5.24.7",
|
"antd": "^5.24.7",
|
||||||
"axios": "^1.9.0",
|
"axios": "^1.9.0",
|
||||||
"axios-retry": "^4.5.0",
|
"axios-retry": "^4.5.0",
|
||||||
@@ -1567,6 +1568,55 @@
|
|||||||
"@babel/types": "^7.20.7"
|
"@babel/types": "^7.20.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/d3-color": {
|
||||||
|
"version": "3.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-color/-/d3-color-3.1.3.tgz",
|
||||||
|
"integrity": "sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-drag": {
|
||||||
|
"version": "3.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-drag/-/d3-drag-3.0.7.tgz",
|
||||||
|
"integrity": "sha512-HE3jVKlzU9AaMazNufooRJ5ZpWmLIoc90A37WU2JMmeq28w1FQqCZswHZ3xR+SuxYftzHq6WU6KJHvqxKzTxxQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-selection": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-interpolate": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-interpolate/-/d3-interpolate-3.0.4.tgz",
|
||||||
|
"integrity": "sha512-mgLPETlrpVV1YRJIglr4Ez47g7Yxjl1lj7YKsiMCb27VJH9W8NVM6Bb9d8kkpG/uAQS5AmbA48q2IAolKKo1MA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-color": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-selection": {
|
||||||
|
"version": "3.0.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-selection/-/d3-selection-3.0.11.tgz",
|
||||||
|
"integrity": "sha512-bhAXu23DJWsrI45xafYpkQ4NtcKMwWnAC/vKrd2l+nxMFuvOT3XMYTIj2opv8vq8AO5Yh7Qac/nSeP/3zjTK0w==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-transition": {
|
||||||
|
"version": "3.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-transition/-/d3-transition-3.0.9.tgz",
|
||||||
|
"integrity": "sha512-uZS5shfxzO3rGlu0cC3bjmMFKsXv+SmZZcgp0KD22ts4uGXp5EVYGzu/0YdwZeKmddhcAccYtREJKkPfXkZuCg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-selection": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-zoom": {
|
||||||
|
"version": "3.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-zoom/-/d3-zoom-3.0.8.tgz",
|
||||||
|
"integrity": "sha512-iqMC4/YlFCSlO8+2Ii1GGGliCAY4XdeG748w5vQUbevlbDu0zSjH/+jojorQVBK/se0j6DUFNPBGSqD3YWYnDw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-interpolate": "*",
|
||||||
|
"@types/d3-selection": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/estree": {
|
"node_modules/@types/estree": {
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
|
||||||
@@ -1633,6 +1683,66 @@
|
|||||||
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0-beta.0"
|
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0-beta.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@xyflow/react": {
|
||||||
|
"version": "12.8.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@xyflow/react/-/react-12.8.1.tgz",
|
||||||
|
"integrity": "sha512-t5Rame4Gc/540VcOZd28yFe9Xd8lyjKUX+VTiyb1x4ykNXZH5zyDmsu+lj9je2O/jGBVb0pj1Vjcxrxyn+Xk2g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@xyflow/system": "0.0.65",
|
||||||
|
"classcat": "^5.0.3",
|
||||||
|
"zustand": "^4.4.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": ">=17",
|
||||||
|
"react-dom": ">=17"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@xyflow/react/node_modules/zustand": {
|
||||||
|
"version": "4.5.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.7.tgz",
|
||||||
|
"integrity": "sha512-CHOUy7mu3lbD6o6LJLfllpjkzhHXSBlX8B9+qPddUsIfeF5S/UZ5q0kmCsnRqT1UHFQZchNFDDzMbQsuesHWlw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"use-sync-external-store": "^1.2.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.7.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": ">=16.8",
|
||||||
|
"immer": ">=9.0.6",
|
||||||
|
"react": ">=16.8"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"immer": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"react": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@xyflow/system": {
|
||||||
|
"version": "0.0.65",
|
||||||
|
"resolved": "https://registry.npmjs.org/@xyflow/system/-/system-0.0.65.tgz",
|
||||||
|
"integrity": "sha512-AliQPQeurQMoNlOdySnRoDQl9yDSA/1Lqi47Eo0m98lHcfrTdD9jK75H0tiGj+0qRC10SKNUXyMkT0KL0opg4g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-drag": "^3.0.7",
|
||||||
|
"@types/d3-interpolate": "^3.0.4",
|
||||||
|
"@types/d3-selection": "^3.0.10",
|
||||||
|
"@types/d3-transition": "^3.0.8",
|
||||||
|
"@types/d3-zoom": "^3.0.8",
|
||||||
|
"d3-drag": "^3.0.0",
|
||||||
|
"d3-interpolate": "^3.0.1",
|
||||||
|
"d3-selection": "^3.0.0",
|
||||||
|
"d3-zoom": "^3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/ansi-regex": {
|
"node_modules/ansi-regex": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||||
@@ -2160,6 +2270,12 @@
|
|||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/classcat": {
|
||||||
|
"version": "5.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/classcat/-/classcat-5.0.5.tgz",
|
||||||
|
"integrity": "sha512-JhZUT7JFcQy/EzW605k/ktHtncoo9vnyW/2GspNYwFlN1C/WmjuV/xtS04e9SOkL2sTdw0VAZ2UGCcQ9lR6p6w==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/classnames": {
|
"node_modules/classnames": {
|
||||||
"version": "2.5.1",
|
"version": "2.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
|
||||||
@@ -2340,6 +2456,111 @@
|
|||||||
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
|
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/d3-color": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-dispatch": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-dispatch/-/d3-dispatch-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-rzUyPU/S7rwUflMyLc1ETDeBj0NRuHKKAcvukozwhshr6g6c5d8zh4c2gQjY2bZ0dXeGLWc1PF174P2tVvKhfg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-drag": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-drag/-/d3-drag-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-pWbUJLdETVA8lQNJecMxoXfH6x+mO2UQo8rSmZ+QqxcbyA3hfeprFgIT//HW2nlHChWeIIMwS2Fq+gEARkhTkg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-dispatch": "1 - 3",
|
||||||
|
"d3-selection": "3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-ease": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-interpolate": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-3bYs1rOD33uo8aqJfKP3JWPAibgw8Zm2+L9vBKEHJ2Rg+viTR7o5Mmv5mZcieN+FRYaAOWX5SJATX6k1PWz72g==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-color": "1 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-selection": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-selection/-/d3-selection-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-timer": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-timer/-/d3-timer-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-transition": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-transition/-/d3-transition-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-ApKvfjsSR6tg06xrL434C0WydLr7JewBB3V+/39RMHsaXTOG0zmt/OAXeng5M5LBm0ojmxJrpomQVZ1aPvBL4w==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-color": "1 - 3",
|
||||||
|
"d3-dispatch": "1 - 3",
|
||||||
|
"d3-ease": "1 - 3",
|
||||||
|
"d3-interpolate": "1 - 3",
|
||||||
|
"d3-timer": "1 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"d3-selection": "2 - 3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-zoom": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-zoom/-/d3-zoom-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-b8AmV3kfQaqWAuacbPuNbL6vahnOJflOhexLzMMNLga62+/nh0JzvJ0aO/5a5MVgUFGS7Hu1P9P03o3fJkDCyw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-dispatch": "1 - 3",
|
||||||
|
"d3-drag": "2 - 3",
|
||||||
|
"d3-interpolate": "1 - 3",
|
||||||
|
"d3-selection": "2 - 3",
|
||||||
|
"d3-transition": "2 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/dayjs": {
|
"node_modules/dayjs": {
|
||||||
"version": "1.11.13",
|
"version": "1.11.13",
|
||||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz",
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz",
|
||||||
@@ -5107,6 +5328,15 @@
|
|||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/use-sync-external-store": {
|
||||||
|
"version": "1.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.5.0.tgz",
|
||||||
|
"integrity": "sha512-Rb46I4cGGVBmjamjphe8L/UnvJD+uPPtTkNvX5mZgqdbavhI4EbgIWJiIHXJ8bc/i9EQGPRh4DwEURJ552Do0A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/util": {
|
"node_modules/util": {
|
||||||
"version": "0.12.5",
|
"version": "0.12.5",
|
||||||
"resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz",
|
"resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "client",
|
"name": "client",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^5.6.1",
|
"@ant-design/icons": "^5.6.1",
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
"@types/jest": "^27.5.2",
|
"@types/jest": "^27.5.2",
|
||||||
"@types/react": "^19.0.11",
|
"@types/react": "^19.0.11",
|
||||||
"@types/react-dom": "^19.0.4",
|
"@types/react-dom": "^19.0.4",
|
||||||
|
"@xyflow/react": "^12.8.1",
|
||||||
"antd": "^5.24.7",
|
"antd": "^5.24.7",
|
||||||
"axios": "^1.9.0",
|
"axios": "^1.9.0",
|
||||||
"axios-retry": "^4.5.0",
|
"axios-retry": "^4.5.0",
|
||||||
|
10
client/public/icons/node/calculate.svg
Normal file
10
client/public/icons/node/calculate.svg
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<mask id="mask0_381_806" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="24" height="24">
|
||||||
|
<rect width="24" height="24" fill="#D9D9D9"/>
|
||||||
|
</mask>
|
||||||
|
<g mask="url(#mask0_381_806)">
|
||||||
|
<path d="M12 13.75H17V12.25H12V13.75ZM12 11.25H17V9.75H12V11.25ZM5 21C4.45 21 3.97917 20.8042 3.5875 20.4125C3.19583 20.0208 3 19.55 3 19V5C3 4.45 3.19583 3.97917 3.5875 3.5875C3.97917 3.19583 4.45 3 5 3H19C19.55 3 20.0208 3.19583 20.4125 3.5875C20.8042 3.97917 21 4.45 21 5V19C21 19.55 20.8042 20.0208 20.4125 20.4125C20.0208 20.8042 19.55 21 19 21H5ZM5 19H19V5H5V19Z" fill="#606060"/>
|
||||||
|
<path d="M9.75 14.0179H7.75V12.5179H9.75V14.0179Z" fill="#606060"/>
|
||||||
|
<path d="M9.75 11.5179H7.75V10.0179H9.75V11.5179Z" fill="#606060"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 828 B |
3
client/public/icons/node/home.svg
Normal file
3
client/public/icons/node/home.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg width="16" height="18" viewBox="0 0 16 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M2 16H5V10H11V16H14V7L8 2.5L2 7V16ZM0 18V6L8 0L16 6V18H9V12H7V18H0Z" fill="#606060"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 198 B |
8
client/public/icons/node/ifElse.svg
Normal file
8
client/public/icons/node/ifElse.svg
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<svg width="28" height="31" viewBox="0 0 28 31" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M0 28.6L1.4 30L3 28.425L4.575 30L6 28.6L4.4 27L6 25.425L4.575 24L3 25.6L1.4 24L0 25.425L1.575 27L0 28.6Z" fill="#606060"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M13 0C14.1 0 15.0419 0.391472 15.8252 1.1748C16.6085 1.95814 17 2.9 17 4C17 5.1 16.6085 6.04186 15.8252 6.8252C15.0419 7.60853 14.1 8 13 8C11.9 8 10.9581 7.60853 10.1748 6.8252C9.39147 6.04186 9 5.1 9 4C9 2.9 9.39147 1.95814 10.1748 1.1748C10.9581 0.391471 11.9 0 13 0ZM13 2C12.45 2 11.9796 2.19622 11.5879 2.58789C11.1962 2.97956 11 3.45 11 4C11 4.53333 11.1962 5.00039 11.5879 5.40039C11.9795 5.80013 12.4502 6 13 6C13.5498 6 14.0205 5.80013 14.4121 5.40039C14.8038 5.00039 15 4.53333 15 4C15 3.45 14.8038 2.97956 14.4121 2.58789C14.0204 2.19622 13.55 2 13 2Z" fill="#606060"/>
|
||||||
|
<path d="M11.8 9H13.8V14H11.8V9Z" fill="#606060"/>
|
||||||
|
<path d="M20 27.55L22.825 30.375L27.775 25.425L26.35 24L22.825 27.55L21.4 26.125L20 27.55Z" fill="#606060"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.167 18.417L12.75 24.834L7.25005 19.334H4.00005L4 23H2L2.00005 17.5H7.25005L12.75 12L19.167 18.417ZM8.9229 18.417L12.75 22.2441L16.5772 18.417L12.75 14.5898L8.9229 18.417Z" fill="#606060"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.5 19.334L22 19.334V23H24V17.5L17.5 17.5V19.334Z" fill="#606060"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.4 KiB |
@@ -1,175 +0,0 @@
|
|||||||
import { Drawer } from 'antd';
|
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
import { Avatar, Typography } from 'antd';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { useUserSelector } from '@/store/userStore';
|
|
||||||
|
|
||||||
interface ContentDrawerProps {
|
|
||||||
open: boolean;
|
|
||||||
closeDrawer: () => void;
|
|
||||||
children: React.ReactNode;
|
|
||||||
type: 'create' | 'edit';
|
|
||||||
login?: string;
|
|
||||||
name?: string;
|
|
||||||
email?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ContentDrawer({
|
|
||||||
open,
|
|
||||||
closeDrawer,
|
|
||||||
children,
|
|
||||||
type,
|
|
||||||
login,
|
|
||||||
name,
|
|
||||||
email,
|
|
||||||
}: ContentDrawerProps) {
|
|
||||||
const user = useUserSelector();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [width, setWidth] = useState<number | string>('30%');
|
|
||||||
|
|
||||||
const calculateWidths = () => {
|
|
||||||
const windowWidth = window.innerWidth;
|
|
||||||
const expanded = Math.max(windowWidth * 0.3, 300);
|
|
||||||
setWidth(expanded);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
calculateWidths();
|
|
||||||
window.addEventListener('resize', calculateWidths);
|
|
||||||
return () => window.removeEventListener('resize', calculateWidths);
|
|
||||||
}, []);
|
|
||||||
console.log(login, user?.login, login === user?.login);
|
|
||||||
|
|
||||||
const editDrawerTitle = (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
gap: 12,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
onClick={closeDrawer}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
height: '24px',
|
|
||||||
width: '24px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="./icons/drawer/arrow_back.svg"
|
|
||||||
alt="close_drawer"
|
|
||||||
style={{ height: '16px', width: '16px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, flex: 1 }}>
|
|
||||||
<Avatar
|
|
||||||
src={
|
|
||||||
login ? `https://gamma.heado.ru/go/ava?name=${login}` : undefined
|
|
||||||
}
|
|
||||||
size={40}
|
|
||||||
style={{ flexShrink: 0 }}
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<Typography.Text
|
|
||||||
strong
|
|
||||||
style={{ display: 'block', fontSize: '20px' }}
|
|
||||||
>
|
|
||||||
{name} {login === user?.login ? t('you') : ''}
|
|
||||||
</Typography.Text>
|
|
||||||
<Typography.Text type="secondary" style={{ fontSize: 14 }}>
|
|
||||||
{email}
|
|
||||||
</Typography.Text>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
height: '24px',
|
|
||||||
width: '24px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="./icons/drawer/delete.svg"
|
|
||||||
alt="delete"
|
|
||||||
style={{ height: '18px', width: '16px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
const createDrawerTitle = (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
gap: 12,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
onClick={closeDrawer}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
height: '24px',
|
|
||||||
width: '24px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="./icons/drawer/arrow_back.svg"
|
|
||||||
alt="close_drawer"
|
|
||||||
style={{ height: '16px', width: '16px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: 12,
|
|
||||||
flex: 1,
|
|
||||||
fontSize: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t('newAccount')}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
height: '24px',
|
|
||||||
width: '24px',
|
|
||||||
}}
|
|
||||||
onClick={closeDrawer}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="./icons/drawer/delete.svg"
|
|
||||||
alt="delete"
|
|
||||||
style={{ height: '18px', width: '16px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Drawer
|
|
||||||
title={type === 'create' ? createDrawerTitle : editDrawerTitle}
|
|
||||||
placement="right"
|
|
||||||
open={open}
|
|
||||||
width={width}
|
|
||||||
destroyOnHidden={true}
|
|
||||||
closable={false}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</Drawer>
|
|
||||||
);
|
|
||||||
}
|
|
@@ -2,8 +2,8 @@ import { useUserSelector } from '@/store/userStore';
|
|||||||
import { Avatar } from 'antd';
|
import { Avatar } from 'antd';
|
||||||
import Title from 'antd/es/typography/Title';
|
import Title from 'antd/es/typography/Title';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import ContentDrawer from './ContentDrawer';
|
import ContentDrawer from './drawers/ContentDrawer';
|
||||||
import UserEdit from './UserEdit';
|
import UserEdit from './drawers/users/UserEdit';
|
||||||
|
|
||||||
interface HeaderProps {
|
interface HeaderProps {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -68,7 +68,7 @@ export default function Header({ title, additionalContent }: HeaderProps) {
|
|||||||
email={user?.email}
|
email={user?.email}
|
||||||
open={openEdit}
|
open={openEdit}
|
||||||
closeDrawer={closeEditDrawer}
|
closeDrawer={closeEditDrawer}
|
||||||
type="edit"
|
type="userEdit"
|
||||||
>
|
>
|
||||||
{user?.id && <UserEdit closeDrawer={closeEditDrawer} userId={user?.id} />}
|
{user?.id && <UserEdit closeDrawer={closeEditDrawer} userId={user?.id} />}
|
||||||
</ContentDrawer>
|
</ContentDrawer>
|
||||||
|
281
client/src/components/ReactFlowDrawer.tsx
Normal file
281
client/src/components/ReactFlowDrawer.tsx
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
import {
|
||||||
|
ReactFlow,
|
||||||
|
Background,
|
||||||
|
Controls,
|
||||||
|
useNodesState,
|
||||||
|
useEdgesState,
|
||||||
|
Node,
|
||||||
|
Edge,
|
||||||
|
} from "@xyflow/react";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import customEdgeStyle from "./edges/defaultEdgeStyle";
|
||||||
|
import { Dropdown, DropdownProps } from "antd";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { edgeTitleGenerator } from "@/utils/edge";
|
||||||
|
import IfElseNode from "./nodes/IfElseNode";
|
||||||
|
import AppropriationNode from "./nodes/AppropriationNode";
|
||||||
|
import StartNode from "./nodes/StartNode";
|
||||||
|
|
||||||
|
const initialNodes: Node[] = [
|
||||||
|
{
|
||||||
|
id: "1",
|
||||||
|
type: "startNode",
|
||||||
|
position: { x: 100, y: 0 },
|
||||||
|
data: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "2",
|
||||||
|
type: "ifElse",
|
||||||
|
position: { x: 100, y: 200 },
|
||||||
|
data: { condition: "B=2" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "3",
|
||||||
|
type: "appropriation",
|
||||||
|
position: { x: 100, y: 400 },
|
||||||
|
data: { value: "Выбрать {{account.email}}" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "4",
|
||||||
|
type: "appropriation",
|
||||||
|
position: { x: 400, y: 400 },
|
||||||
|
data: { value: "Выбрать {{account.role}}" },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const initialEdges: Edge[] = [
|
||||||
|
// {
|
||||||
|
// id: "e1-3",
|
||||||
|
// source: "1",
|
||||||
|
// sourceHandle: "1",
|
||||||
|
// target: "3",
|
||||||
|
// targetHandle: null,
|
||||||
|
// label: "A1",
|
||||||
|
// ...customEdgeStyle,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id: "e1-2",
|
||||||
|
// source: "1",
|
||||||
|
// sourceHandle: "2",
|
||||||
|
// target: "2",
|
||||||
|
// label: "B1",
|
||||||
|
// ...customEdgeStyle,
|
||||||
|
// },
|
||||||
|
];
|
||||||
|
|
||||||
|
interface ReactFlowDrawerProps {
|
||||||
|
showDrawer: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ReactFlowDrawer({ showDrawer }: ReactFlowDrawerProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
|
||||||
|
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
||||||
|
|
||||||
|
const [menuVisible, setMenuVisible] = useState(false);
|
||||||
|
const [selectedHandleId, setSelectedHandleId] = useState<string | null>(null);
|
||||||
|
const [menuPosition, setMenuPosition] = useState({ x: 0, y: 0 });
|
||||||
|
|
||||||
|
const handleOpenChange: DropdownProps["onOpenChange"] = (nextOpen, info) => {
|
||||||
|
if (info.source === "trigger" || nextOpen) {
|
||||||
|
setMenuVisible(nextOpen);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClick = (e: React.MouseEvent, node: Node) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
const target = e.target as HTMLElement;
|
||||||
|
const handleElement = target.closest(".react-flow__handle") as HTMLElement;
|
||||||
|
|
||||||
|
if (!handleElement) return;
|
||||||
|
|
||||||
|
const handleId = handleElement.getAttribute("data-handleid");
|
||||||
|
if (!handleId) return;
|
||||||
|
|
||||||
|
const handlePos = handleElement.getAttribute("data-handlepos");
|
||||||
|
if (handlePos === "top") return;
|
||||||
|
|
||||||
|
setSelectedHandleId(`${node.id}-${handleId}`);
|
||||||
|
|
||||||
|
const flowWrapper = document.querySelector(".react-flow") as HTMLElement;
|
||||||
|
if (flowWrapper) {
|
||||||
|
const wrapperRect = flowWrapper.getBoundingClientRect();
|
||||||
|
const handleRect = handleElement.getBoundingClientRect();
|
||||||
|
setMenuPosition({
|
||||||
|
x: handleRect.right - wrapperRect.left,
|
||||||
|
y: handleRect.top - wrapperRect.top + 20,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setMenuVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMenuItemClick = (targetNodeId: string) => {
|
||||||
|
if (!selectedHandleId) return;
|
||||||
|
|
||||||
|
const [sourceNodeId, sourceHandleId] = selectedHandleId.split("-");
|
||||||
|
|
||||||
|
const label = edgeTitleGenerator(edges.length + 1);
|
||||||
|
|
||||||
|
const newEdge: Edge = {
|
||||||
|
id: `e${sourceNodeId}-${sourceHandleId}-${targetNodeId}:${label}`,
|
||||||
|
source: sourceNodeId,
|
||||||
|
sourceHandle: sourceHandleId,
|
||||||
|
target: targetNodeId,
|
||||||
|
label,
|
||||||
|
...customEdgeStyle,
|
||||||
|
};
|
||||||
|
|
||||||
|
setEdges((eds) => [...eds, newEdge]);
|
||||||
|
setMenuVisible(false);
|
||||||
|
setSelectedHandleId(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCreateNode = (type: string) => {
|
||||||
|
if (!selectedHandleId) return;
|
||||||
|
const [sourceNodeId, sourceHandleId] = selectedHandleId.split("-");
|
||||||
|
const sourceNode = nodes.find((n) => n.id === sourceNodeId);
|
||||||
|
const newId = (
|
||||||
|
Math.max(...nodes.map((n) => Number(n.id) || 0)) + 1
|
||||||
|
).toString();
|
||||||
|
let newNode;
|
||||||
|
if (type === "ifElse") {
|
||||||
|
newNode = {
|
||||||
|
id: newId,
|
||||||
|
type: "ifElse",
|
||||||
|
position: {
|
||||||
|
x: (sourceNode?.position.x || 0) + 200,
|
||||||
|
y: (sourceNode?.position.y || 0) + 100,
|
||||||
|
},
|
||||||
|
data: { condition: "" },
|
||||||
|
};
|
||||||
|
} else if (type === "appropriation") {
|
||||||
|
newNode = {
|
||||||
|
id: newId,
|
||||||
|
type: "appropriation",
|
||||||
|
position: {
|
||||||
|
x: (sourceNode?.position.x || 0) + 200,
|
||||||
|
y: (sourceNode?.position.y || 0) + 100,
|
||||||
|
},
|
||||||
|
data: { value: "" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (newNode) {
|
||||||
|
setNodes((nds) => [...nds, newNode]);
|
||||||
|
const label = edgeTitleGenerator(edges.length + 1);
|
||||||
|
const newEdge = {
|
||||||
|
id: `e${sourceNodeId}-${sourceHandleId}-${newId}:${label}`,
|
||||||
|
source: sourceNodeId,
|
||||||
|
sourceHandle: sourceHandleId,
|
||||||
|
target: newId,
|
||||||
|
label,
|
||||||
|
...customEdgeStyle,
|
||||||
|
};
|
||||||
|
setEdges((eds) => [...eds, newEdge]);
|
||||||
|
setMenuVisible(false);
|
||||||
|
setSelectedHandleId(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const newNodeTypes = [
|
||||||
|
{ key: "ifElse", label: t("ifElseNode") },
|
||||||
|
{
|
||||||
|
key: "appropriation",
|
||||||
|
label: t("appropriationNode"),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const existingNodes = nodes
|
||||||
|
.filter((node) => node.id !== selectedHandleId?.split("-")[0])
|
||||||
|
.filter((node) => {
|
||||||
|
if (!selectedHandleId || node.type === "startNode") return false;
|
||||||
|
const [sourceNodeId, sourceHandleId] = selectedHandleId.split("-");
|
||||||
|
return !edges.some(
|
||||||
|
(edge) =>
|
||||||
|
edge.source === sourceNodeId &&
|
||||||
|
edge.sourceHandle === sourceHandleId &&
|
||||||
|
edge.target === node.id
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const menuItems = [
|
||||||
|
{
|
||||||
|
key: "connectToExisting",
|
||||||
|
label: t("connectToExisting"),
|
||||||
|
children: existingNodes.map((node) => ({
|
||||||
|
key: node.id,
|
||||||
|
label: t("connectTo", { nodeId: node.id }),
|
||||||
|
onClick: () => handleMenuItemClick(node.id),
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
...newNodeTypes.map((nt) => ({
|
||||||
|
key: `createNew-${nt.key}`,
|
||||||
|
label: nt.label,
|
||||||
|
onClick: () => handleCreateNode(nt.key),
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
|
||||||
|
const nodeTypes = useMemo(
|
||||||
|
() => ({
|
||||||
|
startNode: (props: any) => <StartNode {...props} edges={edges} />,
|
||||||
|
ifElse: (props: any) => <IfElseNode {...props} edges={edges} />,
|
||||||
|
appropriation: (props: any) => (
|
||||||
|
<AppropriationNode {...props} edges={edges} />
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
[edges]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ReactFlow
|
||||||
|
nodes={nodes}
|
||||||
|
edges={edges}
|
||||||
|
nodesDraggable={false}
|
||||||
|
elementsSelectable={false}
|
||||||
|
nodesConnectable={false}
|
||||||
|
onNodeClick={(event, node) => {
|
||||||
|
const target = event.target as HTMLElement;
|
||||||
|
|
||||||
|
if (!target.closest(".react-flow__handle")) {
|
||||||
|
console.log("node clicked");
|
||||||
|
showDrawer();
|
||||||
|
} else {
|
||||||
|
handleClick(event, node);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
nodeTypes={nodeTypes}
|
||||||
|
fitView
|
||||||
|
minZoom={0.5}
|
||||||
|
maxZoom={1.0}
|
||||||
|
>
|
||||||
|
<Background color="#F2F2F2" />
|
||||||
|
<Controls
|
||||||
|
position="bottom-center"
|
||||||
|
orientation="horizontal"
|
||||||
|
showInteractive={false}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{menuVisible && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
left: `${menuPosition.x}px`,
|
||||||
|
top: `${menuPosition.y}px`,
|
||||||
|
zIndex: 9999,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Dropdown
|
||||||
|
menu={{ items: menuItems }}
|
||||||
|
open={menuVisible}
|
||||||
|
onOpenChange={handleOpenChange}
|
||||||
|
placement="bottom"
|
||||||
|
>
|
||||||
|
<div style={{ width: 1, height: 1 }} />
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</ReactFlow>
|
||||||
|
);
|
||||||
|
}
|
245
client/src/components/drawers/ContentDrawer.tsx
Normal file
245
client/src/components/drawers/ContentDrawer.tsx
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
import { Drawer } from "antd";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { Avatar, Typography } from "antd";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useUserSelector } from "@/store/userStore";
|
||||||
|
|
||||||
|
interface ContentDrawerProps {
|
||||||
|
open: boolean;
|
||||||
|
closeDrawer: () => void;
|
||||||
|
children: React.ReactNode;
|
||||||
|
type: "userCreate" | "userEdit" | "nodeEdit";
|
||||||
|
login?: string;
|
||||||
|
name?: string;
|
||||||
|
email?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ContentDrawer({
|
||||||
|
open,
|
||||||
|
closeDrawer,
|
||||||
|
children,
|
||||||
|
type,
|
||||||
|
login,
|
||||||
|
name,
|
||||||
|
email,
|
||||||
|
}: ContentDrawerProps) {
|
||||||
|
const user = useUserSelector();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [width, setWidth] = useState<number | string>("30%");
|
||||||
|
|
||||||
|
const calculateWidths = () => {
|
||||||
|
const windowWidth = window.innerWidth;
|
||||||
|
const expanded = Math.max(windowWidth * 0.3, 300);
|
||||||
|
setWidth(expanded);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
calculateWidths();
|
||||||
|
window.addEventListener("resize", calculateWidths);
|
||||||
|
return () => window.removeEventListener("resize", calculateWidths);
|
||||||
|
}, []);
|
||||||
|
console.log(login, user?.login, login === user?.login);
|
||||||
|
|
||||||
|
const userEditDrawerTitle = (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
gap: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
onClick={closeDrawer}
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/arrow_back.svg"
|
||||||
|
alt="close_drawer"
|
||||||
|
style={{ height: "16px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ display: "flex", alignItems: "center", gap: 12, flex: 1 }}>
|
||||||
|
<Avatar
|
||||||
|
src={
|
||||||
|
login ? `https://gamma.heado.ru/go/ava?name=${login}` : undefined
|
||||||
|
}
|
||||||
|
size={40}
|
||||||
|
style={{ flexShrink: 0 }}
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
<Typography.Text
|
||||||
|
strong
|
||||||
|
style={{ display: "block", fontSize: "20px" }}
|
||||||
|
>
|
||||||
|
{name} {login === user?.login ? t("you") : ""}
|
||||||
|
</Typography.Text>
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 14 }}>
|
||||||
|
{email}
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/delete.svg"
|
||||||
|
alt="delete"
|
||||||
|
style={{ height: "18px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const userCreateDrawerTitle = (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
gap: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
onClick={closeDrawer}
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/arrow_back.svg"
|
||||||
|
alt="close_drawer"
|
||||||
|
style={{ height: "16px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 12,
|
||||||
|
flex: 1,
|
||||||
|
fontSize: "20px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("newAccount")}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
}}
|
||||||
|
onClick={closeDrawer}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/delete.svg"
|
||||||
|
alt="delete"
|
||||||
|
style={{ height: "18px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const nodeEditDrawerTitle = (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
gap: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
onClick={closeDrawer}
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/arrow_back.svg"
|
||||||
|
alt="close_drawer"
|
||||||
|
style={{ height: "16px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 12,
|
||||||
|
flex: 1,
|
||||||
|
fontSize: "20px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Редактирование блока
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
}}
|
||||||
|
onClick={closeDrawer}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/delete.svg"
|
||||||
|
alt="delete"
|
||||||
|
style={{ height: "18px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer
|
||||||
|
// title={
|
||||||
|
// type === "userCreate" ? userCreateDrawerTitle : userEditDrawerTitle
|
||||||
|
// }
|
||||||
|
title={(() => {
|
||||||
|
switch (type) {
|
||||||
|
case "userCreate":
|
||||||
|
return userCreateDrawerTitle;
|
||||||
|
case "userEdit":
|
||||||
|
return userEditDrawerTitle;
|
||||||
|
case "nodeEdit":
|
||||||
|
return nodeEditDrawerTitle;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})()}
|
||||||
|
placement="right"
|
||||||
|
open={open}
|
||||||
|
width={width}
|
||||||
|
destroyOnHidden={true}
|
||||||
|
closable={false}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Drawer>
|
||||||
|
);
|
||||||
|
}
|
213
client/src/components/drawers/DrawerTitles.tsx
Normal file
213
client/src/components/drawers/DrawerTitles.tsx
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
import { User } from "@/types/user";
|
||||||
|
import { Avatar, Typography } from "antd";
|
||||||
|
import { TFunction } from "i18next";
|
||||||
|
|
||||||
|
interface DrawerTitleProps {
|
||||||
|
closeDrawer: () => void;
|
||||||
|
t: TFunction;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UserEditDrawerTitleProps extends DrawerTitleProps {
|
||||||
|
login?: string;
|
||||||
|
name?: string;
|
||||||
|
email?: string | null;
|
||||||
|
user: User | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UserCreateDrawerTitleProps extends DrawerTitleProps {}
|
||||||
|
|
||||||
|
interface NodeEditDrawerTitleProps extends DrawerTitleProps {}
|
||||||
|
|
||||||
|
const UserEditDrawerTitle = ({
|
||||||
|
closeDrawer,
|
||||||
|
login,
|
||||||
|
name,
|
||||||
|
email,
|
||||||
|
user,
|
||||||
|
t,
|
||||||
|
}: UserEditDrawerTitleProps) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
gap: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
onClick={closeDrawer}
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/arrow_back.svg"
|
||||||
|
alt="close_drawer"
|
||||||
|
style={{ height: "16px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ display: "flex", alignItems: "center", gap: 12, flex: 1 }}>
|
||||||
|
<Avatar
|
||||||
|
src={
|
||||||
|
login ? `https://gamma.heado.ru/go/ava?name=${login}` : undefined
|
||||||
|
}
|
||||||
|
size={40}
|
||||||
|
style={{ flexShrink: 0 }}
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
<Typography.Text
|
||||||
|
strong
|
||||||
|
style={{ display: "block", fontSize: "20px" }}
|
||||||
|
>
|
||||||
|
{name} {login === user?.login ? t("you") : ""}
|
||||||
|
</Typography.Text>
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 14 }}>
|
||||||
|
{email}
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/delete.svg"
|
||||||
|
alt="delete"
|
||||||
|
style={{ height: "18px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const UserCreateDrawerTitle = ({
|
||||||
|
closeDrawer,
|
||||||
|
t,
|
||||||
|
}: UserCreateDrawerTitleProps) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
gap: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
onClick={closeDrawer}
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/arrow_back.svg"
|
||||||
|
alt="close_drawer"
|
||||||
|
style={{ height: "16px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: "12px",
|
||||||
|
flex: 1,
|
||||||
|
fontSize: "20px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("newAccount")}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
}}
|
||||||
|
onClick={closeDrawer}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/delete.svg"
|
||||||
|
alt="delete"
|
||||||
|
style={{ height: "18px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const NodeEditDrawerTitle = ({ closeDrawer, t }: NodeEditDrawerTitleProps) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
gap: "12px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
onClick={closeDrawer}
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/arrow_back.svg"
|
||||||
|
alt="close_drawer"
|
||||||
|
style={{ height: "16px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: "12px",
|
||||||
|
flex: 1,
|
||||||
|
fontSize: "20px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("editNode")}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
}}
|
||||||
|
onClick={closeDrawer}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="./icons/drawer/delete.svg"
|
||||||
|
alt="delete"
|
||||||
|
style={{ height: "18px", width: "16px" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { UserEditDrawerTitle, UserCreateDrawerTitle, NodeEditDrawerTitle };
|
17
client/src/components/edges/defaultEdgeStyle.tsx
Normal file
17
client/src/components/edges/defaultEdgeStyle.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { MarkerType } from "@xyflow/react";
|
||||||
|
|
||||||
|
const customEdgeStyle = {
|
||||||
|
markerEnd: {
|
||||||
|
type: MarkerType.Arrow,
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
color: "#BDBDBD",
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
strokeWidth: 2,
|
||||||
|
stroke: "#BDBDBD",
|
||||||
|
},
|
||||||
|
type: "step",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default customEdgeStyle;
|
63
client/src/components/nodes/AppropriationNode.tsx
Normal file
63
client/src/components/nodes/AppropriationNode.tsx
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import { Handle, Node, NodeProps, Position, Edge } from "@xyflow/react";
|
||||||
|
import { HANDLE_STYLE_CONNECTED } from "./defaultHandleStyle";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
type AppropriationNodeData = { value: string; edges?: Edge[] };
|
||||||
|
|
||||||
|
export default function AppropriationNode({
|
||||||
|
data,
|
||||||
|
id,
|
||||||
|
edges = [],
|
||||||
|
}: NodeProps<Node & AppropriationNodeData> & { edges?: Edge[] }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
border: "0px solid",
|
||||||
|
borderRadius: 8,
|
||||||
|
backgroundColor: "white",
|
||||||
|
width: "248px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
paddingLeft: "12px",
|
||||||
|
height: "48px",
|
||||||
|
fontWeight: "600px",
|
||||||
|
fontSize: "16px",
|
||||||
|
gap: "12px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
style={{ height: "24px", width: "24px" }}
|
||||||
|
src="/icons/node/calculate.svg"
|
||||||
|
alt="appropriation logo"
|
||||||
|
/>
|
||||||
|
{t("appropriationNode")}
|
||||||
|
</div>
|
||||||
|
<div style={{ height: "1px", backgroundColor: "#E2E2E2" }}></div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
padding: "12px",
|
||||||
|
fontSize: "14px",
|
||||||
|
minHeight: "48px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{data.value as string}
|
||||||
|
</div>
|
||||||
|
<Handle
|
||||||
|
style={{
|
||||||
|
...HANDLE_STYLE_CONNECTED,
|
||||||
|
}}
|
||||||
|
type="target"
|
||||||
|
position={Position.Top}
|
||||||
|
id="input"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
119
client/src/components/nodes/IfElseNode.tsx
Normal file
119
client/src/components/nodes/IfElseNode.tsx
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import { Handle, NodeProps, Position, Node, Edge } from "@xyflow/react";
|
||||||
|
import {
|
||||||
|
HANDLE_STYLE_CONNECTED,
|
||||||
|
HANDLE_STYLE_CONNECTED_V,
|
||||||
|
HANDLE_STYLE_DISCONNECTED,
|
||||||
|
HANDLE_STYLE_DISCONNECTED_V,
|
||||||
|
} from "./defaultHandleStyle";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
interface IfElseNodeProps extends Node {
|
||||||
|
condition: string;
|
||||||
|
edges?: Edge[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function IfElseNode({
|
||||||
|
id,
|
||||||
|
data,
|
||||||
|
edges = [],
|
||||||
|
}: NodeProps<IfElseNodeProps> & { edges?: Edge[] }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const isHandle1Connected = edges.some(
|
||||||
|
(e: Edge) => e.source === id && e.sourceHandle === "1"
|
||||||
|
);
|
||||||
|
const isHandle2Connected = edges.some(
|
||||||
|
(e: Edge) => e.source === id && e.sourceHandle === "2"
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
border: "0px solid",
|
||||||
|
borderRadius: 8,
|
||||||
|
backgroundColor: "white",
|
||||||
|
width: "248px",
|
||||||
|
minHeight: "144px",
|
||||||
|
position: "relative",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
paddingLeft: "12px",
|
||||||
|
height: "48px",
|
||||||
|
fontWeight: "600px",
|
||||||
|
fontSize: "16px",
|
||||||
|
gap: "12px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
style={{ height: "24px", width: "24px" }}
|
||||||
|
src="/icons/node/ifElse.svg"
|
||||||
|
alt="if else logo"
|
||||||
|
/>
|
||||||
|
{t("ifElseNode")}
|
||||||
|
</div>
|
||||||
|
<div style={{ height: "1px", backgroundColor: "#E2E2E2" }}></div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
padding: "12px",
|
||||||
|
fontSize: "14px",
|
||||||
|
minHeight: "48px",
|
||||||
|
position: "relative",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("conditionIf", { condition: data.condition })}
|
||||||
|
<Handle
|
||||||
|
type="source"
|
||||||
|
position={Position.Right}
|
||||||
|
id="1"
|
||||||
|
style={{
|
||||||
|
...(isHandle1Connected
|
||||||
|
? { ...HANDLE_STYLE_CONNECTED_V }
|
||||||
|
: { ...HANDLE_STYLE_DISCONNECTED_V }),
|
||||||
|
position: "absolute",
|
||||||
|
top: "50%",
|
||||||
|
transform: "translateY(-50%)",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div style={{ height: "1px", backgroundColor: "#E2E2E2" }}></div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
paddingLeft: "12px",
|
||||||
|
fontSize: "14px",
|
||||||
|
height: "48px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("conditionElse")}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Handle
|
||||||
|
type="target"
|
||||||
|
position={Position.Top}
|
||||||
|
id="input"
|
||||||
|
style={{ ...HANDLE_STYLE_CONNECTED }}
|
||||||
|
/>
|
||||||
|
<Handle
|
||||||
|
type="source"
|
||||||
|
position={Position.Bottom}
|
||||||
|
id="2"
|
||||||
|
style={
|
||||||
|
isHandle2Connected
|
||||||
|
? { ...HANDLE_STYLE_CONNECTED }
|
||||||
|
: { ...HANDLE_STYLE_DISCONNECTED }
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
83
client/src/components/nodes/StartNode.tsx
Normal file
83
client/src/components/nodes/StartNode.tsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import { Edge, Handle, Node, NodeProps, Position } from "@xyflow/react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import {
|
||||||
|
HANDLE_STYLE_CONNECTED,
|
||||||
|
HANDLE_STYLE_DISCONNECTED,
|
||||||
|
} from "./defaultHandleStyle";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
interface StartNodeProps extends Node {
|
||||||
|
edges?: Edge[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function StartNode({
|
||||||
|
id,
|
||||||
|
edges = [],
|
||||||
|
}: NodeProps<StartNodeProps> & { edges?: Edge[] }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const isHandleConnected = edges.some(
|
||||||
|
(e: Edge) => e.source === id && e.sourceHandle === "1"
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
border: "0px solid",
|
||||||
|
borderRadius: 8,
|
||||||
|
backgroundColor: "white",
|
||||||
|
width: "248px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
paddingLeft: "12px",
|
||||||
|
height: "40px",
|
||||||
|
fontWeight: "600px",
|
||||||
|
fontSize: "16px",
|
||||||
|
gap: "12px",
|
||||||
|
backgroundColor: "#D4E0BD",
|
||||||
|
borderRadius: "8px 8px 0 0",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
height: "24px",
|
||||||
|
width: "24px",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
style={{ height: "16px", width: "18px" }}
|
||||||
|
src="/icons/node/home.svg"
|
||||||
|
alt="start logo"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{t("startNode")}
|
||||||
|
</div>
|
||||||
|
<div style={{ height: "1px", backgroundColor: "#E2E2E2" }}></div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
padding: "12px",
|
||||||
|
fontSize: "14px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("startNodeDescription")}
|
||||||
|
</div>
|
||||||
|
<Handle
|
||||||
|
type="source"
|
||||||
|
position={Position.Bottom}
|
||||||
|
id="1"
|
||||||
|
style={
|
||||||
|
isHandleConnected
|
||||||
|
? { ...HANDLE_STYLE_CONNECTED }
|
||||||
|
: { ...HANDLE_STYLE_DISCONNECTED }
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
34
client/src/components/nodes/defaultHandleStyle.ts
Normal file
34
client/src/components/nodes/defaultHandleStyle.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// horizontal
|
||||||
|
const HANDLE_STYLE_CONNECTED = {
|
||||||
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
backgroundColor: "#BDBDBD",
|
||||||
|
};
|
||||||
|
|
||||||
|
// horizontal
|
||||||
|
const HANDLE_STYLE_DISCONNECTED = {
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
backgroundColor: "#C7D95A",
|
||||||
|
borderColor: "#606060",
|
||||||
|
borderWidth: 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
// vertical
|
||||||
|
const HANDLE_STYLE_CONNECTED_V = {
|
||||||
|
...HANDLE_STYLE_CONNECTED,
|
||||||
|
right: "-4px",
|
||||||
|
};
|
||||||
|
|
||||||
|
// vertical
|
||||||
|
const HANDLE_STYLE_DISCONNECTED_V = {
|
||||||
|
...HANDLE_STYLE_DISCONNECTED,
|
||||||
|
right: "-10px",
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
HANDLE_STYLE_CONNECTED,
|
||||||
|
HANDLE_STYLE_DISCONNECTED,
|
||||||
|
HANDLE_STYLE_CONNECTED_V,
|
||||||
|
HANDLE_STYLE_DISCONNECTED_V,
|
||||||
|
};
|
@@ -1,99 +1,119 @@
|
|||||||
import i18n from 'i18next';
|
import i18n from "i18next";
|
||||||
import { initReactI18next } from 'react-i18next';
|
import { initReactI18next } from "react-i18next";
|
||||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
import LanguageDetector from "i18next-browser-languagedetector";
|
||||||
|
|
||||||
i18n
|
i18n
|
||||||
.use(LanguageDetector)
|
.use(LanguageDetector)
|
||||||
.use(initReactI18next)
|
.use(initReactI18next)
|
||||||
.init({
|
.init({
|
||||||
fallbackLng: 'en',
|
fallbackLng: "en",
|
||||||
supportedLngs: ['en', 'ru'],
|
supportedLngs: ["en", "ru"],
|
||||||
interpolation: { escapeValue: false },
|
interpolation: { escapeValue: false },
|
||||||
resources: {
|
resources: {
|
||||||
en: {
|
en: {
|
||||||
translation: {
|
translation: {
|
||||||
accounts: 'Accounts',
|
accounts: "Accounts",
|
||||||
processDiagrams: 'Process diagrams',
|
processDiagrams: "Process diagrams",
|
||||||
runningProcesses: 'Running processes',
|
runningProcesses: "Running processes",
|
||||||
settings: 'Settings',
|
settings: "Settings",
|
||||||
eventsList: 'Events list',
|
eventsList: "Events list",
|
||||||
configuration: 'Configuration',
|
configuration: "Configuration",
|
||||||
selectPhoto: 'Select photo',
|
selectPhoto: "Select photo",
|
||||||
name: 'Name',
|
name: "Name",
|
||||||
login: 'Login',
|
login: "Login",
|
||||||
password: 'Password',
|
password: "Password",
|
||||||
email: 'Email',
|
email: "Email",
|
||||||
tenant: 'Tenant',
|
tenant: "Tenant",
|
||||||
role: 'Role',
|
role: "Role",
|
||||||
status: 'Status',
|
status: "Status",
|
||||||
nameMessage: 'Enter name',
|
nameMessage: "Enter name",
|
||||||
loginMessage: 'Enter login',
|
loginMessage: "Enter login",
|
||||||
passwordMessage: 'Enter password',
|
passwordMessage: "Enter password",
|
||||||
emailMessage: 'Enter email',
|
emailMessage: "Enter email",
|
||||||
emailErrorMessage: 'Incorrect email',
|
emailErrorMessage: "Incorrect email",
|
||||||
tenantMessage: 'Enter tenant',
|
tenantMessage: "Enter tenant",
|
||||||
roleMessage: 'Choose role',
|
roleMessage: "Choose role",
|
||||||
statusMessage: 'Choose status',
|
statusMessage: "Choose status",
|
||||||
addAccount: 'Add account',
|
addAccount: "Add account",
|
||||||
save: 'Save changes',
|
save: "Save changes",
|
||||||
newAccount: 'New account',
|
newAccount: "New account",
|
||||||
ACTIVE: 'Active',
|
ACTIVE: "Active",
|
||||||
DISABLED: 'Disabled',
|
DISABLED: "Disabled",
|
||||||
BLOCKED: 'Blocked',
|
BLOCKED: "Blocked",
|
||||||
DELETED: 'Deleted',
|
DELETED: "Deleted",
|
||||||
OWNER: 'Owner',
|
OWNER: "Owner",
|
||||||
ADMIN: 'Admin',
|
ADMIN: "Admin",
|
||||||
EDITOR: 'Editor',
|
EDITOR: "Editor",
|
||||||
VIEWER: 'Viewer',
|
VIEWER: "Viewer",
|
||||||
nameLogin: 'Name, login',
|
nameLogin: "Name, login",
|
||||||
createdAt: 'Created',
|
createdAt: "Created",
|
||||||
saving: 'Saving...',
|
saving: "Saving...",
|
||||||
createdAccountMessage: 'User successfully created!',
|
createdAccountMessage: "User successfully created!",
|
||||||
editAccountMessage: 'User successfully updated!',
|
editAccountMessage: "User successfully updated!",
|
||||||
you: '(You)',
|
you: "(You)",
|
||||||
|
// nodes
|
||||||
|
startNode: "Start",
|
||||||
|
startNodeDescription: "Start",
|
||||||
|
connectToExisting: "Connect to existing",
|
||||||
|
editNode: "Editing a block",
|
||||||
|
connectTo: "Connect to {{nodeId}}",
|
||||||
|
ifElseNode: "IF - ELSE",
|
||||||
|
conditionIf: "If {{condition}}, then",
|
||||||
|
conditionElse: "Else",
|
||||||
|
appropriationNode: "Appropriation",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ru: {
|
ru: {
|
||||||
translation: {
|
translation: {
|
||||||
accounts: 'Учетные записи',
|
accounts: "Учетные записи",
|
||||||
processDiagrams: 'Схемы процессов',
|
processDiagrams: "Схемы процессов",
|
||||||
runningProcesses: 'Запущенные процессы',
|
runningProcesses: "Запущенные процессы",
|
||||||
settings: 'Настройки',
|
settings: "Настройки",
|
||||||
eventsList: 'Справочкин событий',
|
eventsList: "Справочкин событий",
|
||||||
configuration: 'Конфигурация',
|
configuration: "Конфигурация",
|
||||||
selectPhoto: 'Выбрать фото',
|
selectPhoto: "Выбрать фото",
|
||||||
name: 'Имя',
|
name: "Имя",
|
||||||
login: 'Логин',
|
login: "Логин",
|
||||||
password: 'Пароль',
|
password: "Пароль",
|
||||||
email: 'Имейл',
|
email: "Имейл",
|
||||||
tenant: 'Привязка',
|
tenant: "Привязка",
|
||||||
role: 'Роль',
|
role: "Роль",
|
||||||
status: 'Статус',
|
status: "Статус",
|
||||||
nameMessage: 'Введите имя',
|
nameMessage: "Введите имя",
|
||||||
loginMessage: 'Введите логин',
|
loginMessage: "Введите логин",
|
||||||
passwordMessage: 'Введите пароль',
|
passwordMessage: "Введите пароль",
|
||||||
emailMessage: 'Введите имейл',
|
emailMessage: "Введите имейл",
|
||||||
emailErrorMessage: 'Некорректный имейл',
|
emailErrorMessage: "Некорректный имейл",
|
||||||
tenantMessage: 'Введите привязку',
|
tenantMessage: "Введите привязку",
|
||||||
roleMessage: 'Выберите роль',
|
roleMessage: "Выберите роль",
|
||||||
statusMessage: 'Выберите статус',
|
statusMessage: "Выберите статус",
|
||||||
addAccount: 'Добавить аккаунт',
|
addAccount: "Добавить аккаунт",
|
||||||
save: 'Сохранить изменения',
|
save: "Сохранить изменения",
|
||||||
newAccount: 'Новая учетная запись',
|
newAccount: "Новая учетная запись",
|
||||||
ACTIVE: 'Активен',
|
ACTIVE: "Активен",
|
||||||
DISABLED: 'Выключен',
|
DISABLED: "Выключен",
|
||||||
BLOCKED: 'Заблокирован',
|
BLOCKED: "Заблокирован",
|
||||||
DELETED: 'Удален',
|
DELETED: "Удален",
|
||||||
OWNER: 'Владелец',
|
OWNER: "Владелец",
|
||||||
ADMIN: 'Админ',
|
ADMIN: "Админ",
|
||||||
EDITOR: 'Редактор',
|
EDITOR: "Редактор",
|
||||||
VIEWER: 'Наблюдатель',
|
VIEWER: "Наблюдатель",
|
||||||
nameLogin: 'Имя, Логин',
|
nameLogin: "Имя, Логин",
|
||||||
createdAt: 'Создано',
|
createdAt: "Создано",
|
||||||
saving: 'Сохранение...',
|
saving: "Сохранение...",
|
||||||
createdAccountMessage: 'Пользователь успешно создан!',
|
createdAccountMessage: "Пользователь успешно создан!",
|
||||||
editAccountMessage: 'Пользователь успешно обновлен!',
|
editAccountMessage: "Пользователь успешно обновлен!",
|
||||||
you: '(Вы)',
|
you: "(Вы)",
|
||||||
|
// nodes
|
||||||
|
startNode: "Запуск",
|
||||||
|
startNodeDescription: "Включение",
|
||||||
|
connectToExisting: "Подключить к существующей",
|
||||||
|
editNode: "Редактирование блока",
|
||||||
|
connectTo: `Подключить к {{nodeId}}`,
|
||||||
|
ifElseNode: "ЕСЛИ - ТО",
|
||||||
|
conditionIf: "Если {{condition}}, то",
|
||||||
|
conditionElse: "Иначе",
|
||||||
|
appropriationNode: "Присвоение",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
import React from 'react';
|
import React from "react";
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from "react-dom/client";
|
||||||
import '@/index.css';
|
import "@/index.css";
|
||||||
import App from '@/App';
|
import App from "@/App";
|
||||||
import AppWrapper from '@/config/AppWrapper';
|
import AppWrapper from "@/config/AppWrapper";
|
||||||
|
import "@xyflow/react/dist/style.css";
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(
|
const root = ReactDOM.createRoot(
|
||||||
document.getElementById('root') as HTMLElement
|
document.getElementById("root") as HTMLElement
|
||||||
);
|
);
|
||||||
|
|
||||||
root.render(
|
root.render(
|
||||||
|
@@ -2,12 +2,12 @@ import { useEffect, useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { AccountStatus, AllUser, AllUserResponse } from "@/types/user";
|
import { AccountStatus, AllUser, AllUserResponse } from "@/types/user";
|
||||||
import Header from "@/components/Header";
|
import Header from "@/components/Header";
|
||||||
import ContentDrawer from "@/components/ContentDrawer";
|
import ContentDrawer from "@/components/drawers/ContentDrawer";
|
||||||
import UserCreate from "@/components/UserCreate";
|
import UserCreate from "@/components/drawers/users/UserCreate";
|
||||||
import { Avatar, Table } from "antd";
|
import { Avatar, Table } from "antd";
|
||||||
import { TableProps } from "antd/lib";
|
import { TableProps } from "antd/lib";
|
||||||
import { UserService } from "@/services/userService";
|
import { UserService } from "@/services/userService";
|
||||||
import UserEdit from "@/components/UserEdit";
|
import UserEdit from "@/components/drawers/users/UserEdit";
|
||||||
import { useSearchParams } from "react-router-dom";
|
import { useSearchParams } from "react-router-dom";
|
||||||
|
|
||||||
export default function AccountsPage() {
|
export default function AccountsPage() {
|
||||||
@@ -201,7 +201,7 @@ export default function AccountsPage() {
|
|||||||
<ContentDrawer
|
<ContentDrawer
|
||||||
open={openCreate}
|
open={openCreate}
|
||||||
closeDrawer={closeCreateDrawer}
|
closeDrawer={closeCreateDrawer}
|
||||||
type="create"
|
type="userCreate"
|
||||||
>
|
>
|
||||||
<UserCreate getUsers={getUsers} closeDrawer={closeCreateDrawer} />
|
<UserCreate getUsers={getUsers} closeDrawer={closeCreateDrawer} />
|
||||||
</ContentDrawer>
|
</ContentDrawer>
|
||||||
@@ -211,7 +211,7 @@ export default function AccountsPage() {
|
|||||||
email={activeAccount?.email}
|
email={activeAccount?.email}
|
||||||
open={openEdit}
|
open={openEdit}
|
||||||
closeDrawer={closeEditDrawer}
|
closeDrawer={closeEditDrawer}
|
||||||
type="edit"
|
type="userEdit"
|
||||||
>
|
>
|
||||||
<UserEdit userId={activeAccount?.id} closeDrawer={closeEditDrawer} />
|
<UserEdit userId={activeAccount?.id} closeDrawer={closeEditDrawer} />
|
||||||
</ContentDrawer>
|
</ContentDrawer>
|
||||||
|
@@ -1,22 +1,22 @@
|
|||||||
/* eslint-disable react-hooks/exhaustive-deps */
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from "react";
|
||||||
import { Layout } from 'antd';
|
import { Layout } from "antd";
|
||||||
import Sider from 'antd/es/layout/Sider';
|
import Sider from "antd/es/layout/Sider";
|
||||||
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
import { Route, Routes, useLocation, useNavigate } from "react-router-dom";
|
||||||
import SiderMenu from '@/components/SiderMenu';
|
import SiderMenu from "@/components/SiderMenu";
|
||||||
import ProcessDiagramPage from './ProcessDiagramPage';
|
import ProcessDiagramPage from "./ProcessDiagramPage";
|
||||||
import RunningProcessesPage from './RunningProcessesPage';
|
import AccountsPage from "./AccountsPage";
|
||||||
import AccountsPage from './AccountsPage';
|
import ConfigurationPage from "./ConfigurationPage";
|
||||||
import EventsListPage from './EventsListPage';
|
import EventsListPage from "./EventsListPage";
|
||||||
import ConfigurationPage from './ConfigurationPage';
|
import RunningProcessesPage from "./RunningProcessesPage";
|
||||||
|
|
||||||
export default function MainLayout() {
|
export default function MainLayout() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
const [selectedKey, setSelectedKey] = useState('1');
|
const [selectedKey, setSelectedKey] = useState("1");
|
||||||
|
|
||||||
const [width, setWidth] = useState<number | string>('15%');
|
const [width, setWidth] = useState<number | string>("15%");
|
||||||
const [collapsedWidth, setCollapsedWidth] = useState(50);
|
const [collapsedWidth, setCollapsedWidth] = useState(50);
|
||||||
|
|
||||||
const calculateWidths = () => {
|
const calculateWidths = () => {
|
||||||
@@ -29,24 +29,24 @@ export default function MainLayout() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
calculateWidths();
|
calculateWidths();
|
||||||
window.addEventListener('resize', calculateWidths);
|
window.addEventListener("resize", calculateWidths);
|
||||||
return () => window.removeEventListener('resize', calculateWidths);
|
return () => window.removeEventListener("resize", calculateWidths);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (location.pathname === '/') {
|
if (location.pathname === "/") {
|
||||||
navigate('/process-diagram');
|
navigate("/process-diagram");
|
||||||
}
|
}
|
||||||
setSelectedKey(location.pathname);
|
setSelectedKey(location.pathname);
|
||||||
}, [location.pathname]);
|
}, [location.pathname]);
|
||||||
|
|
||||||
function hangleMenuClick(e: any) {
|
function hangleMenuClick(e: any) {
|
||||||
const key = e.key;
|
const key = e.key;
|
||||||
if (key === 'toggle') {
|
if (key === "toggle") {
|
||||||
setCollapsed(!collapsed);
|
setCollapsed(!collapsed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (key === 'divider') {
|
if (key === "divider") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ export default function MainLayout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout style={{ minHeight: '100vh' }}>
|
<Layout style={{ minHeight: "100vh" }}>
|
||||||
<Sider
|
<Sider
|
||||||
className="sider"
|
className="sider"
|
||||||
collapsible
|
collapsible
|
||||||
|
@@ -1,11 +1,33 @@
|
|||||||
import Header from '@/components/Header';
|
import Header from "@/components/Header";
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
import ReactFlowDrawer from "@/components/ReactFlowDrawer";
|
||||||
|
import { useState } from "react";
|
||||||
|
import ContentDrawer from "@/components/drawers/ContentDrawer";
|
||||||
|
|
||||||
export default function ProcessDiagramPage() {
|
export default function ProcessDiagramPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
||||||
|
|
||||||
|
const showDrawer = () => setIsDrawerOpen(true);
|
||||||
|
const closeDrawer = () => {
|
||||||
|
setIsDrawerOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Header title={t('processDiagrams')} />
|
<Header title={t("processDiagrams")} />
|
||||||
|
<div style={{ width: "100%", height: "100%" }}>
|
||||||
|
<ReactFlowDrawer showDrawer={showDrawer} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ContentDrawer
|
||||||
|
open={isDrawerOpen}
|
||||||
|
closeDrawer={closeDrawer}
|
||||||
|
children={undefined}
|
||||||
|
type={"nodeEdit"}
|
||||||
|
></ContentDrawer>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
25
client/src/store/nodeStore.ts
Normal file
25
client/src/store/nodeStore.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { Edge, Node } from "@xyflow/react";
|
||||||
|
import { create } from "zustand";
|
||||||
|
import { devtools } from "zustand/middleware";
|
||||||
|
|
||||||
|
type NodeStoreState = {
|
||||||
|
node: Node;
|
||||||
|
edge: Edge;
|
||||||
|
loading: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type NodeStoreActions = {
|
||||||
|
addNode: (node: Node) => void;
|
||||||
|
addEdge: (edge: Edge) => void;
|
||||||
|
removeNode: (nodeId: string) => void;
|
||||||
|
removeEdge: (edgeId: string) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type NodeStore = NodeStoreState & NodeStoreActions;
|
||||||
|
|
||||||
|
export const useNodeStore = create<NodeStore>()(
|
||||||
|
devtools((set) => ({
|
||||||
|
nodes: [],
|
||||||
|
edges: [],
|
||||||
|
}))
|
||||||
|
);
|
8
client/src/utils/edge.ts
Normal file
8
client/src/utils/edge.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
function edgeTitleGenerator(counter: number) {
|
||||||
|
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const num = Math.ceil(counter / chars.length);
|
||||||
|
const letterIndex = (counter - 1) % chars.length;
|
||||||
|
return `${chars[letterIndex]}${num}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { edgeTitleGenerator };
|
Reference in New Issue
Block a user