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

Added a New Card Filter For Labels #9

Open
wants to merge 3 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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
/vendor/
/web/bundles/
composer.lock
.idea
110 changes: 110 additions & 0 deletions src/AppBundle/Helper/CardFilter/LabelNameCardFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php


namespace AppBundle\Helper\CardFilter;


use AppBundle\Helper\TrelloClient\Model\Card;
use AppBundle\Helper\TrelloClient\Model\Label;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;

class LabelNameCardFilter extends AbstractCardFilter
{
/**
* @var Label
*/
private $targetLabel;

/**
* Initialization of the filter should be implemented in this function. This may include asking the user for input.
* If setup needs to be cancelled, then an exception can be thrown for the filter not to be created
*
* @param InputInterface $input
* @param OutputInterface $output
* @param string $boardId
*
* @return CardFilterInterface
* @throws \Exception
*/
static public function setUp(InputInterface $input, OutputInterface $output, $boardId)
{
$trelloClient = self::getContainer()->get('trello_client');

$boardLabels = $trelloClient->getBoardLabels($boardId);
$options = [];
$count = 1;
foreach($boardLabels as $boardLabel ){
$labelName = $boardLabel->getName();
if ( isset($options[ $boardLabel->getName() ]) && ( isset( $labelName ) && !empty( $boardLabel->getName()) ) )
{
$options[$count.' '.$boardLabel->getName() ] = $boardLabel;
}
elseif( isset( $labelName ) && !empty( $boardLabel->getName()) )
{
$options[$count.' '.$boardLabel->getName()] = $boardLabel;
}
$count ++;
//$options[$boardLabel->getId()] = $boardLabel;
}
$filterOptionQuestion = new ChoiceQuestion(
'Select Label to filter by:',
array_merge(array_keys($options), ['<- Back'])
);
$questionHelper = new QuestionHelper();
Copy link
Contributor

Choose a reason for hiding this comment

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

The display for the setup renders as follows:

Configure Filter: Has Label
Select Label to filter by:
  [0] 1 Alpha
  [1] 3 Alpha
  [2] 4 Bravo
  [3] <- Back
 >

You can rely on the ChoiceQuestion to do the option numbering for you

$selectedLabelName = $questionHelper->ask($input, $output, $filterOptionQuestion);
if($selectedLabelName == '<- Back'){
throw new \Exception('Back option selected');
}

$filter = new self();
$filter->targetLabel = $options[$selectedLabelName];

return $filter;
}

/**
* Should return TRUE if the provided card passes this filter and FALSE otherwise
*
* @param Card $card
*
* @return boolean
*/
public function satisfiedBy(Card $card)
{
foreach ($card->getLabels() as $cardLabel){
if ($cardLabel->getId() == $this->getTargetLabel()->getId()){
return true;
}
}
return false;
}

/**
* Should return a unique, static friendly name for the filter to identify it in interfaces
*
* @return string
*/
static public function getName()
{
return 'Has Label';
Copy link
Contributor

@mostertb mostertb Nov 10, 2019

Choose a reason for hiding this comment

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

If you choose to go implement the functionality in #2, then this should probably change to something like Label Name to differentiate it from the alternate functionality of matching a specific Label.

See \AppBundle\Helper\CardFilter\LabelColourCardFilter for reference

}

/**
* Should return a short description (around 50 characters or less) of what this specific instantiation of the filter
* is filtering for
*
* @return string
*/
public function getConfigDescription()
{
return 'Label: '.$this->getTargetLabel()->getName();
Copy link
Contributor

Choose a reason for hiding this comment

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

If you chose to go implement matching a specific label, then have a look at how the labels are rendered in \AppBundle\Command\CardFilterCommand::printFilteredCards()

This covers Labels without names and attempts to differentiate Labels by colour

}

private function getTargetLabel()
{
return $this->targetLabel;
}
}
23 changes: 21 additions & 2 deletions src/AppBundle/Helper/TrelloClient/TrelloClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use AppBundle\Helper\TrelloClient\Model\Board;
use AppBundle\Helper\TrelloClient\Model\BoardList;
use AppBundle\Helper\TrelloClient\Model\Card;
use AppBundle\Helper\TrelloClient\Model\Label;
use AppBundle\Helper\TrelloClient\Model\Member;
use Doctrine\Common\Collections\ArrayCollection;
use GuzzleHttp\Client;
Expand Down Expand Up @@ -121,7 +122,7 @@ public function getBoardLists($boardId)
*
* @return Member[]|ArrayCollection
*/
public function getBoardMembers($boardId)
public function getBoardMembers($boardId)
{
$queryParameters = [
'fields' => 'id,avatarUrl,initials,fullName,username',
Expand All @@ -134,6 +135,24 @@ public function getBoardMembers($boardId)
);
}

/**
* @param $boardId
*
* @return Label[]\ArrayCollection
*/
public function getBoardLabels($boardId)
{
$queryParameters = [
'fields' => 'all',
];
return $this->makeRequest(
'boards/'.$boardId.'/labels',
'GET',
'ArrayCollection<AppBundle\Helper\TrelloClient\Model\Label>',
$queryParameters
);
}


protected function makeRequest($path, $method = 'GET', $expectedResponseClass = null, array $parameters = [])
{
Expand Down Expand Up @@ -194,4 +213,4 @@ protected function getSerializer()
{
return $this->serializer;
}
}
}