Beispiel #1
0
    def delete_comment(self, char):
        try:
            index = bigindex.index(char)
        except ValueError:
            return False
        try:
            comment = self.data[index]
        except IndexError:
            return False
        if comment.id is None:
            return False

        if not comment.is_mine():
            logger.warning('Trying to modify a card that you did not create')
            return False

        card_id = ppcurses.memstore['carddetailstate'].data.id

        endpoint = f"/api/v3/conversations/comment/{comment.id}?item_id={card_id}&item_name=card"
        response = ppcurses.delete(endpoint)
        if response:
            ppcurses.mkundo(
                'commentsstate', ppcurses.post_form,
                "/api/v3/conversations/comment", {
                    "text": comment.text,
                    "encoded_text": comment.encoded_text,
                    "attachments": str(comment.attachments),
                    "send_to_external": False,
                    "sent_from": 'web',
                    "item_name": 'card',
                    "item_id": card_id
                })
        return response
Beispiel #2
0
    def remove_co_assignee(self, char):
        try:
            index = bigindex.index(char)
        except ValueError:
            return False
        if self.data.id is None:
            return False
        try:
            co_assignee = self.data.contributors[index]
        except IndexError:
            return False

        contributor_ids = [
            each['id'] for each in self.data.contributors
            if each['id'] != co_assignee['id']
        ]
        endpoint = f"/api/v1/cards/{self.data.id}"
        data = {"contributor_ids": contributor_ids}
        response = ppcurses.put(endpoint, data)
        if response:
            ppcurses.mkundo('carddetailstate', ppcurses.put, endpoint, {
                "contributor_ids":
                [each['id'] for each in self.data.contributors]
            })
        return response
Beispiel #3
0
 def checklist_to_card(self, char):
     try:
         index = bigindex.index(char)
     except ValueError:
         return False
     if self.data.id is None:
         return False
     if self.data.checklist is None:
         return False
     try:
         checklist = self.data.checklist[index]
     except IndexError:
         return False
     endpoint = f"/api/v1/checklists/{self.data.checklist_id}/checklist-item/{checklist['id']}/convert-to-card"
     data = {
         "column_id": ppcurses.memstore['columnstate'].current_item['id'],
         "board_id": ppcurses.memstore['board'].id
     }
     planlet_id = ppcurses.memstore['planletstate'].current_item['id']
     if planlet_id != -1:
         data['planlet_id'] = planlet_id
     response = ppcurses.post(endpoint, data)
     if response:
         ppcurses.mkundo(
             'cardliststate', ppcurses.data.helper_card_to_checklist, None,
             {
                 'new_card_id': response['id'],
                 'parent_card_id': self.data.id,
                 'checklist_title': checklist['title']
             })
     return response
Beispiel #4
0
    def edit_checklist(self, char):
        try:
            index = bigindex.index(char)
        except ValueError:
            return False
        if self.data.id is None:
            return False
        if self.data.checklist is None:
            return False
        try:
            checklist = self.data.checklist[index]
        except IndexError:
            return False
        endpoint = f"/api/v1/cards/{self.data.id}/checklist/{checklist['id']}/"
        text, _ = ppcurses.hover.textbox('edit checklist item',
                                         checklist['title'])
        if text is None:
            return
        data = {'title': text, 'done': checklist['done']}
        response = ppcurses.put(endpoint, data)
        if response:
            ppcurses.mkundo('carddetailstate', ppcurses.put, endpoint, {
                'title': checklist['title'],
                'done': checklist['done']
            })

        return response
Beispiel #5
0
 def add_comment(self):
     if ppcurses.memstore['carddetailstate'].data.id is None:
         return
     card_id = ppcurses.memstore['carddetailstate'].data.id
     comment_text, encoded_text = ppcurses.hover.textbox('add a comment',
                                                         newlines=True,
                                                         encoded=True)
     if comment_text is None:
         return
     else:
         endpoint = "/api/v3/conversations/comment"
         data = {
             "text": comment_text,
             "encoded_text": encoded_text,
             "attachments": [],
             "send_to_external": False,
             "sent_from": 'web',
             "item_name": 'card',
             "item_id": card_id
         }
         response = ppcurses.post_form(endpoint, data)
         if response:
             ppcurses.mkundo(
                 'commentsstate', ppcurses.delete,
                 f"/api/v3/conversations/comment/{response['data']['id']}?item_id={response['data']['item_id']}&item_name=card"
             )
         return response
Beispiel #6
0
 def change_title(self):
     if self.data.id is None:
         return False
     title, _ = ppcurses.hover.textbox('change title', self.data.title)
     if title is None:
         return
     endpoint = f"/api/v1/cards/{self.data.id}"
     data = {'title': title}
     response = ppcurses.put(endpoint, data)
     if response:
         ppcurses.mkundo('carddetailstate', ppcurses.put, endpoint,
                         {'title': self.data.title})
     return response
Beispiel #7
0
 def change_description(self):
     if self.data.id is None:
         return False
     description, _ = ppcurses.hover.textbox('change description',
                                             self.data.description,
                                             newlines=True)
     if description is None:
         description = ''
     endpoint = f"/api/v1/cards/{self.data.id}"
     data = {'description': description}
     response = ppcurses.put(endpoint, data)
     if response:
         ppcurses.mkundo('carddetailstate', ppcurses.put, endpoint,
                         {'description': self.data.description})
     return response
Beispiel #8
0
 def delete_card(self):
     if self.data.id is None:
         return False
     endpoint = f"/api/v1/cards/{self.data.id}"
     response = ppcurses.delete(endpoint)
     if response:
         project_id = ppcurses.dbstore['project_id']
         ppcurses.mkundo(
             'cardliststate', ppcurses.post,
             f"/api/v1/projects/{project_id}/trashcan", {
                 "action": "restore",
                 "items": [{
                     "id": self.data.id,
                     "type": "card"
                 }]
             })
     return response
Beispiel #9
0
    def move_to_planlet(self):
        if self.data.id is None:
            return False

        board_id = ppcurses.memstore['board'].id
        column_id = ppcurses.memstore['columnstate'].current_item['id']
        selection = ppcurses.hover.select_one(
            'planlets',
            lambda **kwargs: ppcurses.memstore['planletstate'].data)
        if (selection is None) or (
                selection['id']
                == ppcurses.memstore['planletstate'].current_item['id']):
            return
        logger.info('Moving card to %s', selection)
        endpoint = f"/api/v1/boards/{board_id}/move-cards"
        if selection['id'] == -1:
            selection['id'] = None
        data = {
            "card_ids": [self.data.id],
            "column_id": column_id,
            "after_card": None,
            "swimlane": {
                "type": "planlet_id",
                "value": selection['id']
            }
        }
        response = ppcurses.post(endpoint, data)
        if response:
            if ppcurses.memstore['planletstate'].current_item['id'] == -1:
                planlet_id = None
            else:
                planlet_id = ppcurses.memstore['planletstate'].current_item[
                    'id']
            ppcurses.mkundo(
                'planletstate', ppcurses.post, endpoint, {
                    "card_ids": [self.data.id],
                    "column_id": column_id,
                    "after_card": None,
                    "swimlane": {
                        "type": "planlet_id",
                        "value": planlet_id
                    }
                })

        return response
Beispiel #10
0
 def add_co_assignee(self):
     if self.data.id is None:
         return False
     selection = ppcurses.hover.select_one('co-assignees',
                                           ppcurses.data.get_board_members)
     contributor_ids = [each['id'] for each in self.data.contributors]
     if (selection is not None) and (selection['id']
                                     not in contributor_ids):
         endpoint = f"/api/v1/cards/{self.data.id}"
         contributor_ids.append(selection['id'])
         data = {'contributor_ids': contributor_ids}
         response = ppcurses.put(endpoint, data)
         if response:
             ppcurses.mkundo(
                 'carddetailstate', ppcurses.put, endpoint, {
                     'contributor_ids':
                     [each['id'] for each in self.data.contributors]
                 })
         return response
Beispiel #11
0
    def edit_comment(self, char):
        try:
            index = bigindex.index(char)
        except ValueError:
            return False
        try:
            comment = self.data[index]
        except IndexError:
            return False
        if comment.id is None:
            return False
        if not comment.is_mine():
            logger.warning('Trying to modify a card that you did not create')
            return False

        comment_text, encoded_text = ppcurses.hover.textbox(
            'edit a comment',
            comment.encoded_text,
            newlines=True,
            encoded=True,
            encoder_kwargs={'known_atrefs': comment.at_refs})

        if (comment_text is None) or (comment_text == comment.text):
            return
        else:
            endpoint = f"/api/v3/conversations/comment/{comment.id}"
            data = {
                "text": comment_text,
                "encoded_text": encoded_text,
                "attachments": str(comment.attachments),
                "send_to_external": False,
            }
            response = ppcurses.put_form(endpoint, data)
            if response:
                ppcurses.mkundo(
                    'commentsstate', ppcurses.put_form, endpoint, {
                        "text": comment.text,
                        "encoded_text": comment.encoded_text,
                        "attachments": str(comment.attachments),
                        "send_to_external": False,
                    })
            return response
Beispiel #12
0
 def change_assignee(self):
     if self.data.id is None:
         return False
     selection = ppcurses.hover.select_one(
         'assignees', ppcurses.data.get_board_members_with_removal)
     if (selection is None or self.data.assignee is not None
             and self.data.assignee['id'] == selection['id']
             or self.data.assignee is None and selection['id'] == 'remove'):
         return
     endpoint = f"/api/v1/cards/{self.data.id}"
     data = {'assignee_id': selection['id']}
     response = ppcurses.put(endpoint, data)
     if response:
         if self.data.assignee is None:
             assignee_id = 'remove'
         else:
             assignee_id = self.data.assignee['id']
         ppcurses.mkundo('cardliststate', ppcurses.put, endpoint,
                         {'assignee_id': assignee_id})
     return response
Beispiel #13
0
 def add_checklist(self):
     if self.data.id is None:
         return False
     endpoint = f"/api/v1/cards/{self.data.id}/checklist"
     checklist, _ = ppcurses.hover.textbox('add checklist item')
     if checklist is None:
         return
     data = {'title': checklist}
     response = ppcurses.post(endpoint, data)
     if response:
         for each in response['checklist']['items'][-1::-1]:
             if each['title'] == checklist:
                 break
         else:
             return response
         logger.error(each)
         ppcurses.mkundo(
             'carddetailstate', ppcurses.delete,
             f"/api/v1/cards/{self.data.id}/checklist/{each['id']}/")
     return response
Beispiel #14
0
 def delete_checklist(self, char):
     try:
         index = bigindex.index(char)
     except ValueError:
         return False
     if self.data.id is None:
         return False
     if self.data.checklist is None:
         return False
     try:
         checklist = self.data.checklist[index]
     except IndexError:
         return False
     endpoint = f"/api/v1/cards/{self.data.id}/checklist/{checklist['id']}/"
     response = ppcurses.delete(endpoint)
     if response:
         ppcurses.mkundo('carddetailstate', ppcurses.post,
                         f"/api/v1/cards/{self.data.id}/checklist",
                         {'title': checklist['title']})
     return response
Beispiel #15
0
    def change_label(self):
        if self.data.id is None:
            return False
        data = ppcurses.memstore['board'].labels
        data.insert(0, {'id': 'remove', 'name': 'Remove label'})
        selection = ppcurses.hover.select_one('labels', lambda **kwargs: data)
        if ((selection is None) or
            (self.data.label and self.data.label['id'] == selection['id'])
                or (self.data.label is None and selection['id'] == 'remove')):
            return

        endpoint = f"/api/v1/cards/{self.data.id}"
        data = {'label_id': selection['id']}
        response = ppcurses.put(endpoint, data)
        if response:
            if self.data.label is None:
                label_id = 'remove'
            else:
                label_id = self.data.label['id']
            ppcurses.mkundo('carddetailstate', ppcurses.put, endpoint,
                            {'label_id': label_id})
        return response
Beispiel #16
0
 def toggle_checklist(self, char):
     try:
         index = bigindex.index(char)
     except ValueError:
         return False
     if self.data.id is None:
         return False
     if self.data.checklist is None:
         return False
     try:
         checklist = self.data.checklist[index]
     except IndexError:
         return False
     endpoint = f"/api/v1/cards/{self.data.id}/checklist/{checklist['id']}/"
     data = {'done': not checklist['done'], 'title': checklist['title']}
     response = ppcurses.put(endpoint, data)
     if response:
         ppcurses.mkundo('carddetailstate', ppcurses.put, endpoint, {
             'done': checklist['done'],
             'tile': checklist['title']
         })
     return response
Beispiel #17
0
    def change_points(self):
        if self.data.id is None:
            return False
        points = [0, 0.5, 1, 2, 3, 5, 8, 13, 20, 40, 100]
        data = [{'id': str(x), 'name': x} for x in points]
        data.insert(0, {'id': 'remove', 'name': 'Remove points'})
        selection = ppcurses.hover.select_one('points', lambda **kwargs: data)
        if ((selection is None) or
            (self.data.estimate and self.data.estimate == selection['name']) or
            (self.data.estimate is None and selection['id'] == 'remove')):
            return

        endpoint = f"/api/v1/cards/{self.data.id}"
        data = {'estimate': selection['id']}
        response = ppcurses.put(endpoint, data)
        if response:
            if self.data.estimate is None:
                estimate = 'remove'
            else:
                estimate = str(self.data.estimate)
            ppcurses.mkundo('carddetailstate', ppcurses.put, endpoint,
                            {'estimate': estimate})
        return response
Beispiel #18
0
    def create_card(self):
        project_id = ppcurses.dbstore['project_id']
        endpoint = f"/api/v1/projects/{project_id}/cards/create-new"
        board_id = ppcurses.memstore['board'].id
        planlet_id = ppcurses.memstore['planletstate'].current_item['id']
        column_id = ppcurses.memstore['columnstate'].current_item['id']
        if (board_id is None) or (planlet_id is None) or (column_id is None):
            return False
        card_name, _ = ppcurses.hover.textbox('card name')
        if card_name is None:
            return False
        data = {
            "column_id": column_id,
            "board_id": board_id,
            "title": card_name
        }
        if planlet_id != -1:
            data['planlet_id'] = planlet_id
        response = ppcurses.post(endpoint, data)
        if response:
            ppcurses.mkundo('cardliststate', ppcurses.delete,
                            f"/api/v1/cards/{response['id']}")

        return response