Skip to content

Commit 29b8597

Browse files
committed
Add handling for un-auth users
1 parent 513f7e0 commit 29b8597

File tree

7 files changed

+106
-23
lines changed

7 files changed

+106
-23
lines changed

dds_cli/data_lister.py

+14
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ def __init__(
7474

7575
# Public methods ########################### Public methods #
7676

77+
78+
def gui_list_projects(self):
79+
"""Get a list of project(s) the user is involved in."""
80+
response, _ = dds_cli.utils.perform_request(
81+
DDSEndpoint.LIST_PROJ,
82+
headers=self.token,
83+
method="get",
84+
json={"usage": self.show_usage, "show_all": False},
85+
error_message="Failed to get list of projects",
86+
timeout=DDSEndpoint.TIMEOUT,
87+
)
88+
89+
return response
90+
7791
def list_projects(self, sort_by="Updated", show_all: bool = False):
7892
"""Get a list of project(s) the user is involved in."""
7993
# Get projects from API

dds_cli/gui_poc/app.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from dds_cli.gui_poc.data import Data
1010
from dds_cli.gui_poc.home import HomeScreen
1111
from dds_cli.gui_poc.auth import AuthLogin, AuthLogout, AuthStatus
12+
from dds_cli.gui_poc.project import Project
1213
from dds_cli.gui_poc.user import User
1314
from dds_cli.gui_poc.utils import DDSModal
1415

@@ -50,6 +51,7 @@ def __init__(self, token_path: str):
5051
Binding("o", "logout", "Logout", tooltip="Logout from DDS."),
5152
Binding("u", "user", "User", tooltip="Show user info."),
5253
Binding("d", "data", "Data", tooltip="Show data info."),
54+
Binding("p", "project", "Project", tooltip="Show project info."),
5355
]
5456

5557
def compose(self) -> ComposeResult:
@@ -58,9 +60,11 @@ def compose(self) -> ComposeResult:
5860
with Container(id="home"):
5961
yield HomeScreen()
6062
with Container(id="user"):
61-
yield User()
63+
yield User(self.token_path)
6264
with Container(id="data"):
6365
yield Data()
66+
with Container(id="project"):
67+
yield Project()
6468
yield Footer()
6569

6670
def action_token(self) -> None:
@@ -81,6 +85,9 @@ def action_home(self) -> None:
8185
def action_data(self) -> None:
8286
self.query_one(ContentSwitcher).current = "data"
8387

88+
def action_project(self) -> None:
89+
self.query_one(ContentSwitcher).current = "project"
90+
8491
def on_mount(self) -> None:
8592
self.register_theme(theme)
8693
self.theme = "custom"

dds_cli/gui_poc/app.tcss

+14-10
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,23 @@ AuthLogout {
115115

116116
/* Button */
117117

118-
Button{
119-
border: none;
120-
height: 3;
121-
padding: 0 2 0 2; /* Set padding for centered content without default border*/
118+
# Button{
119+
# border: none;
120+
# height: 3;
121+
# padding: 0 2 0 2; /* Set padding for centered content without default border*/
122+
# }
123+
124+
Button {
125+
padding: 0 2 0 2;
122126
}
123127

124-
Button:hover{
125-
border: none;
126-
}
128+
# Button:hover{
129+
# border: none;
130+
# }
127131

128-
Button:focus{
129-
border: none;
130-
}
132+
# Button:focus{
133+
# border: none;
134+
# }
131135

132136
/* Input */
133137

dds_cli/gui_poc/docs/difference.jpeg

611 KB
Loading

dds_cli/gui_poc/docs/poc_ux_ui.md

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ variables: dict[str, str] = field(default_factory=dict)
6767

6868
The textual styling is as said limited in comparison to the full flexibility of CSS styles applications. However, the limited custumization options ensures uniform styling accross the application, both in basic and custom widgets.
6969

70+
Textual is recomanded to not run in the default macos terminal, as it will look ugly. It will still function properly though.
71+
72+
**Question**: Design the application as usual and recommend users to use a different terminal, or design the gui with the macos termial in mind? What is the most commonly used terminal.
73+
74+
![Image](difference.jpeg)
75+
76+
The difference between iTerm2 terminal (left) and macos default terminal (right). The borders and colors are off in the macos terminal.
77+
7078
### Text
7179

7280
There is no support for different fontsizes in textual.

dds_cli/gui_poc/project.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from textual import events
2+
from textual.app import ComposeResult
3+
from textual.containers import Container, VerticalScroll
4+
from textual.widget import Widget
5+
from textual.widgets import Button, ContentSwitcher, DataTable, Label, LoadingIndicator
6+
7+
from dds_cli.gui_poc.utils import DDSSidebar
8+
from dds_cli.data_lister import DataLister
9+
10+
11+
class ProjectList(Widget):
12+
def compose(self) -> ComposeResult:
13+
with VerticalScroll(id="project-list"):
14+
yield Button("Get project list", id="get-project-list")
15+
yield Label("Project list", id="project-list-label")
16+
17+
18+
def on_button_pressed(self, event: events.Click) -> None:
19+
if event.button.id == "get-project-list":
20+
self.get_project_list()
21+
22+
async def get_project_list(self):
23+
#self.query_one("#project-list").mount(LoadingIndicator())
24+
#project_list = await DataLister().gui_list_projects()
25+
#self.query_one(LoadingIndicator).remove()
26+
self.query_one("#project-list-label").update("done")
27+
return None
28+
29+
class Project(Widget):
30+
def __init__(self):
31+
super().__init__()
32+
33+
def compose(self) -> ComposeResult:
34+
yield DDSSidebar([
35+
"list",
36+
"info"
37+
], title="Project")
38+
with ContentSwitcher(initial="list", id="project"):
39+
with Container(id="list"):
40+
yield ProjectList()

dds_cli/gui_poc/user.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from textual.app import ComposeResult
33
from textual.containers import Container
44
from textual.widget import Widget
5-
from textual.widgets import ContentSwitcher, DataTable
5+
from textual.widgets import ContentSwitcher, DataTable, Static
66
from dds_cli.account_manager import AccountManager
77
from dds_cli.gui_poc.utils import DDSSidebar
88

@@ -39,36 +39,46 @@
3939
"""
4040

4141
class UserInfo(Widget):
42-
def __init__(self, user_info: dict):
42+
def __init__(self, token_path: str):
4343
super().__init__()
44-
self.user_info = user_info
44+
self.user = None
45+
self.token_path = token_path
46+
self.user_info = None
4547

4648
def compose(self) -> ComposeResult:
4749
with Container(id="user-info"):
4850
yield DataTable()
4951

5052
def on_mount(self) -> None:
51-
table = self.query_one(DataTable)
52-
table.add_column("Key")
53-
table.add_column("Value")
54-
for key, value in self.user_info.items():
55-
table.add_row(key, value)
53+
try:
54+
self.user = AccountManager(authenticate=False, token_path=self.token_path)
55+
# Set authenticate to false to avoid going into authentication step in the base class init
56+
self.user_info = self.user.get_user_info()
57+
except Exception as e:
58+
print(e)
59+
60+
if self.user_info:
61+
table = self.query_one(DataTable)
62+
table.add_column("Key")
63+
table.add_column("Value")
64+
for key, value in self.user.get_user_info().items():
65+
table.add_row(key, value)
5666

5767

5868
class User(Widget):
59-
def __init__(self):
69+
def __init__(self, token_path: str):
6070
super().__init__()
61-
self.user = AccountManager()
6271
self.id = "user"
63-
72+
self.token_path = token_path
73+
6474
def compose(self) -> ComposeResult:
6575
yield DDSSidebar([
6676
"info"
6777

6878
], help_text)
6979
with ContentSwitcher(initial="info", id="user"):
7080
with Container(id="info"):
71-
yield UserInfo(self.user.get_user_info())
81+
yield UserInfo(self.token_path)
7282

7383
def on_button_pressed(self, event: events.Click) -> None:
7484
if event.button.id == "info":

0 commit comments

Comments
 (0)