Skip to content

Commit

Permalink
Merge pull request #62 from itk-dev/feature/380-views
Browse files Browse the repository at this point in the history
Feature: Add View entity and CRUD
  • Loading branch information
tuj authored Jan 26, 2024
2 parents e830fda + d433040 commit af952ea
Show file tree
Hide file tree
Showing 69 changed files with 1,421 additions and 181 deletions.
1 change: 1 addition & 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 view and related form
* Default to work id worker not longer exists in Leantime worklog sync.
* Added commands to manage data providers.
* Changed how errors are handled in Leantime api calls.
Expand Down
29 changes: 29 additions & 0 deletions assets/controllers/view-selector_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {

static targets = ['select'];
connect() {
this.defaultViewEndpoint = this.element.dataset.defaultViewUpdateEndpoint;
}
select(event) {
const newDefaultView = event.target.options[event.target.selectedIndex].value;
const pathArray = window.location.pathname.split('/');
const params = window.location.search;

let i = 1;
if ('admin' === pathArray[1]) {
let newPath = "";
for (i = 1; i < pathArray.length; i++) {
newPath += "/";
if (i === 2) {
newPath += newDefaultView;
}
else {
newPath += pathArray[i];
}
}

window.location.replace(newPath + params);
}
}
}
12 changes: 8 additions & 4 deletions assets/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@
bottom: 0;
}

.comma-list span:after {
content: ","
}

.comma-list span:last-child:after {
content: ""
}

.navigation-item + .navigation-item-submenu {
padding: 0 18px;
display: none;
Expand All @@ -365,8 +373,4 @@
font-size: 10px;
padding-right: 5px;
}

.navigation-item.current {
background-color: rgb(15, 23, 42);
}
}
2 changes: 2 additions & 0 deletions config/packages/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ twig:
default_path: '%kernel.project_dir%/templates'
date:
format: 'd.m.Y'
globals:
view_controller: '@App\Controller\ViewController'

when@test:
twig:
Expand Down
43 changes: 43 additions & 0 deletions migrations/Version20240118074743.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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 Version20240118074743 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('CREATE TABLE view (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE view_data_provider (view_id INT NOT NULL, data_provider_id INT NOT NULL, INDEX IDX_4AE832DD31518C7 (view_id), INDEX IDX_4AE832DDF593F7E0 (data_provider_id), PRIMARY KEY(view_id, data_provider_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE view_project (view_id INT NOT NULL, project_id INT NOT NULL, INDEX IDX_6EEC51431518C7 (view_id), INDEX IDX_6EEC514166D1F9C (project_id), PRIMARY KEY(view_id, project_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE view_data_provider ADD CONSTRAINT FK_4AE832DD31518C7 FOREIGN KEY (view_id) REFERENCES view (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE view_data_provider ADD CONSTRAINT FK_4AE832DDF593F7E0 FOREIGN KEY (data_provider_id) REFERENCES data_provider (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE view_project ADD CONSTRAINT FK_6EEC51431518C7 FOREIGN KEY (view_id) REFERENCES view (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE view_project ADD CONSTRAINT FK_6EEC514166D1F9C FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE CASCADE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE view_data_provider DROP FOREIGN KEY FK_4AE832DD31518C7');
$this->addSql('ALTER TABLE view_data_provider DROP FOREIGN KEY FK_4AE832DDF593F7E0');
$this->addSql('ALTER TABLE view_project DROP FOREIGN KEY FK_6EEC51431518C7');
$this->addSql('ALTER TABLE view_project DROP FOREIGN KEY FK_6EEC514166D1F9C');
$this->addSql('DROP TABLE view');
$this->addSql('DROP TABLE view_data_provider');
$this->addSql('DROP TABLE view_project');
}
}
12 changes: 8 additions & 4 deletions src/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

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

Expand All @@ -39,14 +40,16 @@ public function new(Request $request, EntityManagerInterface $entityManager): Re
return $this->render('account/new.html.twig', [
'account' => $account,
'form' => $form,
'viewId' => $request->attributes->get('viewId'),
]);
}

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

Expand All @@ -65,6 +68,7 @@ public function edit(Request $request, Account $account, EntityManagerInterface
return $this->render('account/edit.html.twig', [
'account' => $account,
'form' => $form,
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand All @@ -77,6 +81,6 @@ public function delete(Request $request, Account $account, EntityManagerInterfac
$entityManager->flush();
}

return $this->redirectToRoute('app_account_index', [], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_account_index', ['viewId' => $request->attributes->get('viewId')], Response::HTTP_SEE_OTHER);
}
}
12 changes: 8 additions & 4 deletions src/Controller/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

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

Expand All @@ -39,14 +40,16 @@ public function new(Request $request, EntityManagerInterface $entityManager): Re
return $this->render('client/new.html.twig', [
'client' => $client,
'form' => $form,
'viewId' => $request->attributes->get('viewId'),
]);
}

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

Expand All @@ -65,6 +68,7 @@ public function edit(Request $request, Client $client, EntityManagerInterface $e
return $this->render('client/edit.html.twig', [
'client' => $client,
'form' => $form,
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand All @@ -77,6 +81,6 @@ public function delete(Request $request, Client $client, EntityManagerInterface
$entityManager->flush();
}

return $this->redirectToRoute('app_client_index', [], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_client_index', ['viewId' => $request->attributes->get('viewId')], Response::HTTP_SEE_OTHER);
}
}
7 changes: 4 additions & 3 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/admin')]
#[Route('/admin/{viewId}')]
class HomeController extends AbstractController
{
#[Route('/', name: 'index')]
public function index(): Response
public function index(Request $request): Response
{
return $this->render('home/index.html.twig');
return $this->render('home/index.html.twig', ['viewId' => $request->attributes->get('viewId')]);
}
}
16 changes: 11 additions & 5 deletions src/Controller/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

#[Route('/admin/invoices')]
#[Route('/admin/{viewId}/invoices')]
class InvoiceController extends AbstractController
{
public function __construct(
Expand All @@ -47,7 +47,8 @@ public function index(Request $request, InvoiceRepository $invoiceRepository): R
'form' => $form,
'invoices' => $pagination,
'invoiceFilterData' => $invoiceFilterData,
'submitEndpoint' => $this->generateUrl('app_invoices_export_selection'),
'submitEndpoint' => $this->generateUrl('app_invoices_export_selection', ['viewId' => $request->attributes->get('viewId')]),
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand All @@ -69,12 +70,14 @@ public function new(Request $request, InvoiceRepository $invoiceRepository, stri

return $this->redirectToRoute('app_invoices_edit', [
'id' => $invoice->getId(),
'viewId' => $request->attributes->get('viewId'),
], Response::HTTP_SEE_OTHER);
}

return $this->render('invoices/new.html.twig', [
'invoice' => $invoice,
'form' => $form,
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand Down Expand Up @@ -193,6 +196,7 @@ public function edit(Request $request, Invoice $invoice, InvoiceRepository $invo

return $carry;
}, 0.0),
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand Down Expand Up @@ -230,7 +234,7 @@ public function delete(Request $request, Invoice $invoice, InvoiceRepository $in
$invoiceRepository->remove($invoice, true);
}

return $this->redirectToRoute('app_invoices_index', [], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_invoices_index', ['viewId' => $request->attributes->get('viewId')], Response::HTTP_SEE_OTHER);
}

/**
Expand Down Expand Up @@ -262,13 +266,14 @@ public function record(Request $request, Invoice $invoice): Response
$this->billingService->recordInvoice($invoice);
}

return $this->redirectToRoute('app_invoices_edit', ['id' => $invoice->getId()], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_invoices_edit', ['viewId' => $request->attributes->get('viewId'), 'id' => $invoice->getId()], Response::HTTP_SEE_OTHER);
}

return $this->render('invoices/record.html.twig', [
'invoice' => $invoice,
'form' => $form,
'errors' => $errors,
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand All @@ -278,13 +283,14 @@ public function record(Request $request, Invoice $invoice): Response
* @throws EconomicsException
*/
#[Route('/{id}/show-export', name: 'app_invoices_show_export', methods: ['GET'])]
public function showExport(Invoice $invoice): Response
public function showExport(Request $request, Invoice $invoice): Response
{
$html = $this->billingService->generateSpreadsheetHtml([$invoice->getId()]);

return $this->render('invoices/export_show.html.twig', [
'invoice' => $invoice,
'html' => $html,
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand Down
10 changes: 6 additions & 4 deletions src/Controller/InvoiceEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

#[Route('/admin/invoices/{invoice}/entries')]
#[Route('/admin/{viewId}/invoices/{invoice}/entries')]
class InvoiceEntryController extends AbstractController
{
public function __construct(
Expand Down Expand Up @@ -62,16 +62,17 @@ public function new(Request $request, Invoice $invoice, InvoiceEntryTypeEnum $ty
$this->billingService->updateInvoiceEntryTotalPrice($invoiceEntry);

if (InvoiceEntryTypeEnum::MANUAL == $invoiceEntry->getEntryType()) {
return $this->redirectToRoute('app_invoices_edit', ['id' => $invoice->getId()], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_invoices_edit', ['viewId' => $request->attributes->get('viewId'), 'id' => $invoice->getId()], Response::HTTP_SEE_OTHER);
}

return $this->redirectToRoute('app_invoice_entry_edit', ['id' => $invoiceEntry->getId(), 'invoice' => $invoice->getId()], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_invoice_entry_edit', ['viewId' => $request->attributes->get('viewId'), 'id' => $invoiceEntry->getId(), 'invoice' => $invoice->getId()], Response::HTTP_SEE_OTHER);
}

return $this->render('invoice_entry/new.html.twig', [
'invoice_entry' => $invoiceEntry,
'invoice' => $invoice,
'form' => $form,
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand Down Expand Up @@ -109,6 +110,7 @@ public function edit(Request $request, Invoice $invoice, InvoiceEntry $invoiceEn
'invoice_entry' => $invoiceEntry,
'invoice' => $invoice,
'form' => $form,
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand All @@ -129,6 +131,6 @@ public function delete(Request $request, Invoice $invoice, InvoiceEntry $invoice
$this->billingService->updateInvoiceTotalPrice($invoice);
}

return $this->redirectToRoute('app_invoices_edit', ['id' => $invoice->getId()], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_invoices_edit', ['viewId' => $request->attributes->get('viewId'), 'id' => $invoice->getId()], Response::HTTP_SEE_OTHER);
}
}
6 changes: 4 additions & 2 deletions src/Controller/InvoiceEntryWorklogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

#[Route('/admin/invoices/{invoice}/entries')]
#[Route('/admin/{viewId}/invoices/{invoice}/entries')]
class InvoiceEntryWorklogController extends AbstractController
{
public function __construct(
Expand Down Expand Up @@ -93,7 +93,8 @@ public function worklogs(Request $request, Invoice $invoice, InvoiceEntry $invoi
'invoice' => $invoice,
'invoiceEntry' => $invoiceEntry,
'worklogs' => $worklogs,
'submitEndpoint' => $this->generateUrl('app_invoice_entry_select_worklogs', ['invoice' => $invoice->getId(), 'invoiceEntry' => $invoiceEntry->getId()]),
'submitEndpoint' => $this->generateUrl('app_invoice_entry_select_worklogs', ['viewId' => $request->attributes->get('viewId'), 'invoice' => $invoice->getId(), 'invoiceEntry' => $invoiceEntry->getId()]),
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand All @@ -113,6 +114,7 @@ public function showWorklogs(Request $request, Invoice $invoice, InvoiceEntry $i
'invoice' => $invoice,
'invoiceEntry' => $invoiceEntry,
'worklogs' => $worklogs,
'viewId' => $request->attributes->get('viewId'),
]);
}

Expand Down
Loading

0 comments on commit af952ea

Please sign in to comment.