Skip to content

Commit

Permalink
Show message preventing sharing when no workspaces are available
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 11, 2023
1 parent f404147 commit 4daea69
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion felt/core/workspaces_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
Qt,
QAbstractItemModel,
QObject,
QModelIndex
QModelIndex,
pyqtSignal
)
from qgis.PyQt.QtNetwork import (
QNetworkReply
Expand All @@ -37,6 +38,8 @@ class WorkspacesModel(QAbstractItemModel):
UrlRole = Qt.UserRole + 2
IdRole = Qt.UserRole + 4

no_workspaces_found = pyqtSignal()

def __init__(self, parent: Optional[QObject] = None):
super().__init__(parent)

Expand Down Expand Up @@ -81,6 +84,9 @@ def _reply_finished(self, reply: QNetworkReply):

self.endInsertRows()

if not self.workspaces:
self.no_workspaces_found.emit()

# Qt model interface

# pylint: disable=missing-docstring,unused-argument
Expand Down
16 changes: 15 additions & 1 deletion felt/gui/create_map_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def upload_raster_as_styled_toggled():
# pylint: enable=import-outside-toplevel
self.maps_widget = RecentMapsWidget()
self.workspace_combo = WorkspacesComboBox()
self.workspace_combo.no_workspaces_found.connect(self._no_workspace)
self.workspace_combo.workspace_changed.connect(self._workspace_changed)
self.workspace_combo.setFixedHeight(
int(QFontMetrics(self.workspace_combo.font()).height() * 1.5)
Expand Down Expand Up @@ -322,8 +323,21 @@ def _fatal_error(self, error: str):
self.error_label.setText(error)
self.button_box.button(QDialogButtonBox.Ok).deleteLater()

def _validate_initial(self):
def _no_workspace(self):
"""
Called when no workspaces are available
"""
self._fatal_error(
self.tr("You don’t have edit access for any workspaces. "
"Ask your workspace admin for edit access, "
"or create your own workspace."
)
)

def _validate_initial(self):
"""
Performs an initial one-time validated of the environment
"""
error: Optional[str] = None

export_layers = self.layers if self.layers else \
Expand Down
2 changes: 2 additions & 0 deletions felt/gui/workspaces_combo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ class WorkspacesComboBox(QComboBox):
"""

workspace_changed = pyqtSignal(str)
no_workspaces_found = pyqtSignal()

def __init__(self, parent: Optional[QWidget] = None):
super().__init__(parent)

self._model = WorkspacesModel(self)
self._model.no_workspaces_found.connect(self.no_workspaces_found)
self.setModel(self._model)

self.currentIndexChanged.connect(self._index_changed)
Expand Down

0 comments on commit 4daea69

Please sign in to comment.