mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
separate logic for workare and publishe workfiles
This commit is contained in:
parent
ece086c03f
commit
0cc99003f6
1 changed files with 131 additions and 104 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from qtpy import QtCore, QtWidgets
|
from qtpy import QtCore, QtWidgets
|
||||||
|
|
||||||
|
|
@ -7,7 +8,11 @@ def file_size_to_string(file_size):
|
||||||
if not file_size:
|
if not file_size:
|
||||||
return "N/A"
|
return "N/A"
|
||||||
size = 0
|
size = 0
|
||||||
size_ending_mapping = {"KB": 1024**1, "MB": 1024**2, "GB": 1024**3}
|
size_ending_mapping = {
|
||||||
|
"KB": 1024**1,
|
||||||
|
"MB": 1024**2,
|
||||||
|
"GB": 1024**3,
|
||||||
|
}
|
||||||
ending = "B"
|
ending = "B"
|
||||||
for _ending, _size in size_ending_mapping.items():
|
for _ending, _size in size_ending_mapping.items():
|
||||||
if file_size < _size:
|
if file_size < _size:
|
||||||
|
|
@ -66,7 +71,8 @@ class SidePanelWidget(QtWidgets.QWidget):
|
||||||
btn_description_save.clicked.connect(self._on_save_click)
|
btn_description_save.clicked.connect(self._on_save_click)
|
||||||
|
|
||||||
controller.register_event_callback(
|
controller.register_event_callback(
|
||||||
"selection.workarea.changed", self._on_workarea_selection_change
|
"selection.workarea.changed",
|
||||||
|
self._on_workarea_selection_change
|
||||||
)
|
)
|
||||||
controller.register_event_callback(
|
controller.register_event_callback(
|
||||||
"selection.representation.changed",
|
"selection.representation.changed",
|
||||||
|
|
@ -86,9 +92,9 @@ class SidePanelWidget(QtWidgets.QWidget):
|
||||||
self._orig_description = ""
|
self._orig_description = ""
|
||||||
self._controller = controller
|
self._controller = controller
|
||||||
|
|
||||||
self._set_context(None, None, None, None, None)
|
self._set_context(False, None, None)
|
||||||
|
|
||||||
def set_published_mode(self, published_mode):
|
def set_published_mode(self, published_mode: bool) -> None:
|
||||||
"""Change published mode.
|
"""Change published mode.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
@ -97,7 +103,19 @@ class SidePanelWidget(QtWidgets.QWidget):
|
||||||
|
|
||||||
self._description_widget.setVisible(not published_mode)
|
self._description_widget.setVisible(not published_mode)
|
||||||
# Clear the context when switching modes to avoid showing stale data
|
# Clear the context when switching modes to avoid showing stale data
|
||||||
self._set_context(None, None, None, None, None)
|
if published_mode:
|
||||||
|
self._set_publish_context(
|
||||||
|
self._folder_id,
|
||||||
|
self._task_id,
|
||||||
|
self._representation_id,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._set_workarea_context(
|
||||||
|
self._folder_id,
|
||||||
|
self._task_id,
|
||||||
|
self._rootless_path,
|
||||||
|
self._filepath,
|
||||||
|
)
|
||||||
|
|
||||||
def _on_workarea_selection_change(self, event):
|
def _on_workarea_selection_change(self, event):
|
||||||
folder_id = event["folder_id"]
|
folder_id = event["folder_id"]
|
||||||
|
|
@ -105,12 +123,16 @@ class SidePanelWidget(QtWidgets.QWidget):
|
||||||
filepath = event["path"]
|
filepath = event["path"]
|
||||||
rootless_path = event["rootless_path"]
|
rootless_path = event["rootless_path"]
|
||||||
|
|
||||||
self._set_context(folder_id, task_id, rootless_path, filepath, None)
|
self._set_workarea_context(
|
||||||
|
folder_id, task_id, rootless_path, filepath
|
||||||
|
)
|
||||||
|
|
||||||
def _on_representation_selection_change(self, event):
|
def _on_representation_selection_change(self, event):
|
||||||
|
folder_id = event["folder_id"]
|
||||||
|
task_id = event["task_id"]
|
||||||
representation_id = event["representation_id"]
|
representation_id = event["representation_id"]
|
||||||
|
|
||||||
self._set_context(None, None, None, None, representation_id)
|
self._set_publish_context(folder_id, task_id, representation_id)
|
||||||
|
|
||||||
def _on_description_change(self):
|
def _on_description_change(self):
|
||||||
text = self._description_input.toPlainText()
|
text = self._description_input.toPlainText()
|
||||||
|
|
@ -126,130 +148,135 @@ class SidePanelWidget(QtWidgets.QWidget):
|
||||||
self._orig_description = description
|
self._orig_description = description
|
||||||
self._btn_description_save.setEnabled(False)
|
self._btn_description_save.setEnabled(False)
|
||||||
|
|
||||||
def _set_context(
|
def _set_workarea_context(
|
||||||
self, folder_id, task_id, rootless_path, filepath, representation_id
|
self,
|
||||||
):
|
folder_id: Optional[str],
|
||||||
workfile_info = None
|
task_id: Optional[str],
|
||||||
published_workfile_info = None
|
rootless_path: Optional[str],
|
||||||
|
filepath: Optional[str],
|
||||||
|
) -> None:
|
||||||
|
self._rootless_path = rootless_path
|
||||||
|
self._filepath = filepath
|
||||||
|
|
||||||
# Check if folder, task and file are selected (workarea mode)
|
workfile_info = None
|
||||||
|
# Check if folder, task and file are selected
|
||||||
if folder_id and task_id and rootless_path:
|
if folder_id and task_id and rootless_path:
|
||||||
workfile_info = self._controller.get_workfile_info(
|
workfile_info = self._controller.get_workfile_info(
|
||||||
folder_id, task_id, rootless_path
|
folder_id, task_id, rootless_path
|
||||||
)
|
)
|
||||||
# Check if representation is selected (published mode)
|
|
||||||
elif representation_id:
|
|
||||||
published_workfile_info = (
|
|
||||||
self._controller.get_published_workfile_info(representation_id)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get version comment for published workfiles
|
if workfile_info is None:
|
||||||
version_comment = None
|
|
||||||
if representation_id and published_workfile_info:
|
|
||||||
version_comment = (
|
|
||||||
self._controller.get_published_workfile_version_comment(
|
|
||||||
representation_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
enabled = (
|
|
||||||
workfile_info is not None or published_workfile_info is not None
|
|
||||||
)
|
|
||||||
|
|
||||||
self._details_input.setEnabled(enabled)
|
|
||||||
self._description_input.setEnabled(workfile_info is not None)
|
|
||||||
self._btn_description_save.setEnabled(workfile_info is not None)
|
|
||||||
|
|
||||||
self._folder_id = folder_id
|
|
||||||
self._task_id = task_id
|
|
||||||
self._filepath = filepath
|
|
||||||
self._rootless_path = rootless_path
|
|
||||||
self._representation_id = representation_id
|
|
||||||
|
|
||||||
# Disable inputs and remove texts if any required arguments are
|
|
||||||
# missing
|
|
||||||
if not enabled:
|
|
||||||
self._orig_description = ""
|
self._orig_description = ""
|
||||||
self._details_input.setPlainText("")
|
|
||||||
self._description_input.setPlainText("")
|
self._description_input.setPlainText("")
|
||||||
|
self._set_context(False, folder_id, task_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Use published workfile info if available, otherwise use workarea
|
self._set_context(
|
||||||
# info
|
True,
|
||||||
info = (
|
folder_id,
|
||||||
published_workfile_info
|
task_id,
|
||||||
if published_workfile_info
|
file_created = workfile_info.file_created,
|
||||||
else workfile_info
|
file_modified=workfile_info.file_modified,
|
||||||
|
size_value=workfile_info.file_size,
|
||||||
|
created_by=workfile_info.created_by,
|
||||||
|
updated_by=workfile_info.updated_by,
|
||||||
)
|
)
|
||||||
|
|
||||||
description = info.description if hasattr(info, "description") else ""
|
description = workfile_info.description
|
||||||
size_value = file_size_to_string(info.file_size)
|
self._orig_description = description
|
||||||
|
self._description_input.setPlainText(description)
|
||||||
|
|
||||||
|
def _set_publish_context(
|
||||||
|
self,
|
||||||
|
folder_id: Optional[str],
|
||||||
|
task_id: Optional[str],
|
||||||
|
representation_id: Optional[str],
|
||||||
|
) -> None:
|
||||||
|
self._representation_id = representation_id
|
||||||
|
published_workfile_wrap = self._controller.get_published_workfile_info(
|
||||||
|
folder_id,
|
||||||
|
representation_id,
|
||||||
|
)
|
||||||
|
info = published_workfile_wrap.info
|
||||||
|
comment = published_workfile_wrap.comment
|
||||||
|
if info is None:
|
||||||
|
self._set_context(False, folder_id, task_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
self._set_context(
|
||||||
|
True,
|
||||||
|
folder_id,
|
||||||
|
task_id,
|
||||||
|
file_created=info.file_created,
|
||||||
|
file_modified=info.file_modified,
|
||||||
|
size_value=info.file_size,
|
||||||
|
created_by=info.author,
|
||||||
|
comment=comment,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _set_context(
|
||||||
|
self,
|
||||||
|
is_valid: bool,
|
||||||
|
folder_id: Optional[str],
|
||||||
|
task_id: Optional[str],
|
||||||
|
*,
|
||||||
|
file_created: Optional[int] = None,
|
||||||
|
file_modified: Optional[int] = None,
|
||||||
|
size_value: Optional[int] = None,
|
||||||
|
created_by: Optional[str] = None,
|
||||||
|
updated_by: Optional[str] = None,
|
||||||
|
comment: Optional[str] = None,
|
||||||
|
) -> None:
|
||||||
|
self._folder_id = folder_id
|
||||||
|
self._task_id = task_id
|
||||||
|
|
||||||
|
self._details_input.setEnabled(is_valid)
|
||||||
|
self._description_input.setEnabled(is_valid)
|
||||||
|
self._btn_description_save.setEnabled(is_valid)
|
||||||
|
if not is_valid:
|
||||||
|
self._details_input.setPlainText("")
|
||||||
|
return
|
||||||
|
|
||||||
# Append html string
|
|
||||||
datetime_format = "%b %d %Y %H:%M:%S"
|
datetime_format = "%b %d %Y %H:%M:%S"
|
||||||
file_created = info.file_created
|
|
||||||
modification_time = info.file_modified
|
|
||||||
if file_created:
|
if file_created:
|
||||||
file_created = datetime.datetime.fromtimestamp(file_created)
|
file_created = datetime.datetime.fromtimestamp(file_created)
|
||||||
|
|
||||||
if modification_time:
|
if file_modified:
|
||||||
modification_time = datetime.datetime.fromtimestamp(
|
file_modified = datetime.datetime.fromtimestamp(
|
||||||
modification_time
|
file_modified
|
||||||
)
|
)
|
||||||
|
|
||||||
user_items_by_name = self._controller.get_user_items_by_name()
|
user_items_by_name = self._controller.get_user_items_by_name()
|
||||||
|
|
||||||
def convert_username(username):
|
def convert_username(username_v):
|
||||||
user_item = user_items_by_name.get(username)
|
user_item = user_items_by_name.get(username_v)
|
||||||
if user_item is not None and user_item.full_name:
|
if user_item is not None and user_item.full_name:
|
||||||
return user_item.full_name
|
return user_item.full_name
|
||||||
return username
|
return username_v
|
||||||
|
|
||||||
created_lines = []
|
lines = []
|
||||||
# For published workfiles, use 'author' field
|
if size_value is not None:
|
||||||
if published_workfile_info:
|
size_value = file_size_to_string(size_value)
|
||||||
if published_workfile_info.author:
|
lines.append(f"<b>Size:</b><br/>{size_value}")
|
||||||
created_lines.append(
|
|
||||||
convert_username(published_workfile_info.author)
|
|
||||||
)
|
|
||||||
if file_created:
|
|
||||||
created_lines.append(file_created.strftime(datetime_format))
|
|
||||||
else:
|
|
||||||
# For workarea workfiles, use 'created_by' field
|
|
||||||
if workfile_info.created_by:
|
|
||||||
created_lines.append(
|
|
||||||
convert_username(workfile_info.created_by)
|
|
||||||
)
|
|
||||||
if file_created:
|
|
||||||
created_lines.append(file_created.strftime(datetime_format))
|
|
||||||
|
|
||||||
if created_lines:
|
|
||||||
created_lines.insert(0, "<b>Created:</b>")
|
|
||||||
|
|
||||||
modified_lines = []
|
|
||||||
# For workarea workfiles, show 'updated_by'
|
|
||||||
if workfile_info and workfile_info.updated_by:
|
|
||||||
modified_lines.append(convert_username(workfile_info.updated_by))
|
|
||||||
if modification_time:
|
|
||||||
modified_lines.append(modification_time.strftime(datetime_format))
|
|
||||||
if modified_lines:
|
|
||||||
modified_lines.insert(0, "<b>Modified:</b>")
|
|
||||||
|
|
||||||
lines = [
|
|
||||||
"<b>Size:</b>",
|
|
||||||
size_value,
|
|
||||||
]
|
|
||||||
# Add version comment for published workfiles
|
# Add version comment for published workfiles
|
||||||
if version_comment:
|
if comment:
|
||||||
lines.append(f"<b>Comment:</b><br/>{version_comment}")
|
lines.append(f"<b>Comment:</b><br/>{comment}")
|
||||||
if created_lines:
|
|
||||||
lines.append("<br/>".join(created_lines))
|
|
||||||
if modified_lines:
|
|
||||||
lines.append("<br/>".join(modified_lines))
|
|
||||||
|
|
||||||
self._orig_description = description
|
if created_by or file_created:
|
||||||
self._description_input.setPlainText(description)
|
lines.append("<b>Created:</b>")
|
||||||
|
if created_by:
|
||||||
|
lines.append(convert_username(created_by))
|
||||||
|
if file_created:
|
||||||
|
lines.append(file_created.strftime(datetime_format))
|
||||||
|
|
||||||
|
if updated_by or file_modified:
|
||||||
|
lines.append("<b>Modified:</b>")
|
||||||
|
if updated_by:
|
||||||
|
lines.append(convert_username(updated_by))
|
||||||
|
if file_modified:
|
||||||
|
lines.append(file_modified.strftime(datetime_format))
|
||||||
|
|
||||||
# Set as empty string
|
# Set as empty string
|
||||||
self._details_input.setPlainText("")
|
self._details_input.setPlainText("")
|
||||||
self._details_input.appendHtml("<br/>".join(lines))
|
self._details_input.appendHtml("<br/>".join(lines))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue