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

Issue #9 Archiving all cards in a list #27

Merged
merged 2 commits into from May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -49,6 +49,7 @@ There are a couple of commands available in 3llo.
* `card comment <card_id>`: Add a comment to a card.
* `card archive <card_id>`: Archive a card.
* `list list`: List all the lists of the active board.
* `list archive-cards <list_id>`: Archives all the cards on the specified list.
* `help`: Show help menu.
* `exit`: Exit.

Expand Down
11 changes: 11 additions & 0 deletions lib/3llo/api/list.rb
Expand Up @@ -15,6 +15,17 @@ def find_all_by_board(board_id)
)
end

def archive_cards(list_id)
JSON.parse(
client.post(
"/lists/#{list_id}/archiveAllCards",
key: api_key,
token: api_token
),
symbolize_names: true
)
end

private

def client
Expand Down
39 changes: 39 additions & 0 deletions lib/3llo/commands/list/archive_cards.rb
@@ -0,0 +1,39 @@
module Tr3llo
module Command
module List
class ArchiveCardsCommand
def initialize(list_id)
@list_id = list_id
end

def execute
interface.print_frame do
approved = prompt_for_approvement!
if approved
archive_cards
interface.puts("Cards have been archived.")
end
end
end

private

attr_reader :list_id

def prompt_for_approvement!
Tr3llo::Presenter::ConfirmationPresenter
.new(interface)
.prompt_for_confirmation('Are you sure you want to archive all cards?')
end

def archive_cards
API::List.archive_cards(list_id)
end

def interface
$container.resolve(:interface)
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/3llo/commands/list/invalid.rb
Expand Up @@ -17,6 +17,7 @@ def menu_text

list list - Show all lists
list cards <list_id> - Show all cards in list
list archive-cards <list_id> - Archive all cards in list
}
end

Expand Down
4 changes: 4 additions & 0 deletions lib/3llo/list_command_factory.rb
@@ -1,6 +1,7 @@
require '3llo/commands/list/list'
require '3llo/commands/list/cards'
require '3llo/commands/list/invalid'
require '3llo/commands/list/archive_cards'

module Tr3llo
class ListCommandFactory
Expand All @@ -17,6 +18,9 @@ def factory
when 'cards'
list_id, _ = args
Command::List::CardsCommand.new(list_id)
when 'archive-cards'
list_id, _ = args
Command::List::ArchiveCardsCommand.new(list_id)
else
Command::List::InvalidCommand.new
end
Expand Down
1 change: 1 addition & 0 deletions lib/3llo/presenter.rb
Expand Up @@ -8,3 +8,4 @@
require '3llo/presenter/card/assign'
require '3llo/presenter/list/list'
require '3llo/presenter/list/cards'
require '3llo/presenter/confirmation'
18 changes: 18 additions & 0 deletions lib/3llo/presenter/confirmation.rb
@@ -0,0 +1,18 @@
module Tr3llo
module Presenter
class ConfirmationPresenter
def initialize(interface)
@interface = interface
end

def prompt_for_confirmation(message)
answer = interface.input.select(message, ['No', 'Yes'])
answer == 'Yes' ? true : false
end

private

attr_reader :interface
end
end
end
33 changes: 17 additions & 16 deletions lib/3llo/presenter/help.rb
Expand Up @@ -20,22 +20,23 @@ def menu_text
3llo - CLI for Trello

Usage:
board list - Show list of board
board select - Select board
card list - Show list of cards grouped by list
card list mine - Show list of my cards
card add - Create a card
card show <card_id> - Show card information
card move <card_id> - Move card to a list
card self-assign <card_id> - Self-assign a card
card assign <card_id> - Assign a user to a card
card comments <card_id> - Load recent comments of a card
card comment <card_id> - Add a comment to a card
card archive <card_id> - Archive a card
list list - Show all lists
list cards <list_id> - Show all cards in list
help - Show help menu
exit - Exit program
board list - Show list of board
board select - Select board
card list - Show list of cards grouped by list
card list mine - Show list of my cards
card add - Create a card
card show <card_id> - Show card information
card move <card_id> - Move card to a list
card self-assign <card_id> - Self-assign a card
card assign <card_id> - Assign a user to a card
card comments <card_id> - Load recent comments of a card
card comment <card_id> - Add a comment to a card
card archive <card_id> - Archive a card
list list - Show all lists
list cards <list_id> - Show all cards in list
list archive-cards <list_id> - Archive all cards in list
help - Show help menu
exit - Exit program
}
end
end
Expand Down