Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SG-36129 Add customized sort fields #96

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ configuration:
default_value_tk-maya: "{self}/general_actions.py:{self}/{engine_name}_actions.py"
description: Hook which contains all methods for action management.

sort_fields:
type: dict
description: Controls what fields appear for sorting in the UI.
Currently the sort menu only shows on the tasks tab.
You can add any field that would normally be suitable for sorting a query
by for the tab's given entity type.
allows_empty: True
default_value:
"tasks":
- { field_code: 'due_date', display_name: "Due Date", default: True }
- { field_code: 'start_date', display_name: "Start Date" }
- { field_code: 'sg_status_list', display_name: "Status" }
- { field_code: 'step', display_name: "Step"}
values:
type: list
values:
type: dict
items:
field_code: { type: str }
display_name: { type: str }

action_mappings:
type: dict
description: Associates shotgun objects with actions. The actions are all defined
Expand Down
74 changes: 40 additions & 34 deletions python/app/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ def build_entity_tabs(self):
"has_description": True,
"has_view": True,
"has_filter": False,
"tab_name": entity_tab_name,
}

if entity_tab_name == self.ENTITY_TAB_NOTES:
Expand Down Expand Up @@ -1298,7 +1299,7 @@ def _sort_menu_setup(self, task_tab_data):
)
fields_manager.initialized.connect(self._field_filters)
fields_manager.initialize()
self._sort_menu_actions()
self._sort_menu_actions(task_tab_data["tab_name"])

def _field_filters(self):

Expand All @@ -1321,35 +1322,30 @@ def disabled_filter(field):
self._entity_field_menu.set_checked_filter(checked_filter)
self._entity_field_menu.set_disabled_filter(disabled_filter)

def _sort_menu_actions(self):
def _sort_menu_actions(self, tab_name):
"""
Populate the sort menu with actions.
"""

sort_fields = self._app.get_setting("sort_fields").get(tab_name, [])

# Create Sort Menu actions
sort_asc = self._entity_field_menu._get_qaction("ascending", "Ascending")
sort_desc = self._entity_field_menu._get_qaction("descending", "Descending")
separator = self._entity_field_menu.addSeparator()
status_action = self._entity_field_menu._get_qaction("sg_status_list", "Status")
step_action = self._entity_field_menu._get_qaction("step", "Step")
start_date_action = self._entity_field_menu._get_qaction(
"start_date", "Start date"
)
due_date_action = self._entity_field_menu._get_qaction("due_date", "Due date")
field_sort_actions = [
self._entity_field_menu._get_qaction(
field["field_code"], field["display_name"]
)
for field in sort_fields
]

# Actions group list ordered
sort_actions = [
due_date_action,
start_date_action,
status_action,
separator,
sort_asc,
sort_desc,
]
sort_actions = [sort_asc, sort_desc, separator, *field_sort_actions]

# By default it sort Tasks due date in descending order
# By default it sorts in descending order and the default field is set in the configuration
sort_desc.setChecked(True)
due_date_action.setChecked(True)

# Menu sort order actions
sort_asc.triggered[()].connect(
lambda: self.load_sort_data(
Expand All @@ -1361,19 +1357,29 @@ def _sort_menu_actions(self):
"descending", sort_desc, sort_actions, sort_order="desc"
)
)

# Menu sort field actions
status_action.triggered[()].connect(
lambda: self.load_sort_data("sg_status_list", status_action, sort_actions)
)
step_action.triggered[()].connect(
lambda: self.load_sort_data("step", step_action, sort_actions)
)
start_date_action.triggered[()].connect(
lambda: self.load_sort_data("start_date", start_date_action, sort_actions)
)
due_date_action.triggered[()].connect(
lambda: self.load_sort_data("due_date", due_date_action, sort_actions)
)
default_set = False
for index, field_sort_action in enumerate(field_sort_actions):
sort_field = sort_fields[index]
field_code = sort_field["field_code"]

is_default = sort_field.get("default", False)
if is_default:
default_set = True
field_sort_action.setChecked(True)
self._current_menu_sort_item = field_code

field_sort_action.triggered[()].connect(
lambda fc=field_code, fsa=field_sort_action: self.load_sort_data(
fc, fsa, sort_actions
)
)

if not default_set and sort_fields:
field_sort_actions[0].setChecked(True)
self._current_menu_sort_item = sort_fields[0]["field_code"]

# Add actions to the entity Menu
self._entity_field_menu.add_group(sort_actions, "Sort menu")
# Remove the separator from the list
Expand Down Expand Up @@ -1430,11 +1436,11 @@ def load_sort_data(self, field, sort_action, actions_list, **sort_order):

# Set checked the current sort order in the Menu
if sort_order == "asc":
actions_list[3].setChecked(True)
actions_list[4].setChecked(False)
actions_list[0].setChecked(True)
actions_list[1].setChecked(False)
elif sort_order == "desc":
actions_list[4].setChecked(True)
actions_list[3].setChecked(False)
actions_list[0].setChecked(False)
actions_list[1].setChecked(True)
Comment on lines -1433 to +1443
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the sort order to the top, it was shown at the bottom of the list. This brings it inline with the web UI.


# Save the last menu item selected
self._current_menu_sort_item = field
Expand Down