Add role list view, initial routing and methods for crud
This commit is contained in:
parent
a6d55712d9
commit
b38af2e4b5
3 changed files with 260 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ home:
|
|||
path: /
|
||||
controller: App\Controller\HomeController::index
|
||||
|
||||
# auth
|
||||
|
||||
login:
|
||||
path: /login
|
||||
controller: App\Controller\SecurityController::login
|
||||
|
|
@ -14,10 +16,48 @@ login:
|
|||
logout:
|
||||
path: /logout
|
||||
|
||||
# users
|
||||
|
||||
user_list:
|
||||
path: /users
|
||||
controller: App\Controller\UserController::index
|
||||
|
||||
# roles
|
||||
|
||||
role_list:
|
||||
path: /roles
|
||||
controller: App\Controller\RoleController::index
|
||||
|
||||
role_rows:
|
||||
path: /roles/rows
|
||||
controller: App\Controller\RoleController::rows
|
||||
methods: [POST]
|
||||
|
||||
role_create:
|
||||
path: /roles/create
|
||||
controller: App\Controller\RowController::create
|
||||
|
||||
role_create_submit:
|
||||
path: /roles/create
|
||||
controller: App\Controller\RowController::createSubmit
|
||||
methods: [PUT]
|
||||
|
||||
role_update:
|
||||
path: /roles/{id}
|
||||
controller: App\Controller\RowController::update
|
||||
|
||||
role_update_submit:
|
||||
path: /roles/{id}
|
||||
controller: App\Controller\RowController::updateSubmit
|
||||
methods: [POST]
|
||||
|
||||
role_delete:
|
||||
path: /roles/{id}
|
||||
controller: App\Controller\RoleController::destroy
|
||||
methods: [DELETE]
|
||||
|
||||
# test
|
||||
|
||||
test_acl:
|
||||
path: /test_acl
|
||||
controller: App\Controller\TestController::index
|
||||
|
|
|
|||
91
src/Controller/RoleController.php
Normal file
91
src/Controller/RoleController.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Ramcar\BaseController;
|
||||
use App\Entity\Role;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
|
||||
class RoleController extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$params = $this->initParameters('role_list');
|
||||
|
||||
$qb = $this->getDoctrine()
|
||||
->getRepository(Role::class)
|
||||
->createQueryBuilder('q')
|
||||
->getQuery();
|
||||
|
||||
// get all rows
|
||||
$rows = $qb->getResult(Query::HYDRATE_ARRAY);
|
||||
|
||||
return $this->render('role/list.html.twig', $params);
|
||||
}
|
||||
|
||||
public function rows()
|
||||
{
|
||||
// build query
|
||||
$qb = $this->getDoctrine()
|
||||
->getRepository(Role::class)
|
||||
->createQueryBuilder('q')
|
||||
->getQuery();
|
||||
|
||||
// get all rows
|
||||
$rows = $qb->getResult(Query::HYDRATE_ARRAY);
|
||||
|
||||
return $this->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$params = $this->initParameters('role_list');
|
||||
|
||||
return $this->render('role/form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function createSubmit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$params = $this->initParameters('role_list');
|
||||
|
||||
// get row data
|
||||
$repo = $this->getDoctrine()->getRepository(Role::class);
|
||||
$row = $repo->find($id);
|
||||
|
||||
if (!empty($row)) {
|
||||
$params['row'] = $row;
|
||||
} else {
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
}
|
||||
|
||||
return $this->render('role/form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function updateSubmit($id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$params = $this->initParameters('role_list');
|
||||
|
||||
// get row data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$row = $em->getRepository(Role::class)->find($id);
|
||||
|
||||
if (!empty($row)) {
|
||||
// delete this row
|
||||
$em->remove($row);
|
||||
$em->flush();
|
||||
} else {
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
}
|
||||
}
|
||||
}
|
||||
129
templates/role/list.html.twig
Normal file
129
templates/role/list.html.twig
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
{% 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">
|
||||
Roles
|
||||
</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="#" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||
<span>
|
||||
<i class="la la-key"></i>
|
||||
<span>New Role</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() {
|
||||
$(document).on('click', '.btn-delete', function() {
|
||||
var id = $(this).data('id');
|
||||
|
||||
swal({
|
||||
title: 'Confirmation',
|
||||
text: 'Are you sure you want to delete ' + id + '?',
|
||||
type: 'warning',
|
||||
showCancelButton: true
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
swal(
|
||||
'Deleted!',
|
||||
'Your imaginary file has been deleted.',
|
||||
'success'
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var options = {
|
||||
data: {
|
||||
type: 'remote',
|
||||
source: {
|
||||
read: {
|
||||
url: '{{ url("role_rows") }}',
|
||||
method: 'POST'
|
||||
}
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
title: 'ID'
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: 'Name'
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
width: 110,
|
||||
title: 'Actions',
|
||||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
var actions = '<a href="#" 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.id + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||
|
||||
if (row.id != 'ROLE_SUPER_ADMIN') {
|
||||
actions += '<a href="#" 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.id + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||
}
|
||||
|
||||
return actions;
|
||||
},
|
||||
}
|
||||
],
|
||||
search: {
|
||||
onEnter: false,
|
||||
input: $('#data-rows-search'),
|
||||
delay: 400
|
||||
},
|
||||
/*
|
||||
serverPaging: true,
|
||||
serverFiltering: true,
|
||||
serverSorting: true
|
||||
*/
|
||||
};
|
||||
|
||||
$("#data-rows").mDatatable(options);
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Loading…
Reference in a new issue