Skip to content

Commit

Permalink
refactor: Rewrite major parts of the file browser
Browse files Browse the repository at this point in the history
The UI was completely messed up and is fixed now. Folders and files
are aligned again.

In addition, workspace is now expanded by default, new code style has been
applied and the deprecated `NestedTreeControl` was replaced.
  • Loading branch information
MoritzWeber0 committed Oct 2, 2024
1 parent e0c2998 commit a415e77
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 464 deletions.
36 changes: 36 additions & 0 deletions backend/capellacollab/core/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,39 @@ class SVGResponse(fastapi.responses.Response):
}
}
}


class ZIPFileResponse(fastapi.responses.StreamingResponse):
"""Custom error class for zip-file responses.
To use the class as response class, pass the following parameters
to the fastapi route definition.
```python
response_class=fastapi.responses.Response
responses=responses.ZIPFileResponse.responses
```
Don't use ZIPFileResponse as response_class as this will also change the
media type for all error responses, see:
https://github.com/tiangolo/fastapi/discussions/6799
To return an ZIP-file response in the route, use:
```python
return responses.SVGResponse(
content=b"<svg>...</svg>",
)
```
"""

media_type = "application/zip"
responses: dict[int | str, dict[str, t.Any]] | None = {
200: {
"content": {
"application/zip": {
"schema": {"type": "string", "format": "binary"}
}
}
}
}
15 changes: 8 additions & 7 deletions backend/capellacollab/sessions/files/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fastapi
from fastapi import responses

from capellacollab.core import responses as core_responses
from capellacollab.sessions import injectables as sessions_injectables
from capellacollab.sessions import models as sessions_models
from capellacollab.sessions import operators
Expand Down Expand Up @@ -69,17 +70,17 @@ def upload_files(
return {"message": "Upload successful"}


@router.get("/download", response_class=responses.StreamingResponse)
@router.get(
"/download",
response_class=responses.StreamingResponse,
responses=core_responses.ZIPFileResponse.responses,
)
def download_file(
filename: str,
session: sessions_models.DatabaseSession = fastapi.Depends(
sessions_injectables.get_existing_session
),
) -> responses.StreamingResponse:
return responses.StreamingResponse(
) -> core_responses.ZIPFileResponse:
return core_responses.ZIPFileResponse(

Check warning on line 84 in backend/capellacollab/sessions/files/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/sessions/files/routes.py#L84

Added line #L84 was not covered by tests
operators.get_operator().download_file(session.id, filename),
headers={
"content-disposition": 'attachment; filename=f"{filename}.zip"',
"content-type": "application/zip",
},
)
24 changes: 7 additions & 17 deletions frontend/src/app/openapi/api/sessions.service.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 0 additions & 46 deletions frontend/src/app/services/load-files/load-files.service.ts

This file was deleted.

11 changes: 5 additions & 6 deletions frontend/src/app/sessions/service/session.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SessionProvisioningRequest,
SessionsService,
SessionConnectionInformation,
FileTree,
} from 'src/app/openapi';
import { SessionHistoryService } from 'src/app/sessions/user-sessions-wrapper/create-sessions/create-session-history/session-history.service';

Expand Down Expand Up @@ -223,10 +224,8 @@ export interface SessionState {
success: boolean;
}

export interface PathNode {
path: string;
name: string;
type: 'file' | 'directory';
isNew: boolean;
export type PathNode = FileTree & {
isNew?: boolean;
isExpanded?: boolean;
children: PathNode[] | null;
}
};

This file was deleted.

Loading

0 comments on commit a415e77

Please sign in to comment.