diff --git a/nxdrive/data/i18n/i18n.json b/nxdrive/data/i18n/i18n.json index 7cd8a30aaa..0c88d5aea0 100644 --- a/nxdrive/data/i18n/i18n.json +++ b/nxdrive/data/i18n/i18n.json @@ -28,6 +28,7 @@ "CHANNEL": "Channel", "CHANNEL_CHANGE_SETTINGS": "Channel update", "CHANNEL_CONFIRM_DANGEROUS": "Confirm development channel?", + "CHOOSE_PARTICIPANTS": "Choose Participants", "CLOSE": "Close", "COMPLETED": "Completed", "COMPLETED_ON": "Completed on %1", @@ -185,6 +186,7 @@ "FOLDER_USED": "Folder already used by another account", "FREE_DISK_SPACE": "(Free disk space: %1)", "GENERATING": "Generating…", + "GIVE_OPINION": "Give your Opinion", "HELP": "Help", "HISTORY": "History", "HOST": "Host", @@ -386,6 +388,7 @@ "USE_LIGHT_ICONS": "Use the light icons set", "USE_SENTRY": "Enable error reporting", "USERNAME": "Username", + "VALIDATE_DOCUMENT": "Validate the Document", "WEB_AUTHENTICATION_WINDOW_TITLE": "Web Authentication", "WELCOME_MESSAGE": "Set your account and synchronize your files with the Nuxeo Platform.", "WINDOWS_ERROR_TITLE": "Document error", diff --git a/nxdrive/data/qml/Systray.qml b/nxdrive/data/qml/Systray.qml index 662b90b16c..2c3aec5f3c 100755 --- a/nxdrive/data/qml/Systray.qml +++ b/nxdrive/data/qml/Systray.qml @@ -37,6 +37,14 @@ Rectangle { } } + Connections { + target: TasksModel + + function onEngineChanged() { + taskState.pendingTasksCount = api.tasks_remaining(accountSelect.getRole("uid")) + } + } + Connections { target: EngineModel @@ -404,7 +412,7 @@ Rectangle { text: qsTr("PENDING_DOCUMENT_REVIEWS").arg(pendingTasksCount) + tl.tr onClicked: { api.open_tasks_window(accountSelect.getRole("uid")) - tasks_model.loadList(api.get_Tasks_list(accountSelect.getRole("uid")), accountSelect.getRole("uid")); + tasks_model.loadList(api.get_Tasks_list(accountSelect.getRole("uid"))); } } } diff --git a/nxdrive/gui/api.py b/nxdrive/gui/api.py index b1e1e837de..4d36502e8f 100644 --- a/nxdrive/gui/api.py +++ b/nxdrive/gui/api.py @@ -255,7 +255,6 @@ def tasks_remaining(self, uid: str, /) -> int: @pyqtSlot(str) def open_tasks_window(self, uid: str, /) -> None: self.application.hide_systray() - print(f">>>>>> opening task window [engine_id: {uid!r}]") self.application.show_tasks_window(uid) @pyqtSlot() @@ -488,16 +487,27 @@ def show_settings(self, section: str, /) -> None: @pyqtSlot(str, result=list) def get_Tasks_list(self, engine_uid: str, /) -> list: engine = self._get_engine(engine_uid) - return self._fetch_tasks(engine) + tasks_list = self._fetch_tasks(engine) + for task in tasks_list: + doc_id = task.targetDocumentIds[0]["id"] + doc_name = self.get_document_details(engine_uid, doc_id) + task.name = doc_name.title + type = task.directive + if "chooseParticipants" in type or "pleaseSelect" in type: + task.workflowModelName = Translator.get("CHOOSE_PARTICIPANTS") + elif "give_opinion" in type: + task.workflowModelName = Translator.get("GIVE_OPINION") + elif "AcceptReject" in type: + task.workflowModelName = Translator.get("VALIDATE_DOCUMENT") + + return tasks_list @pyqtSlot(str, result=list) def get_document_details(self, engine_uid: str, doc_id: str, /) -> int: engine = self._get_engine(engine_uid) if not engine: log.info("engine not available") - return - doc_details = engine.remote.documents.get(doc_id) - print(f">>>>> doc_details: {doc_details!r}") + return [] return engine.remote.documents.get(doc_id) @pyqtSlot(object) @@ -505,15 +515,7 @@ def fetch_pending_tasks(self, engine: Engine, /) -> None: data = self._fetch_tasks(engine) if len(data) > 0: for task in data: - engine.fetch_pending_task_list(task["id"]) - - """ - @pyqtSlot(str, result=bool) - def get_Tasks_count(self, engine_uid: str, /) -> bool: - engine = self._get_engine(engine_uid) - data = self._fetch_tasks(engine) - return data["resultsCount"] > 0 - """ + engine.fetch_pending_task_list(task.id) def _fetch_tasks(self, engine: Engine) -> Any: return self.application.fetch_pending_tasks(engine) diff --git a/nxdrive/gui/application.py b/nxdrive/gui/application.py index 401a051137..936908477a 100644 --- a/nxdrive/gui/application.py +++ b/nxdrive/gui/application.py @@ -1013,7 +1013,6 @@ def close_direct_transfer_window(self) -> None: @pyqtSlot(str) def show_tasks_window(self, engine_uid: str, /) -> None: """Display the Tasks window.""" - print(f"<<<<<< engine_uid: {engine_uid!r}") self._window_root(self.task_manager_window).setEngine.emit(engine_uid) self._center_on_screen(self.task_manager_window) @@ -1874,6 +1873,7 @@ def fetch_pending_tasks(self, engine: Engine, /) -> list: except Exception: log.info("Unable to fetch tasks") tasks = [] + self.tasks_model.loadList(tasks) return tasks def update_status(self, engine: Engine, /) -> None: diff --git a/nxdrive/gui/view.py b/nxdrive/gui/view.py index dffa1b289a..f4e7c57b40 100755 --- a/nxdrive/gui/view.py +++ b/nxdrive/gui/view.py @@ -856,12 +856,9 @@ def get_model(self): model = pyqtProperty(QObject, fget=get_model, constant=True) @pyqtSlot(list, str) - def loadList(self, tasks_list: list, engine_uid: str, /) -> None: + def loadList(self, tasks_list: list, /) -> None: self.taskmodel.clear() for task in tasks_list: - doc_info = { - "title": "dummy" - } # get_document_info(engine_uid, task.targetDocumentIds[0]["id"]) """ data = { "task_id": task["id"], @@ -873,15 +870,23 @@ def loadList(self, tasks_list: list, engine_uid: str, /) -> None: """ now = date.today() due = datetime.strptime(task.dueDate, "%Y-%m-%dT%H:%M:%S.%f%z").date() - diff = str((due - now).days) + time_remaing = " Day(s)" + diff = (due - now).days + if diff > 365: + diff /= 365 + time_remaing = " Year(s)" + elif diff > 30: + diff /= 30 + time_remaing = " Month(s)" + diff = f"{int(diff)}{time_remaing}" + data = { "task_details": task.workflowModelName + "\n" - + doc_info["title"] + + task.name + "\n" - + "Due:" - + diff - + " Day(s)", + + "Due: in " + + diff, "task_id": task.id, } diff --git a/nxdrive/utils.py b/nxdrive/utils.py index d768db0e29..1b7c5cec92 100644 --- a/nxdrive/utils.py +++ b/nxdrive/utils.py @@ -33,7 +33,6 @@ from urllib.parse import parse_qsl, urlparse, urlsplit, urlunsplit from uuid import uuid4 -import requests from nuxeo.utils import get_digest_algorithm, get_digest_hash from .constants import ( @@ -1341,25 +1340,3 @@ def get_verify(): if "No such file or directory" and "-gw" in str(exc): ssl_verification_needed = False return ssl_verification_needed - - -def get_document_info(doc_id: str): - endpoint = "/api/v1/id/" - url = f"http://localhost:8080/nuxeo{endpoint}{doc_id}" - print(f"^^^^^^ get_document_info url: {url!r}") - headers = { - "Accept": "application/json", - "Content-Type": "application/json", - } - try: - response = requests.get( - url=url, - verify=True, - timeout=3600, - headers=headers, - auth=("Administrator", "Administrator"), - ) - return response.json() - except Exception: - log.exception("Unable to get the document info") - return {}