Made a simple product crud In the Testypes Menu HUD
This commit is contained in:
parent
dc4d5f90a7
commit
42a3e34a98
19 changed files with 870 additions and 142 deletions
|
|
@ -28,6 +28,7 @@
|
|||
"ext-iconv": "*",
|
||||
"composer/package-versions-deprecated": "1.11.99.4",
|
||||
"data-dog/audit-bundle": "^0.1.10",
|
||||
"doctrine/annotations": "^1.13",
|
||||
"doctrine/common": "^2",
|
||||
"doctrine/doctrine-bundle": "^2",
|
||||
"doctrine/doctrine-migrations-bundle": "^2",
|
||||
|
|
|
|||
19
composer.lock
generated
19
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "653f8558c75614dd65421cb3eb48c29b",
|
||||
"content-hash": "da765755121aaeb5c5a43aa74d7eeb76",
|
||||
"packages": [
|
||||
{
|
||||
"name": "composer/package-versions-deprecated",
|
||||
|
|
@ -4400,22 +4400,25 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/flex",
|
||||
"version": "v1.17.3",
|
||||
"version": "v1.21.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/flex.git",
|
||||
"reference": "acd0b5018fe9c2f5be6c67367987b5c723c0e096"
|
||||
"reference": "bda5f869ac51c8e985a6fe9f964c4cb78228a369"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/flex/zipball/acd0b5018fe9c2f5be6c67367987b5c723c0e096",
|
||||
"reference": "acd0b5018fe9c2f5be6c67367987b5c723c0e096",
|
||||
"url": "https://api.github.com/repos/symfony/flex/zipball/bda5f869ac51c8e985a6fe9f964c4cb78228a369",
|
||||
"reference": "bda5f869ac51c8e985a6fe9f964c4cb78228a369",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "^1.0|^2.0",
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"conflict": {
|
||||
"composer/semver": "<1.7.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer": "^1.0.2|^2.0",
|
||||
"symfony/dotenv": "^4.4|^5.0|^6.0",
|
||||
|
|
@ -4445,7 +4448,7 @@
|
|||
"description": "Composer plugin for Symfony",
|
||||
"support": {
|
||||
"issues": "https://github.com/symfony/flex/issues",
|
||||
"source": "https://github.com/symfony/flex/tree/v1.17.3"
|
||||
"source": "https://github.com/symfony/flex/tree/v1.21.8"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
|
@ -4461,7 +4464,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-11-22T18:48:50+00:00"
|
||||
"time": "2024-10-07T08:51:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/framework-bundle",
|
||||
|
|
@ -7969,5 +7972,5 @@
|
|||
"ext-iconv": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -673,6 +673,22 @@ catalyst_auth:
|
|||
- id: item_pricing.update
|
||||
label: Update
|
||||
|
||||
- id: test_list
|
||||
label: TestTypes
|
||||
acls:
|
||||
- id: test.menu
|
||||
label: Menu
|
||||
- id: test.add
|
||||
label: Add
|
||||
- id: test.update
|
||||
label: Update
|
||||
- id: test.delete
|
||||
label: Delete
|
||||
- id: test.list
|
||||
label: List
|
||||
|
||||
|
||||
|
||||
api:
|
||||
user_entity: "App\\Entity\\ApiUser"
|
||||
acl_data:
|
||||
|
|
|
|||
|
|
@ -306,3 +306,7 @@ catalyst_menu:
|
|||
acl: item_pricing.update
|
||||
label: Item Pricing
|
||||
parent: item
|
||||
|
||||
- id: test_list
|
||||
acl: test.menu
|
||||
label: TestTypes
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
#index:
|
||||
# path: /
|
||||
# controller: App\Controller\DefaultController::index
|
||||
#
|
||||
#
|
||||
34
config/routes/test.yaml
Normal file
34
config/routes/test.yaml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
test_list:
|
||||
path: /test
|
||||
controller: App\Controller\EntityController::index
|
||||
methods: [GET]
|
||||
|
||||
test_type_rows:
|
||||
path: /test/rowdata
|
||||
controller: App\Controller\EntityController::datatableRows
|
||||
methods: [POST]
|
||||
|
||||
test_type_add_form:
|
||||
path: /test/newform
|
||||
controller: App\Controller\EntityController::addForm
|
||||
methods: [GET]
|
||||
|
||||
test_type_add_submit:
|
||||
path: /test
|
||||
controller: App\Controller\EntityController::addSubmit
|
||||
methods: [POST]
|
||||
|
||||
test_type_update_form:
|
||||
path: /test/{id}
|
||||
controller: App\Controller\EntityController::updateForm
|
||||
methods: [GET]
|
||||
|
||||
test_type_update_submit:
|
||||
path: /test/{id}
|
||||
controller: App\Controller\EntityController::updateSubmit
|
||||
methods: [POST]
|
||||
|
||||
test_type_delete:
|
||||
path: /test/{id}
|
||||
controller: App\Controller\EntityController::deleteSubmit
|
||||
methods: [DELETE]
|
||||
0
description
Normal file
0
description
Normal file
0
id
Normal file
0
id
Normal file
0
item
Normal file
0
item
Normal file
0
price
Normal file
0
price
Normal file
256
src/Controller/EntityController.php
Normal file
256
src/Controller/EntityController.php
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Test;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
||||
|
||||
use Catalyst\MenuBundle\Annotation\Menu;
|
||||
|
||||
|
||||
|
||||
class EntityController extends Controller{
|
||||
|
||||
/**
|
||||
* @Menu(selected="test_list")
|
||||
* @IsGranted("test.list")
|
||||
*/
|
||||
public function index ()
|
||||
{
|
||||
return $this->render('entity/list.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="test_list")
|
||||
* @IsGranted("test.add")
|
||||
*/
|
||||
public function addForm()
|
||||
{
|
||||
$test = new Test();
|
||||
$params = [
|
||||
'obj' => $test,
|
||||
'mode' => 'create',
|
||||
];
|
||||
|
||||
// response
|
||||
return $this->render('entity/form.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @IsGranted("test.add")
|
||||
*/
|
||||
public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator)
|
||||
{
|
||||
$test = new Test();
|
||||
|
||||
$this->setObject($test, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($test);
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||
}
|
||||
|
||||
// check if any errors were found
|
||||
if (!empty($error_array)) {
|
||||
// return validation failure response
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'errors' => $error_array
|
||||
], 422);
|
||||
}
|
||||
|
||||
// validated! save the entity
|
||||
$em->persist($test);
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Menu(selected="test_list")
|
||||
* @IsGranted("test.update")
|
||||
*/
|
||||
public function updateForm($id, EntityManagerInterface $em, Test $test)
|
||||
{
|
||||
$params = [];
|
||||
$params['obj'] = $test;
|
||||
$params['mode'] = 'update';
|
||||
|
||||
// response
|
||||
return $this->render('entity/form.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @IsGranted("test.update")
|
||||
*/
|
||||
public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, Test $test)
|
||||
{
|
||||
$this->setObject($test, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($test);
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||
}
|
||||
|
||||
// check if any errors were found
|
||||
if (!empty($error_array)) {
|
||||
// return validation failure response
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'errors' => $error_array
|
||||
], 422);
|
||||
}
|
||||
|
||||
// validated! save the entity
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @IsGranted("test.delete")
|
||||
*/
|
||||
public function deleteSubmit(EntityManagerInterface $em, Test $test)
|
||||
{
|
||||
// delete this object
|
||||
$em->remove($test);
|
||||
$em->flush();
|
||||
|
||||
// response
|
||||
$response = new Response();
|
||||
$response->setStatusCode(Response::HTTP_OK);
|
||||
$response->send();
|
||||
}
|
||||
|
||||
protected function setObject(Test $obj, Request $req)
|
||||
{
|
||||
// set and save values
|
||||
$obj->setItem($req->request->get('item'))
|
||||
->setPrice($req->request->get('price'))
|
||||
->setDescription($req->request->get('description'));
|
||||
|
||||
}
|
||||
|
||||
protected function setQueryFilters($datatable, QueryBuilder $query)
|
||||
{
|
||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||
$query->where('q.name LIKE :filter')
|
||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @IsGranted("test.list")
|
||||
*/
|
||||
public function datatableRows(Request $req)
|
||||
{
|
||||
// get query builder
|
||||
$qb = $this->getDoctrine()
|
||||
->getRepository(Test::class)
|
||||
->createQueryBuilder('q');
|
||||
|
||||
// get datatable params
|
||||
$datatable = $req->request->get('datatable');
|
||||
|
||||
// count total records
|
||||
$tquery = $qb->select('COUNT(q)');
|
||||
$this->setQueryFilters($datatable, $tquery);
|
||||
$total = $tquery->getQuery()
|
||||
->getSingleScalarResult();
|
||||
|
||||
// get current page number
|
||||
$page = $datatable['pagination']['page'] ?? 1;
|
||||
|
||||
$perpage = $datatable['pagination']['perpage'];
|
||||
$offset = ($page - 1) * $perpage;
|
||||
|
||||
// add metadata
|
||||
$meta = [
|
||||
'page' => $page,
|
||||
'perpage' => $perpage,
|
||||
'pages' => ceil($total / $perpage),
|
||||
'total' => $total,
|
||||
'sort' => 'asc',
|
||||
'field' => 'id'
|
||||
];
|
||||
|
||||
// build query
|
||||
$query = $qb->select('q');
|
||||
$this->setQueryFilters($datatable, $query);
|
||||
|
||||
// check if sorting is present, otherwise use default
|
||||
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||
} else {
|
||||
$query->orderBy('q.id', 'asc');
|
||||
}
|
||||
|
||||
// get rows for this page
|
||||
$obj_rows = $query->setFirstResult($offset)
|
||||
->setMaxResults($perpage)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
// process rows
|
||||
$rows = [];
|
||||
foreach ($obj_rows as $orow) {
|
||||
// add row data
|
||||
$row['id'] = $orow->getID();
|
||||
$row['item'] = $orow->getItem();
|
||||
$row['price'] = $orow->getPrice();
|
||||
$row['description'] = $orow->getDescription();
|
||||
|
||||
|
||||
// add row metadata
|
||||
$row['meta'] = [
|
||||
'update_url' => '',
|
||||
'delete_url' => ''
|
||||
];
|
||||
|
||||
// add crud urls
|
||||
if ($this->isGranted('test.update'))
|
||||
$row['meta']['update_url'] = $this->generateUrl('test_type_update_form', ['id' => $row['id']]);
|
||||
if ($this->isGranted('test.delete'))
|
||||
$row['meta']['delete_url'] = $this->generateUrl('test_type_delete', ['id' => $row['id']]);
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
// response
|
||||
return $this->json([
|
||||
'meta' => $meta,
|
||||
'data' => $rows
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
75
src/Entity/Test.php
Normal file
75
src/Entity/Test.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\TestRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass=TestRepository::class)
|
||||
*/
|
||||
class Test
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
private $item;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="decimal", precision=8, scale=2)
|
||||
*/
|
||||
private $price;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
private $description;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getItem(): ?string
|
||||
{
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
public function setItem(string $item): self
|
||||
{
|
||||
$this->item = $item;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPrice(): ?string
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
public function setPrice(string $price): self
|
||||
{
|
||||
$this->price = $price;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): self
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
39
src/Migrations/Version20241017062927.php
Normal file
39
src/Migrations/Version20241017062927.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?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 Version20241017062927 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->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, placeholder VARCHAR(120) NOT NULL, password LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('DROP TABLE test');
|
||||
$this->addSql('ALTER TABLE battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||
}
|
||||
}
|
||||
39
src/Migrations/Version20241018002028.php
Normal file
39
src/Migrations/Version20241018002028.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?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 Version20241018002028 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->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||
$this->addSql('ALTER TABLE test ADD item VARCHAR(255) NOT NULL, ADD price NUMERIC(10, 2) NOT NULL, DROP placeholder, CHANGE password description LONGTEXT NOT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||
$this->addSql('ALTER TABLE test ADD placeholder VARCHAR(120) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, DROP item, DROP price, CHANGE description password LONGTEXT CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`');
|
||||
}
|
||||
}
|
||||
39
src/Migrations/Version20241018012501.php
Normal file
39
src/Migrations/Version20241018012501.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?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 Version20241018012501 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->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, item VARCHAR(255) NOT NULL, price NUMERIC(8, 2) NOT NULL, description LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update timestamp default current_timestamp on update current_timestamp');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('DROP TABLE test');
|
||||
$this->addSql('ALTER TABLE battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||
$this->addSql('ALTER TABLE sap_battery CHANGE date_update date_update DATETIME DEFAULT CURRENT_TIMESTAMP');
|
||||
}
|
||||
}
|
||||
50
src/Repository/TestRepository.php
Normal file
50
src/Repository/TestRepository.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Test;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method Test|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Test|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Test[] findAll()
|
||||
* @method Test[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class TestRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Test::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Test[] Returns an array of Test objects
|
||||
// */
|
||||
/*
|
||||
public function findByExampleField($value)
|
||||
{
|
||||
return $this->createQueryBuilder('t')
|
||||
->andWhere('t.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->orderBy('t.id', 'ASC')
|
||||
->setMaxResults(10)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public function findOneBySomeField($value): ?Test
|
||||
{
|
||||
return $this->createQueryBuilder('t')
|
||||
->andWhere('t.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
}
|
||||
151
templates/entity/form.html.twig
Normal file
151
templates/entity/form.html.twig
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">Test Types</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-6">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<span class="m-portlet__head-icon">
|
||||
<i class="la la-industry"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
{% if mode == 'update' %}
|
||||
Edit Test Type
|
||||
<small>{{ obj.getItem() }}</small>
|
||||
{% else %}
|
||||
New Test Type
|
||||
{% endif %}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ mode == 'update' ? url('test_type_update_submit', {'id': obj.getId()}) : url('test_type_add_submit') }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<label class="col-lg-3 col-form-label" data-field="item">
|
||||
Item:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
<input type="text" name="item" class="form-control m-input" value="{{ obj.getItem() }}">
|
||||
<div class="form-control-feedback hide" data-field="item"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<label class="col-lg-3 col-form-label" data-field="price">
|
||||
Price:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
<input type="number" step="0.01" name="price" class="form-control m-input" value="{{ obj.getPrice() }}">
|
||||
<div class="form-control-feedback hide" data-field="price"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<label class="col-lg-3 col-form-label" data-field="description">
|
||||
Description:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
<textarea name="description" class="form-control m-input">{{ obj.getDescription() }}</textarea>
|
||||
<div class="form-control-feedback hide" data-field="description"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
<a href="{{ url('test_list') }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$(function() {
|
||||
$("#row-form").submit(function(e) {
|
||||
var form = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: form.prop('action'),
|
||||
data: form.serialize()
|
||||
}).done(function(response) {
|
||||
// remove all error classes
|
||||
removeErrors();
|
||||
swal({
|
||||
title: 'Done!',
|
||||
text: 'Your changes have been saved!',
|
||||
type: 'success',
|
||||
onClose: function() {
|
||||
window.location.href = "{{ url('test_list') }}";
|
||||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
if (response.status == 422) {
|
||||
var errors = response.responseJSON.errors;
|
||||
var firstfield = false;
|
||||
|
||||
// remove all error classes first
|
||||
removeErrors();
|
||||
|
||||
// display errors contextually
|
||||
$.each(errors, function(field, msg) {
|
||||
var formfield = $("[name='" + field + "']");
|
||||
var label = $("label[data-field='" + field + "']");
|
||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||
|
||||
// add error classes to bad fields
|
||||
formfield.addClass('form-control-danger');
|
||||
label.addClass('has-danger');
|
||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||
|
||||
// check if this field comes first in DOM
|
||||
var domfield = formfield.get(0);
|
||||
|
||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||
firstfield = domfield;
|
||||
}
|
||||
});
|
||||
|
||||
// focus on first bad field
|
||||
firstfield.focus();
|
||||
|
||||
// scroll to above that field to make it visible
|
||||
$('html, body').animate({
|
||||
scrollTop: $(firstfield).offset().top - 200
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// remove all error classes
|
||||
function removeErrors() {
|
||||
$(".form-control-danger").removeClass('form-control-danger');
|
||||
$("[data-field]").removeClass('has-danger');
|
||||
$(".form-control-feedback[data-field]").addClass('hide');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
154
templates/entity/list.html.twig
Normal file
154
templates/entity/list.html.twig
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">
|
||||
Items
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__body">
|
||||
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-xl-8 order-2 order-xl-1">
|
||||
<div class="form-group m-form__group row align-items-center">
|
||||
<div class="col-md-4">
|
||||
<div class="m-input-icon m-input-icon--left">
|
||||
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||
<span><i class="la la-search"></i></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||
<a href="{{ url('test_type_add_form') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||
<span>
|
||||
<i class="la la-industry"></i>
|
||||
<span>New Item</span>
|
||||
</span>
|
||||
</a>
|
||||
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--begin: Datatable -->
|
||||
<div id="data-rows"></div>
|
||||
<!--end: Datatable -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$(function() {
|
||||
var options = {
|
||||
data: {
|
||||
type: 'remote',
|
||||
source: {
|
||||
read: {
|
||||
url: '{{ url("test_type_rows") }}',
|
||||
method: 'POST'
|
||||
}
|
||||
},
|
||||
saveState: {
|
||||
cookie: false,
|
||||
webstorage: false
|
||||
},
|
||||
pageSize: 10,
|
||||
serverPaging: true,
|
||||
serverFiltering: true,
|
||||
serverSorting: true
|
||||
},
|
||||
layout: {
|
||||
scroll: true
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
title: 'ID',
|
||||
width: 30
|
||||
},
|
||||
{
|
||||
field: 'item',
|
||||
title: 'Name'
|
||||
},
|
||||
{
|
||||
field: 'price',
|
||||
title: 'Price'
|
||||
},
|
||||
{
|
||||
field: 'description',
|
||||
title: 'Description'
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
width: 110,
|
||||
title: 'Actions',
|
||||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
var actions = '';
|
||||
|
||||
if (row.meta.update_url != '') {
|
||||
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||
}
|
||||
|
||||
if (row.meta.delete_url != '') {
|
||||
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||
}
|
||||
|
||||
return actions;
|
||||
},
|
||||
}
|
||||
],
|
||||
search: {
|
||||
onEnter: false,
|
||||
input: $('#data-rows-search'),
|
||||
delay: 400
|
||||
}
|
||||
};
|
||||
|
||||
var table = $("#data-rows").mDatatable(options);
|
||||
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
var url = $(this).prop('href');
|
||||
var id = $(this).data('id');
|
||||
var btn = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
swal({
|
||||
title: 'Confirmation',
|
||||
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||
type: 'warning',
|
||||
showCancelButton: true
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
method: "DELETE",
|
||||
url: url
|
||||
}).done(function(response) {
|
||||
table.row(btn.parents('tr')).remove();
|
||||
table.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -10,133 +10,5 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-6">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<span class="m-portlet__head-icon">
|
||||
<i class="la la-industry"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
{% if mode == 'update' %}
|
||||
Edit Item Type
|
||||
<small>{{ obj.getName() }}</small>
|
||||
{% else %}
|
||||
New Item Type
|
||||
{% endif %}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ mode == 'update' ? url('item_type_update_submit', {'id': obj.getId()}) : url('item_type_add_submit') }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<label class="col-lg-3 col-form-label" data-field="name">
|
||||
Name:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
<input type="text" name="name" class="form-control m-input" value="{{ obj.getName() }}">
|
||||
<div class="form-control-feedback hide" data-field="name"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<label class="col-lg-3 col-form-label" data-field="code">
|
||||
Code:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
<input type="text" name="code" class="form-control m-input" value="{{ obj.getCode() }}">
|
||||
<div class="form-control-feedback hide" data-field="code"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
<a href="{{ url('item_type_list') }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$(function() {
|
||||
$("#row-form").submit(function(e) {
|
||||
var form = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: form.prop('action'),
|
||||
data: form.serialize()
|
||||
}).done(function(response) {
|
||||
// remove all error classes
|
||||
removeErrors();
|
||||
swal({
|
||||
title: 'Done!',
|
||||
text: 'Your changes have been saved!',
|
||||
type: 'success',
|
||||
onClose: function() {
|
||||
window.location.href = "{{ url('item_type_list') }}";
|
||||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
if (response.status == 422) {
|
||||
var errors = response.responseJSON.errors;
|
||||
var firstfield = false;
|
||||
|
||||
// remove all error classes first
|
||||
removeErrors();
|
||||
|
||||
// display errors contextually
|
||||
$.each(errors, function(field, msg) {
|
||||
var formfield = $("[name='" + field + "']");
|
||||
var label = $("label[data-field='" + field + "']");
|
||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||
|
||||
// add error classes to bad fields
|
||||
formfield.addClass('form-control-danger');
|
||||
label.addClass('has-danger');
|
||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||
|
||||
// check if this field comes first in DOM
|
||||
var domfield = formfield.get(0);
|
||||
|
||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||
firstfield = domfield;
|
||||
}
|
||||
});
|
||||
|
||||
// focus on first bad field
|
||||
firstfield.focus();
|
||||
|
||||
// scroll to above that field to make it visible
|
||||
$('html, body').animate({
|
||||
scrollTop: $(firstfield).offset().top - 200
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// remove all error classes
|
||||
function removeErrors() {
|
||||
$(".form-control-danger").removeClass('form-control-danger');
|
||||
$("[data-field]").removeClass('has-danger');
|
||||
$(".form-control-feedback[data-field]").addClass('hide');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue