Added admin pages for manufacturers and suppliers.

This commit is contained in:
Jan Böhmer 2019-04-26 19:12:48 +02:00
parent df0a8254bf
commit 4e9cbdffed
9 changed files with 383 additions and 6 deletions

View file

@ -0,0 +1,112 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
use App\Entity\AttachmentType;
use App\Entity\Manufacturer;
use App\Entity\Supplier;
use App\Form\BaseEntityAdminForm;
use App\Form\CompanyForm;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/**
* @Route("/manufacturer")
* @package App\Controller
*/
class ManufacturerController extends BaseAdminController
{
protected $entity_class = Manufacturer::class;
protected $twig_template = 'AdminPages/ManufacturerAdmin.html.twig';
protected $form_class = CompanyForm::class;
protected $route_base = 'manufacturer';
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="manufacturer_edit")
* @Route("/{id}/", requirements={"id"="\d+"})
*/
public function edit(Manufacturer $entity, Request $request, EntityManagerInterface $em)
{
return $this->_edit($entity, $request, $em);
}
/**
* @Route("/new", name="manufacturer_new")
* @Route("/")
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer)
{
return $this->_new($request, $em, $importer);
}
/**
* @Route("/{id}", name="manufacturer_delete", methods={"DELETE"})
*/
public function delete(Request $request, Manufacturer $entity, StructuralElementRecursionHelper $recursionHelper)
{
return $this->_delete($request, $entity, $recursionHelper);
}
/**
* @Route("/export", name="manufacturer_export_all")
* @param Request $request
* @param SerializerInterface $serializer
* @param EntityManagerInterface $em
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
{
return $this->_exportAll($em, $exporter, $request);
}
/**
* @Route("/{id}/export", name="manufacturer_export")
* @param Request $request
* @param Supplier $entity
*/
public function exportEntity(Manufacturer $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}

View file

@ -0,0 +1,111 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
use App\Entity\AttachmentType;
use App\Entity\Supplier;
use App\Form\BaseEntityAdminForm;
use App\Form\CompanyForm;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/**
* @Route("/supplier")
* @package App\Controller
*/
class SupplierController extends BaseAdminController
{
protected $entity_class = Supplier::class;
protected $twig_template = 'AdminPages/SupplierAdmin.html.twig';
protected $form_class = CompanyForm::class;
protected $route_base = "supplier";
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="supplier_edit")
* @Route("/{id}/", requirements={"id"="\d+"})
*/
public function edit(Supplier $entity, Request $request, EntityManagerInterface $em)
{
return $this->_edit($entity, $request, $em);
}
/**
* @Route("/new", name="supplier_new")
* @Route("/")
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer)
{
return $this->_new($request, $em, $importer);
}
/**
* @Route("/{id}", name="supplier_delete", methods={"DELETE"})
*/
public function delete(Request $request, Supplier $entity, StructuralElementRecursionHelper $recursionHelper)
{
return $this->_delete($request, $entity, $recursionHelper);
}
/**
* @Route("/export", name="supplier_export_all")
* @param Request $request
* @param SerializerInterface $serializer
* @param EntityManagerInterface $em
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
{
return $this->_exportAll($em, $exporter, $request);
}
/**
* @Route("/{id}/export", name="supplier_export")
* @param Request $request
* @param Supplier $entity
*/
public function exportEntity(Supplier $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}

View file

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This abstract class is used for companies like suppliers or manufacturers.
@ -36,37 +37,39 @@ abstract class Company extends StructuralDBElement
* @var string The address of the company
* @ORM\Column(type="string")
*/
protected $address;
protected $address = "";
/**
* @var string The phone number of the company
* @ORM\Column(type="string")
*/
protected $phone_number;
protected $phone_number = "";
/**
* @var string The fax number of the company
* @ORM\Column(type="string")
*/
protected $fax_number;
protected $fax_number = "";
/**
* @var string The email address of the company
* @ORM\Column(type="string")
* @Assert\Email()
*/
protected $email_address;
protected $email_address = "";
/**
* @var string The website of the company
* @ORM\Column(type="string")
* @Assert\Url()
*/
protected $website;
protected $website = "";
/**
* @var string
* @ORM\Column(type="string")
*/
protected $auto_product_url;
protected $auto_product_url = "";
/********************************************************************************
*

86
src/Form/CompanyForm.php Normal file
View file

@ -0,0 +1,86 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form;
use App\Entity\NamedDBElement;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
class CompanyForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$builder->add('address', TextareaType::class, ['label' => 'company.address.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
'attr' => ['placeholder' => 'company.address.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('phone_number', TelType::class, ['label' => 'company.phone_number.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
'attr' => ['placeholder' => 'company.phone_number.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('fax_number', TelType::class, ['label' => 'company.fax_number.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('email_address', EmailType::class, ['label' => 'company.email.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
'attr' => ['placeholder' => 'company.email.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('website', UrlType::class, ['label' => 'company.website.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
'attr' => ['placeholder' => 'company.website.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('auto_product_url', UrlType::class, ['label' => 'company.auto_product_url.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
'attr' => ['placeholder' => 'company.auto_product_url.placeholder'], 'required' => false,
'empty_data' => ''
]);
}
}

View file

@ -32,8 +32,10 @@ namespace App\Services;
use App\Entity\AttachmentType;
use App\Entity\Category;
use App\Entity\Device;
use App\Entity\Manufacturer;
use App\Entity\NamedDBElement;
use App\Entity\Part;
use App\Entity\Supplier;
use App\Exceptions\EntityNotSupported;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@ -123,6 +125,14 @@ class EntityURLGenerator
return $this->urlGenerator->generate("device_edit", ['id' => $entity->getID()]);
}
if ($entity instanceof Supplier) {
return $this->urlGenerator->generate("supplier_edit", ['id' => $entity->getID()]);
}
if ($entity instanceof Manufacturer) {
return $this->urlGenerator->generate("manufacturer_edit", ['id' => $entity->getID()]);
}
//Otherwise throw an error
throw new EntityNotSupported('The given entity is not supported yet!');
}
@ -152,6 +162,14 @@ class EntityURLGenerator
return $this->urlGenerator->generate('device_new');
}
if ($entity instanceof Supplier) {
return $this->urlGenerator->generate('supplier_new');
}
if ($entity instanceof Manufacturer) {
return $this->urlGenerator->generate('manufacturer_new');
}
throw new EntityNotSupported('The given entity is not supported yet!');
}
@ -202,6 +220,14 @@ class EntityURLGenerator
return $this->urlGenerator->generate('device_delete', ['id' => $entity->getID()]);
}
if ($entity instanceof Supplier) {
return $this->urlGenerator->generate('supplier_delete', ['id' => $entity->getID()]);
}
if ($entity instanceof Manufacturer) {
return $this->urlGenerator->generate('manufacturer_new', ['id' => $entity->getID()]);
}
throw new EntityNotSupported('The given entity is not supported yet!');
}

View file

@ -0,0 +1,23 @@
{% extends "AdminPages/EntityAdminBase.html.twig" %}
{% block additional_controls %}
{{ form_row(form.address) }}
{{ form_row(form.phone_number) }}
{{ form_row(form.fax_number) }}
{{ form_row(form.email_address) }}
{{ form_row(form.website) }}
{{ form_row(form.auto_product_url) }}
{% endblock %}
{% block comment %}{% endblock %}
{% block additional_pills %}
<li class="nav-item"><a data-toggle="tab" class="nav-link link-anchor" href="#home_comment">{% trans %}admin.comment{% endtrans %}</a></li>
{% endblock %}
{% block additional_panes %}
<div class="tab-pane" id="home_comment">
{{ form_row(form.comment) }}
</div>
{% endblock %}

View file

@ -66,7 +66,13 @@
<div class="tab-pane active" id="home_common">
{{ form_row(form.name) }}
{{ form_row(form.parent) }}
{% block additional_controls %}{% endblock %}
{% block comment %}
{{ form_row(form.comment) }}
{% endblock %}
</div>
{% block additional_panes %}{% endblock %}
</div>

View file

@ -0,0 +1,5 @@
{% extends "AdminPages/CompanyAdminBase.html.twig" %}
{% block card_title %}
<i class="fas fa-industry fa-fw"></i> {% trans %}manufacturer.caption{% endtrans %}
{% endblock %}

View file

@ -0,0 +1,5 @@
{% extends "AdminPages/CompanyAdminBase.html.twig" %}
{% block card_title %}
<i class="fas fa-truck fa-fw"></i> {% trans %}supplier.caption{% endtrans %}
{% endblock %}