CustomTemplateDataTable.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 ModulesGarden\ProxmoxAddon\App\Services\Cloud\ResourceManager;
  35. use ModulesGarden\ProxmoxAddon\App\Decorators\OsTemplateDecorator;
  36. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\isAdmin;
  37. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  38. class CustomTemplateDataTable extends DataTable implements ClientArea
  39. {
  40. use ApiService;
  41. use ProductService;
  42. protected $id = 'customTemplateDataTable';
  43. protected $name = 'customTemplateDataTable';
  44. protected $title = 'customTemplateDataTable';
  45. protected $searchable = false;
  46. protected $tableLength = "100";
  47. public function initContent()
  48. {
  49. $this->addClass('lu-text-left');
  50. //Create
  51. $this->addButton(new CreateButton());
  52. //Update
  53. $this->addActionButton(new UpdateButton());
  54. //Delete
  55. $this->addActionButton(new DeleteButton());
  56. }
  57. protected function loadHtml()
  58. {
  59. $this->addColumn((new Column('name')))
  60. ->addColumn((new Column('description')))
  61. ->addColumn((new Column('disk')))
  62. ->addColumn((new Column('osTemplate')));
  63. }
  64. public function replaceFieldDescription($key, $row)
  65. {
  66. $vmModel = VmModel::ofId($row->id)->firstOrFail();
  67. $this->api();
  68. $vm = (new VmFactory())->fromVmModel($vmModel);
  69. if($vm->config()['description']){
  70. return $vm->config()['description'];
  71. }
  72. return '-';
  73. }
  74. public function replaceFieldOsTemplate($key, $row)
  75. {
  76. $json = \json_decode($row->data, true);
  77. if(!$json['osTemplate'] || $json['osTemplate'] =='installationFromIso'){
  78. return sl('lang')->abtr('template', "Installation From ISO Image");
  79. }
  80. $decorator = new OsTemplateDecorator($json['osTemplate']);
  81. return sl('lang')->abtr('template', $decorator->toFriendlyName());
  82. }
  83. public function replaceFieldDisk($key, $row)
  84. {
  85. return sprintf(" %s GB", $row->disk + $row->disks);
  86. }
  87. protected function loadData()
  88. {
  89. $query = VmModel::select("id", "name", "vcpus", "memory", "disk","disks", "vmid","data")
  90. ->ofHostingId($this->getWhmcsParamByKey('serviceid'))
  91. ->ofTemplate()
  92. ->getQuery();
  93. $dataProv = new QueryDataProvider();
  94. $dataProv->setDefaultSorting("name", 'ASC');
  95. $dataProv->setData($query);
  96. $this->setDataProvider($dataProv);
  97. }
  98. }