diff --git a/assets/app.js b/assets/app.js index b6aa815..bc24b10 100644 --- a/assets/app.js +++ b/assets/app.js @@ -21,3 +21,4 @@ import './js/hoverable-collapse.js'; import './js/cookies.js'; import 'choices.js'; import 'quill' +import 'tabulator-tables' diff --git a/assets/controllers/organization_controller.js b/assets/controllers/organization_controller.js new file mode 100644 index 0000000..fae9cf4 --- /dev/null +++ b/assets/controllers/organization_controller.js @@ -0,0 +1,49 @@ +import {Controller} from '@hotwired/stimulus' +import {TabulatorFull as Tabulator} from "tabulator-tables"; + +export default class extends Controller { + static values = {data: String, aws: String}; + + connect() { + + this.table = new Tabulator("#tabulator-org", { + data: JSON.parse(this.dataValue), layout: "fitColumns", columns: [ + { + title: "Logo", field: "logoUrl", formatter: "image", + width: 100, + formatterParams: {height: "50px", width: "50px", urlPrefix: this.awsValue, urlSuffix: ""}, + }, + {title: "Nom", field: "name", headerFilter: "input"}, + {title: "Email", field: "email", headerFilter: "input"}, + { + title: "Actions", + field: "showUrl", + hozAlign: "center", + width: 80, + headerSort: false, + formatter: (cell) => { + const url = cell.getValue(); + if (url) { + return ` + + + + `; + } + return ''; + } + }] + }); + } + + disconnect() { + if (this.table) { + this.table.destroy(); + } + } +} \ No newline at end of file diff --git a/assets/styles/tabulator.css b/assets/styles/tabulator.css new file mode 100644 index 0000000..48a29c1 --- /dev/null +++ b/assets/styles/tabulator.css @@ -0,0 +1,52 @@ + +/* Remove outer table border */ +.tabulator { + border: none !important; +} + +/* Remove header and row cell borders */ +.tabulator-header, +.tabulator-header .tabulator-col, +.tabulator-tableholder, +.tabulator-table, +.tabulator-row, +.tabulator-row .tabulator-cell { + border: none !important; +} + +/* Remove column header bottom border and row separators */ +.tabulator-header { + border-bottom: none !important; + background-color: transparent !important; + /*border-top-left-radius: 25%;*/ + /*border-top-right-radius: 25%;*/ +} +.tabulator-row { + border-bottom: none !important; + background-color: transparent !important; +} + +/* Remove look on hover/selected without borders */ +.tabulator-row:hover { + box-shadow: none !important; +} +.tabulator-row.tabulator-selected { + box-shadow: none !important; +} + +.tabulator-row.tabulator-row-odd { + background-color: transparent !important; +} + +/* Rounded border for images in cells */ +.tabulator-cell img { + border-radius: 50%; + object-fit: cover; +} +/* Scope to this table only */ +.tabulator, + .tabulator-header, + .tabulator-header .tabulator-header-contents, + .tabulator-header .tabulator-col{ + background: none !important; +} diff --git a/src/Controller/OrganizationController.php b/src/Controller/OrganizationController.php index 675d9bd..33a8a5b 100644 --- a/src/Controller/OrganizationController.php +++ b/src/Controller/OrganizationController.php @@ -39,8 +39,21 @@ class OrganizationController extends AbstractController { $this->denyAccessUnlessGranted('ROLE_ADMIN'); $user = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); + if ($this->isGranted("ROLE_SUPER_ADMIN")) { - $organizations = $this->entityManager->getRepository(Organizations::class)->findBy([ 'isDeleted' => false ]); + $organizations = $this->entityManager->getRepository(Organizations::class)->findBy(['isDeleted' => false]); + + // Map the entities for tabulator + $organizationsData = array_map(function($org) { + return [ + 'id' => $org->getId(), + 'name' => $org->getName(), + 'email' => $org->getEmail(), + 'logoUrl' => $org->getLogoUrl() ? $org->getLogoUrl() : null, // or prepend base URL if needed + 'active' => $org->isActive(), + 'showUrl' => $this->generateUrl('organization_show', ['id' => $org->getId()]), + ]; + }, $organizations); } else { //get all the UO of the user $uos = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user]); @@ -57,9 +70,8 @@ class OrganizationController extends AbstractController } } - return $this->render('organization/index.html.twig', [ - 'organizations' => $organizations, + 'organizationsData' => $organizationsData, ]); } diff --git a/templates/organization/index.html.twig b/templates/organization/index.html.twig index 560c999..6ff1ab3 100644 --- a/templates/organization/index.html.twig +++ b/templates/organization/index.html.twig @@ -10,7 +10,7 @@ Ajouter une organisation {% endif %} - {% if organizations|length == 0 %} + {% if organizationsData|length == 0 %}
| Logo | -Nom | -Visualiser | -Status | -|
|---|---|---|---|---|
|
- {% if organization.logoUrl %}
- |
- {{ organization.name }} | -{{ organization.email }} | -- {% if organization.active %} - Active - {% else %} - Inactive - {% endif %} - | -- - {{ ux_icon('fa6-regular:eye', {height: '30px', width: '30px'}) }} - - | -