Fixed Consistency for routes and names

This commit is contained in:
Ansley 2024-10-23 15:21:52 +08:00
parent 2db8d5cd06
commit 9ea0224880
10 changed files with 157 additions and 56 deletions

View file

@ -673,20 +673,29 @@ catalyst_auth:
- id: item_pricing.update
label: Update
- id: test_list
label: TestTypes
- id: entity_list
label: EntityTypes
acls:
- id: test.menu
- id: entity.menu
label: Menu
- id: test.add
- id: entity.add
label: Add
- id: test.update
- id: entity.update
label: Update
- id: test.delete
- id: entity.delete
label: Delete
- id: test.list
- id: entity.list
label: List
- id: send_EDA
label: sendeda
acls:
- id: eda.menu
label: Menu
- id: eda.update
label: Update
- id: eda.list
label: List
api:

View file

@ -307,6 +307,11 @@ catalyst_menu:
label: Item Pricing
parent: item
- id: test_list
acl: test.menu
label: TestTypes
- id: entity_list
acl: entity.menu
label: EntityTypes
- id: send_EDA
acl: eda.menu
label: Notifs
parent: entity_list

View file

@ -1,34 +1,34 @@
test_list:
entity_list:
path: /test
controller: App\Controller\EntityController::index
methods: [GET]
test_type_rows:
entity_rows:
path: /test/rowdata
controller: App\Controller\EntityController::datatableRows
methods: [POST]
test_type_add_form:
entity_add_form:
path: /test/newform
controller: App\Controller\EntityController::addForm
methods: [GET]
test_type_add_submit:
entity_add_submit:
path: /test
controller: App\Controller\EntityController::addSubmit
methods: [POST]
test_type_update_form:
entity_update_form:
path: /test/{id}
controller: App\Controller\EntityController::updateForm
methods: [GET]
test_type_update_submit:
entity_update_submit:
path: /test/{id}
controller: App\Controller\EntityController::updateSubmit
methods: [POST]
test_type_delete:
entity_delete:
path: /test/{id}
controller: App\Controller\EntityController::deleteSubmit
methods: [DELETE]

View file

@ -2,7 +2,7 @@
namespace App\Controller;
use App\Entity\Test;
use App\Entity\Entity;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\EntityManagerInterface;
@ -21,8 +21,8 @@ use Catalyst\MenuBundle\Annotation\Menu;
class EntityController extends Controller{
/**
* @Menu(selected="test_list")
* @IsGranted("test.list")
* @Menu(selected="entity_list")
* @IsGranted("entity.list")
*/
public function index ()
{
@ -30,14 +30,14 @@ class EntityController extends Controller{
}
/**
* @Menu(selected="test_list")
* @IsGranted("test.add")
* @Menu(selected="entity_list")
* @IsGranted("entity.add")
*/
public function addForm()
{
$test = new Test();
$entity = new Entity();
$params = [
'obj' => $test,
'obj' => $entity,
'mode' => 'create',
];
@ -46,11 +46,11 @@ class EntityController extends Controller{
}
/**
* @IsGranted("test.add")
* @IsGranted("entity.add")
*/
public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator)
{
$test = new Test();
$test = new Entity();
$this->setObject($test, $req);
@ -86,13 +86,13 @@ class EntityController extends Controller{
/**
* @Menu(selected="test_list")
* @IsGranted("test.update")
* @Menu(selected="entity_list")
* @IsGranted("entity.update")
*/
public function updateForm($id, EntityManagerInterface $em, Test $test)
public function updateForm($id, EntityManagerInterface $em, Entity $e)
{
$params = [];
$params['obj'] = $test;
$params['obj'] = $e;
$params['mode'] = 'update';
// response
@ -100,14 +100,14 @@ class EntityController extends Controller{
}
/**
* @IsGranted("test.update")
* @IsGranted("entity.update")
*/
public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, Test $test)
public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, Entity $e)
{
$this->setObject($test, $req);
$this->setObject($e, $req);
// validate
$errors = $validator->validate($test);
$errors = $validator->validate($e);
// initialize error list
$error_array = [];
@ -136,12 +136,12 @@ class EntityController extends Controller{
}
/**
* @IsGranted("test.delete")
* @IsGranted("entity.delete")
*/
public function deleteSubmit(EntityManagerInterface $em, Test $test)
public function deleteSubmit(EntityManagerInterface $em, Entity $entity)
{
// delete this object
$em->remove($test);
$em->remove($entity);
$em->flush();
// response
@ -150,7 +150,7 @@ class EntityController extends Controller{
$response->send();
}
protected function setObject(Test $obj, Request $req)
protected function setObject(Entity $obj, Request $req)
{
// set and save values
$obj->setItem($req->request->get('item'))
@ -168,13 +168,13 @@ class EntityController extends Controller{
}
/**
* @IsGranted("test.list")
* @IsGranted("entity.list")
*/
public function datatableRows(Request $req)
{
// get query builder
$qb = $this->getDoctrine()
->getRepository(Test::class)
->getRepository(Entity::class)
->createQueryBuilder('q');
// get datatable params
@ -237,10 +237,10 @@ class EntityController extends Controller{
];
// 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']]);
if ($this->isGranted('entity.update'))
$row['meta']['update_url'] = $this->generateUrl('entity_update_form', ['id' => $row['id']]);
if ($this->isGranted('entity.delete'))
$row['meta']['delete_url'] = $this->generateUrl('entity_delete', ['id' => $row['id']]);
$rows[] = $row;
}

View file

@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=TestRepository::class)
*/
class Test
class Entity
{
/**
* @ORM\Id

View file

@ -0,0 +1,37 @@
<?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 Version20241023070137 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');
}
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');
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace App\Repository;
use App\Entity\Notifs;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Notifs|null find($id, $lockMode = null, $lockVersion = null)
* @method Notifs|null findOneBy(array $criteria, array $orderBy = null)
* @method Notifs[] findAll()
* @method Notifs[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class NotifsRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Notifs::class);
}
// /**
// * @return Notifs[] Returns an array of Notifs objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('n')
->andWhere('n.exampleField = :val')
->setParameter('val', $value)
->orderBy('n.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Notifs
{
return $this->createQueryBuilder('n')
->andWhere('n.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

View file

@ -2,7 +2,7 @@
namespace App\Repository;
use App\Entity\Test;
use App\Entity\Entity;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
@ -16,7 +16,7 @@ class TestRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Test::class);
parent::__construct($registry, Entity::class);
}
// /**

View file

@ -5,7 +5,7 @@
<div class="m-subheader">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h3 class="m-subheader__title">Test Types</h3>
<h3 class="m-subheader__title">Product list</h3>
</div>
</div>
</div>
@ -23,16 +23,16 @@
</span>
<h3 class="m-portlet__head-text">
{% if mode == 'update' %}
Edit Test Type
Edit Product Type
<small>{{ obj.getItem() }}</small>
{% else %}
New Test Type
New Product 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') }}">
<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('entity_update_submit', {'id': obj.getId()}) : url('entity_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">
@ -67,7 +67,7 @@
<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>
<a href="{{ url('entity_list') }}" class="btn btn-secondary">Back</a>
</div>
</div>
</div>
@ -99,7 +99,7 @@ $(function() {
text: 'Your changes have been saved!',
type: 'success',
onClose: function() {
window.location.href = "{{ url('test_list') }}";
window.location.href = "{{ url('entity_list') }}";
}
});
}).fail(function(response) {

View file

@ -33,7 +33,7 @@
</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">
<a href="{{ url('entity_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>
@ -61,7 +61,7 @@ $(function() {
type: 'remote',
source: {
read: {
url: '{{ url("test_type_rows") }}',
url: '{{ url("entity_rows") }}',
method: 'POST'
}
},