Skip to content

Commit

Permalink
import to mscolab uses the filename as version name
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimarBauer committed Dec 9, 2024
1 parent ca9db4a commit 561d739
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions mslib/mscolab/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def get_authorized_users(self, op_id):
"id": permission.u_id})
return users

def save_file(self, op_id, content, user, comment=""):
def save_file(self, op_id, content, user, version_name=None, comment=""):
"""
op_id: operation-id,
content: content of the file to be saved
Expand Down Expand Up @@ -427,7 +427,7 @@ def save_file(self, op_id, content, user, comment=""):
repo.index.add(['main.ftml'])
cm = repo.index.commit("committing changes")
# change db table
change = Change(op_id, user.id, cm.hexsha)
change = Change(op_id, user.id, cm.hexsha, version_name=version_name)
db.session.add(change)
db.session.commit()
return True
Expand Down
3 changes: 2 additions & 1 deletion mslib/mscolab/sockets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,14 @@ def handle_file_save(self, json_req):
op_id = json_req['op_id']
content = json_req['content']
comment = json_req.get('comment', "")
version_name = json_req.get('version_name', None)
messageText = json_req.get('messageText')
user = User.verify_auth_token(json_req['token'])
if user is not None:
# when the socket connection is expired this in None and also on wrong tokens
perm = self.permission_check_emit(user.id, int(op_id))
# if permission is correct and file saved properly
if perm and self.fm.save_file(int(op_id), content, user, comment):
if perm and self.fm.save_file(int(op_id), content, user, version_name=version_name, comment=comment):
# send service message
message_ = f"[service message] **{user.username}** saved changes. {messageText}"
new_message = self.cm.add_message(user, message_, str(op_id), message_type=MessageType.SYSTEM_MESSAGE)
Expand Down
7 changes: 3 additions & 4 deletions mslib/msui/mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1905,14 +1905,13 @@ def reload_wps_from_server(self):
self.reload_view_windows()

@verify_user_token
def handle_waypoints_changed(self, _1=None, _2=None, _3=None):
def handle_waypoints_changed(self, _1=None, _2=None, _3=None, version_name=None):
logging.debug("handle_waypoints_changed")
if self.ui.workLocallyCheckbox.isChecked():
self.waypoints_model.save_to_ftml(self.local_ftml_file)
else:
xml_content = self.waypoints_model.get_xml_content()
self.conn.save_file(self.token, self.active_op_id, xml_content, comment=None,
messageText=self.lastChangeMessage)
self.conn.save_file(self.token, self.active_op_id, xml_content, version_name=version_name, comment=None)
# Reset the last change message to make sure that it is used only once
self.lastChangeMessage = ""

Expand Down Expand Up @@ -1964,7 +1963,7 @@ def handle_import_msc(self, file_path, extension, function, pickertype):
self.waypoints_model.dataChanged.disconnect(self.handle_waypoints_changed)
self.waypoints_model = model
self.waypoints_model.changeMessageSignal.connect(self.handle_change_message)
self.handle_waypoints_changed()
self.handle_waypoints_changed(version_name=file_name)
self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
self.reload_view_windows()
show_popup(self.ui, "Import Success", f"The file - {file_name}, was imported successfully!", 1)
Expand Down
3 changes: 2 additions & 1 deletion mslib/msui/socket_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def select_operation(self, op_id):
# Emit an event to notify the server of the operation selection.
self.sio.emit('operation-selected', {'token': self.token, 'op_id': op_id})

def save_file(self, token, op_id, content, comment=None, messageText=""):
def save_file(self, token, op_id, content, comment=None, version_name=None, messageText=""):
# ToDo refactor API
if verify_user_token(self.mscolab_server_url, self.token):
logging.debug("saving file")
Expand All @@ -212,6 +212,7 @@ def save_file(self, token, op_id, content, comment=None, messageText=""):
"token": self.token,
"content": content,
"comment": comment,
"version_name": version_name,
"messageText": messageText})
else:
# this triggers disconnect
Expand Down

0 comments on commit 561d739

Please sign in to comment.