~mapperr/trl

ref: f0199cf618af7c4bcc3737e98948d2f7ceeb02e6 trl/trullo/printer.py -rw-r--r-- 3.0 KiB
f0199cf6 — mapperr Add labels to board view 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from typing import List, Optional

import attr

from trullo.shortener import Shortener
from trullo.trl_board import TrlBoard
from trullo.trl_card import TrlCard


@attr.s(auto_attribs=True)
class Printer:
    @staticmethod
    def print_boards(boards: List[TrlBoard]):
        for board in boards:
            print(f"[{board.raw_data['shortLink'].lower()}] "
                  f"{board.raw_data['name']}")

    @staticmethod
    def print_board(board: TrlBoard,
                    list_shortcuts: Optional[List[str]] = None):
        print(f"{board.raw_data['shortUrl']}")
        print('------------------------------')
        print(f"{board.raw_data['name']}")
        print()
        if board.lists is not None:
            matching_lists = board.lists
            if list_shortcuts is not None and len(list_shortcuts) > 0:
                matching_lists = [
                    list_ for list_ in board.lists
                    if Printer._there_is_a_match(
                        list_.get_normalized_name(),
                        list_shortcuts)
                ]
            for list_ in matching_lists:
                print(f"\n{list_.raw_data['name']}\n"
                      f"[{list_.raw_data['id'].lower()}]")
                for card in board.cards:
                    if card.raw_data['idList'] == list_.id:
                        card_output = f"\t[{card.raw_data['shortLink'].lower()}] "
                        for raw_label in card.raw_data['labels']:
                            card_output += f'({raw_label["name"]}) '
                        card_output += f"{card.raw_data['name']}"
                        print(card_output)
        print()

    @staticmethod
    def print_board_lists(board: TrlBoard):
        symbol_count_lists = Shortener.get_min_symbols_to_uniq(
            [list_.get_normalized_name() for list_ in board.lists])
        print(f"{board.raw_data['shortUrl']}")
        print('------------------------------')
        print(f"{board.raw_data['name']}")
        print()
        if board.lists is not None:
            for list_ in board.lists:
                print(f"[{list_.raw_data['id'].lower()}] "
                      f"{list_.raw_data['name']}")
        print()

    @staticmethod
    def print_card(card: TrlCard):
        d = card.raw_data
        formatted_desc = '\t' + str(d['desc']).replace('\n', '\n\t')

        print(f'{d["shortUrl"]}')
        print('-------------------------------------')
        print(f'{d["name"]}')
        if len(d['labels']) > 0:
            print()
        for label in d['labels']:
            label_name = label["name"] \
                if label["name"] is not None and label["name"] != "" \
                else label["color"]
            print(f'({label_name})  ', end='')
        print()
        print(formatted_desc)
        print()

    @staticmethod
    def _there_is_a_match(normalized_name: str, shortcuts: List[str]) -> bool:
        return len([
            shortcut for shortcut in shortcuts
            if Shortener.is_a_match(shortcut, normalized_name)
        ]) > 0