CustomTemplateDataTable.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (26.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\CustomTemplate\Pages;
  20. use MGProvision\Proxmox\v2\VmFactory;
  21. use ModulesGarden\ProxmoxAddon\App\Models\VmModel;
  22. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  23. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\CustomTemplate\Buttons\CreateButton;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\CustomTemplate\Buttons\DeleteButton;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\CustomTemplate\Buttons\ImportButton;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\CustomTemplate\Buttons\UpdateButton;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Buttons\ButtonRedirect;
  31. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\Column;
  32. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataProviders\Providers\QueryDataProvider;
  33. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataTable;
  34. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\isAdmin;
  35. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  36. class CustomTemplateDataTable extends DataTable implements ClientArea
  37. {
  38. use ApiService;
  39. use ProductService;
  40. protected $id = 'customTemplateDataTable';
  41. protected $name = 'customTemplateDataTable';
  42. protected $title = 'customTemplateDataTable';
  43. protected $searchable = false;
  44. protected $tableLength = "100";
  45. public function initContent()
  46. {
  47. $this->addClass('lu-text-left');
  48. //Create
  49. $this->addButton(new CreateButton());
  50. //Update
  51. $this->addActionButton(new UpdateButton());
  52. //Delete
  53. $this->addActionButton(new DeleteButton());
  54. }
  55. protected function loadHtml()
  56. {
  57. $this->addColumn((new Column('name')))
  58. ->addColumn((new Column('description')));
  59. }
  60. public function replaceFieldDescription($key, $row)
  61. {
  62. $vmModel = VmModel::ofId($row->id)->firstOrFail();
  63. $this->api();
  64. $vm = (new VmFactory())->fromVmModel($vmModel);
  65. if($vm->config()['description']){
  66. return $vm->config()['description'];
  67. }
  68. return '-';
  69. }
  70. protected function loadData()
  71. {
  72. $query = VmModel::select("id", "name", "vcpus", "memory", "disk","disks", "vmid","data")
  73. ->ofHostingId($this->getWhmcsParamByKey('serviceid'))
  74. ->ofTemplate()
  75. ->getQuery();
  76. $dataProv = new QueryDataProvider();
  77. $dataProv->setDefaultSorting("name", 'ASC');
  78. $dataProv->setData($query);
  79. $this->setDataProvider($dataProv);
  80. }
  81. }