From 27078413a523208e242bf74120029c58d59fbc94 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Mon, 11 Nov 2024 13:58:47 -0300 Subject: [PATCH 01/15] new dialog impl --- Mergin/project_limit_hit_dialog.py | 24 ++++ Mergin/ui/ui_project_limit_hit_dialog.ui | 168 +++++++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 Mergin/project_limit_hit_dialog.py create mode 100644 Mergin/ui/ui_project_limit_hit_dialog.ui diff --git a/Mergin/project_limit_hit_dialog.py b/Mergin/project_limit_hit_dialog.py new file mode 100644 index 00000000..28565fbe --- /dev/null +++ b/Mergin/project_limit_hit_dialog.py @@ -0,0 +1,24 @@ +import os +from qgis.PyQt import uic +from qgis.PyQt.QtWidgets import QDialog +from qgis.PyQt.QtCore import QUrl +from qgis.PyQt.QtGui import QDesktopServices + +ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_project_limit_hit_dialog.ui") + +class ProjectLimitHitDialog(QDialog): + def __init__(self, e, parent=None): + QDialog.__init__(self, parent) + self.ui = uic.loadUi(ui_file, self) + + quota = e.server_response.get('projects_quota', 'N/A') + plan = e.server_response.get('plan', 'N/A') + self.planQuota_label.setText(str(quota)) + self.planName_label.setText(str(plan)) + + self.cancel_btn.clicked.connect(self.reject) + self.upgrade_plan_btn.clicked.connect(self.open_upgrade_link) + + def open_upgrade_link(self): + QDesktopServices.openUrl(QUrl("https://www.merginmaps.com/pricing")) + self.accept() \ No newline at end of file diff --git a/Mergin/ui/ui_project_limit_hit_dialog.ui b/Mergin/ui/ui_project_limit_hit_dialog.ui new file mode 100644 index 00000000..c13e1e15 --- /dev/null +++ b/Mergin/ui/ui_project_limit_hit_dialog.ui @@ -0,0 +1,168 @@ + + + Dialog + + + + 0 + 0 + 332 + 278 + + + + Project limit hit + + + + + + + 0 + 0 + + + + + 16 + 75 + true + + + + You have reached the maximum limit of active monthly contributors for your subscription. + + + Qt::AutoText + + + Qt::AlignCenter + + + true + + + + + + + Upgrade your subscription or wait until next month +for refresh of slots. + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Used + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + 100 + + + + + + + + + Plan + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + 0 + 0 + + + + Cancel + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 200 + 16777215 + + + + Upgrade + + + true + + + + + + + + + + From b187b7890942f6cff3c5a675767ce741b6b101f3 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Mon, 11 Nov 2024 14:00:00 -0300 Subject: [PATCH 02/15] dialog exec --- Mergin/projects_manager.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Mergin/projects_manager.py b/Mergin/projects_manager.py index 2823ac5c..3bd6e950 100644 --- a/Mergin/projects_manager.py +++ b/Mergin/projects_manager.py @@ -29,7 +29,7 @@ from .mergin.merginproject import MerginProject from .project_status_dialog import ProjectStatusDialog - +from .project_limit_hit_dialog import ProjectLimitHitDialog class MerginProjectsManager(object): """Class for managing Mergin Maps projects in QGIS.""" @@ -96,10 +96,10 @@ def create_project(self, project_name, project_dir, is_public, namespace): if e.http_error == 409: msg = f'Project named "{project_name}" already exists in the workspace "{namespace}".\nPlease try renaming the project.' elif e.server_code == ErrorCode.ProjectsLimitHit.value: - msg = ( - "Maximum number of projects reached. Please upgrade your subscription to create new projects.\n" - f"Projects quota: {e.server_response['projects_quota']}" - ) + print(e.server_response) + dlg = ProjectLimitHitDialog(e) + dlg.exec() + return False elif e.server_code == ErrorCode.StorageLimitHit.value: msg = ( f"{e.detail}\nCurrent limit: {bytes_to_human_size(dlg.exception.server_response['storage_limit'])}" From 0edb653bcfa9f48eff7bea099b4fdb440ca7d105 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Tue, 12 Nov 2024 17:41:53 -0300 Subject: [PATCH 03/15] new code adjustments --- Mergin/project_limit_hit_dialog.py | 32 ++++-- Mergin/projects_manager.py | 1 + Mergin/ui/ui_project_limit_hit_dialog.ui | 132 +++++++++++------------ 3 files changed, 88 insertions(+), 77 deletions(-) diff --git a/Mergin/project_limit_hit_dialog.py b/Mergin/project_limit_hit_dialog.py index 28565fbe..18d40de2 100644 --- a/Mergin/project_limit_hit_dialog.py +++ b/Mergin/project_limit_hit_dialog.py @@ -6,19 +6,35 @@ ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_project_limit_hit_dialog.ui") + class ProjectLimitHitDialog(QDialog): def __init__(self, e, parent=None): QDialog.__init__(self, parent) self.ui = uic.loadUi(ui_file, self) - - quota = e.server_response.get('projects_quota', 'N/A') - plan = e.server_response.get('plan', 'N/A') - self.planQuota_label.setText(str(quota)) - self.planName_label.setText(str(plan)) - + + self.server_response = e.server_response + self.setDialogStyle() + self.cancel_btn.clicked.connect(self.reject) self.upgrade_plan_btn.clicked.connect(self.open_upgrade_link) - + + def setDialogStyle(self): + quota = self.server_response.get("projects_quota", "N/A") + quota_text = f"{quota}/{quota}" + + self.plan_quota_progress_bar.setFormat(quota_text) + self.plan_quota_progress_bar.setStyleSheet( + """ + QProgressBar { + border: none; + text-align: center; + } + QProgressBar::chunk { + background-color: rgb(0, 76, 69); + } + """ + ) + def open_upgrade_link(self): QDesktopServices.openUrl(QUrl("https://www.merginmaps.com/pricing")) - self.accept() \ No newline at end of file + self.accept() diff --git a/Mergin/projects_manager.py b/Mergin/projects_manager.py index 3bd6e950..54d67ade 100644 --- a/Mergin/projects_manager.py +++ b/Mergin/projects_manager.py @@ -31,6 +31,7 @@ from .project_status_dialog import ProjectStatusDialog from .project_limit_hit_dialog import ProjectLimitHitDialog + class MerginProjectsManager(object): """Class for managing Mergin Maps projects in QGIS.""" diff --git a/Mergin/ui/ui_project_limit_hit_dialog.ui b/Mergin/ui/ui_project_limit_hit_dialog.ui index c13e1e15..dd6a44a6 100644 --- a/Mergin/ui/ui_project_limit_hit_dialog.ui +++ b/Mergin/ui/ui_project_limit_hit_dialog.ui @@ -6,15 +6,15 @@ 0 0 - 332 - 278 + 352 + 224 Project limit hit - - + + @@ -30,7 +30,7 @@ - You have reached the maximum limit of active monthly contributors for your subscription. + You've reached the maximum number of active monthly contributors for your current subscription. Qt::AutoText @@ -43,80 +43,41 @@ - - - - Upgrade your subscription or wait until next month -for refresh of slots. + + + + true - - Qt::AlignCenter + + + 0 + 0 + - - - - - - Qt::Vertical + + + 0 + 15 + - + - 20 - 40 + 16777215 + 16777215 + + + + + 0 + 15 - - - - - - - - Used - - - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 100 - - - - - - Plan - - - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - + @@ -133,8 +94,11 @@ for refresh of slots. + + true + - + 0 0 @@ -151,12 +115,42 @@ for refresh of slots. 16777215 + + + true + + Upgrade true + + false + + + + + + + + + Upgrade your subscription or wait until next month +for the limit to reset. + + + Qt::AlignCenter + + + + + + + + + Used + From cf27787b6eedc1fd8f6ecdaf922cca61adc6d4c6 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Tue, 12 Nov 2024 17:59:39 -0300 Subject: [PATCH 04/15] last adjustments before review - dialog and code --- Mergin/projects_manager.py | 1 - Mergin/ui/ui_project_limit_hit_dialog.ui | 14 ++++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Mergin/projects_manager.py b/Mergin/projects_manager.py index 54d67ade..0a81d1f0 100644 --- a/Mergin/projects_manager.py +++ b/Mergin/projects_manager.py @@ -97,7 +97,6 @@ def create_project(self, project_name, project_dir, is_public, namespace): if e.http_error == 409: msg = f'Project named "{project_name}" already exists in the workspace "{namespace}".\nPlease try renaming the project.' elif e.server_code == ErrorCode.ProjectsLimitHit.value: - print(e.server_response) dlg = ProjectLimitHitDialog(e) dlg.exec() return False diff --git a/Mergin/ui/ui_project_limit_hit_dialog.ui b/Mergin/ui/ui_project_limit_hit_dialog.ui index dd6a44a6..442e00f8 100644 --- a/Mergin/ui/ui_project_limit_hit_dialog.ui +++ b/Mergin/ui/ui_project_limit_hit_dialog.ui @@ -6,8 +6,8 @@ 0 0 - 352 - 224 + 367 + 212 @@ -82,7 +82,7 @@ - + 0 0 @@ -98,7 +98,7 @@ true - + 0 0 @@ -148,6 +148,12 @@ for the limit to reset. + + + 0 + 0 + + Used From c75fa81d7ad1b5c2ec1a46a845273b4463a0c545 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Tue, 12 Nov 2024 18:01:52 -0300 Subject: [PATCH 05/15] dialog title update --- Mergin/ui/ui_project_limit_hit_dialog.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mergin/ui/ui_project_limit_hit_dialog.ui b/Mergin/ui/ui_project_limit_hit_dialog.ui index 442e00f8..d5072040 100644 --- a/Mergin/ui/ui_project_limit_hit_dialog.ui +++ b/Mergin/ui/ui_project_limit_hit_dialog.ui @@ -11,7 +11,7 @@ - Project limit hit + Project Limit Hit From 8b102b5f05556c3206d0305e8846a21be3434a3b Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Wed, 13 Nov 2024 08:13:37 -0300 Subject: [PATCH 06/15] last code adjustments --- Mergin/project_limit_hit_dialog.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Mergin/project_limit_hit_dialog.py b/Mergin/project_limit_hit_dialog.py index 18d40de2..45486ed2 100644 --- a/Mergin/project_limit_hit_dialog.py +++ b/Mergin/project_limit_hit_dialog.py @@ -6,20 +6,19 @@ ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_project_limit_hit_dialog.ui") - class ProjectLimitHitDialog(QDialog): def __init__(self, e, parent=None): QDialog.__init__(self, parent) self.ui = uic.loadUi(ui_file, self) self.server_response = e.server_response - self.setDialogStyle() + self.set_dialog_style() self.cancel_btn.clicked.connect(self.reject) self.upgrade_plan_btn.clicked.connect(self.open_upgrade_link) - def setDialogStyle(self): - quota = self.server_response.get("projects_quota", "N/A") + def set_dialog_style(self): + quota = self.server_response.get("projects_quota", "#NA") quota_text = f"{quota}/{quota}" self.plan_quota_progress_bar.setFormat(quota_text) From c28c7c2efbc6abccba6e158a47981fb52e066feb Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Wed, 13 Nov 2024 09:42:02 -0300 Subject: [PATCH 07/15] updating to MonthlyContributorsError --- Mergin/configuration_dialog.py | 2 +- ...log.py => monthly_contributors_error_dialog.py} | 4 ++-- Mergin/projects_manager.py | 14 +++++++++----- ....ui => ui_monthly_contributors_error_dialog.ui} | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) rename Mergin/{project_limit_hit_dialog.py => monthly_contributors_error_dialog.py} (91%) rename Mergin/ui/{ui_project_limit_hit_dialog.ui => ui_monthly_contributors_error_dialog.ui} (97%) diff --git a/Mergin/configuration_dialog.py b/Mergin/configuration_dialog.py index 76aaafe6..b31f735b 100644 --- a/Mergin/configuration_dialog.py +++ b/Mergin/configuration_dialog.py @@ -14,7 +14,7 @@ this_dir = os.path.dirname(os.path.realpath(__file__)) path = os.path.join(this_dir, "mergin_client.whl") sys.path.append(path) - from mergin.client import MerginClient, ClientError, LoginError + from .mergin.client import MerginClient, ClientError, LoginError from .utils import ( get_mergin_auth, diff --git a/Mergin/project_limit_hit_dialog.py b/Mergin/monthly_contributors_error_dialog.py similarity index 91% rename from Mergin/project_limit_hit_dialog.py rename to Mergin/monthly_contributors_error_dialog.py index 45486ed2..8abea96b 100644 --- a/Mergin/project_limit_hit_dialog.py +++ b/Mergin/monthly_contributors_error_dialog.py @@ -4,9 +4,9 @@ from qgis.PyQt.QtCore import QUrl from qgis.PyQt.QtGui import QDesktopServices -ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_project_limit_hit_dialog.ui") +ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_monthly_contributors_error_dialog.ui.ui") -class ProjectLimitHitDialog(QDialog): +class MonthlyContributorsErrorDialog(QDialog): def __init__(self, e, parent=None): QDialog.__init__(self, parent) self.ui = uic.loadUi(ui_file, self) diff --git a/Mergin/projects_manager.py b/Mergin/projects_manager.py index 0a81d1f0..5289ba65 100644 --- a/Mergin/projects_manager.py +++ b/Mergin/projects_manager.py @@ -29,7 +29,7 @@ from .mergin.merginproject import MerginProject from .project_status_dialog import ProjectStatusDialog -from .project_limit_hit_dialog import ProjectLimitHitDialog +from .monthly_contributors_error_dialog import MonthlyContributorsErrorDialog class MerginProjectsManager(object): @@ -97,14 +97,18 @@ def create_project(self, project_name, project_dir, is_public, namespace): if e.http_error == 409: msg = f'Project named "{project_name}" already exists in the workspace "{namespace}".\nPlease try renaming the project.' elif e.server_code == ErrorCode.ProjectsLimitHit.value: - dlg = ProjectLimitHitDialog(e) - dlg.exec() - return False + msg = ( + "Maximum number of projects reached. Please upgrade your subscription to create new projects.\n" + f"Projects quota: {e.server_response['projects_quota']}" + ) elif e.server_code == ErrorCode.StorageLimitHit.value: msg = ( f"{e.detail}\nCurrent limit: {bytes_to_human_size(dlg.exception.server_response['storage_limit'])}" ) - + elif e.server_code == ErrorCode.MonthlyContributorsError.value: + dlg = MonthlyContributorsErrorDialog(e) + dlg.exec() + return False QMessageBox.critical(None, "Create Project", "Failed to create Mergin Maps project.\n" + msg) return False except Exception as e: diff --git a/Mergin/ui/ui_project_limit_hit_dialog.ui b/Mergin/ui/ui_monthly_contributors_error_dialog.ui similarity index 97% rename from Mergin/ui/ui_project_limit_hit_dialog.ui rename to Mergin/ui/ui_monthly_contributors_error_dialog.ui index d5072040..280fe942 100644 --- a/Mergin/ui/ui_project_limit_hit_dialog.ui +++ b/Mergin/ui/ui_monthly_contributors_error_dialog.ui @@ -11,7 +11,7 @@ - Project Limit Hit + Monthly Contributors Error @@ -155,7 +155,7 @@ for the limit to reset. - Used + Monthly Contributors From 0af5e53be372567c3e409bf7f0c587d70dd6a71f Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Wed, 13 Nov 2024 09:46:18 -0300 Subject: [PATCH 08/15] code layout adjustment --- Mergin/monthly_contributors_error_dialog.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Mergin/monthly_contributors_error_dialog.py b/Mergin/monthly_contributors_error_dialog.py index 8abea96b..7f8baa2d 100644 --- a/Mergin/monthly_contributors_error_dialog.py +++ b/Mergin/monthly_contributors_error_dialog.py @@ -6,6 +6,7 @@ ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_monthly_contributors_error_dialog.ui.ui") + class MonthlyContributorsErrorDialog(QDialog): def __init__(self, e, parent=None): QDialog.__init__(self, parent) From 94d7e78065751184b3bf8eb8b4b00bc37205e679 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Thu, 14 Nov 2024 10:43:16 -0300 Subject: [PATCH 09/15] fixing dialog --- Mergin/projects_manager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Mergin/projects_manager.py b/Mergin/projects_manager.py index 5289ba65..fbb3db82 100644 --- a/Mergin/projects_manager.py +++ b/Mergin/projects_manager.py @@ -96,6 +96,10 @@ def create_project(self, project_name, project_dir, is_public, namespace): # User friendly error messages if e.http_error == 409: msg = f'Project named "{project_name}" already exists in the workspace "{namespace}".\nPlease try renaming the project.' + elif e.http_error == 422: + dlg = MonthlyContributorsErrorDialog(e) + dlg.exec() + return False elif e.server_code == ErrorCode.ProjectsLimitHit.value: msg = ( "Maximum number of projects reached. Please upgrade your subscription to create new projects.\n" @@ -105,10 +109,6 @@ def create_project(self, project_name, project_dir, is_public, namespace): msg = ( f"{e.detail}\nCurrent limit: {bytes_to_human_size(dlg.exception.server_response['storage_limit'])}" ) - elif e.server_code == ErrorCode.MonthlyContributorsError.value: - dlg = MonthlyContributorsErrorDialog(e) - dlg.exec() - return False QMessageBox.critical(None, "Create Project", "Failed to create Mergin Maps project.\n" + msg) return False except Exception as e: From 1e1253eaf5e4cc79382612211249206f5c63da1e Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Thu, 14 Nov 2024 11:11:47 -0300 Subject: [PATCH 10/15] finalizing dialog usage --- Mergin/monthly_contributors_error_dialog.py | 4 ++-- Mergin/projects_manager.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Mergin/monthly_contributors_error_dialog.py b/Mergin/monthly_contributors_error_dialog.py index 7f8baa2d..c4bbe446 100644 --- a/Mergin/monthly_contributors_error_dialog.py +++ b/Mergin/monthly_contributors_error_dialog.py @@ -4,7 +4,7 @@ from qgis.PyQt.QtCore import QUrl from qgis.PyQt.QtGui import QDesktopServices -ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_monthly_contributors_error_dialog.ui.ui") +ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_monthly_contributors_error_dialog.ui") class MonthlyContributorsErrorDialog(QDialog): @@ -19,7 +19,7 @@ def __init__(self, e, parent=None): self.upgrade_plan_btn.clicked.connect(self.open_upgrade_link) def set_dialog_style(self): - quota = self.server_response.get("projects_quota", "#NA") + quota = self.server_response.get("contributors_quota", "#NA") quota_text = f"{quota}/{quota}" self.plan_quota_progress_bar.setFormat(quota_text) diff --git a/Mergin/projects_manager.py b/Mergin/projects_manager.py index fbb3db82..9ab2f561 100644 --- a/Mergin/projects_manager.py +++ b/Mergin/projects_manager.py @@ -379,6 +379,10 @@ def sync_project(self, project_dir, project_name=None): if dlg.exception.http_error == 400 and "Another process" in dlg.exception.detail: # To note we check for a string since error in flask doesn't return server error code msg = "Somebody else is syncing, please try again later" + elif dlg.exception.http_error == 422: + dlg = MonthlyContributorsErrorDialog(dlg.exception) + dlg.exec() + return elif dlg.exception.server_code == ErrorCode.StorageLimitHit.value: msg = f"{e.detail}\nCurrent limit: {bytes_to_human_size(dlg.exception.server_response['storage_limit'])}" else: From 4491267ed57f7f37f405647d63b946ef2ad749ae Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Fri, 15 Nov 2024 12:05:11 -0300 Subject: [PATCH 11/15] post review updates --- Mergin/help.py | 10 +- Mergin/monthly_contributors_error_dialog.py | 21 +-- .../ui_monthly_contributors_error_dialog.ui | 125 +++++++----------- 3 files changed, 64 insertions(+), 92 deletions(-) diff --git a/Mergin/help.py b/Mergin/help.py index 951da21c..4c3989db 100644 --- a/Mergin/help.py +++ b/Mergin/help.py @@ -1,11 +1,13 @@ -HELP_ROOT = "https://merginmaps.com/docs" - +MAIN_ROOT = "https://merginmaps.com/" class MerginHelp: """Class for generating Mergin plugin help URLs.""" def howto_attachment_widget(self): - return f"{HELP_ROOT}/layer/settingup_forms/" + return f"{MAIN_ROOT}/docs/layer/settingup_forms/" def howto_background_maps(self): - return f"{HELP_ROOT}/gis/settingup_background_map/" + return f"{MAIN_ROOT}/docs/gis/settingup_background_map/" + + def mergin_subscription_link(self): + return f"{MAIN_ROOT}/pricing/" diff --git a/Mergin/monthly_contributors_error_dialog.py b/Mergin/monthly_contributors_error_dialog.py index c4bbe446..d95bb2a7 100644 --- a/Mergin/monthly_contributors_error_dialog.py +++ b/Mergin/monthly_contributors_error_dialog.py @@ -1,11 +1,12 @@ import os from qgis.PyQt import uic -from qgis.PyQt.QtWidgets import QDialog +from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox from qgis.PyQt.QtCore import QUrl from qgis.PyQt.QtGui import QDesktopServices -ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_monthly_contributors_error_dialog.ui") +from .help import MerginHelp +ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_monthly_contributors_error_dialog.ui") class MonthlyContributorsErrorDialog(QDialog): def __init__(self, e, parent=None): @@ -14,15 +15,18 @@ def __init__(self, e, parent=None): self.server_response = e.server_response self.set_dialog_style() - - self.cancel_btn.clicked.connect(self.reject) - self.upgrade_plan_btn.clicked.connect(self.open_upgrade_link) + + self.buttonBox.accepted.connect(self.open_upgrade_link) + self.buttonBox.rejected.connect(self.reject) def set_dialog_style(self): + upgrade_button = self.buttonBox.button(QDialogButtonBox.Ok) + upgrade_button.setText("Upgrade") + quota = self.server_response.get("contributors_quota", "#NA") quota_text = f"{quota}/{quota}" - self.plan_quota_progress_bar.setFormat(quota_text) + self.plan_quota_progress_bar.setStyleSheet( """ QProgressBar { @@ -32,9 +36,8 @@ def set_dialog_style(self): QProgressBar::chunk { background-color: rgb(0, 76, 69); } - """ - ) + """) def open_upgrade_link(self): - QDesktopServices.openUrl(QUrl("https://www.merginmaps.com/pricing")) + QDesktopServices.openUrl(QUrl(MerginHelp().mergin_subscription_link())) self.accept() diff --git a/Mergin/ui/ui_monthly_contributors_error_dialog.ui b/Mergin/ui/ui_monthly_contributors_error_dialog.ui index 280fe942..a3b8c339 100644 --- a/Mergin/ui/ui_monthly_contributors_error_dialog.ui +++ b/Mergin/ui/ui_monthly_contributors_error_dialog.ui @@ -6,43 +6,14 @@ 0 0 - 367 + 366 212 - Monthly Contributors Error + Monthly Contributors Limit Hit - - - - - 0 - 0 - - - - - 16 - 75 - true - - - - You've reached the maximum number of active monthly contributors for your current subscription. - - - Qt::AutoText - - - Qt::AlignCenter - - - true - - - @@ -77,10 +48,10 @@ - - + + - + 0 @@ -88,51 +59,41 @@ - Cancel - - - - - - - true - - - - 0 - 0 - - - - - 100 - 0 - - - - - 200 - 16777215 - - - - - true - - - - Upgrade - - - true - - - false + Monthly Contributors + + + + + 0 + 0 + + + + + 16 + 75 + true + + + + You've reached the maximum number of active monthly contributors for your current subscription. + + + Qt::AutoText + + + Qt::AlignCenter + + + true + + + @@ -144,18 +105,24 @@ for the limit to reset. - - + + - + 0 0 - - Monthly Contributors + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true From c88c027557cee795ea7691a04f8794677566ab32 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Fri, 15 Nov 2024 12:05:46 -0300 Subject: [PATCH 12/15] code formatting --- Mergin/help.py | 3 ++- Mergin/monthly_contributors_error_dialog.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Mergin/help.py b/Mergin/help.py index 4c3989db..3526d18a 100644 --- a/Mergin/help.py +++ b/Mergin/help.py @@ -1,5 +1,6 @@ MAIN_ROOT = "https://merginmaps.com/" + class MerginHelp: """Class for generating Mergin plugin help URLs.""" @@ -8,6 +9,6 @@ def howto_attachment_widget(self): def howto_background_maps(self): return f"{MAIN_ROOT}/docs/gis/settingup_background_map/" - + def mergin_subscription_link(self): return f"{MAIN_ROOT}/pricing/" diff --git a/Mergin/monthly_contributors_error_dialog.py b/Mergin/monthly_contributors_error_dialog.py index d95bb2a7..f3cbdcb9 100644 --- a/Mergin/monthly_contributors_error_dialog.py +++ b/Mergin/monthly_contributors_error_dialog.py @@ -8,6 +8,7 @@ ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_monthly_contributors_error_dialog.ui") + class MonthlyContributorsErrorDialog(QDialog): def __init__(self, e, parent=None): QDialog.__init__(self, parent) @@ -15,14 +16,14 @@ def __init__(self, e, parent=None): self.server_response = e.server_response self.set_dialog_style() - + self.buttonBox.accepted.connect(self.open_upgrade_link) self.buttonBox.rejected.connect(self.reject) def set_dialog_style(self): upgrade_button = self.buttonBox.button(QDialogButtonBox.Ok) upgrade_button.setText("Upgrade") - + quota = self.server_response.get("contributors_quota", "#NA") quota_text = f"{quota}/{quota}" self.plan_quota_progress_bar.setFormat(quota_text) @@ -36,7 +37,8 @@ def set_dialog_style(self): QProgressBar::chunk { background-color: rgb(0, 76, 69); } - """) + """ + ) def open_upgrade_link(self): QDesktopServices.openUrl(QUrl(MerginHelp().mergin_subscription_link())) From f3d6f77854e27e919677b8140ba2b8d4a217e796 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Mon, 18 Nov 2024 10:34:56 -0300 Subject: [PATCH 13/15] reverting dot --- Mergin/configuration_dialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mergin/configuration_dialog.py b/Mergin/configuration_dialog.py index b31f735b..76aaafe6 100644 --- a/Mergin/configuration_dialog.py +++ b/Mergin/configuration_dialog.py @@ -14,7 +14,7 @@ this_dir = os.path.dirname(os.path.realpath(__file__)) path = os.path.join(this_dir, "mergin_client.whl") sys.path.append(path) - from .mergin.client import MerginClient, ClientError, LoginError + from mergin.client import MerginClient, ClientError, LoginError from .utils import ( get_mergin_auth, From f1ea460fb94c5c45d1d4e88218bbbd451dad624b Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Thu, 21 Nov 2024 09:16:33 -0300 Subject: [PATCH 14/15] dialog adjustmenet --- Mergin/monthly_contributors_error_dialog.py | 16 +--- Mergin/projects_manager.py | 4 +- .../ui_monthly_contributors_error_dialog.ui | 75 +++---------------- 3 files changed, 16 insertions(+), 79 deletions(-) diff --git a/Mergin/monthly_contributors_error_dialog.py b/Mergin/monthly_contributors_error_dialog.py index f3cbdcb9..51be755e 100644 --- a/Mergin/monthly_contributors_error_dialog.py +++ b/Mergin/monthly_contributors_error_dialog.py @@ -25,20 +25,8 @@ def set_dialog_style(self): upgrade_button.setText("Upgrade") quota = self.server_response.get("contributors_quota", "#NA") - quota_text = f"{quota}/{quota}" - self.plan_quota_progress_bar.setFormat(quota_text) - - self.plan_quota_progress_bar.setStyleSheet( - """ - QProgressBar { - border: none; - text-align: center; - } - QProgressBar::chunk { - background-color: rgb(0, 76, 69); - } - """ - ) + quota_text = f"You've reached the maximum number of active monthly contributors ({quota}) for your current subscription." + self.label.setText(quota_text) def open_upgrade_link(self): QDesktopServices.openUrl(QUrl(MerginHelp().mergin_subscription_link())) diff --git a/Mergin/projects_manager.py b/Mergin/projects_manager.py index 9ab2f561..c0b5d528 100644 --- a/Mergin/projects_manager.py +++ b/Mergin/projects_manager.py @@ -96,7 +96,7 @@ def create_project(self, project_name, project_dir, is_public, namespace): # User friendly error messages if e.http_error == 409: msg = f'Project named "{project_name}" already exists in the workspace "{namespace}".\nPlease try renaming the project.' - elif e.http_error == 422: + elif e.server_code == ErrorCode.MonthlyContributorsLimitHit.value: dlg = MonthlyContributorsErrorDialog(e) dlg.exec() return False @@ -379,7 +379,7 @@ def sync_project(self, project_dir, project_name=None): if dlg.exception.http_error == 400 and "Another process" in dlg.exception.detail: # To note we check for a string since error in flask doesn't return server error code msg = "Somebody else is syncing, please try again later" - elif dlg.exception.http_error == 422: + elif dlg.exception.server_code == ErrorCode.MonthlyContributorsLimitHit.value: dlg = MonthlyContributorsErrorDialog(dlg.exception) dlg.exec() return diff --git a/Mergin/ui/ui_monthly_contributors_error_dialog.ui b/Mergin/ui/ui_monthly_contributors_error_dialog.ui index a3b8c339..579c443d 100644 --- a/Mergin/ui/ui_monthly_contributors_error_dialog.ui +++ b/Mergin/ui/ui_monthly_contributors_error_dialog.ui @@ -6,60 +6,32 @@ 0 0 - 366 - 212 + 367 + 163 Monthly Contributors Limit Hit - - - - true - - - - 0 - 0 - - - - - 0 - 15 - - - - - 16777215 - 16777215 - - - - - 0 - 15 - - - - 100 - - - - + - + 0 0 - - Monthly Contributors + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true @@ -105,29 +77,6 @@ for the limit to reset. - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - true - - - - - From 193de9aa51c49f1a452e91b59c320761830b2cf9 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Thu, 21 Nov 2024 09:18:59 -0300 Subject: [PATCH 15/15] code formatting --- Mergin/monthly_contributors_error_dialog.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Mergin/monthly_contributors_error_dialog.py b/Mergin/monthly_contributors_error_dialog.py index 51be755e..c0f9bb05 100644 --- a/Mergin/monthly_contributors_error_dialog.py +++ b/Mergin/monthly_contributors_error_dialog.py @@ -25,7 +25,9 @@ def set_dialog_style(self): upgrade_button.setText("Upgrade") quota = self.server_response.get("contributors_quota", "#NA") - quota_text = f"You've reached the maximum number of active monthly contributors ({quota}) for your current subscription." + quota_text = ( + f"You've reached the maximum number of active monthly contributors ({quota}) for your current subscription." + ) self.label.setText(quota_text) def open_upgrade_link(self):