Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #141 from pypeclub/feature/220_from_master_to_eq
Browse files Browse the repository at this point in the history
Feature/220 from master to eq
  • Loading branch information
mkolar authored Jul 28, 2020
2 parents 0a423bf + a32afc5 commit 5d38e1d
Showing 1 changed file with 76 additions and 5 deletions.
81 changes: 76 additions & 5 deletions avalon/tools/sceneinventory/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,75 @@ def build_item_menu_for_selection(self, items, menu):
if has_outdated:
break

updatetolatest_action = None
switch_to_versioned = None
if has_loaded_master_versions:
def _on_switch_to_versioned(items):
repre_ids = []
for item in items:
item_id = io.ObjectId(item["representation"])
if item_id not in repre_ids:
repre_ids.append(item_id)

repre_entities = io.find({
"type": "representation",
"_id": {"$in": repre_ids}
})

version_ids = []
version_id_by_repre_id = {}
for repre in repre_entities:
version_id = repre["parent"]
version_id_by_repre_id[repre["_id"]] = version_id
if version_id not in version_ids:
version_ids.append(version_id)

master_versions = list(io.find({
"_id": {"$in": version_ids},
"type": "master_version"
}))

version_ids = set()
for master_version in master_versions:
version_id = master_version["version_id"]
version_ids.add(version_id)
master_version_id = master_version["_id"]
for _repre_id, _version_id in (
version_id_by_repre_id.items()
):
if _version_id == master_version_id:
version_id_by_repre_id[_repre_id] = version_id

version_docs = io.find({
"_id": {"$in": list(version_ids)},
"type": "version"
})
version_name_by_id = {}
for version in version_docs:
version_name_by_id[version["_id"]] = version["name"]

for item in items:
repre_id = io.ObjectId(item["representation"])
version_id = version_id_by_repre_id.get(repre_id)
version_name = version_name_by_id.get(version_id)
if version_name is not None:
api.update(item, version_name)

self.data_changed.emit()

update_icon = qtawesome.icon(
"fa.asterisk",
color=DEFAULT_COLOR
)
switch_to_versioned = QtWidgets.QAction(
update_icon,
"Switch to versioned",
menu
)
switch_to_versioned.triggered.connect(
lambda: _on_switch_to_versioned(items)
)

update_to_latest_action = None
if has_outdated or has_loaded_master_versions:
# update to latest version
def _on_update_to_latest(items):
Expand All @@ -133,12 +201,12 @@ def _on_update_to_latest(items):
"fa.angle-double-up",
color=DEFAULT_COLOR
)
updatetolatest_action = QtWidgets.QAction(
update_to_latest_action = QtWidgets.QAction(
update_icon,
"Update to latest",
menu
)
updatetolatest_action.triggered.connect(
update_to_latest_action.triggered.connect(
lambda: _on_update_to_latest(items)
)

Expand Down Expand Up @@ -191,8 +259,11 @@ def _on_update_to_master(items):
lambda: self.show_remove_warning_dialog(items))

# add the actions
if updatetolatest_action:
menu.addAction(updatetolatest_action)
if switch_to_versioned:
menu.addAction(switch_to_versioned)

if update_to_latest_action:
menu.addAction(update_to_latest_action)

if change_to_master:
menu.addAction(change_to_master)
Expand Down

0 comments on commit 5d38e1d

Please sign in to comment.