use project name in site sync calls

This commit is contained in:
Jakub Trllo 2024-11-22 17:59:47 +01:00
parent 7935ed3284
commit b25715ee2b
3 changed files with 29 additions and 15 deletions

View file

@ -132,7 +132,6 @@ class InventoryModel(QtGui.QStandardItemModel):
# for debugging or testing, injecting items from outside
container_items = self._controller.get_container_items()
self._clear_items()
repre_ids = set()
repre_ids_by_project = collections.defaultdict(set)
version_items_by_product_id = collections.defaultdict(dict)
repre_info_by_id_by_project = collections.defaultdict(dict)
@ -146,7 +145,6 @@ class InventoryModel(QtGui.QStandardItemModel):
# continue
project_name = container_item.project_name
representation_id = container_item.representation_id
repre_ids.add(representation_id)
repre_ids_by_project[project_name].add(representation_id)
item_by_repre_id_by_project_id[project_name][representation_id].add(container_item)
@ -167,9 +165,13 @@ class InventoryModel(QtGui.QStandardItemModel):
version_items_by_product_id[project_name] = version_items
# SiteSync addon information
progress_by_id = self._controller.get_representations_site_progress(
repre_ids
)
progress_by_project = {}
for project_name, repre_ids in repre_ids_by_project.items():
progress_by_id = self._controller.get_representations_site_progress(
project_name, repre_ids
)
progress_by_project[project_name] = progress_by_id
sites_info = self._controller.get_sites_information()
site_icons = {
provider: get_qt_icon(icon_def)
@ -207,6 +209,7 @@ class InventoryModel(QtGui.QStandardItemModel):
root_item = self.invisibleRootItem()
group_items = []
for project_name, items_by_repre_id in item_by_repre_id_by_project_id.items():
progress_by_id = progress_by_project[project_name]
for repre_id, container_items in items_by_repre_id.items():
repre_info = repre_info_by_id_by_project[project_name][repre_id]
version_color = None

View file

@ -103,7 +103,7 @@ class SiteSyncModel:
active_site = self._get_active_site()
remote_site = self._get_remote_site()
progress = self.get_representations_site_progress(
representation_ids
project_name, representation_ids
)
for repre_id in representation_ids:
repre_progress = progress.get(repre_id)

View file

@ -413,12 +413,13 @@ class SceneInventoryView(QtWidgets.QTreeView):
self._handle_sitesync(menu, valid_repre_ids)
def _handle_sitesync(self, menu, repre_ids):
def _handle_sitesync(self, menu, repre_ids_by_project_name):
"""Adds actions for download/upload when SyncServer is enabled
Args:
menu (OptionMenu)
repre_ids (list) of object_ids
repre_ids_by_project_name (Dict[str, Set[str]]): Representation
ids by project name.
Returns:
(OptionMenu)
@ -427,7 +428,7 @@ class SceneInventoryView(QtWidgets.QTreeView):
if not self._controller.is_sitesync_enabled():
return
if not repre_ids:
if not repre_ids_by_project_name:
return
menu.addSeparator()
@ -439,7 +440,10 @@ class SceneInventoryView(QtWidgets.QTreeView):
menu
)
download_active_action.triggered.connect(
lambda: self._add_sites(repre_ids, "active_site"))
lambda: self._add_sites(
repre_ids_by_project_name, "active_site"
)
)
upload_icon = qtawesome.icon("fa.upload", color=DEFAULT_COLOR)
upload_remote_action = QtWidgets.QAction(
@ -448,23 +452,30 @@ class SceneInventoryView(QtWidgets.QTreeView):
menu
)
upload_remote_action.triggered.connect(
lambda: self._add_sites(repre_ids, "remote_site"))
lambda: self._add_sites(
repre_ids_by_project_name, "remote_site"
)
)
menu.addAction(download_active_action)
menu.addAction(upload_remote_action)
def _add_sites(self, repre_ids, site_type):
def _add_sites(self, repre_ids_by_project_name, site_type):
"""(Re)sync all 'repre_ids' to specific site.
It checks if opposite site has fully available content to limit
accidents. (ReSync active when no remote >> losing active content)
Args:
repre_ids (list)
repre_ids_by_project_name (Dict[str, Set[str]]): Representation
ids by project name.
site_type (Literal[active_site, remote_site]): Site type.
"""
self._controller.resync_representations(repre_ids, site_type)
"""
for project_name, repre_ids in repre_ids_by_project_name.items():
self._controller.resync_representations(
project_name, repre_ids, site_type
)
self.data_changed.emit()