Adding Jira DataProcessor
This commit is contained in:
@@ -48,4 +48,22 @@ def post(session, _id: str, content: str):
|
||||
def post(session, _id: str):
|
||||
logger.debug(f"Entering {Routes.ImportHolidays} with args {debug_session(session)}, {_id=}")
|
||||
instance = InstanceManager.get(session, _id)
|
||||
return instance.import_holidays()
|
||||
return instance.import_holidays()
|
||||
|
||||
@rt(Routes.ConfigureJira)
|
||||
def get(session, _id: str, boundaries: str):
|
||||
logger.debug(f"Entering {Routes.ConfigureJira} - GET with args {debug_session(session)}, {_id=}, {boundaries=}")
|
||||
instance = InstanceManager.get(session, _id)
|
||||
return instance.show_configure_jira(json.loads(boundaries) if boundaries else None)
|
||||
|
||||
@rt(Routes.ConfigureJira)
|
||||
def post(session, _id: str, args: dict):
|
||||
logger.debug(f"Entering {Routes.ConfigureJira} - POST with args {debug_session(session)}, {_id=}, {args=}")
|
||||
instance = InstanceManager.get(session, _id)
|
||||
return instance.update_jira_settings(args)
|
||||
|
||||
@rt(Routes.ConfigureJiraCancel)
|
||||
def post(session, _id: str):
|
||||
logger.debug(f"Entering {Routes.ConfigureJiraCancel} with args {debug_session(session)}, {_id=}")
|
||||
instance = InstanceManager.get(session, _id)
|
||||
return instance.cancel_jira_settings()
|
||||
@@ -23,9 +23,16 @@ class AiBuddySettingsEntry:
|
||||
self.ollama_port = port
|
||||
|
||||
|
||||
@dataclass()
|
||||
class JiraSettingsEntry:
|
||||
user_name: str = ""
|
||||
api_token: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class AdminSettings:
|
||||
ai_buddy: AiBuddySettingsEntry = field(default_factory=AiBuddySettingsEntry)
|
||||
jira: JiraSettingsEntry = field(default_factory=JiraSettingsEntry)
|
||||
|
||||
|
||||
class AdminDbManager:
|
||||
@@ -37,3 +44,8 @@ class AdminDbManager:
|
||||
ADMIN_SETTINGS_ENTRY,
|
||||
AdminSettings,
|
||||
"ai_buddy")
|
||||
self.jira = NestedSettingsManager(session,
|
||||
settings_manager,
|
||||
ADMIN_SETTINGS_ENTRY,
|
||||
AdminSettings,
|
||||
"jira")
|
||||
|
||||
10
src/components/admin/assets/icons.py
Normal file
10
src/components/admin/assets/icons.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from fastcore.basics import NotStr
|
||||
|
||||
icon_jira = NotStr("""<svg name="jara" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<style>.a{fill:none;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;}</style>
|
||||
</defs>
|
||||
<path class="a" d="M5.5,22.9722h0a8.7361,8.7361,0,0,0,8.7361,8.7361h2.0556v2.0556A8.7361,8.7361,0,0,0,25.0278,42.5h0V22.9722Z"/>
|
||||
<path class="a" d="M14.2361,14.2361h0a8.7361,8.7361,0,0,0,8.7361,8.7361h2.0556v2.0556a8.7361,8.7361,0,0,0,8.7361,8.7361h0V14.2361Z"/>
|
||||
<path class="a" d="M22.9722,5.5h0a8.7361,8.7361,0,0,0,8.7361,8.7361h2.0556v2.0556A8.7361,8.7361,0,0,0,42.5,25.0278h0V5.5Z"/>
|
||||
</svg>""")
|
||||
@@ -38,7 +38,31 @@ class AdminCommandManager(BaseCommandManager):
|
||||
"hx-swap": "outerHTML",
|
||||
"hx-vals": f'js:{{"_id": "{self._id}", boundaries: getTabContentBoundaries("{self._owner.tabs_manager.get_id()}")}}',
|
||||
}
|
||||
|
||||
|
||||
def show_configure_jira(self):
|
||||
return {
|
||||
"hx-get": f"{ROUTE_ROOT}{Routes.ConfigureJira}",
|
||||
"hx-target": f"#{self._owner.tabs_manager.get_id()}",
|
||||
"hx-swap": "outerHTML",
|
||||
"hx-vals": f'js:{{"_id": "{self._id}", boundaries: getTabContentBoundaries("{self._owner.tabs_manager.get_id()}")}}',
|
||||
}
|
||||
|
||||
def save_configure_jira(self):
|
||||
return {
|
||||
"hx-post": f"{ROUTE_ROOT}{Routes.ConfigureJira}",
|
||||
"hx-target": f"#{self._owner.tabs_manager.get_id()}",
|
||||
"hx-swap": "outerHTML",
|
||||
"hx-vals": f'js:{{"_id": "{self._id}"}}',
|
||||
# The form adds the rest
|
||||
}
|
||||
|
||||
def cancel_configure_jira(self):
|
||||
return {
|
||||
"hx-post": f"{ROUTE_ROOT}{Routes.ConfigureJiraCancel}",
|
||||
"hx-target": f"#{self._owner.tabs_manager.get_id()}",
|
||||
"hx-swap": "outerHTML",
|
||||
"hx-vals": f'js:{{"_id": "{self._id}"}}',
|
||||
}
|
||||
|
||||
class ImportHolidaysCommandManager(BaseCommandManager):
|
||||
def __init__(self, owner):
|
||||
|
||||
@@ -4,10 +4,11 @@ from ai.mcp_client import MPC_CLIENTS_IDS
|
||||
from ai.mcp_tools import MCPServerTools
|
||||
from components.BaseComponent import BaseComponent
|
||||
from components.admin.admin_db_manager import AdminDbManager
|
||||
from components.admin.assets.icons import icon_jira
|
||||
from components.admin.commands import AdminCommandManager
|
||||
from components.admin.components.AdminForm import AdminFormItem, AdminFormType, AdminForm
|
||||
from components.admin.components.ImportHolidays import ImportHolidays
|
||||
from components.admin.constants import ADMIN_INSTANCE_ID, ADMIN_AI_BUDDY_INSTANCE_ID, ADMIN_IMPORT_HOLIDAYS_INSTANCE_ID
|
||||
from components.admin.constants import ADMIN_INSTANCE_ID, ADMIN_AI_BUDDY_INSTANCE_ID, ADMIN_JIRA_INSTANCE_ID
|
||||
from components.aibuddy.assets.icons import icon_brain_ok
|
||||
from components.hoildays.assets.icons import icon_holidays
|
||||
from components.tabs.components.MyTabs import MyTabs
|
||||
@@ -59,6 +60,30 @@ class Admin(BaseComponent):
|
||||
|
||||
return self._add_tab(ADMIN_AI_BUDDY_INSTANCE_ID, "Admin - Import Holidays", form)
|
||||
|
||||
def show_configure_jira(self, boundaries):
|
||||
fields = [
|
||||
AdminFormItem('user_name', "Email", "Email used to connect to JIRA.", AdminFormType.TEXT),
|
||||
AdminFormItem("api_token", "API Key", "API Key to connect to JIRA.", AdminFormType.TEXT),
|
||||
]
|
||||
hooks = {
|
||||
"on_ok": self.commands.save_configure_jira(),
|
||||
"on_cancel": self.commands.cancel_configure_jira(),
|
||||
"ok_title": "Apply"
|
||||
}
|
||||
|
||||
form = InstanceManager.get(self._session,
|
||||
AdminForm.create_component_id(self._session, prefix=self._id),
|
||||
AdminForm,
|
||||
owner=self,
|
||||
title="Jira Configuration Page",
|
||||
obj=self.db.jira,
|
||||
form_fields=fields,
|
||||
hooks=hooks,
|
||||
key=ADMIN_JIRA_INSTANCE_ID,
|
||||
boundaries=boundaries
|
||||
)
|
||||
return self._add_tab(ADMIN_JIRA_INSTANCE_ID, "Admin - Jira Configuration", form)
|
||||
|
||||
def update_ai_buddy_settings(self, values: dict):
|
||||
values = self.manage_lists(values)
|
||||
self.db.ai_buddy.update(values, ignore_missing=True)
|
||||
@@ -69,6 +94,17 @@ class Admin(BaseComponent):
|
||||
self.tabs_manager.remove_tab(tab_id)
|
||||
return self.tabs_manager.render()
|
||||
|
||||
def update_jira_settings(self, values: dict):
|
||||
values = self.manage_lists(values)
|
||||
self.db.jira.update(values, ignore_missing=True)
|
||||
return self.tabs_manager.render()
|
||||
|
||||
def cancel_jira_settings(self):
|
||||
tab_id = self.tabs_manager.get_tab_id(ADMIN_JIRA_INSTANCE_ID)
|
||||
self.tabs_manager.remove_tab(tab_id)
|
||||
return self.tabs_manager.render()
|
||||
|
||||
|
||||
def __ft__(self):
|
||||
return Div(
|
||||
Div(cls="divider"),
|
||||
@@ -84,6 +120,11 @@ class Admin(BaseComponent):
|
||||
mk_ellipsis("holidays", cls="text-sm", **self.commands.show_import_holidays()),
|
||||
cls="flex p-0 min-h-0 truncate",
|
||||
),
|
||||
Div(
|
||||
mk_icon(icon_jira, can_select=False),
|
||||
mk_ellipsis("jira", cls="text-sm", **self.commands.show_configure_jira()),
|
||||
cls="flex p-0 min-h-0 truncate",
|
||||
),
|
||||
#
|
||||
# cls=""),
|
||||
# Script(f"bindAdmin('{self._id}')"),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
ADMIN_INSTANCE_ID = "__Admin__"
|
||||
ADMIN_AI_BUDDY_INSTANCE_ID = "__AdminAIBuddy__"
|
||||
ADMIN_IMPORT_HOLIDAYS_INSTANCE_ID = "__AdminImportHolidays__"
|
||||
ADMIN_JIRA_INSTANCE_ID = "__AdminJira__"
|
||||
ROUTE_ROOT = "/admin"
|
||||
ADMIN_SETTINGS_ENTRY = "Admin"
|
||||
|
||||
@@ -8,4 +9,6 @@ class Routes:
|
||||
AiBuddy = "/ai-buddy"
|
||||
AiBuddyCancel = "/ai-buddy-cancel"
|
||||
ImportHolidays = "/import-holidays"
|
||||
PasteHolidays = "/paste-holidays"
|
||||
PasteHolidays = "/paste-holidays"
|
||||
ConfigureJira = "/configure-jira"
|
||||
ConfigureJiraCancel = "/configure-jira-cancel"
|
||||
|
||||
Reference in New Issue
Block a user