Skip to content

Commit

Permalink
Merge pull request #321 from opengisch/fix_update_project
Browse files Browse the repository at this point in the history
Fixes while updating the project details
  • Loading branch information
suricactus authored Sep 20, 2021
2 parents d4ba7f7 + 4ab2f4c commit d6e4ea2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ qfield-sync.*.zip
qfieldsync/resources_rc.py

.vscode/**
.qt_for_python/**
82 changes: 45 additions & 37 deletions qfieldsync/gui/cloud_projects_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ def __init__(
self.localDirLineEdit.textChanged.connect(
lambda: self.on_local_dir_line_edit_text_changed()
)
self.localDirLineEdit.editingFinished.connect(
lambda: self.on_local_dir_line_edit_editing_finished()
)
self.localDirButton.clicked.connect(lambda: self.on_local_dir_button_clicked())
self.localDirButton.setMenu(QMenu())
self.localDirButton.setPopupMode(QToolButton.MenuButtonPopup)
Expand Down Expand Up @@ -516,12 +513,6 @@ def on_local_dir_line_edit_text_changed(self) -> None:
local_dir = self.localDirLineEdit.text()
self.update_local_dir_feedback(local_dir)

def on_local_dir_line_edit_editing_finished(self) -> None:
local_dir = self.localDirLineEdit.text()

if self.current_cloud_project:
self.current_cloud_project.update_data({"local_dir": local_dir})

def on_local_dir_button_clicked(self) -> None:
dirname = self.select_local_dir()
if dirname:
Expand Down Expand Up @@ -839,39 +830,54 @@ def on_back_button_clicked(self) -> None:
def on_submit_button_clicked(self) -> None:
assert self.current_cloud_project

cloud_project_data = {
"name": self.projectNameLineEdit.text(),
"description": self.projectDescriptionTextEdit.toPlainText(),
"local_dir": self.localDirLineEdit.text(),
}

should_update_online = False
if (
self.projectNameLineEdit.validator().validate(
cloud_project_data["name"], 0
)[0]
!= QValidator.Acceptable
self.current_cloud_project.name != self.projectNameLineEdit.text()
or self.current_cloud_project.description
!= self.projectDescriptionTextEdit.toPlainText()
):
QMessageBox.warning(
None,
self.tr("Invalid project name"),
self.tr(
"You cannot create a new project without setting a valid name first."
),
cloud_project_data = {
"name": self.projectNameLineEdit.text(),
"description": self.projectDescriptionTextEdit.toPlainText(),
}

if (
self.projectNameLineEdit.validator().validate(
cloud_project_data["name"], 0
)[0]
!= QValidator.Acceptable
):
QMessageBox.warning(
None,
self.tr("Invalid project name"),
self.tr(
"You cannot create a new project without setting a valid name first."
),
)
return

self.projectsFormPage.setEnabled(False)
self.feedbackLabel.setVisible(True)

self.current_cloud_project.update_data(cloud_project_data)
self.feedbackLabel.setText(self.tr("Updating project…"))

reply = self.network_manager.update_project(
self.current_cloud_project.id,
self.current_cloud_project.name,
self.current_cloud_project.description,
)
return
reply.finished.connect(lambda: self.on_update_project_finished(reply))

self.projectsFormPage.setEnabled(False)
self.feedbackLabel.setVisible(True)
should_update_online = True

self.current_cloud_project.update_data(cloud_project_data)
self.feedbackLabel.setText(self.tr("Updating project…"))
if self.current_cloud_project.local_dir != self.localDirLineEdit.text():
self.current_cloud_project.update_data(
{"local_dir": self.localDirLineEdit.text()}
)

reply = self.network_manager.update_project(
self.current_cloud_project.id,
self.current_cloud_project.name,
self.current_cloud_project.description,
)
reply.finished.connect(lambda: self.on_update_project_finished(reply))
if not should_update_online:
self.projectsStack.setCurrentWidget(self.projectsListPage)

def on_edit_online_button_clicked(self) -> None:
assert self.current_cloud_project
Expand Down Expand Up @@ -1026,7 +1032,9 @@ def show_sync_popup(self) -> None:
self.transfer_dialog.open()

def update_local_dir_feedback(self, local_dir: str) -> None:
feedback, feedback_msg = local_dir_feedback(local_dir)
feedback, feedback_msg = local_dir_feedback(
local_dir, no_path_status=LocalDirFeedback.Warning
)
self.localDirFeedbackLabel.setText(feedback_msg)

if feedback == LocalDirFeedback.Error:
Expand Down
3 changes: 3 additions & 0 deletions qfieldsync/ui/cloud_projects_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@
</item>
<item>
<widget class="QCheckBox" name="projectIsPrivateCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Private</string>
</property>
Expand Down

0 comments on commit d6e4ea2

Please sign in to comment.