Skip to content

Commit

Permalink
Merge pull request #39 from itk-dev/feature/projects
Browse files Browse the repository at this point in the history
feature/projects
  • Loading branch information
tuj authored Jan 22, 2024
2 parents 903b3f6 + 3d13aa5 commit b7b16d1
Show file tree
Hide file tree
Showing 43 changed files with 1,529 additions and 517 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Added commands to manage data providers.
* Changed how errors are handled in Leantime api calls.
* Modified getSprintReportData to work with Leantime data
* Added project lead to client when syncing projects.
Expand All @@ -30,6 +31,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Refactored error handling.
* Added support for multiple data providers
* Removed project creator for Jira.
* Added client view.
* Added account view.
* Added leantime support for projects and project sync.


* RELEASE NOTES:
Expand Down
31 changes: 31 additions & 0 deletions migrations/Version20240118132209.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240118132209 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE data_provider ADD enabled TINYINT(1) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE data_provider DROP enabled');
}
}
8 changes: 5 additions & 3 deletions src/Command/DataProviderCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: 'app:project-tracker:create',
description: 'Create a new Project Tracker',
name: 'app:data-provider:create',
description: 'Create a new Data Provider',
)]
class DataProviderCreateCommand extends Command
{
Expand All @@ -37,7 +37,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$question->setAutocompleterValues(DataProviderService::IMPLEMENTATIONS);
$class = $io->askQuestion($question);

$dataProvider = $this->dataProviderService->createDataProvider($name, $class, $url, $secret, false, false);
$dataProvider = $this->dataProviderService->createDataProvider($name, $class, $url, $secret);
$dataProvider->setCreatedBy('CLI');
$dataProvider->setUpdatedBy('CLI');

$text = "Created the following data provider\n\n";
$text .= 'ID: '.$dataProvider->getId()."\n";
Expand Down
48 changes: 48 additions & 0 deletions src/Command/DataProviderListCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Command;

use App\Entity\DataProvider;
use App\Repository\DataProviderRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: 'app:data-provider:list',
description: 'List data providers',
)]
class DataProviderListCommand extends Command
{
public function __construct(
private readonly DataProviderRepository $dataProviderRepository
) {
parent::__construct($this->getName());
}

protected function configure(): void
{
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$dataProviders = $this->dataProviderRepository->findAll();

/* @var DataProvider $provider */
$io->table(['id', 'name', 'enabled', 'class', 'url', 'sync clients', 'sync accounts'], array_map(fn ($provider) => [
$provider->getId(),
$provider->getName(),
$provider->isEnabled() ? 'true' : 'false',
$provider->getClass(),
$provider->getUrl(),
$provider->isEnableClientSync(),
$provider->isEnableAccountSync(),
], $dataProviders));

return Command::SUCCESS;
}
}
54 changes: 54 additions & 0 deletions src/Command/DataProviderSetEnableCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Command;

use App\Repository\DataProviderRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: 'app:data-provider:set-enable',
description: 'Enable/disable a data provider',
)]
class DataProviderSetEnableCommand extends Command
{
public function __construct(
private readonly DataProviderRepository $dataProviderRepository
) {
parent::__construct($this->getName());
}

protected function configure(): void
{
$this->addArgument('id', InputArgument::REQUIRED, 'data provider id');
$this->addArgument('enable', InputArgument::REQUIRED, 'data provider enable');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$id = (int) $input->getArgument('id');
$enable = $input->getArgument('enable');

$dataProvider = $this->dataProviderRepository->find($id);

if (null != $dataProvider) {
$dataProvider->setEnabled('true' == $enable);
$dataProvider->setUpdatedBy('CLI');
$this->dataProviderRepository->save($dataProvider, true);

$io->info('Data provider with id: '.$dataProvider->getId().' '.($dataProvider->isEnabled() ? 'enabled' : 'disabled'));

return Command::SUCCESS;
} else {
$io->error('Data provider not found');

return Command::FAILURE;
}
}
}
2 changes: 1 addition & 1 deletion src/Command/SyncAccountsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$dataProviders = $this->dataProviderRepository->findAll();
$dataProviders = $this->dataProviderRepository->findBy(['enabled' => true]);

foreach ($dataProviders as $dataProvider) {
$io->info('Processing accounts in '.$dataProvider->getName());
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->info('Processing projects');

$dataProviders = $this->dataProviderRepository->findAll();
$dataProviders = $this->dataProviderRepository->findBy(['enabled' => true]);

foreach ($dataProviders as $dataProvider) {
$this->dataSynchronizationService->syncProjects(function ($i, $length) use ($io) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SyncIssuesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$dataProviders = $this->dataProviderRepository->findAll();
$dataProviders = $this->dataProviderRepository->findBy(['enabled' => true]);

foreach ($dataProviders as $dataProvider) {
$projects = $this->projectRepository->findBy(['include' => true, 'dataProvider' => $dataProvider]);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SyncProjectsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$dataProviders = $this->dataProviderRepository->findAll();
$dataProviders = $this->dataProviderRepository->findBy(['enabled' => true]);

foreach ($dataProviders as $dataProvider) {
$this->dataSynchronizationService->syncProjects(function ($i, $length) use ($io) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SyncWorklogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$dataProviders = $this->dataProviderRepository->findAll();
$dataProviders = $this->dataProviderRepository->findBy(['enabled' => true]);

foreach ($dataProviders as $dataProvider) {
$projects = $this->projectRepository->findBy(['include' => true, 'dataProvider' => $dataProvider]);
Expand Down
82 changes: 82 additions & 0 deletions src/Controller/AccountController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Controller;

use App\Entity\Account;
use App\Form\AccountType;
use App\Repository\AccountRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/admin/account')]
class AccountController extends AbstractController
{
#[Route('/', name: 'app_account_index', methods: ['GET'])]
public function index(AccountRepository $accountRepository): Response
{
return $this->render('account/index.html.twig', [
'accounts' => $accountRepository->findAll(),
]);
}

#[Route('/new', name: 'app_account_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$account = new Account();
$form = $this->createForm(AccountType::class, $account);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($account);
$entityManager->flush();

return $this->redirectToRoute('app_account_index', [], Response::HTTP_SEE_OTHER);
}

return $this->render('account/new.html.twig', [
'account' => $account,
'form' => $form,
]);
}

#[Route('/{id}', name: 'app_account_show', methods: ['GET'])]
public function show(Account $account): Response
{
return $this->render('account/show.html.twig', [
'account' => $account,
]);
}

#[Route('/{id}/edit', name: 'app_account_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Account $account, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(AccountType::class, $account);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();

return $this->redirectToRoute('app_account_index', [], Response::HTTP_SEE_OTHER);
}

return $this->render('account/edit.html.twig', [
'account' => $account,
'form' => $form,
]);
}

#[Route('/{id}', name: 'app_account_delete', methods: ['POST'])]
public function delete(Request $request, Account $account, EntityManagerInterface $entityManager): Response
{
$token = $request->request->get('_token');
if (is_string($token) && $this->isCsrfTokenValid('delete'.$account->getId(), $token)) {
$entityManager->remove($account);
$entityManager->flush();
}

return $this->redirectToRoute('app_account_index', [], Response::HTTP_SEE_OTHER);
}
}
82 changes: 82 additions & 0 deletions src/Controller/ClientController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Controller;

use App\Entity\Client;
use App\Form\ClientType;
use App\Repository\ClientRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/admin/client')]
class ClientController extends AbstractController
{
#[Route('/', name: 'app_client_index', methods: ['GET'])]
public function index(ClientRepository $clientRepository): Response
{
return $this->render('client/index.html.twig', [
'clients' => $clientRepository->findAll(),
]);
}

#[Route('/new', name: 'app_client_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$client = new Client();
$form = $this->createForm(ClientType::class, $client);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($client);
$entityManager->flush();

return $this->redirectToRoute('app_client_index', [], Response::HTTP_SEE_OTHER);
}

return $this->render('client/new.html.twig', [
'client' => $client,
'form' => $form,
]);
}

#[Route('/{id}', name: 'app_client_show', methods: ['GET'])]
public function show(Client $client): Response
{
return $this->render('client/show.html.twig', [
'client' => $client,
]);
}

#[Route('/{id}/edit', name: 'app_client_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Client $client, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(ClientType::class, $client);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();

return $this->redirectToRoute('app_client_index', [], Response::HTTP_SEE_OTHER);
}

return $this->render('client/edit.html.twig', [
'client' => $client,
'form' => $form,
]);
}

#[Route('/{id}', name: 'app_client_delete', methods: ['POST'])]
public function delete(Request $request, Client $client, EntityManagerInterface $entityManager): Response
{
$token = $request->request->get('_token');
if (is_string($token) && $this->isCsrfTokenValid('delete'.$client->getId(), $token)) {
$entityManager->remove($client);
$entityManager->flush();
}

return $this->redirectToRoute('app_client_index', [], Response::HTTP_SEE_OTHER);
}
}
Loading

0 comments on commit b7b16d1

Please sign in to comment.