Skip to content

Commit

Permalink
NXDRIVE-2912: Display Drive notification for document review --05/04
Browse files Browse the repository at this point in the history
  • Loading branch information
gitofanindya committed Apr 5, 2024
1 parent 694820f commit 2755b5e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 48 deletions.
3 changes: 3 additions & 0 deletions nxdrive/data/i18n/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion nxdrive/data/qml/Systray.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ Rectangle {
}
}

Connections {
target: TasksModel

function onEngineChanged() {
taskState.pendingTasksCount = api.tasks_remaining(accountSelect.getRole("uid"))
}
}

Connections {
target: EngineModel

Expand Down Expand Up @@ -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")));
}
}
}
Expand Down
30 changes: 16 additions & 14 deletions nxdrive/gui/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -488,32 +487,35 @@ 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)
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)
Expand Down
2 changes: 1 addition & 1 deletion nxdrive/gui/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
23 changes: 14 additions & 9 deletions nxdrive/gui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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,
}

Expand Down
23 changes: 0 additions & 23 deletions nxdrive/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {}

0 comments on commit 2755b5e

Please sign in to comment.