From 1609a69a76c95ef7a08679f32316c945533fb24f Mon Sep 17 00:00:00 2001 From: ReimarBauer Date: Mon, 9 Dec 2024 15:39:33 +0100 Subject: [PATCH] default all changes and uptodate --- mslib/mscolab/file_manager.py | 3 ++- mslib/msui/mscolab_version_history.py | 9 +++++---- mslib/msui/qt5/ui_mscolab_version_history.py | 15 ++++++-------- mslib/msui/ui/ui_mscolab_version_history.ui | 11 ++-------- .../test_mscolab_version_history.py | 20 ++++++------------- 5 files changed, 21 insertions(+), 37 deletions(-) diff --git a/mslib/mscolab/file_manager.py b/mslib/mscolab/file_manager.py index 2b06fff4c..cbef864d2 100644 --- a/mslib/mscolab/file_manager.py +++ b/mslib/mscolab/file_manager.py @@ -464,9 +464,10 @@ def get_all_changes(self, op_id, user, named_version=False): return False # Get only named versions if named_version: + # the default of version_name is None and e.g. adding waypoints stores it as "None" changes = Change.query\ .filter(Change.op_id == op_id)\ - .filter(~Change.version_name.is_(None))\ + .filter(Change.version_name != "None")\ .order_by(Change.created_at.desc())\ .all() # Get all changes diff --git a/mslib/msui/mscolab_version_history.py b/mslib/msui/mscolab_version_history.py index f2b4b9cd9..4459619c5 100644 --- a/mslib/msui/mscolab_version_history.py +++ b/mslib/msui/mscolab_version_history.py @@ -30,10 +30,10 @@ import requests from urllib.parse import urljoin, urlencode +from PyQt5 import QtCore, QtWidgets, QtGui from mslib.utils.verify_user_token import verify_user_token from mslib.msui.flighttrack import WaypointsTableModel -from PyQt5 import QtCore, QtWidgets, QtGui from mslib.msui.qt5 import ui_mscolab_version_history as ui from mslib.utils.qt import show_popup from mslib.utils.config import config_loader @@ -71,7 +71,7 @@ def __init__(self, token, op_id, user, operation_name, conn, parent=None, self.mscolab_server_url = mscolab_server_url # Event handlers - self.refreshBtn.clicked.connect(self.handle_refresh) + self.conn.signal_reload.connect(self.handle_refresh) self.checkoutBtn.clicked.connect(self.handle_undo) self.nameVersionBtn.clicked.connect(self.handle_named_version) self.deleteVersionNameBtn.clicked.connect(self.handle_delete_version_name) @@ -134,7 +134,7 @@ def load_all_changes(self): "op_id": self.op_id } named_version_only = False - if self.versionFilterCB.currentIndex() == 0: + if self.versionFilterCB.currentIndex() == 1: named_version_only = True query_string = urlencode({"named_version": named_version_only}) url_path = f'get_all_changes?{query_string}' @@ -149,7 +149,8 @@ def load_all_changes(self): date = local_time.strftime('%d/%m/%Y') time = local_time.strftime('%I:%M %p') item_text = f'{change["username"]} made change on {date} at {time}' - if change["version_name"] is not None: + # default is None, but adding waypoints uses str(None) + if str(change["version_name"]) != 'None': item_text = f'{change["version_name"]}\n{item_text}' item = QtWidgets.QListWidgetItem(item_text, parent=self.changes) item.id = change["id"] diff --git a/mslib/msui/qt5/ui_mscolab_version_history.py b/mslib/msui/qt5/ui_mscolab_version_history.py index d3ddccbfe..fa7dfceb2 100644 --- a/mslib/msui/qt5/ui_mscolab_version_history.py +++ b/mslib/msui/qt5/ui_mscolab_version_history.py @@ -2,9 +2,10 @@ # Form implementation generated from reading ui file 'ui_mscolab_version_history.ui' # -# Created by: PyQt5 UI code generator 5.12.3 +# Created by: PyQt5 UI code generator 5.15.9 # -# WARNING! All changes made in this file will be lost! +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. from PyQt5 import QtCore, QtGui, QtWidgets @@ -55,9 +56,6 @@ def setupUi(self, MscolabVersionHistory): self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.verticalLayout_2 = QtWidgets.QVBoxLayout() self.verticalLayout_2.setObjectName("verticalLayout_2") - self.refreshBtn = QtWidgets.QPushButton(self.centralwidget) - self.refreshBtn.setObjectName("refreshBtn") - self.verticalLayout_2.addWidget(self.refreshBtn) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.label = QtWidgets.QLabel(self.centralwidget) @@ -137,7 +135,7 @@ def setupUi(self, MscolabVersionHistory): MscolabVersionHistory.addAction(self.actionCloseWindow) self.retranslateUi(MscolabVersionHistory) - self.actionCloseWindow.triggered.connect(MscolabVersionHistory.close) + self.actionCloseWindow.triggered.connect(MscolabVersionHistory.close) # type: ignore QtCore.QMetaObject.connectSlotsByName(MscolabVersionHistory) def retranslateUi(self, MscolabVersionHistory): @@ -145,10 +143,9 @@ def retranslateUi(self, MscolabVersionHistory): MscolabVersionHistory.setWindowTitle(_translate("MscolabVersionHistory", "Version History")) self.usernameLabel.setText(_translate("MscolabVersionHistory", "Logged In: ")) self.operationNameLabel.setText(_translate("MscolabVersionHistory", "Operation:")) - self.refreshBtn.setText(_translate("MscolabVersionHistory", "Refresh Window")) self.label.setText(_translate("MscolabVersionHistory", "Viewing:")) - self.versionFilterCB.setItemText(0, _translate("MscolabVersionHistory", "Named Versions")) - self.versionFilterCB.setItemText(1, _translate("MscolabVersionHistory", "All Changes")) + self.versionFilterCB.setItemText(0, _translate("MscolabVersionHistory", "All Changes")) + self.versionFilterCB.setItemText(1, _translate("MscolabVersionHistory", "Named Versions")) self.label_3.setText(_translate("MscolabVersionHistory", "Current Waypoints:")) self.label_2.setText(_translate("MscolabVersionHistory", "Version Preview:")) self.deleteVersionNameBtn.setToolTip(_translate("MscolabVersionHistory", "Delete the name of the selected version")) diff --git a/mslib/msui/ui/ui_mscolab_version_history.ui b/mslib/msui/ui/ui_mscolab_version_history.ui index 04163a6de..bf2fb827a 100644 --- a/mslib/msui/ui/ui_mscolab_version_history.ui +++ b/mslib/msui/ui/ui_mscolab_version_history.ui @@ -77,13 +77,6 @@ - - - - Refresh Window - - - @@ -103,12 +96,12 @@ - Named Versions + All Changes - All Changes + Named Versions diff --git a/tests/_test_msui/test_mscolab_version_history.py b/tests/_test_msui/test_mscolab_version_history.py index 6e672e053..1378aa67e 100644 --- a/tests/_test_msui/test_mscolab_version_history.py +++ b/tests/_test_msui/test_mscolab_version_history.py @@ -66,14 +66,13 @@ def setup(self, qtbot, mscolab_server): self.window.mscolab.conn.disconnect() def test_changes(self, qtbot): - self._change_version_filter(1) + self._change_version_filter(0) len_prev = self.version_window.changes.count() # make a changes self.window.mscolab.waypoints_model.invert_direction() self.window.mscolab.waypoints_model.invert_direction() def assert_(): - self.version_window.load_all_changes() len_after = self.version_window.changes.count() assert len_prev == (len_after - 2) qtbot.wait_until(assert_) @@ -83,16 +82,18 @@ def test_set_version_name(self, qtbot): def test_version_name_delete(self, qtbot): self._set_version_name(qtbot) + self._activate_change_at_index(0) QtTest.QTest.mouseClick(self.version_window.deleteVersionNameBtn, QtCore.Qt.LeftButton) def assert_(): assert self.version_window.changes.count() == 1 - assert self.version_window.changes.currentItem().version_name is None + self._activate_change_at_index(0) + assert str(self.version_window.changes.currentItem().version_name) == "None" qtbot.wait_until(assert_) @mock.patch("PyQt5.QtWidgets.QMessageBox.question", return_value=QtWidgets.QMessageBox.Yes) def test_undo_changes(self, mockbox, qtbot): - self._change_version_filter(1) + self._change_version_filter(0) assert self.version_window.changes.count() == 0 # make changes for i in range(2): @@ -108,15 +109,6 @@ def assert_(): new_changes_count = self.version_window.changes.count() assert changes_count + 1 == new_changes_count - def test_refresh(self): - self._change_version_filter(1) - changes_count = self.version_window.changes.count() - self.window.mscolab.waypoints_model.invert_direction() - self.window.mscolab.waypoints_model.invert_direction() - QtTest.QTest.mouseClick(self.version_window.refreshBtn, QtCore.Qt.LeftButton) - new_changes_count = self.version_window.changes.count() - assert new_changes_count == changes_count + 2 - def _connect_to_mscolab(self, qtbot): self.connect_window = mscolab.MSColab_ConnectDialog(parent=self.window, mscolab=self.window.mscolab) self.window.mscolab.connect_window = self.connect_window @@ -158,7 +150,7 @@ def _change_version_filter(self, index): self.version_window.versionFilterCB.currentIndexChanged.emit(index) def _set_version_name(self, qtbot): - self._change_version_filter(1) + self._change_version_filter(0) num_changes_before = self.version_window.changes.count() # make a changes self.window.mscolab.waypoints_model.invert_direction()