From 46542c328335e62ac4f589e4725c10c4ce923436 Mon Sep 17 00:00:00 2001 From: Georg-Stahn Date: Mon, 20 Nov 2023 17:39:21 +0100 Subject: [PATCH 01/49] push first sql setup try --- .../clan-cli/clan_cli/webui/routers/health.py | 6 ++- pkgs/clan-cli/clan_cli/webui/sql_db.py | 0 pkgs/clan-cli/clan_cli/webui/sql_models.py | 25 +++++++++++ pkgs/clan-cli/clan_cli/webui/sql_schemas.py | 41 +++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 pkgs/clan-cli/clan_cli/webui/sql_db.py create mode 100644 pkgs/clan-cli/clan_cli/webui/sql_models.py create mode 100644 pkgs/clan-cli/clan_cli/webui/sql_schemas.py diff --git a/pkgs/clan-cli/clan_cli/webui/routers/health.py b/pkgs/clan-cli/clan_cli/webui/routers/health.py index 24967e5..2deed84 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/health.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/health.py @@ -1,8 +1,10 @@ from fastapi import APIRouter +from ..api_outputs import Machine, Status router = APIRouter() @router.get("/health", include_in_schema=True) -async def health() -> str: - return "OK" +async def health() -> Machine: #str: + return Machine(name="test", status=Status.ONLINE) +# return "OK" diff --git a/pkgs/clan-cli/clan_cli/webui/sql_db.py b/pkgs/clan-cli/clan_cli/webui/sql_db.py new file mode 100644 index 0000000..e69de29 diff --git a/pkgs/clan-cli/clan_cli/webui/sql_models.py b/pkgs/clan-cli/clan_cli/webui/sql_models.py new file mode 100644 index 0000000..82ff6a5 --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/sql_models.py @@ -0,0 +1,25 @@ +from sqlalchemy import Boolean, Column, ForeignKey, Integer, String +from sqlalchemy.orm import relationship +from .sql_db import Base + +class Repository(Base): + __tablename__ = "repositories" + + id = Column(Integer, primary_key=True, index=True) + service_name = Column(String, unique=True, index=True) + service_type = Column(String, unique=True, index=True) + end_point = Column(String, unique=True, index=True) + producer = Column(String) + producer_did = Column(String) + network = Column(String) + +class Producer(Base): + __tablename__ = "producers" + + id = Column(Integer, primary_key=True, index=True) + service_name = Column(String, unique=True, index=True) + service_type = Column(String, unique=True, index=True) + end_point = Column(String, unique=True, index=True) + usage = Column(String) # TODO enum? + status = Column(String) + action = Column(String) diff --git a/pkgs/clan-cli/clan_cli/webui/sql_schemas.py b/pkgs/clan-cli/clan_cli/webui/sql_schemas.py new file mode 100644 index 0000000..d0fa20f --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/sql_schemas.py @@ -0,0 +1,41 @@ +from pydantic import BaseModel + + +class ProducerBase(BaseModel): + title: str + description: str | None = None + + +class ProducerCreate(ProducerBase): + service_name: str + service_type: str + end_point: str + usage_str: str + status: str + action: str + + +class Producer(ProducerBase): + id: int + + class Config: + orm_mode = True + + +class RepositoryBase(BaseModel): + service_name: str + + +class RepositoryCreate(RepositoryBase): + service_type: str + end_point: str + producer_did: str + network: str + + +class Repository(RepositoryBase): + id: int + Producers: list[Producer] = [] + + class Config: + orm_mode = True -- 2.51.0 From d5150d47a27eb040f691a7e3dbf33dd1c1ceeced Mon Sep 17 00:00:00 2001 From: Georg-Stahn Date: Mon, 20 Nov 2023 17:51:12 +0100 Subject: [PATCH 02/49] add sql db --- pkgs/clan-cli/clan_cli/webui/sql_db.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/clan-cli/clan_cli/webui/sql_db.py b/pkgs/clan-cli/clan_cli/webui/sql_db.py index e69de29..4acf1eb 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_db.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_db.py @@ -0,0 +1,12 @@ +from sqlalchemy import create_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker + +URL = "sqlite:///./sql_app.db" + +engine = create_engine( + URL, connect_args={"check_same_thread":False} +) +SessionLocal = sessionmaker(autocommit=False, autoflush=Flase, bind=engine) + +Base = declarative_base() \ No newline at end of file -- 2.51.0 From f3888b851b2beb5855814797de639dc930dd7491 Mon Sep 17 00:00:00 2001 From: Georg-Stahn Date: Mon, 20 Nov 2023 22:45:31 +0100 Subject: [PATCH 03/49] first running test get and post :) --- .gitignore | 1 + pkgs/clan-cli/clan_cli/webui/app.py | 15 ++++- .../clan-cli/clan_cli/webui/routers/health.py | 2 +- .../clan_cli/webui/routers/sql_connect.py | 15 +++++ pkgs/clan-cli/clan_cli/webui/sql_crud.py | 24 ++++++++ pkgs/clan-cli/clan_cli/webui/sql_db.py | 12 +++- pkgs/clan-cli/clan_cli/webui/sql_models.py | 31 +++++------ pkgs/clan-cli/clan_cli/webui/sql_schemas.py | 55 ++++++++----------- 8 files changed, 102 insertions(+), 53 deletions(-) create mode 100644 pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py create mode 100644 pkgs/clan-cli/clan_cli/webui/sql_crud.py diff --git a/.gitignore b/.gitignore index c899ee7..72b259b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ __pycache__ .coverage .mypy_cache .pytest_cache +pkgs.pyproj .reports .ruff_cache htmlcov diff --git a/pkgs/clan-cli/clan_cli/webui/app.py b/pkgs/clan-cli/clan_cli/webui/app.py index 88ff380..8ef7b04 100644 --- a/pkgs/clan-cli/clan_cli/webui/app.py +++ b/pkgs/clan-cli/clan_cli/webui/app.py @@ -8,7 +8,14 @@ from fastapi.staticfiles import StaticFiles from ..errors import ClanError from .assets import asset_path from .error_handlers import clan_error_handler -from .routers import health, root +from .routers import health, root, sql_connect # sql router hinzufügen + +#import for sql +from fastapi import Depends, FastAPI, HTTPException +from sqlalchemy.orm import Session +from . import sql_crud, sql_models, sql_schemas +from .sql_db import SessionLocal, engine + origins = [ "http://localhost:3000", @@ -18,6 +25,10 @@ log = logging.getLogger(__name__) def setup_app() -> FastAPI: + # bind sql engine + sql_models.Base.metadata.drop_all(engine) + sql_models.Base.metadata.create_all(bind=engine) + app = FastAPI() app.add_middleware( CORSMiddleware, @@ -28,6 +39,8 @@ def setup_app() -> FastAPI: ) app.include_router(health.router) + #sql methodes + app.include_router(sql_connect.router) # Needs to be last in register. Because of wildcard route app.include_router(root.router) diff --git a/pkgs/clan-cli/clan_cli/webui/routers/health.py b/pkgs/clan-cli/clan_cli/webui/routers/health.py index 2deed84..3714c36 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/health.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/health.py @@ -7,4 +7,4 @@ router = APIRouter() @router.get("/health", include_in_schema=True) async def health() -> Machine: #str: return Machine(name="test", status=Status.ONLINE) -# return "OK" +# return "OK" \ No newline at end of file diff --git a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py new file mode 100644 index 0000000..f61ab91 --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py @@ -0,0 +1,15 @@ +from fastapi import APIRouter, Request, Depends +from sqlalchemy.orm import Session +from .. import sql_crud, sql_models, sql_schemas, sql_db + +router = APIRouter() + +@router.get("/get_producers", response_model=list[sql_schemas.Producer]) +def get_producers(skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db)): + producers = sql_crud.get_producers(db, skip=skip, limit=limit) + return producers + +@router.post("/create_producers", response_model=sql_schemas.Producer) +def create_producers(producer: sql_schemas.ProducerCreate, db: Session = Depends(sql_db.get_db)): + #todo checken ob schon da ... + return sql_crud.create_producer(db=db, producer=producer) \ No newline at end of file diff --git a/pkgs/clan-cli/clan_cli/webui/sql_crud.py b/pkgs/clan-cli/clan_cli/webui/sql_crud.py new file mode 100644 index 0000000..c8ff904 --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/sql_crud.py @@ -0,0 +1,24 @@ +from sqlalchemy.orm import Session +from . import sql_models, sql_schemas + +def get_producers(db: Session, skip: int = 0, limit: int = 100): + return db.query(sql_models.Producer).offset(skip).limit(limit).all() + +def create_producer(db: Session, producer: sql_schemas.ProducerCreate): + jsonblob_init = {"test_repo":"jsonblob_create"} + db_producer = sql_models.Producer(jsonblob=jsonblob_init) + db.add(db_producer) + db.commit() + db.refresh(db_producer) + return db_producer + + +def get_repositories(db: Session, skip: int = 0, limit: int = 100): + return db.query(sql_models.Repository).offset(skip).limit(limit).all() + +def create_repository(db: Session, repository: sql_schemas.RepositoryCreate, producers_id: int): + db_repository = sql_models.Repository(**repository.dict(), prod_id=producers_id) + db.add(db_repository) + db.commit() + db.refresh(db_repository) + return db_repository \ No newline at end of file diff --git a/pkgs/clan-cli/clan_cli/webui/sql_db.py b/pkgs/clan-cli/clan_cli/webui/sql_db.py index 4acf1eb..cc59363 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_db.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_db.py @@ -7,6 +7,14 @@ URL = "sqlite:///./sql_app.db" engine = create_engine( URL, connect_args={"check_same_thread":False} ) -SessionLocal = sessionmaker(autocommit=False, autoflush=Flase, bind=engine) +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) -Base = declarative_base() \ No newline at end of file +Base = declarative_base() + +# Dependency to start a clean thread of the db +def get_db(): + db = SessionLocal() + try: + yield db + finally: + db.close() \ No newline at end of file diff --git a/pkgs/clan-cli/clan_cli/webui/sql_models.py b/pkgs/clan-cli/clan_cli/webui/sql_models.py index 82ff6a5..d8d7cea 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_models.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_models.py @@ -1,25 +1,20 @@ -from sqlalchemy import Boolean, Column, ForeignKey, Integer, String +from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, JSON from sqlalchemy.orm import relationship from .sql_db import Base -class Repository(Base): - __tablename__ = "repositories" - - id = Column(Integer, primary_key=True, index=True) - service_name = Column(String, unique=True, index=True) - service_type = Column(String, unique=True, index=True) - end_point = Column(String, unique=True, index=True) - producer = Column(String) - producer_did = Column(String) - network = Column(String) - class Producer(Base): __tablename__ = "producers" id = Column(Integer, primary_key=True, index=True) - service_name = Column(String, unique=True, index=True) - service_type = Column(String, unique=True, index=True) - end_point = Column(String, unique=True, index=True) - usage = Column(String) # TODO enum? - status = Column(String) - action = Column(String) + jsonblob = Column(JSON) + + repos = relationship("Repository", back_populates="producer") + +class Repository(Base): + __tablename__ = "repositories" + + id = Column(Integer, primary_key=True, index=True) + jsonblob = Column(JSON) + prod_id = Column(Integer, ForeignKey("producers.id")) + + producer = relationship("Producer", back_populates="repos") \ No newline at end of file diff --git a/pkgs/clan-cli/clan_cli/webui/sql_schemas.py b/pkgs/clan-cli/clan_cli/webui/sql_schemas.py index d0fa20f..1fcd4c3 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_schemas.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_schemas.py @@ -1,41 +1,34 @@ -from pydantic import BaseModel +from pydantic import BaseModel, Field - -class ProducerBase(BaseModel): +class RepositoryBase(BaseModel): title: str description: str | None = None - -class ProducerCreate(ProducerBase): - service_name: str - service_type: str - end_point: str - usage_str: str - status: str - action: str - - -class Producer(ProducerBase): - id: int - - class Config: - orm_mode = True - - -class RepositoryBase(BaseModel): - service_name: str - - class RepositoryCreate(RepositoryBase): - service_type: str - end_point: str - producer_did: str - network: str - + pass class Repository(RepositoryBase): id: int - Producers: list[Producer] = [] - + prod_id: str + class Config: + orm_mode = True + + +class ProducerBase(BaseModel): + id: int + +class ProducerCreate(ProducerBase): + jsonblob: int = Field( + 42, + title='The Json', + description='this is the value of json', + gt=30, + lt=50, + list=[1,2,"3"], + ) + +class Producer(ProducerBase): + id: int + repos: list[Repository] = [] class Config: orm_mode = True -- 2.51.0 From 533897c91cc16b17d6db6344f467e234baf6f8d9 Mon Sep 17 00:00:00 2001 From: Georg-Stahn Date: Sun, 26 Nov 2023 13:00:31 +0100 Subject: [PATCH 04/49] last changes to db --- pkgs/clan-cli/clan_cli/webui/sql_app.db | Bin 0 -> 20480 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 pkgs/clan-cli/clan_cli/webui/sql_app.db diff --git a/pkgs/clan-cli/clan_cli/webui/sql_app.db b/pkgs/clan-cli/clan_cli/webui/sql_app.db new file mode 100644 index 0000000000000000000000000000000000000000..382350b21428fe4ac0daedc1e08532fd7f155e42 GIT binary patch literal 20480 zcmWFz^vNtqRY=P(%1ta$FlG>7U}R))P*7lCU|?rpU|?lH02T%Y1`vjcFv1vkXm$p@ zyq&xtjeNok{N4QKe8qgic+`(djfTKz2#kinXb6mkz-S1JhQMeDjE2By2#kinXb8|R z1malO#0^y$OEdFQQY$hm;)_xX@{2P|@{2N4i{mp>kh!eRL9UJ=t_q%hF0K&@m}(XL z{S=VZD`;e$GB&xEBqrsgBFiJQS)gWzI6C>bqM5?QnVF*C=@;Va?i!@v z=O3cr7wY4qqrki;BTIxHN;9*u=Hv88cyF1ecG`Oo6kR zp+10z4qOK0B7Z+LQ;Qkd#pUH08%@E%0#^%XFhPxj1PEMML4)|vK=(SACa7=D%s-KV z|2F?N{)zNUWTQ5XhQMeDjE2By2#kinXb6mkz-S1JhQMeDjE2By2#kinhzKDj70u_RTgR+)(yMT|r!;$mQ6VCMh8!2gH;8~=w99rB}| z9}R)g5Eu=C(GVC7fzc2c4S~@R7!85Z5Eu=C(GVC7fngH@tjvsz%*-H?iHVt+lM^)m z&mb^tyf^BR(GVC7fzc2c4S~@R7!85Z5Eu=C(GVC7fzc2c4S~@R7!3g|Apn~HAMO8R s37Ao#(GVC7fzc2c4S~@R7!85Z5Eu=C(GVC7fzc2c4S~@R7)Bug0F;W+@c;k- literal 0 HcmV?d00001 -- 2.51.0 From f4336d224477203bb69a5b6b233b0e5ea5a7031c Mon Sep 17 00:00:00 2001 From: sara-pervana Date: Tue, 21 Nov 2023 17:12:21 +0100 Subject: [PATCH 05/49] added custom table component - again --- pkgs/ui/src/components/table/index.tsx | 66 ++++++++++++++++++++++++++ pkgs/ui/src/components/table/style.tsx | 23 +++++++++ pkgs/ui/src/types/index.ts | 10 ++++ 3 files changed, 99 insertions(+) create mode 100644 pkgs/ui/src/components/table/index.tsx create mode 100644 pkgs/ui/src/components/table/style.tsx create mode 100644 pkgs/ui/src/types/index.ts diff --git a/pkgs/ui/src/components/table/index.tsx b/pkgs/ui/src/components/table/index.tsx new file mode 100644 index 0000000..0b389cb --- /dev/null +++ b/pkgs/ui/src/components/table/index.tsx @@ -0,0 +1,66 @@ +import React from "react"; +import Table from '@mui/material/Table'; +import TableBody from '@mui/material/TableBody'; +import TableContainer from '@mui/material/TableContainer'; +import TableHead from '@mui/material/TableHead'; +import TableRow from '@mui/material/TableRow'; +import Paper from '@mui/material/Paper'; + +import { NoDataOverlay } from "@/components/noDataOverlay"; +import { StyledTableCell, StyledTableRow } from "./style"; +import { ICustomTable, CustomTableConfiguration } from "@/types"; + +const CustomTable = ({ configuration, data }: ICustomTable) => { + + // display empty icon in case there is no data + if (!data || data.length === 0) + return + + const renderTableCell = (value: any, cellKey: string, render?: (param: any) => void | undefined) => { + + let renderedValue = value; + + // cover use case if the data is an array + if (Array.isArray(value)) renderedValue = value.join(', ') + + // cover use case if we want to render a component + if (render) renderedValue = render(value); + + return ( + + {renderedValue} + + ); + + } + + return ( + + + + + {configuration.map((header: CustomTableConfiguration) => ( + + {header.label} + + ))} + + + + {data.map((data: any, rowIndex: number) => ( + + {configuration.map((column: CustomTableConfiguration) => { + const cellValue: any = data[column.key]; + const cellKey = column.key; + const renderComponent = column?.render; + return renderTableCell(cellValue, cellKey, renderComponent); + })} + + ))} + +
+
+ ) +} + +export default CustomTable; \ No newline at end of file diff --git a/pkgs/ui/src/components/table/style.tsx b/pkgs/ui/src/components/table/style.tsx new file mode 100644 index 0000000..9785f80 --- /dev/null +++ b/pkgs/ui/src/components/table/style.tsx @@ -0,0 +1,23 @@ +import { styled } from '@mui/material/styles'; +import TableCell, { tableCellClasses } from '@mui/material/TableCell'; +import TableRow from '@mui/material/TableRow'; + +export const StyledTableCell = styled(TableCell)(({ theme }) => ({ + [`&.${tableCellClasses.head}`]: { + backgroundColor: theme.palette.common.black, + color: theme.palette.common.white, + }, + [`&.${tableCellClasses.body}`]: { + fontSize: 14, + }, +})); + +export const StyledTableRow = styled(TableRow)(({ theme }) => ({ + '&:nth-of-type(odd)': { + backgroundColor: theme.palette.action.hover, + }, + // hide last border + '&:last-child td, &:last-child th': { + border: 0, + }, +})); \ No newline at end of file diff --git a/pkgs/ui/src/types/index.ts b/pkgs/ui/src/types/index.ts new file mode 100644 index 0000000..ca5a5fc --- /dev/null +++ b/pkgs/ui/src/types/index.ts @@ -0,0 +1,10 @@ +export interface CustomTableConfiguration { + key: string; + label: string; + render?: (param: any) => void; +} + +export interface ICustomTable { + configuration: CustomTableConfiguration[], + data: any +} \ No newline at end of file -- 2.51.0 From ef0954bcb9656c411238fef53063276a599ddbf0 Mon Sep 17 00:00:00 2001 From: sara-pervana Date: Tue, 21 Nov 2023 18:04:58 +0100 Subject: [PATCH 06/49] ran format command --- pkgs/ui/src/components/table/index.tsx | 37 +++++++++++++------------- pkgs/ui/src/components/table/style.tsx | 12 ++++----- pkgs/ui/src/types/index.ts | 6 ++--- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/pkgs/ui/src/components/table/index.tsx b/pkgs/ui/src/components/table/index.tsx index 0b389cb..cbfec7e 100644 --- a/pkgs/ui/src/components/table/index.tsx +++ b/pkgs/ui/src/components/table/index.tsx @@ -1,27 +1,29 @@ import React from "react"; -import Table from '@mui/material/Table'; -import TableBody from '@mui/material/TableBody'; -import TableContainer from '@mui/material/TableContainer'; -import TableHead from '@mui/material/TableHead'; -import TableRow from '@mui/material/TableRow'; -import Paper from '@mui/material/Paper'; +import Table from "@mui/material/Table"; +import TableBody from "@mui/material/TableBody"; +import TableContainer from "@mui/material/TableContainer"; +import TableHead from "@mui/material/TableHead"; +import TableRow from "@mui/material/TableRow"; +import Paper from "@mui/material/Paper"; import { NoDataOverlay } from "@/components/noDataOverlay"; import { StyledTableCell, StyledTableRow } from "./style"; import { ICustomTable, CustomTableConfiguration } from "@/types"; const CustomTable = ({ configuration, data }: ICustomTable) => { - // display empty icon in case there is no data if (!data || data.length === 0) - return - - const renderTableCell = (value: any, cellKey: string, render?: (param: any) => void | undefined) => { + return ; + const renderTableCell = ( + value: any, + cellKey: string, + render?: (param: any) => void | undefined, + ) => { let renderedValue = value; // cover use case if the data is an array - if (Array.isArray(value)) renderedValue = value.join(', ') + if (Array.isArray(value)) renderedValue = value.join(", "); // cover use case if we want to render a component if (render) renderedValue = render(value); @@ -31,8 +33,7 @@ const CustomTable = ({ configuration, data }: ICustomTable) => { {renderedValue} ); - - } + }; return ( @@ -40,9 +41,7 @@ const CustomTable = ({ configuration, data }: ICustomTable) => { {configuration.map((header: CustomTableConfiguration) => ( - - {header.label} - + {header.label} ))} @@ -60,7 +59,7 @@ const CustomTable = ({ configuration, data }: ICustomTable) => { - ) -} + ); +}; -export default CustomTable; \ No newline at end of file +export default CustomTable; diff --git a/pkgs/ui/src/components/table/style.tsx b/pkgs/ui/src/components/table/style.tsx index 9785f80..b0e5429 100644 --- a/pkgs/ui/src/components/table/style.tsx +++ b/pkgs/ui/src/components/table/style.tsx @@ -1,6 +1,6 @@ -import { styled } from '@mui/material/styles'; -import TableCell, { tableCellClasses } from '@mui/material/TableCell'; -import TableRow from '@mui/material/TableRow'; +import { styled } from "@mui/material/styles"; +import TableCell, { tableCellClasses } from "@mui/material/TableCell"; +import TableRow from "@mui/material/TableRow"; export const StyledTableCell = styled(TableCell)(({ theme }) => ({ [`&.${tableCellClasses.head}`]: { @@ -13,11 +13,11 @@ export const StyledTableCell = styled(TableCell)(({ theme }) => ({ })); export const StyledTableRow = styled(TableRow)(({ theme }) => ({ - '&:nth-of-type(odd)': { + "&:nth-of-type(odd)": { backgroundColor: theme.palette.action.hover, }, // hide last border - '&:last-child td, &:last-child th': { + "&:last-child td, &:last-child th": { border: 0, }, -})); \ No newline at end of file +})); diff --git a/pkgs/ui/src/types/index.ts b/pkgs/ui/src/types/index.ts index ca5a5fc..d4635d5 100644 --- a/pkgs/ui/src/types/index.ts +++ b/pkgs/ui/src/types/index.ts @@ -5,6 +5,6 @@ export interface CustomTableConfiguration { } export interface ICustomTable { - configuration: CustomTableConfiguration[], - data: any -} \ No newline at end of file + configuration: CustomTableConfiguration[]; + data: any; +} -- 2.51.0 From 7d2b055c3e89fba2a73937fc7b3eb5763c283404 Mon Sep 17 00:00:00 2001 From: sara-pervana Date: Tue, 21 Nov 2023 17:45:57 +0100 Subject: [PATCH 07/49] Onur changes - added config and dummy data for DLG and AP --- pkgs/ui/src/mock/access-point/index.ts | 92 ++++++++++++++++++++++++++ pkgs/ui/src/mock/dlg/index.ts | 34 ++++++++++ 2 files changed, 126 insertions(+) create mode 100644 pkgs/ui/src/mock/access-point/index.ts create mode 100644 pkgs/ui/src/mock/dlg/index.ts diff --git a/pkgs/ui/src/mock/access-point/index.ts b/pkgs/ui/src/mock/access-point/index.ts new file mode 100644 index 0000000..1dce0d9 --- /dev/null +++ b/pkgs/ui/src/mock/access-point/index.ts @@ -0,0 +1,92 @@ +// AP - Attachements + +export const APAttachmentsDummyData = [ + { + "entity_name": "C1", + "entity_DID": "did:sov:test:1234", + "network": "Carlo's Home Network", + "ip_address": "127.0.0.1", + }, + { + "entity_name": "C2", + "entity_DID": "did:sov:test:4567", + "network": "Steve's Home Network", + "ip_address": "127.0.0.1", + }, + { + "entity_name": "C1-TEST", + "entity_DID": "did:sov:test:0001", + "network": "Test Network A", + "ip_address": "127.0.0.1", + }, + { + "entity_name": "C2-TEST", + "entity_DID": "did:sov:test:0002", + "network": "Test Network B", + "ip_address": "127.0.0.1", + } +] +export const APAttachmentsTableConfig = [ + { + key: "entity_name", + label: "Entity name" + }, + { + key: "entity_DID", + label: "Entity DID" + }, + { + key: "network", + label: "Network" + }, + { + key: "ip_address", + label: "IP address" + } +] + +// AP - Service Repository +export const APServiceRepositoryDummyData = [ + { + "service_name": "Carlo's Printing", + "service_type": "3D Printing", + "end_point": "URL", + "producer": "C1", + "producer_DID": "did:sov:test:1234", + "network": "Carlo's Home Network", + }, + { + "service_name": "Jeff's Printing", + "service_type": "3D Printing", + "end_point": "URL", + "producer": "C2", + "producer_DID": "did:sov:test:5678", + "network": "Jeff's Home Network", + }, +] +export const APServiceRepositoryTableConfig = [ + { + key: "service_name", + label: "Service name" + }, + { + key: "service_type", + label: "Service type" + }, + { + key: "end_point", + label: "End point" + }, + { + key: "producer", + label: "Producer" + }, + { + key: "producer_DID", + label: "Producer DID" + }, + { + key: "network", + label: "Network" + }, +] \ No newline at end of file diff --git a/pkgs/ui/src/mock/dlg/index.ts b/pkgs/ui/src/mock/dlg/index.ts new file mode 100644 index 0000000..6201847 --- /dev/null +++ b/pkgs/ui/src/mock/dlg/index.ts @@ -0,0 +1,34 @@ +export const DLGResolutionDummyData = [ + { + "requester_name": "C1", + "requester_DID": "did:sov:test:1234", + "DID_resolved": "did:sov:test:1234", + "timestamp": "2023.11.01 17:05:45", + }, + { + "requester_name": "C2", + "requester_DID": "did:sov:test:5678", + "DID_resolved": "did:sov:test:5678", + "timestamp": "2023.12.01 15:05:50", + }, +] + + +export const DLGResolutionTableConfig = [ + { + key: "requester_name", + label: "Requester name" + }, + { + key: "requester_DID", + label: "Requester DID" + }, + { + key: "DID_resolved", + label: "DID resolved" + }, + { + key: "timestamp", + label: "Timestamp" + } +] \ No newline at end of file -- 2.51.0 From f12343c9648a86c70cfcb99c61c50f9ca92b943f Mon Sep 17 00:00:00 2001 From: sara-pervana Date: Tue, 21 Nov 2023 18:09:58 +0100 Subject: [PATCH 08/49] ran format command --- pkgs/ui/src/mock/access-point/index.ts | 92 +++++++++++++------------- pkgs/ui/src/mock/dlg/index.ts | 31 +++++---- 2 files changed, 61 insertions(+), 62 deletions(-) diff --git a/pkgs/ui/src/mock/access-point/index.ts b/pkgs/ui/src/mock/access-point/index.ts index 1dce0d9..9b139af 100644 --- a/pkgs/ui/src/mock/access-point/index.ts +++ b/pkgs/ui/src/mock/access-point/index.ts @@ -2,91 +2,91 @@ export const APAttachmentsDummyData = [ { - "entity_name": "C1", - "entity_DID": "did:sov:test:1234", - "network": "Carlo's Home Network", - "ip_address": "127.0.0.1", + entity_name: "C1", + entity_DID: "did:sov:test:1234", + network: "Carlo's Home Network", + ip_address: "127.0.0.1", }, { - "entity_name": "C2", - "entity_DID": "did:sov:test:4567", - "network": "Steve's Home Network", - "ip_address": "127.0.0.1", + entity_name: "C2", + entity_DID: "did:sov:test:4567", + network: "Steve's Home Network", + ip_address: "127.0.0.1", }, { - "entity_name": "C1-TEST", - "entity_DID": "did:sov:test:0001", - "network": "Test Network A", - "ip_address": "127.0.0.1", + entity_name: "C1-TEST", + entity_DID: "did:sov:test:0001", + network: "Test Network A", + ip_address: "127.0.0.1", }, { - "entity_name": "C2-TEST", - "entity_DID": "did:sov:test:0002", - "network": "Test Network B", - "ip_address": "127.0.0.1", - } -] + entity_name: "C2-TEST", + entity_DID: "did:sov:test:0002", + network: "Test Network B", + ip_address: "127.0.0.1", + }, +]; export const APAttachmentsTableConfig = [ { key: "entity_name", - label: "Entity name" + label: "Entity name", }, { key: "entity_DID", - label: "Entity DID" + label: "Entity DID", }, { key: "network", - label: "Network" + label: "Network", }, { key: "ip_address", - label: "IP address" - } -] + label: "IP address", + }, +]; // AP - Service Repository export const APServiceRepositoryDummyData = [ { - "service_name": "Carlo's Printing", - "service_type": "3D Printing", - "end_point": "URL", - "producer": "C1", - "producer_DID": "did:sov:test:1234", - "network": "Carlo's Home Network", - }, - { - "service_name": "Jeff's Printing", - "service_type": "3D Printing", - "end_point": "URL", - "producer": "C2", - "producer_DID": "did:sov:test:5678", - "network": "Jeff's Home Network", + service_name: "Carlo's Printing", + service_type: "3D Printing", + end_point: "URL", + producer: "C1", + producer_DID: "did:sov:test:1234", + network: "Carlo's Home Network", }, -] + { + service_name: "Jeff's Printing", + service_type: "3D Printing", + end_point: "URL", + producer: "C2", + producer_DID: "did:sov:test:5678", + network: "Jeff's Home Network", + }, +]; export const APServiceRepositoryTableConfig = [ { key: "service_name", - label: "Service name" + label: "Service name", }, { key: "service_type", - label: "Service type" + label: "Service type", }, { key: "end_point", - label: "End point" + label: "End point", }, { key: "producer", - label: "Producer" + label: "Producer", }, { key: "producer_DID", - label: "Producer DID" + label: "Producer DID", }, { key: "network", - label: "Network" + label: "Network", }, -] \ No newline at end of file +]; diff --git a/pkgs/ui/src/mock/dlg/index.ts b/pkgs/ui/src/mock/dlg/index.ts index 6201847..33b9992 100644 --- a/pkgs/ui/src/mock/dlg/index.ts +++ b/pkgs/ui/src/mock/dlg/index.ts @@ -1,34 +1,33 @@ export const DLGResolutionDummyData = [ { - "requester_name": "C1", - "requester_DID": "did:sov:test:1234", - "DID_resolved": "did:sov:test:1234", - "timestamp": "2023.11.01 17:05:45", + requester_name: "C1", + requester_DID: "did:sov:test:1234", + DID_resolved: "did:sov:test:1234", + timestamp: "2023.11.01 17:05:45", }, { - "requester_name": "C2", - "requester_DID": "did:sov:test:5678", - "DID_resolved": "did:sov:test:5678", - "timestamp": "2023.12.01 15:05:50", + requester_name: "C2", + requester_DID: "did:sov:test:5678", + DID_resolved: "did:sov:test:5678", + timestamp: "2023.12.01 15:05:50", }, -] - +]; export const DLGResolutionTableConfig = [ { key: "requester_name", - label: "Requester name" + label: "Requester name", }, { key: "requester_DID", - label: "Requester DID" + label: "Requester DID", }, { key: "DID_resolved", - label: "DID resolved" + label: "DID resolved", }, { key: "timestamp", - label: "Timestamp" - } -] \ No newline at end of file + label: "Timestamp", + }, +]; -- 2.51.0 From da287b3248726cd80769cf70e1e56bfee9564e3b Mon Sep 17 00:00:00 2001 From: sara-pervana Date: Tue, 21 Nov 2023 17:56:43 +0100 Subject: [PATCH 09/49] Orun changes - added router pages for DLG and AP --- pkgs/ui/src/app/access-point/page.tsx | 9 +++ .../app/distributed-ledger-gateway/page.tsx | 9 +++ pkgs/ui/src/components/sidebar/index.tsx | 58 +++++++++++++++---- 3 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 pkgs/ui/src/app/access-point/page.tsx create mode 100644 pkgs/ui/src/app/distributed-ledger-gateway/page.tsx diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx new file mode 100644 index 0000000..c2fea8a --- /dev/null +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -0,0 +1,9 @@ +"use client"; + +export default function AccessPoint() { + return ( +
+ Access Point Page +
+ ) +} \ No newline at end of file diff --git a/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx new file mode 100644 index 0000000..93da773 --- /dev/null +++ b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx @@ -0,0 +1,9 @@ +"use client"; + +export default function DLG() { + return ( +
+ DLG Page +
+ ) +} \ No newline at end of file diff --git a/pkgs/ui/src/components/sidebar/index.tsx b/pkgs/ui/src/components/sidebar/index.tsx index c75bfa2..b862b89 100644 --- a/pkgs/ui/src/components/sidebar/index.tsx +++ b/pkgs/ui/src/components/sidebar/index.tsx @@ -8,13 +8,16 @@ import { ListItemText, } from "@mui/material"; import Image from "next/image"; -import { ReactNode } from "react"; +import React, { ReactNode } from "react"; import { tw } from "@/utils/tailwind"; -import AssignmentIndIcon from "@mui/icons-material/AssignmentInd"; import Link from "next/link"; -import WysiwygIcon from "@mui/icons-material/Wysiwyg"; import ChevronLeftIcon from "@mui/icons-material/ChevronLeft"; +import HomeIcon from '@mui/icons-material/Home'; +import HubIcon from '@mui/icons-material/Hub'; +import PersonIcon from '@mui/icons-material/Person'; +import RouterIcon from '@mui/icons-material/Router'; +import StorageIcon from '@mui/icons-material/Storage'; type MenuEntry = { icon: ReactNode; @@ -27,17 +30,41 @@ type MenuEntry = { const menuEntries: MenuEntry[] = [ { - icon: , - label: "Freelance", + icon: , + label: "Home", to: "/", disabled: false, }, { - icon: , - label: "Blog", - to: "/blog", + icon: , + label: "Entities", + to: "/entities", disabled: true, }, + { + icon: , + label: "C1", + to: "/client-1", + disabled: false, + }, + { + icon: , + label: "C2", + to: "/client-2", + disabled: false, + }, + { + icon: , + label: "AP", + to: "/access-point", + disabled: false, + }, + { + icon: , + label: "DLG", + to: "/distributed-ledger-gateway", + disabled: false, + } ]; const hideSidebar = tw`-translate-x-14 lg:-translate-x-64`; @@ -50,17 +77,22 @@ interface SidebarProps { export function Sidebar(props: SidebarProps) { const { show, onClose } = props; + const [activeMenuItem, setActiveMenuItem] = React.useState('/'); + + const handleMenuItemClick = (path: string) => { + setActiveMenuItem(path); + }; + return ( + ); } diff --git a/pkgs/ui/src/mock/client_1/index.ts b/pkgs/ui/src/mock/client_1/index.ts index fbbe0d5..658b51e 100644 --- a/pkgs/ui/src/mock/client_1/index.ts +++ b/pkgs/ui/src/mock/client_1/index.ts @@ -17,124 +17,124 @@ export const Client1SummaryDetails = [ export const Client1ConsumerData = [ { - "service_name": "Carlo's Printing", - "service_type": "3D Printing", - "end_point": "Consume", - "producer": "C2", - "producer_did": "did:sov:test:1223", - "network": "Carlo's Home Network", + service_name: "Carlo's Printing", + service_type: "3D Printing", + end_point: "Consume", + producer: "C2", + producer_did: "did:sov:test:1223", + network: "Carlo's Home Network", }, { - "service_name": "Steve's Printing", - "service_type": "3D Printing", - "end_point": "Consume", - "producer": "C2", - "producer_did": "did:sov:test:1234", - "network": "Steve's Home Network", + service_name: "Steve's Printing", + service_type: "3D Printing", + end_point: "Consume", + producer: "C2", + producer_did: "did:sov:test:1234", + network: "Steve's Home Network", }, { - "service_name": "Test A", - "service_type": "3D Printing", - "end_point": "Consume", - "producer": "C2", - "producer_did": "did:sov:test:4567", - "network": "Test Network A", + service_name: "Test A", + service_type: "3D Printing", + end_point: "Consume", + producer: "C2", + producer_did: "did:sov:test:4567", + network: "Test Network A", }, { - "service_name": "Test B", - "service_type": "3D Printing", - "end_point": "Consume", - "producer": "C2", - "producer_did": "did:sov:test:0062", - "network": "Test Network B", + service_name: "Test B", + service_type: "3D Printing", + end_point: "Consume", + producer: "C2", + producer_did: "did:sov:test:0062", + network: "Test Network B", }, -] +]; export const Client1ConsumerTableConfig = [ { key: "service_name", - label: "Service name" + label: "Service name", }, { key: "service_type", - label: "Service Type" + label: "Service Type", }, { key: "end_point", - label: "End Point" + label: "End Point", }, { key: "producer", - label: "Producer" + label: "Producer", }, { key: "producer_did", - label: "Producer DID" + label: "Producer DID", }, { key: "network", - label: "Network" - } -] + label: "Network", + }, +]; export const Client1ProducerData = [ { - "service_name": "Carlo's Printing", - "service_type": "3D Printing", - "end_point": "URL", - "usage": "C1(3), C3(4)", - "status": "DRAFT, REGISTERED", - "action": "Register, Deregister, Delete", + service_name: "Carlo's Printing", + service_type: "3D Printing", + end_point: "URL", + usage: "C1(3), C3(4)", + status: "DRAFT, REGISTERED", + action: "Register, Deregister, Delete", }, { - "service_name": "Steve's Printing", - "service_type": "3D Printing", - "end_point": "URL", - "usage": "C1(3), C3(4)", - "status": "REGISTERED", - "action": "Create", + service_name: "Steve's Printing", + service_type: "3D Printing", + end_point: "URL", + usage: "C1(3), C3(4)", + status: "REGISTERED", + action: "Create", }, { - "service_name": "Test Printing A", - "service_type": "3D Printing", - "end_point": "URL", - "usage": "C1(3), C3(4)", - "status": "DRAFT", - "action": "Register, Deregister", + service_name: "Test Printing A", + service_type: "3D Printing", + end_point: "URL", + usage: "C1(3), C3(4)", + status: "DRAFT", + action: "Register, Deregister", }, { - "service_name": "Test Printing B", - "service_type": "3D Printing", - "end_point": "URL", - "usage": "C1(3), C3(4)", - "status": "DRAFT, REGISTERED", - "action": "Delete, Create", + service_name: "Test Printing B", + service_type: "3D Printing", + end_point: "URL", + usage: "C1(3), C3(4)", + status: "DRAFT, REGISTERED", + action: "Delete, Create", }, -] +]; export const Client1ProducerTableConfig = [ { key: "service_name", - label: "Service name" + label: "Service name", }, { key: "service_type", - label: "Service Type" + label: "Service Type", }, { key: "end_point", - label: "End Point" + label: "End Point", }, { key: "usage", - label: "Usage" + label: "Usage", }, { key: "status", - label: "Status" + label: "Status", }, { key: "action", - label: "Action" - } -] \ No newline at end of file + label: "Action", + }, +]; diff --git a/pkgs/ui/src/mock/client_2/index.ts b/pkgs/ui/src/mock/client_2/index.ts index 8898587..b0105fd 100644 --- a/pkgs/ui/src/mock/client_2/index.ts +++ b/pkgs/ui/src/mock/client_2/index.ts @@ -17,124 +17,124 @@ export const Client2SummaryDetails = [ export const Client2ConsumerData = [ { - "service_name": "Carlo's Printing", - "service_type": "3D Printing", - "end_point": "Consume", - "producer": "C2", - "producer_did": "did:sov:test:1223", - "network": "Carlo's Home Network", + service_name: "Carlo's Printing", + service_type: "3D Printing", + end_point: "Consume", + producer: "C2", + producer_did: "did:sov:test:1223", + network: "Carlo's Home Network", }, { - "service_name": "Steve's Printing", - "service_type": "3D Printing", - "end_point": "Consume", - "producer": "C2", - "producer_did": "did:sov:test:1234", - "network": "Steve's Home Network", + service_name: "Steve's Printing", + service_type: "3D Printing", + end_point: "Consume", + producer: "C2", + producer_did: "did:sov:test:1234", + network: "Steve's Home Network", }, { - "service_name": "Test A", - "service_type": "3D Printing", - "end_point": "Consume", - "producer": "C2", - "producer_did": "did:sov:test:4567", - "network": "Test Network A", + service_name: "Test A", + service_type: "3D Printing", + end_point: "Consume", + producer: "C2", + producer_did: "did:sov:test:4567", + network: "Test Network A", }, { - "service_name": "Test B", - "service_type": "3D Printing", - "end_point": "Consume", - "producer": "C2", - "producer_did": "did:sov:test:0062", - "network": "Test Network B", + service_name: "Test B", + service_type: "3D Printing", + end_point: "Consume", + producer: "C2", + producer_did: "did:sov:test:0062", + network: "Test Network B", }, -] +]; export const Client2ConsumerTableConfig = [ { key: "service_name", - label: "Service name" + label: "Service name", }, { key: "service_type", - label: "Service Type" + label: "Service Type", }, { key: "end_point", - label: "End Point" + label: "End Point", }, { key: "producer", - label: "Producer" + label: "Producer", }, { key: "producer_did", - label: "Producer DID" + label: "Producer DID", }, { key: "network", - label: "Network" - } -] + label: "Network", + }, +]; export const Client2ProducerData = [ { - "service_name": "Carlo's Printing", - "service_type": "3D Printing", - "end_point": "URL", - "usage": "C1(3), C3(4)", - "status": "DRAFT, REGISTERED", - "action": "Register, Deregister, Delete", + service_name: "Carlo's Printing", + service_type: "3D Printing", + end_point: "URL", + usage: "C1(3), C3(4)", + status: "DRAFT, REGISTERED", + action: "Register, Deregister, Delete", }, { - "service_name": "Steve's Printing", - "service_type": "3D Printing", - "end_point": "URL", - "usage": "C1(3), C3(4)", - "status": "REGISTERED", - "action": "Create", + service_name: "Steve's Printing", + service_type: "3D Printing", + end_point: "URL", + usage: "C1(3), C3(4)", + status: "REGISTERED", + action: "Create", }, { - "service_name": "Test Printing A", - "service_type": "3D Printing", - "end_point": "URL", - "usage": "C1(3), C3(4)", - "status": "DRAFT", - "action": "Register, Deregister", + service_name: "Test Printing A", + service_type: "3D Printing", + end_point: "URL", + usage: "C1(3), C3(4)", + status: "DRAFT", + action: "Register, Deregister", }, { - "service_name": "Test Printing B", - "service_type": "3D Printing", - "end_point": "URL", - "usage": "C1(3), C3(4)", - "status": "DRAFT, REGISTERED", - "action": "Delete, Create", + service_name: "Test Printing B", + service_type: "3D Printing", + end_point: "URL", + usage: "C1(3), C3(4)", + status: "DRAFT, REGISTERED", + action: "Delete, Create", }, -] +]; export const Client2ProducerTableConfig = [ { key: "service_name", - label: "Service name" + label: "Service name", }, { key: "service_type", - label: "Service Type" + label: "Service Type", }, { key: "end_point", - label: "End Point" + label: "End Point", }, { key: "usage", - label: "Usage" + label: "Usage", }, { key: "status", - label: "Status" + label: "Status", }, { key: "action", - label: "Action" - } -] + label: "Action", + }, +]; -- 2.51.0 From 78144fde030bce8c9ca4781bc25eba34ce84fe0a Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Fri, 24 Nov 2023 19:06:38 +0100 Subject: [PATCH 32/49] [Homepage] Table View - implemented home view table and added checkbox component --- pkgs/ui/src/app/home/page.tsx | 3 +- pkgs/ui/src/components/table/index.tsx | 98 ++++++++++++++------------ pkgs/ui/src/mock/home/index.ts | 47 ++++++++++++ 3 files changed, 100 insertions(+), 48 deletions(-) create mode 100644 pkgs/ui/src/mock/home/index.ts diff --git a/pkgs/ui/src/app/home/page.tsx b/pkgs/ui/src/app/home/page.tsx index bfcddf8..f60c2ff 100644 --- a/pkgs/ui/src/app/home/page.tsx +++ b/pkgs/ui/src/app/home/page.tsx @@ -3,6 +3,7 @@ import { NoDataOverlay } from "@/components/noDataOverlay"; import SummaryDetails from "@/components/summary_card"; import CustomTable from "@/components/table"; +import {HomeDummyData, HomeTableConfig} from "@/mock/home"; export default function Home() { return ( @@ -15,7 +16,7 @@ export default function Home() {

Home View Table

- +
diff --git a/pkgs/ui/src/components/table/index.tsx b/pkgs/ui/src/components/table/index.tsx index cbfec7e..28ac3d8 100644 --- a/pkgs/ui/src/components/table/index.tsx +++ b/pkgs/ui/src/components/table/index.tsx @@ -6,60 +6,64 @@ import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import Paper from "@mui/material/Paper"; -import { NoDataOverlay } from "@/components/noDataOverlay"; -import { StyledTableCell, StyledTableRow } from "./style"; -import { ICustomTable, CustomTableConfiguration } from "@/types"; +import {NoDataOverlay} from "@/components/noDataOverlay"; +import {StyledTableCell, StyledTableRow} from "./style"; +import {ICustomTable, CustomTableConfiguration} from "@/types"; +import {Checkbox} from "@mui/material"; -const CustomTable = ({ configuration, data }: ICustomTable) => { - // display empty icon in case there is no data - if (!data || data.length === 0) - return ; +const CustomTable = ({configuration, data}: ICustomTable) => { + // display empty icon in case there is no data + if (!data || data.length === 0) + return ; - const renderTableCell = ( - value: any, - cellKey: string, - render?: (param: any) => void | undefined, - ) => { - let renderedValue = value; + const renderTableCell = ( + value: any, + cellKey: string, + render?: (param: any) => void | undefined, + ) => { + let renderedValue = value; - // cover use case if the data is an array - if (Array.isArray(value)) renderedValue = value.join(", "); + // cover use case if the data is an array + if (Array.isArray(value)) renderedValue = value.join(", "); - // cover use case if we want to render a component - if (render) renderedValue = render(value); + // cover use case if the data is an boolean + if (typeof value === "boolean") renderedValue = ; + + // cover use case if we want to render a component + if (render) renderedValue = render(value); + + return ( + + {renderedValue} + + ); + }; return ( - - {renderedValue} - + + + + + {configuration.map((header: CustomTableConfiguration) => ( + {header.label} + ))} + + + + {data.map((data: any, rowIndex: number) => ( + + {configuration.map((column: CustomTableConfiguration) => { + const cellValue: any = data[column.key]; + const cellKey = column.key; + const renderComponent = column?.render; + return renderTableCell(cellValue, cellKey, renderComponent); + })} + + ))} + +
+
); - }; - - return ( - - - - - {configuration.map((header: CustomTableConfiguration) => ( - {header.label} - ))} - - - - {data.map((data: any, rowIndex: number) => ( - - {configuration.map((column: CustomTableConfiguration) => { - const cellValue: any = data[column.key]; - const cellKey = column.key; - const renderComponent = column?.render; - return renderTableCell(cellValue, cellKey, renderComponent); - })} - - ))} - -
-
- ); }; export default CustomTable; diff --git a/pkgs/ui/src/mock/home/index.ts b/pkgs/ui/src/mock/home/index.ts new file mode 100644 index 0000000..b92be36 --- /dev/null +++ b/pkgs/ui/src/mock/home/index.ts @@ -0,0 +1,47 @@ +// HOME - Table Data + +export const HomeDummyData = [ + { + entity_name: "C1", + entity_DID: "did:sov:test:1234", + network: "Carlo's Home Network", + ip_address: "127.0.0.1", + roles: "service repository, service consumer, DLG", + visible: true + }, + { + entity_name: "C2", + entity_DID: "did:sov:test:4567", + network: "Steve's Home Network", + ip_address: "127.0.0.1", + roles: "service repository, service consumer, DLG", + visible: false + } +]; + +export const HomeTableConfig = [ + { + key: "entity_name", + label: "Entity name", + }, + { + key: "entity_DID", + label: "Entity DID", + }, + { + key: "network", + label: "Network", + }, + { + key: "ip_address", + label: "IP address", + }, + { + key: "roles", + label: "Roles", + }, + { + key: "visible", + label: "Visible", + }, +]; \ No newline at end of file -- 2.51.0 From f3cf07df8ece7bc89ead2ede32c41d4a4199d54b Mon Sep 17 00:00:00 2001 From: "Arslan, Erdem" Date: Sat, 25 Nov 2023 01:43:31 +0100 Subject: [PATCH 33/49] fix linting --- pkgs/ui/src/app/home/page.tsx | 2 +- pkgs/ui/src/components/table/index.tsx | 101 +++++++++++++------------ pkgs/ui/src/mock/home/index.ts | 82 ++++++++++---------- 3 files changed, 93 insertions(+), 92 deletions(-) diff --git a/pkgs/ui/src/app/home/page.tsx b/pkgs/ui/src/app/home/page.tsx index f60c2ff..37e51de 100644 --- a/pkgs/ui/src/app/home/page.tsx +++ b/pkgs/ui/src/app/home/page.tsx @@ -3,7 +3,7 @@ import { NoDataOverlay } from "@/components/noDataOverlay"; import SummaryDetails from "@/components/summary_card"; import CustomTable from "@/components/table"; -import {HomeDummyData, HomeTableConfig} from "@/mock/home"; +import { HomeDummyData, HomeTableConfig } from "@/mock/home"; export default function Home() { return ( diff --git a/pkgs/ui/src/components/table/index.tsx b/pkgs/ui/src/components/table/index.tsx index 28ac3d8..36714df 100644 --- a/pkgs/ui/src/components/table/index.tsx +++ b/pkgs/ui/src/components/table/index.tsx @@ -6,64 +6,65 @@ import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import Paper from "@mui/material/Paper"; -import {NoDataOverlay} from "@/components/noDataOverlay"; -import {StyledTableCell, StyledTableRow} from "./style"; -import {ICustomTable, CustomTableConfiguration} from "@/types"; -import {Checkbox} from "@mui/material"; +import { NoDataOverlay } from "@/components/noDataOverlay"; +import { StyledTableCell, StyledTableRow } from "./style"; +import { ICustomTable, CustomTableConfiguration } from "@/types"; +import { Checkbox } from "@mui/material"; -const CustomTable = ({configuration, data}: ICustomTable) => { - // display empty icon in case there is no data - if (!data || data.length === 0) - return ; +const CustomTable = ({ configuration, data }: ICustomTable) => { + // display empty icon in case there is no data + if (!data || data.length === 0) + return ; - const renderTableCell = ( - value: any, - cellKey: string, - render?: (param: any) => void | undefined, - ) => { - let renderedValue = value; + const renderTableCell = ( + value: any, + cellKey: string, + render?: (param: any) => void | undefined, + ) => { + let renderedValue = value; - // cover use case if the data is an array - if (Array.isArray(value)) renderedValue = value.join(", "); + // cover use case if the data is an array + if (Array.isArray(value)) renderedValue = value.join(", "); - // cover use case if the data is an boolean - if (typeof value === "boolean") renderedValue = ; + // cover use case if the data is an boolean + if (typeof value === "boolean") + renderedValue = ; - // cover use case if we want to render a component - if (render) renderedValue = render(value); - - return ( - - {renderedValue} - - ); - }; + // cover use case if we want to render a component + if (render) renderedValue = render(value); return ( - - - - - {configuration.map((header: CustomTableConfiguration) => ( - {header.label} - ))} - - - - {data.map((data: any, rowIndex: number) => ( - - {configuration.map((column: CustomTableConfiguration) => { - const cellValue: any = data[column.key]; - const cellKey = column.key; - const renderComponent = column?.render; - return renderTableCell(cellValue, cellKey, renderComponent); - })} - - ))} - -
-
+ + {renderedValue} + ); + }; + + return ( + + + + + {configuration.map((header: CustomTableConfiguration) => ( + {header.label} + ))} + + + + {data.map((data: any, rowIndex: number) => ( + + {configuration.map((column: CustomTableConfiguration) => { + const cellValue: any = data[column.key]; + const cellKey = column.key; + const renderComponent = column?.render; + return renderTableCell(cellValue, cellKey, renderComponent); + })} + + ))} + +
+
+ ); }; export default CustomTable; diff --git a/pkgs/ui/src/mock/home/index.ts b/pkgs/ui/src/mock/home/index.ts index b92be36..ccff693 100644 --- a/pkgs/ui/src/mock/home/index.ts +++ b/pkgs/ui/src/mock/home/index.ts @@ -1,47 +1,47 @@ // HOME - Table Data export const HomeDummyData = [ - { - entity_name: "C1", - entity_DID: "did:sov:test:1234", - network: "Carlo's Home Network", - ip_address: "127.0.0.1", - roles: "service repository, service consumer, DLG", - visible: true - }, - { - entity_name: "C2", - entity_DID: "did:sov:test:4567", - network: "Steve's Home Network", - ip_address: "127.0.0.1", - roles: "service repository, service consumer, DLG", - visible: false - } + { + entity_name: "C1", + entity_DID: "did:sov:test:1234", + network: "Carlo's Home Network", + ip_address: "127.0.0.1", + roles: "service repository, service consumer, DLG", + visible: true, + }, + { + entity_name: "C2", + entity_DID: "did:sov:test:4567", + network: "Steve's Home Network", + ip_address: "127.0.0.1", + roles: "service repository, service consumer, DLG", + visible: false, + }, ]; export const HomeTableConfig = [ - { - key: "entity_name", - label: "Entity name", - }, - { - key: "entity_DID", - label: "Entity DID", - }, - { - key: "network", - label: "Network", - }, - { - key: "ip_address", - label: "IP address", - }, - { - key: "roles", - label: "Roles", - }, - { - key: "visible", - label: "Visible", - }, -]; \ No newline at end of file + { + key: "entity_name", + label: "Entity name", + }, + { + key: "entity_DID", + label: "Entity DID", + }, + { + key: "network", + label: "Network", + }, + { + key: "ip_address", + label: "IP address", + }, + { + key: "roles", + label: "Roles", + }, + { + key: "visible", + label: "Visible", + }, +]; -- 2.51.0 From b347e0f3f2844c91bd808a0a46cbb7535c7c876e Mon Sep 17 00:00:00 2001 From: ui-asset-bot Date: Sat, 25 Nov 2023 23:35:24 +0000 Subject: [PATCH 34/49] update ui-assets.nix --- pkgs/ui/nix/ui-assets.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/ui/nix/ui-assets.nix b/pkgs/ui/nix/ui-assets.nix index f39033d..9e81835 100644 --- a/pkgs/ui/nix/ui-assets.nix +++ b/pkgs/ui/nix/ui-assets.nix @@ -1,5 +1,5 @@ { fetchzip }: fetchzip { - url = "https://gitea.gchq.icu/api/packages/IoSL/generic/IoSL-service-aware-frontend/032md4b8k45b7fli3i0jwqzcmwk4s2kwbshk0b2lhcklckqdmjdr/assets.tar.gz"; - sha256 = "032md4b8k45b7fli3i0jwqzcmwk4s2kwbshk0b2lhcklckqdmjdr"; + url = "https://gitea.gchq.icu/api/packages/IoSL/generic/IoSL-service-aware-frontend/16glc9nkcqsalf5jwcwcsv1nx65cqwrqr95n1ghmb365nxi57bb4/assets.tar.gz"; + sha256 = "16glc9nkcqsalf5jwcwcsv1nx65cqwrqr95n1ghmb365nxi57bb4"; } -- 2.51.0 From 811a6f107ff968ad10860cc2fbd34741efcd7a90 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Mon, 20 Nov 2023 19:45:47 +0100 Subject: [PATCH 35/49] Added broadcaster dependency --- flake.lock | 35 +++++--- flake.nix | 1 + pkgs/clan-cli/.vscode/settings.json | 2 +- pkgs/clan-cli/clan_cli/webui/app.py | 6 +- .../clan_cli/webui/routers/socket_manager.py | 79 +++++++++++++++++++ pkgs/clan-cli/default.nix | 4 + pkgs/clan-cli/flake-module.nix | 4 +- pkgs/nix-unit/default.nix | 48 ++--------- 8 files changed, 125 insertions(+), 54 deletions(-) create mode 100644 pkgs/clan-cli/clan_cli/webui/routers/socket_manager.py diff --git a/flake.lock b/flake.lock index add9b0c..314e233 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1696343447, - "narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=", + "lastModified": 1698882062, + "narHash": "sha256-HkhafUayIqxXyHH1X8d9RDl1M2CkFgZLjKD3MzabiEo=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4", + "rev": "8c9fa2545007b49a5db5f650ae91f227672c3877", "type": "github" }, "original": { @@ -42,11 +42,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1697059129, - "narHash": "sha256-9NJcFF9CEYPvHJ5ckE8kvINvI84SZZ87PvqMbH6pro0=", + "lastModified": 1700390070, + "narHash": "sha256-de9KYi8rSJpqvBfNwscWdalIJXPo8NjdIZcEJum1mH0=", "owner": "nixos", "repo": "nixpkgs", - "rev": "5e4c2ada4fcd54b99d56d7bd62f384511a7e2593", + "rev": "e4ad989506ec7d71f7302cc3067abd82730a4beb", "type": "github" }, "original": { @@ -56,11 +56,28 @@ "type": "github" } }, + "nixpkgs-for-iosl": { + "locked": { + "lastModified": 1700505490, + "narHash": "sha256-MLF5dkExensQoByZCmsR/kdcwZoaY/j6/ctSvmQHBJc=", + "owner": "Luis-Hebendanz", + "repo": "nixpkgs", + "rev": "5f9d94794badee6fcb3230ccea75628a802baeab", + "type": "github" + }, + "original": { + "owner": "Luis-Hebendanz", + "ref": "iosl", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "flake-parts": "flake-parts", "floco": "floco", "nixpkgs": "nixpkgs", + "nixpkgs-for-iosl": "nixpkgs-for-iosl", "treefmt-nix": "treefmt-nix" } }, @@ -71,11 +88,11 @@ ] }, "locked": { - "lastModified": 1695822946, - "narHash": "sha256-IQU3fYo0H+oGlqX5YrgZU3VRhbt2Oqe6KmslQKUO4II=", + "lastModified": 1699786194, + "narHash": "sha256-3h3EH1FXQkIeAuzaWB+nK0XK54uSD46pp+dMD3gAcB4=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "720bd006d855b08e60664e4683ccddb7a9ff614a", + "rev": "e82f32aa7f06bbbd56d7b12186d555223dc399d1", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 9e1a4e3..6c73ad1 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,7 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; floco.url = "github:aakropotkin/floco"; floco.inputs.nixpkgs.follows = "nixpkgs"; + nixpkgs-for-iosl.url = "github:Luis-Hebendanz/nixpkgs/iosl"; flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; treefmt-nix.url = "github:numtide/treefmt-nix"; diff --git a/pkgs/clan-cli/.vscode/settings.json b/pkgs/clan-cli/.vscode/settings.json index e5c2632..0c7964c 100644 --- a/pkgs/clan-cli/.vscode/settings.json +++ b/pkgs/clan-cli/.vscode/settings.json @@ -18,5 +18,5 @@ "python.linting.mypyPath": "mypy", "python.linting.mypyEnabled": true, "python.linting.enabled": true, - "python.defaultInterpreterPath": "python" + "python.defaultInterpreterPath": "/nix/store/k34qdl5397mwg3k00jsl3xcynij7n0z9-python3-3.11.6-env/bin/python" } \ No newline at end of file diff --git a/pkgs/clan-cli/clan_cli/webui/app.py b/pkgs/clan-cli/clan_cli/webui/app.py index 8ef7b04..62bc017 100644 --- a/pkgs/clan-cli/clan_cli/webui/app.py +++ b/pkgs/clan-cli/clan_cli/webui/app.py @@ -8,7 +8,7 @@ from fastapi.staticfiles import StaticFiles from ..errors import ClanError from .assets import asset_path from .error_handlers import clan_error_handler -from .routers import health, root, sql_connect # sql router hinzufügen +from .routers import health, root, sql_connect, socket_manager # sql router hinzufügen #import for sql from fastapi import Depends, FastAPI, HTTPException @@ -42,9 +42,11 @@ def setup_app() -> FastAPI: #sql methodes app.include_router(sql_connect.router) + app.include_router(socket_manager.router) + # Needs to be last in register. Because of wildcard route app.include_router(root.router) - app.add_exception_handler(ClanError, clan_error_handler) + app.add_exception_handler(ClanError, clan_error_handler) # type: ignore app.mount("/static", StaticFiles(directory=asset_path()), name="static") diff --git a/pkgs/clan-cli/clan_cli/webui/routers/socket_manager.py b/pkgs/clan-cli/clan_cli/webui/routers/socket_manager.py new file mode 100644 index 0000000..cdfa46e --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/routers/socket_manager.py @@ -0,0 +1,79 @@ +from fastapi import FastAPI, WebSocket, WebSocketDisconnect +from fastapi.responses import HTMLResponse +from fastapi import APIRouter, Response + +router = APIRouter() + +html = """ + + + + Chat + + +

WebSocket Chat

+

Your ID:

+
+ + +
+
    +
+ + + +""" + +class ConnectionManager: + def __init__(self) -> None: + self.active_connections: list[WebSocket] = [] + + async def connect(self, websocket: WebSocket) -> None: + await websocket.accept() + self.active_connections.append(websocket) + + def disconnect(self, websocket: WebSocket) -> None: + self.active_connections.remove(websocket) + + async def send_personal_message(self, message: str, websocket: WebSocket) -> None: + await websocket.send_text(message) + + async def broadcast(self, message: str) -> None: + for connection in self.active_connections: + await connection.send_text(message) + + +manager = ConnectionManager() + +@router.get("/ws_example") +async def get() -> HTMLResponse: + return HTMLResponse(html) + +@router.websocket("/ws/{client_id}") +async def websocket_endpoint(websocket: WebSocket, client_id: int) -> None: + await manager.connect(websocket) + try: + while True: + data = await websocket.receive_text() + await manager.send_personal_message(f"You wrote: {data}", websocket) + await manager.broadcast(f"Client #{client_id} says: {data}") + except WebSocketDisconnect: + manager.disconnect(websocket) + await manager.broadcast(f"Client #{client_id} left the chat") \ No newline at end of file diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index a9f4b66..42347b6 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -36,6 +36,8 @@ , mypy , sqlalchemy , websockets +, deal +, broadcaster }: let @@ -45,6 +47,8 @@ let uvicorn # optional dependencies: if not enabled, webui subcommand will not work sqlalchemy websockets + broadcaster + deal ]; pytestDependencies = runtimeDependencies ++ dependencies ++ [ diff --git a/pkgs/clan-cli/flake-module.nix b/pkgs/clan-cli/flake-module.nix index 2f912d0..5e3719c 100644 --- a/pkgs/clan-cli/flake-module.nix +++ b/pkgs/clan-cli/flake-module.nix @@ -1,6 +1,6 @@ { inputs, ... }: { - perSystem = { self', pkgs, ... }: { + perSystem = { self', pkgs, system, ... }: { devShells.clan-cli = pkgs.callPackage ./shell.nix { inherit (self'.packages) clan-cli ui-assets nix-unit; }; @@ -8,6 +8,8 @@ clan-cli = pkgs.python3.pkgs.callPackage ./default.nix { inherit (self'.packages) ui-assets; inherit (inputs) nixpkgs; + inherit (inputs.nixpkgs-for-iosl.legacyPackages.${system}.python3Packages) deal; + inherit (inputs.nixpkgs-for-iosl.legacyPackages.${system}.python3Packages) broadcaster; }; inherit (self'.packages.clan-cli) clan-openapi; default = self'.packages.clan-cli; diff --git a/pkgs/nix-unit/default.nix b/pkgs/nix-unit/default.nix index 507ed57..fe917f0 100644 --- a/pkgs/nix-unit/default.nix +++ b/pkgs/nix-unit/default.nix @@ -1,43 +1,9 @@ -{ stdenv -, lib -, nixVersions -, fetchFromGitHub -, nlohmann_json -, boost -, meson -, pkg-config -, ninja -, cmake -, clang-tools -}: - -stdenv.mkDerivation { - pname = "nix-unit"; - version = "0.1"; - src = fetchFromGitHub { - owner = "adisbladis"; - repo = "nix-unit"; - rev = "3ed2378bddad85257fc508a291408f9ed9673d01"; - sha256 = "sha256-HvMq0TJGYSx37zHm4j2d+JUZx4/6X7xKEt/0DeCiwjQ="; +{ callPackage }: +let + nix-unit-src = builtins.fetchGit { + url = "https://github.com/adisbladis/nix-unit"; + rev = "7e2ee1c70f930b9b65b9fc33c3f3eca0dfae00d1"; }; - buildInputs = [ - nlohmann_json - nixVersions.stable - boost - ]; - nativeBuildInputs = [ - meson - pkg-config - ninja - # nlohmann_json can be only discovered via cmake files - cmake - ] ++ (lib.optional stdenv.cc.isClang [ clang-tools ]); +in +callPackage nix-unit-src { } - meta = { - description = "Nix unit test runner"; - homepage = "https://github.com/adisbladis/nix-unit"; - license = lib.licenses.gpl3; - maintainers = with lib.maintainers; [ adisbladis ]; - platforms = lib.platforms.unix; - }; -} -- 2.51.0 From 35506e6793a76ed7f667a3f54d279299a139c082 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Mon, 20 Nov 2023 22:58:01 +0100 Subject: [PATCH 36/49] Working broadcasting library --- flake.lock | 6 +- .../clan_cli/{types.py => clan_types.py} | 0 pkgs/clan-cli/clan_cli/webui/app.py | 16 +- .../clan_cli/webui/routers/messenger.html | 202 ++++++++++++++++++ .../clan_cli/webui/routers/socket_manager2.py | 54 +++++ 5 files changed, 272 insertions(+), 6 deletions(-) rename pkgs/clan-cli/clan_cli/{types.py => clan_types.py} (100%) create mode 100644 pkgs/clan-cli/clan_cli/webui/routers/messenger.html create mode 100644 pkgs/clan-cli/clan_cli/webui/routers/socket_manager2.py diff --git a/flake.lock b/flake.lock index 314e233..5234a63 100644 --- a/flake.lock +++ b/flake.lock @@ -58,11 +58,11 @@ }, "nixpkgs-for-iosl": { "locked": { - "lastModified": 1700505490, - "narHash": "sha256-MLF5dkExensQoByZCmsR/kdcwZoaY/j6/ctSvmQHBJc=", + "lastModified": 1700515317, + "narHash": "sha256-DSnKT3glZCKE0/Rc6ainSJUbUGC248HNKVRSbo9kxkM=", "owner": "Luis-Hebendanz", "repo": "nixpkgs", - "rev": "5f9d94794badee6fcb3230ccea75628a802baeab", + "rev": "bcd6be7a5ab22c94c775945fb16a61b5867f15d2", "type": "github" }, "original": { diff --git a/pkgs/clan-cli/clan_cli/types.py b/pkgs/clan-cli/clan_cli/clan_types.py similarity index 100% rename from pkgs/clan-cli/clan_cli/types.py rename to pkgs/clan-cli/clan_cli/clan_types.py diff --git a/pkgs/clan-cli/clan_cli/webui/app.py b/pkgs/clan-cli/clan_cli/webui/app.py index 62bc017..7d2a7b2 100644 --- a/pkgs/clan-cli/clan_cli/webui/app.py +++ b/pkgs/clan-cli/clan_cli/webui/app.py @@ -4,11 +4,13 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.routing import APIRoute from fastapi.staticfiles import StaticFiles +from contextlib import asynccontextmanager +from typing import Any from ..errors import ClanError from .assets import asset_path from .error_handlers import clan_error_handler -from .routers import health, root, sql_connect, socket_manager # sql router hinzufügen +from .routers import health, root, sql_connect, socket_manager2 # sql router hinzufügen #import for sql from fastapi import Depends, FastAPI, HTTPException @@ -24,12 +26,19 @@ origins = [ log = logging.getLogger(__name__) +@asynccontextmanager +async def lifespan(app: FastAPI) -> Any: + await socket_manager2.brd.connect() + yield + await socket_manager2.brd.disconnect() + + def setup_app() -> FastAPI: # bind sql engine sql_models.Base.metadata.drop_all(engine) sql_models.Base.metadata.create_all(bind=engine) - - app = FastAPI() + + app = FastAPI(lifespan=lifespan) app.add_middleware( CORSMiddleware, allow_origins=origins, @@ -43,6 +52,7 @@ def setup_app() -> FastAPI: app.include_router(sql_connect.router) app.include_router(socket_manager.router) + app.include_router(socket_manager2.router) # Needs to be last in register. Because of wildcard route app.include_router(root.router) diff --git a/pkgs/clan-cli/clan_cli/webui/routers/messenger.html b/pkgs/clan-cli/clan_cli/webui/routers/messenger.html new file mode 100644 index 0000000..a24b097 --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/routers/messenger.html @@ -0,0 +1,202 @@ + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/pkgs/clan-cli/clan_cli/webui/routers/socket_manager2.py b/pkgs/clan-cli/clan_cli/webui/routers/socket_manager2.py new file mode 100644 index 0000000..e8bf1ca --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/routers/socket_manager2.py @@ -0,0 +1,54 @@ +# Requires: `starlette`, `uvicorn`, `jinja2` +# Run with `uvicorn example:app` +import anyio +from broadcaster import Broadcast +from fastapi import FastAPI, WebSocket, WebSocketDisconnect +from fastapi.responses import HTMLResponse +from fastapi import APIRouter, Response +import os +import logging +import asyncio + +log = logging.getLogger(__name__) +router = APIRouter() + + +brd = Broadcast("memory://") + + +@router.get("/ws2_example") +async def get() -> HTMLResponse: + + html = open(f"{os.getcwd()}/webui/routers/messenger.html").read() + return HTMLResponse(html) + +@router.websocket("/ws2") +async def chatroom_ws(websocket: WebSocket) -> None: + await websocket.accept() + + + async with anyio.create_task_group() as task_group: + # run until first is complete + async def run_chatroom_ws_receiver() -> None: + await chatroom_ws_receiver(websocket=websocket) + task_group.cancel_scope.cancel() + + task_group.start_soon(run_chatroom_ws_receiver) + log.warning("Started chatroom_ws_sender") + + await chatroom_ws_sender(websocket) + + +async def chatroom_ws_receiver(websocket: WebSocket) -> None: + async for message in websocket.iter_text(): + log.warning(f"Received message: {message}") + await brd.publish(channel="chatroom", message=message) + + +async def chatroom_ws_sender(websocket: WebSocket) -> None: + async with brd.subscribe(channel="chatroom") as subscriber: + log.warning("====>Subscribed to chatroom channel") + async for event in subscriber: + log.warning(f"Sending message: {event.message}") + await websocket.send_text(event.message) + -- 2.51.0 From 3b494dd83a89aedb6e3bc11f0cc40bdfd6e56da6 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sun, 26 Nov 2023 12:35:27 +0100 Subject: [PATCH 37/49] Removed old socket manager --- .../clan_cli/webui/routers/socket_manager.py | 79 ------------------- 1 file changed, 79 deletions(-) delete mode 100644 pkgs/clan-cli/clan_cli/webui/routers/socket_manager.py diff --git a/pkgs/clan-cli/clan_cli/webui/routers/socket_manager.py b/pkgs/clan-cli/clan_cli/webui/routers/socket_manager.py deleted file mode 100644 index cdfa46e..0000000 --- a/pkgs/clan-cli/clan_cli/webui/routers/socket_manager.py +++ /dev/null @@ -1,79 +0,0 @@ -from fastapi import FastAPI, WebSocket, WebSocketDisconnect -from fastapi.responses import HTMLResponse -from fastapi import APIRouter, Response - -router = APIRouter() - -html = """ - - - - Chat - - -

WebSocket Chat

-

Your ID:

-
- - -
-
    -
- - - -""" - -class ConnectionManager: - def __init__(self) -> None: - self.active_connections: list[WebSocket] = [] - - async def connect(self, websocket: WebSocket) -> None: - await websocket.accept() - self.active_connections.append(websocket) - - def disconnect(self, websocket: WebSocket) -> None: - self.active_connections.remove(websocket) - - async def send_personal_message(self, message: str, websocket: WebSocket) -> None: - await websocket.send_text(message) - - async def broadcast(self, message: str) -> None: - for connection in self.active_connections: - await connection.send_text(message) - - -manager = ConnectionManager() - -@router.get("/ws_example") -async def get() -> HTMLResponse: - return HTMLResponse(html) - -@router.websocket("/ws/{client_id}") -async def websocket_endpoint(websocket: WebSocket, client_id: int) -> None: - await manager.connect(websocket) - try: - while True: - data = await websocket.receive_text() - await manager.send_personal_message(f"You wrote: {data}", websocket) - await manager.broadcast(f"Client #{client_id} says: {data}") - except WebSocketDisconnect: - manager.disconnect(websocket) - await manager.broadcast(f"Client #{client_id} left the chat") \ No newline at end of file -- 2.51.0 From e007d989859df532e83b899be741b6c57b62a799 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sun, 26 Nov 2023 12:47:16 +0100 Subject: [PATCH 38/49] nix fmt --- pkgs/clan-cli/clan_cli/dirs.py | 2 +- pkgs/clan-cli/clan_cli/webui/api_inputs.py | 2 +- pkgs/clan-cli/clan_cli/webui/app.py | 7 +- .../clan_cli/webui/routers/messenger.html | 389 +++++++++--------- .../clan_cli/webui/routers/socket_manager2.py | 20 +- pkgs/clan-cli/pyproject.toml | 5 + 6 files changed, 215 insertions(+), 210 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index 5f11577..ce5ff14 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -4,8 +4,8 @@ import sys from pathlib import Path from typing import Optional +from .clan_types import FlakeName from .errors import ClanError -from .types import FlakeName log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_cli/webui/api_inputs.py b/pkgs/clan-cli/clan_cli/webui/api_inputs.py index 70539e7..1148c7b 100644 --- a/pkgs/clan-cli/clan_cli/webui/api_inputs.py +++ b/pkgs/clan-cli/clan_cli/webui/api_inputs.py @@ -5,8 +5,8 @@ from typing import Any from pydantic import AnyUrl, BaseModel, validator from pydantic.tools import parse_obj_as +from ..clan_types import validate_path from ..dirs import clan_data_dir, clan_flakes_dir -from ..types import validate_path DEFAULT_URL = parse_obj_as(AnyUrl, "http://localhost:8000") diff --git a/pkgs/clan-cli/clan_cli/webui/app.py b/pkgs/clan-cli/clan_cli/webui/app.py index 7d2a7b2..0d463bf 100644 --- a/pkgs/clan-cli/clan_cli/webui/app.py +++ b/pkgs/clan-cli/clan_cli/webui/app.py @@ -1,11 +1,11 @@ import logging +from contextlib import asynccontextmanager +from typing import Any from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.routing import APIRoute from fastapi.staticfiles import StaticFiles -from contextlib import asynccontextmanager -from typing import Any from ..errors import ClanError from .assets import asset_path @@ -51,12 +51,11 @@ def setup_app() -> FastAPI: #sql methodes app.include_router(sql_connect.router) - app.include_router(socket_manager.router) app.include_router(socket_manager2.router) # Needs to be last in register. Because of wildcard route app.include_router(root.router) - app.add_exception_handler(ClanError, clan_error_handler) # type: ignore + app.add_exception_handler(ClanError, clan_error_handler) # type: ignore app.mount("/static", StaticFiles(directory=asset_path()), name="static") diff --git a/pkgs/clan-cli/clan_cli/webui/routers/messenger.html b/pkgs/clan-cli/clan_cli/webui/routers/messenger.html index a24b097..cdc6618 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/messenger.html +++ b/pkgs/clan-cli/clan_cli/webui/routers/messenger.html @@ -1,202 +1,205 @@ - + - - - + + - - - - -