From ad70566dc686629168cbbc4ad202a149791550e3 Mon Sep 17 00:00:00 2001 From: joeydelarago Date: Wed, 10 Aug 2022 17:34:48 +0200 Subject: Added a message for pending approval status. Updated CloudPrintJobResponse to use an enum for status CURA-9221 --- .../src/Cloud/CloudOutputDevice.py | 7 +++++- .../Messages/PrintJobAwaitingApprovalMessage.py | 25 ++++++++++++++++++++++ .../src/Models/Http/CloudPrintJobResponse.py | 9 +++++++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index 6431d09b7b..0eb0644676 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -21,6 +21,7 @@ from cura.PrinterOutput.PrinterOutputDevice import ConnectionType from .CloudApiClient import CloudApiClient from ..ExportFileJob import ExportFileJob +from ..Messages.PrintJobAwaitingApprovalMessage import PrintJobPendingApprovalMessage from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice from ..Messages.PrintJobUploadBlockedMessage import PrintJobUploadBlockedMessage from ..Messages.PrintJobUploadErrorMessage import PrintJobUploadErrorMessage @@ -30,7 +31,7 @@ from ..Models.Http.CloudClusterResponse import CloudClusterResponse from ..Models.Http.CloudClusterStatus import CloudClusterStatus from ..Models.Http.CloudPrintJobUploadRequest import CloudPrintJobUploadRequest from ..Models.Http.CloudPrintResponse import CloudPrintResponse -from ..Models.Http.CloudPrintJobResponse import CloudPrintJobResponse +from ..Models.Http.CloudPrintJobResponse import CloudPrintJobResponse, CloudUploadStatus from ..Models.Http.ClusterPrinterStatus import ClusterPrinterStatus from ..Models.Http.ClusterPrintJobStatus import ClusterPrintJobStatus @@ -230,6 +231,10 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): :param job_response: The response received from the cloud API. """ + + if job_response.status is CloudUploadStatus.WAIT_APPROVAL: + PrintJobPendingApprovalMessage().show() + if not self._tool_path: return self._onUploadError() self._pre_upload_print_job = job_response # store the last uploaded job to prevent re-upload of the same file diff --git a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py new file mode 100644 index 0000000000..cacfcd362b --- /dev/null +++ b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py @@ -0,0 +1,25 @@ +# Copyright (c) 2022 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. +from UM import i18nCatalog +from UM.Message import Message + + +I18N_CATALOG = i18nCatalog("cura") + + +class PrintJobPendingApprovalMessage(Message): + """Message shown when waiting for approval on an uploaded print job.""" + + def __init__(self) -> None: + super().__init__( + text = I18N_CATALOG.i18nc("@info:status", "The print job was succesfully submitted"), + title=I18N_CATALOG.i18nc("@info:title", "You will recieve a confirmation via email when the print job is approved"), + message_type=Message.MessageType.POSITIVE + ) + self.self.addAction("learn_more", + I18N_CATALOG.i18nc("@action", "Learn more"), + "", + "", + "", + button_style = Message.ActionButtonStyle.LINK, + button_align = Message.ActionButtonAlignment.ALIGN_LEFT) diff --git a/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py b/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py index 83cbb5a030..eb824c2708 100644 --- a/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py +++ b/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py @@ -1,5 +1,6 @@ # Copyright (c) 2019 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +from enum import Enum from typing import Optional from ..BaseModel import BaseModel @@ -25,7 +26,7 @@ class CloudPrintJobResponse(BaseModel): """ self.job_id = job_id - self.status = status + self.status: CloudUploadStatus = CloudUploadStatus(status) self.download_url = download_url self.job_name = job_name self.upload_url = upload_url @@ -33,3 +34,9 @@ class CloudPrintJobResponse(BaseModel): self.status_description = status_description self.slicing_details = slicing_details super().__init__(**kwargs) + + +class CloudUploadStatus(Enum): + FAILED = "failed", + QUEUED = "queued", + WAIT_APPROVAL = "wait_approval" -- cgit v1.2.3 From abb6d20bebe6b1de1fca4dc086164e68982e6a03 Mon Sep 17 00:00:00 2001 From: joeydelarago Date: Wed, 24 Aug 2022 14:06:30 +0200 Subject: Remove enum, python has no build in support for getting enum from string value. This will be in Python 3.11 though. CURA-9221 --- plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py | 4 ++-- .../UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index 0eb0644676..c8a6b30d90 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -31,7 +31,7 @@ from ..Models.Http.CloudClusterResponse import CloudClusterResponse from ..Models.Http.CloudClusterStatus import CloudClusterStatus from ..Models.Http.CloudPrintJobUploadRequest import CloudPrintJobUploadRequest from ..Models.Http.CloudPrintResponse import CloudPrintResponse -from ..Models.Http.CloudPrintJobResponse import CloudPrintJobResponse, CloudUploadStatus +from ..Models.Http.CloudPrintJobResponse import CloudPrintJobResponse from ..Models.Http.ClusterPrinterStatus import ClusterPrinterStatus from ..Models.Http.ClusterPrintJobStatus import ClusterPrintJobStatus @@ -232,7 +232,7 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): :param job_response: The response received from the cloud API. """ - if job_response.status is CloudUploadStatus.WAIT_APPROVAL: + if job_response.status is "wait_approval": PrintJobPendingApprovalMessage().show() if not self._tool_path: diff --git a/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py b/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py index eb824c2708..170adf593d 100644 --- a/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py +++ b/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py @@ -26,7 +26,7 @@ class CloudPrintJobResponse(BaseModel): """ self.job_id = job_id - self.status: CloudUploadStatus = CloudUploadStatus(status) + self.status = status self.download_url = download_url self.job_name = job_name self.upload_url = upload_url @@ -34,9 +34,3 @@ class CloudPrintJobResponse(BaseModel): self.status_description = status_description self.slicing_details = slicing_details super().__init__(**kwargs) - - -class CloudUploadStatus(Enum): - FAILED = "failed", - QUEUED = "queued", - WAIT_APPROVAL = "wait_approval" -- cgit v1.2.3 From 1a023f7285ef1cb5c74243802262638d0cf9dfca Mon Sep 17 00:00:00 2001 From: joeydelarago Date: Wed, 24 Aug 2022 17:02:17 +0200 Subject: Swap text and title for message. Move link opening code into the PrintJobAwaitingApprovalMessage.py CURA-9221 --- .../UM3NetworkPrinting/src/Cloud/CloudApiClient.py | 3 +++ .../src/Cloud/CloudOutputDevice.py | 6 +---- .../Messages/PrintJobAwaitingApprovalMessage.py | 26 ++++++++++++++-------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py index 470e57947e..20a7dcc17c 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py @@ -16,6 +16,7 @@ from cura.CuraApplication import CuraApplication from cura.UltimakerCloud import UltimakerCloudConstants from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope from .ToolPathUploader import ToolPathUploader +from ..Messages.PrintJobAwaitingApprovalMessage import PrintJobPendingApprovalMessage from ..Models.BaseModel import BaseModel from ..Models.Http.CloudClusterResponse import CloudClusterResponse from ..Models.Http.CloudClusterStatus import CloudClusterStatus @@ -241,6 +242,8 @@ class CloudApiClient: status_code, response = self._parseReply(reply) if status_code >= 300 and on_error is not None: on_error() + elif "data" in response and "status" in response["data"] and response["data"]["status"] == "wait_approval": + PrintJobPendingApprovalMessage().show() else: self._parseModels(response, on_finished, model) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index c8a6b30d90..e3eac7da02 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -3,7 +3,7 @@ from time import time import os -from typing import cast, List, Optional, TYPE_CHECKING +from typing import cast, List, Optional from PyQt6.QtCore import QObject, QUrl, pyqtProperty, pyqtSignal, pyqtSlot from PyQt6.QtGui import QDesktopServices @@ -21,7 +21,6 @@ from cura.PrinterOutput.PrinterOutputDevice import ConnectionType from .CloudApiClient import CloudApiClient from ..ExportFileJob import ExportFileJob -from ..Messages.PrintJobAwaitingApprovalMessage import PrintJobPendingApprovalMessage from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice from ..Messages.PrintJobUploadBlockedMessage import PrintJobUploadBlockedMessage from ..Messages.PrintJobUploadErrorMessage import PrintJobUploadErrorMessage @@ -232,9 +231,6 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): :param job_response: The response received from the cloud API. """ - if job_response.status is "wait_approval": - PrintJobPendingApprovalMessage().show() - if not self._tool_path: return self._onUploadError() self._pre_upload_print_job = job_response # store the last uploaded job to prevent re-upload of the same file diff --git a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py index cacfcd362b..c326a35363 100644 --- a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py +++ b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py @@ -1,5 +1,8 @@ # Copyright (c) 2022 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +from PyQt6.QtCore import QUrl +from PyQt6.QtGui import QDesktopServices + from UM import i18nCatalog from UM.Message import Message @@ -12,14 +15,19 @@ class PrintJobPendingApprovalMessage(Message): def __init__(self) -> None: super().__init__( - text = I18N_CATALOG.i18nc("@info:status", "The print job was succesfully submitted"), - title=I18N_CATALOG.i18nc("@info:title", "You will recieve a confirmation via email when the print job is approved"), + text = I18N_CATALOG.i18nc("@info:status", "You will receive a confirmation via email when the print job is approved"), + title=I18N_CATALOG.i18nc("@info:title", "The print job was successfully submitted"), message_type=Message.MessageType.POSITIVE ) - self.self.addAction("learn_more", - I18N_CATALOG.i18nc("@action", "Learn more"), - "", - "", - "", - button_style = Message.ActionButtonStyle.LINK, - button_align = Message.ActionButtonAlignment.ALIGN_LEFT) + self.addAction("manage_print_jobs", I18N_CATALOG.i18nc("@action", "Manage print jobs"), "", "") + + self.addAction("learn_more", I18N_CATALOG.i18nc("@action", "Learn more"), "", "", + button_style = Message.ActionButtonStyle.LINK, + button_align = Message.ActionButtonAlignment.ALIGN_LEFT) + + self.actionTriggered.connect(self._onActionTriggered) + + def _onActionTriggered(self, message: Message, action: str): + """ Callback function for the "Manage print jobs" button on the pending approval notification. """ + if action == "manage_print_jobs": + QDesktopServices.openUrl(QUrl("https://ultimaker.com/")) -- cgit v1.2.3 From 30692bb4b8fe269f07eae5f5ccaa47e6af0cc89b Mon Sep 17 00:00:00 2001 From: joeydelarago Date: Thu, 25 Aug 2022 14:13:25 +0200 Subject: Add link out to learn more CURA-9221 --- .../src/Messages/PrintJobAwaitingApprovalMessage.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py index c326a35363..1a54485a70 100644 --- a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py +++ b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py @@ -29,5 +29,8 @@ class PrintJobPendingApprovalMessage(Message): def _onActionTriggered(self, message: Message, action: str): """ Callback function for the "Manage print jobs" button on the pending approval notification. """ - if action == "manage_print_jobs": - QDesktopServices.openUrl(QUrl("https://ultimaker.com/")) + match action: + case "manage_print_jobs": + QDesktopServices.openUrl(QUrl("https://ultimaker.com/")) + case "learn_more": + QDesktopServices.openUrl(QUrl("https://ultimaker.com/")) -- cgit v1.2.3 From a58690c774d52bad4076d2ec2f6644c7395e64eb Mon Sep 17 00:00:00 2001 From: joeydelarago Date: Thu, 25 Aug 2022 14:49:40 +0200 Subject: change _parseModels -> _parseResponse since it now parses responses with no models included. Move status check into _parseResponse Don't give PrintJobUploadSuccessMessage() if printis awaiting approval. The print has successfully uploaded but it is pending approval instead so it does not make sense to display both messages. CURA-9221 --- .../UM3NetworkPrinting/src/Cloud/CloudApiClient.py | 16 ++++++++------- .../src/Cloud/CloudOutputDevice.py | 23 ++++++++++++---------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py index 20a7dcc17c..e8afe5a0ba 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py @@ -190,9 +190,9 @@ class CloudApiClient: Logger.logException("e", "Could not parse the stardust response: %s", error.toDict()) return status_code, {"errors": [error.toDict()]} - def _parseModels(self, response: Dict[str, Any], on_finished: Union[Callable[[CloudApiClientModel], Any], - Callable[[List[CloudApiClientModel]], Any]], model_class: Type[CloudApiClientModel]) -> None: - """Parses the given models and calls the correct callback depending on the result. + def _parseResponse(self, response: Dict[str, Any], on_finished: Union[Callable[[CloudApiClientModel], Any], + Callable[[List[CloudApiClientModel]], Any]], model_class: Type[CloudApiClientModel]) -> None: + """Parses the given response and calls the correct callback depending on the result. :param response: The response from the server, after being converted to a dict. :param on_finished: The callback in case the response is successful. @@ -201,7 +201,11 @@ class CloudApiClient: if "data" in response: data = response["data"] - if isinstance(data, list): + if "status" in data and data["status"] == "wait_approval": + PrintJobPendingApprovalMessage().show() + on_finished_empty = cast(Callable[[List], Any], on_finished) + on_finished_empty([]) + elif isinstance(data, list): results = [model_class(**c) for c in data] # type: List[CloudApiClientModel] on_finished_list = cast(Callable[[List[CloudApiClientModel]], Any], on_finished) on_finished_list(results) @@ -242,10 +246,8 @@ class CloudApiClient: status_code, response = self._parseReply(reply) if status_code >= 300 and on_error is not None: on_error() - elif "data" in response and "status" in response["data"] and response["data"]["status"] == "wait_approval": - PrintJobPendingApprovalMessage().show() else: - self._parseModels(response, on_finished, model) + self._parseResponse(response, on_finished, model) self._anti_gc_callbacks.append(parse) return parse diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index e3eac7da02..86f3bc0ffc 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -259,16 +259,19 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): """ self._uploaded_print_job = self._pre_upload_print_job self._progress.hide() - message = PrintJobUploadSuccessMessage() - message.addAction("monitor print", - name=I18N_CATALOG.i18nc("@action:button", "Monitor print"), - icon="", - description=I18N_CATALOG.i18nc("@action:tooltip", "Track the print in Ultimaker Digital Factory"), - button_align=message.ActionButtonAlignment.ALIGN_RIGHT) - df_url = f"https://digitalfactory.ultimaker.com/app/jobs/{self._cluster.cluster_id}?utm_source=cura&utm_medium=software&utm_campaign=message-printjob-sent" - message.pyQtActionTriggered.connect(lambda message, action: (QDesktopServices.openUrl(QUrl(df_url)), message.hide())) - - message.show() + + if response: + message = PrintJobUploadSuccessMessage() + message.addAction("monitor print", + name=I18N_CATALOG.i18nc("@action:button", "Monitor print"), + icon="", + description=I18N_CATALOG.i18nc("@action:tooltip", "Track the print in Ultimaker Digital Factory"), + button_align=message.ActionButtonAlignment.ALIGN_RIGHT) + df_url = f"https://digitalfactory.ultimaker.com/app/jobs/{self._cluster.cluster_id}?utm_source=cura&utm_medium=software&utm_campaign=message-printjob-sent" + message.pyQtActionTriggered.connect(lambda message, action: (QDesktopServices.openUrl(QUrl(df_url)), message.hide())) + + message.show() + self.writeFinished.emit() def _onPrintUploadSpecificError(self, reply: "QNetworkReply", _: "QNetworkReply.NetworkError"): -- cgit v1.2.3 From a6f459b0f68cec7fd5c5cb345b174db2b1d39b23 Mon Sep 17 00:00:00 2001 From: joeydelarago Date: Fri, 26 Aug 2022 08:55:12 +0200 Subject: Update links CURA-9221 --- .../src/Messages/PrintJobAwaitingApprovalMessage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py index 1a54485a70..f5a92a519d 100644 --- a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py +++ b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py @@ -31,6 +31,6 @@ class PrintJobPendingApprovalMessage(Message): """ Callback function for the "Manage print jobs" button on the pending approval notification. """ match action: case "manage_print_jobs": - QDesktopServices.openUrl(QUrl("https://ultimaker.com/")) + QDesktopServices.openUrl(QUrl("https://digitalfactory.ultimaker.com/app/jobs/")) case "learn_more": - QDesktopServices.openUrl(QUrl("https://ultimaker.com/")) + QDesktopServices.openUrl(QUrl("https://support.ultimaker.com/hc/en-us/articles/5329940078620")) -- cgit v1.2.3 From 0993dc99f9eb1cfa17e6d55f76093e112f1b51b0 Mon Sep 17 00:00:00 2001 From: joeydelarago Date: Fri, 26 Aug 2022 09:00:17 +0200 Subject: Remove unused import CURA-9221 --- plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py b/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py index 170adf593d..83cbb5a030 100644 --- a/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py +++ b/plugins/UM3NetworkPrinting/src/Models/Http/CloudPrintJobResponse.py @@ -1,6 +1,5 @@ # Copyright (c) 2019 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from enum import Enum from typing import Optional from ..BaseModel import BaseModel -- cgit v1.2.3 From 119fb3268134b3106276f4ddc01ce55cd0166e09 Mon Sep 17 00:00:00 2001 From: Joey de l'Arago Date: Fri, 26 Aug 2022 10:14:36 +0200 Subject: Update plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py Co-authored-by: Jaime van Kessel --- .../UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py index f5a92a519d..2e015dd46f 100644 --- a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py +++ b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py @@ -27,7 +27,7 @@ class PrintJobPendingApprovalMessage(Message): self.actionTriggered.connect(self._onActionTriggered) - def _onActionTriggered(self, message: Message, action: str): + def _onActionTriggered(self, message: Message, action: str) -> None: """ Callback function for the "Manage print jobs" button on the pending approval notification. """ match action: case "manage_print_jobs": -- cgit v1.2.3 From 9c599870e36cf607ed08f76f51177ce92365f899 Mon Sep 17 00:00:00 2001 From: joeydelarago Date: Fri, 26 Aug 2022 10:57:35 +0200 Subject: Move message triggering into CloudOutputDevice so that the campaign link can include the cluster_id. CURA-9221 --- plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py | 2 -- plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py | 3 +++ .../src/Messages/PrintJobAwaitingApprovalMessage.py | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py index e8afe5a0ba..1fc926fe90 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py @@ -16,7 +16,6 @@ from cura.CuraApplication import CuraApplication from cura.UltimakerCloud import UltimakerCloudConstants from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope from .ToolPathUploader import ToolPathUploader -from ..Messages.PrintJobAwaitingApprovalMessage import PrintJobPendingApprovalMessage from ..Models.BaseModel import BaseModel from ..Models.Http.CloudClusterResponse import CloudClusterResponse from ..Models.Http.CloudClusterStatus import CloudClusterStatus @@ -202,7 +201,6 @@ class CloudApiClient: if "data" in response: data = response["data"] if "status" in data and data["status"] == "wait_approval": - PrintJobPendingApprovalMessage().show() on_finished_empty = cast(Callable[[List], Any], on_finished) on_finished_empty([]) elif isinstance(data, list): diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index 86f3bc0ffc..6426f01b76 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -21,6 +21,7 @@ from cura.PrinterOutput.PrinterOutputDevice import ConnectionType from .CloudApiClient import CloudApiClient from ..ExportFileJob import ExportFileJob +from ..Messages.PrintJobAwaitingApprovalMessage import PrintJobPendingApprovalMessage from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice from ..Messages.PrintJobUploadBlockedMessage import PrintJobUploadBlockedMessage from ..Messages.PrintJobUploadErrorMessage import PrintJobUploadErrorMessage @@ -271,6 +272,8 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): message.pyQtActionTriggered.connect(lambda message, action: (QDesktopServices.openUrl(QUrl(df_url)), message.hide())) message.show() + else: + PrintJobPendingApprovalMessage(self._cluster.cluster_id).show() self.writeFinished.emit() diff --git a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py index 2e015dd46f..03691d5c6f 100644 --- a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py +++ b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py @@ -13,7 +13,7 @@ I18N_CATALOG = i18nCatalog("cura") class PrintJobPendingApprovalMessage(Message): """Message shown when waiting for approval on an uploaded print job.""" - def __init__(self) -> None: + def __init__(self, cluster_id: str) -> None: super().__init__( text = I18N_CATALOG.i18nc("@info:status", "You will receive a confirmation via email when the print job is approved"), title=I18N_CATALOG.i18nc("@info:title", "The print job was successfully submitted"), @@ -27,10 +27,12 @@ class PrintJobPendingApprovalMessage(Message): self.actionTriggered.connect(self._onActionTriggered) + self.cluster_id = cluster_id + def _onActionTriggered(self, message: Message, action: str) -> None: """ Callback function for the "Manage print jobs" button on the pending approval notification. """ match action: case "manage_print_jobs": - QDesktopServices.openUrl(QUrl("https://digitalfactory.ultimaker.com/app/jobs/")) + QDesktopServices.openUrl(QUrl(f"https://digitalfactory.ultimaker.com/app/jobs/{self._cluster.cluster_id}?utm_source=cura&utm_medium=software&utm_campaign=message-printjob-sent")) case "learn_more": - QDesktopServices.openUrl(QUrl("https://support.ultimaker.com/hc/en-us/articles/5329940078620")) + QDesktopServices.openUrl(QUrl("https://support.ultimaker.com/hc/en-us/articles/5329940078620?utm_source=cura&utm_medium=software&utm_campaign=message-printjob-sent")) -- cgit v1.2.3 From 7ab16e078c15c2697fd18c48192a70b367fab3a3 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Tue, 30 Aug 2022 16:45:34 +0200 Subject: Speared spurious space. done as part of CURA-9221 --- .../UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py index 03691d5c6f..c60d596da9 100644 --- a/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py +++ b/plugins/UM3NetworkPrinting/src/Messages/PrintJobAwaitingApprovalMessage.py @@ -13,7 +13,7 @@ I18N_CATALOG = i18nCatalog("cura") class PrintJobPendingApprovalMessage(Message): """Message shown when waiting for approval on an uploaded print job.""" - def __init__(self, cluster_id: str) -> None: + def __init__(self, cluster_id: str) -> None: super().__init__( text = I18N_CATALOG.i18nc("@info:status", "You will receive a confirmation via email when the print job is approved"), title=I18N_CATALOG.i18nc("@info:title", "The print job was successfully submitted"), -- cgit v1.2.3