Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinBuira committed Nov 4, 2024
1 parent 082f58d commit 44193ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
5 changes: 2 additions & 3 deletions Mergin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ def format_datetime(date_string):

def parse_user_agent(user_agent: str) -> str:
browsers = ["Chrome", "Firefox", "Mozilla", "Opera", "Safari", "Webkit"]
if any([ browser in user_agent for browser in browsers]):
if any([browser in user_agent for browser in browsers]):
return "Web dashboard"
elif "Input" in user_agent:
return "Mobile app"
Expand All @@ -1571,6 +1571,5 @@ def parse_user_agent(user_agent: str) -> str:
return "Synced from Media Sync"
elif "Python-client" in user_agent:
return "Mergin Maps Python Client"
else: # For uncommon user agent we display user agent as is
else: # For uncommon user agent we display user agent as is
return user_agent

35 changes: 15 additions & 20 deletions Mergin/version_viewer_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
QMenu,
QMessageBox,
QAbstractItemView,
QToolButton
QToolButton,
)
from qgis.PyQt.QtGui import QStandardItem, QStandardItemModel, QIcon, QFont, QColor
from qgis.PyQt.QtCore import (
Expand Down Expand Up @@ -211,35 +211,32 @@ class VersionsFetcher(QThread):

finished = pyqtSignal(list)

def __init__(
self,
mc: MerginClient,
project_path,
model : VersionsTableModel
):
def __init__(self, mc: MerginClient, project_path, model: VersionsTableModel):
super(VersionsFetcher, self).__init__()
self.mc = mc
self.project_path = project_path
self.model = model

self.current_page = 1
self.per_page = 50
self.current_page = 1
self.per_page = 50

version_count = self.mc.project_versions_count(self.project_path)
self.nb_page = math.ceil(version_count / self.per_page)

def run(self):
self.fetch_another_page()

def has_more_page(self):
return self.current_page <= self.nb_page

def fetch_another_page(self):
if self.has_more_page() == False:
return
versions = self.mc.project_versions_page(self.project_path, self.current_page, per_page=self.per_page, descending=True)
versions = self.mc.project_versions_page(
self.project_path, self.current_page, per_page=self.per_page, descending=True
)
self.model.add_versions(versions)

self.current_page += 1


Expand Down Expand Up @@ -291,13 +288,13 @@ def __init__(self, mc, parent=None):
self.toggle_layers_action.setChecked(True)
self.toggle_layers_action.toggled.connect(self.toggle_project_layers)

#We use a ToolButton instead of simple action to dislay both icon AND text
# We use a ToolButton instead of simple action to dislay both icon AND text
self.toggle_layers_button = QToolButton()
self.toggle_layers_button.setDefaultAction(self.toggle_layers_action)
self.toggle_layers_button.setText("Show projecct layers")
self.toggle_layers_button.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
self.toolbar.addWidget(self.toggle_layers_button)

self.toolbar.addSeparator()

self.zoom_full_action = QAction(QgsApplication.getThemeIcon("/mActionZoomFullExtent.svg"), "Zoom Full", self)
Expand Down Expand Up @@ -350,21 +347,21 @@ def __init__(self, mc, parent=None):
self.versionModel.current_version = self.mp.version()

def exec(self):

try:
ws_id = self.mp.workspace_id()
except ClientError as e:
QMessageBox.warning(None, "Client Error", str(e))
return

# check if user has permissions
try:
try:
usage = self.mc.workspace_usage(ws_id)
if not usage["view_history"]["allowed"]:
QMessageBox.warning(None, "Permission Error", "The workspace does not allow to view project history.")
return
except ClientError:
# Some versions e.g CE, EE edition doesn't have
except ClientError:
# Some versions e.g CE, EE edition doesn't have
pass
super().exec()

Expand Down Expand Up @@ -405,7 +402,6 @@ def on_scrollbar_changed(self, value):
if self.ui.history_treeview.verticalScrollBar().maximum() <= value:
self.fetch_from_server()


def current_version_changed(self, current_index, previous_index):
# Update the ui when the selected version change
item = self.versionModel.item_from_index(current_index)
Expand Down Expand Up @@ -439,7 +435,6 @@ def populate_details(self):
self.edit_user_agent.setText(parse_user_agent(self.version_details["user_agent"]))
self.edit_user_agent.setToolTip(self.version_details["user_agent"])


self.model_detail.clear()
root_item = QStandardItem(f"Changes in version {self.version_details['name']}")
self.model_detail.appendRow(root_item)
Expand Down

0 comments on commit 44193ce

Please sign in to comment.