events cluster updated with PageInfo
This commit is contained in:
@@ -5,29 +5,106 @@ from uuid import UUID
|
||||
from ApiLayers.AllConfigs.Redis.configs import RedisCategoryKeys
|
||||
|
||||
|
||||
class PageInfo:
|
||||
class PageComponent:
|
||||
|
||||
NAME: str
|
||||
BUTTON_NAME: str
|
||||
PAGE_URL: str
|
||||
PAGEINFO: Dict[str, Any]
|
||||
URL: str = ""
|
||||
URL: str
|
||||
FETCH_URL: str
|
||||
LANGUAGE_MODELS: Dict[str, Any]
|
||||
TYPE_COMPONENT: Optional[str] = "Page"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
title: Dict[str, Any],
|
||||
description: Dict[str, Any],
|
||||
icon: str,
|
||||
parent: str,
|
||||
url: str,
|
||||
# fetch_url: str,
|
||||
language_models: Dict[str, Any],
|
||||
):
|
||||
self.NAME = name
|
||||
self.TITLE = title
|
||||
self.DESCRIPTION = description
|
||||
self.ICON = icon
|
||||
self.PARENT = parent
|
||||
self.URL = url
|
||||
# self.FETCH_URL = fetch_url
|
||||
self.LANGUAGE_MODELS = language_models
|
||||
|
||||
def set_language_models(self, language_models: Dict[str, Any]):
|
||||
self.LANGUAGE_MODELS = language_models
|
||||
|
||||
@property
|
||||
def language_models(self):
|
||||
return self.LANGUAGE_MODELS
|
||||
|
||||
def as_dict(self):
|
||||
return {
|
||||
"name": self.NAME,
|
||||
"url": self.URL,
|
||||
"language_models": self.LANGUAGE_MODELS,
|
||||
# "fetch_url": self.FETCH_URL,
|
||||
}
|
||||
|
||||
|
||||
class PageInfo:
|
||||
"""
|
||||
match_page: {
|
||||
"/dashboard?site=AccountCluster": [
|
||||
"/accounts/create",
|
||||
"/accounts/update",
|
||||
"/accounts/list",
|
||||
],
|
||||
"/update?site=AccountCluster": ["/accounts/update"],
|
||||
"/create?site=AccountCluster": ["/accounts/create"],
|
||||
},
|
||||
"""
|
||||
NAME: str
|
||||
PAGE_URL: str
|
||||
PAGEINFO: Dict[str, Any]
|
||||
URL: str = ""
|
||||
ENDPOINTS: Dict[str, Any]
|
||||
LANGUAGE_MODELS: Dict[str, Any]
|
||||
SUB_COMPONENTS: Optional[list["PageComponent"]] = None
|
||||
INSTRUCTIONS: Optional[Dict[str, Any]] = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
icon: str,
|
||||
url: str,
|
||||
endpoints: Dict[str, Any],
|
||||
language_models: Dict[str, Any],
|
||||
page_info: Optional[Dict[str, Any]] = None,
|
||||
sub_components: Optional[list["PageComponent"]] = None,
|
||||
instructions: Optional[Dict[str, Any]] = None,
|
||||
):
|
||||
self.NAME = name
|
||||
self.LANGUAGE_MODELS = language_models
|
||||
self.ICON = icon
|
||||
self.URL = url
|
||||
self.SUB_COMPONENTS = sub_components
|
||||
self.ENDPOINTS = endpoints
|
||||
self.PAGEINFO = page_info
|
||||
self.INSTRUCTIONS = instructions
|
||||
|
||||
@property
|
||||
def endpoints(self):
|
||||
return self.ENDPOINTS
|
||||
|
||||
@property
|
||||
def sub_components(self):
|
||||
return self.SUB_COMPONENTS
|
||||
|
||||
@property
|
||||
def as_dict(self):
|
||||
as_dict = {
|
||||
"name": self.NAME,
|
||||
"icon": self.ICON,
|
||||
"url": self.URL,
|
||||
"endpoints": self.ENDPOINTS,
|
||||
"language_models": self.LANGUAGE_MODELS,
|
||||
"page_info": self.PAGEINFO,
|
||||
}
|
||||
if self.INSTRUCTIONS:
|
||||
as_dict["instructions"] = self.INSTRUCTIONS
|
||||
if self.SUB_COMPONENTS:
|
||||
as_dict["sub_components"] = [i.as_dict() for i in self.SUB_COMPONENTS]
|
||||
return as_dict
|
||||
|
||||
|
||||
class Event:
|
||||
@@ -185,7 +262,7 @@ class CategoryCluster:
|
||||
|
||||
TAGS: list
|
||||
PREFIX: str
|
||||
PAGEINFO: Optional[PageInfo]
|
||||
PAGEINFO: Optional[Dict['str', PageInfo]]
|
||||
DESCRIPTION: str
|
||||
ENDPOINTS: dict[str, MethodToEvent] # {"MethodToEvent": MethodToEvent, ...}
|
||||
SUBCATEGORY: Optional[List["CategoryCluster"]] # [CategoryCluster, ...]
|
||||
@@ -200,7 +277,7 @@ class CategoryCluster:
|
||||
description: str,
|
||||
endpoints: dict[str, MethodToEvent],
|
||||
sub_category: list,
|
||||
pageinfo: Optional[PageInfo] = None,
|
||||
pageinfo: Optional[Dict['str', PageInfo]] = None,
|
||||
include_in_schema: Optional[bool] = True,
|
||||
is_client: Optional[bool] = False,
|
||||
):
|
||||
@@ -262,7 +339,14 @@ class CategoryCluster:
|
||||
def retrieve_page_info(self):
|
||||
"""
|
||||
PAGE_INFO:ClusterToMethod = {"PageInfo": {...}, "subCategory": PAGE_INFO:ClusterToMethod}
|
||||
return {"prefix": self.PREFIX, **page_info}
|
||||
"""
|
||||
raise NotImplementedError(
|
||||
"CategoryCluster retrieve_page_info() method is not implemented"
|
||||
)
|
||||
page_infos = {}
|
||||
if isinstance(self.PAGEINFO, dict):
|
||||
for page_key, page_info in dict(self.PAGEINFO).items():
|
||||
if page_info_dict := getattr(page_info, 'as_dict', None):
|
||||
page_infos[page_key] = page_info_dict
|
||||
return {"prefix": self.PREFIX, **page_infos}
|
||||
if hasattr(self.PAGEINFO, 'as_dict'):
|
||||
return {"prefix": self.PREFIX, **self.PAGEINFO.as_dict}
|
||||
return
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from ApiLayers.AllConfigs.Redis.configs import RedisCategoryKeys
|
||||
from ApiLayers.AllConfigs.Redis.configs import RedisCategoryKeys, RedisCategoryPageInfoKeysAction
|
||||
|
||||
|
||||
class PrepareRedisItems:
|
||||
@@ -13,6 +13,8 @@ class PrepareRedisItems:
|
||||
METHOD_FUNCTION_CODES_VALUE: dict = {}
|
||||
ENDPOINT2CLASS_KEY: str = RedisCategoryKeys.ENDPOINT2CLASS
|
||||
ENDPOINT2CLASS_VALUE: dict = {}
|
||||
PAGE_INFO_KEY: str = RedisCategoryPageInfoKeysAction.page_index
|
||||
PAGE_INFO_VALUE: dict = {}
|
||||
|
||||
@property
|
||||
def as_dict(self):
|
||||
@@ -22,6 +24,7 @@ class PrepareRedisItems:
|
||||
self.CLUSTER_FUNCTION_CODES_KEY: self.CLUSTER_FUNCTION_CODES_VALUE,
|
||||
self.METHOD_FUNCTION_CODES_KEY: self.METHOD_FUNCTION_CODES_VALUE,
|
||||
self.ENDPOINT2CLASS_KEY: self.ENDPOINT2CLASS_VALUE,
|
||||
self.PAGE_INFO_KEY: self.PAGE_INFO_VALUE,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from ApiLayers.ApiServices.Cluster.create_router import (
|
||||
CreateRouterFromCluster,
|
||||
CreateEndpointFromCluster,
|
||||
)
|
||||
from ApiLayers.AllConfigs.Redis.configs import RedisCategoryKeys
|
||||
from ApiLayers.AllConfigs.Redis.configs import RedisCategoryKeys, RedisCategoryPageInfoKeys
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from Services.Redis.Actions.actions import RedisActions
|
||||
from Services.Redis.Models.cluster import RedisList
|
||||
@@ -75,6 +75,18 @@ class PrepareEvents(DecoratorModule):
|
||||
self.cluster_controller_group = cluster_controller_group
|
||||
self.valid_redis_items: PrepareRedisItems = PrepareRedisItems()
|
||||
self.prepare_needs()
|
||||
self.prepare_page_info()
|
||||
|
||||
def prepare_page_info(self):
|
||||
"""
|
||||
[SAVE]REDIS => PAGE_MENU_INDEX:PAGE_URL= {...PageInfo}
|
||||
"""
|
||||
for cluster_control in self.cluster_controller_group.imports:
|
||||
cluster = cluster_control.category_cluster
|
||||
if retrieve_page_info := cluster.retrieve_page_info():
|
||||
self.valid_redis_items.PAGE_INFO_VALUE.update({
|
||||
f"{self.valid_redis_items.PAGE_INFO_KEY}:{cluster.name}": retrieve_page_info
|
||||
})
|
||||
|
||||
def prepare_needs(self):
|
||||
# @Pages iterate(ClusterToMethod)
|
||||
@@ -137,6 +149,15 @@ class SetItems2Redis:
|
||||
continue
|
||||
RedisActions.delete(list_keys=[f"{redis_values_to_delete}*"])
|
||||
|
||||
for (
|
||||
redis_values_to_delete,
|
||||
redis_key_type,
|
||||
) in RedisCategoryPageInfoKeys.__annotations__.items():
|
||||
if isinstance(redis_key_type, str):
|
||||
continue
|
||||
RedisActions.delete(list_keys=[f"{redis_values_to_delete}*"]
|
||||
)
|
||||
|
||||
# Save MENU_FIRST_LAYER to Redis
|
||||
redis_list = RedisList(redis_key=RedisCategoryKeys.MENU_FIRST_LAYER)
|
||||
RedisActions.set_json(
|
||||
@@ -193,3 +214,11 @@ class SetItems2Redis:
|
||||
f"{RedisCategoryKeys.ENDPOINT2CLASS}": True,
|
||||
},
|
||||
)
|
||||
|
||||
for redis_key, redis_value in dict_prep.get(
|
||||
PrepareRedisItems.PAGE_INFO_KEY
|
||||
).items():
|
||||
redis_list = RedisList(redis_key=redis_key)
|
||||
RedisActions.set_json(
|
||||
list_keys=redis_list.to_list(), value=redis_value
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user