Skip to content

Commit

Permalink
fix: sort lists for focalboard report according to view
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyqu committed Apr 28, 2024
1 parent e09aeb4 commit b2cebfe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
26 changes: 21 additions & 5 deletions src/focalboard/focalboard_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def get_boards_for_user(self, user_id=None):
logger.debug(f"get_boards_for_user: {boards}")
return boards

def get_lists(self):
board_id = self.board_id
def get_lists(self, board_id=None, sorted=False):
if board_id is None:
# default board
board_id = self.board_id
# TODO make it more efficient
# essentially all list information is already passed via boards handler
_, data = self._make_request("api/v2/teams/0/boards")
Expand All @@ -45,6 +47,19 @@ def get_lists(self):
objects.TrelloList.from_focalboard_dict(trello_list, board_id)
for trello_list in lists_data
]
if sorted:
# we need to get sorting order from the view, which is currently not efficient
try:
_, data = self._make_request(f"api/v2/boards/{board_id}/blocks?all=true")
view = [card_dict for card_dict in data if card_dict["type"] == "view"][0]
order = view["fields"]["visibleOptionIds"]
sorted_lists = []
for list_id in order:
this_list = [lst for lst in lists if lst.id == list_id][0]
sorted_lists.append(this_list)
lists = sorted_lists
except Exception as e:
logger.error(f"can't sort focalboard lists", exc_info=e)
logger.debug(f"get_lists: {lists}")
return lists

Expand Down Expand Up @@ -152,13 +167,14 @@ def get_members(self, board_id) -> List[objects.TrelloMember]:
logger.debug(f"get_members: {members}")
return members

def get_cards(self, list_ids):
board_id = self.board_id
def get_cards(self, list_ids, board_id=None):
if board_id is None:
board_id = self.board_id
_, data = self._make_request(f"api/v2/boards/{board_id}/blocks?all=true")
cards = []
# TODO: move this to app state
members = self.get_members(board_id)
lists = self.get_lists()
lists = self.get_lists(board_id=board_id)
list_prop = self._get_list_property(board_id)
member_prop = self._get_member_property(board_id)
view_id = [card_dict for card_dict in data if card_dict["type"] == "view"][0][
Expand Down
2 changes: 1 addition & 1 deletion src/tg/handlers/user_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def handle_user_message(
assert 0 <= list_idx < len(board_list)
board_id = board_list[list_idx]["id"]
if use_focalboard:
trello_lists = focalboard_client.get_lists(board_id)
trello_lists = focalboard_client.get_lists(board_id, sorted=True)
trello_lists = trello_lists[::-1]
else:
trello_lists = trello_client.get_lists(board_id)
Expand Down

0 comments on commit b2cebfe

Please sign in to comment.