Folder creation
This commit is contained in:
parent
b0f20680b4
commit
37940d633a
37
desktop_client/create_folder_widget.py
Normal file
37
desktop_client/create_folder_widget.py
Normal file
@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
import file_widgets
|
||||
from PyQt6.QtWidgets import QLineEdit, QMessageBox, QPushButton, QVBoxLayout, QWidget
|
||||
from request_client import RequestClient
|
||||
|
||||
|
||||
class CreateFolderWidget(QWidget):
|
||||
def __init__(self, folder_id: uuid.UUID, file_list: file_widgets.FileListWidget):
|
||||
super().__init__()
|
||||
self.folder_id = folder_id
|
||||
self.file_list = file_list
|
||||
self.setWindowTitle("Folder creation")
|
||||
layout = QVBoxLayout()
|
||||
self.edit = QLineEdit()
|
||||
layout.addWidget(self.edit)
|
||||
button = QPushButton("Submit")
|
||||
button.clicked.connect(self.submit)
|
||||
layout.addWidget(button)
|
||||
self.setLayout(layout)
|
||||
|
||||
def submit(self):
|
||||
response = RequestClient().client.post(
|
||||
"/folders",
|
||||
json={
|
||||
"folder_name": self.edit.text(),
|
||||
"parent_folder_id": str(self.folder_id),
|
||||
},
|
||||
)
|
||||
if not response.is_success:
|
||||
QMessageBox.warning(None, "Error creating folder", response.text)
|
||||
else:
|
||||
QMessageBox.information(None, "Folder created", "Folder created")
|
||||
self.file_list.update_response()
|
||||
self.close()
|
@ -1,23 +1,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import user
|
||||
import datetime
|
||||
import os
|
||||
import uuid
|
||||
from typing import Protocol, Self
|
||||
|
||||
import create_folder_widget
|
||||
import httpx
|
||||
import pydantic
|
||||
import state
|
||||
import user
|
||||
from PyQt6.QtCore import QPoint, Qt
|
||||
from PyQt6.QtGui import (
|
||||
QAction,
|
||||
QDragEnterEvent,
|
||||
QDragMoveEvent,
|
||||
QDropEvent,
|
||||
QIcon,
|
||||
)
|
||||
from PyQt6.QtGui import QAction, QDragEnterEvent, QDragMoveEvent, QDropEvent, QIcon
|
||||
from PyQt6.QtWidgets import (
|
||||
QFileDialog,
|
||||
QHBoxLayout,
|
||||
@ -62,9 +57,7 @@ class File(pydantic.BaseModel):
|
||||
return self.file_name
|
||||
|
||||
def delete(self) -> None:
|
||||
RequestClient().client.delete(
|
||||
"/files", params={"file_id": self.file_id}
|
||||
)
|
||||
RequestClient().client.delete("/files", params={"file_id": self.file_id})
|
||||
|
||||
def details(self, list: FileListWidget) -> QWidget:
|
||||
del list
|
||||
@ -121,8 +114,10 @@ class Folder(pydantic.BaseModel):
|
||||
return self.folder_name
|
||||
|
||||
def delete(self) -> None:
|
||||
RequestClient().client.delete(
|
||||
"/folders", params={"folder_id": self.folder_id}
|
||||
print(
|
||||
RequestClient()
|
||||
.client.delete("/folders", params={"folder_id": self.folder_id})
|
||||
.text
|
||||
)
|
||||
|
||||
def details(self, list: FileListWidget) -> QWidget:
|
||||
@ -144,6 +139,9 @@ class ResponseProtocol(Protocol):
|
||||
def update(self) -> ResponseProtocol:
|
||||
raise NotImplementedError
|
||||
|
||||
def create_folder(self) -> QWidget | None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class ListResponse(pydantic.BaseModel):
|
||||
folder_id: uuid.UUID
|
||||
@ -165,6 +163,32 @@ class ListResponse(pydantic.BaseModel):
|
||||
def update(self) -> ResponseProtocol:
|
||||
return self.get(self.folder_id)
|
||||
|
||||
def create_folder(self, file_list: FileListWidget):
|
||||
return create_folder_widget.CreateFolderWidget(self.folder_id, file_list)
|
||||
|
||||
|
||||
@dataclasses.dataclass(slots=True)
|
||||
class TlpResponse:
|
||||
folders: list[Folder]
|
||||
|
||||
@staticmethod
|
||||
def get() -> Self:
|
||||
url = "/permissions/get_top_level_permitted_folders"
|
||||
return TlpResponse(
|
||||
pydantic.TypeAdapter(list[Folder]).validate_json(
|
||||
RequestClient().client.get(url).text
|
||||
)
|
||||
)
|
||||
|
||||
def items(self) -> list[DisplayProtocol]:
|
||||
return self.folders
|
||||
|
||||
def update(self) -> ResponseProtocol:
|
||||
return self.get()
|
||||
|
||||
def create_folder(self):
|
||||
return # Not much to do
|
||||
|
||||
|
||||
class FileListWidget(QListWidget):
|
||||
def __init__(self, state: state.State):
|
||||
@ -217,9 +241,7 @@ class FileListWidget(QListWidget):
|
||||
response = RequestClient().client.post(
|
||||
"http://localhost:3000/files",
|
||||
files=files,
|
||||
params={
|
||||
"parent_folder": self.current_response().folder_id
|
||||
},
|
||||
params={"parent_folder": self.current_response().folder_id},
|
||||
)
|
||||
if response.is_success:
|
||||
QMessageBox.information(
|
||||
@ -276,6 +298,7 @@ class Sidebar(QWidget):
|
||||
self.state = state
|
||||
self.file_list = file_list
|
||||
self.user_widget = None
|
||||
self.folder_widget = None
|
||||
layout = QVBoxLayout()
|
||||
self.setLayout(layout)
|
||||
buttons = [
|
||||
@ -285,6 +308,7 @@ class Sidebar(QWidget):
|
||||
("Go root", self.go_root),
|
||||
("Get permitted", self.get_tlp),
|
||||
("Sync", self.sync),
|
||||
("Create folder", self.create_folder),
|
||||
]
|
||||
for text, func in buttons:
|
||||
button = QPushButton(text)
|
||||
@ -317,25 +341,12 @@ class Sidebar(QWidget):
|
||||
# TODO
|
||||
...
|
||||
|
||||
|
||||
@dataclasses.dataclass(slots=True)
|
||||
class TlpResponse:
|
||||
folders: list[Folder]
|
||||
|
||||
@staticmethod
|
||||
def get() -> Self:
|
||||
url = "/permissions/get_top_level_permitted_folders"
|
||||
return TlpResponse(
|
||||
pydantic.TypeAdapter(list[Folder]).validate_json(
|
||||
RequestClient().client.get(url).text
|
||||
def create_folder(self):
|
||||
self.folder_widget = self.file_list.current_response().create_folder(
|
||||
self.file_list
|
||||
)
|
||||
)
|
||||
|
||||
def items(self) -> list[DisplayProtocol]:
|
||||
return self.folders
|
||||
|
||||
def update(self) -> ResponseProtocol:
|
||||
return self.get()
|
||||
if self.folder_widget is not None:
|
||||
self.folder_widget.show()
|
||||
|
||||
|
||||
class MainFileWidget(QWidget):
|
||||
|
@ -3,13 +3,13 @@ from __future__ import annotations
|
||||
import pydantic
|
||||
import state
|
||||
from PyQt6.QtWidgets import (
|
||||
QWidget,
|
||||
QLineEdit,
|
||||
QLabel,
|
||||
QVBoxLayout,
|
||||
QPushButton,
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
)
|
||||
from request_client import RequestClient
|
||||
|
||||
|
Reference in New Issue
Block a user